From 1687de2e80c650d539c682cc097ae0394a866cc8 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 14 Sep 2026 12:56:04 +0530 Subject: [PATCH] Updated default values and approver statuses on request characteristic resource file --- .../RequestCharacteristicResource.php | 123 +++++++++++------- 1 file changed, 78 insertions(+), 45 deletions(-) diff --git a/app/Filament/Resources/RequestCharacteristicResource.php b/app/Filament/Resources/RequestCharacteristicResource.php index e8c5f63..4a3491d 100644 --- a/app/Filament/Resources/RequestCharacteristicResource.php +++ b/app/Filament/Resources/RequestCharacteristicResource.php @@ -246,11 +246,11 @@ class RequestCharacteristicResource extends Resource } $set('updated_by', Filament::auth()->user()?->name); }) - ->default(function () { - $userHas = Filament::auth()->user()->plant_id; + // ->default(function () { + // $userHas = Filament::auth()->user()->plant_id; - return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->aufnr ?? null; - }) + // return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->aufnr ?? null; + // }) ->readOnly(fn ($get) => ($get('item_id') == null)) ->disabled(fn (Get $get) => ! empty($get('id'))), Forms\Components\TextInput::make('gernr') @@ -311,19 +311,24 @@ class RequestCharacteristicResource extends Resource $set('update_value', null); $set('updated_by', Filament::auth()->user()?->name); }) - ->default(function () { - $machineName = ''; - $reqId = RequestCharacteristic::latest()->first()?->characteristic_approver_master_id; - if ($reqId) { - $reqMac = CharacteristicApproverMaster::where('id', $reqId)->first()?->machine_name; - $machineName = $reqMac ?? null; - } else { - $machineName = null; - } + // ->default(function () { + // $machineName = ''; + // $reqId = RequestCharacteristic::latest()->first()?->characteristic_approver_master_id; + // if ($reqId) { + // $reqMac = CharacteristicApproverMaster::where('id', $reqId)->first()?->machine_name; + // $machineName = $reqMac ?? null; + // } else { + // $machineName = null; + // } + // $userHas = Filament::auth()->user()->plant_id; + + // return ($userHas && strlen($userHas) > 0) ? null : $machineName ?? null; + // }) + ->default(function () { $userHas = Filament::auth()->user()->plant_id; - return ($userHas && strlen($userHas) > 0) ? null : $machineName ?? null; + return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->characteristicApproverMaster->machine_name ?? null; }) ->afterStateHydrated(function ($component, $state, Get $get, Set $set) { if ($get('id')) { @@ -377,21 +382,15 @@ class RequestCharacteristicResource extends Resource } $set('updated_by', Filament::auth()->user()?->name); }) + // ->default(function () { + // $userHas = Filament::auth()->user()->plant_id; + + // return ($userHas && strlen($userHas) > 0) ? null : 'Characteristic'; + // }) ->default(function () { $userHas = Filament::auth()->user()->plant_id; - return ($userHas && strlen($userHas) > 0) ? null : 'Characteristic'; - // $approverType = null; - // $reqId = RequestCharacteristic::latest()->first()?->characteristic_approver_master_id; - // if ($reqId) { - // $reqTyp = CharacteristicApproverMaster::where('id', $reqId)->first()?->approver_type; - // $approverType = $reqTyp ?? null; - // } else { - // $approverType = null; - // } - - // // return optional(CharacteristicApproverMaster::latest()->first())->approver_type ?? null; - // return $approverType ?? null; + return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->characteristicApproverMaster->approver_type ?? null; }) ->afterStateHydrated(function ($component, $state, Get $get, Set $set) { if ($get('id')) { @@ -457,7 +456,11 @@ class RequestCharacteristicResource extends Resource $set('update_value', null); $set('updated_by', Filament::auth()->user()?->name); }) - ->default('MOTOR') + ->default(function () { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? null : optional(RequestCharacteristic::latest()->first())->model_type ?? null; + }) ->disabled(fn (Get $get) => ! empty($get('id'))), Section::make('Request Characteristic Details') // ->columnSpan(['default' => 2, 'sm' => 4]) @@ -577,11 +580,21 @@ class RequestCharacteristicResource extends Resource ->label('Approver Status') ->reactive() // ->live() - ->options([ - 'Approved' => 'Approved', - 'Hold' => 'Hold', - 'Rejected' => 'Rejected', - ]) + ->options(function (callable $set, callable $get) { + $apprTyp = $get('approver_type'); + + if ($apprTyp && $apprTyp == 'Stop') { + return [ + 'Approved' => 'Approved', + ]; + } + + return [ + 'Approved' => 'Approved', + 'Hold' => 'Hold', + 'Rejected' => 'Rejected', + ]; + }) ->afterStateUpdated(function ($state, callable $set, callable $get) { if ($state) {// && empty($get('approved1_at')) $set('approved1_at', now()->toDateTimeString()); // now()->format('d-m-Y H:i:s') @@ -618,7 +631,7 @@ class RequestCharacteristicResource extends Resource }), Forms\Components\TextInput::make('approver_remark1') ->label('Approver Remark') - ->live() + ->reactive() ->maxLength(60) ->afterStateUpdated(function ($state, callable $set, callable $get) { $appStat = $get('approver_status1'); @@ -693,11 +706,21 @@ class RequestCharacteristicResource extends Resource Forms\Components\Select::make('approver_status2') ->label('Approver Status') ->reactive() - ->options([ - 'Approved' => 'Approved', - 'Hold' => 'Hold', - 'Rejected' => 'Rejected', - ]) + ->options(function (callable $set, callable $get) { + $apprTyp = $get('approver_type'); + + if ($apprTyp && $apprTyp == 'Stop') { + return [ + 'Approved' => 'Approved', + ]; + } + + return [ + 'Approved' => 'Approved', + 'Hold' => 'Hold', + 'Rejected' => 'Rejected', + ]; + }) ->afterStateUpdated(function ($state, callable $set, callable $get) { if ($state) { $set('approved2_at', now()->toDateTimeString()); @@ -734,7 +757,7 @@ class RequestCharacteristicResource extends Resource }), Forms\Components\TextInput::make('approver_remark2') ->label('Approver Remark') - ->live() + ->reactive() ->maxLength(60) ->afterStateUpdated(function ($state, callable $set, callable $get) { $appStat = $get('approver_status2'); @@ -807,11 +830,21 @@ class RequestCharacteristicResource extends Resource Forms\Components\Select::make('approver_status3') ->label('Approver Status') ->reactive() - ->options([ - 'Approved' => 'Approved', - 'Hold' => 'Hold', - 'Rejected' => 'Rejected', - ]) + ->options(function (callable $set, callable $get) { + $apprTyp = $get('approver_type'); + + if ($apprTyp && $apprTyp == 'Stop') { + return [ + 'Approved' => 'Approved', + ]; + } + + return [ + 'Approved' => 'Approved', + 'Hold' => 'Hold', + 'Rejected' => 'Rejected', + ]; + }) ->afterStateUpdated(function ($state, callable $set, callable $get) { if ($state) { $set('approved3_at', now()->toDateTimeString()); @@ -847,7 +880,7 @@ class RequestCharacteristicResource extends Resource }), Forms\Components\TextInput::make('approver_remark3') ->label('Approver Remark') - ->live() + ->reactive() ->maxLength(60) ->afterStateUpdated(function ($state, callable $set, callable $get) { $appStat = $get('approver_status3');