Added production_order, operate_id column and skip insert when invalid plant-line-shift-item on import
This commit is contained in:
@@ -21,12 +21,12 @@ class ProductionQuantityImporter extends Importer
|
|||||||
->example('12-02-2025 15:51:00')
|
->example('12-02-2025 15:51:00')
|
||||||
->label('Created DateTime')
|
->label('Created DateTime')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
// ImportColumn::make('hourly_quantity')
|
ImportColumn::make('production_order')
|
||||||
// ->requiredMapping()
|
->requiredMapping()
|
||||||
// ->exampleHeader('Hourly Quantity')
|
->exampleHeader('Production Order')
|
||||||
// ->label('Hourly Quantity')
|
->example('1234567')
|
||||||
// ->numeric()
|
->label('Production Order')
|
||||||
// ->rules(['required', 'integer']),
|
->numeric(),
|
||||||
ImportColumn::make('item')
|
ImportColumn::make('item')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Item Code')
|
->exampleHeader('Item Code')
|
||||||
@@ -67,17 +67,44 @@ class ProductionQuantityImporter extends Importer
|
|||||||
->example('12-02-2025 15:51:00')
|
->example('12-02-2025 15:51:00')
|
||||||
->label('Updated DateTime')
|
->label('Updated DateTime')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
|
ImportColumn::make('operator_id')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Operator ID')
|
||||||
|
->example('admin')
|
||||||
|
->label('Operator ID')
|
||||||
|
->rules(['required']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolveRecord(): ?ProductionQuantity
|
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([
|
// return ProductionQuantity::firstOrNew([
|
||||||
// // Update existing records, matching them by `$this->data['column_name']`
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
// 'email' => $this->data['email'],
|
// 'email' => $this->data['email'],
|
||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
return new ProductionQuantity();
|
// return new ProductionQuantity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
|
|||||||
Reference in New Issue
Block a user