hostname = config('api.url'); $kod_cawangan = $request->kod_cawangan; $action = $request->input('action', 'search'); $getReportDate = function ($date_string) use ($current) { if ($date_string == null) { return $current->toDateString(); } return $date_string; }; $request->hostname = config('api.url'); $lelongan = Http::get($request->hostname . '/api/reports/lelongan', [ 'startDate' => $getReportDate($request->startDate), 'endDate' => $getReportDate($request->endDate), ])->json(); // dd($lelongan); $startDate = $getReportDate($request->startDate); $endDate = $getReportDate($request->endDate); if ($action === 'excel') { $file_title = sprintf("LaporanLelongan %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate); return Excel::download(new LelonganAllExportExcel($data), $file_title); } return view('reports.laporan-lelong.index', compact('lelongan', 'startDate', '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/lelongan", [ 'startDate' => $getReportDate($request->startDate), 'endDate' => $getReportDate($request->endDate), ]); $lelongan = $response->json() ?? []; // Ensure it's an array // Debugging: Check the response before using it if (empty($lelongan)) { return back()->with('error', 'Failed to fetch data from API.'); } $startDate = $getReportDate($request->startDate); $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("LaporanLelongan %s (%s - %s).xlsx", $kod_cawangan, $startDate, $endDate); return Excel::download(new LelonganAllExportExcel($lelongan), $file_title); } return view('reports.laporan-lelong.index', compact('lelongan', 'startDate', 'endDate')); } public function downloadLelonganCawanganExcel(Request $request) { $api_url = $request->hostname; $auth_user = Auth::user(); $current = Carbon::now(); $current = new Carbon(); $tarikh_cetak = $current->toDateString(); $getReportDate = function ($date_string) use ($current) { if ($date_string == null) { return $current->toDateString(); } return $date_string; }; $request->hostname = config('api.url'); $kod_cawangan = $request->kod_cawangan; // dd($kod_cawangan); $data = Http::get($request->hostname . '/api/reports/lelongan/' . $kod_cawangan, [ 'startDate' => $getReportDate($request->startDate), 'endDate' => $getReportDate($request->endDate), ])->json(); // dd($data); $file_title = sprintf("LaporanLelongan %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate); return Excel::download(new LelonganExport($data), $file_title); } }