tambah function untuk stok audit semasa
This commit is contained in:
@@ -25,38 +25,53 @@ class StokAuditController extends Controller
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$tarikh_cetak = Carbon::now()->toDateString(); // tarikh cetak
|
||||
|
||||
if ($request->dateOption === 'current') {
|
||||
$date = Carbon::now();
|
||||
$tebus_date = $date->format('d-m-Y'); // tarikh semasa
|
||||
$monthName = $date->translatedFormat('F'); // bulan semasa
|
||||
} else {
|
||||
$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
|
||||
$date = Carbon::createFromDate($year, $month, 1); // set day = 1
|
||||
$monthName = $date->translatedFormat('F');
|
||||
$tebus_date = $monthName . ' ' . $year;
|
||||
}
|
||||
|
||||
$month = $date->month;
|
||||
$year = $date->year;
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$stokAudit = Http::get($request->hostname . '/api/reports/stok-audit', [
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'dateOption' => $request->dateOption
|
||||
])->json();
|
||||
|
||||
$tebus_date = $monthName . ' ' . $year;
|
||||
$file_title = sprintf("Laporan-StokAudit %s (%s - %s).xlsx", 'Semua cawanangan', $monthName, $year);
|
||||
$file_title = sprintf(
|
||||
"Laporan-StokAudit %s (%s).xlsx",
|
||||
'Semua cawangan',
|
||||
$tebus_date
|
||||
);
|
||||
|
||||
if ($request->generateType === 'pdf') {
|
||||
return view('reports.stok-audit.show', compact('tebus_date', 'tarikh_cetak', 'stokAudit', 'month', 'year'));
|
||||
return view('reports.stok-audit.show', compact(
|
||||
'stokAudit',
|
||||
'month',
|
||||
'year',
|
||||
'monthName',
|
||||
'tarikh_cetak',
|
||||
'tebus_date'
|
||||
));
|
||||
} else {
|
||||
return Excel::download(new StokAuditExport($stokAudit), $file_title);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user