Updated label and updated_by user name on edit and plant load logic updated on filter
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-04-02 12:52:43 +05:30
parent 75b88e4b8a
commit e90973ea23
2 changed files with 148 additions and 36 deletions

View File

@@ -42,9 +42,10 @@ class MotorTestingMasterResource extends Resource
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->label('Plant Name')
->relationship('plant', 'name')
->required()
->searchable()
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
@@ -64,6 +65,8 @@ class MotorTestingMasterResource extends Resource
} else {
$set('mTmError', null);
}
$set('updated_by', Filament::auth()->user()?->name);
})
->extraAttributes(fn ($get) => [
'class' => $get('mTmError') ? 'border-red-500' : '',
@@ -74,6 +77,9 @@ class MotorTestingMasterResource extends Resource
->label('Routine Test Time')
->default('00:40:00')
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->reactive(),
Forms\Components\Select::make('item_id')
->label('Item Code')
@@ -84,13 +90,27 @@ class MotorTestingMasterResource extends Resource
return [];
}
return Item::where('plant_id', $plantId)
->pluck('code', 'id')
->toArray();
if (! $get('id')) {
// whereHas
return Item::where('plant_id', $plantId)->whereDoesntHave('motorTestingMasters')->pluck('code', 'id');
} else {
$itemId = MotorTestingMaster::where('id', $get('id'))->first()?->item_id;
return Item::where('plant_id', $plantId)
->where(function ($query) use ($itemId) {
$query->whereDoesntHave('motorTestingMasters')
->orWhere('id', $itemId);
})
->pluck('code', 'id');
}
// return Item::where('plant_id', $plantId)->pluck('code', 'id')->toArray();
})
->required()
->searchable()
->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->rule(function (callable $get) {
return Rule::unique('motor_testing_masters', 'item_id')
->where('plant_id', $get('plant_id'))
@@ -122,6 +142,8 @@ class MotorTestingMasterResource extends Resource
}
$set('iCodeError', null);
}
$set('updated_by', Filament::auth()->user()?->name);
})
->extraAttributes(fn ($get) => [
'class' => $get('iCodeError') ? 'border-red-500' : '',
@@ -138,6 +160,9 @@ class MotorTestingMasterResource extends Resource
->selectablePlaceholder(false)
->default(1)
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->reactive(),
Forms\Components\Select::make('phase')
->label('Phase')
@@ -159,35 +184,57 @@ class MotorTestingMasterResource extends Resource
})
->selectablePlaceholder(false)
->afterStateUpdated(function ($state, callable $set, callable $get) {
if ($state == 'Single' && $get('connection') == 'Star-Delta') {
$set('phase', 'Three');
}
$set('updated_by', Filament::auth()->user()?->name);
})
->default('Single')
->required()
->reactive(),
Forms\Components\TextInput::make('hp')
->label('HP')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('kw')
->label('KW')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('volt')
->label('Volt')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('current')
->label('Current')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('rpm')
->label('RPM')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('torque')
->label('Torque')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('frequency')
->label('Frequency')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Select::make('connection')
->label('Connection')
->selectablePlaceholder(false)
@@ -210,12 +257,17 @@ class MotorTestingMasterResource extends Resource
if ($state == 'Star-Delta') {
$set('phase', 'Three');
}
$set('updated_by', Filament::auth()->user()?->name);
})
->required()
->default('Star')
->reactive(),
Forms\Components\TextInput::make('ins_res_limit')
->label('Insulation Resistance Limit')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\Select::make('ins_res_type')
->label('Insulation Resistance Type')
@@ -236,55 +288,106 @@ class MotorTestingMasterResource extends Resource
->toArray();
}
})
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_ry_ll')
->label('Resistance RY LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_ry_ul')
->label('Resistance RY UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_yb_ll')
->label('Resistance YB LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_yb_ul')
->label('Resistance YB UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_br_ll')
->label('Resistance BR LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_br_ul')
->label('Resistance BR UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('lock_volt_limit')
->label('Lock Volt Limit')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('leak_cur_limit')
->label('Leakage Current Limit')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('lock_cur_ll')
->label('Lock Current LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('lock_cur_ul')
->label('Lock Current UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_cur_ll')
->label('No Load Current LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_cur_ul')
->label('No Load Current UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_pow_ll')
->label('No Load Power LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_pow_ul')
->label('No Load Power UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_spd_ll')
->label('No Load Speed LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_spd_ul')
->label('No Load Speed UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Hidden::make('created_by')
->default(fn () => Filament::auth()->user()?->name)
->required(),
@@ -311,7 +414,7 @@ class MotorTestingMasterResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->label('Plant Name')
->searchable()
->alignCenter()
->sortable(),
@@ -458,17 +561,26 @@ class MotorTestingMasterResource extends Resource
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->label('Search by Plant Name')
->nullable()
->searchable()
->reactive()
// ->options(function () {
// return Plant::pluck('name', 'id');
// })
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
if ($userHas && strlen($userHas) > 0) {
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
} else {
return Plant::whereHas('motorTestingMasters', function ($query) {
$query->whereNotNull('id');
})->orderBy('code')->pluck('name', 'id');
}
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
$set('isi_type', null);
@@ -681,7 +793,7 @@ class MotorTestingMasterResource extends Resource
$indicators = [];
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
$indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;