diff --git a/app/Exports/SppSiswaExport.php b/app/Exports/SppSiswaExport.php index 5fd78cb..e75c971 100644 --- a/app/Exports/SppSiswaExport.php +++ b/app/Exports/SppSiswaExport.php @@ -2,15 +2,24 @@ 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 { - /** - * @return \Illuminate\Support\Collection - */ - public function collection() + public function __construct($siswa, $transaksi, $tanggal) { - // + $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 + ]); } } diff --git a/app/Http/Controllers/TransaksiController.php b/app/Http/Controllers/TransaksiController.php index e142679..f2d64b6 100644 --- a/app/Http/Controllers/TransaksiController.php +++ b/app/Http/Controllers/TransaksiController.php @@ -9,6 +9,7 @@ use App\Models\Tagihan; use Illuminate\Support\Facades\DB; use App\Models\Keuangan; use App\Models\Tabungan; +use App\Exports\SppSiswaExport; class TransaksiController extends Controller { @@ -149,4 +150,23 @@ class TransaksiController extends Controller 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'); + } } diff --git a/resources/views/siswa/show.blade.php b/resources/views/siswa/show.blade.php index 1628ba4..1ec2838 100644 --- a/resources/views/siswa/show.blade.php +++ b/resources/views/siswa/show.blade.php @@ -76,7 +76,7 @@
@endif @@ -146,6 +146,30 @@ 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()) + }) }); @endsection \ No newline at end of file diff --git a/resources/views/transaksi/export.blade.php b/resources/views/transaksi/export.blade.php new file mode 100644 index 0000000..5d6179d --- /dev/null +++ b/resources/views/transaksi/export.blade.php @@ -0,0 +1,33 @@ +Nama : {{ $siswa->nama }} Kelas : {{ $siswa->kelas->nama }}{{ isset($siswa->kelas->periode) ? '('.$siswa->kelas->periode->nama.')' : '' }}
+Tanggal : {{ $tanggal }}
+No | +Tagihan | +Tanggal | +Jumlah | +Keterangan | +
---|---|---|---|---|
+ {{ $index+1 }} + | ++ {{ $item->tagihan->nama }} + | ++ {{ $item->created_at->format('d-m-Y') }} + | ++ IDR. {{ format_idr($item->keuangan->jumlah) }} + | ++ {{ $item->keterangan }} + | +