1
0
forked from poc/pds

Loading foreign key value while update for productionQuantity

This commit is contained in:
dhanabalan
2025-04-01 16:19:32 +05:30
parent a838faf5d0
commit 7cd0db415c

View File

@@ -8,6 +8,7 @@ use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
use App\Models\ProductionQuantity;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -37,6 +38,7 @@ class ProductionQuantityResource extends Resource
->required()
// ->nullable()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
@@ -71,8 +73,20 @@ class ProductionQuantityResource extends Resource
->reactive()
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
$getShift = ProductionQuantity::where('id', $get('id'))->first();
$getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
$set('block_name', $getBlock->block_id);
$set('pqBlockError', null);
}
}
$blockId = $get('block_name');
$set('shift_id', null);
if (!$blockId) {
$set('pqBlockError', 'Please select a block first.');
return;
@@ -105,8 +119,19 @@ class ProductionQuantityResource extends Resource
->reactive()
->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
$getShift = ProductionQuantity::where('id', $get('id'))->first();
if($getShift->shift_id)
{
$set('shift_id', $getShift->shift_id);
$set('pqShiftError', null);
}
}
$shiftId = $get('shift_id');
$set('line_id', null);
if (!$shiftId) {
$set('pqShiftError', 'Please select a shift first.');
return;
@@ -142,7 +167,18 @@ class ProductionQuantityResource extends Resource
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
$getShift = ProductionQuantity::where('id', $get('id'))->first();
if($getShift->line_id)
{
$set('line_id', $getShift->line_id);
$set('pqLineError', null);
}
}
$lineId = $get('line_id');
$set('item_code', null);
if (!$lineId) {
$set('pqLineError', 'Please select a line first.');
@@ -397,6 +433,9 @@ class ProductionQuantityResource extends Resource
->readOnly(true)
->autocapitalize('serial_number'),
//->columnSpanFull(),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);