Added workGroupMaster functionality in resource and Updated navigation sort
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Filament\Resources\MachineResource\Pages;
|
|||||||
use App\Filament\Resources\MachineResource\RelationManagers;
|
use App\Filament\Resources\MachineResource\RelationManagers;
|
||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
use App\Models\Machine;
|
use App\Models\Machine;
|
||||||
|
use App\Models\WorkGroupMaster;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@@ -30,7 +31,7 @@ class MachineResource extends Resource
|
|||||||
|
|
||||||
protected static ?string $navigationGroup = 'Master Entries';
|
protected static ?string $navigationGroup = 'Master Entries';
|
||||||
|
|
||||||
protected static ?int $navigationSort = 11;
|
protected static ?int $navigationSort = 12;
|
||||||
|
|
||||||
public static function form(Form $form): Form
|
public static function form(Form $form): Form
|
||||||
{
|
{
|
||||||
@@ -49,6 +50,8 @@ class MachineResource extends Resource
|
|||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (!$plantId) {
|
if (!$plantId) {
|
||||||
$set('mPlantError', 'Please select a plant first.');
|
$set('mPlantError', 'Please select a plant first.');
|
||||||
|
$set('line_id', null);
|
||||||
|
$set('work_group_master_id', null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -81,6 +84,7 @@ class MachineResource extends Resource
|
|||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
if (!$lineId) {
|
if (!$lineId) {
|
||||||
$set('mLineError', 'Please select a line first.');
|
$set('mLineError', 'Please select a line first.');
|
||||||
|
$set('work_group_master_id', null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -100,19 +104,73 @@ class MachineResource extends Resource
|
|||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('mLineError') ? $get('mLineError') : null)
|
->hint(fn ($get) => $get('mLineError') ? $get('mLineError') : null)
|
||||||
->hintColor('danger'),
|
->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')
|
Forms\Components\TextInput::make('name')
|
||||||
->label('Name')
|
->label('Name')
|
||||||
->placeholder('Scan the valid Machine Name')
|
->placeholder('Scan the valid Machine Name')
|
||||||
->required()
|
->required()
|
||||||
->rule(function (callable $get) {
|
->rule(function (callable $get) {
|
||||||
return Rule::unique('machines', 'name')
|
return Rule::unique('machines', 'name')
|
||||||
->where('line_id', $get('line_id'))
|
//->where('line_id', $get('line_id'))
|
||||||
->where('plant_id', $get('plant_id'))
|
->where('plant_id', $get('plant_id'))
|
||||||
->ignore($get('id')); // Ignore current record during updates
|
->ignore($get('id')); // Ignore current record during updates
|
||||||
}),
|
}),
|
||||||
Forms\Components\TextInput::make('work_center')
|
Forms\Components\TextInput::make('work_center')
|
||||||
->label('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')
|
Forms\Components\TextInput::make('id')
|
||||||
->hidden()
|
->hidden()
|
||||||
->readOnly(),
|
->readOnly(),
|
||||||
@@ -133,21 +191,26 @@ class MachineResource extends Resource
|
|||||||
}),
|
}),
|
||||||
Tables\Columns\TextColumn::make('plant.name')
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
->label('Plant')
|
->label('Plant')
|
||||||
->searchable()
|
->alignCenter()
|
||||||
->alignCenter(),
|
->searchable(),
|
||||||
Tables\Columns\TextColumn::make('line.name')
|
Tables\Columns\TextColumn::make('line.name')
|
||||||
->label('Line')
|
->label('Line')
|
||||||
->searchable()
|
->alignCenter()
|
||||||
->alignCenter(),
|
->searchable(),
|
||||||
Tables\Columns\TextColumn::make('name')
|
Tables\Columns\TextColumn::make('name')
|
||||||
->label('Name')
|
->label('Name')
|
||||||
->searchable()
|
->alignCenter()
|
||||||
->alignCenter(),
|
->searchable(),
|
||||||
Tables\Columns\TextColumn::make('work_center')
|
Tables\Columns\TextColumn::make('work_center')
|
||||||
->label('Work Center')
|
->label('Work Center')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->sortable()
|
->searchable()
|
||||||
->searchable(),
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('workGroupMaster.name')
|
||||||
|
->label('Work Group Center')
|
||||||
|
->alignCenter()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('created_at')
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
|
|||||||
Reference in New Issue
Block a user