hostname = config('api.url'); // dd($request->hostname ); $kod_cawangan = $request->kod_cawangan; $action = $request->input('action', 'search'); // dd($action); $getReportDate = function ($date_string) use ($current) { if ($date_string == null) { return $current->toDateString(); } return $date_string; }; $request->hostname = config('api.url'); $pelangganbaru = Http::get($request->hostname . '/api/reports/pelangganbaru', [ 'startDate' => $getReportDate($request->startDate), 'endDate' => $getReportDate($request->endDate), ])->json(); // dd($pelangganbaru); $startDate = $getReportDate($request->startDate); $endDate = $getReportDate($request->endDate); if ($action === 'excel') { $file_title = sprintf("LaporanPelangganBaru(%s).xlsx", $kod_cawangan, $request->startDate, $request->endDate); return Excel::download(new PelangganbaruAllExportExcel($pelangganbaru,$startDate,$endDate), $file_title); } $pelangganbaru = $pelangganbaru ?? []; return view('reports.pelangganbaru.index', compact('pelangganbaru', 'startDate', 'endDate')); } public function pelangganaktif(Request $request) { $current = new Carbon(); $request->hostname = config('api.url'); // dd($request->hostname ); $kod_cawangan = $request->kod_cawangan; $action = $request->input('action', 'search'); // dd($action); $getReportDate = function ($date_string) use ($current) { if ($date_string == null) { return $current->toDateString(); } return $date_string; }; $request->hostname = config('api.url'); $pelangganaktif = Http::get($request->hostname . '/api/reports/pelangganaktif', [ 'startDate' => $getReportDate($request->startDate), 'endDate' => $getReportDate($request->endDate), ])->json(); // dd($pelangganbaru); $startDate = $getReportDate($request->startDate); $endDate = $getReportDate($request->endDate); if ($action === 'excel') { $file_title = sprintf("LaporanPelangganAktif(%s).xlsx", $kod_cawangan, $request->startDate, $request->endDate); return Excel::download(new PelangganaktifAllExportExcel($pelangganaktif,$startDate,$endDate), $file_title); } $pelangganaktif = $pelangganaktif ?? []; return view('reports.pelangganaktif.index', compact('pelangganaktif', 'startDate', 'endDate')); } public function dataPelanggan(Request $request) { $request->hostname = config('api.url'); $current = new Carbon(); $month = $request->filled('month') ? $request->month : $current->month; $year = $request->filled('year') ? $request->year : $current->year; return view('reports.data-pelanggan.index', compact('month', 'year')); } public function dataPelangganShow(Request $request) { $validated = $request->validate([ 'year' => 'required|digits:4' ]); $year = $validated['year']; $tarikh_cetak = now()->format('d/m/Y'); $tebus_date = 'Tahun ' . $year; $request->hostname = config('api.url'); $response = Http::get($request->hostname . '/api/reports/data-pelanggan', [ 'year' => $year, ])->json(); $summary = $response['summary']; $pelanggan = $response['pelanggan']; if ($request->generateType === 'pdf') { return view( 'reports.data-pelanggan.show', compact('summary','pelanggan','tarikh_cetak','tebus_date','year') ); } elseif ($request->generateType === 'excel') { return Excel::download( new DataPelangganDetailExport($pelanggan, $year), "Laporan-Data-Pelanggan-{$year}.xlsx" ); } } public function dataPelangganBycaw(Request $request) { $request->hostname = config('api.url'); $current = new Carbon(); $month = $request->filled('month') ? $request->month : $current->month; $year = $request->filled('year') ? $request->year : $current->year; return view('reports.data-pelanggan-bycaw.index', compact('month', 'year')); } public function dataPelangganBycawShow(Request $request) { $validated = $request->validate([ 'year' => 'required|digits:4', 'cawangan' => 'required|array|min:1' ]); $year = $validated['year']; $cawangan = $validated['cawangan']; // array kod cawangan $tarikh_cetak = now()->format('d/m/Y'); $tebus_date = 'Tahun ' . $year; $request->hostname = config('api.url'); // 🔑 Forward ke API $response = Http::get( $request->hostname . '/api/reports/data-pelanggan-bycaw', [ 'year' => $year, 'cawangan' => $cawangan, // array terus ] )->json(); if (!isset($response['summary'], $response['pelanggan'])) { abort(500, 'Data API tidak sah'); } $summary = $response['summary']; $pelanggan = $response['pelanggan']; if ($request->generateType === 'pdf') { return view( 'reports.data-pelanggan-bycaw.show', compact('summary','pelanggan','tarikh_cetak','tebus_date','year','cawangan') ); } if ($request->generateType === 'excel') { return Excel::download( new DataPelangganBycawDetailExport($pelanggan, $year, $cawangan), "Laporan-Data-Pelanggan-Bycaw-{$year}.xlsx" ); } abort(400, 'Jenis laporan tidak sah'); } }