Added workGroupMaster functionality in resource and Updated navigation sort

This commit is contained in:
dhanabalan
2025-09-15 12:27:10 +05:30
parent 55c0ebfa6d
commit 23fa24ca46

View File

@@ -8,6 +8,7 @@ use App\Filament\Resources\MachineResource\Pages;
use App\Filament\Resources\MachineResource\RelationManagers;
use App\Models\Line;
use App\Models\Machine;
use App\Models\WorkGroupMaster;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
@@ -30,7 +31,7 @@ class MachineResource extends Resource
protected static ?string $navigationGroup = 'Master Entries';
protected static ?int $navigationSort = 11;
protected static ?int $navigationSort = 12;
public static function form(Form $form): Form
{
@@ -49,6 +50,8 @@ class MachineResource extends Resource
$plantId = $get('plant_id');
if (!$plantId) {
$set('mPlantError', 'Please select a plant first.');
$set('line_id', null);
$set('work_group_master_id', null);
return;
}
else
@@ -81,6 +84,7 @@ class MachineResource extends Resource
$lineId = $get('line_id');
if (!$lineId) {
$set('mLineError', 'Please select a line first.');
$set('work_group_master_id', null);
return;
}
else
@@ -100,19 +104,73 @@ class MachineResource extends Resource
])
->hint(fn ($get) => $get('mLineError') ? $get('mLineError') : null)
->hintColor('danger'),
Forms\Components\Select::make('work_group_master_id')
->label('Group Work Center')
->relationship('workGroupMaster', 'name')
->required()
->reactive()
->options(function (callable $get) {
if (!$get('plant_id') || !$get('line_id')) {
return [];
}
$line = Line::find($get('line_id'));
$workGroupIds = [];
for ($i = 1; $i <= $line->no_of_operation; $i++) {
$column = "work_group{$i}_id";
if (!empty($line->$column)) {
$workGroupIds[] = $line->$column;
}
}
return WorkGroupMaster::where('plant_id', $get('plant_id'))->whereIn('id', $workGroupIds)->pluck('name', 'id')->toArray();
})
->default(function () {
return optional(Machine::latest()->first())->work_group_master_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineId = $get('line_id');
if (!$lineId) {
$set('mGroupWorkError', 'Please select a line first.');
return;
}
else
{
// $grpWrkCnr = Line::find($lineId)->group_work_center;
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
// {
// $set('mGroupWorkError', 'Please select a group work center line.');
// $set('line_id', null);
// return;
// }
$set('mGroupWorkError', null);
}
})
->extraAttributes(fn ($get) => [
'class' => $get('mGroupWorkError') ? 'border-red-500' : '',
])
->hint(fn ($get) => $get('mGroupWorkError') ? $get('mGroupWorkError') : null)
->hintColor('danger'),
Forms\Components\TextInput::make('name')
->label('Name')
->placeholder('Scan the valid Machine Name')
->required()
->rule(function (callable $get) {
return Rule::unique('machines', 'name')
->where('line_id', $get('line_id'))
//->where('line_id', $get('line_id'))
->where('plant_id', $get('plant_id'))
->ignore($get('id')); // Ignore current record during updates
}),
Forms\Components\TextInput::make('work_center')
->label('Work Center')
->placeholder('Scan the valid Work Center'),
->placeholder('Scan the valid Work Center')
->required()
->rule(function (callable $get) {
return Rule::unique('machines', 'work_center')
->where('plant_id', $get('plant_id'))
->ignore($get('id')); // Ignore current record during updates
}),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
@@ -133,21 +191,26 @@ class MachineResource extends Resource
}),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->searchable()
->alignCenter(),
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('line.name')
->label('Line')
->searchable()
->alignCenter(),
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('name')
->label('Name')
->searchable()
->alignCenter(),
->alignCenter()
->searchable(),
Tables\Columns\TextColumn::make('work_center')
->label('Work Center')
->alignCenter()
->sortable()
->searchable(),
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('workGroupMaster.name')
->label('Work Group Center')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->alignCenter()