From dc7d5333fae14e989607b1ab7781af797263e17b Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 30 Nov 2026 14:21:07 +0530 Subject: [PATCH 1/5] Added panel pallet validation resource pages --- .../PanelPalletValidationResource.php | 339 +++++++ .../Pages/CreatePanelPalletValidation.php | 867 ++++++++++++++++++ .../Pages/EditPanelPalletValidation.php | 22 + .../Pages/ListPanelPalletValidations.php | 19 + .../Pages/ViewPanelPalletValidation.php | 19 + 5 files changed, 1266 insertions(+) create mode 100644 app/Filament/Resources/PanelPalletValidationResource.php create mode 100644 app/Filament/Resources/PanelPalletValidationResource/Pages/CreatePanelPalletValidation.php create mode 100644 app/Filament/Resources/PanelPalletValidationResource/Pages/EditPanelPalletValidation.php create mode 100644 app/Filament/Resources/PanelPalletValidationResource/Pages/ListPanelPalletValidations.php create mode 100644 app/Filament/Resources/PanelPalletValidationResource/Pages/ViewPanelPalletValidation.php diff --git a/app/Filament/Resources/PanelPalletValidationResource.php b/app/Filament/Resources/PanelPalletValidationResource.php new file mode 100644 index 00000000..25b893e1 --- /dev/null +++ b/app/Filament/Resources/PanelPalletValidationResource.php @@ -0,0 +1,339 @@ +schema([ + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant') + ->relationship('plant', 'name') + ->required() + ->reactive() + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->afterStateUpdated(function ($state, callable $set) { + $set('pallet_number', null); + $set('serial_number', null); + $set('removeSno_number', null); + $set('Sno_quantity', 0); + $set('pending_pallet_list', null); + }), + Forms\Components\TextInput::make('pallet_number') + ->label('Scan Pallet No') + ->reactive() + ->required() + ->readonly() // fn ($get) => (bool)$get('pallet_number_locked') || $get('serial_number') || $get('removeSno_number') + ->extraAttributes([ + 'x-data' => '{ value: "" }', + 'x-model' => 'value', + 'x-on:keydown.enter.prevent' => '$wire.processPalletNo()', + ]) + ->suffixAction(fn ($get, $set) => Forms\Components\Actions\Action::make('addPallet') + ->label('') + ->button() + ->icon('heroicon-o-plus') + ->color('primary') + ->extraAttributes([ + 'class' => 'p-1 w-7 h-7', + ]) + ->action(function ($get, $set, $livewire) { + $plantId = $get('plant_id'); + + session(['pallet_clicked_time' => now()->toDateTimeString()]); + + session(['pallet_created_by' => Filament::auth()->user()->name]); + + $year = now()->format('y'); + $month = now()->format('m'); + $prefix = "PP-{$year}{$month}"; + + $lastPallet1 = PanelPalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first(); + $newNumber = '001'; + if ($lastPallet1) { + $serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix)); + $newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT); + } + + $newPalletNumber = "{$prefix}{$newNumber}"; + + // dd($newPalletNumber); + + $set('pallet_number', $newPalletNumber); + $set('pallet_number_locked', true); + $set('plant_id', $plantId); + + $livewire->redirectToPanelQrPdf($newPalletNumber); + }) + ), + Forms\Components\TextInput::make('serial_number') + ->label('Scan Serial No') + ->reactive() + ->minLength(9) + ->readOnly(fn (callable $get) => ! $get('pallet_number') || $get('removeSno_number')) + ->extraAttributes([ + 'x-on:keydown.enter.prevent' => '$wire.processPalletSNo()', + ]), + Forms\Components\TextInput::make('removeSno_number') + ->label('Remove Serial No') + ->reactive() + ->minLength(9) + ->readOnly(fn (callable $get) => ! $get('pallet_number') || $get('serial_number')) + ->extraAttributes([ + 'x-data' => '{ value: "" }', + 'x-model' => 'value', + 'x-on:keydown.enter.prevent' => '$wire.processRemoveSNo()', + ]), + + Forms\Components\TextInput::make('Sno_quantity') + ->label('SNo. Quantity') + ->readOnly() + ->default('0'), + Forms\Components\Hidden::make('created_by') + ->default(Filament::auth()->user()?->name), + Forms\Components\Hidden::make('scanned_by') + ->default(Filament::auth()->user()?->name), + Forms\Components\Hidden::make('pallet_number_locked') + ->default(false), + Forms\Components\Select::make('pending_pallet_list') + ->label('Pending Pallet List') + ->reactive() + ->afterStateUpdated(function ($state, callable $set) { + $set('pallet_number', $state); + $set('pallet_number_locked', false); + }) + ->options(function ($get) { + + $plantId = $get('plant_id'); + + if (! $plantId) { + return []; + } + + return PanelPalletValidation::query() + ->where('plant_id', $plantId) + ->where(function ($query) { + $query->whereNull('pallet_status') + ->orWhere('pallet_status', ''); + }) + ->whereNotNull('pallet_number') + ->orderBy('pallet_number', 'asc') + ->pluck('pallet_number') + ->unique() + ->mapWithKeys(fn ($number) => [$number => $number]) + ->toArray(); + }), + Forms\Components\View::make('forms.components.save-panel-pallet-button'), + + ]) + ->columns(5), + Forms\Components\TextInput::make('id') + ->hidden() + ->readOnly(), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('No.') + ->label('No.') + ->alignCenter() + ->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('item.code') + ->label('Item') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('pallet_number') + ->label('Pallet Number') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('serial_number') + ->label('Serial Number') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('panel_box_supplier') + ->label('Panel Box Supplier') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('panel_box_serial_number') + ->label('Panel Box Serial Number') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('panel_box_code') + ->label('Panel Box Code') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('pallet_status') + ->label('Pallet Status') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->label('Created At') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('scanned_at') + ->dateTime() + ->sortable(), + Tables\Columns\TextColumn::make('deleted_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + Tables\Filters\TrashedFilter::make(), + ]) + ->actions([ + Tables\Actions\ViewAction::make(), + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), + ]), + ]) + ->headerActions([ + Tables\Actions\Action::make('reprint_pallet') + ->label('Re-Print Panel Pallet QR') + ->form([ + Forms\Components\Section::make() + ->schema([ + Forms\Components\Select::make('plant') + ->label('Select Plant') + // ->options(Plant::pluck('name', 'id')->toArray()) + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->required() + ->reactive() + ->columnSpan(2), + Forms\Components\Select::make('pallet_list') + ->label('Select Pallet') + ->searchable() + ->required() + ->reactive() + ->columnSpan(1) + // ->optionsLimit(500) + ->options(function (callable $get) { + $plantId = $get('plant'); + + if (! $plantId) { + return []; + } + + return PanelPalletValidation::query()->where('plant_id', $plantId) + // ->whereNotNull('pallet_number') + // ->where('pallet_number', '!=', '') + ->where('pallet_number', 'like', 'PP-'.'%') + ->select('pallet_number') + ->distinct() + ->orderBy('pallet_number', 'desc') + ->pluck('pallet_number', 'pallet_number') + ->toArray(); + }), + ]) + ->columns(['default' => 1, 'sm' => 3]), + ]) + ->action(function (array $data) { + $selectedPalletNumber = $data['pallet_list']; + + return redirect()->route('download-reprint-qr-pdf', ['palletNo' => $selectedPalletNumber]); + + }) + ->visible(function () { + return Filament::auth()->user()->can('view reprint pallet number'); + }), + ImportAction::make() + ->importer(PanelPalletValidationImporter::class) + ->label('Import Panel Pallet') + ->color('warning') + ->visible(function () { + return Filament::auth()->user()->can('view import panel pallet validation'); + }), + ExportAction::make() + ->exporter(PanelPalletValidationExporter::class) + ->label('Export Panel Pallet') + ->color('warning') + ->visible(function () { + return Filament::auth()->user()->can('view export panel pallet validation'); + }), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListPanelPalletValidations::route('/'), + 'create' => Pages\CreatePanelPalletValidation::route('/create'), + 'view' => Pages\ViewPanelPalletValidation::route('/{record}'), + 'edit' => Pages\EditPanelPalletValidation::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/PanelPalletValidationResource/Pages/CreatePanelPalletValidation.php b/app/Filament/Resources/PanelPalletValidationResource/Pages/CreatePanelPalletValidation.php new file mode 100644 index 00000000..90e0808f --- /dev/null +++ b/app/Filament/Resources/PanelPalletValidationResource/Pages/CreatePanelPalletValidation.php @@ -0,0 +1,867 @@ + 'handleUpdateSnoQuantity', + ]; + + public ?array $data = null; + + protected function getRedirectUrl(): string + { + return $this->getResource()::getUrl('create'); + } + + public function processPalletSNo() + { + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $pendingPallet = $this->form->getState()['pending_pallet_list']; + + $palletNumber = trim($this->form->getState()['pallet_number'])?? null; + + $palletNumber = trim($palletNumber) ?? null; + + $serNo = trim($this->form->getState()['serial_number'])?? null; + + $serNo = trim($serNo) ?? null; + + $user = Filament::auth()->user(); + + $operatorName = $user->name; + + $clickedAt = session('pallet_clicked_time'); + + $clickedBy = session('pallet_created_by'); + + $plantName = Plant::where('id', $plantId)->value('name'); + + if (!$palletNumber) + { + Notification::make() + ->title("Pallet number can't be empty") + ->danger() + ->duration(5000) + ->send(); + + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $count = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->count('pallet_number'); + + if (!preg_match('/^(\d+)\/(\d+)\/(\d+)\/(\d+)$/', $serNo, $matches)) { + Notification::make() + ->title("Invalid Panel Box QR format: $serNo
Sample Format '1070107/398679/2611/000001'") + ->danger() + ->send(); + + $this->form->fill([ + 'plant_id' => $plantId, + 'item_id' => null, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'serial_number' => null, + 'panel_box_supplier' => null, + 'panel_box_serial_number' => null, + 'panel_box_code' => null, + 'Sno_quantity' => 0, + ]); + + return; + } + + + if (preg_match('/^(\d+)\/(\d+)\/(\d+)\/(\d+)$/', $serNo, $matches)) { + $itemCode = $matches[2]; + $serialNumber = $matches[1] . $matches[3] . $matches[4]; + + $supplierNo = $matches[1]; + $supplierSNo = implode('/', array_slice($matches, 3)); + $panelBoxCode = $matches[2]; + + $pBoxSNo = $matches[3] . '/' . $matches[4]; + + $itemExists = Item::where('code', $panelBoxCode)->first(); + + if (!$itemExists) { + Notification::make() + ->title("Item code '$panelBoxCode' does not exist.") + ->danger() + ->duration(5000) + ->send(); + + $this->form->fill([ + 'plant_id' => $plantId, + 'item_id' => null, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'serial_number' => null, + 'panel_box_supplier' => null, + 'panel_box_serial_number' => null, + 'panel_box_code' => null, + 'Sno_quantity' => 0, + ]); + + return; + } + + $itemExistsAgaPlant = Item::where('plant_id', $plantId)->where('code', $panelBoxCode)->first(); + + if (!$itemExistsAgaPlant) { + Notification::make() + ->title("Item code '$panelBoxCode' does not exist against plant $plantName.") + ->danger() + ->duration(5000) + ->send(); + + $this->form->fill([ + 'plant_id' => $plantId, + 'item_id' => null, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'serial_number' => null, + 'panel_box_supplier' => null, + 'panel_box_serial_number' => null, + 'panel_box_code' => null, + 'Sno_quantity' => 0, + ]); + + return; + } + + $panelBoxExist = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->where('panel_box_code', $panelBoxCode)->first(); + + if(!$panelBoxExist){ + Notification::make() + ->title('Unknwon : Serial Number') + ->body("Scanned Panel Box Serial Number '$serNo' was not found in Panel Box Validation.
Please complete the testing process for this Panel Box before proceeding.") + ->danger() + ->seconds(3) + ->send(); + + $this->dispatch('playWarnSound'); + + $this->form->fill([ + 'plant_id' => $plantId, + 'item_id' => null, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'serial_number' => null, + 'panel_box_supplier' => null, + 'panel_box_serial_number' => null, + 'panel_box_code' => null, + 'Sno_quantity' => 0, + ]); + + return; + } + + $panelBoxExistStatus = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->where('panel_box_code', $panelBoxCode)->first(); + + if($panelBoxExistStatus && $panelBoxExistStatus->status == 'NotOk'){ + Notification::make() + ->title('NotOk : Serial Number') + ->body("Scanned Panel Box Serial Number '$serNo' was found in Panel Box Validation, but its status is Not OK.") + ->danger() + ->seconds(3) + ->send(); + + $this->dispatch('playWarnSound'); + + $this->form->fill([ + 'plant_id' => $plantId, + 'item_id' => null, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'serial_number' => null, + 'panel_box_supplier' => null, + 'panel_box_serial_number' => null, + 'panel_box_code' => null, + 'Sno_quantity' => 0, + ]); + + return; + } + + } + + try + { + + $existingPallet = PanelPalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->first(); + + $createdAt = $existingPallet ? $existingPallet->created_at : $clickedAt ?? now(); + + $createdBy = $existingPallet ? $existingPallet->created_by : $clickedBy ?? $operatorName; + + $record = PanelPalletValidation::create([ + 'plant_id' => $plantId, + 'item_id' => $itemExistsAgaPlant->id, + 'pallet_number' => $palletNumber, + 'serial_number' => $serialNumber, + 'panel_box_supplier' => $supplierNo, + 'panel_box_serial_number' => $pBoxSNo, + 'panel_box_code' => $panelBoxCode, + 'created_by' => $createdBy, + 'scanned_by' => $operatorName, + 'created_at' => $createdAt, + 'scanned_at' => now(), + 'updated_by' => $operatorName, + ]); + + $count = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->count('pallet_number'); + + if ($record) + { + + $this->snoCount = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->count(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'serial_number' => null, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + else + { + Notification::make() + ->title("Failed to insert scanned serial number '$serialNumber' into pallet table!") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'serial_number' => null, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'scanned_by' => $operatorName, + ]); + return; + } + } + catch (\Exception $e) + { + Notification::make() + ->title('Error: Serial not inserted.') + ->body("Something went wrong while inserting serial number '{$serialNumber}' into pallet table!\nScan the new serial number to proceed...") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'serial_number' => null, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + + public function handleUpdateSnoQuantity($newValue) + { + // Update the form field + $this->form->fill([ + 'Sno_quantity' => $newValue, + ]); + } + + public function redirectToPanelQrPdf($palletNo) + { + $this->palletNo = $palletNo; + + //return redirect()->route('download-qr-pdf', ['palletNo' => $this->palletNo]); + $url = route('download-qr-panel-pdf', ['panelPalletNo' => $this->palletNo]); + $this->js(<<form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $pendingPallet = $this->form->getState()['pending_pallet_list']; + + $palletNumber = trim($this->form->getState()['pallet_number'])?? null; + + $palletNumber = trim($palletNumber) ?? null; + + $serialNumber = trim($this->form->getState()['serial_number'])?? null; + + $serialNumber = trim($serialNumber) ?? null; + + $user = Filament::auth()->user(); + + $operatorName = $user->name; + + $isCompleted = $this->data['is_completed'] ?? false; + + $this->pendingPallet = $this->form->getState()['pending_pallet_list']; + + + $palletExist = PanelPalletValidation::where('pallet_number', $palletNumber) + ->where('plant_id', $plantId) + ->first(); + + if (!$palletExist) + { + Notification::make() + ->title("Pallet number '$palletNumber' does not have serial numbers to save!
Add the valid serial number into pallet number to proceed...") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $allCompleted = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->where('pallet_status', '=','Completed') + ->first(); + + if ($allCompleted) + { + Notification::make() + ->title("Pallet number '$palletNumber' already completed the master packing!
Generate the new pallet number or choose from pending pallet list!") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', '', $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => null, + 'pending_pallet_list' => null,//$pendingPallet + 'Sno_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + // $count = PalletValidation::where('plant_id', $plantId) + // ->where('pallet_number', $palletNumber) + // ->count('pallet_number'); + + if (!$isCompleted) + { + $updated = PanelPalletValidation::where('pallet_number', $palletNumber) + ->where('plant_id', $plantId) + ->update([ + 'updated_at' => now(), + 'updated_by' => $operatorName, + ]); + + if ($updated > 0) + { + Notification::make() + ->title("Pallet number '$palletNumber' records saved successfully!") + ->success() + ->duration(800) + ->send(); + + $this->dispatch('loadData', '', $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => null,//$palletNumber + 'pending_pallet_list' => null,//$pendingPallet + 'Sno_quantity' => 0,//$count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + else + { + $updated = PanelPalletValidation::where('pallet_number', $palletNumber) + ->where('plant_id', $plantId) + ->update([ + 'pallet_status' => 'Completed', + 'updated_at' => now(), + 'updated_by' => $operatorName, + ]); + + if ($updated > 0) + { + Notification::make() + ->title("Pallet number '$palletNumber' completed the master packing successfully!") + ->success() + ->duration(800) + ->send(); + + $this->dispatch('loadData', '', $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => null,//$palletNumber + 'pending_pallet_list' => null,//$pendingPallet + 'Sno_quantity' => 0,//$count + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + } + + public function processRemoveSNo() + { + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $pendingPallet = $this->form->getState()['pending_pallet_list']; + + $palletNumber = trim($this->form->getState()['pallet_number']) ?? null; + + $palletNumber = trim($palletNumber) ?? null; + + $serialNumber = trim($this->form->getState()['removeSno_number']) ?? null; + + $serialNumber = trim($serialNumber) ?? null; + + $user = Filament::auth()->user(); + + $operatorName = $user->name; + + if (!$palletNumber) + { + Notification::make() + ->title('Pallet number is required to remove.') + ->danger() + ->duration(5000) + ->send(); + return; + } + + + $count = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->count('pallet_number'); + + if (!$serialNumber) + { + Notification::make() + ->title('Serial number is required to remove.') + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (strlen($serialNumber) < 9 || strlen($serialNumber) > 20) + { + Notification::make() + ->title('Serial number should contain minimum 9 digits and maximum 20 digits.') + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (!ctype_alnum($serialNumber)) + { + Notification::make() + ->title('Serial number must contain alpha-numeric values only.') + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $invoiceExist = LocatorInvoiceValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNumber) + ->where('scanned_status', '=', 'Scanned') + ->first(); + + if ($invoiceExist) + { + Notification::make() + ->title("Scanned serial number '{$serialNumber}' already completed the scanning process and exist in invoice number '{$invoiceExist->invoice_number}'.
Scan the valid exist serial number to remove!") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $serialexist = PanelPalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNumber) + ->first(); + if (!$serialexist) + { + Notification::make() + ->title('Serial number not exists in pallet table.') + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $palletExist = PanelPalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNumber) + ->where('pallet_number', '!=', '') + ->where('pallet_number', '!=', null) + ->first(); + + if ($palletExist && $palletExist->pallet_number != $palletNumber) + { + Notification::make() + ->title("Scanned serial number exist in pallet number '$palletExist->pallet_number'.
Scan the valid exist serial number to remove!") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $locatorExist = PanelPalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNumber) + ->where('locator_number', '!=', '') + ->where('locator_number', '!=', null) + ->first(); + + if ($locatorExist && $locatorExist->locator_number) + { + Notification::make() + ->title("Scanned serial number exist in locator number '$locatorExist->locator_number'.
Scan the valid exist serial number to remove!") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + + $deleted = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->where('serial_number', $serialNumber) + ->forceDelete(); + + if ($deleted) + { + // Notification::make() + // ->title("Scanned serial number '$serialNumber' successfully removed from pallet table!
Scan the next exist serial number to remove...") + // ->success() + // ->duration(600) + // ->send(); + + $this->snoCount = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->count(); + + $this->form->fill([ + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'removeSno_number' => null, + 'pending_pallet_list' => $this->pendingPallet, + 'Sno_quantity' => $this->snoCount, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + $this->dispatch('loadData', $palletNumber, $plantId); + } + else + { + Notification::make() + ->title("Failed to remove scanned serial number '$serialNumber' from pallet table!") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + + //$this->dispatch('removeSno', $serialNumber, $palletNumber, $plantId); + } + + public function processPalletNo() + { + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $pendingPallet = $this->form->getState()['pending_pallet_list']; + + $palletNumber = trim($this->form->getState()['pallet_number']) ?? null; + + $palletNumber = trim($palletNumber) ?? null; + + $serialNumber = trim($this->form->getState()['serial_number']) ?? null; + + $serialNumber = trim($serialNumber) ?? null; + + $user = Filament::auth()->user(); + + $operatorName = $user->name; + + //$this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + if (!$palletNumber) + { + Notification::make() + ->title('Pallet number is required.') + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', '', $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($palletNumber) < 10) + { + Notification::make() + ->title("Pallet number '$palletNumber' must be at least 10 digits.") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $count = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->count('pallet_number'); + + + $palletNotCompleted = PanelPalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNumber) + ->where('pallet_status', '=','') + ->orWhere('pallet_status', '=',null) + ->first(); + + if (!$palletNotCompleted) + { + Notification::make() + ->title("Already completed for pallet number $palletNumber!") + ->danger() + ->duration(5000) + ->send(); + + $this->dispatch('loadData', $palletNumber, $plantId); + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $this->form->fill([ + 'serial_number' => null, + 'plant_id' => $plantId, + 'pallet_number' => $palletNumber, + 'pending_pallet_list' => $pendingPallet, + 'Sno_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + $this->dispatch('loadData', $palletNumber, $plantId); + + } + + public function getFormActions(): array + { + return []; + } +} diff --git a/app/Filament/Resources/PanelPalletValidationResource/Pages/EditPanelPalletValidation.php b/app/Filament/Resources/PanelPalletValidationResource/Pages/EditPanelPalletValidation.php new file mode 100644 index 00000000..7de53db8 --- /dev/null +++ b/app/Filament/Resources/PanelPalletValidationResource/Pages/EditPanelPalletValidation.php @@ -0,0 +1,22 @@ + Date: Mon, 30 Nov 2026 14:22:53 +0530 Subject: [PATCH 2/5] Added panel pallet validation importer and exporter --- .../Exports/PanelPalletValidationExporter.php | 69 +++++++++++++++++++ .../Imports/PanelPalletValidationImporter.php | 59 ++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 app/Filament/Exports/PanelPalletValidationExporter.php create mode 100644 app/Filament/Imports/PanelPalletValidationImporter.php diff --git a/app/Filament/Exports/PanelPalletValidationExporter.php b/app/Filament/Exports/PanelPalletValidationExporter.php new file mode 100644 index 00000000..bda06414 --- /dev/null +++ b/app/Filament/Exports/PanelPalletValidationExporter.php @@ -0,0 +1,69 @@ +label('NO') + ->state(function ($record) use (&$rowNumber) { + // Increment and return the row number + return ++$rowNumber; + }), + ExportColumn::make('plant.name') + ->label('PLANT'), + ExportColumn::make('item.code') + ->label('ITEM'), + ExportColumn::make('pallet_number') + ->label('PALLET NUMBER'), + ExportColumn::make('serial_number') + ->label('SERIAL NUMBER'), + ExportColumn::make('panel_box_supplier') + ->label('PANEL BOX SUPPLIER'), + ExportColumn::make('panel_box_code') + ->label('PANEL BOX CODE'), + ExportColumn::make('panel_box_serial_number') + ->label('PANEL BOX SERIAL NUMBER'), + ExportColumn::make('pallet_status') + ->label('PALLET STATUS'), + ExportColumn::make('created_at') + ->label('CREATED AT'), + ExportColumn::make('updated_at') + ->label('UPDATED AT'), + ExportColumn::make('scanned_at') + ->label('SCANNED AT'), + ExportColumn::make('created_by') + ->label('CREATED BY'), + ExportColumn::make('updated_by') + ->label('UPDATED BY'), + ExportColumn::make('scanned_by') + ->label('SCANNED BY'), + ExportColumn::make('deleted_at') + ->label('DELETED AT') + ->enabledByDefault(false), + ]; + } + + public static function getCompletedNotificationBody(Export $export): string + { + $body = 'Your panel pallet validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.'; + + if ($failedRowsCount = $export->getFailedRowsCount()) { + $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.'; + } + + return $body; + } +} diff --git a/app/Filament/Imports/PanelPalletValidationImporter.php b/app/Filament/Imports/PanelPalletValidationImporter.php new file mode 100644 index 00000000..fca40a9a --- /dev/null +++ b/app/Filament/Imports/PanelPalletValidationImporter.php @@ -0,0 +1,59 @@ +requiredMapping() + ->relationship() + ->rules(['required']), + ImportColumn::make('item') + ->requiredMapping() + ->relationship() + ->rules(['required']), + ImportColumn::make('pallet_number'), + ImportColumn::make('serial_number'), + ImportColumn::make('panel_box_supplier'), + ImportColumn::make('panel_box_code'), + ImportColumn::make('panel_box_serial_number'), + ImportColumn::make('pallet_status'), + ImportColumn::make('scanned_at') + ->rules(['datetime']), + ImportColumn::make('created_by'), + ImportColumn::make('scanned_by'), + ImportColumn::make('updated_by'), + ]; + } + + public function resolveRecord(): ?PanelPalletValidation + { + // return PanelPalletValidation::firstOrNew([ + // // Update existing records, matching them by `$this->data['column_name']` + // 'email' => $this->data['email'], + // ]); + + return new PanelPalletValidation(); + } + + public static function getCompletedNotificationBody(Import $import): string + { + $body = 'Your panel pallet validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; + + if ($failedRowsCount = $import->getFailedRowsCount()) { + $body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.'; + } + + return $body; + } +} -- 2.49.1 From 61b7e1e131dd5d361bb9275d592b94feb771d82c Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 30 Nov 2026 14:23:47 +0530 Subject: [PATCH 3/5] Added panel pallet validation policy file --- app/Policies/PanelPalletValidationPolicy.php | 106 +++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 app/Policies/PanelPalletValidationPolicy.php diff --git a/app/Policies/PanelPalletValidationPolicy.php b/app/Policies/PanelPalletValidationPolicy.php new file mode 100644 index 00000000..26125c31 --- /dev/null +++ b/app/Policies/PanelPalletValidationPolicy.php @@ -0,0 +1,106 @@ +checkPermissionTo('view-any PanelPalletValidation'); + } + + /** + * Determine whether the user can view the model. + */ + public function view(User $user, PanelPalletValidation $panelpalletvalidation): bool + { + return $user->checkPermissionTo('view PanelPalletValidation'); + } + + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + return $user->checkPermissionTo('create PanelPalletValidation'); + } + + /** + * Determine whether the user can update the model. + */ + public function update(User $user, PanelPalletValidation $panelpalletvalidation): bool + { + return $user->checkPermissionTo('update PanelPalletValidation'); + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, PanelPalletValidation $panelpalletvalidation): bool + { + return $user->checkPermissionTo('delete PanelPalletValidation'); + } + + /** + * Determine whether the user can delete any models. + */ + public function deleteAny(User $user): bool + { + return $user->checkPermissionTo('delete-any PanelPalletValidation'); + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, PanelPalletValidation $panelpalletvalidation): bool + { + return $user->checkPermissionTo('restore PanelPalletValidation'); + } + + /** + * Determine whether the user can restore any models. + */ + public function restoreAny(User $user): bool + { + return $user->checkPermissionTo('restore-any PanelPalletValidation'); + } + + /** + * Determine whether the user can replicate the model. + */ + public function replicate(User $user, PanelPalletValidation $panelpalletvalidation): bool + { + return $user->checkPermissionTo('replicate PanelPalletValidation'); + } + + /** + * Determine whether the user can reorder the models. + */ + public function reorder(User $user): bool + { + return $user->checkPermissionTo('reorder PanelPalletValidation'); + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, PanelPalletValidation $panelpalletvalidation): bool + { + return $user->checkPermissionTo('force-delete PanelPalletValidation'); + } + + /** + * Determine whether the user can permanently delete any models. + */ + public function forceDeleteAny(User $user): bool + { + return $user->checkPermissionTo('force-delete-any PanelPalletValidation'); + } +} -- 2.49.1 From 8ac6067e34642946f1bdb3e3b787cd6921eba63e Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 30 Nov 2026 14:24:21 +0530 Subject: [PATCH 4/5] Added panel pallet validation blade file --- .../create-panel-pallet-validation.blade.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 resources/views/filament/resources/panel-pallet-validation-resource/create-panel-pallet-validation.blade.php diff --git a/resources/views/filament/resources/panel-pallet-validation-resource/create-panel-pallet-validation.blade.php b/resources/views/filament/resources/panel-pallet-validation-resource/create-panel-pallet-validation.blade.php new file mode 100644 index 00000000..04291ddb --- /dev/null +++ b/resources/views/filament/resources/panel-pallet-validation-resource/create-panel-pallet-validation.blade.php @@ -0,0 +1,32 @@ + + + + +
+ {{ $this->form }} +
+ +
+ +
+ +
+ + @foreach ($this->getFormActions() as $action) + {{ $action }} + @endforeach + +
+ + @push('scripts') + + @endpush +
-- 2.49.1 From 77f02d555a9dcb6f287fbcd472dc669d64d917b9 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 30 Nov 2026 14:25:40 +0530 Subject: [PATCH 5/5] Added panel pallet data livewire page --- app/Livewire/PanelPalletDataTable.php | 58 +++++++++++++++++++ .../panel-pallet-data-table.blade.php | 46 +++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 app/Livewire/PanelPalletDataTable.php create mode 100644 resources/views/livewire/panel-pallet-data-table.blade.php diff --git a/app/Livewire/PanelPalletDataTable.php b/app/Livewire/PanelPalletDataTable.php new file mode 100644 index 00000000..06224d5e --- /dev/null +++ b/app/Livewire/PanelPalletDataTable.php @@ -0,0 +1,58 @@ + 'requestRemoveSerialNumber', + 'loadData' => 'loadPalletData', + ]; + + + + public function loadPalletData($palletNumber, $plantId) + { + $this->plantId = $plantId; + $this->palletNumber = $palletNumber; + $this->records = []; + + $this->records = PanelPalletValidation::query() + ->where('plant_id', $this->plantId) + ->where('pallet_number', $this->palletNumber) + ->orderBy('scanned_at') + ->get() + ->map(function ($record) { + return [ + 'created_at' => $record->created_at, + 'created_by' => $record->created_by ?? '', + 'pallet_number' => $record->pallet_number, + 'serial_number' => $record->serial_number, + 'panel_box_supplier' => $record->panel_box_supplier, + 'panel_box_code' => $record->panel_box_code, + 'panel_box_serial_number' => $record->panel_box_serial_number, + 'scanned_at' => $record->scanned_at, + 'scanned_by' => $record->scanned_by ?? '', + ]; + }) + ->toArray(); + + } + + public function render() + { + return view('livewire.panel-pallet-data-table'); + } +} diff --git a/resources/views/livewire/panel-pallet-data-table.blade.php b/resources/views/livewire/panel-pallet-data-table.blade.php new file mode 100644 index 00000000..c40e5c81 --- /dev/null +++ b/resources/views/livewire/panel-pallet-data-table.blade.php @@ -0,0 +1,46 @@ +
+

+ PANEL PALLET DATA TABLE: +

+
+ + + + + + + + + + + + + + + + + @forelse ($records as $index => $record) + + + + + + + + + + + + + @empty + + + + @endforelse + +
NoCreated DatetimeCreated ByPallet NumberSerial NumberPanel Box SupplierPanel Box CodePanel Box Serial NumberScanned DatetimeScanned By
{{ $index + 1 }}{{ $record['created_at'] ?? '-' }}{{ $record['created_by'] ?? '-' }}{{ $record['pallet_number'] ?? '-' }}{{ $record['serial_number'] ?? '-' }}{{ $record['panel_box_supplier'] ?? '-' }}{{ $record['panel_box_code'] ?? '-' }}{{ $record['panel_box_serial_number'] ?? '-' }}{{ $record['scanned_at'] ?? '-' }}{{ $record['scanned_by'] ?? '-' }}
+ No Panel pallet records found. +
+
+ +
-- 2.49.1