diff --git a/app/Exports/LaporanHarianExport.php b/app/Exports/LaporanHarianExport.php new file mode 100644 index 0000000..e3e0f1b --- /dev/null +++ b/app/Exports/LaporanHarianExport.php @@ -0,0 +1,31 @@ +date = $date; + $this->tanggal = $tanggal; + } + public function collection() + { + return Transaksi::orderBy('siswa_id','desc')->whereDate('created_at', $this->date)->get(); + } + + public function view(): View + { + return view('dashboard.export', [ + 'transaksi' => $this->collection(), + 'date' => $this->date, + 'tanggal' => $this->tanggal, + 'jumlah' => 0 + ]); + } +} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index ee04593..aaba0a2 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -5,6 +5,10 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Models\Keuangan; +use App\Models\Tagihan; +use App\Models\Transaksi; +use App\Exports\LaporanHarianExport; +use Maatwebsite\Excel\Facades\Excel; class HomeController extends Controller { @@ -14,12 +18,17 @@ class HomeController extends Controller $total_uang_spp = Keuangan::where('tipe','in')->where('transaksi_id','!=','null')->sum('jumlah') - Keuangan::where('tipe','out')->where('transaksi_id','!=','null')->sum('jumlah');; $total_uang_masuk = Keuangan::where('tipe','in')->sum('jumlah'); $total_uang_keluar = Keuangan::where('tipe','out')->sum('jumlah'); + + $transaksi = Transaksi::orderBy('siswa_id','desc')->whereDate('created_at', now()->today())->get(); + return view('dashboard.index',[ 'total_uang' => $total_uang, 'total_uang_tabungan' => $total_uang_tabungan, 'total_uang_spp' => $total_uang_spp, 'total_uang_masuk' => $total_uang_masuk, 'total_uang_keluar' => $total_uang_keluar, + 'transaksi' => $transaksi, + 'jumlah' => '0' ]); } @@ -58,6 +67,15 @@ class HomeController extends Controller ]); } - //TODO: dump sql all data - //TODO: reset all data + public function cetak(Request $request){ + $date = \Carbon\Carbon::create($request->date)->format('Y-m-d'); + $transaksi = Transaksi::orderBy('siswa_id','desc')->whereDate('created_at', $date)->get(); + + return view('dashboard.export', ['transaksi' => $transaksi, 'date' => $request->date, 'jumlah' => 0, 'print' => true]); + } + + public function export(Request $request){ + $date = \Carbon\Carbon::create($request->date)->format('Y-m-d'); + return Excel::download(new LaporanHarianExport($date, $request->date), 'laporan-harian-'.now().'.xlsx'); + } } diff --git a/app/Models/Tagihan.php b/app/Models/Tagihan.php index df4b12d..9921104 100644 --- a/app/Models/Tagihan.php +++ b/app/Models/Tagihan.php @@ -22,6 +22,10 @@ class Tagihan extends Model return $this->hasMany('App\Models\Transaksi','tagihan_id','id'); } + public function transaksiToday(){ + return $this->transaksi()->whereDate('created_at', now()->today()); + } + public function role(){ return $this->hasMany('App\Models\Role','tagihan_id','id'); } diff --git a/resources/views/dashboard/export.blade.php b/resources/views/dashboard/export.blade.php new file mode 100644 index 0000000..f07739a --- /dev/null +++ b/resources/views/dashboard/export.blade.php @@ -0,0 +1,49 @@ +

{{ $sitename }}

+

Laporan Harian

+

Tanggal : {{ $date }}

+ + + + + + + + + + + @foreach ($transaksi as $index => $item) + + + + + + @php + $jumlah += $item->keuangan->jumlah + @endphp + + @endforeach + + + + + + + +
TanggalNamaPembayaranTotal
{{ $item->created_at->format('d-m-Y') }}{{ $item->siswa->nama." (".$item->siswa->kelas->nama.")" }}{{ $item->tagihan->nama }}IDR. {{ format_idr($item->keuangan->jumlah) }}
TotalIDR. {{ format_idr($jumlah) }}
+@if(isset($print)) + + +@endif \ No newline at end of file diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 69f5f62..1d7a1c5 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -54,13 +54,42 @@

Laporan Harian : {{ now()->format('d-m-Y') }}

- + - Export +
- report harian + + + + + + + + + + + @foreach ($transaksi as $item) + + + + + + @php + $jumlah += $item->keuangan->jumlah + @endphp + + @endforeach + + + + + + + +
TanggalNamaPembayaranTotal
{{ $item->created_at->format('d-m-Y') }}{{ $item->siswa->nama }}{{ $item->tagihan->nama }}IDR. {{ format_idr($item->keuangan->jumlah) }}
TotalIDR. {{ format_idr($jumlah) }}
+
@@ -73,6 +102,46 @@ $('[data-toggle="datepicker"]').datepicker({ format: 'dd-MM-yyyy' }); + $('#btn-cetak-spp').on('click', function(){ + var form = document.createElement("form"); + form.setAttribute("style", "display: none"); + form.setAttribute("method", "post"); + form.setAttribute("action", "{{route('laporan-harian.cetak')}}"); + 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", "date"); + dateForm.setAttribute("value", $('#date').val()); + + form.appendChild(token); + form.appendChild(dateForm); + document.body.appendChild(form); + form.submit(); + }) + $('#btn-export-spp').on('click', function(){ + var form = document.createElement("form"); + form.setAttribute("style", "display: none"); + form.setAttribute("method", "post"); + form.setAttribute("action", "{{route('laporan-harian.export')}}"); + 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", "date"); + dateForm.setAttribute("value", $('#date').val()); + + form.appendChild(token); + form.appendChild(dateForm); + document.body.appendChild(form); + form.submit(); + }) }); }); diff --git a/resources/views/pengaturan/index.blade.php b/resources/views/pengaturan/index.blade.php index 72c9789..c5ff814 100644 --- a/resources/views/pengaturan/index.blade.php +++ b/resources/views/pengaturan/index.blade.php @@ -32,8 +32,8 @@

Logo :

Logo Sistem
- - + {{-- + --}}
diff --git a/routes/web.php b/routes/web.php index 0a159f1..1cbe4db 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,6 +17,8 @@ Route::middleware(['auth:web'])->group(function(){ Route::get('pengaturan','HomeController@pengaturan')->name('pengaturan.index'); Route::get('ubah-pengaturan','HomeController@editPengaturan')->name('pengaturan.edit'); Route::post('ubah-pengaturan','HomeController@storePengaturan')->name('pengaturan.store'); + Route::Post('cetak-laporan-harian','HomeController@cetak')->name('laporan-harian.cetak'); + Route::post('export-laporan-harian','HomeController@export')->name('laporan-harian.export'); //Siswa Route::get('siswa','SiswaController@index')->name('siswa.index');