Added required mapping for import columns and Updated plant selection logic in various resources on Advanced Filters

This commit is contained in:
dhanabalan
2025-10-08 17:46:19 +05:30
parent 377fd4c615
commit 98dc59538f
16 changed files with 177 additions and 123 deletions

View File

@@ -26,107 +26,107 @@ class StickerMasterImporter extends Importer
->relationship(resolveUsing: 'code') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
ImportColumn::make('serial_number_motor') ImportColumn::make('serial_number_motor')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Serial Number Motor') ->exampleHeader('Serial Number Motor')
->label('SERIAL NUMBER MOTOR') ->label('SERIAL NUMBER MOTOR')
->example('1'), ->example('1'),
ImportColumn::make('serial_number_pump') ImportColumn::make('serial_number_pump')
//->requiredMapping() ->requiredMapping()
->exampleHeader('Serial Number Pump') ->exampleHeader('Serial Number Pump')
->label('SERIAL NUMBER PUMP') ->label('SERIAL NUMBER PUMP')
->example('1'), ->example('1'),
ImportColumn::make('serial_number_pumpset') ImportColumn::make('serial_number_pumpset')
//->requiredMapping() ->requiredMapping()
->exampleHeader('Serial Number PumpSet') ->exampleHeader('Serial Number PumpSet')
->label('SERIAL NUMBER PUMPSET') ->label('SERIAL NUMBER PUMPSET')
->example(''), ->example(''),
ImportColumn::make('pack_slip_motor') ImportColumn::make('pack_slip_motor')
//->requiredMapping() ->requiredMapping()
->exampleHeader('Pack Slip Motor') ->exampleHeader('Pack Slip Motor')
->label('PACK SLIP MOTOR') ->label('PACK SLIP MOTOR')
->example('1'), ->example('1'),
ImportColumn::make('pack_slip_pump') ImportColumn::make('pack_slip_pump')
//->requiredMapping() ->requiredMapping()
->exampleHeader('Pack Slip Pump') ->exampleHeader('Pack Slip Pump')
->label('PACK SLIP PUMP') ->label('PACK SLIP PUMP')
->example('1'), ->example('1'),
ImportColumn::make('pack_slip_pumpset') ImportColumn::make('pack_slip_pumpset')
//->requiredMapping() ->requiredMapping()
->exampleHeader('Pack Slip PumpSet') ->exampleHeader('Pack Slip PumpSet')
->label('PACK SLIP PUMPSET') ->label('PACK SLIP PUMPSET')
->example(''), ->example(''),
ImportColumn::make('name_plate_motor') ImportColumn::make('name_plate_motor')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Name Plate Motor') ->exampleHeader('Name Plate Motor')
->label('NAME PLATE MOTOR') ->label('NAME PLATE MOTOR')
->example('1'), ->example('1'),
ImportColumn::make('name_plate_pump') ImportColumn::make('name_plate_pump')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Name Plate Pump') ->exampleHeader('Name Plate Pump')
->label('NAME PLATE PUMP') ->label('NAME PLATE PUMP')
->example('1'), ->example('1'),
ImportColumn::make('name_plate_pumpset') ImportColumn::make('name_plate_pumpset')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Name Plate PumpSet') ->exampleHeader('Name Plate PumpSet')
->label('NAME PLATE PUMPSET') ->label('NAME PLATE PUMPSET')
->example(''), ->example(''),
ImportColumn::make('tube_sticker_motor') ImportColumn::make('tube_sticker_motor')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Tube Sticker Motor') ->exampleHeader('Tube Sticker Motor')
->label('TUBE STICKER MOTOR') ->label('TUBE STICKER MOTOR')
->example('1'), ->example('1'),
ImportColumn::make('tube_sticker_pump') ImportColumn::make('tube_sticker_pump')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Tube Sticker Pump') ->exampleHeader('Tube Sticker Pump')
->label('TUBE STICKER PUMP') ->label('TUBE STICKER PUMP')
->example('1'), ->example('1'),
ImportColumn::make('tube_sticker_pumpset') ImportColumn::make('tube_sticker_pumpset')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Tube Sticker PumpSet') ->exampleHeader('Tube Sticker PumpSet')
->label('TUBE STICKER PUMPSET') ->label('TUBE STICKER PUMPSET')
->example(''), ->example(''),
ImportColumn::make('warranty_card') ImportColumn::make('warranty_card')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Warranty Card') ->exampleHeader('Warranty Card')
->label('WARRANTY CARD') ->label('WARRANTY CARD')
->example('1'), ->example('1'),
ImportColumn::make('part_validation1') ImportColumn::make('part_validation1')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Part Validation 1') ->exampleHeader('Part Validation 1')
->label('PART VALIDATION 1') ->label('PART VALIDATION 1')
->example('12345'), ->example('12345'),
ImportColumn::make('part_validation2') ImportColumn::make('part_validation2')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Part Validation 2') ->exampleHeader('Part Validation 2')
->label('PART VALIDATION 2') ->label('PART VALIDATION 2')
->example('23456'), ->example('23456'),
ImportColumn::make('part_validation3') ImportColumn::make('part_validation3')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Part Validation 3') ->exampleHeader('Part Validation 3')
->label('PART VALIDATION 3') ->label('PART VALIDATION 3')
->example('34567'), ->example('34567'),
ImportColumn::make('part_validation4') ImportColumn::make('part_validation4')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Part Validation 4') ->exampleHeader('Part Validation 4')
->label('PART VALIDATION 4') ->label('PART VALIDATION 4')
->example('45678'), ->example('45678'),
ImportColumn::make('part_validation5') ImportColumn::make('part_validation5')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Part Validation 5') ->exampleHeader('Part Validation 5')
->label('PART VALIDATION 5') ->label('PART VALIDATION 5')
->example('56789'), ->example('56789'),
ImportColumn::make('laser_part_validation1') ImportColumn::make('laser_part_validation1')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Laser Part Validation 1') ->exampleHeader('Laser Part Validation 1')
->label('LASER PART VALIDATION 1') ->label('LASER PART VALIDATION 1')
->example('67890'), ->example('67890'),
ImportColumn::make('laser_part_validation2') ImportColumn::make('laser_part_validation2')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Laser Part Validation 2') ->exampleHeader('Laser Part Validation 2')
->label('LASER PART VALIDATION 2') ->label('LASER PART VALIDATION 2')
->example('78901'), ->example('78901'),
ImportColumn::make('panel_box_code') ImportColumn::make('panel_box_code')
// ->requiredMapping() ->requiredMapping()
->exampleHeader('Panel Box Code') ->exampleHeader('Panel Box Code')
->label('PANEL BOX CODE') ->label('PANEL BOX CODE')
->example('123456'), ->example('123456'),
@@ -138,13 +138,13 @@ class StickerMasterImporter extends Importer
->example('0') ->example('0')
->rules(['required']), ->rules(['required']),
ImportColumn::make('material_type') ImportColumn::make('material_type')
// ->requiredMapping() ->requiredMapping()
->integer() ->integer()
->exampleHeader('Material Type') ->exampleHeader('Material Type')
->label('MATERIAL TYPE') ->label('MATERIAL TYPE')
->example(''), ->example(''),
ImportColumn::make('bundle_quantity') ImportColumn::make('bundle_quantity')
// ->requiredMapping() ->requiredMapping()
->integer() ->integer()
->exampleHeader('Bundle Quantity') ->exampleHeader('Bundle Quantity')
->label('BUNDLE QUANTITY') ->label('BUNDLE QUANTITY')

