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'); $aging = Http::get($request->hostname . '/api/reports/aging', [ 'endDate' => $getReportDate($request->endDate), ])->json(); $endDate = $getReportDate($request->endDate); if ($action === 'excel') { $file_title = sprintf("LaporanAging(%s).xlsx", $kod_cawangan, $request->endDate); return Excel::download(new AgingAllExportExcel($aging), $file_title); } $aging = $aging ?? []; return view('reports.aging.index', compact('aging', 'endDate')); } public function show(Request $request) { $current = Carbon::now(); $action = $request->input('action', 'search'); $getReportDate = function ($date_string) use ($current) { return $date_string ? $date_string : $current->toDateString(); }; $hostname = config('api.url'); $response = Http::get("$hostname/api/reports/aging", [ 'endDate' => $getReportDate($request->endDate), ]); $aging = $response->json() ?? []; // Ensure it's an array // Debugging: Check the response before using it if (empty($aging)) { return back()->with('error', 'Failed to fetch data from API.'); } $endDate = $getReportDate($request->endDate); if ($action === 'excel') { // Ensure $kod_cawangan is defined (Modify as per your data structure) $kod_cawangan = $request->input('kod_cawangan', 'DEFAULT'); $file_title = sprintf("LaporanAging(%s).xlsx", $kod_cawangan, $endDate); return Excel::download(new AgingAllExportExcel($aging), $file_title); } return view('reports.aging.index', compact('aging', 'endDate')); } public function agingtebus(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'); $startDate = $getReportDate($request->startDate); $endDate = $getReportDate($request->endDate); $aging = Http::get($request->hostname . '/api/reports/agingtebus', [ 'startDate' => $startDate, 'endDate' => $endDate, ])->json(); $aging = $aging ?? []; if ($action === 'excel') { $file_title = sprintf("LaporanAging(%s).xlsx", $kod_cawangan, $startDate, $endDate); return Excel::download(new AgingTebusAllExportExcel($aging,$startDate,$endDate), $file_title); } return view('reports.agingtebus.index', compact('aging', 'startDate', 'endDate')); } public function showagingtebus(Request $request) { $current = Carbon::now(); $action = $request->input('action', 'search'); $getReportDate = function ($date_string) use ($current) { return $date_string ? $date_string : $current->toDateString(); }; $hostname = config('api.url'); $startDate = $getReportDate($request->startDate); $endDate = $getReportDate($request->endDate); $response = Http::get("$hostname/api/reports/agingtebus", [ 'startDate' => $startDate, 'endDate' => $endDate, ]); $aging = $response->json() ?? []; // Ensure it's an array // Debugging: Check the response before using it if (empty($aging)) { return back()->with('error', 'Failed to fetch data from API.'); } if ($action === 'excel') { // Ensure $kod_cawangan is defined (Modify as per your data structure) $kod_cawangan = $request->input('kod_cawangan', 'DEFAULT'); $file_title = sprintf("LaporanAgingTebus(%s).xlsx", $kod_cawangan, $startDate, $endDate); return Excel::download(new AgingTebusAllExportExcel($aging, $startDate, $endDate), $file_title); } return view('reports.agingtebus.index', compact('aging', 'startDate', 'endDate')); } }