After Production Quantity and Overall Validation

This commit is contained in:
dhanabalan
2025-03-30 23:04:29 +05:30
parent e46f290fd1
commit 6e44b690f1
16 changed files with 1726 additions and 407 deletions

View File

@@ -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 ShiftResource extends Resource
{
@@ -23,56 +24,181 @@ class ShiftResource extends Resource
protected static ?string $navigationGroup = 'Master Entries';
protected static ?int $navigationSort = 4;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required()
->nullable()
->reactive()
->afterStateUpdated(fn ($set) => $set('block_id', null)), // Reset block_id when plant changes
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required()
->nullable()
// ->options(fn (callable $get) =>
// \App\Models\Block::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_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');
$set('block_id', null);
// Ensure `linestop_id` is not cleared
if (!$plantId) {
$set('sPlantError', 'Please select a plant first.');
return;
}
else
{
$set('sPlantError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sPlantError') ? $get('sPlantError') : null)
->hintColor('danger'),
Forms\Components\Select::make('block_id')
->relationship('block', 'name')
->required()
// ->nullable()
->reactive()
// ->options(fn (callable $get) =>
// \App\Models\Block::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(),
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\TimePicker::make('start_time')
->required()
->live()
->afterStateUpdated(fn (callable $set, callable $get, $state) =>
$set('end_time', self::calculateEndTime($state, $get('duration')))
),
Forms\Components\TextInput::make('duration')
->required()
->inputMode('decimal')
->minValue(0.01) // Minimum valid duration
->lazy()
->afterStateUpdated(fn (callable $set, callable $get, $state) =>
$set('end_time', self::calculateEndTime($get('start_time'), $state))
),
Forms\Components\TimePicker::make('end_time')
->required(),
// ->native(false),
return \App\Models\Block::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
// ->afterStateUpdated(fn ($set) => $set('name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$blockId = $get('block_id');
$set('name', null);
// Ensure `linestop_id` is not cleared
if (!$blockId) {
$set('sBlockError', 'Please select a block first.');
return;
}
else
{
$set('sBlockError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sBlockError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sBlockError') ? $get('sBlockError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('name')
->placeholder('Scan the valid name')
->required()
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('name');
$set('start_time', null);
// Ensure `linestop_id` is not cleared
if (!$nameId) {
$set('sNameError', 'Scan the valid name.');
return;
}
else
{
$set('sNameError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sNameError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sNameError') ? $get('sNameError') : null)
->hintColor('danger'),
Forms\Components\TimePicker::make('start_time')
->required()
->label('Start Time')
->live()
// ->afterStateUpdated(fn (callable $set, callable $get, $state) =>
// $set('end_time', self::calculateEndTime($state, $get('duration')))
// )
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('start_time');
// $set('duration', null);
$set('end_time', self::calculateEndTime($state, $get('duration')));
// Ensure `linestop_id` is not cleared
if (!$nameId) {
$set('sStartTimeError', 'Choose the valid start time.');
return;
}
else
{
$set('sStartTimeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sStartTimeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sStartTimeError') ? $get('sStartTimeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('duration')
->required()
->placeholder('Scan the valid duration')
->numeric()
->inputMode('decimal')
->minValue(0.01) // Minimum valid duration
->lazy()
// ->afterStateUpdated(fn (callable $set, callable $get, $state) =>
// $set('end_time', self::calculateEndTime($get('start_time'), $state))
// )
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$duration = $get('duration');
// $set('end_time', null);
$set('end_time', self::calculateEndTime($get('start_time'), $state));
// Ensure `linestop_id` is not cleared
if (!$duration) {
$set('sDurationError', 'Scan the valid duration.');
return;
}
else
{
$set('sDurationError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sDurationError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sDurationError') ? $get('sDurationError') : null)
->hintColor('danger'),
Forms\Components\TimePicker::make('end_time')
->required()
->label('End Time')
->readOnly()
// ->native(false),
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$endTime = $get('end_time');
$set('end_time', self::calculateEndTime($get('start_time'), $state));
// Ensure `linestop_id` is not cleared
if (!$endTime) {
$set('sEndTimeError', 'Choose the valid start time & duration.');
return;
}
else
{
$set('sEndTimeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('sEndTimeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('sEndTimeError') ? $get('sEndTimeError') : null)
->hintColor('danger'),
])
->columns(2),
]);