update trip report

This commit is contained in:
Pringgosutono
2025-09-02 09:57:39 +07:00
parent cf6594a5da
commit 3ad22e0cf5
2 changed files with 96 additions and 74 deletions

View File

@ -97,79 +97,79 @@ class ReportsController extends Controller
$list = DB::select($q, $d);
// RETURN 1 - LIST
if($req->type != 'report'){
// // RETURN 1 - LIST
// if($req->type != 'report'){
$apiResp = Responses::success("success list vehicles report");
$apiResp["data"] = $list;
return new Response($apiResp, $apiResp["meta"]["code"]);
}
// }
// RETURN 2 - REPORT
if($req->type == 'report'){
$headings = ['Name', 'License Plate', 'Number of Trip', 'Total Mileage'];
// // RETURN 2 - REPORT
// if($req->type == 'report'){
// $headings = ['Name', 'License Plate', 'Number of Trip', 'Total Mileage'];
$export = new class($list, $headings) implements FromArray, WithHeadings {
private $list;
private $headings;
// $export = new class($list, $headings) implements FromArray, WithHeadings {
// private $list;
// private $headings;
public function __construct($list, $headings)
{
$this->list = $list;
$this->headings = $headings;
}
// public function __construct($list, $headings)
// {
// $this->list = $list;
// $this->headings = $headings;
// }
public function array(): array
{
return array_map(function ($item) {
return [
$item->name,
$item->nopol1,
$item->numOfTrip,
$item->total_milleage,
];
}, $this->list);
}
// public function array(): array
// {
// return array_map(function ($item) {
// return [
// $item->name,
// $item->nopol1,
// $item->numOfTrip,
// $item->total_milleage,
// ];
// }, $this->list);
// }
public function headings(): array
{
return $this->headings;
}
// public function headings(): array
// {
// return $this->headings;
// }
// Start table from A3
public function startCell(): string
{
return 'A3';
}
// // Start table from A3
// public function startCell(): string
// {
// return 'A3';
// }
// Add title & border styling
public function styles(Worksheet $sheet)
{
$tgl0 = date('d-m-Y', $GLOBALS['from_date']);
$tgl1 = date('d-m-Y', $GLOBALS['to_date']);
// // Add title & border styling
// public function styles(Worksheet $sheet)
// {
// $tgl0 = date('d-m-Y', $GLOBALS['from_date']);
// $tgl1 = date('d-m-Y', $GLOBALS['to_date']);
// Title in A1
$sheet->setCellValue('A1', 'Vehicle Trip Report $tgl0 until $tgl1');
$sheet->mergeCells('A1:D1'); // Merge across 4 columns
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
$sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
// // Title in A1
// $sheet->setCellValue('A1', 'Vehicle Trip Report $tgl0 until $tgl1');
// $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
// $sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
// $sheet->mergeCells('A1:D1'); // Merge across 4 columns
// Get last row
$lastRow = $this->list->count() + 3; // 3 = heading row
$range = "A3:D{$lastRow}";
// // Get last row
// $lastRow = $this->list->count() + 3; // 3 = heading row
// $range = "A3:D{$lastRow}";
// Add borders
$sheet->getStyle($range)->getBorders()->getAllBorders()
->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
// // Add borders
// $sheet->getStyle($range)->getBorders()->getAllBorders()
// ->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN);
// Bold headings
$sheet->getStyle('A3:D3')->getFont()->setBold(true);
// // Bold headings
// $sheet->getStyle('A3:D3')->getFont()->setBold(true);
return [];
}
};
// return [];
// }
// };
return Excel::download($export, 'trip_report.xlsx');
}
// return Excel::download($export, 'trip_report.xlsx');
// }
} catch (\Exception $e) {
$apiResp = Responses::error($e->getMessage());
return new Response($apiResp, $apiResp["meta"]["code"]);