From 98c445a98a1ac3fcd12cf6aef66bd892d59f152e Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 1 Jul 2025 14:15:10 +0530 Subject: [PATCH] Added locator validation page and locator data table --- app/Filament/Pages/LocatorValidation.php | 1801 +++++++++++++++++ app/Livewire/LocatorDataTable.php | 132 ++ .../pages/locator-validation.blade.php | 77 + .../livewire/locator-data-table.blade.php | 44 + 4 files changed, 2054 insertions(+) create mode 100644 app/Filament/Pages/LocatorValidation.php create mode 100644 app/Livewire/LocatorDataTable.php create mode 100644 resources/views/filament/pages/locator-validation.blade.php create mode 100644 resources/views/livewire/locator-data-table.blade.php diff --git a/app/Filament/Pages/LocatorValidation.php b/app/Filament/Pages/LocatorValidation.php new file mode 100644 index 0000000..0347698 --- /dev/null +++ b/app/Filament/Pages/LocatorValidation.php @@ -0,0 +1,1801 @@ +form->fill([ + 'plant_id'=>$this->plantId, + 'pallet_quantity' => 0, + ]); + } + + public function form(Form $form): Form + { + return $form + ->statePath('filters') + ->schema([ + Section::make('') + ->schema([ + Select::make('plant_id') + ->options(Plant::pluck('name', 'id')) + ->label('Plant') + ->reactive() + ->required(), + TextInput::make('scan_pallet_no') + ->label('Scan Pallet No') + ->reactive() + // ->readonly(fn () => $this->disablePalletNo) + ->readOnly(fn (callable $get) => !empty($get('scan_serial_no')) || !empty($get('scan_locator_no'))) + ->extraAttributes([ + 'wire:keydown.enter' => 'processPalletNo($event.target.value)', + ]), + TextInput::make('scan_serial_no') + ->label('Scan Serial No') + // ->readOnly(fn () => $this->disableSerialNo) + ->readOnly(fn (callable $get) => !empty($get('scan_pallet_no')) || !empty($get('scan_locator_no'))) + ->reactive() + ->extraAttributes([ + 'wire:keydown.enter' => 'processSerialNo($event.target.value)', + ]), + TextInput::make('scan_locator_no') + ->label('Scan Locator No') + ->reactive() + // ->readOnly(fn ($get) => filled($get('scan_locator_no'))) + ->extraAttributes([ + 'id' => 'scan_locator_no', + 'wire:keydown.enter' => 'processLocatorNo($event.target.value)', + ]), + TextInput::make('pallet_quantity') + ->label('Pallet Quantity') + ->reactive() + ->default('0') + ->readOnly(), + ]) + ->columns(5) + ]); + } + + public function processPalletNo($palletNo) + { + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $palletNo= $this->form->getState()['scan_pallet_no']; + + $palletNo = trim($palletNo) ?? null; + + $serialNo = $this->form->getState()['scan_serial_no'] ?? null; + + $serialNo = trim($serialNo) ?? null; + + $scanLocator = $this->form->getState()['scan_locator_no']; + + $scanLocator = trim($scanLocator) ?? null; + + $operatorName = Filament::auth()->user()->name; + + if ($serialNo && $scanLocator ) + { + return; + } + + if ($palletNo == null || $palletNo == '') + { + Notification::make() + ->title("Pallet number cannot be empty!") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($palletNo) < 10) + { + Notification::make() + ->title("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $Palletexists = PalletValidation::where('pallet_number', $palletNo) + ->where('plant_id', $plantId)->first(); + if(!$Palletexists) + { + Notification::make() + ->title("Pallet number '$palletNo' does not found in pallet table.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $locators = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->get(); + + $query = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo); + + $palletRow = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->first(); + + $locatorNumber = $palletRow->locator_number; + + // $allRows = PalletValidation::where('plant_id', $plantId) + // ->where(function ($query) use ($palletNo, $locatorNumber) { + // $query->where('pallet_number', $palletNo) + // ->orWhere('locator_number', $locatorNumber); + // }) + // ->get(); + + // $count = $allRows + // ->filter(function ($row) { + // return !empty($row->pallet_number); + // }) + // ->unique('pallet_number') + // ->count(); + + // $hasAnyLocator = $allRows->contains(function ($row) + // { + // return !empty($row->locator_number); + // }); + // if (!$hasAnyLocator) + // { + // $count = 0; + // } + $count = PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $locatorNumber) + ->count('locator_number'); + + $pallets = $query->first(); + + if ($pallets) + { + $this->locatorNumber = $pallets->locator_number; + } + else + { + $this->locatorNumber = ''; + } + + $allCompleted = $locators->every(function ($pallet) + { + return $pallet->pallet_status == 'Completed'; + }); + + $notAlreadyCompleted = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->whereNull('pallet_status') + ->orWhere('pallet_status', '=','') + // ->where('locator_number', $this->scanLocator) + ->first(); + + if($notAlreadyCompleted) + { + Notification::make() + ->title("Pallet number '{$palletNo}' does not completed the master packing.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if ($allCompleted && $locators->count() > 0) { + $this->disableSerialNo = true; + $this->disablePalletNo = true; + $this->dispatch('focus-scan-locator-no'); + // $this->form->fill([ + // 'plant_id' => $plantId, + // 'scan_pallet_no' => $palletNo, + // 'pallet_quantity' => $count, + // 'scan_locator_no' => $locatorNumber, + // ]); + + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $locatorNumber, + 'pallet_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + if ($this->locatorNumber) + { + Notification::make() + ->title("Press 'Remove Pallet' button to remove Pallet number : '$palletNo' from Locator number : '$locatorNumber'..!") + ->info() + ->send(); + } + + $this->dispatch('loadData' ,$palletNo,$locatorNumber,$plantId); + } + } + + public function processSerialNo($serialNo) + { + + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $this->plantId = $plantId; + + $palletNo = $this->form->getState()['scan_pallet_no']; + + $scanLocator = $this->form->getState()['scan_locator_no']; + + $this->disablePalletNo = true; + + $operatorName = Filament::auth()->user()->name; + + if ($palletNo && $scanLocator ) + { + return; + } + + if (strlen($serialNo) < 13) + { + Notification::make() + ->title("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (!ctype_alnum($serialNo)) + { + Notification::make() + ->title("Serial number '$serialNo' must contain alpha-numeric values only.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->where('scanned_status', '=','Scanned') + ->first(); + + $invoiceNo = $invoicesnoexists?->invoice_number; + + if ($invoicesnoexists) + { + Notification::make() + ->title("Serial number '$serialNo' already exists in invoice number '$invoiceNo' and completed the scanning process.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $existingRecord = PalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->where(function ($query) { + $query->where('pallet_number', '!=', '') + ->whereNotNull('pallet_number'); + }) + ->first(); + + $existingLocator = PalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->first(); + + $palletnumber = $existingRecord?->pallet_number; + + $locatorNo = $existingLocator?->locator_number; + + if ($existingRecord) + { + Notification::make() + ->title("Scanned serial number '$serialNo' already exist in pallet number '$palletnumber'!
Scan the valid new serial number to proceed...") + ->danger() + ->send(); + + // $this->form->fill([ + // 'plant_id' => $plantId, + // 'scan_serial_no' => null, + // 'created_by' => $operatorName, + // 'scanned_by' => $operatorName, + // ]); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + $this->dispatch('loadLocator' ,'',$plantId); + + return; + } + else + { + $this->disableSerialNo = true; + + if ($locatorNo) { + Notification::make() + ->title("Press 'Remove Serial Number' button to remove Serial number : '$serialNo' from Locator number : '$locatorNo'..!") + ->info() + ->send(); + } + + $count = PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $locatorNo) + ->count('locator_number'); + + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $locatorNo, + 'pallet_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + + $this->dispatch('focus-scan-locator-no'); + + $this->dispatch('loadserialNo' ,$serialNo,$plantId); + + } + } + + public function processLocatorNo($locatorNo) + { + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $this->plantId = $plantId; + + $palletNo= $this->form->getState()['scan_pallet_no']; + + $palletNo = trim($palletNo) ?? null; + + $serialNo = $this->form->getState()['scan_serial_no'] ?? null; + + $serialNo = trim($serialNo) ?? null; + + $scanLocator = $this->form->getState()['scan_locator_no']; + + $scanLocator = trim($scanLocator) ?? null; + + $operatorName = Filament::auth()->user()->name; + + $this->locators = PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->get(); + + if (strlen($scanLocator) < 7) + { + Notification::make() + ->title("Locator number '$scanLocator' must be at least 7 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $exists = Locator::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->first(); + + if(!$exists) + { + Notification::make() + ->title("Locator number '{$scanLocator}' does not exist in the master.") + ->danger() + ->send(); + + // $this->form->fill([ + // 'plant_id' => $plantId, + // 'scan_serial_no' => null, + // 'scan_pallet_no' => null, + // 'pallet_quantity' => 0, + // ]); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + $this->dispatch('loadLocator' ,'',$plantId); + return; + } + + $locator = Locator::where('locator_number', $scanLocator) + ->where('plant_id', $plantId) + ->first(); + + if ($locator->locator_quantity >= 2) { // Use >= for simplicity + Notification::make() + ->title("No space available for locator number '{$scanLocator}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if ($palletNo) + { + if (strlen($palletNo) < 10) + { + Notification::make() + ->title("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $notAlreadyCompleted = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->whereNull('pallet_status') + ->orWhere('pallet_status', '=','') + // ->where('locator_number', $this->scanLocator) + ->first(); + + if($notAlreadyCompleted) + { + Notification::make() + ->title("Pallet number '{$palletNo}' does not completed the master packing.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $locatorExist = PalletValidation::where('pallet_number', $palletNo) + ->where('plant_id', $plantId) + ->first(); + + if ($locatorExist && $locatorExist->locator_number && $locatorExist->locator_number != $scanLocator) + { + Notification::make() + ->title("Pallet number '$palletNo' is already assigned to locator number '{$locatorExist->locator_number}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + return; + } + + if ($locatorExist && $locatorExist->locator_number == $scanLocator) + { + Notification::make() + ->title("Press 'Remove Pallet' button to remove Pallet number : '$palletNo' from Locator number : '$scanLocator'..!") + ->info() + ->send(); + } + else + { + Notification::make() + ->title("Press 'Add Pallet' button to add Pallet number : '$palletNo' into Locator number : '$scanLocator'..!") + ->info() + ->send(); + } + } + else + { + if ($serialNo == '' || $serialNo == null) { + Notification::make() + ->title("Serial number is required to add or remove when pallet number is empty.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($serialNo) < 13) + { + Notification::make() + ->title("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (!ctype_alnum($serialNo)) + { + Notification::make() + ->title("Serial number '$serialNo' must contain alpha-numeric values only.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->where('scanned_status', '=','Scanned') + ->first(); + + $invoiceNo = $invoicesnoexists?->invoice_number; + + if ($invoicesnoexists) + { + Notification::make() + ->title("Serial number '$serialNo' already exists in invoice number '$invoiceNo' and completed the scanning process.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + return; + } + + $serialExist = PalletValidation::where('serial_number', $serialNo) + ->where('plant_id', $plantId) + ->first(); + + if ($serialExist && $serialExist->locator_number && $serialExist->locator_number != $scanLocator) + { + Notification::make() + ->title("Serial number '$serialNo' is already assigned to locator number '{$serialExist->locator_number}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if ($serialExist && $serialExist->locator_number == $scanLocator) + { + Notification::make() + ->title("Press 'Remove Serial Number' button to remove Serial number : '$serialNo' from Locator number : '$scanLocator'..!") + ->info() + ->send(); + } + else + { + Notification::make() + ->title("Press 'Add Serial Number' button to add Serial number : '$serialNo' into Locator number : '$scanLocator'..!") + ->info() + ->send(); + } + } + + $count = PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->count('locator_number'); + + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => $count, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + $this->dispatch('loadLocator' ,$scanLocator,$plantId); + } + + public function addPallet() + { + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $this->plantId = $plantId; + + $palletNo= $this->form->getState()['scan_pallet_no']; + + $palletNo = trim($palletNo) ?? null; + + $serialNo = $this->form->getState()['scan_serial_no'] ?? null; + + $serialNo = trim($serialNo) ?? null; + + $scanLocator = $this->form->getState()['scan_locator_no']; + + $scanLocator = trim($scanLocator) ?? null; + + $operatorName = Filament::auth()->user()->name; + + if ($scanLocator == null || $scanLocator == '') { + Notification::make() + ->title("Locator number cannot be empty!") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($scanLocator) < 7) + { + Notification::make() + ->title("Locator number '$scanLocator' must be at least 7 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $exists = Locator::where('locator_number', $scanLocator) + ->where('plant_id', $plantId) + ->first(); + + if (!$exists) + { + Notification::make() + ->title("Locator number '{$scanLocator}' does not exist in the master.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $locator = Locator::where('locator_number', $scanLocator) + ->where('plant_id', $plantId) + ->first(); + + if ($locator->locator_quantity >= 2) { + Notification::make() + ->title("No space available for locator number '{$scanLocator}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if($palletNo) + { + if (strlen($palletNo) < 10) + { + Notification::make() + ->title("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $Palletexists = PalletValidation::where('pallet_number', $palletNo)->where('plant_id', $plantId)->first(); + + if(!$Palletexists) + { + Notification::make() + ->title("Pallet number '$palletNo' does not found in pallet table.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $notAlreadyCompleted = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->whereNull('pallet_status') + ->orWhere('pallet_status', '=','') + // ->where('locator_number', $this->scanLocator) + ->first(); + + if($notAlreadyCompleted) + { + Notification::make() + ->title("Pallet number '{$palletNo}' does not completed the master packing.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $alreadyAssigned = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->where('locator_number', '!=', '') + ->where('locator_number', '!=', null) + // ->where('locator_number', $this->scanLocator) + ->first(); + + if ($alreadyAssigned) + { + Notification::make() + ->title("Pallet number '{$palletNo}' is already added into locator number '{$alreadyAssigned->locator_number}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $updatedRows = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->update([ + 'locator_number' => $scanLocator, + ]); + + $count = PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->count('locator_number'); + + if ($updatedRows > 0) + { + Notification::make() + ->title("Scanned pallet number '$palletNo' added into locator number '$scanLocator' successfully.") + ->success() + ->send(); + $locator = Locator::where('locator_number', $scanLocator) + ->where('plant_id', $plantId)->first(); + $locator->increment('locator_quantity'); + + Locator::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->update(['updated_at' => now(), 'operator_id' => $operatorName]); + + PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->where('locator_number', $scanLocator) + ->update(['locator_quantity' => $locator->locator_quantity,'updated_at' => now(), 'updated_by' => $operatorName]); + + PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->update(['locator_quantity' => $locator->locator_quantity, 'updated_at' => now()]); + + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => null, + 'scan_locator_no' => null, + 'pallet_quantity' => null, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, + ]); + $this->dispatch('loadLocator' ,$scanLocator,$plantId); + return; + } + else + { + Notification::make() + ->title("pallet number failed to add into locator number '$scanLocator'") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + else + { + + if ($serialNo == '' || $serialNo == null) { + Notification::make() + ->title("Serial number is required to add when pallet number is empty.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($serialNo) < 13) + { + Notification::make() + ->title("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (!ctype_alnum($serialNo)) + { + Notification::make() + ->title("Serial number '$serialNo' must contain alpha-numeric values only.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->where('scanned_status', '=','Scanned') + ->first(); + + $invoiceNo = $invoicesnoexists?->invoice_number; + + if ($invoicesnoexists) + { + Notification::make() + ->title("Serial number '$serialNo' already exists in invoice number '$invoiceNo' and completed the scanning process.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $palletexists = PalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->where('pallet_number', '!=', '') + ->where('pallet_number', '!=', null) + ->first(); + + if($palletexists) + { + Notification::make() + ->title("Serial number '$serialNo' already exists in pallet number '{$palletexists->pallet_number}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $exists = PalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->where('locator_number', '!=', '') + ->where('locator_number', '!=', null) + ->first(); + + if ($exists) + { + Notification::make() + ->title("Serial number '$serialNo' already exists in locator number '{$exists->locator_number}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + PalletValidation::create([ + 'plant_id' => $plantId, + 'pallet_number' => null, + 'locator_number' => $scanLocator, + 'serial_number' => $serialNo, + 'locator_quantity'=> $locator->locator_quantity, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + 'updated_by' => $operatorName, + 'updated_at' => now(), + 'scanned_at' => now(), + ]); + + Locator::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->update(['updated_at' => now(), 'operator_id' => $operatorName]); + + PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->update(['locator_quantity' => $locator->locator_quantity, 'updated_at' => now()]); + + + Notification::make() + ->title("Scanned serial number '$serialNo' added into locator number '$scanLocator' successfully.") + ->success() + ->send(); + + // $count = PalletValidation::where('plant_id', $plantId) + // ->where('locator_number', $scanLocator) + // ->count('locator_number'); + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => null, + 'scan_locator_no' => null, + 'pallet_quantity' => null, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + + // $this->disableSerialNo = false; + // $this->disablePalletNo = false; + + $this->dispatch('loadLocator' ,$scanLocator,$plantId); + + } + } + + public function removePallet() + { + $plantId = $this->form->getState()['plant_id']; + + $plantId = trim($plantId) ?? null; + + $this->plantId = $plantId; + + $palletNo = $this->form->getState()['scan_pallet_no']; + + $palletNo = trim($palletNo) ?? null; + + $serialNo = $this->form->getState()['scan_serial_no'] ?? null; + + $serialNo = trim($serialNo) ?? null; + + $scanLocator = $this->form->getState()['scan_locator_no']; + + $scanLocator = trim($scanLocator) ?? null; + + $operatorName = Filament::auth()->user()->name; + + if ($scanLocator == null || $scanLocator == '') { + Notification::make() + ->title("Locator number cannot be empty!") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($scanLocator) < 7) + { + Notification::make() + ->title("Locator number '$scanLocator' must be at least 7 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $exists = Locator::where('locator_number', $scanLocator) + ->where('plant_id', $plantId) + ->first(); + + if (!$exists) + { + Notification::make() + ->title("Locator number '{$scanLocator}' does not exist in the master.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if($palletNo) + { + if (strlen($palletNo) < 10) + { + Notification::make() + ->title("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $Palletexists = PalletValidation::where('pallet_number', $palletNo)->where('plant_id', $plantId)->first(); + + if(!$Palletexists) + { + Notification::make() + ->title("Pallet number '$palletNo' does not found in pallet table.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $notAlreadyCompleted = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->whereNull('pallet_status') + ->orWhere('pallet_status', '=','') + // ->where('locator_number', $this->scanLocator) + ->first(); + + if($notAlreadyCompleted) + { + Notification::make() + ->title("Pallet number '{$palletNo}' does not completed the master packing.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $palletValidation = PalletValidation::where('pallet_number', $palletNo) + ->where('plant_id', $plantId) + ->where('locator_number', '!=', '') + ->where('locator_number', '!=',null) + ->first(); + + if ($palletValidation && $palletValidation->locator_number != $scanLocator) + { + Notification::make() + ->title("Pallet number '$palletNo' is exists in locator number '$palletValidation->locator_number'
Scan the valid locator number to remove pallet number.") + ->danger() + ->send(); + $this->dispatch('loadLocator', '', $plantId); + + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $palletRecord = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->whereNotNull('locator_number') + ->where('locator_number', '!=', '') + ->first(); + + if (!$palletRecord) + { + Notification::make() + ->title("Pallet number '{$palletNo}' doesn't exist in locator number.
Add locator number to proceed...") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $updatedRows = PalletValidation::where('plant_id', $plantId) + ->where('pallet_number', $palletNo) + ->update([ + 'locator_number' => null, + 'locator_quantity' => 0, + 'updated_at' => now(), + 'updated_by' => $operatorName, + ]); + + // if ($updatedRows > 0) + // { + // // Locator::where('locator_number', $scanLocator)->decrement('locator_quantity'); + + // $locator = Locator::where('locator_number', $scanLocator) + // ->where('plant_id', $plantId) + // ->first(); + // // $locator->decrement('locator_quantity'); + // $locator->locator_quantity; + + // $locator --; + + // Locator::where('plant_id', $plantId) + // ->where('locator_number', $scanLocator) + // ->update(['updated_at' => now(), 'operator_id' => $operatorName]); + + // PalletValidation::where('plant_id', $plantId) + // ->where('locator_number', $scanLocator) + // ->update(['locator_quantity' => $locator->locator_quantity, 'updated_at' => now()]); + + if ($updatedRows > 0) + { + + $locator = Locator::where('locator_number', $scanLocator) + ->where('plant_id', $plantId) + ->first(); + + if ($locator && $locator->locator_quantity > 0) { + $locator->locator_quantity = $locator->locator_quantity - 1; + $locator->save(); + } + + Locator::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->update([ + 'updated_at' => now(), + 'operator_id' => $operatorName + ]); + + PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->update([ + 'locator_quantity' => $locator->locator_quantity, + 'updated_at' => now() + ]); + + Notification::make() + ->title("Scanned pallet number '{$palletNo}' removed from locator number '$scanLocator' successfully.") + ->success() + ->send(); + $this->dispatch('loadLocator' ,$scanLocator,$plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => null, + 'scan_locator_no' => null, + 'pallet_quantity' => null, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, + ]); + } + else + { + Notification::make() + ->title("No matching pallet found or locator number already empty.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => $palletNo, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + } + else + { + + if ($serialNo == '' || $serialNo == null) { + Notification::make() + ->title("Serial number is required to remove when pallet number is empty.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($serialNo) < 13) + { + Notification::make() + ->title("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (!ctype_alnum($serialNo)) + { + Notification::make() + ->title("Serial number '$serialNo' must contain alpha-numeric values only.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->where('scanned_status', '=','Scanned') + ->first(); + + $invoiceNo = $invoicesnoexists?->invoice_number; + + if ($invoicesnoexists) + { + Notification::make() + ->title("Serial number '$serialNo' already exists in invoice number '$invoiceNo' and completed the scanning process.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $exists = PalletValidation::where('serial_number', $serialNo) + ->where('plant_id', $plantId) + ->first(); + + if (!$exists) { + Notification::make() + ->title("Serial number '{$serialNo}' does not exist in the pallet table to remove.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $existsInPallet = PalletValidation::where('serial_number', $serialNo) + ->where('pallet_number', '!=', '') + ->where('pallet_number', '!=',null) + ->where('plant_id', $plantId) + ->first(); + + if ($existsInPallet) { + Notification::make() + ->title("Serial number '{$serialNo}' already exists in pallet number '$existsInPallet->pallet_number'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $existsInPallet = PalletValidation::where('serial_number', $serialNo) + ->where('locator_number', '!=', '') + ->where('locator_number', '!=',null) + ->where('plant_id', $plantId) + ->first(); + + if ($existsInPallet && $existsInPallet->locator_number != $scanLocator) { + Notification::make() + ->title("Serial number '{$serialNo}' exist in the locator number '$existsInPallet->locator_number'.
Scan the valid locator number to remove serial number.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $deleted = PalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->forceDelete(); + + if ($deleted > 0) + { + Locator::where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->update(['updated_at' => now(), 'operator_id' => $operatorName]); + + Notification::make() + ->title("Scanned serial number '{$serialNo}' removed from locator number '$scanLocator' successfully.") + ->success() + ->send(); + + $this->dispatch('loadLocator', $scanLocator, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'scan_serial_no' => null, + 'scan_pallet_no' => null, + 'scan_locator_no' => null, + 'pallet_quantity' => null, + 'created_by' => $operatorName, + 'updated_by' => $operatorName, + ]); + } + else + { + Notification::make() + ->title("No matching record found for serial number '{$serialNo}'.") + ->danger() + ->send(); + $this->dispatch('loadLocator' ,'',$plantId); + $this->form->fill + ([ + 'plant_id' => $plantId, + 'scan_serial_no' => $serialNo, + 'scan_pallet_no' => null, + 'scan_locator_no' => $scanLocator, + 'pallet_quantity' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + } + + public static function getNavigationLabel(): string + { + return 'Locator Validations'; + } + + public static function canAccess(): bool + { + return Auth::check() && Auth::user()->can('create locator validation page'); + } + +} diff --git a/app/Livewire/LocatorDataTable.php b/app/Livewire/LocatorDataTable.php new file mode 100644 index 0000000..531fecc --- /dev/null +++ b/app/Livewire/LocatorDataTable.php @@ -0,0 +1,132 @@ + 'loadPalletData', + 'loadLocator' => 'loadLocatorData', + 'loadserialNo' => 'loadserialNodata', + ]; + + public function loadserialNodata($serialNo, $plantId) + { + $this->plantId = $plantId; + $this->serialNumber = $serialNo; + $this->locators = []; + + $record = PalletValidation::where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->whereNotNull('locator_number') + ->where('locator_number', '!=', '') + ->first(); + + if (!$record) + { + return; + } + + $locatorNumber = $record->locator_number; + + $this->locators = PalletValidation::where('plant_id', $plantId) + ->where('locator_number', $locatorNumber) + ->whereNotNull('locator_number') + ->where('locator_number', '!=', '') + ->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 ?? '', + 'locator_number' => $record->locator_number ?? '', + 'locator_quantity' => $record->locator_quantity ?? '', + 'updated_at' => $record->updated_at ?? '', + 'updated_by' => $record->updated_by ?? '', + ]; + }) + ->toArray(); + } + + public function loadPalletData($palletNumber,$locatorNumber,$plantId) + { + $this->plantId = $plantId; + $this->palletNumber = $palletNumber; + $this->locators = []; + + $this->locators = PalletValidation::query() + ->where('plant_id', $plantId) + ->where(function ($query) use ($palletNumber, $locatorNumber) { + $query->where(function ($q) use ($palletNumber) { + $q->where('pallet_number', $palletNumber) + ->whereNotNull('locator_number') + ->where('locator_number', '!=', ''); + }) + ->orWhere(function ($q) use ($locatorNumber) { + $q->where('locator_number', $locatorNumber) + ->whereNotNull('locator_number') + ->where('locator_number', '!=', ''); + }); + }) + ->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 ?? '', + 'locator_number' => $record->locator_number ?? '', + 'locator_quantity' => $record->locator_quantity ?? '', + 'updated_at' => $record->updated_at ?? '', + 'updated_by' => $record->updated_by ?? '', + ]; + }) + ->toArray(); + } + + public function loadLocatorData($scanLocator, $plantId) + { + $this->plantId = $plantId; + $this->locatorNumber = $scanLocator; + $this->locators = []; + + $this->locators = PalletValidation::query() + ->where('plant_id', $plantId) + ->where('locator_number', $scanLocator) + ->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 ?? '', + 'locator_number' => $record->locator_number ?? '', + 'locator_quantity' => $record->locator_quantity ?? '', + 'updated_at' => $record->updated_at ?? '', + 'updated_by' => $record->updated_by ?? '', + ]; + }) + ->toArray(); + } + + public function render() + { + return view('livewire.locator-data-table'); + } +} diff --git a/resources/views/filament/pages/locator-validation.blade.php b/resources/views/filament/pages/locator-validation.blade.php new file mode 100644 index 0000000..391a69c --- /dev/null +++ b/resources/views/filament/pages/locator-validation.blade.php @@ -0,0 +1,77 @@ +{{-- + +
+
+ {{ $this->form }} +
+ +
+ +
+ +
+ + + +
--}} + + + +
+ {{-- Render the Select form fields --}} +
+ {{ $this->form }} +
+ + {{-- Add Pallet and Remove Pallet buttons --}} +
+ + + {{-- --}} +
+ +
+ +
+
+ + + +
+ diff --git a/resources/views/livewire/locator-data-table.blade.php b/resources/views/livewire/locator-data-table.blade.php new file mode 100644 index 0000000..980074f --- /dev/null +++ b/resources/views/livewire/locator-data-table.blade.php @@ -0,0 +1,44 @@ +
+

+ LOCATOR DATA TABLE: +

+
+ + + + + + + + + + + + + + + + @forelse ($locators as $index => $locator) + + + + + + + + + + + + @empty + + + + @endforelse + +
NoCreated DatetimeCreated ByPallet NumberSerial NumberLocator NumberLocator QuantityUpdated DatetimeUpdated By
{{ $index + 1 }}{{ $locator['created_at']?->format('Y-m-d H:i:s') ?? '-' }}{{ $locator['created_by'] ?? '-' }}{{ $locator['pallet_number'] ?? '-' }}{{ $locator['serial_number'] ?? '-' }}{{ $locator['locator_number'] ?? '-' }}{{ $locator['locator_quantity'] ?? '-' }}{{ $locator['updated_at']?->format('Y-m-d H:i:s') ?? '-' }}{{ $locator['updated_by'] ?? '-' }}
+ No locator records found. +
+
+ +