From 1ef91af0d7469499c403b82711570d1334891310 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 3 Oct 2026 16:38:16 +0530 Subject: [PATCH 1/6] Added migration file to add rework_winded column in testing_panel_readings table --- ...column_in_testing_panel_readings_table.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 database/migrations/2026_10_01_165457_add_rework_winded_column_in_testing_panel_readings_table.php diff --git a/database/migrations/2026_10_01_165457_add_rework_winded_column_in_testing_panel_readings_table.php b/database/migrations/2026_10_01_165457_add_rework_winded_column_in_testing_panel_readings_table.php new file mode 100644 index 00000000..68267f5e --- /dev/null +++ b/database/migrations/2026_10_01_165457_add_rework_winded_column_in_testing_panel_readings_table.php @@ -0,0 +1,31 @@ + Date: Sat, 3 Oct 2026 16:47:25 +0530 Subject: [PATCH 2/6] Updated model file to add rework_winded column in testing_panel_readings table --- app/Models/TestingPanelReading.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/TestingPanelReading.php b/app/Models/TestingPanelReading.php index 991ee492..9450d85c 100644 --- a/app/Models/TestingPanelReading.php +++ b/app/Models/TestingPanelReading.php @@ -58,6 +58,7 @@ class TestingPanelReading extends Model 'result', 'remark', 'rework_count', + 'rework_winded', 'update_count', 'output_flag', 'tested_by', From 36dd327177ed88949c4974064b8bb22291a3969d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 3 Oct 2026 16:56:40 +0530 Subject: [PATCH 3/6] 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; From c410f37d3ddbfd1cc5e826e7a10931cacbb34bd1 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 3 Oct 2026 17:52:01 +0530 Subject: [PATCH 4/6] Updated importer / exporter file to add rework_winded and group work center column and Refactored design --- .../Exports/TestingPanelReadingExporter.php | 20 +- .../Imports/TestingPanelReadingImporter.php | 293 +++++++++++++++--- 2 files changed, 256 insertions(+), 57 deletions(-) diff --git a/app/Filament/Exports/TestingPanelReadingExporter.php b/app/Filament/Exports/TestingPanelReadingExporter.php index a14393f8..94a85f9e 100644 --- a/app/Filament/Exports/TestingPanelReadingExporter.php +++ b/app/Filament/Exports/TestingPanelReadingExporter.php @@ -28,16 +28,18 @@ class TestingPanelReadingExporter extends Exporter ->label('PLANT CODE'), ExportColumn::make('line.name') ->label('LINE NAME'), - ExportColumn::make('machine.name') - ->label('MACHINE NAME'), + ExportColumn::make('machine.workGroupMaster.name') + ->label('GROUP WORK CENTER'), + ExportColumn::make('machine.work_center') + ->label('WORK CENTER'), ExportColumn::make('motorTestingMaster.item.code') ->label('ITEM CODE'), ExportColumn::make('motorTestingMaster.item.description') ->label('MODEL DESCRIPTION'), ExportColumn::make('output') - ->label('OUTPUT NAME'), + ->label('OUTPUT ID'), ExportColumn::make('serial_number') - ->label('SERIAL NUMBER'), + ->label('MOTOR SERIAL NUMBER'), ExportColumn::make('winded_serial_number') ->label('WINDED SERIAL NUMBER'), ExportColumn::make('motorTestingMaster.kw') @@ -51,7 +53,7 @@ class TestingPanelReadingExporter extends Exporter ExportColumn::make('motorTestingMaster.isi_model') ->label('ISI MODEL'), ExportColumn::make('before_fr_volt') - ->label('BEFORE FR VOLT'), + ->label('BEFORE FR VOLTAGE'), ExportColumn::make('before_fr_cur') ->label('BEFORE FR CURRENT'), ExportColumn::make('before_fr_pow') @@ -75,7 +77,7 @@ class TestingPanelReadingExporter extends Exporter ExportColumn::make('before_fr_speed') ->label('BEFORE FR SPEED'), ExportColumn::make('after_fr_vol') - ->label('AFTER FR VOLT'), + ->label('AFTER FR VOLTAGE'), ExportColumn::make('after_fr_cur') ->label('AFTER FR CURRENT'), ExportColumn::make('after_fr_pow') @@ -103,13 +105,13 @@ class TestingPanelReadingExporter extends Exporter ExportColumn::make('after_fr_leak_cur') ->label('AFTER FR LEAK CURRENT'), ExportColumn::make('locked_rt_volt') - ->label('LOCKED RT VOLT'), + ->label('LOCKED RT VOLTAGE'), ExportColumn::make('locked_rt_cur') ->label('LOCKED RT CURRENT'), ExportColumn::make('locked_rt_pow') ->label('LOCKED RT POWER'), ExportColumn::make('no_load_pickup_volt') - ->label('NO LOAD PICKUP VOLT'), + ->label('NO LOAD PICKUP VOLTAGE'), ExportColumn::make('room_temperature') ->label('ROOM TEMPERATURE'), ExportColumn::make('hv_test') @@ -124,6 +126,8 @@ class TestingPanelReadingExporter extends Exporter ->label('REMARK'), ExportColumn::make('rework_count') ->label('REWORK COUNT'), + ExportColumn::make('rework_winded') + ->label('REWORK WINDED STATUS'), ExportColumn::make('update_count') ->label('UPDATED COUNT'), ExportColumn::make('output_flag') diff --git a/app/Filament/Imports/TestingPanelReadingImporter.php b/app/Filament/Imports/TestingPanelReadingImporter.php index ccc3882d..e16f021c 100644 --- a/app/Filament/Imports/TestingPanelReadingImporter.php +++ b/app/Filament/Imports/TestingPanelReadingImporter.php @@ -14,88 +14,283 @@ class TestingPanelReadingImporter extends Importer public static function getColumns(): array { return [ - ImportColumn::make('machine') + ImportColumn::make('plant') ->requiredMapping() + ->label('PLANT CODE') + ->exampleHeader('PLANT CODE') + ->example(['1000']) + ->relationship(resolveUsing: 'code') + ->rules(['required']), + ImportColumn::make('line') + ->requiredMapping() + ->label('LINE NAME') + ->exampleHeader('LINE NAME') + ->example(['4 inch pump line']) + ->relationship(resolveUsing: 'name') + ->rules(['required']), + ImportColumn::make('machine.workGroupMaster.name') + ->requiredMapping() + ->label('GROUP WORK CENTER') + ->exampleHeader('GROUP WORK CENTER') + ->example('TESTGMG01') ->relationship() ->rules(['required']), + ImportColumn::make('machine.work_center') + ->requiredMapping() + ->label('WORK CENTER') + ->exampleHeader('WORK CENTER') + ->example('TESTIMG01') + ->relationship() // resolveUsing: 'work_center' + ->rules(['required']), ImportColumn::make('motorTestingMaster.item.code') ->requiredMapping() + ->label('ITEM CODE') + ->exampleHeader('ITEM CODE') + ->example('ITEM001') ->relationship() ->rules(['required']), ImportColumn::make('output') ->requiredMapping() + ->label('OUTPUT ID') + ->exampleHeader('OUTPUT ID') + ->example('Output1') ->rules(['required']), ImportColumn::make('serial_number') ->requiredMapping() + ->label('MOTOR SERIAL NUMBER') + ->exampleHeader('MOTOR SERIAL NUMBER') + ->example('12345678901234') ->rules(['required']), ImportColumn::make('winded_serial_number') ->requiredMapping() + ->label('WINDED SERIAL NUMBER') + ->exampleHeader('WINDED SERIAL NUMBER') + ->example('98765432101234') + ->rules(['required']), + ImportColumn::make('before_fr_volt') + ->requiredMapping() + ->label('BEFORE FR VOLTAGE') + ->exampleHeader('BEFORE FR VOLTAGE') + ->example('0'), + ImportColumn::make('before_fr_cur') + ->requiredMapping() + ->label('BEFORE FR CURRENT') + ->exampleHeader('BEFORE FR CURRENT') + ->example('0'), + ImportColumn::make('before_fr_pow') + ->requiredMapping() + ->label('BEFORE FR POWER') + ->exampleHeader('BEFORE FR POWER') + ->example('0'), + ImportColumn::make('before_fr_res_ry') + ->requiredMapping() + ->label('BEFORE FR RESISTANCE RY') + ->exampleHeader('BEFORE FR RESISTANCE RY') + ->example('0'), + ImportColumn::make('before_fr_res_yb') + ->requiredMapping() + ->label('BEFORE FR RESISTANCE YB') + ->exampleHeader('BEFORE FR RESISTANCE YB') + ->example('0'), + ImportColumn::make('before_fr_res_br') + ->requiredMapping() + ->label('BEFORE FR RESISTANCE BR') + ->exampleHeader('BEFORE FR RESISTANCE BR') + ->example('0'), + ImportColumn::make('before_fr_ir') + ->requiredMapping() + ->label('BEFORE FR IR') + ->exampleHeader('BEFORE FR IR') + ->example('0'), + ImportColumn::make('before_fr_ir_r') + ->requiredMapping() + ->label('BEFORE FR IR R') + ->exampleHeader('BEFORE FR IR R') + ->example('0'), + ImportColumn::make('before_fr_ir_y') + ->requiredMapping() + ->label('BEFORE FR IR Y') + ->exampleHeader('BEFORE FR IR Y') + ->example('0'), + ImportColumn::make('before_fr_ir_b') + ->requiredMapping() + ->label('BEFORE FR IR B') + ->exampleHeader('BEFORE FR IR B') + ->example('0'), + ImportColumn::make('before_fr_freq') + ->requiredMapping() + ->label('BEFORE FR FREQUENCY') + ->exampleHeader('BEFORE FR FREQUENCY') + ->example('0'), + ImportColumn::make('before_fr_speed') + ->requiredMapping() + ->label('BEFORE FR SPEED') + ->exampleHeader('BEFORE FR SPEED') + ->example('0'), + ImportColumn::make('after_fr_vol') + ->requiredMapping() + ->label('AFTER FR VOLTAGE') + ->exampleHeader('AFTER FR VOLTAGE') + ->example('0'), + ImportColumn::make('after_fr_cur') + ->requiredMapping() + ->label('AFTER FR CURRENT') + ->exampleHeader('AFTER FR CURRENT') + ->example('0'), + ImportColumn::make('after_fr_pow') + ->requiredMapping() + ->label('AFTER FR POWER') + ->exampleHeader('AFTER FR POWER') + ->example('0'), + ImportColumn::make('after_fr_ir_hot') + ->requiredMapping() + ->label('AFTER FR IR HOT') + ->exampleHeader('AFTER FR IR HOT') + ->example('0'), + ImportColumn::make('after_fr_ir_hot_r') + ->requiredMapping() + ->label('AFTER FR IR HOT R') + ->exampleHeader('AFTER FR IR HOT R') + ->example('0'), + ImportColumn::make('after_fr_ir_hot_y') + ->requiredMapping() + ->label('AFTER FR IR HOT Y') + ->exampleHeader('AFTER FR IR HOT Y') + ->example('0'), + ImportColumn::make('after_fr_ir_hot_b') + ->requiredMapping() + ->label('AFTER FR IR HOT B') + ->exampleHeader('AFTER FR IR HOT B') + ->example('0'), + ImportColumn::make('after_fr_ir_cool') + ->requiredMapping() + ->label('AFTER FR IR COOL') + ->exampleHeader('AFTER FR IR COOL') + ->example('0'), + ImportColumn::make('after_fr_ir_cool_r') + ->requiredMapping() + ->label('AFTER FR IR COOL R') + ->exampleHeader('AFTER FR IR COOL R') + ->example('0'), + ImportColumn::make('after_fr_ir_cool_y') + ->requiredMapping() + ->label('AFTER FR IR COOL Y') + ->exampleHeader('AFTER FR IR COOL Y') + ->example('0'), + ImportColumn::make('after_fr_ir_cool_b') + ->requiredMapping() + ->label('AFTER FR IR COOL B') + ->exampleHeader('AFTER FR IR COOL B') + ->example('0'), + ImportColumn::make('after_fr_freq') + ->requiredMapping() + ->label('AFTER FR FREQUENCY') + ->exampleHeader('AFTER FR FREQUENCY') + ->example('0'), + ImportColumn::make('after_fr_speed') + ->requiredMapping() + ->label('AFTER FR SPEED') + ->exampleHeader('AFTER FR SPEED') + ->example('0'), + ImportColumn::make('after_fr_leak_cur') + ->requiredMapping() + ->label('AFTER FR LEAK CURRENT') + ->exampleHeader('AFTER FR LEAK CURRENT') + ->example('0'), + ImportColumn::make('locked_rt_volt') + ->requiredMapping() + ->label('LOCKED RT VOLTAGE') + ->exampleHeader('LOCKED RT VOLTAGE') + ->example('0'), + ImportColumn::make('locked_rt_cur') + ->requiredMapping() + ->label('LOCKED RT CURRENT') + ->exampleHeader('LOCKED RT CURRENT') + ->example('0'), + ImportColumn::make('locked_rt_pow') + ->requiredMapping() + ->label('LOCKED RT POWER') + ->exampleHeader('LOCKED RT POWER') + ->example('0'), + ImportColumn::make('no_load_pickup_volt') + ->requiredMapping() + ->label('NO LOAD PICKUP VOLTAGE') + ->exampleHeader('NO LOAD PICKUP VOLTAGE') + ->example('0'), + ImportColumn::make('room_temperature') + ->requiredMapping() + ->label('ROOM TEMPERATURE') + ->exampleHeader('ROOM TEMPERATURE') + ->example('0'), + ImportColumn::make('hv_test') + ->requiredMapping() + ->label('HIGH VOLTAGE TEST') + ->exampleHeader('HIGH VOLTAGE TEST') + ->example('Not With Stood') + ->rules(['required']), + ImportColumn::make('batch_number') + ->requiredMapping() + ->label('BATCH NUMBER') + ->exampleHeader('BATCH NUMBER') + ->example('261231B001') ->rules(['required']), - ImportColumn::make('before_fr_volt'), - ImportColumn::make('before_fr_cur'), - ImportColumn::make('before_fr_pow'), - ImportColumn::make('before_fr_res_ry'), - ImportColumn::make('before_fr_res_yb'), - ImportColumn::make('before_fr_res_br'), - ImportColumn::make('before_fr_ir'), - ImportColumn::make('before_fr_ir_r'), - ImportColumn::make('before_fr_ir_y'), - ImportColumn::make('before_fr_ir_b'), - ImportColumn::make('before_fr_freq'), - ImportColumn::make('before_fr_speed'), - ImportColumn::make('after_fr_vol'), - ImportColumn::make('after_fr_cur'), - ImportColumn::make('after_fr_pow'), - ImportColumn::make('after_fr_ir_hot'), - ImportColumn::make('after_fr_ir_hot_r'), - ImportColumn::make('after_fr_ir_hot_y'), - ImportColumn::make('after_fr_ir_hot_b'), - ImportColumn::make('after_fr_ir_cool'), - ImportColumn::make('after_fr_ir_cool_r'), - ImportColumn::make('after_fr_ir_cool_y'), - ImportColumn::make('after_fr_ir_cool_b'), - ImportColumn::make('after_fr_freq'), - ImportColumn::make('after_fr_speed'), - ImportColumn::make('after_fr_leak_cur'), - ImportColumn::make('locked_rt_volt'), - ImportColumn::make('locked_rt_cur'), - ImportColumn::make('locked_rt_pow'), - ImportColumn::make('no_load_pickup_volt'), - ImportColumn::make('room_temperature'), - ImportColumn::make('hv_test'), - ImportColumn::make('batch_number'), ImportColumn::make('batch_count') ->requiredMapping() + ->label('BATCH COUNT') + ->exampleHeader('BATCH COUNT') + ->example('1') ->rules(['required']), - ImportColumn::make('result'), - ImportColumn::make('remark'), + ImportColumn::make('result') + ->requiredMapping() + ->label('RESULT') + ->exampleHeader('RESULT') + ->example('FAIL') + ->rules(['required']), + ImportColumn::make('remark') + ->requiredMapping() + ->label('REMARK') + ->exampleHeader('REMARK') + ->example('Testing Remark'), ImportColumn::make('rework_count') ->requiredMapping() + ->label('REWORK COUNT') + ->exampleHeader('REWORK COUNT') + ->example('0') + ->rules(['required']), + ImportColumn::make('rework_winded') + ->requiredMapping() + ->label('REWORK WINDED STATUS') + ->exampleHeader('REWORK WINDED STATUS') + ->example('0') ->rules(['required']), ImportColumn::make('update_count') ->requiredMapping() + ->label('UPDATED COUNT') + ->exampleHeader('UPDATED COUNT') + ->example('0') ->rules(['required']), ImportColumn::make('output_flag') ->requiredMapping() + ->label('OUTPUT FLAG') + ->exampleHeader('OUTPUT FLAG') + ->example('0') ->rules(['required']), - ImportColumn::make('line') + ImportColumn::make('tested_by') ->requiredMapping() - ->relationship(resolveUsing: 'name') - ->exampleHeader('Line Name') - ->example(['4 inch pump line']) - ->label('Line Name') + ->label('TESTED BY') + ->exampleHeader('TESTED BY') + ->example('RAW01234') ->rules(['required']), - ImportColumn::make('plant') + ImportColumn::make('updated_by') ->requiredMapping() - ->relationship(resolveUsing: 'code') - ->exampleHeader('Plant Code') - ->example(['1000']) - ->label('Plant Code') - ->rules(['required']), - ImportColumn::make('tested_by'), - ImportColumn::make('updated_by'), + ->label('UPDATED BY') + ->exampleHeader('UPDATED BY') + ->example('RAW01234'), ImportColumn::make('scanned_at') ->requiredMapping() + ->label('SCANNED AT') + ->exampleHeader('SCANNED AT') + ->example('01-01-2026 00:08:00') ->rules(['required']), ]; } From 693a97cf78f337c11f04ff6a2521f0150c2564b9 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 3 Oct 2026 17:59:26 +0530 Subject: [PATCH 5/6] Refactored validations and design in resource file --- .../Resources/BeforeTestReadingResource.php | 304 ++++++++++-------- 1 file changed, 178 insertions(+), 126 deletions(-) diff --git a/app/Filament/Resources/BeforeTestReadingResource.php b/app/Filament/Resources/BeforeTestReadingResource.php index c3e89041..eba48fb2 100644 --- a/app/Filament/Resources/BeforeTestReadingResource.php +++ b/app/Filament/Resources/BeforeTestReadingResource.php @@ -11,6 +11,7 @@ use App\Models\Line; use App\Models\Machine; use App\Models\MotorTestingMaster; use App\Models\Plant; +use Closure; use Filament\Facades\Filament; use Filament\Forms; use Filament\Forms\Components\DateTimePicker; @@ -26,6 +27,7 @@ use Filament\Tables\Filters\Filter; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; +use Illuminate\Support\Str; class BeforeTestReadingResource extends Resource { @@ -47,33 +49,29 @@ class BeforeTestReadingResource extends Resource ->label('Plant Name') ->relationship('plant', 'name') ->columnSpan(1) // (['default' => 1, 'sm' => 2]) - ->searchable() - ->required() ->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(BeforeTestReading::latest()->first())->plant_id ?? null; - }) ->disabled(fn (Get $get) => ! empty($get('id'))) + ->default(function () { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? $userHas : optional(BeforeTestReading::latest()->first())->plant_id ?? null; + }) ->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; } else { - $set('line_id', null); - $set('motor_testing_master_id', null); - $set('machine_id', null); $set('tPrError', null); } + $set('line_id', null); + $set('motor_testing_master_id', null); + $set('machine_id', null); $set('updated_by', Filament::auth()->user()?->name); }) @@ -81,10 +79,12 @@ class BeforeTestReadingResource extends Resource 'class' => $get('tPrError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('tPrError') ? $get('tPrError') : null) - ->hintColor('danger'), + ->hintColor('danger') + ->required(), Forms\Components\Select::make('line_id') ->label('Line Name') - // ->relationship('line', 'name') + // ->relationship('line', 'name') + ->columnSpan(1) ->searchable() ->options(function (callable $get) { $plantId = $get('plant_id'); @@ -92,24 +92,29 @@ class BeforeTestReadingResource extends Resource return []; } - return Line::where('plant_id', $plantId) - ->pluck('name', 'id') - ->toArray(); - }) - ->default(function () { - return optional(BeforeTestReading::latest()->first())->line_id ?? null; + return Line::where('plant_id', $plantId)->pluck('name', 'id')->toArray(); }) ->disabled(fn (Get $get) => ! empty($get('id'))) - ->required() + ->default(function (callable $get) { + $plantId = $get('plant_id'); + if (empty($plantId)) { + return null; + } + + return BeforeTestReading::where('plant_id', $plantId)->latest()->first()->line_id ?? null; + }) ->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); - }), + }) + ->required(), Forms\Components\Select::make('machine_id') ->label('Work Center') - // ->relationship('machine', 'work_center') + // ->relationship('machine', 'work_center') + ->columnSpan(1) + ->reactive() ->searchable() ->options(function (callable $get) { $lineId = $get('line_id'); @@ -118,34 +123,39 @@ class BeforeTestReadingResource extends Resource } // Only show machines for the selected line - return Machine::where('line_id', $lineId) - ->pluck('work_center', 'id') - ->toArray(); - }) - ->default(function () { - return optional(BeforeTestReading::latest()->first())->machine_id ?? null; + return Machine::where('line_id', $lineId)->pluck('work_center', 'id')->toArray(); }) ->disabled(fn (Get $get) => ! empty($get('id'))) - ->required() - ->reactive() + ->default(function (callable $get) { + $plantId = $get('plant_id'); + if (empty($plantId)) { + return null; + } + + return BeforeTestReading::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') - // ->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(); - // }) + // ->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) { @@ -159,42 +169,83 @@ class BeforeTestReadingResource extends Resource ->pluck('items.code', 'motor_testing_masters.id') ->toArray(); }) - // ->getOptionLabelUsing(fn ($value) => - // MotorTestingMaster::with('item')->find($value)?->item?->code - // ) - ->required() - ->searchable() - ->reactive() + ->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('serial_number') ->label('Serial Number') - ->required() + ->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('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('tested_by') + ->label('Tested By') + ->columnSpan(1) ->default(fn () => Filament::auth()->user()?->name) ->readOnly() ->required(), @@ -232,6 +283,9 @@ class BeforeTestReadingResource 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(), @@ -244,9 +298,20 @@ class BeforeTestReadingResource 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('serial_number') ->label('Serial Number') ->alignCenter() + ->searchable() ->sortable(), Tables\Columns\TextColumn::make('motorTestingMaster.kw') ->label('KW') @@ -288,8 +353,7 @@ class BeforeTestReadingResource 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() @@ -297,8 +361,7 @@ class BeforeTestReadingResource 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() @@ -306,6 +369,7 @@ class BeforeTestReadingResource extends Resource ->dateTime() ->toggleable(isToggledHiddenByDefault: true), ]) + ->searchPlaceholder('Search by Serial Number') ->filters([ Tables\Filters\TrashedFilter::make(), Filter::make('advanced_filters') @@ -313,8 +377,9 @@ class BeforeTestReadingResource 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; @@ -329,7 +394,6 @@ class BeforeTestReadingResource 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); @@ -337,26 +401,25 @@ class BeforeTestReadingResource 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'); @@ -365,31 +428,26 @@ class BeforeTestReadingResource 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); }), @@ -399,57 +457,52 @@ class BeforeTestReadingResource 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('beforeTestReadings', 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('beforeTestReadings', 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); }), 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('connection') ->label('Connection') - ->required() + ->nullable() + ->reactive() + ->selectablePlaceholder(false) ->default('Star') ->options(function (callable $get) { $plantId = $get('Plant'); @@ -466,11 +519,12 @@ class BeforeTestReadingResource extends Resource ->toArray(); } }) - ->selectablePlaceholder(false) - ->reactive(), + ->required(), Select::make('tested_by') ->label('Tested By') ->nullable() + ->searchable() + ->reactive() ->options(function (callable $get) { $plantId = $get('Plant'); if (! $plantId) { @@ -478,22 +532,22 @@ class BeforeTestReadingResource extends Resource } else { return BeforeTestReading::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) { @@ -501,17 +555,15 @@ class BeforeTestReadingResource extends Resource } else { return BeforeTestReading::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), ]) From 393153b8987853c36e36a36921df027be9c71d7d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 3 Oct 2026 18:05:21 +0530 Subject: [PATCH 6/6] Added rework_winded column in Motor Testing Panel Post API and Refactored validations in TestingPanelController --- .../Controllers/TestingPanelController.php | 246 ++++++++++-------- 1 file changed, 143 insertions(+), 103 deletions(-) diff --git a/app/Http/Controllers/TestingPanelController.php b/app/Http/Controllers/TestingPanelController.php index 3c230d93..cef11017 100644 --- a/app/Http/Controllers/TestingPanelController.php +++ b/app/Http/Controllers/TestingPanelController.php @@ -48,21 +48,67 @@ class TestingPanelController extends Controller $data = $request->all(); - if ($data['plant_code'] == null || $data['plant_code'] == '') { - // return response("ERROR: Please provide a valid plant code.", 400) - // ->header('Content-Type', 'text/plain'); + $plantCode = $data['plant_code'] ?? null; + $groupWorkCenter = $data['line_name'] ?? null; + $workCenter = $data['machine_name'] ?? null; + + if ($plantCode == null || $plantCode == '' || ! $plantCode) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", - ], 404); - } elseif (Str::length($data['plant_code']) < 4 || ! is_numeric($data['plant_code']) || ! preg_match('/^[1-9]\d{3,}$/', $data['plant_code'])) {// !ctype_digit($data['plant_code']) + ], 400); + } elseif (! is_numeric($plantCode)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Invalid plant code found!', + 'status_description' => "Plant code '{$plantCode}' should contain only numeric values!", + ], 400); + } elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!", + ], 400); + } elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Invalid plant code '{$plantCode}' found!", + ], 400); + } + + if ($groupWorkCenter == null || $groupWorkCenter == '' || ! $groupWorkCenter) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Group work center can't be empty!", + ], 404); + } elseif (Str::length($groupWorkCenter) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Group work center '{$groupWorkCenter}' should contain minimum 6 characters!", + ], 404); + } elseif (! ctype_alnum($groupWorkCenter)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Group work center '{$groupWorkCenter}' should contain only alpha-numeric values!", ], 404); } - $plant = Plant::where('code', $data['plant_code'])->first(); + if ($workCenter == null || $workCenter == '' || ! $workCenter) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center can't be empty!", + ], 404); + } elseif (Str::length($workCenter) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center '{$workCenter}' should contain minimum 6 characters!", + ], 404); + } elseif (! ctype_alnum($workCenter)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center '{$workCenter}' should contain only alpha-numeric values!", + ], 404); + } + + $plant = Plant::where('code', $plantCode)->first(); if (! $plant) { // return response("Plant not found.", 400)->header('Content-Type', 'text/plain'); return response()->json([ @@ -74,19 +120,7 @@ class TestingPanelController extends Controller $plantId = $plant->id; $plantName = $plant->name; - if ($data['line_name'] == null || $data['line_name'] == '') { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => "Group work center can't be empty!", - ], 404); - } elseif (Str::length($data['line_name']) < 0) { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => 'Invalid group work center found!', - ], 404); - } - - $gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->first(); + $gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->first(); if (! $gWorkCenter) { return response()->json([ 'status_code' => 'ERROR', @@ -94,30 +128,18 @@ class TestingPanelController extends Controller ], 404); } - $gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->where('plant_id', $plantId)->first(); + $gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->where('plant_id', $plantId)->first(); if (! $gWorkCenter) { - // return response( "Line not found for the specified plant : {$data['plant_code']}",400)->header('Content-Type', 'text/plain'); + // return response( "Line not found for the specified plant : {$plantCode}",400)->header('Content-Type', 'text/plain'); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Group work center not found for the specified plant : '{$data['plant_code']}'!", + 'status_description' => "Group work center not found for the specified plant : '{$plantCode}'!", ], 404); } $gWorkCenterId = $gWorkCenter->id; - if ($data['machine_name'] == null || $data['machine_name'] == '') { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => "Work center can't be empty!", - ], 404); - } elseif (Str::length($data['machine_name']) < 0) { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => 'Invalid work center found!', - ], 404); - } - - $machine = Machine::where('work_center', $data['machine_name'])->first(); + $machine = Machine::where('work_center', $workCenter)->first(); if (! $machine) { return response()->json([ 'status_code' => 'ERROR', @@ -125,29 +147,29 @@ class TestingPanelController extends Controller ], 404); } - $machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->first(); + $machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->first(); if (! $machine) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Work center not found for the specified plant : '{$data['plant_code']}'!", + 'status_description' => "Work center not found for the specified plant : '{$plantCode}'!", ], 404); } - $machine = Machine::where('work_center', $data['machine_name'])->where('work_group_master_id', $gWorkCenterId)->first(); + $machine = Machine::where('work_center', $workCenter)->where('work_group_master_id', $gWorkCenterId)->first(); if (! $machine) { - // return response("Machine not found for the specified line : {$data['line_name']}", 400)->header('Content-Type', 'text/plain'); + // return response("Machine not found for the specified line : {$groupWorkCenter}", 400)->header('Content-Type', 'text/plain'); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Work center not found for the specified Group work center : '{$data['line_name']}'!", + 'status_description' => "Work center not found for the specified Group work center : '{$groupWorkCenter}'!", ], 404); } - $machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first(); + $machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first(); if (! $machine) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Work center not found for the specified Plant : '{$data['plant_code']}' and Group work center : '{$data['line_name']}'!", + 'status_description' => "Work center not found for the specified Plant : '{$plantCode}' and Group work center : '{$groupWorkCenter}'!", ], 404); } @@ -255,7 +277,7 @@ class TestingPanelController extends Controller $newUpdateCount = ($lastUpdateCount == null || $lastUpdateCount == '') ? 0 : (int) $lastUpdateCount?->update_count + 1; // $maxUpdateCount?->update_count - $updateCountString = (string) $newUpdateCount; + // $updateCountString = (string) $newUpdateCount; $row = [ 'plant_id' => $plantId, @@ -302,13 +324,14 @@ class TestingPanelController extends Controller 'result' => $serial['result'] ?? null, 'remark' => $serial['remark'] ?? null, 'rework_count' => $serial['rework_count'] ?? 0, + 'rework_winded' => $serial['rework_winded'] ?? 0, 'output_flag' => $serial['output_flag'] ?? 0, - 'tested_by' => $serial['tested_by'] ?? null, - 'updated_by' => $serial['updated_by'] ?? null, + 'tested_by' => (($serial['tested_by'] == 'jothi') ? 'Admin' : $serial['tested_by']) ?? null, + 'updated_by' => (($serial['updated_by'] == 'jothi') ? 'Admin' : $serial['updated_by']) ?? null, 'created_at' => $serial['created_at'] ?? null, 'updated_at' => $serial['updated_at'] ?? $serial['created_at'], 'scanned_at' => $serial['scanned_at'] ?? null, - 'update_count' => $updateCountString, + 'update_count' => (string) $newUpdateCount, ]; // Insert the new record @@ -365,9 +388,9 @@ class TestingPanelController extends Controller $data = $request->all(); - $plantCode = $data['plant_code'] ?? ''; - $itemCode = $data['item_code'] ?? ''; - $serialNumber = $data['serial_number'] ?? ''; + $plantCode = $data['plant_code'] ?? null; + $itemCode = $data['item_code'] ?? null; + $serialNumber = $data['serial_number'] ?? null; $testStatus = $data['test_status'] ?? 'F'; if ($plantCode == null || $plantCode == '' || ! $plantCode) { @@ -686,22 +709,67 @@ class TestingPanelController extends Controller } $data = $request->all(); + $plantCode = $data['plant_code'] ?? null; + $groupWorkCenter = $data['line_name'] ?? null; + $workCenter = $data['machine_name'] ?? null; - if ($data['plant_code'] == null || $data['plant_code'] == '') { - // return response("ERROR: Please provide a valid plant code.", 400) - // ->header('Content-Type', 'text/plain'); + if ($plantCode == null || $plantCode == '' || ! $plantCode) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", - ], 404); - } elseif (Str::length($data['plant_code']) < 4 || ! is_numeric($data['plant_code']) || ! preg_match('/^[1-9]\d{3,}$/', $data['plant_code'])) {// !ctype_digit($data['plant_code']) + ], 400); + } elseif (! is_numeric($plantCode)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Invalid plant code found!', + 'status_description' => "Plant code '{$plantCode}' should contain only numeric values!", + ], 400); + } elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!", + ], 400); + } elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Invalid plant code '{$plantCode}' found!", + ], 400); + } + + if ($groupWorkCenter == null || $groupWorkCenter == '' || ! $groupWorkCenter) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Group work center can't be empty!", + ], 404); + } elseif (Str::length($groupWorkCenter) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Group work center '{$groupWorkCenter}' should contain minimum 6 characters!", + ], 404); + } elseif (! ctype_alnum($groupWorkCenter)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Group work center '{$groupWorkCenter}' should contain only alpha-numeric values!", ], 404); } - $plant = Plant::where('code', $data['plant_code'])->first(); + if ($workCenter == null || $workCenter == '' || ! $workCenter) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center can't be empty!", + ], 404); + } elseif (Str::length($workCenter) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center '{$workCenter}' should contain minimum 6 characters!", + ], 404); + } elseif (! ctype_alnum($workCenter)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Work center '{$workCenter}' should contain only alpha-numeric values!", + ], 404); + } + + $plant = Plant::where('code', $plantCode)->first(); if (! $plant) { // return response("Plant not found.", 400)->header('Content-Type', 'text/plain'); return response()->json([ @@ -713,19 +781,7 @@ class TestingPanelController extends Controller $plantId = $plant->id; $plantName = $plant->name; - if ($data['line_name'] == null || $data['line_name'] == '') { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => "Group work center can't be empty!", - ], 404); - } elseif (Str::length($data['line_name']) < 0) { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => 'Invalid group work center found!', - ], 404); - } - - $gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->first(); + $gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->first(); if (! $gWorkCenter) { return response()->json([ 'status_code' => 'ERROR', @@ -733,30 +789,18 @@ class TestingPanelController extends Controller ], 404); } - $gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->where('plant_id', $plantId)->first(); + $gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->where('plant_id', $plantId)->first(); if (! $gWorkCenter) { - // return response( "Line not found for the specified plant : {$data['plant_code']}",400)->header('Content-Type', 'text/plain'); + // return response( "Line not found for the specified plant : {$plantCode}",400)->header('Content-Type', 'text/plain'); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Group work center not found for the specified plant : '{$data['plant_code']}'!", + 'status_description' => "Group work center not found for the specified plant : '{$plantCode}'!", ], 404); } $gWorkCenterId = $gWorkCenter->id; - if ($data['machine_name'] == null || $data['machine_name'] == '') { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => "Work center can't be empty!", - ], 404); - } elseif (Str::length($data['machine_name']) < 0) { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => 'Invalid work center found!', - ], 404); - } - - $machine = Machine::where('work_center', $data['machine_name'])->first(); + $machine = Machine::where('work_center', $workCenter)->first(); if (! $machine) { return response()->json([ 'status_code' => 'ERROR', @@ -764,29 +808,29 @@ class TestingPanelController extends Controller ], 404); } - $machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->first(); + $machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->first(); if (! $machine) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Work center not found for the specified plant : '{$data['plant_code']}'!", + 'status_description' => "Work center not found for the specified plant : '{$plantCode}'!", ], 404); } - $machine = Machine::where('work_center', $data['machine_name'])->where('work_group_master_id', $gWorkCenterId)->first(); + $machine = Machine::where('work_center', $workCenter)->where('work_group_master_id', $gWorkCenterId)->first(); if (! $machine) { - // return response("Machine not found for the specified line : {$data['line_name']}", 400)->header('Content-Type', 'text/plain'); + // return response("Machine not found for the specified line : {$groupWorkCenter}", 400)->header('Content-Type', 'text/plain'); return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Work center not found for the specified Group work center : '{$data['line_name']}'!", + 'status_description' => "Work center not found for the specified Group work center : '{$groupWorkCenter}'!", ], 404); } - $machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first(); + $machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first(); if (! $machine) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Work center not found for the specified Plant : '{$data['plant_code']}' and Group work center : '{$data['line_name']}'!", + 'status_description' => "Work center not found for the specified Plant : '{$plantCode}' and Group work center : '{$groupWorkCenter}'!", ], 404); } @@ -1478,7 +1522,7 @@ class TestingPanelController extends Controller 'flow_reading' => $entry['flow_reading'] ?? '0', 'current' => $entry['current'] ?? '0', 'watt' => $entry['watt'] ?? '0', - 'tested_by' => $entry['created_by'] ?? $userName, + 'tested_by' => (($entry['created_by'] == 'Admin') ? 'jothi' : $entry['created_by']) ?? $userName, 'created_datetime' => ! empty($entry['created_at']) ? Carbon::parse($entry['created_at'])->setTimezone('Asia/Kolkata')->format('Y-m-d H:i:s') : now('Asia/Kolkata')->format('Y-m-d H:i:s'), ]; }, $pumpTestingEntries ?? []), @@ -1704,8 +1748,7 @@ class TestingPanelController extends Controller $flow_reading = $entry['flow_reading'] ?? '0'; $current = $entry['current'] ?? '0'; $watt = $entry['watt'] ?? '0'; - $tested_by = $entry['tested_by'] ?? $userName; - $tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by; + $tested_by = (($entry['tested_by'] == 'jothi') ? 'Admin' : $entry['tested_by']) ?? $userName; // $pendingExists = PumpTestingEntry::where('plant_id', $plantId)->where('pump_serial_number', $pumpSerial)->where('pump_testing_master_id', $pumpMasterId)->where('tested_type', $testedType)->where('sl_no', $sl_no)->first(); $cnt++; @@ -1780,8 +1823,7 @@ class TestingPanelController extends Controller $flow_reading = $entry['flow_reading'] ?? '0'; $current = $entry['current'] ?? '0'; $watt = $entry['watt'] ?? '0'; - $tested_by = $entry['tested_by'] ?? $userName; - $tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by; + $tested_by = (($entry['tested_by'] == 'jothi') ? 'Admin' : $entry['tested_by']) ?? $userName; $createdRows++; PumpTestingEntry::create([ @@ -2043,7 +2085,7 @@ class TestingPanelController extends Controller 'flow_reading' => $result['discharge'] ?? '0', 'current' => $result['current'] ?? '0', 'watt' => (string) (($result['watt'] ?? '0') * 1000), - 'tested_by' => $result['created_by'] ?? $userName, + 'tested_by' => (($result['created_by'] == 'Admin') ? 'jothi' : $result['created_by']) ?? $userName, 'created_datetime' => ! empty($result['created_at']) ? Carbon::parse($result['created_at'])->setTimezone('Asia/Kolkata')->format('Y-m-d H:i:s') : now('Asia/Kolkata')->format('Y-m-d H:i:s'), ]; }, $pumpTestingResults ?? []), @@ -2277,8 +2319,7 @@ class TestingPanelController extends Controller $power_p2 = $result['power_p2'] ?? '0'; $overall_efficiency = $result['overall_efficiency'] ?? '0'; $pump_efficiency = $result['pump_efficiency'] ?? '0'; - $tested_by = $result['tested_by'] ?? $userName; - $tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by; + $tested_by = (($result['tested_by'] == 'jothi') ? 'Admin' : $result['tested_by']) ?? $userName; // $pendingExists = PumpTestingResult::where('plant_id', $plantId)->where('pump_serial_number', $pumpSerial)->where('pump_testing_master_id', $pumpMasterId)->where('tested_type', $testedType)->where('sl_no', $sl_no)->first(); $cnt++; @@ -2368,8 +2409,7 @@ class TestingPanelController extends Controller $power_p2 = $result['power_p2'] ?? '0'; $overall_efficiency = $result['overall_efficiency'] ?? '0'; $pump_efficiency = $result['pump_efficiency'] ?? '0'; - $tested_by = $result['tested_by'] ?? $userName; - $tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by; + $tested_by = (($result['tested_by'] == 'jothi') ? 'Admin' : $result['tested_by']) ?? $userName; $createdRows++; PumpTestingResult::create([