diff --git a/app/Filament/Resources/PanelGrMasterResource.php b/app/Filament/Resources/PanelGrMasterResource.php index 3944db9..421d708 100644 --- a/app/Filament/Resources/PanelGrMasterResource.php +++ b/app/Filament/Resources/PanelGrMasterResource.php @@ -9,6 +9,7 @@ use App\Filament\Resources\PanelGrMasterResource\RelationManagers; use App\Models\Item; use App\Models\PalletValidation; use App\Models\PanelGrMaster; +use App\Models\PanelBoxValidation; use App\Models\Plant; use Filament\Facades\Filament; use Filament\Forms; @@ -26,6 +27,8 @@ use Filament\Forms\Components\Section; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Closure; +use Filament\Notifications\Notification; +use Illuminate\Support\Facades\Log; class PanelGrMasterResource extends Resource { @@ -99,6 +102,9 @@ class PanelGrMasterResource extends Resource if ((float) $state == 0) { $set('quantity', null); } + + $set('updated_by', Filament::auth()->user()?->name); + $set('updated_at', now()); }), Forms\Components\Hidden::make('created_by') ->label('Created By') @@ -161,7 +167,16 @@ class PanelGrMasterResource extends Resource ->label('Scanned Quantity') ->searchable() ->alignCenter() - ->sortable(), + ->sortable() + ->getStateUsing(function ($record) { + return PanelBoxValidation::where('plant_id', $record->plant_id) + ->where('production_order', $record->document_number) + ->where('inspection_lot_number', $record->inspection_lot_number) + ->whereHas('stickerMaster', function ($query) use ($record) { + $query->where('item_id', $record->item_id); + }) + ->count(); + }), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->alignCenter() @@ -371,10 +386,6 @@ class PanelGrMasterResource extends Resource return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, - ]) - ->withCount([ - 'panelBoxValidations as scanned_quantity' ]); - } } diff --git a/app/Models/PanelGrMaster.php b/app/Models/PanelGrMaster.php index cebd0d9..baa559d 100644 --- a/app/Models/PanelGrMaster.php +++ b/app/Models/PanelGrMaster.php @@ -32,10 +32,8 @@ class PanelGrMaster extends Model return $this->belongsTo(Item::class); } - public function panelBoxValidations() + public function stickerMaster() { - return $this->hasMany(PanelBoxValidation::class, 'plant_id', 'plant_id') - ->whereColumn('production_order', 'panel_gr_masters.document_number') - ->whereColumn('inspection_lot_number', 'panel_gr_masters.inspection_lot_number'); + return $this->belongsTo(StickerMaster::class, 'sticker_master_id'); } }