1
0
forked from poc/pds

Loading foreign key value while update

This commit is contained in:
dhanabalan
2025-04-01 16:16:37 +05:30
parent 6160d91357
commit a8b34fe1f3
6 changed files with 207 additions and 212 deletions

View File

@@ -7,6 +7,7 @@ use App\Filament\Resources\BlockResource\Pages;
use App\Models\Block;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -58,6 +59,7 @@ class BlockResource extends Resource
// ->unique(ignoreRecord: true)
->required()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$nameId = $get('plant_id');
// Ensure `linestop_id` is not cleared
@@ -75,6 +77,9 @@ class BlockResource extends Resource
])
->hint(fn ($get) => $get('bPlantError') ? $get('bPlantError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Filament\Resources\ItemResource\Pages;
use App\Models\Item;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ExportAction;
@@ -38,6 +39,7 @@ class ItemResource extends Resource
->required()
// ->nullable(),
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->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');
@@ -64,6 +66,7 @@ class ItemResource extends Resource
->minLength(6)
// ->autocapitalize('characters')
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$code = $get('code');
// Ensure `linestop_id` is not cleared
@@ -123,6 +126,9 @@ class ItemResource extends Resource
->required()
->placeholder('Scan the valid description'),
// ->columnSpanFull(),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Filament\Resources\LineResource\RelationManagers;
use App\Models\Line;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -33,97 +34,101 @@ class LineResource extends Resource
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('lPlantError', 'Please select a plant first.');
return;
}
else
{
$set('lPlantError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('lPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('lPlantError') ? $get('lPlantError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('name')
->required()
->placeholder('Scan the valid name')
// ->unique(
// ignoreRecord: true,
// modifyRuleUsing: function (Unique $rule) {
// return $rule->where('plant_id', $this->data['plant_id']);
// }
// )
// ->rule(function () {
// return function ($attribute, $value, $fail) {
// $exists = Line::where('name', $value)
// ->where('plant_id', request()->input('plant_id'))
// ->exists();
// if ($exists) {
// $fail('The combination of name and plant ID must be unique.');
// }
// };
// })
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineNam = $get('name');
// Ensure `linestop_id` is not cleared
if (!$lineNam) {
$set('lNameError', 'Scan the valid name.');
return;
}
else
{
$exists = Line::where('name', $lineNam)
->where('plant_id', $get('plant_id'))
->exists();
if ($exists) {
$set('name', null);
$set('lNameError', 'The name has already been taken.');
// $set('lNameError', 'The combination of name and plant ID must be unique.');
->relationship('plant', 'name')
->required()
// ->nullable(),
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->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('lPlantError', 'Please select a plant first.');
return;
}
$set('lNameError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('lNameError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('lNameError') ? $get('lNameError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('type')
->required()
->placeholder('Scan the valid type')
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineTyp = $get('type');
// Ensure `linestop_id` is not cleared
if (!$lineTyp) {
$set('lTypeError', 'Scan the valid type.');
return;
}
else
{
$set('lTypeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('lTypeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('lTypeError') ? $get('lTypeError') : null)
->hintColor('danger'),
else
{
$set('lPlantError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('lPlantError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('lPlantError') ? $get('lPlantError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('name')
->required()
->placeholder('Scan the valid name')
// ->unique(
// ignoreRecord: true,
// modifyRuleUsing: function (Unique $rule) {
// return $rule->where('plant_id', $this->data['plant_id']);
// }
// )
// ->rule(function () {
// return function ($attribute, $value, $fail) {
// $exists = Line::where('name', $value)
// ->where('plant_id', request()->input('plant_id'))
// ->exists();
// if ($exists) {
// $fail('The combination of name and plant ID must be unique.');
// }
// };
// })
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineNam = $get('name');
// Ensure `linestop_id` is not cleared
if (!$lineNam) {
$set('lNameError', 'Scan the valid name.');
return;
}
else
{
$exists = Line::where('name', $lineNam)
->where('plant_id', $get('plant_id'))
->exists();
if ($exists) {
$set('name', null);
$set('lNameError', 'The name has already been taken.');
// $set('lNameError', 'The combination of name and plant ID must be unique.');
return;
}
$set('lNameError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('lNameError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('lNameError') ? $get('lNameError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('type')
->required()
->placeholder('Scan the valid type')
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineTyp = $get('type');
// Ensure `linestop_id` is not cleared
if (!$lineTyp) {
$set('lTypeError', 'Scan the valid type.');
return;
}
else
{
$set('lTypeError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('lTypeError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('lTypeError') ? $get('lTypeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Models\Plant;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Actions\ImportAction;
@@ -69,6 +70,7 @@ class PlantResource extends Resource
->relationship('company', 'name')
->required()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$companyId = $get('company_id');
// Ensure `linestop_id` is not cleared
@@ -132,6 +134,9 @@ class PlantResource extends Resource
])
->hint(fn ($get) => $get('pAddressError') ? $get('pAddressError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -8,6 +8,7 @@ use App\Models\Shift;
use Carbon\Carbon;
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 ShiftResource extends Resource
->required()
// ->nullable()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->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');
@@ -60,6 +62,7 @@ class ShiftResource extends Resource
->required()
// ->nullable()
->reactive()
->disabled(fn (Get $get) => !empty($get('id')))
// ->options(fn (callable $get) =>
// \App\Models\Block::where('plant_id', $get('plant_id'))
// ->pluck('name', 'id')
@@ -203,6 +206,9 @@ class ShiftResource extends Resource
])
->hint(fn ($get) => $get('sEndTimeError') ? $get('sEndTimeError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
])
->columns(2),
]);

View File

@@ -32,7 +32,7 @@ class StickerMasterResource extends Resource
->relationship('plant', 'name')
->reactive()
->nullable()
->disabled(fn (Get $get) => !empty($get('id')))
->disabled(fn (Get $get) => !empty($get('id'))) //disable in edit if user try to change
->afterStateUpdated(fn (callable $set) =>
$set('item_id', null) & $set('item_description', null)
)
@@ -56,8 +56,8 @@ class StickerMasterResource extends Resource
->disabled(fn (Get $get) => !empty($get('id')))
->live(debounce: 500) // Enable live updates
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id'); // Get selected plant_id
$itemId = $get('item_id'); // Get entered item_id
$plantId = $get('plant_id');
$itemId = $get('item_id');
// Ensure `item_id` is not cleared
if (!$plantId || !$itemId) {
@@ -77,115 +77,83 @@ class StickerMasterResource extends Resource
}
}),
// ->validationAttribute('Item Code')
// ->rule('required')
// ->extraAttributes(fn ($get) => [
// 'class' => $get('validationError') ? 'border-red-500' : '',
// ])
// ->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
// ->hintColor('danger'), // Show error in red under the input field
Forms\Components\TextInput::make('item_description')
->label('Description')
->required()
->reactive()
->readOnly(true),
//Forms\Components\Textarea::make('serial_number_motor'),
Forms\Components\TextInput::make('item_description')
->label('Description')
->required()
->reactive()
->readOnly(true),
Forms\Components\TextInput::make('part_validation1')
->nullable(),
->nullable(),
Forms\Components\TextInput::make('part_validation2')
->nullable(),
->nullable(),
Forms\Components\TextInput::make('part_validation3')
->nullable(),
->nullable(),
Forms\Components\TextInput::make('part_validation4')
->nullable(),
->nullable(),
Forms\Components\TextInput::make('part_validation5')
->nullable(),
->nullable(),
Forms\Components\Checkbox::make('serial_number_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\Textarea::make('serial_number_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('serial_number_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('serial_number_pumpset'),
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('serial_number_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_motor'),
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('pack_slip_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_pump'),
Forms\Components\Checkbox::make('pack_slip_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('pack_slip_pumpset'),
Forms\Components\Checkbox::make('pack_slip_pumpset')
Forms\Components\Checkbox::make('pack_slip_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_motor'),
Forms\Components\Checkbox::make('pack_slip_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_pump'),
Forms\Components\Checkbox::make('name_plate_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('name_plate_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('name_plate_pumpset'),
Forms\Components\Checkbox::make('name_plate_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_motor'),
Forms\Components\Checkbox::make('tube_sticker_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_pump'),
Forms\Components\Checkbox::make('tube_sticker_motor')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('tube_sticker_pump')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('tube_sticker_pumpset'),
Forms\Components\Checkbox::make('tube_sticker_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null), //to pass null value
Forms\Components\Checkbox::make('tube_sticker_pumpset')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\Checkbox::make('warranty_card')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
//Forms\Components\TextInput::make('warranty_card'),
Forms\Components\Checkbox::make('warranty_card')
->nullable()
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
]);
}
@@ -196,74 +164,74 @@ class StickerMasterResource extends Resource
->searchable()
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->numeric()
->sortable(),
->label('ID')
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('item.code')
->sortable(),
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->sortable(),
->sortable(),
Tables\Columns\CheckboxColumn::make('serial_number_motor')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('serial_number_pump')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('serial_number_pumpset')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('pack_slip_motor')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('pack_slip_pump')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('pack_slip_pumpset')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('name_plate_motor')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('name_plate_pump')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('name_plate_pumpset')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('tube_sticker_motor')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('tube_sticker_pump')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('tube_sticker_pumpset')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\CheckboxColumn::make('warranty_card')
->disabled(true)
->sortable(),
->disabled(true)
->sortable(),
Tables\Columns\TextColumn::make('part_validation1')
->sortable(),
->sortable(),
Tables\Columns\TextColumn::make('part_validation2')
->sortable(),
->sortable(),
Tables\Columns\TextColumn::make('part_validation3')
->sortable(),
->sortable(),
Tables\Columns\TextColumn::make('part_validation4')
->sortable(),
->sortable(),
Tables\Columns\TextColumn::make('part_validation5')
->sortable(),
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),