add spp siswa export

pull/1/head
Aji Kamaludin 5 years ago
parent 45cc07061b
commit 2c9d6e449d
No known key found for this signature in database
GPG Key ID: 23E2BDC458317AF8

@ -2,15 +2,24 @@
namespace App\Exports; namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection; use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class SppSiswaExport implements FromCollection class SppSiswaExport implements FromView
{ {
/** public function __construct($siswa, $transaksi, $tanggal)
* @return \Illuminate\Support\Collection
*/
public function collection()
{ {
// $this->siswa = $siswa;
$this->transaksi = $transaksi;
$this->tanggal = $tanggal;
}
public function view(): View
{
return view('transaksi.export', [
'siswa' => $this->siswa,
'transaksi' => $this->transaksi,
'tanggal' => $this->tanggal
]);
} }
} }

@ -9,6 +9,7 @@ use App\Models\Tagihan;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Models\Keuangan; use App\Models\Keuangan;
use App\Models\Tabungan; use App\Models\Tabungan;
use App\Exports\SppSiswaExport;
class TransaksiController extends Controller class TransaksiController extends Controller
{ {
@ -149,4 +150,23 @@ class TransaksiController extends Controller
return $tagihan; return $tagihan;
} }
public function export(Request $request, Siswa $siswa)
{
$beweendate = [];
$dates = explode('-',$request->dates);
foreach($dates as $index => $date){
if($index == 0){
$date .= ' 00:00:00';
}else{
$date .= ' 23:59:59';
}
$beweendate[] = \Carbon\Carbon::create($date)->format('Y-m-d H:i:s');
}
$transaksi = Transaksi::where('siswa_id', $siswa->id)->whereBetween('created_at', [$beweendate[0], $beweendate[1]])->get();
return \Excel::download(new SppSiswaExport($siswa, $transaksi, $request->dates), 'spp_siswa-'.now().'.xlsx');
}
} }

@ -76,7 +76,7 @@
<div class="card-options"> <div class="card-options">
<input class="form-control mr-2" type="text" name="dates" style="max-width: 200px" id="daterange" value="{{ now()->subDay(7)->format('m-d-Y')." - ".now()->format('m-d-Y') }}"> <input class="form-control mr-2" type="text" name="dates" style="max-width: 200px" id="daterange" value="{{ now()->subDay(7)->format('m-d-Y')." - ".now()->format('m-d-Y') }}">
<button id="btn-cetak-spp" class="btn btn-primary mr-1" value="{{ $siswa->id }}">Cetak</button> <button id="btn-cetak-spp" class="btn btn-primary mr-1" value="{{ $siswa->id }}">Cetak</button>
<a href="#!" target="_blank" class="btn btn-primary">Export</a> <button id="btn-export-spp" class="btn btn-primary" value="{{ $siswa->id }}">Export</button>
</div> </div>
@endif @endif
</div> </div>
@ -146,6 +146,30 @@
console.log($('#daterange').val()) console.log($('#daterange').val())
}) })
$('#btn-export-spp').on('click', function(){
//form print
var form = document.createElement("form");
form.setAttribute("style", "display: none");
form.setAttribute("method", "post");
form.setAttribute("action", "{{ route('spp.export') }}/" + this.value);
form.setAttribute("target", "_blank");
var token = document.createElement("input");
token.setAttribute("name", "_token");
token.setAttribute("value", "{{csrf_token()}}");
var dateForm = document.createElement("input");
dateForm.setAttribute("name", "dates");
dateForm.setAttribute("value", $('#daterange').val());
form.appendChild(token);
form.appendChild(dateForm);
document.body.appendChild(form);
form.submit();
console.log($('#daterange').val())
})
}); });
</script> </script>
@endsection @endsection

@ -0,0 +1,33 @@
<h2 style="text-align:center"><b> {{ $sitename }} </b></h2>
<h3 style="text-align:center">Tanda Bukti Pembayaran</h3>
<br>
<p><b>Nama :</b> {{ $siswa->nama }} <b>Kelas : </b> {{ $siswa->kelas->nama }}{{ isset($siswa->kelas->periode) ? '('.$siswa->kelas->periode->nama.')' : '' }}</p>
<p><b>Tanggal : </b> {{ $tanggal }}</p>
<table style="border: 1px solid black; width: 100%">
<tr style="border: 1px solid black;">
<th>No</th>
<th>Tagihan</th>
<th>Tanggal</th>
<th>Jumlah</th>
<th>Keterangan</th>
</tr>
@foreach ($transaksi as $index => $item)
<tr class="{{ ($index%2) ? 'gray' : '' }}">
<td style="min-width:20px;text-align: center;">
{{ $index+1 }}
</td>
<td style="min-width:200px;text-align: center;">
{{ $item->tagihan->nama }}
</td>
<td style="min-width:80px;text-align: center;">
{{ $item->created_at->format('d-m-Y') }}
</td>
<td style="min-width:200px;text-align: left;">
IDR. {{ format_idr($item->keuangan->jumlah) }}
</td>
<td style="min-width:20px;text-align: center;">
{{ $item->keterangan }}
</td>
</tr>
@endforeach
</table>

@ -79,7 +79,7 @@ Route::middleware(['auth:web'])->group(function(){
//Pembayaran SPP //Pembayaran SPP
Route::get('transaksi-spp','TransaksiController@index')->name('spp.index'); Route::get('transaksi-spp','TransaksiController@index')->name('spp.index');
Route::post('print-spp/{siswa?}','TransaksiController@print')->name('spp.print'); Route::post('print-spp/{siswa?}','TransaksiController@print')->name('spp.print');
Route::post('export-spp/{siswa?}','TransaksiController@export')->name('spp.export');// TODO: export spp Route::post('export-spp/{siswa?}','TransaksiController@export')->name('spp.export');
}); });

Loading…
Cancel
Save