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 @@ +
Tanggal : {{ $date }}
+Tanggal | +Nama | +Pembayaran | +Total | +
---|---|---|---|
{{ $item->created_at->format('d-m-Y') }} | +{{ $item->siswa->nama." (".$item->siswa->kelas->nama.")" }} | +{{ $item->tagihan->nama }} | +IDR. {{ format_idr($item->keuangan->jumlah) }} | + @php + $jumlah += $item->keuangan->jumlah + @endphp +
Total | ++ | + | IDR. {{ format_idr($jumlah) }} | +
Tanggal | +Nama | +Pembayaran | +Total | +
---|---|---|---|
{{ $item->created_at->format('d-m-Y') }} | +{{ $item->siswa->nama }} | +{{ $item->tagihan->nama }} | +IDR. {{ format_idr($item->keuangan->jumlah) }} | + @php + $jumlah += $item->keuangan->jumlah + @endphp +
Total | ++ | + | IDR. {{ format_idr($jumlah) }} | +
Logo :