Merge pull request 'Added production non plan export page' (#1221) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #1221
This commit was merged in pull request #1221.
This commit is contained in:
2026-10-12 08:39:34 +00:00

View File

@@ -0,0 +1,102 @@
<?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);
},
];
}
}