View File

@@ -323,78 +323,82 @@ class EbReadingResource extends Resource
// ]) // ])
->filters([ ->filters([
Tables\Filters\TrashedFilter::make(), Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters') Filter::make('advanced_filters')
->label('Advanced Filters') ->label('Advanced Filters')
->form([ ->form([
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // return Plant::pluck('name', 'id');
}) // })
->reactive() ->options(function (callable $get) {
->afterStateUpdated(function ($state, callable $set, callable $get) { $userHas = Filament::auth()->user()->plant_id;
$set('electrician_sign', null); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
}), })
TextInput::make('electrician_sign') ->reactive()
->label('Created By'), ->afterStateUpdated(function ($state, callable $set, callable $get) {
DateTimePicker::make(name: 'created_from') $set('electrician_sign', null);
->label('Created From') }),
->placeholder(placeholder: 'Select From DateTime') TextInput::make('electrician_sign')
->reactive() ->label('Created By'),
->native(false), DateTimePicker::make(name: 'created_from')
DateTimePicker::make('created_to') ->label('Created From')
->label('Created To') ->placeholder(placeholder: 'Select From DateTime')
->placeholder(placeholder: 'Select To DateTime') ->reactive()
->reactive() ->native(false),
->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) { ->filtersFormMaxHeight('280px')
// 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')
->actions([ ->actions([
Tables\Actions\ViewAction::make(), Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),

View File

@@ -126,7 +126,6 @@ class GrMasterResource extends Resource
} }
// else if (preg_match('/E CODE\s*:\s*(\S+)/i', $text, $matches)) { // else if (preg_match('/E CODE\s*:\s*(\S+)/i', $text, $matches)) {
// $item2 = $matches[1]; // $item2 = $matches[1];
// dd($item2); // dd($item2);
// } // }
@@ -189,14 +188,13 @@ class GrMasterResource extends Resource
} }
else else
{ {
Notification::make() Notification::make()
->title('Item Code not matched') ->title('Item Code not matched')
->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.") ->body("Item Code: {$item->code} not matched with the uploaded pdf code $item1.")
->danger() ->danger()
->send(); ->send();
if (Storage::disk('local')->exists($storedPath)) { if (Storage::disk('local')->exists($storedPath)) {
Storage::disk('local')->delete($storedPath); Storage::disk('local')->delete($storedPath);
} }
return; return;

View File

@@ -283,8 +283,12 @@ class GuardPatrolEntryResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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(), ->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) { // ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -1025,8 +1025,12 @@ class InvoiceValidationResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -716,8 +716,12 @@ class LocatorInvoiceValidationResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -189,8 +189,12 @@ class LocatorResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -469,8 +469,12 @@ class MotorTestingMasterResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -281,8 +281,12 @@ class PalletValidationResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -438,8 +438,12 @@ class ProductionLineStopResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -588,8 +588,12 @@ class ProductionPlanResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -1044,8 +1044,12 @@ class ProductionQuantityResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // Assuming 'name' is the column you want to display // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -2318,8 +2318,12 @@ class QualityValidationResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {

View File

@@ -466,8 +466,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -1006,8 +1006,12 @@ class SerialValidationResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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() ->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get): void { ->afterStateUpdated(function ($state, callable $set, callable $get): void {

View File

@@ -168,8 +168,12 @@ class WeightValidationResource extends Resource
Select::make('Plant') Select::make('Plant')
->label('Select Plant') ->label('Select Plant')
->nullable() ->nullable()
->options(function () { // ->options(function () {
return Plant::pluck('name', 'id'); // 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(), ->reactive(),
// ->afterStateUpdated(function ($state, callable $set, callable $get) { // ->afterStateUpdated(function ($state, callable $set, callable $get) {