Merge pull request 'Added searchable method for plant and work center and updated_by name on every change and deleted_at column added at the end and Enhance EquipmentMasterResource form' (#825) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s

Reviewed-on: #825
This commit was merged in pull request #825.
This commit is contained in:
2026-07-08 13:15:29 +00:00

View File

@@ -12,6 +12,7 @@ use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
use Filament\Forms\Components\Actions\Action; use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Notifications\Notification; use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
@@ -39,18 +40,32 @@ class EquipmentMasterResource extends Resource
return $form return $form
->schema([ ->schema([
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant') ->label('Plant Name')
->reactive()
->relationship('plant', 'name') ->relationship('plant', 'name')
->required()
->searchable()
->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id; $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(); return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
}) })
->required(), ->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('machine_id', null);
$set('updated_by', Filament::auth()->user()?->name);
})
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(EquipmentMaster::latest()->first())->plant_id;
}),
Forms\Components\Select::make('machine_id') Forms\Components\Select::make('machine_id')
// ->relationship('machine', 'name') // ->relationship('machine', 'name')
->label('Work Center') ->label('Work Center')
->required()
->searchable()
->reactive() ->reactive()
->options(function (callable $get) { ->options(function (callable $get) {
$plantId = $get('plant_id'); $plantId = $get('plant_id');
@@ -60,15 +75,30 @@ class EquipmentMasterResource extends Resource
return \App\Models\Machine::where('plant_id', $plantId)->pluck('work_center', 'id'); return \App\Models\Machine::where('plant_id', $plantId)->pluck('work_center', 'id');
}) })
->required(), ->disabled(fn (Get $get) => ! empty($get('id')))
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('name') Forms\Components\TextInput::make('name')
->label('Name'), ->label('Name')
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('description') Forms\Components\TextInput::make('description')
->label('Description'), ->label('Description')
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('make') Forms\Components\TextInput::make('make')
->label('Make'), ->label('Make')
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('model') Forms\Components\TextInput::make('model')
->label('Model'), ->label('Model')
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('equipment_number') Forms\Components\TextInput::make('equipment_number')
->label('Equipment Number') ->label('Equipment Number')
->reactive() ->reactive()
@@ -82,6 +112,8 @@ class EquipmentMasterResource extends Resource
]; ];
}) })
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
if (! $state) { if (! $state) {
return; return;
} }
@@ -108,7 +140,10 @@ class EquipmentMasterResource extends Resource
// } // }
// }), // }),
Forms\Components\TextInput::make('instrument_serial_number') Forms\Components\TextInput::make('instrument_serial_number')
->label('Instrument Serial Number'), ->label('Instrument Serial Number')
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
// Forms\Components\DateTimePicker::make('calibrated_on') // Forms\Components\DateTimePicker::make('calibrated_on')
// ->label('Calibrated On') // ->label('Calibrated On')
// ->required(), // ->required(),
@@ -128,6 +163,7 @@ class EquipmentMasterResource extends Resource
$frequency = $get('frequency') ?? '1'; $frequency = $get('frequency') ?? '1';
$nextDate = self::calculateNextCalibrationDate($state, $frequency); $nextDate = self::calculateNextCalibrationDate($state, $frequency);
$set('next_calibration_date', $nextDate); $set('next_calibration_date', $nextDate);
$set('updated_by', Filament::auth()->user()?->name);
}), }),
// ->afterStateUpdated(function ($state, callable $get, callable $set) { // ->afterStateUpdated(function ($state, callable $get, callable $set) {
// $frequency = (int) $get('frequency'); // $frequency = (int) $get('frequency');
@@ -152,6 +188,7 @@ class EquipmentMasterResource extends Resource
$calibratedOn = $get('calibrated_on'); $calibratedOn = $get('calibrated_on');
$nextDate = self::calculateNextCalibrationDate($calibratedOn, $state); $nextDate = self::calculateNextCalibrationDate($calibratedOn, $state);
$set('next_calibration_date', $nextDate); $set('next_calibration_date', $nextDate);
$set('updated_by', Filament::auth()->user()?->name);
}), }),
// ->afterStateUpdated(function ($state, callable $get, callable $set) { // ->afterStateUpdated(function ($state, callable $get, callable $set) {
// $calibratedOn = $get('calibrated_on'); // $calibratedOn = $get('calibrated_on');
@@ -171,12 +208,21 @@ class EquipmentMasterResource extends Resource
Forms\Components\DateTimePicker::make('next_calibration_date') Forms\Components\DateTimePicker::make('next_calibration_date')
->label('Next Calibration Date') ->label('Next Calibration Date')
->readOnly() ->readOnly()
->required(), ->required()
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('calibrated_by') Forms\Components\TextInput::make('calibrated_by')
->label('Calibrated By'), ->label('Calibrated By')
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Textarea::make('calibration_certificate') Forms\Components\Textarea::make('calibration_certificate')
->label('Calibration Certificate'), ->label('Calibration Certificate')
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\FileUpload::make('attachment') Forms\Components\FileUpload::make('attachment')
->label('PDF Upload') ->label('PDF Upload')
@@ -185,7 +231,10 @@ class EquipmentMasterResource extends Resource
->disk('local') ->disk('local')
->directory('uploads/temp') ->directory('uploads/temp')
->preserveFilenames() ->preserveFilenames()
->reactive(), ->reactive()
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
}),
// Forms\Components\Actions::make([ // Forms\Components\Actions::make([
// Action::make('uploadNow') // Action::make('uploadNow')
@@ -267,6 +316,9 @@ class EquipmentMasterResource extends Resource
// } // }
// } // }
// }), // }),
->afterStateUpdated(function ($state, callable $set) {
$set('updated_by', Filament::auth()->user()?->name);
})
->action(function ($get, callable $set) { ->action(function ($get, callable $set) {
$uploadedFiles = $get('attachment'); $uploadedFiles = $get('attachment');
@@ -341,7 +393,11 @@ class EquipmentMasterResource extends Resource
->label('Created By') ->label('Created By')
->default(Filament::auth()->user()?->name), ->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by') Forms\Components\Hidden::make('updated_by')
->label('Updated By'), ->label('Updated By')
->default(Filament::auth()->user()?->name),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
]); ]);
} }
@@ -359,7 +415,7 @@ class EquipmentMasterResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration; return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}), }),
Tables\Columns\TextColumn::make('plant.name') Tables\Columns\TextColumn::make('plant.name')
->label('Plant') ->label('Plant Name')
->alignCenter() ->alignCenter()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('machine.work_center') Tables\Columns\TextColumn::make('machine.work_center')
@@ -413,24 +469,30 @@ class EquipmentMasterResource extends Resource
->alignCenter() ->alignCenter()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('created_by') Tables\Columns\TextColumn::make('created_by')
->label('Created Bys') ->label('Created By')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('updated_by')
->label('Updated By')
->alignCenter() ->alignCenter()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('created_at') Tables\Columns\TextColumn::make('created_at')
->label('Created At') ->label('Created At')
->dateTime() ->dateTime()
->alignCenter() ->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('updated_by')
->label('Updated By')
->alignCenter()
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: false),
Tables\Columns\TextColumn::make('updated_at') Tables\Columns\TextColumn::make('updated_at')
->label('Updated At') ->label('Updated At')
->dateTime() ->dateTime()
->alignCenter() ->alignCenter()
->sortable() ->sortable()
->toggleable(isToggledHiddenByDefault: false),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->dateTime()
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true), ->toggleable(isToggledHiddenByDefault: true),
]) ])
->filters([ ->filters([