data = $data; $this->dates = $dates; } public function array(): array { return $this->data; } public function headings(): array { $headings = [ 'Plant Name', 'Line Name', 'Item Code', ]; // Add dynamic headings for each date: Target / Produced foreach ($this->dates as $date) { $headings[] = $date . ' - Target Plan'; $headings[] = $date . ' - Produced Quantity'; } return $headings; } public function map($row): array { $mapped = [ $row['plant_name'] ?? '', $row['line_name'] ?? '', $row['item_code'] ?? '', ]; // Add daily target and produced quantity for each date foreach ($this->dates as $date) { $mapped[] = $row['daily_target'] ?? 0; $mapped[] = $row['produced_quantity'][$date] ?? 0; } return $mapped; } }