Files
GSB-Construction/Modules/MasterData/app/Exports/BoqTemplateExport.php

99 lines
3.2 KiB
PHP

<?php
namespace Modules\MasterData\Exports;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class BoqTemplateExport implements FromArray, WithStyles, WithColumnWidths
{
public function array(): array
{
return [
// Header section (A=label, B=value)
['PROJECT NAME', ''],
['OWNER NAME', ''],
['LOCATION', ''],
['DATE', ''],
[],
// Detail table header
['BILL OF QUANTITIES'],
['Item no.', 'Description of Materials', 'UNIT', 'APPROVED QUANTITY', 'REQUEST QUANTITY', 'SYSTEM /WORK AREA'],
// Sample rows
['1', '200mm thk aggregate sub-base course', 'cu.m', '2970.00', '505.00', 'Access Road'],
['2', '300mm thk portland cement concrete pavement', 'cu.m', '4240.00', '721.00', 'Access Road'],
['3', '6mm thk bituminous joint sealant', 'lm', '1460.00', '90', 'Access Road'],
];
}
public function columnWidths(): array
{
return [
'A' => 12,
'B' => 50,
'C' => 12,
'D' => 20,
'E' => 20,
'F' => 25,
];
}
public function styles(Worksheet $sheet): array
{
// Merge header label cells for the title section
$sheet->mergeCells('B1:F1');
$sheet->mergeCells('B2:F2');
$sheet->mergeCells('B3:F3');
$sheet->mergeCells('B4:F4');
// BOQ title row
$sheet->mergeCells('A6:F6');
$sheet->getStyle('A6')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
return [
// Header labels (A1:A4)
'A1:A4' => [
'font' => ['bold' => true, 'size' => 11],
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => ['argb' => 'FFD9E1F2'],
],
],
// BOQ title row
6 => [
'font' => ['bold' => true, 'size' => 14, 'color' => ['argb' => 'FFFFFFFF']],
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => ['argb' => 'FF2F5496'],
],
],
// Detail table header (row 7)
7 => [
'font' => ['bold' => true, 'size' => 10],
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => ['argb' => 'FFFFFF00'],
],
'borders' => [
'allBorders' => ['borderStyle' => Border::BORDER_THIN],
],
],
// Sample data rows
'8:10' => [
'fill' => [
'fillType' => Fill::FILL_SOLID,
'startColor' => ['argb' => 'FFFFFFCC'],
],
'borders' => [
'allBorders' => ['borderStyle' => Border::BORDER_THIN],
],
],
];
}
}