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

@@ -15,7 +15,7 @@ use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Carbon\Carbon;
use Filament\Forms\Components\Section;
class ProductionLineStopResource extends Resource
{
@@ -32,120 +32,218 @@ class ProductionLineStopResource 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('plsPlantError', 'Please select a plant first.');
return;
}
else
{
$set('plsPlantError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('plsPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('plsPlantError') ? $get('plsPlantError') : 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('plsBlockError', 'Please select a block first.');
return;
}
else
{
$set('plsBlockError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('plsBlockError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('plsBlockError') ? $get('plsBlockError') : null)
->hintColor('danger'),
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') || !$get('block_name')) {
return [];
}
return \App\Models\Line::where('plant_id', $get('plant_id'))
->pluck('name', 'id')
->toArray();
})
->reactive(),
// Forms\Components\Select::make('linestop_id')
// ->label('Line Stop Code')
// ->relationship('linestop', 'code')
// ->searchable()
// ->required()
// ->nullable()
// ->reactive(),
Forms\Components\Select::make('linestop_id')
->label('Line Stop Code')
// ->options(fn (callable $get) =>
// \App\Models\LineStop::where('id', $get('linestop_id'))
// ->pluck('code', 'id')
// )
->options(fn () => \App\Models\LineStop::pluck('code', 'id'))
->required()
->nullable()
// ->reactive()
->searchable()
->live(debounce: 500) // Enable live updates
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineStopId = $get('linestop_id'); // Get entered linestop_id
// // Get the block ID based on plant_id and block_name
// $block = \App\Models\Block::where('plant_id', $get('plant_id'))
// ->where('name', $get('block_name'))
// ->first();
// Ensure `linestop_id` is not cleared
if (!$lineStopId) {
$set('lineStop_reason', null);
return;
}
// if (!$block) {
// return [];
// }
// Check if item exists for the selected plant
$lineStop = \App\Models\LineStop::where('id', $lineStopId)
->where('id', $lineStopId)
->first();
// return \App\Models\Shift::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
// ->toArray();
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('plsShiftError', 'Please select a shift first.');
return;
}
else
{
$set('plsShiftError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('plsShiftError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('plsShiftError') ? $get('plsShiftError') : 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 [];
}
$set('lineStop_reason', $lineStop?->reason ?? null);
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('plsLineError', 'Please select a line first.');
return;
}
else
{
$set('plsLineError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('plsLineError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('plsLineError') ? $get('plsLineError') : null)
->hintColor('danger'),
// Forms\Components\Select::make('linestop_id')
// ->label('Line Stop Code')
// ->relationship('linestop', 'code')
// ->searchable()
// ->required()
// ->nullable()
// ->reactive(),
Forms\Components\Select::make('linestop_id')
->label('Line Stop Code')
// ->options(fn (callable $get) =>
// \App\Models\LineStop::where('id', $get('linestop_id'))
// ->pluck('code', 'id')
// )
->placeholder('Scan the valid code')
->options(fn () => \App\Models\LineStop::pluck('code', 'id'))
->required()
// ->nullable()
// ->reactive()
->searchable()
->live(debounce: 500) // Enable live updates
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineStopId = $get('linestop_id'); // Get entered linestop_id
}),
Forms\Components\TextInput::make('lineStop_reason')
->label('Line Stop Reason')
->required()
->reactive()
->readOnly(true),
Forms\Components\DateTimePicker::make('from_datetime')
->label('From DateTime')
->required()
->reactive()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set)
),
Forms\Components\DateTimePicker::make('to_datetime')
->label('To DateTime')
->required()
->reactive()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set) //self means it calling the function within the class
),
Forms\Components\TextInput::make('stop_hour')
->required()
// ->dehydrated(false) // Don't send to backend
->readOnly(true)
->numeric(),
Forms\Components\TextInput::make('stop_min')
->required()
// ->dehydrated(false)
->readOnly(true)
->numeric(),
// Ensure `linestop_id` is not cleared
if (!$lineStopId) {
$set('lineStop_reason', null);
return;
}
// Check if item exists for the selected plant
$lineStop = \App\Models\LineStop::where('id', $lineStopId)
->where('id', $lineStopId)
->first();
$set('lineStop_reason', $lineStop?->reason ?? null);
}),
Forms\Components\TextInput::make('lineStop_reason')
->label('Line Stop Reason')
->required()
->reactive()
->readOnly(true),
Forms\Components\DateTimePicker::make('from_datetime')
->label('From DateTime')
->required()
->reactive()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set)
),
Forms\Components\DateTimePicker::make('to_datetime')
->label('To DateTime')
->required()
->reactive()
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
self::updateStopDuration($get, $set) //self means it calling the function within the class
),
Forms\Components\TextInput::make('stop_hour')
->required()
->label( 'Stop Hour')
// ->dehydrated(false) // Don't send to backend
->readOnly(true)
->numeric(),
Forms\Components\TextInput::make('stop_min')
->required()
->label('Stop Minute')
// ->dehydrated(false)
->readOnly(true)
->numeric(),
])
->columns(2),
]);
}