Merge pull request 'Added production plan export in production target page' (#174) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #174
This commit was merged in pull request #174.
This commit is contained in:
61
app/Exports/ProductionPlanExport.php
Normal file
61
app/Exports/ProductionPlanExport.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ProductionPlanExport implements FromArray, WithHeadings, WithMapping
|
||||
{
|
||||
|
||||
protected array $data;
|
||||
protected array $dates;
|
||||
|
||||
public function __construct(array $data, array $dates)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user