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

@@ -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);