1
0
forked from poc/pds

Enhance production order validation to require numeric values with 7 to 14 digits across multiple resources

This commit is contained in:
dhanabalan
2025-08-04 19:35:50 +05:30
parent 68d4240ab0
commit d6c77bd6c3
5 changed files with 164 additions and 101 deletions

View File

@@ -319,8 +319,10 @@ class ProductionQuantityResource extends Resource
->label('Production Order')
->reactive()
->required()
->minLength(7)
->maxLength(14)
->columnSpan(2)
// ->rules(['regex:/^[1-9][0-9]{6,}$/'])
//->rules(['regex:/^[1-9][0-9]{6,}$/'])
// ->disabled(function ($get) {
// return $get('item_code');
// })
@@ -332,15 +334,35 @@ class ProductionQuantityResource extends Resource
return $latestProduction ? $latestProduction->production_order : null;
})
->afterStateUpdated(function ($state, callable $get, callable $set): void {
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', null);
return;
// if (empty($state)) {
// }
}),
if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
{
$set('item_code', null);
$set('item_id', null);
$set('serial_number', null);
$set('production_order', null);
$set('prodOrdError', "Must be a numeric value with 7 to 14 digits.");
$set('validationError', null);
return;
}
else
{
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('production_order', $state);
$set('prodOrdError', null);
$set('validationError', null);
return;
// if (empty($state)) {
// }
}
})
->extraAttributes(fn ($get) => [
'class' => $get('prodOrdError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('prodOrdError') ? $get('prodOrdError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('item_code')
->label('Item Code')
// ->required()

View File

@@ -335,7 +335,7 @@ class CreateProductionQuantity extends CreateRecord
->send();
return;
}
else if (!preg_match('/^[1-9][0-9]{6,}$/', $this->prodOrder))
else if (!preg_match('/^[1-9][0-9]{6,13}$/', $this->prodOrder))
{
$this->form->fill([
'plant_id'=> $this->pId,
@@ -354,7 +354,7 @@ class CreateProductionQuantity extends CreateRecord
Notification::make()
->title('Invalid Production Order')
->body("Must contain at least 7 digits.<br>Must start with a non-zero digit.")
->body("Must be a numeric value with 7 to 14 digits.<br>Must start with a non-zero digit.")
->danger()
->seconds(2)
->send();

View File

@@ -127,31 +127,31 @@ class QualityValidationResource extends Resource
Forms\Components\TextInput::make('production_order')
->placeholder('Scan the valid Production Order')
->minLength(7)
->maxLength(14)
->reactive()
->readOnly(fn (callable $get) => $get('item_id'))
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
if(!is_numeric($get('production_order')))
if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
{
$set('productionError', "Must be a numeric value.");
$set('prodOrdError', "Must be a numeric value with 7 to 14 digits.");
$set('production_order', null);
$set('item_id', null);
$set('sticker_master_id', null);
$set('uom', null);
$set('serial_number', null);
return;
}
else
{
$set('productionError', null);
$set('prodOrdError', null);
$set('production_order', $state);
$set('production', $state);
}
})
->default(fn ($get) => $get('production') ?? session('last_selected_production'))
->extraAttributes(fn ($get) => [
'class' => $get('productionError') ? 'border-red-500' : '',
'class' => $get('prodOrdError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('productionError') ? $get('productionError') : null)
->hint(fn ($get) => $get('prodOrdError') ? $get('prodOrdError') : null)
->hintColor('danger')
->required(),
@@ -187,11 +187,12 @@ class QualityValidationResource extends Resource
$pOrder = $get('production_order');
if (!$pOrder)
{
$set('productionError', 'Production Order cant be empty.');
$set('prodOrdError', "Production Order can't be empty.");
$set('production_order', null);
}
else
{
$set('productionError', null);
$set('prodOrdError', null);
}
$serialFields = [
@@ -333,9 +334,9 @@ class QualityValidationResource extends Resource
$set('serial_number', null);
return;
}
elseif(!is_numeric($get('production_order')))
else if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
{
$set('productionError', "Must be a numeric value.");
$set('prodOrdError', "Must be a numeric value.");
$set('item_id', null);
$set('sticker_master_id', null);
$set('uom', null);