From 98dc59538f5c1e6a2c2206a5507232356e611492 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 8 Oct 2025 17:46:19 +0530 Subject: [PATCH] Added required mapping for import columns and Updated plant selection logic in various resources on Advanced Filters --- .../Imports/StickerMasterImporter.php | 46 +++--- app/Filament/Resources/EbReadingResource.php | 146 +++++++++--------- app/Filament/Resources/GrMasterResource.php | 4 +- .../Resources/GuardPatrolEntryResource.php | 8 +- .../Resources/InvoiceValidationResource.php | 8 +- .../LocatorInvoiceValidationResource.php | 8 +- app/Filament/Resources/LocatorResource.php | 8 +- .../Resources/MotorTestingMasterResource.php | 8 +- .../Resources/PalletValidationResource.php | 8 +- .../Resources/ProductionLineStopResource.php | 8 +- .../Resources/ProductionPlanResource.php | 8 +- .../Resources/ProductionQuantityResource.php | 8 +- .../Resources/QualityValidationResource.php | 8 +- ...ReworkLocatorInvoiceValidationResource.php | 8 +- .../Resources/SerialValidationResource.php | 8 +- .../Resources/WeightValidationResource.php | 8 +- 16 files changed, 177 insertions(+), 123 deletions(-) diff --git a/app/Filament/Imports/StickerMasterImporter.php b/app/Filament/Imports/StickerMasterImporter.php index ca348bc..bcec1da 100644 --- a/app/Filament/Imports/StickerMasterImporter.php +++ b/app/Filament/Imports/StickerMasterImporter.php @@ -26,107 +26,107 @@ class StickerMasterImporter extends Importer ->relationship(resolveUsing: 'code') ->rules(['required']), ImportColumn::make('serial_number_motor') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Serial Number Motor') ->label('SERIAL NUMBER MOTOR') ->example('1'), ImportColumn::make('serial_number_pump') - //->requiredMapping() + ->requiredMapping() ->exampleHeader('Serial Number Pump') ->label('SERIAL NUMBER PUMP') ->example('1'), ImportColumn::make('serial_number_pumpset') - //->requiredMapping() + ->requiredMapping() ->exampleHeader('Serial Number PumpSet') ->label('SERIAL NUMBER PUMPSET') ->example(''), ImportColumn::make('pack_slip_motor') - //->requiredMapping() + ->requiredMapping() ->exampleHeader('Pack Slip Motor') ->label('PACK SLIP MOTOR') ->example('1'), ImportColumn::make('pack_slip_pump') - //->requiredMapping() + ->requiredMapping() ->exampleHeader('Pack Slip Pump') ->label('PACK SLIP PUMP') ->example('1'), ImportColumn::make('pack_slip_pumpset') - //->requiredMapping() + ->requiredMapping() ->exampleHeader('Pack Slip PumpSet') ->label('PACK SLIP PUMPSET') ->example(''), ImportColumn::make('name_plate_motor') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Name Plate Motor') ->label('NAME PLATE MOTOR') ->example('1'), ImportColumn::make('name_plate_pump') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Name Plate Pump') ->label('NAME PLATE PUMP') ->example('1'), ImportColumn::make('name_plate_pumpset') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Name Plate PumpSet') ->label('NAME PLATE PUMPSET') ->example(''), ImportColumn::make('tube_sticker_motor') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Tube Sticker Motor') ->label('TUBE STICKER MOTOR') ->example('1'), ImportColumn::make('tube_sticker_pump') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Tube Sticker Pump') ->label('TUBE STICKER PUMP') ->example('1'), ImportColumn::make('tube_sticker_pumpset') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Tube Sticker PumpSet') ->label('TUBE STICKER PUMPSET') ->example(''), ImportColumn::make('warranty_card') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Warranty Card') ->label('WARRANTY CARD') ->example('1'), ImportColumn::make('part_validation1') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Part Validation 1') ->label('PART VALIDATION 1') ->example('12345'), ImportColumn::make('part_validation2') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Part Validation 2') ->label('PART VALIDATION 2') ->example('23456'), ImportColumn::make('part_validation3') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Part Validation 3') ->label('PART VALIDATION 3') ->example('34567'), ImportColumn::make('part_validation4') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Part Validation 4') ->label('PART VALIDATION 4') ->example('45678'), ImportColumn::make('part_validation5') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Part Validation 5') ->label('PART VALIDATION 5') ->example('56789'), ImportColumn::make('laser_part_validation1') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Laser Part Validation 1') ->label('LASER PART VALIDATION 1') ->example('67890'), ImportColumn::make('laser_part_validation2') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Laser Part Validation 2') ->label('LASER PART VALIDATION 2') ->example('78901'), ImportColumn::make('panel_box_code') - // ->requiredMapping() + ->requiredMapping() ->exampleHeader('Panel Box Code') ->label('PANEL BOX CODE') ->example('123456'), @@ -138,13 +138,13 @@ class StickerMasterImporter extends Importer ->example('0') ->rules(['required']), ImportColumn::make('material_type') - // ->requiredMapping() + ->requiredMapping() ->integer() ->exampleHeader('Material Type') ->label('MATERIAL TYPE') ->example(''), ImportColumn::make('bundle_quantity') - // ->requiredMapping() + ->requiredMapping() ->integer() ->exampleHeader('Bundle Quantity') ->label('BUNDLE QUANTITY') diff --git a/app/Filament/Resources/EbReadingResource.php b/app/Filament/Resources/EbReadingResource.php index 69d9508..b97e43a 100644 --- a/app/Filament/Resources/EbReadingResource.php +++ b/app/Filament/Resources/EbReadingResource.php @@ -323,78 +323,82 @@ class EbReadingResource extends Resource // ]) ->filters([ Tables\Filters\TrashedFilter::make(), - Filter::make('advanced_filters') - ->label('Advanced Filters') - ->form([ - Select::make('Plant') - ->label('Select Plant') - ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); - }) - ->reactive() - ->afterStateUpdated(function ($state, callable $set, callable $get) { - $set('electrician_sign', null); - }), - TextInput::make('electrician_sign') - ->label('Created By'), - DateTimePicker::make(name: 'created_from') - ->label('Created From') - ->placeholder(placeholder: 'Select From DateTime') - ->reactive() - ->native(false), - DateTimePicker::make('created_to') - ->label('Created To') - ->placeholder(placeholder: 'Select To DateTime') - ->reactive() - ->native(false), + Filter::make('advanced_filters') + ->label('Advanced Filters') + ->form([ + Select::make('Plant') + ->label('Select Plant') + ->nullable() + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('electrician_sign', null); + }), + TextInput::make('electrician_sign') + ->label('Created By'), + DateTimePicker::make(name: 'created_from') + ->label('Created From') + ->placeholder(placeholder: 'Select From DateTime') + ->reactive() + ->native(false), + DateTimePicker::make('created_to') + ->label('Created To') + ->placeholder(placeholder: 'Select To DateTime') + ->reactive() + ->native(false), + ]) + ->query(function ($query, array $data) { + // Hide all records initially if no filters are applied + if (empty($data['Plant']) && empty($data['electrician_sign'])) { + return $query->whereRaw('1 = 0'); + } + + if (!empty($data['Plant'])) { + $query->where('plant_id', $data['Plant']); + } + + if (!empty($data['created_from'])) { + $query->where('created_at', '>=', $data['created_from']); + } + + if (!empty($data['created_to'])) { + $query->where('created_at', '<=', $data['created_to']); + } + + if (!empty($data['electrician_sign'])) { + $query->where('electrician_sign', $data['electrician_sign']); + } + + }) + ->indicateUsing(function (array $data) { + $indicators = []; + + if (!empty($data['Plant'])) { + $indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name'); + } + + if (!empty($data['electrician_sign'])) { + $indicators[] = 'Created By: ' . $data['electrician_sign']; + } + + if (!empty($data['created_from'])) { + $indicators[] = 'From: ' . $data['created_from']; + } + + if (!empty($data['created_to'])) { + $indicators[] = 'To: ' . $data['created_to']; + } + + return $indicators; + }) ]) - ->query(function ($query, array $data) { - // Hide all records initially if no filters are applied - if (empty($data['Plant']) && empty($data['electrician_sign'])) { - return $query->whereRaw('1 = 0'); - } - - if (!empty($data['Plant'])) { - $query->where('plant_id', $data['Plant']); - } - - if (!empty($data['created_from'])) { - $query->where('created_at', '>=', $data['created_from']); - } - - if (!empty($data['created_to'])) { - $query->where('created_at', '<=', $data['created_to']); - } - - if (!empty($data['electrician_sign'])) { - $query->where('electrician_sign', $data['electrician_sign']); - } - - }) - ->indicateUsing(function (array $data) { - $indicators = []; - - if (!empty($data['Plant'])) { - $indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name'); - } - - if (!empty($data['electrician_sign'])) { - $indicators[] = 'Created By: ' . $data['electrician_sign']; - } - - if (!empty($data['created_from'])) { - $indicators[] = 'From: ' . $data['created_from']; - } - - if (!empty($data['created_to'])) { - $indicators[] = 'To: ' . $data['created_to']; - } - - return $indicators; - }) - ]) - ->filtersFormMaxHeight('280px') + ->filtersFormMaxHeight('280px') ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(), diff --git a/app/Filament/Resources/GrMasterResource.php b/app/Filament/Resources/GrMasterResource.php index 7ea0f24..f3a1626 100644 --- a/app/Filament/Resources/GrMasterResource.php +++ b/app/Filament/Resources/GrMasterResource.php @@ -126,7 +126,6 @@ class GrMasterResource extends Resource } // else if (preg_match('/E CODE\s*:\s*(\S+)/i', $text, $matches)) { - // $item2 = $matches[1]; // dd($item2); // } @@ -189,14 +188,13 @@ class GrMasterResource extends Resource } else { - Notification::make() ->title('Item Code not matched') ->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.") ->danger() ->send(); - if (Storage::disk('local')->exists($storedPath)) { + if (Storage::disk('local')->exists($storedPath)) { Storage::disk('local')->delete($storedPath); } return; diff --git a/app/Filament/Resources/GuardPatrolEntryResource.php b/app/Filament/Resources/GuardPatrolEntryResource.php index 1f609f5..a9acdd9 100644 --- a/app/Filament/Resources/GuardPatrolEntryResource.php +++ b/app/Filament/Resources/GuardPatrolEntryResource.php @@ -283,8 +283,12 @@ class GuardPatrolEntryResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive(), // ->afterStateUpdated(function ($state, callable $set, callable $get) { diff --git a/app/Filament/Resources/InvoiceValidationResource.php b/app/Filament/Resources/InvoiceValidationResource.php index bff15ef..1efe6e9 100644 --- a/app/Filament/Resources/InvoiceValidationResource.php +++ b/app/Filament/Resources/InvoiceValidationResource.php @@ -1025,8 +1025,12 @@ class InvoiceValidationResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get): void { diff --git a/app/Filament/Resources/LocatorInvoiceValidationResource.php b/app/Filament/Resources/LocatorInvoiceValidationResource.php index 8e9ddb1..fee783e 100644 --- a/app/Filament/Resources/LocatorInvoiceValidationResource.php +++ b/app/Filament/Resources/LocatorInvoiceValidationResource.php @@ -716,8 +716,12 @@ class LocatorInvoiceValidationResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get): void { diff --git a/app/Filament/Resources/LocatorResource.php b/app/Filament/Resources/LocatorResource.php index a5673e8..09ec035 100644 --- a/app/Filament/Resources/LocatorResource.php +++ b/app/Filament/Resources/LocatorResource.php @@ -189,8 +189,12 @@ class LocatorResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get): void { diff --git a/app/Filament/Resources/MotorTestingMasterResource.php b/app/Filament/Resources/MotorTestingMasterResource.php index e061247..f705ed4 100644 --- a/app/Filament/Resources/MotorTestingMasterResource.php +++ b/app/Filament/Resources/MotorTestingMasterResource.php @@ -469,8 +469,12 @@ class MotorTestingMasterResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { diff --git a/app/Filament/Resources/PalletValidationResource.php b/app/Filament/Resources/PalletValidationResource.php index 3ffcd08..2d58c32 100644 --- a/app/Filament/Resources/PalletValidationResource.php +++ b/app/Filament/Resources/PalletValidationResource.php @@ -281,8 +281,12 @@ class PalletValidationResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get): void { diff --git a/app/Filament/Resources/ProductionLineStopResource.php b/app/Filament/Resources/ProductionLineStopResource.php index 55d26a2..9af43e0 100644 --- a/app/Filament/Resources/ProductionLineStopResource.php +++ b/app/Filament/Resources/ProductionLineStopResource.php @@ -438,8 +438,12 @@ class ProductionLineStopResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display + // ->options(function () { + // return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { diff --git a/app/Filament/Resources/ProductionPlanResource.php b/app/Filament/Resources/ProductionPlanResource.php index 0597ac4..d492a85 100644 --- a/app/Filament/Resources/ProductionPlanResource.php +++ b/app/Filament/Resources/ProductionPlanResource.php @@ -588,8 +588,12 @@ class ProductionPlanResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display + // ->options(function () { + // return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { diff --git a/app/Filament/Resources/ProductionQuantityResource.php b/app/Filament/Resources/ProductionQuantityResource.php index 336a829..fb3c3cd 100644 --- a/app/Filament/Resources/ProductionQuantityResource.php +++ b/app/Filament/Resources/ProductionQuantityResource.php @@ -1044,8 +1044,12 @@ class ProductionQuantityResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display + // ->options(function () { + // return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { diff --git a/app/Filament/Resources/QualityValidationResource.php b/app/Filament/Resources/QualityValidationResource.php index 220f8b9..0323a0e 100644 --- a/app/Filament/Resources/QualityValidationResource.php +++ b/app/Filament/Resources/QualityValidationResource.php @@ -2318,8 +2318,12 @@ class QualityValidationResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { diff --git a/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php index 3f68f50..332f8f1 100644 --- a/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php +++ b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php @@ -466,8 +466,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get): void { diff --git a/app/Filament/Resources/SerialValidationResource.php b/app/Filament/Resources/SerialValidationResource.php index 5002cb5..19d180b 100644 --- a/app/Filament/Resources/SerialValidationResource.php +++ b/app/Filament/Resources/SerialValidationResource.php @@ -1006,8 +1006,12 @@ class SerialValidationResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get): void { diff --git a/app/Filament/Resources/WeightValidationResource.php b/app/Filament/Resources/WeightValidationResource.php index ca03e60..5c2da03 100644 --- a/app/Filament/Resources/WeightValidationResource.php +++ b/app/Filament/Resources/WeightValidationResource.php @@ -168,8 +168,12 @@ class WeightValidationResource extends Resource Select::make('Plant') ->label('Select Plant') ->nullable() - ->options(function () { - return Plant::pluck('name', 'id'); + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->reactive(), // ->afterStateUpdated(function ($state, callable $set, callable $get) {