From 6ead4bce3df240534f116d5775ddd42662648b39 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 6 Dec 2025 12:54:18 +0530 Subject: [PATCH] Commented drop unique constraint for plant and operation number on work_group_masters --- .../Resources/WorkGroupMasterResource.php | 137 +++++++++--------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/app/Filament/Resources/WorkGroupMasterResource.php b/app/Filament/Resources/WorkGroupMasterResource.php index 523c966..94a2c2e 100644 --- a/app/Filament/Resources/WorkGroupMasterResource.php +++ b/app/Filament/Resources/WorkGroupMasterResource.php @@ -5,21 +5,19 @@ namespace App\Filament\Resources; use App\Filament\Exports\WorkGroupMasterExporter; use App\Filament\Imports\WorkGroupMasterImporter; use App\Filament\Resources\WorkGroupMasterResource\Pages; -use App\Filament\Resources\WorkGroupMasterResource\RelationManagers; -use App\Models\Line; use App\Models\Plant; use App\Models\WorkGroupMaster; +use Filament\Facades\Filament; use Filament\Forms; +use Filament\Forms\Components\Section; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; +use Filament\Tables\Actions\ExportAction; +use Filament\Tables\Actions\ImportAction; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletingScope; -use Filament\Forms\Components\Section; -use Filament\Facades\Filament; -use Filament\Tables\Actions\ImportAction; -use Filament\Tables\Actions\ExportAction; use Illuminate\Validation\Rule; class WorkGroupMasterResource extends Resource @@ -37,68 +35,70 @@ class WorkGroupMasterResource extends Resource return $form ->schema([ Section::make('') - ->schema([ - Forms\Components\Select::make('plant_id') - ->label('Plant') - ->relationship('plant', 'name') - ->reactive() - ->columnSpan(1) - ->required() - ->options(function (callable $get) { - $userHas = Filament::auth()->user()->plant_id; - return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); - }) - ->afterStateUpdated(function ($state, $set, callable $get) { - $plantId = $get('plant_id'); + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant') + ->relationship('plant', 'name') + ->reactive() + ->columnSpan(1) + ->required() + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; - if (!$plantId) { - $set('pqPlantError', 'Please select a plant first.'); - $set('name', null); - $set('description', null); - $set('operation_number', null); - return; - } + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); + }) + ->afterStateUpdated(function ($state, $set, callable $get) { + $plantId = $get('plant_id'); - $set('validationError', null); - $set('pqPlantError', null); - $set('name', null); - $set('description', null); - $set('operation_number', null); - }) - ->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null) - ->hintColor('danger'), - Forms\Components\TextInput::make('name') - ->label('Name') - ->required() - ->minLength(6) - ->columnSpan(1) - ->reactive() - ->rule(function (callable $get) { - return Rule::unique('work_group_masters', 'name') - ->where('plant_id', $get('plant_id')) - ->ignore($get('id')); - }), - Forms\Components\TextInput::make('operation_number') - ->label('Operation Number') - ->numeric() - ->columnSpan(1) - ->reactive() - ->required() - ->rule(function (callable $get) { - return Rule::unique('work_group_masters', 'operation_number') - ->where('plant_id', $get('plant_id')) - ->ignore($get('id')); - }), - Forms\Components\TextInput::make('description') - ->label('Description') - ->required() - ->minLength(5) - ->reactive() - ->columnSpan(['default' => 1, 'sm' => 3]), - Forms\Components\Hidden::make('created_by') - ->default(Filament::auth()->user()?->name), - ]) - ->columns(['default' => 1, 'sm' => 3]), + if (! $plantId) { + $set('pqPlantError', 'Please select a plant first.'); + $set('name', null); + $set('description', null); + $set('operation_number', null); + + return; + } + + $set('validationError', null); + $set('pqPlantError', null); + $set('name', null); + $set('description', null); + $set('operation_number', null); + }) + ->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null) + ->hintColor('danger'), + Forms\Components\TextInput::make('name') + ->label('Name') + ->required() + ->minLength(6) + ->columnSpan(1) + ->reactive() + ->rule(function (callable $get) { + return Rule::unique('work_group_masters', 'name') + ->where('plant_id', $get('plant_id')) + ->ignore($get('id')); + }), + Forms\Components\TextInput::make('operation_number') + ->label('Operation Number') + ->numeric() + ->columnSpan(1) + ->reactive() + ->required(), + // ->rule(function (callable $get) { + // return Rule::unique('work_group_masters', 'operation_number') + // ->where('plant_id', $get('plant_id')) + // ->ignore($get('id')); + // }), + Forms\Components\TextInput::make('description') + ->label('Description') + ->required() + ->minLength(5) + ->reactive() + ->columnSpan(['default' => 1, 'sm' => 3]), + Forms\Components\Hidden::make('created_by') + ->default(Filament::auth()->user()?->name), + ]) + ->columns(['default' => 1, 'sm' => 3]), ]); } @@ -112,6 +112,7 @@ class WorkGroupMasterResource extends Resource $paginator = $livewire->getTableRecords(); $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; + return ($currentPage - 1) * $perPage + $rowLoop->iteration; }), Tables\Columns\TextColumn::make('plant.name') @@ -177,14 +178,14 @@ class WorkGroupMasterResource extends Resource ->label('Import Work Group Masters') ->color('warning') ->importer(WorkGroupMasterImporter::class) - ->visible(function() { + ->visible(function () { return Filament::auth()->user()->can('view import work group master'); }), ExportAction::make() ->label('Export Work Group Masters') ->color('warning') ->exporter(WorkGroupMasterExporter::class) - ->visible(function() { + ->visible(function () { return Filament::auth()->user()->can('view export work group master'); }), ]);