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.stok-audit.index', compact('month', 'year')); } public function show(Request $request) { $validated = $request->validate( ['monthYear' => 'required'], ['monthYear.required' => 'Sila isi tarikh sebelum hantar', ]); $current = Carbon::now(); $tarikh_cetak = $current->toDateString(); $tokens = explode('-', $validated['monthYear']); $month = ltrim($tokens[0], '0'); $year = $tokens[1]; // Set the locale to Malaysian App::setLocale('ms'); // Create a Carbon instance representing the date $date = Carbon::createFromDate($year, $month, 1); // Set the day to 1st of the month // Get the name of the month in Malaysian local $monthName = $date->translatedFormat('F'); $request->hostname = config('api.url'); $stokAudit = Http::get($request->hostname . '/api/reports/stok-audit', [ 'month' => $month, 'year' => $year, ])->json(); $tebus_date = $monthName . ' ' . $year; $file_title = sprintf("Laporan-StokAudit %s (%s - %s).xlsx", 'Semua cawangan', $monthName, $year); if ($request->generateType === 'pdf') { return view('reports.stok-audit.show', compact('tebus_date', 'tarikh_cetak', 'stokAudit', 'month', 'year')); } else { return Excel::download(new StokAuditExport($stokAudit), $file_title); } } }