Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 17s
Laravel Pint / pint (pull_request) Successful in 3m53s
Laravel Larastan / larastan (pull_request) Failing after 4m23s
103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\FromArray;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
|
use Maatwebsite\Excel\Events\AfterSheet;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class ProductionNonPlanExport implements FromArray, WithHeadings, WithMapping, WithCustomStartCell, WithEvents
|
|
{
|
|
protected array $data;
|
|
protected string $startDate;
|
|
protected string $endDate;
|
|
|
|
public function __construct(array $data, string $startDate, string $endDate)
|
|
{
|
|
$this->data = $data;
|
|
$this->startDate = $startDate;
|
|
$this->endDate = $endDate;
|
|
}
|
|
|
|
public function array(): array
|
|
{
|
|
return $this->data;
|
|
}
|
|
|
|
public function startCell(): string
|
|
{
|
|
// Headings start on row 2
|
|
return 'A2';
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
$headings = [
|
|
'Plant Name',
|
|
'Line Name',
|
|
'Item Code',
|
|
'Category',
|
|
'Non Planned Production',
|
|
];
|
|
|
|
return $headings;
|
|
}
|
|
|
|
public function map($row): array
|
|
{
|
|
$mapped = [
|
|
$row['plant_name'] ?? '',
|
|
$row['line_name'] ?? '',
|
|
$row['item_code'] ?? '',
|
|
$row['item_category'] ?? '',
|
|
$row['total_qty'] ?? '',
|
|
];
|
|
return $mapped;
|
|
}
|
|
|
|
public function registerEvents(): array
|
|
{
|
|
return [
|
|
AfterSheet::class => function (AfterSheet $event) {
|
|
$sheet = $event->sheet->getDelegate();
|
|
|
|
$start = Carbon::parse($this->startDate)
|
|
->format('d-m-Y h:i:s A');
|
|
|
|
$end = Carbon::parse($this->endDate)
|
|
->format('d-m-Y h:i:s A');
|
|
|
|
// First row: merge five columns
|
|
$sheet->mergeCells('A1:E1');
|
|
|
|
$sheet->setCellValue(
|
|
'A1',
|
|
"Report date from {$start} to {$end}"
|
|
);
|
|
|
|
// Style report title
|
|
$sheet->getStyle('A1:E1')->applyFromArray([
|
|
'font' => [
|
|
'bold' => true,
|
|
'size' => 12,
|
|
],
|
|
'alignment' => [
|
|
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
|
|
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
|
|
],
|
|
]);
|
|
|
|
$sheet->getRowDimension(1)->setRowHeight(25);
|
|
|
|
// Style headings
|
|
$sheet->getStyle('A2:E2')->getFont()->setBold(true);
|
|
},
|
|
];
|
|
}
|
|
}
|