diff --git a/app/Filament/Resources/ProductionQuantityResource.php b/app/Filament/Resources/ProductionQuantityResource.php index e04896e..9f83b0f 100644 --- a/app/Filament/Resources/ProductionQuantityResource.php +++ b/app/Filament/Resources/ProductionQuantityResource.php @@ -298,6 +298,7 @@ class ProductionQuantityResource extends Resource ->reactive() ->required() ->columnSpan(2) + // ->rules(['regex:/^[1-9][0-9]{6,}$/']) ->disabled(function ($get) { return $get('item_code'); }) @@ -306,6 +307,16 @@ class ProductionQuantityResource extends Resource // return $latestProductionOrder ?? null; $latestProduction = ProductionQuantity::latest()->first(); 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)) { + // } }), Forms\Components\TextInput::make('item_code') ->label('Item Code') @@ -382,6 +393,49 @@ class ProductionQuantityResource extends Resource ->send(); return; } + else if (!$get('production_order')) { + $set('item_code', null); + $set('item_id', null); + // $set('item_description', null); + $set('serial_number', null); + $set('validationError', 'Please scan the production order first.'); + Notification::make() + ->title('Scan the production order first.') + ->danger() + ->send(); + return; + } + + if(!is_numeric($get('production_order'))) + { + $set('item_code', null); + $set('item_id', null); + // $set('item_description', null); + $set('serial_number', null); + $set('validationError', 'Please scan the valid production order.'); + + Notification::make() + ->title('Invalid Production Order') + ->body("Must contain numeric values only.") + ->danger() + ->send(); + return; + } + else if (!preg_match('/^[1-9][0-9]{6,}$/', $get('production_order'))) + { + $set('item_code', null); + $set('item_id', null); + // $set('item_description', null); + $set('serial_number', null); + $set('validationError', 'Please scan the valid production order first.'); + + Notification::make() + ->title('Invalid Production Order') + ->body("Must contain at least 7 digits.
Must start with a non-zero digit.") + ->danger() + ->send(); + return; + } // ********************************