After Production Quantity and Overall Validation
This commit is contained in:
@@ -14,6 +14,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 ProductionPlanResource extends Resource
|
||||
{
|
||||
@@ -29,65 +30,162 @@ class ProductionPlanResource extends Resource
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
->nullable()
|
||||
->reactive(),
|
||||
Forms\Components\Select::make('block_name')
|
||||
->required()
|
||||
->nullable()
|
||||
->reactive()
|
||||
->afterStateUpdated(fn ($set) => $set('shift_id', null)),
|
||||
Forms\Components\Select::make('shift_id')
|
||||
->relationship('shift', 'name')
|
||||
->required()
|
||||
->nullable()
|
||||
// ->options(fn (callable $get) =>
|
||||
// \App\Models\Shift::where('plant_id', $get('plant_id'))
|
||||
// ->pluck('name', 'id')
|
||||
// ->toArray() // Convert collection to array
|
||||
// )
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
// ->nullable()
|
||||
->reactive()
|
||||
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
$set('block_name', null);
|
||||
if (!$plantId) {
|
||||
$set('ppPlantError', 'Please select a plant first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('ppPlantError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('ppPlantError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('ppPlantError') ? $get('ppPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('block_name')
|
||||
->required()
|
||||
// ->nullable()
|
||||
->label('Block')
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(fn ($set) => $set('line_id', null)),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->relationship('line', 'name')
|
||||
->required()
|
||||
->nullable()
|
||||
// ->options(fn (callable $get) =>
|
||||
// \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
// ->pluck('name', 'id')
|
||||
// ->toArray() // Convert collection to array
|
||||
// )
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
return \App\Models\Block::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
//->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$blockId = $get('block_name');
|
||||
$set('shift_id', null);
|
||||
if (!$blockId) {
|
||||
$set('ppBlockError', 'Please select a block first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('ppBlockError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('ppBlockError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('ppBlockError') ? $get('ppBlockError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('shift_id')
|
||||
->relationship('shift', 'name')
|
||||
->required()
|
||||
// ->nullable()
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id') || !$get('block_name')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
Forms\Components\TextInput::make('plan_quantity')
|
||||
->required()
|
||||
->numeric()
|
||||
->minValue(1),
|
||||
Forms\Components\TextInput::make('production_quantity')
|
||||
->required()
|
||||
->numeric()
|
||||
->readOnly()
|
||||
->default(0),
|
||||
return \App\Models\Shift::where('plant_id', $get('plant_id'))
|
||||
->where('block_id', $get('block_name'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$shiftId = $get('shift_id');
|
||||
$set('line_id', null);
|
||||
if (!$shiftId) {
|
||||
$set('ppShiftError', 'Please select a shift first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('ppShiftError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('ppShiftError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('ppShiftError') ? $get('ppShiftError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->relationship('line', 'name')
|
||||
->required()
|
||||
// ->nullable()
|
||||
// ->options(fn (callable $get) =>
|
||||
// \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
// ->pluck('name', 'id')
|
||||
// ->toArray() // Convert collection to array
|
||||
// )
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$lineId = $get('line_id');
|
||||
if (!$lineId) {
|
||||
$set('ppLineError', 'Please select a line first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('ppLineError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('ppLineError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('ppLineError') ? $get('ppLineError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('plan_quantity')
|
||||
->required()
|
||||
->integer()
|
||||
->label('Plan Quantity')
|
||||
->placeholder('Scan the valid quantity')
|
||||
->minValue(1)
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$planQuan = $get('plan_quantity');
|
||||
if (!$planQuan) {
|
||||
$set('ppPlanQuanError', 'Scan the valid plan quantity.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('ppPlanQuanError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('ppPlanQuanError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('ppPlanQuanError') ? $get('ppPlanQuanError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('production_quantity')
|
||||
->required()
|
||||
->integer()
|
||||
->label('Production Quantity')
|
||||
->readOnly()
|
||||
->default(0),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user