toDateString(); } return $date_string; }; $request->hostname = config('api.url'); $data = Http::get($request->hostname . '/api/reports/ansuran', [ 'startDate' => $getReportDate($request->startDate), 'endDate' => $getReportDate($request->endDate), ])->json(); $summary_ansuran_by_cawangan = $data['summary_ansuran_by_cawangan']; $summary_ansuran = $data['summary_ansuran']; $startDate = $getReportDate($request->startDate); $endDate = $getReportDate($request->endDate); return view('reports.ansuran.index', compact('summary_ansuran_by_cawangan', 'summary_ansuran', 'startDate', 'endDate')); } public function downloadAnsuranCawanganExcel(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; $data = Http::get($request->hostname . '/api/reports/ansuran/' . $kod_cawangan, [ 'startDate' => $getReportDate($request->startDate), 'endDate' => $getReportDate($request->endDate), ])->json(); $file_title = sprintf("LaporanAnsuran %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate); return Excel::download(new AnsuranExport($data), $file_title); } }