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

@@ -320,23 +320,44 @@ class ProductionQuantityPage extends Page implements HasForms
->hintColor('danger'), ->hintColor('danger'),
TextInput::make('production_order') TextInput::make('production_order')
->label('Production Order') ->label('Production Order')
->reactive() ->reactive()
->required() ->required()
//->columnSpan(1) ->minLength(7)
->columnSpan(['default' => 1, 'sm' => 1]) ->maxLength(14)
->afterStateUpdated(function ($state, callable $get, callable $set): void { //->columnSpan(1)
$set('item_code', null); ->columnSpan(['default' => 1, 'sm' => 1])
$set('item_id', null); ->afterStateUpdated(function ($state, callable $get, callable $set): void {
// $set('item_description', null); if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
$set('serial_number', null); {
$set('validationError', null); $set('productionError', "Must be a numeric value with 7 to 14 digits.");
$this->prodOrder = $state; $set('production_order', null);
$set('item_code', null);
return; $set('item_id', null);
// if (empty($state)) { // $set('item_description', null);
// } $set('serial_number', null);
}), $set('validationError', null);
$this->prodOrder = null;
}
else
{
$set('productionError', null);
$set('production_order', $state);
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$set('validationError', null);
$this->prodOrder = $state;
// if (empty($state)) {
// }
}
})
->extraAttributes(fn ($get) => [
'class' => $get('productionError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('productionError') ? $get('productionError') : null)
->hintColor('danger'),
// TextInput::make('item_code') // TextInput::make('item_code')
// ->label('Item Code') // ->label('Item Code')
@@ -592,7 +613,7 @@ class ProductionQuantityPage extends Page implements HasForms
->send(); ->send();
return; 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([ $this->form->fill([
'plant_id'=> $this->pId, 'plant_id'=> $this->pId,
@@ -611,7 +632,7 @@ class ProductionQuantityPage extends Page implements HasForms
Notification::make() Notification::make()
->title('Invalid Production Order') ->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() ->danger()
->send(); ->send();
return; return;

View File

@@ -313,23 +313,40 @@ class StickerReprint extends Page implements HasForms
TextInput::make('production_order') TextInput::make('production_order')
->label('Production Order') ->label('Production Order')
->minLength(7)
->maxLength(14)
->reactive() ->reactive()
//->required() //->required()
//->columnSpan(1) //->columnSpan(1)
->columnSpan(['default' => 1, 'sm' => 1]) ->columnSpan(['default' => 1, 'sm' => 1])
->afterStateUpdated(function ($state, callable $get, callable $set): void { ->afterStateUpdated(function ($state, callable $get, callable $set): void {
$set('item_code', null); if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
$set('item_id', null); {
// $set('item_description', null); $set('productionError', "Must be a numeric value with 7 to 14 digits.");
$set('serial_number', null); $set('production_order', null);
$set('validationError', null); $set('item_code', null);
$this->prodOrder = $state; $set('item_id', null);
$set('serial_number', null);
return; $this->prodOrder = null;
// if (empty($state)) { }
// } else
}), {
$set('productionError', null);
$set('production_order', $state);
$set('item_code', null);
$set('item_id', null);
// $set('item_description', null);
$set('serial_number', null);
$this->prodOrder = $state;
// if (empty($state)) {
// }
}
})
->extraAttributes(fn ($get) => [
'class' => $get('productionError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('productionError') ? $get('productionError') : null)
->hintColor('danger'),
// TextInput::make('item_code') // TextInput::make('item_code')
// ->label('Item Code') // ->label('Item Code')
// ->columnSpan(1) // ->columnSpan(1)
@@ -565,55 +582,57 @@ class StickerReprint extends Page implements HasForms
// ->send(); // ->send();
// return; // return;
// } // }
else if ($this->prodOrder)
{
if(!is_numeric($this->prodOrder))
{
$this->form->fill([
'plant_id'=> $this->pId,
'block_name'=> $this->bId,
'shift_id'=> $this->sId,
'line_id'=> $this->lId,
'item_id'=> null,
'serial_number'=> null,
'success_msg'=> null,
'production_order'=> null,
'sap_msg_status' => null,
'sap_msg_description' => null,
'operator_id'=> $operatorName,
'recent_qr' => $this->recQr,
]);
// if(!is_numeric($this->prodOrder)) Notification::make()
// { ->title('Invalid Production Order')
// $this->form->fill([ ->body("Must contain numeric values only.")
// 'plant_id'=> $this->pId, ->danger()
// 'block_name'=> $this->bId, ->send();
// 'shift_id'=> $this->sId, return;
// 'line_id'=> $this->lId, }
// 'item_id'=> null, else if (!preg_match('/^[1-9][0-9]{6,13}$/', $this->prodOrder))
// 'serial_number'=> null, {
// 'success_msg'=> null, $this->form->fill([
// 'production_order'=> null, 'plant_id'=> $this->pId,
// 'sap_msg_status' => null, 'block_name'=> $this->bId,
// 'sap_msg_description' => null, 'shift_id'=> $this->sId,
// 'operator_id'=> $operatorName, 'line_id'=> $this->lId,
// 'recent_qr' => $this->recQr, 'item_id'=> null,
// ]); 'serial_number'=> null,
'success_msg'=> null,
'production_order'=> null,
'sap_msg_status' => null,
'sap_msg_description' => null,
'operator_id'=> $operatorName,
'recent_qr' => $this->recQr,
]);
// Notification::make() Notification::make()
// ->title('Invalid Production Order') ->title('Invalid Production Order')
// ->body("Must contain numeric values only.") ->body("Must be a numeric value with 7 to 14 digits.<br>Must start with a non-zero digit.")
// ->danger() ->danger()
// ->send(); ->send();
// return; return;
// } }
// else if (!preg_match('/^[1-9][0-9]{6,}$/', $this->prodOrder)) }
// {
// $this->form->fill([
// 'plant_id'=> $this->pId,
// 'block_name'=> $this->bId,
// 'shift_id'=> $this->sId,
// 'line_id'=> $this->lId,
// 'item_id'=> null,
// 'serial_number'=> null,
// 'success_msg'=> null,
// 'production_order'=> null,
// 'sap_msg_status' => null,
// 'sap_msg_description' => null,
// 'operator_id'=> $operatorName,
// 'recent_qr' => $this->recQr,
// ]);
// Notification::make()
// ->title('Invalid Production Order')
// ->body("Must contain at least 7 digits.<br>Must start with a non-zero digit.")
// ->danger()
// ->send();
// return;
// }
// ******************************** // ********************************

View File

@@ -319,8 +319,10 @@ class ProductionQuantityResource extends Resource
->label('Production Order') ->label('Production Order')
->reactive() ->reactive()
->required() ->required()
->minLength(7)
->maxLength(14)
->columnSpan(2) ->columnSpan(2)
// ->rules(['regex:/^[1-9][0-9]{6,}$/']) //->rules(['regex:/^[1-9][0-9]{6,}$/'])
// ->disabled(function ($get) { // ->disabled(function ($get) {
// return $get('item_code'); // return $get('item_code');
// }) // })
@@ -332,15 +334,35 @@ class ProductionQuantityResource extends Resource
return $latestProduction ? $latestProduction->production_order : null; return $latestProduction ? $latestProduction->production_order : null;
}) })
->afterStateUpdated(function ($state, callable $get, callable $set): void { ->afterStateUpdated(function ($state, callable $get, callable $set): void {
$set('item_code', null); if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
$set('item_id', null); {
// $set('item_description', null); $set('item_code', null);
$set('serial_number', null); $set('item_id', null);
$set('validationError', null); $set('serial_number', null);
return; $set('production_order', null);
// if (empty($state)) { $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') Forms\Components\TextInput::make('item_code')
->label('Item Code') ->label('Item Code')
// ->required() // ->required()

View File

@@ -335,7 +335,7 @@ class CreateProductionQuantity extends CreateRecord
->send(); ->send();
return; 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([ $this->form->fill([
'plant_id'=> $this->pId, 'plant_id'=> $this->pId,
@@ -354,7 +354,7 @@ class CreateProductionQuantity extends CreateRecord
Notification::make() Notification::make()
->title('Invalid Production Order') ->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() ->danger()
->seconds(2) ->seconds(2)
->send(); ->send();

View File

@@ -127,31 +127,31 @@ class QualityValidationResource extends Resource
Forms\Components\TextInput::make('production_order') Forms\Components\TextInput::make('production_order')
->placeholder('Scan the valid Production Order') ->placeholder('Scan the valid Production Order')
->minLength(7) ->minLength(7)
->maxLength(14)
->reactive() ->reactive()
->readOnly(fn (callable $get) => $get('item_id')) ->readOnly(fn (callable $get) => $get('item_id'))
->afterStateUpdated(function (callable $set, callable $get, ?string $state) { ->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('production_order', null);
$set('item_id', null); $set('item_id', null);
$set('sticker_master_id', null); $set('sticker_master_id', null);
$set('uom', null); $set('uom', null);
$set('serial_number', null); $set('serial_number', null);
return;
} }
else else
{ {
$set('productionError', null); $set('prodOrdError', null);
$set('production_order', $state);
$set('production', $state); $set('production', $state);
} }
}) })
->default(fn ($get) => $get('production') ?? session('last_selected_production')) ->default(fn ($get) => $get('production') ?? session('last_selected_production'))
->extraAttributes(fn ($get) => [ ->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') ->hintColor('danger')
->required(), ->required(),
@@ -187,11 +187,12 @@ class QualityValidationResource extends Resource
$pOrder = $get('production_order'); $pOrder = $get('production_order');
if (!$pOrder) if (!$pOrder)
{ {
$set('productionError', 'Production Order cant be empty.'); $set('prodOrdError', "Production Order can't be empty.");
$set('production_order', null);
} }
else else
{ {
$set('productionError', null); $set('prodOrdError', null);
} }
$serialFields = [ $serialFields = [
@@ -333,9 +334,9 @@ class QualityValidationResource extends Resource
$set('serial_number', null); $set('serial_number', null);
return; 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('item_id', null);
$set('sticker_master_id', null); $set('sticker_master_id', null);
$set('uom', null); $set('uom', null);