Added validation for process order with item code #64
@@ -144,6 +144,34 @@ class ProcessOrderResource extends Resource
|
||||
$set('sfgNumberError', null);
|
||||
}
|
||||
})
|
||||
->rule(function (callable $get) {
|
||||
return function (string $attribute, $value, \Closure $fail) use ($get) {
|
||||
|
||||
$plantId = $get('plant_id');
|
||||
$itemId = $get('item_id');
|
||||
$processOrder = $value;
|
||||
//$currentId = $get('id'); // current editing record id
|
||||
|
||||
if (! $plantId || ! $processOrder) {
|
||||
return;
|
||||
}
|
||||
|
||||
$existing = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('item_id', '!=', $itemId)
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
|
||||
Notification::make()
|
||||
->title('Duplicate Process Order!')
|
||||
->body("Process Order '{$value}' is already exist with item code '{$existing->item->code}'.")
|
||||
->danger()
|
||||
->send();
|
||||
$fail("process order already exists for this plant and item code '{$existing->item->code}'.");
|
||||
}
|
||||
};
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('coil_number')
|
||||
->label('Coil Number')
|
||||
|
||||
Reference in New Issue
Block a user