init project

This commit is contained in:
2026-05-25 11:08:52 +07:00
parent a388c619b5
commit 895fdd9b83
1437 changed files with 384844 additions and 27 deletions

View File

@@ -0,0 +1,158 @@
<?php
namespace App\Exports;
use App\Enums\ExcelDesignEnum;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use App\Helpers\Helpers;
class FinancialReportExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
{
use Exportable;
protected array $data;
protected array $headingTitle;
protected string $sheet;
protected string $title;
public function __construct($data)
{
$this->data = $data;
}
public function array(): array
{
return $this->data;
}
public function title(): string
{
return 'Fianancial-Report';
}
public function startCell(): string
{
return 'A3';
}
public function setTitleHeadingTable($data): array
{
return $this->headingTitle = $data;
}
public function setTitle($title){
$this->title = $title;
}
public function registerEvents(): array
{
return [
AfterSheet::class => function (AfterSheet $event) {
$sheet = $event->sheet->getDelegate();
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
$bgGrandTotal = [
'fill' => [
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
'color' => [
'rgb' => 'd9d9d9',
]
],
'font' => [
'bold' => true,
]
];
$alignmentCenter = [
'alignment' => [
'horizontal' => 'center'
]
];
$alignmentLeft = [
'alignment' => [
'horizontal' => 'left',
]
];
$borderAll = [
'borders' => [
'allBorders' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['rgb' => '000000'],
],
]
];
$outBorder = [
'borders' => [
'outline' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'color' => ['rgb' => '000000'],
],
]
];
$textBold = [
'font' => [
'bold' => true,
'size' => 11,
],
];
$title = $this->title;
$columns = count($this->headingTitle);
$rows = count($this->data) + 2;
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
for($i = 1; $i<=$columns; $i++){
$nameCell = Coordinate::stringFromColumnIndex($i);
$sheet->getColumnDimension($nameCell)->setWidth(21);
}
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
$sheet->mergeCells("A1:$lastColumnString".'1');
$sheet->setCellValue('A1',$title);
foreach ($this->headingTitle as $key => $value){
$cellColumn = $key + 1;
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
$sheet->setCellValue($cellColumnName.'2', $value);
}
$sheet->getStyle("A".($rows+1).":G".($rows+1))->applyFromArray($alignmentCenter);
$sheet->mergeCells("A".($rows+1).":G".($rows+1));
$sheet->setCellValue('A'.($rows+1), 'Total');
$sheet->setCellValue('H'.($rows+1), '=SUM(H3:H'.($rows).')');
$sheet->setCellValue('I'.($rows+1), '=SUM(I3:I'.($rows).')');
$sheet->setCellValue('J'.($rows+1), '=SUM(J3:J'.($rows).')');
$sheet->setCellValue('K'.($rows+1), '=SUM(K3:K'.($rows).')');
$sheet->setCellValue('L'.($rows+1), '=SUM(L3:L'.($rows).')');
$sheet->setCellValue('M'.($rows+1), '=SUM(M3:M'.($rows).')');
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
$sheet->getRowDimension(1)->setRowHeight(28);
$sheet->getStyle("A1")->applyFromArray($textBold);
$sheet->getRowDimension(2)->setRowHeight(25);
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
}
];
}
}