66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Reports;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Http;
|
|
use App\Exports\LaporanKeseluruhan\StokAuditExport;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
class StokAuditController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$request->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);
|
|
}
|
|
|
|
}
|
|
}
|