tambah excel untuk laporan keseluruhan
This commit is contained in:
@@ -10,12 +10,16 @@ use Illuminate\Support\Facades\Http;
|
||||
use App\Exports\LelonganExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Exports\LaporanKeseluruhan\LelonganAllExportExcel;
|
||||
|
||||
class LelonganController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$request->hostname = config('api.url');
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
@@ -36,48 +40,49 @@ class LelonganController extends Controller
|
||||
$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)
|
||||
{
|
||||
$validated = $request->validate(
|
||||
['monthYear' => 'required'],
|
||||
['monthYear.required' => 'Sila isi tarikh sebelum hantar',
|
||||
]);
|
||||
{
|
||||
$current = Carbon::now();
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$current = Carbon::now();
|
||||
$tarikh_cetak = $current->toDateString();
|
||||
$tokens = explode('-', $validated['monthYear']);
|
||||
$month = ltrim($tokens[0], '0');
|
||||
$year = $tokens[1];
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
return $date_string ? $date_string : $current->toDateString();
|
||||
};
|
||||
|
||||
// Set the locale to Malaysian
|
||||
App::setLocale('ms');
|
||||
$hostname = config('api.url');
|
||||
|
||||
// Create a Carbon instance representing the date
|
||||
$date = Carbon::createFromDate($year, $month, 1); // Set the day to 1st of the month
|
||||
$response = Http::get("$hostname/api/reports/lelongan", [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
]);
|
||||
|
||||
// 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 cawanangan', $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);
|
||||
}
|
||||
$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;
|
||||
|
||||
Reference in New Issue
Block a user