1
0
forked from poc/pds

Added production_order, operate_id column and skip insert when invalid plant-line-shift-item on import

This commit is contained in:
dhanabalan
2025-04-28 00:18:03 +05:30
parent 9aacf25eb5
commit a275e18d0b

View File

@@ -21,12 +21,12 @@ class ProductionQuantityImporter extends Importer
->example('12-02-2025 15:51:00')
->label('Created DateTime')
->rules(['required']),
// ImportColumn::make('hourly_quantity')
// ->requiredMapping()
// ->exampleHeader('Hourly Quantity')
// ->label('Hourly Quantity')
// ->numeric()
// ->rules(['required', 'integer']),
ImportColumn::make('production_order')
->requiredMapping()
->exampleHeader('Production Order')
->example('1234567')
->label('Production Order')
->numeric(),
ImportColumn::make('item')
->requiredMapping()
->exampleHeader('Item Code')
@@ -67,17 +67,44 @@ class ProductionQuantityImporter extends Importer
->example('12-02-2025 15:51:00')
->label('Updated DateTime')
->rules(['required']),
ImportColumn::make('operator_id')
->requiredMapping()
->exampleHeader('Operator ID')
->example('admin')
->label('Operator ID')
->rules(['required']),
];
}
public function resolveRecord(): ?ProductionQuantity
{
$plant = \App\Models\Plant::where('name', $this->data['plant'])->first();
$item = \App\Models\Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
$line = \App\Models\Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
$shift = \App\Models\Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->first();
if (!$plant || !$item || !$line || !$shift) {
// Optionally handle missing plant/item/line/shift
return null;
}
return ProductionQuantity::updateOrCreate([
'serial_number' => $this->data['serial_number'],
'plant_id' => $plant->id,
],
[
'shift_id' => $shift->id,
'line_id' => $line->id,
'item_id' => $item->id,
'production_order' => $this->data['production_order'] ?? null,
'created_at' => $this->data['created_at'],
'updated_at' => $this->data['updated_at']
]
);
// return ProductionQuantity::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
return new ProductionQuantity();
// return new ProductionQuantity();
}
public static function getCompletedNotificationBody(Import $import): string