diff --git a/app/Filament/Resources/TestingPanelReadingResource.php b/app/Filament/Resources/TestingPanelReadingResource.php index 188c935..08a6480 100644 --- a/app/Filament/Resources/TestingPanelReadingResource.php +++ b/app/Filament/Resources/TestingPanelReadingResource.php @@ -56,8 +56,9 @@ class TestingPanelReadingResource extends Resource return $form ->schema([ Forms\Components\Select::make('plant_id') - ->label('Plant') + ->label('Plant Name') ->relationship('plant', 'name') + ->searchable() ->required() ->reactive() ->options(function (callable $get) { @@ -73,17 +74,19 @@ class TestingPanelReadingResource extends Resource $plantId = $get('plant_id'); if (! $plantId) { $set('line_id', null); - $set('item_id', null); + $set('motor_testing_master_id', null); $set('machine_id', null); $set('tPrError', 'Please select a plant first.'); return; } else { $set('line_id', null); - $set('item_id', null); + $set('motor_testing_master_id', null); $set('machine_id', null); $set('tPrError', null); } + + $set('updated_by', Filament::auth()->user()?->name); }) ->extraAttributes(fn ($get) => [ 'class' => $get('tPrError') ? 'border-red-500' : '', @@ -91,8 +94,9 @@ class TestingPanelReadingResource extends Resource ->hint(fn ($get) => $get('tPrError') ? $get('tPrError') : null) ->hintColor('danger'), Forms\Components\Select::make('line_id') - ->label('Line') + ->label('Line Name') ->relationship('line', 'name') + ->searchable() ->options(function (callable $get) { $plantId = $get('plant_id'); if (! $plantId) { @@ -109,10 +113,14 @@ class TestingPanelReadingResource extends Resource ->disabled(fn (Get $get) => ! empty($get('id'))) ->required() ->reactive() - ->afterStateUpdated(fn (callable $set) => $set('item_id', null)), + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('motor_testing_master_id', null); + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\Select::make('machine_id') - ->label('Machine') - ->relationship('machine', 'name') + ->label('Work Center') + ->relationship('machine', 'work_center') + ->searchable() ->options(function (callable $get) { $lineId = $get('line_id'); if (! $lineId) { @@ -121,7 +129,7 @@ class TestingPanelReadingResource extends Resource // Only show machines for the selected line return Machine::where('line_id', $lineId) - ->pluck('name', 'id') + ->pluck('work_center', 'id') ->toArray(); }) ->default(function () { @@ -129,7 +137,10 @@ class TestingPanelReadingResource extends Resource }) ->disabled(fn (Get $get) => ! empty($get('id'))) ->required() - ->reactive(), + ->reactive() + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\Select::make('motor_testing_master_id') ->label('Item Code') // ->relationship('motorTestingMaster', 'item.code') @@ -163,101 +174,234 @@ class TestingPanelReadingResource extends Resource // ) ->required() ->searchable() - ->reactive(), + ->reactive() + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('output') ->label('Output') - ->required(), + ->required() + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('serial_number') ->label('Serial Number') - ->required(), + ->required() + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('winded_serial_number') - ->label('Winded Serial Number'), + ->label('Winded Serial Number') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_volt') - ->label('Before FR Volt'), + ->label('Before FR Volt') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_cur') - ->label('Before FR Current'), + ->label('Before FR Current') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_pow') - ->label('Before FR Power'), + ->label('Before FR Power') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_res_ry') - ->label('Before FR Resistance RY'), + ->label('Before FR Resistance RY') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_res_yb') - ->label('Before FR Resistance YB'), + ->label('Before FR Resistance YB') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_res_br') - ->label('Before FR Resistance BR'), + ->label('Before FR Resistance BR') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_ir') - ->label('Before FR IR'), + ->label('Before FR IR') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_ir_r') - ->label('Before FR IR R'), + ->label('Before FR IR R') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_ir_y') - ->label('Before FR IR Y'), + ->label('Before FR IR Y') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_ir_b') - ->label('Before FR IR B'), + ->label('Before FR IR B') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_freq') - ->label('Before FR Frequency'), + ->label('Before FR Frequency') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('before_fr_speed') - ->label('Before FR Speed'), + ->label('Before FR Speed') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_vol') - ->label('After FR Volt'), + ->label('After FR Volt') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_cur') - ->label('After FR Current'), + ->label('After FR Current') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_pow') - ->label('After FR Power'), + ->label('After FR Power') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_hot') - ->label('After FR IR Hot'), + ->label('After FR IR Hot') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_hot_r') - ->label('After FR IR Hot R'), + ->label('After FR IR Hot R') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_hot_y') - ->label('After FR IR Hot Y'), + ->label('After FR IR Hot Y') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_hot_b') - ->label('After FR IR Hot B'), + ->label('After FR IR Hot B') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_cool') - ->label('After FR IR Cool'), + ->label('After FR IR Cool') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_cool_r') - ->label('After FR IR Cool R'), + ->label('After FR IR Cool R') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_cool_y') - ->label('After FR IR Cool Y'), + ->label('After FR IR Cool Y') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_ir_cool_b') - ->label('After FR IR Cool B'), + ->label('After FR IR Cool B') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_freq') - ->label('After FR Frequency'), + ->label('After FR Frequency') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_speed') - ->label('After FR Speed'), + ->label('After FR Speed') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('after_fr_leak_cur') - ->label('After FR Leak Current'), + ->label('After FR Leak Current') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('locked_rt_volt') - ->label('Locked RT Volt'), + ->label('Locked RT Volt') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('locked_rt_cur') - ->label('Locked RT Current'), + ->label('Locked RT Current') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('locked_rt_pow') - ->label('Locked RT Power'), + ->label('Locked RT Power') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('no_load_pickup_volt') - ->label('No Load Pickup Volt'), + ->label('No Load Pickup Volt') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('room_temperature') - ->label('Room Temperature'), + ->label('Room Temperature') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('hv_test') - ->label('High Voltage Test'), + ->label('High Voltage Test') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('batch_number') - ->label('Batch Number'), + ->label('Batch Number') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('batch_count') ->label('Batch Count') - ->default('0'), + ->default('0') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('result') - ->label('Result'), + ->label('Result') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('remark') - ->label('Remark'), + ->label('Remark') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('rework_count') ->label('Rework Count') - ->default('0'), + ->default('0') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('update_count') ->label('Update Count') - ->default('0'), + ->default('0') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('output_flag') ->label('Output Flag') - ->default('0'), + ->default('0') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), Forms\Components\TextInput::make('tested_by') - ->label('Tested By'), + ->label('Tested By') + ->default(fn () => Filament::auth()->user()?->name) + ->required(), Forms\Components\TextInput::make('updated_by') - ->label('Updated By'), + ->label('Updated By') + ->default(fn () => Filament::auth()->user()?->name) + ->required(), Forms\Components\TextInput::make('id') ->hidden() ->readOnly(), @@ -283,17 +427,20 @@ class TestingPanelReadingResource extends Resource return ($currentPage - 1) * $perPage + $rowLoop->iteration; }), Tables\Columns\TextColumn::make('plant.name') - ->label('Plant') + ->label('Plant Name') ->alignCenter(), Tables\Columns\TextColumn::make('line.name') - ->label('Line') + ->label('Line Name') ->alignCenter(), - Tables\Columns\TextColumn::make('machine.name') - ->label('Machine') + Tables\Columns\TextColumn::make('machine.work_center') + ->label('Work Center') ->alignCenter(), Tables\Columns\TextColumn::make('motorTestingMaster.item.code') ->label('Item Code') ->alignCenter(), + Tables\Columns\TextColumn::make('motorTestingMaster.subassembly_code') + ->label('Subassembly Code') + ->alignCenter(), Tables\Columns\TextColumn::make('motorTestingMaster.item.description') ->label('Model') ->alignCenter(), @@ -477,13 +624,22 @@ class TestingPanelReadingResource extends Resource ->label('Advanced Filters') ->form([ Select::make('Plant') - ->label('Select Plant') + ->label('Search by Plant Name') + ->searchable() ->nullable() ->options(function () { // return Plant::pluck('name', 'id'); $userHas = Filament::auth()->user()->plant_id; + + if ($userHas && strlen($userHas) > 0) { + return Plant::where('id', $userHas)->pluck('name', 'id')->toArray(); + } else { + return Plant::whereHas('testingPanelReadings', function ($query) { + $query->whereNotNull('id'); + })->orderBy('code')->pluck('name', 'id'); + } - return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + //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) { @@ -492,7 +648,8 @@ class TestingPanelReadingResource extends Resource }), Select::make('Line') - ->label('Select Line') + ->label('Search by Line Name') + ->searchable() ->nullable() ->options(function (callable $get) { $plantId = $get('Plant'); @@ -507,11 +664,11 @@ class TestingPanelReadingResource extends Resource ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('item_code', null); - }), Select::make('item_code') - ->label('Item Code') + ->label('Search by Item Code') ->searchable() + ->nullable() ->options(function (callable $get) { $plantId = $get('Plant'); if ($plantId) { @@ -520,15 +677,20 @@ class TestingPanelReadingResource extends Resource ->pluck('code', 'id') ->toArray(); } else { - return Item::whereHas('motorTestingMasters') - ->pluck('code', 'id') - ->toArray(); + return []; + // return Item::whereHas('motorTestingMasters') + // ->pluck('code', 'id') + // ->toArray(); } - // return []; }) - ->reactive(), + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('item_description', null); + }), Select::make('machine_name') - ->label('Machine Name') + ->label('Search by Work Center') + ->searchable() + ->nullable() ->options(function (callable $get) { $plantId = $get('Plant'); $lineId = $get('Line'); @@ -539,30 +701,43 @@ class TestingPanelReadingResource extends Resource return Machine::where('plant_id', $plantId) ->where('line_id', $lineId) - ->pluck('name', 'id') + ->pluck('work_center', 'id') ->toArray(); }) ->reactive(), TextInput::make('serial_number') ->label('Serial Number') ->reactive() - ->placeholder(placeholder: 'Enter Serial Number'), + ->placeholder('Enter Serial Number'), Select::make('item_description') ->label('Model') ->searchable() ->options(function (callable $get) { $plantId = $get('Plant'); - $query = Item::query(); + // $query = Item::query(); + // if ($plantId) { + // $query->where('plant_id', $plantId); + // } + + $plantId = $get('Plant'); if ($plantId) { - $query->where('plant_id', $plantId); + return Item::where('plant_id', $plantId) + ->whereHas('motorTestingMasters') + ->pluck('description', 'id') + ->toArray(); + } else { + return []; + // return Item::whereHas('motorTestingMasters') + // ->pluck('description', 'id') + // ->toArray(); } - - return $query->pluck('description', 'description')->toArray(); - + //return $query->pluck('description', 'description')->toArray(); }) - ->reactive(), - + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('item_code', null); + }), Select::make('output') ->label('Output') ->searchable() @@ -702,12 +877,23 @@ class TestingPanelReadingResource extends Resource } if (! empty($data['item_description'])) { - $item = Item::where('description', $data['item_description'])->first(); + $itemId = $data['item_description']; // Item::where('description', $data['item_description'])->first()?->id ?? null; - if ($item) { - $query->whereHas('motorTestingMaster', function ($subQuery) use ($item) { - $subQuery->where('item_id', $item->id); - }); + if ($itemId) { // $item + $mastId = MotorTestingMaster::where('item_id', $itemId)->first()?->id ?? null; + if ($mastId) { // $item + $motId = TestingPanelReading::where('motor_testing_master_id', $mastId)->first()?->id ?? null; + if ($motId) { // $item + $query->where('motor_testing_master_id', $mastId); + // $query->whereHas('motorTestingMaster', function ($subQuery) use ($itemId) { + // $subQuery->where('item_id', $itemId); //$item->id + // }); + } else { + $query->whereRaw('1 = 0'); + } + } else { + $query->whereRaw('1 = 0'); + } } else { $query->whereRaw('1 = 0'); } @@ -756,7 +942,7 @@ class TestingPanelReadingResource extends Resource $indicators = []; if (! empty($data['Plant'])) { - $indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name'); + $indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name'); } else { $userHas = Filament::auth()->user()->plant_id; @@ -765,26 +951,27 @@ class TestingPanelReadingResource extends Resource } } if (! empty($data['Line'])) { - $indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name'); + $indicators[] = 'Line Name: '.Line::where('id', $data['Line'])->value('name'); } if (! empty($data['item_code'])) { $indicators[] = 'Item Code: '.Item::where('id', $data['item_code'])->value('code'); } if (! empty($data['machine_name'])) { - $indicators[] = 'Machine: '.Machine::where('id', $data['machine_name'])->value('name'); + $indicators[] = 'Work Center: '.Machine::where('id', $data['machine_name'])->value('work_center'); } if (! empty($data['output'])) { $indicators[] = 'Output: '.$data['output']; } if (! empty($data['item_description'])) { - $indicators[] = 'Model: '.$data['item_description']; + $item = Item::where('id', $data['item_description'])->first()?->description ?? null; + $indicators[] = 'Model: '.$item; } // if (!empty($data['phase'])) { // $indicators[] = 'Phase: ' . $data['phase']; // } - // if (!empty($data['connection'])) { - // $indicators[] = 'Connection: ' . $data['connection']; - // } + if (!empty($data['connection'])) { + $indicators[] = 'Connection: ' . $data['connection']; + } if (! empty($data['remark'])) { $indicators[] = 'Remark: '.$data['remark']; }