Added hasMany relation on model file and item description on exporter file and commented unwanted warning msg, added disabled function on edit for plant, line, item columns in resource file
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Laravel Pint / pint (pull_request) Successful in 3m7s
Laravel Larastan / larastan (pull_request) Failing after 3m53s

This commit is contained in:
dhanabalan
2026-02-26 21:14:02 +05:30
parent 1704761844
commit fe54de7ac8
3 changed files with 61 additions and 26 deletions

View File

@@ -50,14 +50,15 @@ class ProcessOrderResource extends Resource
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->searchable()
->label('Plant Name')
->relationship('plant', 'name')
->searchable()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
@@ -93,7 +94,8 @@ class ProcessOrderResource extends Resource
->hintColor('danger')
->required(),
Forms\Components\Select::make('line_id')
->label('Line')
->label('Line Name')
->reactive()
->searchable()
->options(function (callable $get) {
$plantId = $get('plant_id');
@@ -103,7 +105,7 @@ class ProcessOrderResource extends Resource
return Line::where('plant_id', $plantId)->pluck('name', 'id');
})
->reactive()
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('item_id', null);
$set('item_description', null);
@@ -123,6 +125,7 @@ class ProcessOrderResource extends Resource
// ->relationship('item', 'id')
// ->required(),
->searchable()
->reactive()
->options(function (callable $get) {
$plantId = $get('plant_id');
if (empty($plantId)) {
@@ -131,7 +134,7 @@ class ProcessOrderResource extends Resource
return Item::where('plant_id', $plantId)->pluck('code', 'id');
})
->reactive()
->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$plantId = $get('plant_id');
$itemId = $get('item_id');
@@ -166,9 +169,8 @@ class ProcessOrderResource extends Resource
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('item_description')
->label('Description')
->label('Item Description')
->readOnly()
->required()
->reactive()
@@ -187,7 +189,7 @@ class ProcessOrderResource extends Resource
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('item_uom')
->label('UOM')
->label('Item UOM')
->readOnly()
->required()
->reactive()
@@ -262,12 +264,11 @@ class ProcessOrderResource extends Resource
->first();
if ($existing) {
Notification::make()
->title('Duplicate Process Order!')
->body("Process Order '{$value}' is already exist with item code '{$existing->item->code}'.")
->danger()
->send();
// Notification::make()
// ->title('Duplicate Process Order!')
// ->body("Process Order '{$value}' is already exist with item code '{$existing->item->code}'.")
// ->danger()
// ->send();
$fail("process order already exists for this plant and item code '{$existing->item->code}'.");
}
};
@@ -445,7 +446,7 @@ class ProcessOrderResource extends Resource
->hint(fn ($get) => $get('sfgNumberError') ? $get('sfgNumberError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('machine_name')
->label('Machine ID')
->label('Machine Name')
->reactive()
->readOnly(fn ($get) => ($get('process_order') == null))
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
@@ -680,27 +681,27 @@ class ProcessOrderResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->label('Plant Name')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('line.name')
->label('Line')
->label('Line Name')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('item.code')
->label('Item')
->label('Item Code')
->searchable()
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('item.description')
->label('Description')
->label('Item Description')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('item.uom')
->label('Uom')
->label('Item UOM')
->alignCenter()
->searchable()
->sortable(),
@@ -735,7 +736,7 @@ class ProcessOrderResource extends Resource
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('machine_name')
->label('Machine ID')
->label('Machine Name')
->alignCenter()
->searchable()
->sortable(),
@@ -778,16 +779,35 @@ class ProcessOrderResource extends Resource
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant Name')
->label('Search by Plant Name')
->nullable()
->searchable()
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
$set('Line', null);
}),
Select::make('Line')
->label('Search by Line Name')
->nullable()
->searchable()
->reactive()
->options(function (callable $get) {
$plantId = $get('Plant');
return Line::whereHas('processOrders', function ($query) use ($plantId) {
if ($plantId) {
$query->where('plant_id', $plantId);
}
})->pluck('name', 'id');
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('process_order', null);
}),
Select::make('Item')
->label('Search by Item Code')
@@ -847,7 +867,7 @@ class ProcessOrderResource extends Resource
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['Item']) && empty($data['process_order']) && Str::length($data['coil_number']) <= 0 && empty($data['sfg_number']) && empty($data['machine_name']) && ($data['rework_status'] == null || $data['rework_status'] == '') && empty($data['created_from']) && empty($data['created_to'])) {
if (empty($data['Plant']) && empty($data['Line']) && empty($data['Item']) && empty($data['process_order']) && Str::length($data['coil_number']) <= 0 && empty($data['sfg_number']) && empty($data['machine_name']) && ($data['rework_status'] == null || $data['rework_status'] == '') && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0');
}
@@ -861,6 +881,10 @@ class ProcessOrderResource extends Resource
}
}
if (! empty($data['Line'])) {
$query->where('line_id', $data['Line']);
}
if (! empty($data['Item'])) {
$query->where('item_id', $data['Item']);
}
@@ -905,12 +929,16 @@ class ProcessOrderResource extends Resource
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
return 'Plant Name: Choose plant to filter records.';
}
}
if (! empty($data['Line'])) {
$indicators[] = 'Line Name: '.Line::where('id', $data['Line'])->value('name');
}
if (! empty($data['Item'])) {
$indicators[] = 'Item: '.Item::where('id', $data['Item'])->value('code');
$indicators[] = 'Item Code: '.Item::where('id', $data['Item'])->value('code');
}
if (! empty($data['process_order'])) {