From 8b8e89ba5dfa3f5b2a3fa8a479e6f87435eae297 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 12 Oct 2026 14:09:14 +0530 Subject: [PATCH] Added production non plan export page --- app/Exports/ProductionNonPlanExport.php | 102 ++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 app/Exports/ProductionNonPlanExport.php diff --git a/app/Exports/ProductionNonPlanExport.php b/app/Exports/ProductionNonPlanExport.php new file mode 100644 index 00000000..e484eae2 --- /dev/null +++ b/app/Exports/ProductionNonPlanExport.php @@ -0,0 +1,102 @@ +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); + }, + ]; + } +}