From 017088c38017d1b5a1ca35bdb3465cf72713dab5 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 2 Jul 2025 13:06:00 +0530 Subject: [PATCH] Added create pallet from locator page and livewire pages and table --- app/Filament/Pages/PalletFromLocator.php | 933 ++++++++++++++++++ app/Livewire/PalletFromLocatorDataTable.php | 88 ++ .../pages/pallet-from-locator.blade.php | 51 + .../pallet-from-locator-data-table.blade.php | 42 + 4 files changed, 1114 insertions(+) create mode 100644 app/Filament/Pages/PalletFromLocator.php create mode 100644 app/Livewire/PalletFromLocatorDataTable.php create mode 100644 resources/views/filament/pages/pallet-from-locator.blade.php create mode 100644 resources/views/livewire/pallet-from-locator-data-table.blade.php diff --git a/app/Filament/Pages/PalletFromLocator.php b/app/Filament/Pages/PalletFromLocator.php new file mode 100644 index 000000000..b16e6b6a4 --- /dev/null +++ b/app/Filament/Pages/PalletFromLocator.php @@ -0,0 +1,933 @@ +Checking = []; + // session()->forget('latestPalletSerials'); + session()->forget('latestPalletNumber'); + session()->forget('latestPalletDateTime'); + session()->forget('latestPalletCreatedBy'); + } + + // use InteractsWithForms; + + // public $form; + + 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() + ->columnSpan(1) + ->disabled(fn (Get $get) => $get('plant_id')) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $plantId = $get('plant_id'); + if ($plantId) + { + $set('plant', $plantId); + $set('scan_locator_number', null); + $set('scan_serial_number', null); + $set('scan_remove_sno', null); + $set('sno_quantity', 0); + } + else + { + $set('plant', null); + $set('scan_locator_number', null); + $set('scan_serial_number', null); + $set('scan_remove_sno', null); + $set('sno_quantity', 0); + } + }), + Hidden::make('plant') + ->reactive(), + TextInput::make('scan_locator_number') + ->label('Scan Locator Number') + ->reactive() + ->columnSpan(1) + ->readOnly(fn (callable $get) => !$get('plant') || $get('scan_serial_number') || $get('scan_remove_sno')) + ->extraAttributes([ + 'wire:keydown.enter' => 'processLocatorNo($event.target.value)', + ]), + TextInput::make('scan_serial_number') + ->label('Scan Serial Number') + ->reactive() + ->columnSpan(1) + ->readOnly(fn (callable $get) => !$get('plant') || $get('scan_locator_number') || $get('scan_remove_sno')) + ->extraAttributes([ + 'wire:keydown.enter' => 'processSerialNo($event.target.value)', + ]), + TextInput::make('scan_remove_sno') + ->label('Remove Serial Number') + ->reactive() + ->columnSpan(1) + ->readOnly(fn (callable $get) => !$get('plant') || $get('scan_locator_number') || $get('scan_serial_number') || count($this->records) <= 0) + ->extraAttributes([ + 'wire:keydown.enter' => 'processremoveSNo($event.target.value)', + ]), + TextInput::make('sno_quantity') + ->label('SNo. Quantity') + ->reactive() + ->readOnly() + ->columnSpan(1), + ]) + ->columns(5) + ]); + } + + public function processLocatorNo($locatorNo) + { + $locatorNo = trim($locatorNo); + $this->locatorNo = $locatorNo; + + $plantId = trim($this->form->getState()['plant']) ?? null; + $this->plantId = $plantId; + $serialNo = trim($this->form->getState()['scan_serial_number']) ?? null; + $removeSerial = trim($this->form->getState()['scan_remove_sno']) ?? null; + //$operatorName = Filament::auth()->user()->name; + $count = count($this->records); + + if ($serialNo != null || $serialNo != '') + { + Notification::make() + ->title('Press enter on "Scan Serial Number" field to proceed..!') + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => $serialNo, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else if ($removeSerial != null || $removeSerial != '') + { + Notification::make() + ->title('Press enter on "Remove Serial Number" field to proceed..!') + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => $removeSerial, + 'sno_quantity' => $count, + ]); + return; + } + + if ($locatorNo == null || $locatorNo == '') + { + Notification::make() + ->title('Unknown: Locator') + ->body("Locator number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + if (strlen($locatorNo) < 7) + { + Notification::make() + ->title("Locator number '$locatorNo' must be at least 7 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + + $exists = Locator::where('locator_number', $locatorNo) + ->where('plant_id', $plantId) + ->first(); + + if (!$exists) + { + Notification::make() + ->title("Locator number '$locatorNo' does not exist in the master.") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + + $serialLocator = PalletValidation::query() + ->where('plant_id', $plantId) + ->where('locator_number', $locatorNo) + ->where(function($query) { + $query->whereNull('pallet_number') + ->orWhere('pallet_number', ''); + }) + ->get(); + + //$locatorSno = $serialLocator->pluck('serial_number')->toArray(); + + if ($serialLocator->count() <= 0) + { + Notification::make() + ->title('Serial Locator Number Not Found') + ->body("Scanned locator number '$locatorNo' does not have any locator serial numbers to store into the pallet.
+ Please scan a valid stored locator number to proceed.") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else + { + Notification::make() + ->title('Add: Locator Serial Numbers') + ->body("Scanned locator number '$locatorNo' has '".$serialLocator->count()."' locator serial numbers!
Do you want to store it into 'PALLET DATA' table?") + ->info() + ->seconds(2) + ->send(); + $this->dispatch('open-confirm-modal', locatorNo: $locatorNo, plantId: $plantId); + } + } + + public function loadlocatorData($locatorNo, $serialNo, $removeserial, $plantId) + { + $operatorName = Filament::auth()->user()->name; + + if(count($this->records) <= 0) + { + session(['latestPalletDateTime' => now()->format('Y-m-d H:i:s')]); + session(['latestPalletCreatedBy' => $operatorName]); + } + + if ($locatorNo != null && $locatorNo != '') + { + $serialNumbers = PalletValidation::query() + ->where('plant_id', $plantId) + ->where(function($query) { + $query->whereNull('pallet_number') + ->orWhere('pallet_number', ''); + }) + ->where('locator_number', $locatorNo) + ->get() + ->map(function ($record) use($operatorName) { + return [ + 'created_at' => session('latestPalletDateTime') ?? '', + 'created_by' => session('latestPalletCreatedBy') ?? '', + // 'pallet_number' => '', + 'serial_number' => $record->serial_number, + 'scanned_at' => now()->format('Y-m-d H:i:s'), + 'scanned_by' => $operatorName ?? '', + ]; + }) + ->toArray(); + + if (count($this->records) > 0) + { + // $this->records = array_values(array_filter($this->records, function ($record) use ($serialNumbers) { + // return !in_array($record['serial_number'], $serialNumbers); + // })); + foreach ($serialNumbers as $serial) + { + $serialNo = $serial['serial_number']; + $this->records = array_values(array_filter($this->records, function ($record) use ($serialNo) { + return $record['serial_number'] != $serialNo; + })); + } + } + + $newRecords = PalletValidation::query() + ->where('plant_id', $plantId) + ->where(function($query) { + $query->whereNull('pallet_number') + ->orWhere('pallet_number', ''); + }) + ->where('locator_number', $locatorNo) + ->orderByDesc('created_at') + ->get() + ->map(function ($record) use($operatorName) { + return [ + 'created_at' => session('latestPalletDateTime') ?? '', + 'created_by' => session('latestPalletCreatedBy') ?? '', + // 'pallet_number' => '', + 'serial_number' => $record->serial_number, + 'scanned_at' => now()->format('Y-m-d H:i:s'), + 'scanned_by' => $operatorName ?? '', + ]; + }) + ->toArray(); + + $this->records = array_merge($this->records, $newRecords); + + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => $locatorNo, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => count($this->records), + ]); + } + else if ($serialNo != null && $serialNo != '') + { + if (count($this->records) > 0) + { + $this->records = array_values(array_filter($this->records, function ($record) use ($serialNo) { + return $record['serial_number'] != $serialNo; + })); + } + + $newRecords = PalletValidation::query() + ->where('plant_id', $plantId) + ->where('serial_number', $serialNo) + ->get() + ->map(function ($record) use($operatorName) { + return [ + 'created_at' => session('latestPalletDateTime') ?? '', + 'created_by' => session('latestPalletCreatedBy') ?? '', + // 'pallet_number' => '', + 'serial_number' => $record->serial_number, + 'scanned_at' => now()->format('Y-m-d H:i:s'), + 'scanned_by' => $operatorName ?? '', + ]; + }) + ->toArray(); + + $this->records = array_merge($this->records, $newRecords); + + Notification::make() + ->title('Add: Locator Serial Number') + ->body( + "Scanned locator serial number '$serialNo' successfully added into 'PALLET DATA' table." + ) + ->success() + ->send(); + + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => count($this->records), + ]); + } + else if ($removeserial != null && $removeserial != '') + { + $this->records = array_values(array_filter($this->records, function ($record) use ($removeserial) { + return $record['serial_number'] != $removeserial; + })); + + Notification::make() + ->title('Remove: Locator Serial Number') + ->body( + "Scanned locator serial number '$removeserial' removed successfully from 'PALLET DATA' table." + ) + ->success() + ->send(); + + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => count($this->records), + ]); + } + } + + public function addToPalletValidation() + { + $plantId = $this->form->getState()['plant']; + $locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null; + $serial = trim($this->form->getState()['scan_serial_number']) ?? null; + $removeSno = trim($this->form->getState()['scan_remove_sno']) ?? null; + + $serialLocator = PalletValidation::query() + ->where('plant_id', $plantId) + ->where('locator_number', $locatorNo) + ->where(function($query) { + $query->whereNull('pallet_number') + ->orWhere('pallet_number', ''); + }) + ->get() + ->count(); + + $this->loadlocatorData($locatorNo, $serial, $removeSno, $plantId); + + $this->dispatch('close-modal', id: 'confirm-process-modal'); + + Notification::make() + ->title('Add: Locator Serial Numbers') + ->body("Scanned locator number '$locatorNo' has '$serialLocator' locator serial numbers!
Successfully added into 'PALLET DATA' table.") + ->success() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => count($this->records), + ]); + } + + public function skipAddToPalletValidation() + { + $plantId = $this->form->getState()['plant']; + Notification::make() + ->title('Scan the new locator number to proceed..!') + ->info() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => count($this->records), + ]); + } + + public function processSerialNo($serialNo) + { + $serialNo = trim($serialNo); + + $plantId = $this->form->getState()['plant']; + + $locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null; + + $removeSerial = trim($this->form->getState()['scan_remove_sno']) ?? null; + //$operatorName = Filament::auth()->user()->name; + $count = count($this->records); + + if ($locatorNo != null || $locatorNo != '') + { + Notification::make() + ->title('Press enter on "Scan Locator Number" field to proceed..!') + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => $locatorNo, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else if ($removeSerial != null || $removeSerial != '') + { + Notification::make() + ->title('Press enter on "Remove Serial Number" field to proceed..!') + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => $removeSerial, + 'sno_quantity' => $count, + ]); + return; + } + + if ($serialNo == '' || $serialNo == null) + { + Notification::make() + ->title("Serial number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else if (strlen($serialNo) < 13) + { + Notification::make() + ->title("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else if (!ctype_alnum($serialNo)) + { + Notification::make() + ->title("Serial number '$serialNo' must contain alpha-numeric values only.") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + + $serialLocator = PalletValidation::query() + ->where('plant_id', $plantId) + // ->where(function($query) { + // $query->whereNull('pallet_number') + // ->orWhere('pallet_number', ''); + // }) + ->where('serial_number', $serialNo) + ->first(); + + if ($serialLocator == '' || $serialLocator == null) + { + Notification::make() + ->title('UNKNOWN SERIAL NUMBER') + ->body("Scanned serial number: '$serialNo' doesn't exist in database!
Scan the valid exist locator-serial number to proceed...") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => null, + ]); + return; + } + elseif ($serialLocator->pallet_number != '' && $serialLocator->pallet_number != null) + { + Notification::make() + ->title('INVALID SERIAL NUMBER') + ->body("Scanned serial number: '$serialNo' already exist in pallet number '$serialLocator->pallet_number'!
Scan the valid locator-serial number to proceed...") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => null, + ]); + return; + } + + $this->loadlocatorData('', $serialNo, '', $plantId); + } + + public function generatePallet() + { + $plantId = $this->form->getState()['plant']; + $locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null; + $serialNo = trim($this->form->getState()['scan_serial_number']) ?? null; + $removeSerial = trim($this->form->getState()['scan_remove_sno']) ?? null; + // $this->Checking = session('latestPalletSerials'); + $operatorName = Filament::auth()->user()->name; + + $plantId = trim($plantId) ?? null; + + $year = now()->format('y'); + $month = now()->format('m'); + $prefix = "EP-{$year}{$month}"; + + $lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%") + ->where('plant_id', $plantId) + ->orderByDesc('pallet_number') + ->first(); + + $newNumber = $lastPallet + ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) + : '001'; + + $newPalletNumber = "{$prefix}{$newNumber}"; + + session(['latestPalletNumber' => $newPalletNumber]); + $this->latestPalletNumber = session('latestPalletNumber'); + + $url = route('download-qr-pdf', ['palletNo' => $newPalletNumber]); + $this->js(<<records) <= 0) + { + Notification::make() + ->title('Locator Serials Not Found') + ->body("Add some locator serial numbers to proceed generate pallet..!") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => $locatorNo, + 'scan_serial_number' => $serialNo, + 'scan_remove_sno' => $removeSerial, + 'sno_quantity' => 0, + ]); + return; + } + + // $affected = PalletValidation::where('locator_number', $locatorNo) + // ->where('plant_id', $plantId) + // ->whereIn('serial_number', $this->Checking) + // ->update([ + // 'pallet_number' => $newPalletNumber, + // 'locator_number' => null, + // 'updated_at' => now()->format('Y-m-d H:i:s'), + // 'updated_by' => $operatorName, + // ]); + + $newSerialNumbers = array_column($this->records, 'serial_number'); + + PalletValidation::where('plant_id', $plantId)->whereIn('serial_number', $newSerialNumbers)->forceDelete(); + + $rowsAdded = 0; + + foreach ($this->records as &$record) { + $rowsAdded++; + $record['plant_id'] = $plantId; + // $record['pallet_number'] = $newPalletNumber; + // $record['pallet_status'] = 'Completed'; + $record['updated_by'] = $operatorName; + + PalletValidation::updateOrCreate( + [ + 'plant_id' => $plantId, + 'serial_number' => $record['serial_number'], + ], + [ + 'pallet_number' => $newPalletNumber, + 'pallet_status' => 'Completed', + 'locator_number' => null, + 'locator_quantity' => 0, + 'created_at' => $record['created_at'], + 'created_by' => $record['created_by'], + 'scanned_at' => $record['scanned_at'], + 'scanned_by' => $record['scanned_by'], + 'updated_by' => $operatorName + ] + ); + } + unset($record); + + // PalletValidation::insert($this->records); + + if ($rowsAdded > 0) + { + $this->records = []; + Notification::make() + ->title('Success: Pallet Generated') + ->body("Pallet number '$newPalletNumber' completed the master packing successfully!") + ->success() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => $locatorNo, + 'scan_serial_number' => $serialNo, + 'scan_remove_sno' => $removeSerial, + 'sno_quantity' => 0, + ]); + return; + } + else + { + $this->records = []; + Notification::make() + ->title('Failed: Pallet Generated') + ->body("No locator serial number records found to generate pallet..!") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => $locatorNo, + 'scan_serial_number' => $serialNo, + 'scan_remove_sno' => $removeSerial, + 'sno_quantity' => 0, + ]); + return; + } + + // $locator = Locator::where('locator_number', $locatorNo) + // ->where('plant_id', $plantId) + // ->first(); + + // if ($locator && $locator->locator_quantity > 0) { + // $locator->update([ + // 'locator_quantity' => $locator->locator_quantity - 1, + // 'updated_at' => now()->format('Y-m-d H:i:s'), + // 'updated_by' => $operatorName + // ]); + // } + + // Notification::make() + // ->title('Pallet Generated') + // ->body("Pallet number {$this->latestPalletNumber} assigned to all serials for locator {$locatorNo}") + // ->success() + // ->send(); + // $this->dispatch('loadData', $this->records, $plantId); + // $this->form->fill([ + // 'plant_id' => $plantId, + // 'plant' => $plantId, + // 'scan_locator_number' => null, + // 'scan_serial_number' => null, + // 'scan_remove_sno' => null, + // 'sno_quantity' => null, + // ]); + } + + public function processremoveSNo($removeSno) + { + $plantId = $this->form->getState()['plant']; + + $locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null; + + $removeSno = trim($removeSno); + + $serialNo = trim($this->form->getState()['scan_serial_number']) ?? null; + $count = count($this->records); + + if ($locatorNo != null || $locatorNo != '') + { + Notification::make() + ->title('Press enter on "Scan Locator Number" field to proceed..!') + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => $locatorNo, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else if ($serialNo != null || $serialNo != '') + { + Notification::make() + ->title('Press enter on "Scan Serial Number" field to proceed..!') + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => $serialNo, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + + + if ($removeSno == '' || $removeSno == null) + { + Notification::make() + ->title("Serial number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else if (strlen($removeSno) < 13) + { + Notification::make() + ->title("Serial number '$removeSno' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + else if (!ctype_alnum($removeSno)) + { + Notification::make() + ->title("Serial number '$removeSno' must contain alpha-numeric values only.") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + + // $serialLocator = PalletValidation::query() + // ->where('plant_id', $plantId) + // ->where(function($query) { + // $query->whereNull('pallet_number') + // ->orWhere('pallet_number', ''); + // }) + // ->first(); + + $serialNumbers = array_column($this->records, 'serial_number'); + + $exists = in_array($removeSno, $serialNumbers); + + if (!$exists) + { + Notification::make() + ->title('UNKNOWN SERIAL NUMBER') + ->body("Scanned serial number: '$removeSno' doesn't exist in 'PALLET DATA' table!
Scan the valid exist locator-serial number to proceed...") + ->danger() + ->send(); + $this->dispatch('loadData', $this->records, $plantId); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'scan_locator_number' => null, + 'scan_serial_number' => null, + 'scan_remove_sno' => null, + 'sno_quantity' => $count, + ]); + return; + } + + $this->loadlocatorData('', '', $removeSno, $plantId); + + } + + public static function canAccess(): bool + { + return Auth::check() && Auth::user()->can('create pallet from locator page'); + } + +} diff --git a/app/Livewire/PalletFromLocatorDataTable.php b/app/Livewire/PalletFromLocatorDataTable.php new file mode 100644 index 000000000..9a24a08b4 --- /dev/null +++ b/app/Livewire/PalletFromLocatorDataTable.php @@ -0,0 +1,88 @@ + 'loadlocatorData', + 'open-confirm-modal' => 'openConfirmModal', + ]; + + // public function generatePallet($plantId) + // { + // $year = now()->format('y'); + // $month = now()->format('m'); + // $prefix = "EP-{$year}{$month}"; + + // $lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%") + // ->where('plant_id', $plantId) + // ->orderByDesc('pallet_number') + // ->first(); + + // $newNumber = $lastPallet + // ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT) + // : '001'; + + // $newPalletNumber = "{$prefix}{$newNumber}"; + + + // session(['latestPalletNumber' => $newPalletNumber]); + + // $url = route('download-qr-pdf', ['palletNo' => $newPalletNumber]); + // $this->js(<<locatorNo = $locatorNo; + $this->plantId = $plantId; + $this->dispatch('open-modal', id: 'confirm-process-modal'); + } + + public function loadlocatorData($records,$plantId) + { + $this->plantId = $plantId; + $this->records = $records; + } + + public function render() + { + return view('livewire.pallet-from-locator-data-table'); + } + + + + // public function render() + // { + // return view('livewire.pallet-from-locator-data-table'); + // } +} diff --git a/resources/views/filament/pages/pallet-from-locator.blade.php b/resources/views/filament/pages/pallet-from-locator.blade.php new file mode 100644 index 000000000..25ba902d2 --- /dev/null +++ b/resources/views/filament/pages/pallet-from-locator.blade.php @@ -0,0 +1,51 @@ + +
+ {{-- Render the Select form fields --}} +
+ {{ $this->form }} +
+
+ +
+ +
+ +
+ + {{--
+

Locator No: {{ $locatorNo }}

+
--}} + + + + ADD: CONFIRMATION + +

Scanned locator number has locator serial numbers!
Do you want to store it into 'Pallet Data' table?

+ + + Yes + + + No + + +
+ @push('scripts') + + @endpush +
+
diff --git a/resources/views/livewire/pallet-from-locator-data-table.blade.php b/resources/views/livewire/pallet-from-locator-data-table.blade.php new file mode 100644 index 000000000..8f8c0bff0 --- /dev/null +++ b/resources/views/livewire/pallet-from-locator-data-table.blade.php @@ -0,0 +1,42 @@ +
+

+ PALLET DATA TABLE: +

+
+ + + + + + + + + + + + + + @forelse ($records as $index => $record) + + + + + + + + + + @empty + + + + @endforelse + +
NoCreated DatetimeCreated ByPallet NumberSerial NumberScanned DatetimeScanned By
{{ $index + 1 }}{{ $record['created_at'] ?? '' }}{{ $record['created_by'] ?? '' }}{{ $record['pallet_number'] ?? '' }}{{ $record['serial_number'] ?? '' }}{{ $record['scanned_at'] ?? '' }}{{ $record['scanned_by'] ?? '' }}
+ No pallet records found. +
+
+
+ + +