From 36dd327177ed88949c4974064b8bb22291a3969d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 3 Oct 2026 16:56:40 +0530 Subject: [PATCH] Updated resource file to add rework_winded and group work center column and Refactor resource validations and design --- .../Resources/TestingPanelReadingResource.php | 1247 ++++++++++------- 1 file changed, 719 insertions(+), 528 deletions(-) diff --git a/app/Filament/Resources/TestingPanelReadingResource.php b/app/Filament/Resources/TestingPanelReadingResource.php index 0e0867c3..4d5cca61 100644 --- a/app/Filament/Resources/TestingPanelReadingResource.php +++ b/app/Filament/Resources/TestingPanelReadingResource.php @@ -19,6 +19,7 @@ use Closure; use Filament\Facades\Filament; use Filament\Forms; use Filament\Forms\Components\DateTimePicker; +use Filament\Forms\Components\Section; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; @@ -57,449 +58,611 @@ class TestingPanelReadingResource extends Resource { return $form ->schema([ - Forms\Components\Select::make('plant_id') - ->label('Plant Name') - ->relationship('plant', 'name') - ->searchable() - ->required() - ->reactive() - ->options(function (callable $get) { - $userHas = Filament::auth()->user()->plant_id; + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant Name') + ->relationship('plant', 'name') + ->columnSpan(1) // (['default' => 1, 'sm' => 2]) + ->reactive() + ->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(); - }) - ->default(function () { - return optional(TestingPanelReading::latest()->first())->plant_id; - }) - ->disabled(fn (Get $get) => ! empty($get('id'))) - ->afterStateUpdated(function ($state, callable $set, callable $get) { - $plantId = $get('plant_id'); - if (! $plantId) { - $set('line_id', null); - $set('motor_testing_master_id', null); - $set('machine_id', null); - $set('tPrError', 'Please select a plant first.'); + 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; - return; - } else { - $set('line_id', null); - $set('motor_testing_master_id', null); - $set('machine_id', null); - $set('tPrError', null); - } + return ($userHas && strlen($userHas) > 0) ? $userHas : optional(TestingPanelReading::latest()->first())->plant_id ?? null; + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $plantId = $get('plant_id'); + if (! $plantId) { + $set('tPrError', 'Please select a plant first.'); + } else { + $set('tPrError', null); + } + $set('line_id', null); + $set('motor_testing_master_id', null); + $set('machine_id', null); - $set('updated_by', Filament::auth()->user()?->name); - }) - ->extraAttributes(fn ($get) => [ - 'class' => $get('tPrError') ? 'border-red-500' : '', + $set('updated_by', Filament::auth()->user()?->name); + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('tPrError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('tPrError') ? $get('tPrError') : null) + ->hintColor('danger') + ->required(), + Forms\Components\Select::make('line_id') + ->label('Line Name') + // ->relationship('line', 'name') + ->columnSpan(1) + ->reactive() + ->searchable() + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if (! $plantId) { + return []; + } + + return Line::where('plant_id', $plantId)->pluck('name', 'id')->toArray(); + }) + ->disabled(fn (Get $get) => ! empty($get('id'))) + ->default(function (callable $get) { + $plantId = $get('plant_id'); + if (empty($plantId)) { + return null; + } + + return TestingPanelReading::where('plant_id', $plantId)->latest()->first()->line_id ?? null; + }) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('motor_testing_master_id', null); + $set('machine_id', null); + $set('updated_by', Filament::auth()->user()?->name); + }) + ->required(), + Forms\Components\Select::make('machine_id') + ->label('Work Center') + // ->relationship('machine', 'work_center') + ->columnSpan(1) + ->reactive() + ->searchable() + ->options(function (callable $get) { + $lineId = $get('line_id'); + if (! $lineId) { + return []; + } + + return Machine::where('line_id', $lineId)->pluck('work_center', 'id')->toArray(); + }) + ->disabled(fn (Get $get) => ! empty($get('id'))) + ->default(function (callable $get) { + $plantId = $get('plant_id'); + if (empty($plantId)) { + return null; + } + + return TestingPanelReading::where('plant_id', $plantId)->latest()->first()->machine_id ?? null; + }) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->required(), + Forms\Components\Select::make('motor_testing_master_id') + ->label('Item Code') + // ->relationship('motorTestingMaster', 'item.code') + ->columnSpan(1) + // ->options(function (callable $get) { + // $plantId = $get('plant_id'); + // if (!$plantId) { + // return []; + // } + // return MotorTestingMaster::with('item') + // ->where('plant_id', $plantId) + // ->get() + // //->filter(fn ($mtm) => $mtm->item) + // ->pluck('item.code', 'id') + // ->toArray(); + // }) + ->reactive() + ->searchable() + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if (! $plantId) { + return []; + } + + return MotorTestingMaster::query() + ->join('items', 'motor_testing_masters.item_id', '=', 'items.id') + ->where('motor_testing_masters.plant_id', $plantId) + ->select('motor_testing_masters.id', 'items.code') + ->pluck('items.code', 'motor_testing_masters.id') + ->toArray(); + }) + ->disabled(fn (Get $get) => ! empty($get('id'))) + // ->getOptionLabelUsing(fn ($value) => + // MotorTestingMaster::with('item')->find($value)?->item?->code + // ) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->required(), + Forms\Components\TextInput::make('output') + ->label('Output ID') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->rule(function (callable $get) { + return function (string $attribute, $value, Closure $fail) use ($get) { + + $plantId = $get('plant_id'); + $lineId = $get('line_id'); + $machineId = $get('machine_id'); + $itemId = $get('motor_testing_master_id'); + $output = trim($value); + // $currentId = $get('id'); // current editing record id + + if (! $plantId || ! $lineId || ! $machineId || ! $itemId) { + return; + } + + if ($output == null || $output == '' || ! $output) { + $fail("Output can't be empty!"); // Output1 - Output99 + } elseif (Str::length($output) < 7) { + $fail('Output must be at least 7 characters long!'); + } elseif (Str::length($output) > 8) { + $fail('Output must be at most 8 characters long!'); + } elseif (! ctype_alnum($output)) { + $fail('Output should contain only alpha-numeric values!'); + } elseif (! preg_match('/^Output([1-9]|[1-9][0-9])$/', $output)) { + $fail("Output should be between 'Output1' and 'Output99'!"); + } + }; + }) + ->required(), + Forms\Components\TextInput::make('serial_number') + ->label('Serial Number') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->rule(function (callable $get) { + return function (string $attribute, $value, Closure $fail) use ($get) { + + $plantId = $get('plant_id'); + $lineId = $get('line_id'); + $machineId = $get('machine_id'); + $itemId = $get('motor_testing_master_id'); + $serialNumber = trim($value); + // $currentId = $get('id'); // current editing record id + + if (! $plantId || ! $lineId || ! $machineId || ! $itemId) { + return; + } + + if ($serialNumber == null || $serialNumber == '' || ! $serialNumber) { + $fail("Serial number can't be empty!"); + } elseif (Str::length($serialNumber) < 9) { + $fail('Serial number should contain minimum 9 digits!'); + } elseif (! ctype_alnum($serialNumber)) { + $fail('Serial number should contain only alpha-numeric values!'); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { + $fail("Serial number should not begin with '0' or letter!"); + } + }; + }) + ->required(), + Forms\Components\TextInput::make('winded_serial_number') + ->label('Winded Serial Number') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->rule(function (callable $get) { + return function (string $attribute, $value, Closure $fail) use ($get) { + + $plantId = $get('plant_id'); + $lineId = $get('line_id'); + $machineId = $get('machine_id'); + $itemId = $get('motor_testing_master_id'); + $serialNumber = trim($value); + // $currentId = $get('id'); // current editing record id + + if (! $plantId || ! $lineId || ! $machineId || ! $itemId || ! $serialNumber) { + return; + } + + if (Str::length($serialNumber) > 0 && Str::length($serialNumber) < 9) { + $fail('Winded serial number should contain minimum 9 digits!'); + } elseif (! ctype_alnum($serialNumber)) { + $fail('Winded serial number should contain only alpha-numeric values!'); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { + $fail("Winded serial number should not begin with '0' or letter!"); + } + }; + }), + Forms\Components\TextInput::make('before_fr_volt') + ->label('Before FR Volt') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->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') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\TextInput::make('room_temperature') + ->label('Room Temperature') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\Select::make('hv_test') + ->label('High Voltage Test') + ->columnSpan(1) + ->reactive() + ->disabled(fn (Get $get) => $get('id')) + ->options([ + 'With Stood' => 'With Stood', + 'Not With Stood' => 'Not With Stood', + ]) + ->selectablePlaceholder(false) + ->default('Not With Stood') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->required(), + Forms\Components\TextInput::make('batch_number') + ->label('Batch Number') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\TextInput::make('batch_count') + ->label('Batch Count') + ->columnSpan(1) + ->reactive() + ->integer() + ->minValue(0) + ->default(0) + ->readOnly(fn (Get $get) => $get('id') || ! $get('batch_number')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\Select::make('result') + ->label('Result') + ->columnSpan(1) + ->reactive() + ->disabled(fn (Get $get) => $get('id')) + ->options([ + 'PASS' => 'PASS', // Not With Stood + 'FAIL' => 'FAIL', + ]) + ->selectablePlaceholder(false) + ->default('FAIL') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->required(), + Forms\Components\TextInput::make('remark') + ->label('Remark') + ->columnSpan(1) + ->reactive() + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\TextInput::make('rework_count') + ->label('Rework Count') + ->columnSpan(1) + ->reactive() + ->integer() + ->minValue(0) + ->default(0) + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\Select::make('rework_winded') + ->label('Rework Winded Status') + ->columnSpan(1) + // ->nullable() + ->reactive() + ->disabled(fn (Get $get) => $get('id')) + ->options(function () { + return [ + '1' => 'Yes', + '0' => 'No', + ]; + }) + ->selectablePlaceholder(false) + ->default('0') + ->afterStateUpdated(function (callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->required(), + Forms\Components\TextInput::make('update_count') + ->label('Update Count') + ->columnSpan(1) + ->reactive() + ->integer() + ->minValue(0) + ->default(0) + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\TextInput::make('output_flag') + ->label('Output Flag') + ->columnSpan(1) + ->reactive() + ->integer() + ->minValue(0) + ->default(0) + ->maxValue(1) + ->readOnly(fn (Get $get) => $get('id')) + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }), + Forms\Components\TextInput::make('tested_by') + ->label('Tested By') + ->columnSpan(1) + ->default(fn () => Filament::auth()->user()?->name) + ->readOnly() + ->required(), + Forms\Components\Hidden::make('updated_by') + ->default(fn () => Filament::auth()->user()?->name) + ->required(), + Forms\Components\TextInput::make('id') + ->hidden() + ->readOnly(), ]) - ->hint(fn ($get) => $get('tPrError') ? $get('tPrError') : null) - ->hintColor('danger'), - Forms\Components\Select::make('line_id') - ->label('Line Name') - // ->relationship('line', 'name') - ->searchable() - ->options(function (callable $get) { - $plantId = $get('plant_id'); - if (! $plantId) { - return []; - } - - return Line::where('plant_id', $plantId) - ->pluck('name', 'id') - ->toArray(); - }) - ->default(function () { - return optional(TestingPanelReading::latest()->first())->line_id; - }) - ->disabled(fn (Get $get) => ! empty($get('id'))) - ->required() - ->reactive() - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('motor_testing_master_id', null); - $set('machine_id', null); - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\Select::make('machine_id') - ->label('Work Center') - // ->relationship('machine', 'work_center') - ->searchable() - ->options(function (callable $get) { - $lineId = $get('line_id'); - if (! $lineId) { - return []; - } - - // Only show machines for the selected line - return Machine::where('line_id', $lineId) - ->pluck('work_center', 'id') - ->toArray(); - }) - ->default(function () { - return optional(TestingPanelReading::latest()->first())->machine_id; - }) - ->disabled(fn (Get $get) => ! empty($get('id'))) - ->required() - ->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') - // ->options(function (callable $get) { - // $plantId = $get('plant_id'); - // if (!$plantId) { - // return []; - // } - // return MotorTestingMaster::with('item') - // ->where('plant_id', $plantId) - // ->get() - // //->filter(fn ($mtm) => $mtm->item) - // ->pluck('item.code', 'id') - // ->toArray(); - // }) - ->options(function (callable $get) { - $plantId = $get('plant_id'); - if (! $plantId) { - return []; - } - - return MotorTestingMaster::query() - ->join('items', 'motor_testing_masters.item_id', '=', 'items.id') - ->where('motor_testing_masters.plant_id', $plantId) - ->select('motor_testing_masters.id', 'items.code') - ->pluck('items.code', 'motor_testing_masters.id') - ->toArray(); - }) - // ->getOptionLabelUsing(fn ($value) => - // MotorTestingMaster::with('item')->find($value)?->item?->code - // ) - ->required() - ->searchable() - ->reactive() - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\TextInput::make('output') - ->label('Output') - ->required() - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }) - ->rule(function (callable $get) { - return function (string $attribute, $value, Closure $fail) use ($get) { - - $plantId = $get('plant_id'); - $lineId = $get('line_id'); - $machineId = $get('machine_id'); - $itemId = $get('motor_testing_master_id'); - $output = trim($value); - // $currentId = $get('id'); // current editing record id - - if (! $plantId || ! $lineId || ! $machineId || ! $itemId) { - return; - } - - if ($output == null || $output == '' || ! $output) { - $fail("Output can't be empty!"); // Output1 - Output99 - } elseif (Str::length($output) < 7) { - $fail('Output must be at least 7 characters long!'); - } elseif (Str::length($output) > 8) { - $fail('Output must be at most 8 characters long!'); - } elseif (! ctype_alnum($output)) { - $fail('Output should contain only alpha-numeric values!'); - } elseif (! preg_match('/^Output([1-9]|[1-9][0-9])$/', $output)) { - $fail("Output should be between 'Output1' and 'Output99'!"); - } - }; - }), - Forms\Components\TextInput::make('serial_number') - ->label('Serial Number') - ->required() - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }) - ->rule(function (callable $get) { - return function (string $attribute, $value, Closure $fail) use ($get) { - - $plantId = $get('plant_id'); - $lineId = $get('line_id'); - $machineId = $get('machine_id'); - $itemId = $get('motor_testing_master_id'); - $serialNumber = trim($value); - // $currentId = $get('id'); // current editing record id - - if (! $plantId || ! $lineId || ! $machineId || ! $itemId) { - return; - } - - if ($serialNumber == null || $serialNumber == '' || ! $serialNumber) { - $fail("Serial number can't be empty!"); - } elseif (Str::length($serialNumber) < 9) { - $fail('Serial number should contain minimum 9 digits!'); - } elseif (! ctype_alnum($serialNumber)) { - $fail('Serial number should contain only alpha-numeric values!'); - } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { - $fail("Serial number should not begin with '0' or letter!"); - } - }; - }), - Forms\Components\TextInput::make('winded_serial_number') - ->label('Winded Serial Number') - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }) - ->rule(function (callable $get) { - return function (string $attribute, $value, Closure $fail) use ($get) { - - $plantId = $get('plant_id'); - $lineId = $get('line_id'); - $machineId = $get('machine_id'); - $itemId = $get('motor_testing_master_id'); - $serialNumber = trim($value); - // $currentId = $get('id'); // current editing record id - - if (! $plantId || ! $lineId || ! $machineId || ! $itemId || ! $serialNumber) { - return; - } - - if (Str::length($serialNumber) > 0 && Str::length($serialNumber) < 9) { - $fail('Winded serial number should contain minimum 9 digits!'); - } elseif (! ctype_alnum($serialNumber)) { - $fail('Winded serial number should contain only alpha-numeric values!'); - } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { - $fail("Winded serial number should not begin with '0' or letter!"); - } - }; - }), - Forms\Components\TextInput::make('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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->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') - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\TextInput::make('room_temperature') - ->label('Room Temperature') - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\Select::make('hv_test') - ->label('High Voltage Test') - ->options([ - 'With Stood' => 'With Stood', - 'Not With Stood' => 'Not With Stood', - ]) - ->selectablePlaceholder(false) - ->default('Not With Stood') - ->required() - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\TextInput::make('batch_number') - ->label('Batch Number') - ->readOnly(fn (callable $get) => ! $get('id')) - ->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') - ->readOnly(fn (callable $get) => ! $get('id')) - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\Select::make('result') - ->label('Result') - ->options([ - 'PASS' => 'PASS', // Not With Stood - 'FAIL' => 'FAIL', - ]) - ->selectablePlaceholder(false) - ->default('FAIL') - ->required() - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\TextInput::make('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') - ->readOnly(fn (callable $get) => ! $get('id')) - ->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') - ->readOnly(fn (callable $get) => ! $get('id')) - ->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') - ->readOnly(fn (callable $get) => ! $get('id')) - ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { - $set('updated_by', Filament::auth()->user()?->name); - }), - Forms\Components\Hidden::make('tested_by') - ->default(fn () => Filament::auth()->user()?->name) - ->required(), - Forms\Components\Hidden::make('updated_by') - ->default(fn () => Filament::auth()->user()?->name) - ->required(), - Forms\Components\TextInput::make('id') - ->hidden() - ->readOnly(), + ->columns(['default' => 1, 'sm' => 2]), ]); } @@ -514,6 +677,7 @@ class TestingPanelReadingResource extends Resource // ->sortable(), Tables\Columns\TextColumn::make('No.') ->label('No.') + ->alignCenter() ->getStateUsing(function ($record, $livewire, $column, $rowLoop) { $paginator = $livewire->getTableRecords(); $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; @@ -527,6 +691,9 @@ class TestingPanelReadingResource extends Resource Tables\Columns\TextColumn::make('line.name') ->label('Line Name') ->alignCenter(), + Tables\Columns\TextColumn::make('machine.workGroupMaster.name') + ->label('Group Work Center') + ->alignCenter(), Tables\Columns\TextColumn::make('machine.work_center') ->label('Work Center') ->alignCenter(), @@ -539,16 +706,28 @@ class TestingPanelReadingResource extends Resource Tables\Columns\TextColumn::make('motorTestingMaster.item.description') ->label('Model') ->alignCenter(), + Tables\Columns\TextColumn::make('motorTestingMaster.item.category') + ->label('Category') + ->default('-') + ->alignCenter() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('motorTestingMaster.item.uom') + ->label('Unit of Measure') + ->default('-') + ->alignCenter() + ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('output') - ->label('Output') + ->label('Output ID') ->alignCenter(), Tables\Columns\TextColumn::make('serial_number') - ->label('Serial Number') + ->label('Motor Serial Number') ->alignCenter() + ->searchable() ->sortable(), Tables\Columns\TextColumn::make('winded_serial_number') ->label('Winded Serial Number') ->alignCenter() + ->searchable() ->sortable(), Tables\Columns\TextColumn::make('motorTestingMaster.kw') ->label('KW') @@ -661,7 +840,13 @@ class TestingPanelReadingResource extends Resource ->alignCenter(), Tables\Columns\TextColumn::make('hv_test') ->label('High Voltage Test') - ->alignCenter(), + ->alignCenter() + ->color(fn (string $state): string => match ($state) { + 'With Stood' => 'success', + 'Not With Stood' => 'danger', + default => 'warning', // gray + }) + ->default('-'), Tables\Columns\TextColumn::make('batch_number') ->label('Batch Number') ->alignCenter(), @@ -670,13 +855,29 @@ class TestingPanelReadingResource extends Resource ->alignCenter(), Tables\Columns\TextColumn::make('result') ->label('Result') - ->alignCenter(), + ->alignCenter() + ->color(fn (string $state): string => match ($state) { + 'PASS' => 'success', + 'FAIL' => 'danger', + default => 'warning', // gray + }) + ->badge() + ->default('-'), Tables\Columns\TextColumn::make('remark') ->label('Remark') ->alignCenter(), Tables\Columns\TextColumn::make('rework_count') ->label('Rework Count') ->alignCenter(), + Tables\Columns\TextColumn::make('rework_winded') + ->label('Rework Winded Status') + ->alignCenter() + ->formatStateUsing(fn ($state): string => match ((string) $state) { + '1' => 'Yes', + '0' => 'No', + default => 'No', + }) + ->badge(), Tables\Columns\TextColumn::make('update_count') ->label('Updated Count') ->alignCenter(), @@ -695,8 +896,7 @@ class TestingPanelReadingResource extends Resource ->sortable(), Tables\Columns\TextColumn::make('tested_by') ->label('Tested By') - ->alignCenter() - ->numeric(), + ->alignCenter(), Tables\Columns\TextColumn::make('updated_at') ->label('Updated At') ->alignCenter() @@ -704,8 +904,7 @@ class TestingPanelReadingResource extends Resource ->dateTime(), Tables\Columns\TextColumn::make('updated_by') ->label('Updated By') - ->alignCenter() - ->numeric(), + ->alignCenter(), Tables\Columns\TextColumn::make('deleted_at') ->label('Deleted At') ->alignCenter() @@ -713,6 +912,7 @@ class TestingPanelReadingResource extends Resource ->dateTime() ->toggleable(isToggledHiddenByDefault: true), ]) + ->searchPlaceholder('Search by Serial Number') ->filters([ Tables\Filters\TrashedFilter::make(), Filter::make('advanced_filters') @@ -720,8 +920,9 @@ class TestingPanelReadingResource extends Resource ->form([ Select::make('Plant') ->label('Search by Plant Name') - ->searchable() ->nullable() + ->searchable() + ->reactive() ->options(function () { // return Plant::pluck('name', 'id'); $userHas = Filament::auth()->user()->plant_id; @@ -736,7 +937,6 @@ class TestingPanelReadingResource extends Resource // 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('Line', null); $set('item_code', null); @@ -744,26 +944,25 @@ class TestingPanelReadingResource extends Resource }), Select::make('Line') ->label('Search by Line Name') - ->searchable() ->nullable() + ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); if (! $plantId) { return []; } - return Line::where('plant_id', $plantId) - ->pluck('name', 'id') - ->toArray(); + return Line::where('plant_id', $plantId)->pluck('name', 'id')->toArray(); }) - ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('item_code', null); }), Select::make('machine_name') ->label('Search by Work Center') - ->searchable() ->nullable() + ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); $lineId = $get('Line'); @@ -772,31 +971,26 @@ class TestingPanelReadingResource extends Resource return []; } - return Machine::where('plant_id', $plantId) - ->where('line_id', $lineId) - ->pluck('work_center', 'id') - ->toArray(); - }) - ->reactive(), + return Machine::where('plant_id', $plantId)->where('line_id', $lineId)->pluck('work_center', 'id')->toArray(); + }), Select::make('item_code') ->label('Search by Item Code') - ->searchable() ->nullable() + ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); - if ($plantId) { - return Item::where('plant_id', $plantId) - ->whereHas('motorTestingMasters') - ->pluck('code', 'id') - ->toArray(); - } else { + + if (empty($plantId)) { return []; - // return Item::whereHas('motorTestingMasters') - // ->pluck('code', 'id') - // ->toArray(); } + + return Item::whereHas('motorTestingMasters', function ($query) use ($plantId) { + if ($plantId) { + $query->where('plant_id', $plantId); + } + })->pluck('code', 'id')->toArray(); }) - ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('item_description', null); }), @@ -806,22 +1000,23 @@ class TestingPanelReadingResource extends Resource ->placeholder('Enter Serial Number'), Select::make('subassembly_code') ->label('Search by Subassembly Code') - ->searchable() ->nullable() + ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); - if ($plantId) { - return MotorTestingMaster::whereHas('testingPanelReadings', function ($query) { - $query->whereNotNull('id'); - })->whereNotNull('subassembly_code')->orderBy('subassembly_code')->pluck('subassembly_code', 'id'); - } else { + + if (empty($plantId)) { return []; - // return Item::whereHas('motorTestingMasters') - // ->pluck('code', 'id') - // ->toArray(); } + + return MotorTestingMaster::whereHas('testingPanelReadings', function ($query) use ($plantId) { + if ($plantId) { + $query->where('plant_id', $plantId); + } + $query->whereNotNull('id'); + })->whereNotNull('subassembly_code')->orderBy('subassembly_code')->pluck('subassembly_code', 'id'); }) - ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('item_description', null); }), @@ -831,45 +1026,40 @@ class TestingPanelReadingResource extends Resource ->placeholder('Enter Winded Serial Number'), Select::make('item_description') ->label('Search by Model') + ->nullable() ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); - // $query = Item::query(); - // if ($plantId) { - // $query->where('plant_id', $plantId); - // } - - $plantId = $get('Plant'); - if ($plantId) { - return Item::where('plant_id', $plantId) - ->whereHas('motorTestingMasters') - ->pluck('description', 'id') - ->toArray(); - } else { + if (empty($plantId)) { return []; - // return Item::whereHas('motorTestingMasters') - // ->pluck('description', 'id') - // ->toArray(); } - // return $query->pluck('description', 'description')->toArray(); + + return Item::whereHas('motorTestingMasters', function ($query) use ($plantId) { + if ($plantId) { + $query->where('plant_id', $plantId); + } + })->pluck('description', 'id')->toArray(); }) - ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('item_code', null); }), Select::make('output') - ->label('Search by Output') + ->label('Search by Output ID') + ->nullable() ->searchable() - ->options(function () { - return TestingPanelReading::whereNotNull('output') - ->select('output') - ->distinct() - ->orderBy('output') - ->pluck('output', 'output') // key and label are both the output value - ->toArray(); - }) - ->reactive(), + ->reactive() + ->options(function (callable $get) { + $plantId = $get('Plant'); + + if (empty($plantId)) { + return []; + } + + return TestingPanelReading::where('plant_id', $plantId)->whereNotNull('output')->distinct()->orderBy('output')->pluck('output', 'output')->toArray(); + // ->select('output') + }), // TextInput::make('phase') // ->label('Phase'), // Select::make('phase') @@ -900,10 +1090,11 @@ class TestingPanelReadingResource extends Resource // }) // ->reactive(), // ... - Select::make('connection') ->label('Connection') - ->required() + ->nullable() + ->reactive() + ->selectablePlaceholder(false) ->default('Star') ->options(function (callable $get) { $plantId = $get('Plant'); @@ -920,8 +1111,7 @@ class TestingPanelReadingResource extends Resource ->toArray(); } }) - ->selectablePlaceholder(false) - ->reactive(), + ->required(), // .. TextInput::make('remark') ->label('Remark') @@ -933,7 +1123,9 @@ class TestingPanelReadingResource extends Resource ->placeholder(placeholder: 'Enter Batch Number'), Select::make('result') ->label('Search by Result') + ->nullable() ->searchable() + ->reactive() ->options(function () { return TestingPanelReading::query() ->whereNotNull('result') @@ -942,11 +1134,12 @@ class TestingPanelReadingResource extends Resource ->filter() // filters out nulls and empty automatically ->mapWithKeys(fn ($value) => [$value => $value]) ->toArray(); - }) - ->reactive(), + }), Select::make('tested_by') ->label('Tested By') ->nullable() + ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); if (! $plantId) { @@ -954,22 +1147,22 @@ class TestingPanelReadingResource extends Resource } else { return TestingPanelReading::where('plant_id', $plantId)->whereNotNull('tested_by')->select('tested_by')->distinct()->pluck('tested_by', 'tested_by'); } - }) - ->searchable() - ->reactive(), - DateTimePicker::make(name: 'created_from') + }), + DateTimePicker::make('created_from') ->label('Created From') - ->placeholder(placeholder: 'Select From DateTime') + ->placeholder('Select From DateTime') ->reactive() ->native(false), DateTimePicker::make('created_to') ->label('Created To') - ->placeholder(placeholder: 'Select To DateTime') + ->placeholder('Select To DateTime') ->reactive() ->native(false), Select::make('updated_by') ->label('Updated By') ->nullable() + ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); if (! $plantId) { @@ -977,17 +1170,15 @@ class TestingPanelReadingResource extends Resource } else { return TestingPanelReading::where('plant_id', $plantId)->whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by'); } - }) - ->searchable() - ->reactive(), - DateTimePicker::make(name: 'updated_from') + }), + DateTimePicker::make('updated_from') ->label('Updated From') - ->placeholder(placeholder: 'Select From DateTime') + ->placeholder('Select From DateTime') ->reactive() ->native(false), DateTimePicker::make('updated_to') ->label('Updated To') - ->placeholder(placeholder: 'Select To DateTime') + ->placeholder('Select To DateTime') ->reactive() ->native(false), ]) @@ -1141,7 +1332,7 @@ class TestingPanelReadingResource extends Resource $indicators[] = 'Subassembly Code: '.MotorTestingMaster::where('id', $data['subassembly_code'])->value('subassembly_code'); } if (! empty($data['output'])) { - $indicators[] = 'Output: '.$data['output']; + $indicators[] = 'Output ID: '.$data['output']; } if (! empty($data['item_description'])) { $item = Item::where('id', $data['item_description'])->first()?->description ?? null;