diff --git a/app/Filament/Resources/QualityValidationResource.php b/app/Filament/Resources/QualityValidationResource.php index cd38d4a..354bbaa 100644 --- a/app/Filament/Resources/QualityValidationResource.php +++ b/app/Filament/Resources/QualityValidationResource.php @@ -7,6 +7,7 @@ use App\Filament\Imports\QualityValidationImporter; use App\Filament\Resources\QualityValidationResource\Pages; use App\Filament\Resources\QualityValidationResource\RelationManagers; use App\Models\Item; +use App\Models\Line; use App\Models\Plant; use App\Models\QualityValidation; use App\Models\StickerMaster; @@ -50,12 +51,62 @@ class QualityValidationResource extends Resource Forms\Components\Select::make('plant_id') ->relationship('plant', 'name') ->reactive() - ->afterStateUpdated(fn (callable $set) => [ - $set('item_id', null), - $set('validationError', null), - ]) + ->afterStateUpdated(function (callable $set, callable $get) { + $set('item_id', null); + $set('line_id', null); + $set('production_order', null); + + $pId = $get('plant_id'); + if (!$pId) { + $set('pqPlantError', 'Please select a plant first.'); + } else { + $set('pqPlantError', null); + } + + $pId = $get('line_id'); + if (!$pId) { + $set('pqLineError', null); + } + }) ->required() - ->default(fn () => request()->query('plant_id')), + ->default(fn () => request()->query('plant_id')) + ->extraAttributes(fn ($get) => [ + 'class' => $get('pqPlantError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null) + ->hintColor('danger'), + Forms\Components\Select::make('line_id') + ->relationship('line', titleAttribute: 'name') + ->reactive() + ->required() + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if (!$plantId) + { + return []; + } + + return Line::where('plant_id', $plantId) + ->where('type', 'FG Line') // Filter by type + ->pluck('name', 'id') + ->toArray(); + }) + ->afterStateUpdated(function (callable $set, callable $get) { + $set('item_id', null); + $set('production_order', null); + + $pId = $get('line_id'); + if (!$pId) { + $set('pqLineError', 'Please select a line.'); + } else { + $set('pqLineError', null); + } + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('pqLineError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('pqLineError') ? $get('pqLineError') : null) + ->hintColor('danger'), Forms\Components\Hidden::make('sticker_master_id') // ->relationship('stickerMaster', 'id') ->required(), @@ -111,6 +162,23 @@ class QualityValidationResource extends Resource ->live() ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $pId = $get('line_id'); + if (!$pId) { + $set('pqLineError', 'Please select a line.'); + } else { + $set('pqLineError', null); + } + + $pOrder = $get('production_order'); + if (!$pOrder) + { + $set('productionError', 'Production Order cant be empty.'); + } + else + { + $set('productionError', null); + } + $serialFields = [ 'serial_number_motor_qr', 'serial_number_pump_qr', 'serial_number_pumpset_qr', 'pack_slip_motor_qr', 'pack_slip_pump_qr', 'pack_slip_pumpset_qr', 'name_plate_motor_qr', 'name_plate_pump_qr', 'name_plate_pumpset_qr', 'tube_sticker_motor_qr', 'tube_sticker_pump_qr', 'tube_sticker_pumpset_qr', 'warranty_card_qr' ]; @@ -1894,21 +1962,37 @@ class QualityValidationResource extends Resource return $table ->query(QualityValidation::query()) ->columns([ - Tables\Columns\TextColumn::make('id') - ->label('ID') - ->numeric() - ->sortable(), + // Tables\Columns\TextColumn::make('id') + // ->label('ID') + // ->numeric() + // ->sortable(), + Tables\Columns\TextColumn::make('No.') + ->label('No.') + ->getStateUsing(function ($record, $livewire, $column, $rowLoop) { + $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') ->label('Plant') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('line.name') + ->label('Line') + ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('production_order') ->label('Production Order') + ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('serial_number') ->label('Serial Number') + ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('stickerMaster.item.code') ->label('Item Code') + ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('uom') ->label('Unit of Measure') @@ -1992,20 +2076,23 @@ class QualityValidationResource extends Resource ->sortable(), Tables\Columns\TextColumn::make('sap_msg_description') ->label('SAP Message Description') + ->alignCenter() ->sortable(), Tables\Columns\TextColumn::make('created_at') ->label('Created At') ->dateTime() - ->sortable() - ->toggleable(isToggledHiddenByDefault: true), + ->alignCenter() + ->sortable(), Tables\Columns\TextColumn::make('updated_at') ->label('Updated At') ->dateTime() + ->alignCenter() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('deleted_at') ->label('Deleted At') ->dateTime() + ->alignCenter() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) @@ -2027,6 +2114,26 @@ class QualityValidationResource extends Resource $set('sticker_master_id', null); $set('sap_msg_status', null); }), + Select::make('Line') + ->label('Select Line') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + if (!$plantId) + { + return []; + } + + return Line::where('plant_id', $plantId) + ->where('type', 'FG Line') // Filter by type + ->pluck('name', 'id') + ->toArray(); + }) + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('sticker_master_id', null); + $set('sap_msg_status', null); + }), TextInput::make('production_order') ->label('Production Order') ->placeholder('Enter Production Order'), @@ -2083,6 +2190,10 @@ class QualityValidationResource extends Resource $query->where('plant_id', $data['Plant']); } + if (!empty($data['Line'])) { + $query->where('line_id', $data['Line']); + } + if (!empty($data['production_order'])) { $query->where('production_order', 'like', '%' . $data['production_order'] . '%'); } @@ -2120,6 +2231,10 @@ class QualityValidationResource extends Resource $indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name'); } + if (!empty($data['Line'])) { + $indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name'); + } + if (!empty($data['production_order'])) { $indicators[] = 'Production Order: ' . $data['production_order']; }