After Production Quantity and Overall Validation
This commit is contained in:
@@ -15,6 +15,7 @@ use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
|
||||
class ItemResource extends Resource
|
||||
{
|
||||
@@ -24,26 +25,106 @@ class ItemResource extends Resource
|
||||
|
||||
protected static ?string $navigationGroup = 'Master Entries';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required(),
|
||||
// ->nullable(),
|
||||
Forms\Components\TextInput::make('code')
|
||||
->required()
|
||||
->unique(ignoreRecord: true)
|
||||
->minLength(6)
|
||||
->autocapitalize('code'),
|
||||
Forms\Components\TextInput::make('hourly_quantity')
|
||||
->required()
|
||||
->numeric()
|
||||
->minValue(1),
|
||||
Forms\Components\Textarea::make('description')
|
||||
->required(),
|
||||
// ->columnSpanFull(),
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
// ->nullable(),
|
||||
->reactive()
|
||||
// ->afterStateUpdated(fn ($set) => $set('block_id', null) & $set('name', null) & $set('start_time', null) & $set('duration', null) & $set('end_time', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$plantId) {
|
||||
$set('iPlantError', 'Please select a plant first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('iPlantError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('iPlantError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('iPlantError') ? $get('iPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('code')
|
||||
->required()
|
||||
->placeholder('Scan the valid code')
|
||||
->unique(ignoreRecord: true)
|
||||
->alphaNum()
|
||||
->minLength(6)
|
||||
// ->autocapitalize('characters')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$code = $get('code');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$code) {
|
||||
$set('iCodeError', 'Scan the valid code.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen($code) < 6) {
|
||||
$set('iCodeError', 'Item code must be at least 6 digits.');
|
||||
return;
|
||||
}
|
||||
else if (!preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) {
|
||||
$set('code',null);
|
||||
$set('iCodeError', 'Item code must contain only alpha-numeric characters.');
|
||||
return;
|
||||
}
|
||||
$set('iCodeError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('iCodeError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('iCodeError') ? $get('iCodeError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('hourly_quantity')
|
||||
->required()
|
||||
->label('Hourly Quantity')
|
||||
->placeholder('Scan the valid quantity')
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$hourQuan = $get('hourly_quantity');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$hourQuan) {
|
||||
$set('iHourQuanError', 'Scan the valid hourly quantity.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!preg_match('/^[0-9]{1,}$/', $hourQuan)) {
|
||||
$set('hourly_quantity',null);
|
||||
$set('iHourQuanError', 'Quantity must be integer value.');
|
||||
return;
|
||||
}
|
||||
$set('iHourQuanError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('iHourQuanError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('iHourQuanError') ? $get('iHourQuanError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Textarea::make('description')
|
||||
->required()
|
||||
->placeholder('Scan the valid description'),
|
||||
// ->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user