diff --git a/app/Filament/Pages/UploadSerialLocator.php b/app/Filament/Pages/UploadSerialLocator.php
new file mode 100644
index 000000000..02752133c
--- /dev/null
+++ b/app/Filament/Pages/UploadSerialLocator.php
@@ -0,0 +1,1757 @@
+ null,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ];
+
+ public function form(Form $form): Form
+ {
+ return $form
+ ->statePath('filters')
+ ->schema([
+ Section::make('') // You can give your section a title or leave it blank
+ ->schema([
+ Select::make('plant_id')
+ ->options(Plant::pluck('name', 'id'))
+ ->label('Plant')
+ ->reactive()
+ ->required()
+ ->disabled(fn (Get $get) => $get('scan_serial_number') || $get('scan_locator')) //!empty($get('scan_serial_number'))
+ ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ $set('scan_serial_number', null);
+ $set('scan_locator', null);
+ $set('upload_serial_locator', null);
+ })
+ ->columnSpan(1),
+ TextInput::make('scan_serial_number')
+ ->label('Scan Serial Number')
+ ->reactive()
+ ->readOnly(fn (callable $get) => !$get('plant_id'))
+ ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ $plantId = $get('plant_id');
+ if (!$plantId) {
+ $set('scan_serial_number', null);
+ $set('scan_locator', null);
+ }
+ $set('upload_serial_locator', null);
+ })
+ ->columnSpan(1),
+ TextInput::make('scan_locator')
+ ->label('Scan Locator Number')
+ ->reactive()
+ ->readOnly(fn (callable $get) => !$get('plant_id'))
+ ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ $plantId = $get('plant_id');
+ if (!$plantId) {
+ $set('scan_serial_number', null);
+ $set('scan_locator', null);
+ }
+ $set('upload_serial_locator', null);
+ })
+ ->columnSpan(1),
+ FileUpload::make('upload_serial_locator')
+ ->label('Choose Serial-Locator Master file')
+ ->preserveFilenames()
+ ->storeFiles(false)
+ ->reactive()
+ ->disabled(fn (Get $get) => $get('scan_serial_number') || $get('scan_locator'))//!$get('plant_id') ||
+ ->afterStateUpdated(function ($state, callable $set, callable $get) {
+ $plantId = $get('plant_id');
+ if (!$plantId) {
+ $set('scan_serial_number', null);
+ $set('scan_locator', null);
+ $set('upload_serial_locator', null);
+ }
+ $set('scan_serial_number', null);
+ $set('scan_locator', null);
+ })
+ ->directory('uploads/temp')
+ ->disk('local')
+ ->columnSpan('full')
+ ])
+ ->columns(3)
+ ]);
+ }
+
+ public function masterFileUpload()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+
+ $userName = Filament::auth()->user()->name;
+
+ if($plantId == '' || $plantId == null)
+ {
+ Notification::make()
+ ->title('Please select a plant first.')
+ ->danger()
+ ->send();
+
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => null,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $fileArray = $this->filters['upload_serial_locator'];
+
+ $file = is_array($fileArray) ? reset($fileArray) : $fileArray; // Get the first file
+
+ if (!$file) {
+ Notification::make()
+ ->title('Please upload a file!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $originalName = $file->getClientOriginalName();
+
+ $extension = $file->getClientOriginalExtension();
+
+ if (!in_array(strtolower($extension), ['xlsx', 'xls', 'csv']))
+ {
+ Notification::make()
+ ->title('Choose a proper Excel file')
+ ->danger()
+ ->body('The file must be an Excel file (xlsx, xls, csv).')
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $path = $file->storeAs('uploads/temp', $originalName, 'local');
+
+ $fullPath = Storage::disk('local')->path($path);
+
+ if (!file_exists($fullPath)) {
+ Notification::make()
+ ->title('File not found after upload!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $data = Excel::toArray([], $fullPath);
+
+ $rows = $data[0];
+
+ $insertedCount = 0;
+
+ $plantId = $this->filters['plant_id'];
+
+ $existingSerials = [];
+
+ $excelSerials = [];
+ $excelLocators = [];
+
+ $invalidSerial = [];
+ $invalidLocator = [];
+
+ foreach (array_slice($rows, 1) as $row) {
+ $serialNumber = $row[0] ?? null;
+ $locator = $row[1] ?? null;
+
+ if ($serialNumber)
+ {
+ $excelSerials[] = $serialNumber;
+ if (strlen($serialNumber) < 13) {
+ $invalidSerial[] = $serialNumber;
+ } elseif (!ctype_alnum($serialNumber)) {
+ $invalidSerial[] = $serialNumber;
+ }
+ }
+
+ if ($locator) {
+ $excelLocators[] = $locator;
+ if (strlen($locator) > 7) {
+ $invalidLocator[] = $locator;
+ }
+ }
+ }
+
+ $uniqueInvalidSerial = array_unique($invalidSerial);
+ $uniqueInvalidLocator = array_unique($invalidLocator);
+
+ if (count($uniqueInvalidSerial) > 0) {
+ Notification::make()
+ ->title('Invalid Serial Numbers Found')
+ ->body('The following serial numbers are invalid, length should contain minimum of 13 digits alpha numeric values: Some locator numbers does not have space? Some Serial numbers are already exists in pallet table?
' . implode(', ', $uniqueInvalidSerial))
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (count($uniqueInvalidLocator) > 0) {
+ Notification::make()
+ ->title('Invalid Locator Numbers Found')
+ ->body('The following locator numbers are invalid, length should contain minimum of 13 digits alpha numeric values:
' . implode(', ', $uniqueInvalidLocator))
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ // foreach (array_slice($rows, 1) as $row)
+ // {
+ // $serialNumber = $row[0] ?? null;
+ // $locator = $row[1] ?? null;
+ // if ($serialNumber) {
+ // $excelSerials[] = $serialNumber;
+ // }
+ // if ($locator) {
+ // $excelLocators[] = $locator;
+ // }
+ // }
+
+ // dd($excelSerials);
+
+ if (count($excelSerials) !== count(array_unique($excelSerials))) {
+ $duplicates = array_diff_assoc($excelSerials, array_unique($excelSerials));
+ $duplicates = array_values(array_unique($duplicates));
+ Notification::make()
+ ->title('Duplicate Serial Numbers in Excel')
+ ->body('The following serial numbers are duplicated in the file:
' . implode(', ', $duplicates))
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+
+
+ $excelLocators = array_unique($excelLocators);
+ $locatorsWithQuantityTwo = Locator::whereIn('locator_number', $excelLocators)
+ ->where('plant_id',$plantId)
+ ->where('locator_quantity', '>=', 2)
+ ->pluck('locator_number')
+ ->toArray();
+
+ if (count($locatorsWithQuantityTwo) > 0) {
+ Notification::make()
+ ->title('Locators with Insufficient Space')
+ ->body('The following locators does not have space:
' . implode(', ', $locatorsWithQuantityTwo))
+ ->warning()
+ ->send();
+ $this->dispatch('open-confirm-modal', locatorNo: $locator, plantId: $plantId);
+ return;
+ }
+
+ $excelSerials = array_unique($excelSerials);
+
+ $palletSerials = PalletValidation::whereIn('serial_number', $excelSerials)->where('plant_id',$plantId)->pluck('serial_number')->toArray();
+ $invoiceSerials = LocatorInvoiceValidation::whereIn('serial_number', $excelSerials)->where('plant_id',$plantId)->where('scanned_status','!=','')->where('scanned_status','!=',null)->pluck('serial_number')->toArray();
+
+ $existingSerials = array_unique(array_merge($palletSerials, $invoiceSerials));
+
+ if (count($existingSerials) > 0)
+ {
+ Notification::make()
+ ->title('Duplicate Serial Numbers Found')
+ ->body('The following serial numbers already exist and cannot be imported:
' . implode(', ', $existingSerials))
+ ->danger()
+ ->send();
+ $this->dispatch('open-confirm-serial', locatorNo: $locator, plantId: $plantId);
+ return;
+ }
+
+ $insertedCount = 0;
+
+ foreach (array_slice($rows, 1) as $row)
+ {
+ $serialNumber = $row[0] ?? null;
+ $locator_num = $row[1] ?? null;
+
+ $locatorQuantity = Locator::where('plant_id',$plantId)->where('locator_number', $locator_num)->first();
+
+ if (empty($row[0]) && empty($row[1])) {
+ continue;
+ }
+
+ if (!in_array($serialNumber, $existingSerials) && $serialNumber && $locator_num)
+ {
+ PalletValidation::create([
+ 'plant_id' => $plantId,
+ 'pallet_number' => null,
+ 'serial_number' => $serialNumber,
+ 'locator_number' => $locator_num,
+ 'locator_quantity' => $locatorQuantity->locator_quantity,
+ 'created_by' => $userName,
+ 'updated_by' => $userName,
+ 'scanned_by' => $userName,
+ 'scanned_at' => now(),
+ ]);
+ $insertedCount++;
+ }
+ }
+
+ Storage::delete($fullPath);
+
+ if ($insertedCount > 0) {
+ Notification::make()
+ ->title('Serial Locators imported successfully!')
+ ->body("{$insertedCount} locator serial number(s) have been imported.")
+ ->success()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title('Serial Locators imported Failed!')
+ ->body('No new serial number(s) found in the uploaded excel file..!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+
+ public function skipLocatorsQuestion()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+
+ $userName = Filament::auth()->user()->name;
+
+ if($plantId == '' || $plantId == null)
+ {
+ Notification::make()
+ ->title('Please select a plant first.')
+ ->danger()
+ ->send();
+
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => null,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $fileArray = $this->filters['upload_serial_locator'];
+
+ $file = is_array($fileArray) ? reset($fileArray) : $fileArray;
+
+ if (!$file) {
+ Notification::make()
+ ->title('Please upload a file!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $originalName = $file->getClientOriginalName();
+
+ $extension = $file->getClientOriginalExtension();
+
+ if (!in_array(strtolower($extension), ['xlsx', 'xls', 'csv']))
+ {
+ Notification::make()
+ ->title('Choose a proper Excel file')
+ ->danger()
+ ->body('The file must be an Excel file (xlsx, xls, csv).')
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $path = $file->storeAs('uploads/temp', $originalName, 'local');
+
+ $fullPath = Storage::disk('local')->path($path);
+
+ if (!file_exists($fullPath)) {
+ Notification::make()
+ ->title('File not found after upload!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $data = Excel::toArray([], $fullPath);
+
+ $rows = $data[0];
+
+ $plantId = $this->filters['plant_id'];
+
+ $existingSerials = [];
+
+ $excelSerials = [];
+ $excelLocators = [];
+
+ foreach (array_slice($rows, 1) as $row)
+ {
+ $serialNumber = $row[0] ?? null;
+ $locator = $row[1] ?? null;
+ if ($serialNumber) {
+ $excelSerials[] = $serialNumber;
+ }
+ if ($locator) {
+ $excelLocators[] = $locator;
+ }
+ }
+
+ $excelSerials = array_unique($excelSerials);
+
+ $palletSerials = PalletValidation::whereIn('serial_number', $excelSerials)->where('plant_id',$plantId)->pluck('serial_number')->toArray();
+ $invoiceSerials = LocatorInvoiceValidation::whereIn('serial_number', $excelSerials)->where('scanned_status','!=','')->where('scanned_status','!=',null)->where('plant_id',$plantId)->pluck('serial_number')->toArray();
+ $existingSerials = array_unique(array_merge($palletSerials, $invoiceSerials));
+
+
+ $excelLocators = array_unique($excelLocators);
+ $locatorsWithQuantityTwo = Locator::whereIn('locator_number', $excelLocators)
+ ->where('plant_id',$plantId)
+ ->where('locator_quantity', '>=', 2)
+ ->pluck('locator_number')
+ ->toArray();
+
+
+ if (count($existingSerials) > 0)
+ {
+ Notification::make()
+ ->title('Duplicate Serial Numbers Found')
+ ->body('The following serial numbers already exist and cannot be imported: ' . implode(', ', $existingSerials))
+ ->danger()
+ ->seconds(10)
+ ->send();
+ $this->dispatch('open-confirm-serial', locatorNo: $locator, plantId: $plantId);
+ return;
+ }
+
+ $insertedCount = 0;
+
+ foreach (array_slice($rows, 1) as $row) {
+ $serialNumber = $row[0] ?? null;
+ $locator_num = $row[1] ?? null;
+
+
+ $locatorQuantity = Locator::where('plant_id',$plantId)->where('locator_number', $locator_num)->first();
+
+ if (empty($row[0]) && empty($row[1])) {
+ continue;
+ }
+
+ if ($serialNumber && $locator_num && !in_array($locator_num, $locatorsWithQuantityTwo)) {
+ PalletValidation::create([
+ 'plant_id' => $plantId,
+ 'pallet_number' => null,
+ 'serial_number' => $serialNumber,
+ 'locator_number' => $locator_num,
+ 'locator_quantity' => $locatorQuantity->locator_quantity,
+ 'created_by' => $userName,
+ 'updated_by' => $userName,
+ 'scanned_by' => $userName,
+ 'scanned_at' => now(),
+ ]);
+ $insertedCount++;
+ }
+ }
+
+
+ Storage::delete($fullPath);
+
+ if ($insertedCount > 0) {
+ Notification::make()
+ ->title('Serial Locators imported successfully!')
+ ->body("{$insertedCount} locator serial number(s) have been imported.")
+ ->success()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title('Serial Locators imported Failed!')
+ ->body('No new serial number(s) found in the uploaded excel file..!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+
+ public function cancelLocatorsQuestion()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ }
+
+ public function skipSerialQuestion()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+
+ $userName = Filament::auth()->user()->name;
+
+ if($plantId == '' || $plantId == null)
+ {
+ Notification::make()
+ ->title('Please select a plant first.')
+ ->danger()
+ ->send();
+
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => null,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $fileArray = $this->filters['upload_serial_locator'];
+
+ $file = is_array($fileArray) ? reset($fileArray) : $fileArray; // Get the first file
+
+ if (!$file) {
+ Notification::make()
+ ->title('Please upload a file!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $originalName = $file->getClientOriginalName();
+
+ $extension = $file->getClientOriginalExtension();
+
+ if (!in_array(strtolower($extension), ['xlsx', 'xls', 'csv']))
+ {
+ Notification::make()
+ ->title('Choose a proper Excel file')
+ ->danger()
+ ->body('The file must be an Excel file (xlsx, xls, csv).')
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $path = $file->storeAs('uploads/temp', $originalName, 'local');
+
+ $fullPath = Storage::disk('local')->path($path);
+
+ if (!file_exists($fullPath)) {
+ Notification::make()
+ ->title('File not found after upload!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $data = Excel::toArray([], $fullPath);
+
+ $rows = $data[0];
+
+ $plantId = $this->filters['plant_id'];
+
+ $existingSerials = [];
+
+ $excelSerials = [];
+
+ foreach (array_slice($rows, 1) as $row)
+ {
+ $serialNumber = $row[0] ?? null;
+ $locator = $row[1] ?? null;
+ if ($serialNumber) {
+ $excelSerials[] = $serialNumber;
+ }
+ if ($locator) {
+ $excelLocators[] = $locator;
+ }
+ }
+
+ $excelSerials = array_unique($excelSerials);
+
+ $palletSerials = PalletValidation::whereIn('serial_number', $excelSerials)->where('plant_id',$plantId)->pluck('serial_number')->toArray();
+ $invoiceSerials = LocatorInvoiceValidation::whereIn('serial_number', $excelSerials)->where('scanned_status','!=','')->where('scanned_status','!=',null)->where('plant_id',$plantId)->pluck('serial_number')->toArray();
+ $existingSerials = array_unique(array_merge($palletSerials, $invoiceSerials));
+ $excelLocators = array_unique($excelLocators);
+ $locatorsWithQuantityTwo = Locator::whereIn('locator_number', $excelLocators)
+ ->where('plant_id',$plantId)
+ ->where('locator_quantity', '>=', 2)
+ ->pluck('locator_number')
+ ->toArray();
+
+
+ $skipSerials = array_unique(array_merge(
+ $existingSerials
+ ));
+
+ $insertedCount = 0;
+ foreach (array_slice($rows, 1) as $row) {
+ $serialNumber = $row[0] ?? null;
+ $locator_num = $row[1] ?? null;
+
+ $locatorQuantity = Locator::where('plant_id',$plantId)->where('locator_number', $locator_num)->first();
+
+ if (empty($row[0]) && empty($row[1])) {
+ continue;
+ }
+
+ if ($serialNumber && $locator_num && !in_array($serialNumber, $existingSerials) && !in_array($locator_num, $locatorsWithQuantityTwo)) {
+ PalletValidation::create([
+ 'plant_id' => $plantId,
+ 'pallet_number' => null,
+ 'serial_number' => $serialNumber,
+ 'locator_number' => $locator_num,
+ 'locator_quantity' => $locatorQuantity->locator_quantity,
+ 'created_by' => $userName,
+ 'updated_by' => $userName,
+ 'scanned_by' => $userName,
+ 'scanned_at' => now(),
+ ]);
+ $insertedCount++;
+ }
+ }
+
+ Storage::delete($fullPath);
+
+ if ($insertedCount > 0) {
+ Notification::make()
+ ->title('Serial Locators imported successfully!')
+ ->body("{$insertedCount} locator serial number(s) have been imported.")
+ ->success()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ } else {
+ Notification::make()
+ ->title('Serial Locators imported Failed!')
+ ->body('No new serial number(s) found in the uploaded excel file..!')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+
+ public function cancelSerialQuestion()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ }
+
+ public function addLocator()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+ $scanLocator = $this->filters['scan_locator'] ?? null;
+ $scanSno = $this->filters['scan_serial_number'] ?? null;
+
+ if ($plantId == '' || $plantId == null)
+ {
+ Notification::make()
+ ->title('Please select a plant first.')
+ ->danger()
+ ->send();
+
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => null,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if(!$scanSno && !$scanLocator)
+ {
+ Notification::make()
+ ->title('Please enter serial number and locator number to add data.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if(!$scanSno)
+ {
+ Notification::make()
+ ->title('Please enter serial number to add data.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (strlen($scanSno) < 13)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' must be at least 13 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ if (!ctype_alnum($scanSno))
+ {
+ Notification::make()
+ ->title('Serial number must contain alpha-numeric values only.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if(!$scanLocator)
+ {
+ Notification::make()
+ ->title('Please enter locator number to add data.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (strlen($scanLocator) < 7) {
+ Notification::make()
+ ->title("Locator number '$scanLocator' must be at least 7 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $locator = Locator::where('locator_number', $scanLocator)
+ ->where('plant_id', $plantId)
+ ->first();
+
+ if (!$locator)
+ {
+ Notification::make()
+ ->title("Locator number '$scanLocator' does not exist in the master.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if ($locator->locator_quantity >= 2)
+ {
+ Notification::make()
+ ->title("No space available for locator number '{$scanLocator}'.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if($scanSno && $scanLocator)
+ {
+ $palletRecord = PalletValidation::where('serial_number', $scanSno)
+ ->where('plant_id', $plantId)
+ ->first();
+
+ if ($palletRecord)
+ {
+ if ($palletRecord->pallet_number == null || $palletRecord->pallet_number == '')
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in locator number '$palletRecord->locator_number'.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else if ($palletRecord->locator_number == null || $palletRecord->locator_number == '')
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in pallet number '$palletRecord->pallet_number'.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in pallet number '$palletRecord->pallet_number' with locator number '$palletRecord->locator_number'.")
+ ->warning()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+ else
+ {
+ $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId)
+ ->where('serial_number', $scanSno)
+ ->where('scanned_status', '=', 'Scanned')
+ ->first();
+
+ $invoiceNo = $invoicesnoexists?->invoice_number;
+
+ if ($invoicesnoexists)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in invoice number '$invoiceNo' and completed the scanning process.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+ }
+ $locatorQuantity = Locator::where('plant_id',$plantId)->where('locator_number', $scanLocator)->first();
+
+ $userName = Filament::auth()->user()->name;
+
+ $created = PalletValidation::create([
+ 'plant_id' => $plantId,
+ 'locator_number' => $scanLocator,
+ 'serial_number' => $scanSno,
+ 'locator_quantity' => $locatorQuantity->locator_quantity,
+ 'created_at' => now(),
+ 'created_by' => $userName,
+ 'scanned_at' => now(),
+ 'scanned_by' => $userName,
+ 'updated_at' => now(),
+ 'updated_by' => $userName,
+ ]);
+
+ if ($created)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' added into locator number '$scanLocator' successfully!")
+ ->success()
+ ->send();
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ }
+ else
+ {
+ Notification::make()
+ ->title("Failed to add serial number '$scanSno' into locator number '$scanLocator'!")
+ ->danger()
+ ->send();
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ }
+
+ // Refresh the table to show the new record
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ }
+
+
+
+ public function viewLocator()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+ $scanLocator = $this->filters['scan_locator'] ?? null;
+ $scanSno = $this->filters['scan_serial_number'] ?? null;
+
+ if ($plantId == '' || $plantId == null)
+ {
+ Notification::make()
+ ->title('Please select a plant first.')
+ ->danger()
+ ->send();
+
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => null,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if(!$scanSno && !$scanLocator)
+ {
+ Notification::make()
+ ->title('Please enter atleast a serial number or locator number to view data.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ if($scanSno && $scanLocator)
+ {
+ if (strlen($scanSno) < 13) {
+ Notification::make()
+ ->title("Serial number '$scanSno' must be at least 13 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (!ctype_alnum($scanSno))
+ {
+ Notification::make()
+ ->title('Serial number must contain alpha-numeric values only.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (strlen($scanLocator) < 7) {
+ Notification::make()
+ ->title("Locator number '$scanLocator' must be at least 7 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ return;
+ }
+
+ $locator = Locator::where('locator_number', $scanLocator)
+ ->where('plant_id', $plantId)
+ ->first();
+ if (!$locator)
+ {
+ Notification::make()
+ ->title("Locator number '$scanLocator' does not exist in the master.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId)
+ ->where('serial_number', $scanSno)
+ ->where('scanned_status', '=', 'Scanned')
+ ->first();
+
+ $invoiceNo = $invoicesnoexists?->invoice_number;
+
+ if ($invoicesnoexists)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' exists in invoice number '$invoiceNo' and completed the scanning process.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $serialNumberExists = PalletValidation::where('serial_number', $scanSno)
+ ->where('plant_id', $plantId)
+ ->where('locator_number', $scanLocator)
+ ->first();
+ if (!$serialNumberExists)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' and locator number '$scanLocator' does not exist in pallet table.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ if ($serialNumberExists->pallet_number != null && $serialNumberExists->pallet_number != '')
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in pallet number '$serialNumberExists->pallet_number' with locator number '$serialNumberExists->locator_number'.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' exists in locator number '$serialNumberExists->locator_number'.")
+ ->success()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+ }
+ else if($scanSno)
+ {
+ if (strlen($scanSno) < 13) {
+ Notification::make()
+ ->title("Serial number '$scanSno' must be at least 13 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (!ctype_alnum($scanSno))
+ {
+ Notification::make()
+ ->title('Serial number must contain alpha-numeric values only.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ // Check if the serial number exists in pallet or locator or invoice
+ $palletRecord = PalletValidation::where('serial_number', $scanSno)
+ ->where('plant_id', $plantId)
+ ->first();
+
+ if ($palletRecord)
+ {
+ if ($palletRecord->pallet_number == null || $palletRecord->pallet_number == '')
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' exists in locator number '$palletRecord->locator_number'.")
+ ->success()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else if ($palletRecord->locator_number == null || $palletRecord->locator_number == '')
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in pallet number '$palletRecord->pallet_number'.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in pallet number '$palletRecord->pallet_number' with locator number '$palletRecord->locator_number'.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+ else
+ {
+ $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId)
+ ->where('serial_number', $scanSno)
+ ->where('scanned_status', '=', 'Scanned')
+ ->first();
+
+ $invoiceNo = $invoicesnoexists?->invoice_number;
+
+ if ($invoicesnoexists)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' exists in invoice number '$invoiceNo' and completed the scanning process.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' does not exist in pallet table.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+ }
+ else if($scanLocator)
+ {
+ if (strlen($scanLocator) < 7) {
+ Notification::make()
+ ->title("Locator number '$scanLocator' must be at least 7 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $locator = Locator::where('locator_number', $scanLocator)
+ ->where('plant_id', $plantId)
+ ->first();
+ if (!$locator)
+ {
+ Notification::make()
+ ->title("Locator number '$scanLocator' does not exist in the master.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $serialNumbernExists = PalletValidation::where('locator_number', $scanLocator)
+ ->where('plant_id', $plantId)
+ ->first();
+ if (!$serialNumbernExists) {
+ Notification::make()
+ ->title("Locator number '$scanLocator' does not exist in pallet table.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title("Locator number '$scanLocator' exist in pallet table.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ }
+
+ public function deleteLocator()
+ {
+ $plantId = $this->filters['plant_id'] ?? null;
+ $scanLocator = $this->filters['scan_locator'] ?? null;
+ $scanSno = $this->filters['scan_serial_number'] ?? null;
+
+ if ($plantId == '' || $plantId == null)
+ {
+ Notification::make()
+ ->title('Please select a plant first.')
+ ->danger()
+ ->send();
+
+ $this->dispatch('loadData', '', '', 0);
+ $this->form->fill
+ ([
+ 'plant_id' => null,
+ 'scan_serial_number' => null,
+ 'scan_locator' => null,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if(!$scanSno && !$scanLocator)
+ {
+ Notification::make()
+ ->title('Please enter serial number and locator number to delete data.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if(!$scanSno)
+ {
+ Notification::make()
+ ->title('Please enter serial number to delete data.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (strlen($scanSno) < 13) {
+ Notification::make()
+ ->title("Serial number '$scanSno' must be at least 13 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (!ctype_alnum($scanSno))
+ {
+ Notification::make()
+ ->title('Serial number must contain alpha-numeric values only.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if(!$scanLocator)
+ {
+ Notification::make()
+ ->title('Please enter locator number to delete data.')
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ if (strlen($scanLocator) < 7) {
+ Notification::make()
+ ->title("Locator number '$scanLocator' must be at least 7 digits.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $locator = Locator::where('locator_number', $scanLocator)->where('plant_id',$plantId)->first();
+
+ if (!$locator)
+ {
+ Notification::make()
+ ->title("Locator number '$scanLocator' does not exist in the master.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $invoicesnoexists = LocatorInvoiceValidation::where('plant_id', $plantId)
+ ->where('serial_number', $scanSno)
+ ->where('scanned_status', '=','Scanned')
+ ->first();
+
+ $invoiceNo = $invoicesnoexists?->invoice_number;
+
+ if ($invoicesnoexists)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' exists in invoice number '$invoiceNo' and completed the scanning process.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $palletExists = PalletValidation::where('plant_id', $plantId)
+ ->where('serial_number', $scanSno)
+ ->where('locator_number', $scanLocator)
+ ->where('pallet_number', '!=','')
+ ->where('pallet_number', '!=',null)
+ ->first();
+
+ if($palletExists)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' already exists in pallet number '$palletExists->pallet_number'!
Please enter locator serial number to remove data.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+
+ $query = PalletValidation::where('plant_id', $plantId)->where('locator_number', $scanLocator)->where('serial_number', $scanSno);
+
+ $deleted = $query->forceDelete();
+
+ if ($deleted)
+ {
+ Notification::make()
+ ->title("Serial number '$scanSno' removed from locator number '$scanLocator' successfully.")
+ ->success()
+ ->send();
+ $this->dispatch('loadData', '', '', $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ else
+ {
+ Notification::make()
+ ->title("Failed to remove serial number '$scanSno' from locator number '$scanLocator'!")
+ //->title("Serial number '{$scanSno}' and Locator number '{$scanLocator}' does not exist in pallet table.")
+ ->danger()
+ ->send();
+ $this->dispatch('loadData', $scanLocator, $scanSno, $plantId);
+ $this->form->fill
+ ([
+ 'plant_id' => $plantId,
+ 'scan_serial_number' => $scanSno,
+ 'scan_locator' => $scanLocator,
+ 'upload_serial_locator' => null,
+ ]);
+ return;
+ }
+ }
+
+ public static function canAccess(): bool
+ {
+ return Auth::check() && Auth::user()->can('create serial locator page');
+ }
+}
diff --git a/app/Livewire/SerialLocatorDataTable.php b/app/Livewire/SerialLocatorDataTable.php
new file mode 100644
index 000000000..ed7d68b3b
--- /dev/null
+++ b/app/Livewire/SerialLocatorDataTable.php
@@ -0,0 +1,94 @@
+ 'loadLocatorData',
+ 'open-confirm-modal' => 'openConfirmModal',
+ 'open-confirm-serial' => 'openConfirmSerial',
+ ];
+
+ public function openConfirmModal($locatorNo, $plantId)
+ {
+ $this->locatorNo = $locatorNo;
+ $this->plantId = $plantId;
+
+ $this->dispatch('open-modal', id: 'confirm-process-modal');
+ }
+
+ public function openConfirmSerial($locatorNo, $plantId)
+ {
+ $this->locatorNo = $locatorNo;
+ $this->plantId = $plantId;
+
+ $this->dispatch('open-modal', id: 'confirm-process-serial');
+ }
+
+ public function loadLocatorData($scanLocator, $scanSno, $plantId)
+ {
+
+ $this->hasSearched = true;
+ $this->locatorNumber = $scanLocator;
+ $this->serialNumber = $scanSno;
+ $this->plantId = $plantId;
+ $this->locators = [];
+
+ // $query = PalletValidation::query()->where('plant_id', $plantId)
+ // ->whereNull('pallet_number')
+ // ->orWhere('pallet_number', '=','');
+ $query = PalletValidation::query()
+ ->where('plant_id', $plantId)
+ ->where(function($q) {
+ $q->whereNull('pallet_number')
+ ->orWhere('pallet_number', '=', '');
+ });
+
+
+
+ if ($scanLocator && $scanSno)
+ {
+ $query->where('locator_number', $scanLocator)
+ ->where('serial_number', $scanSno);
+ }
+ elseif ($scanLocator)
+ {
+ $query->where('locator_number', $scanLocator);
+ }
+ elseif ($scanSno)
+ {
+ $query->where('serial_number', $scanSno);
+ }
+ else
+ {
+ $this->locators = collect();
+ return;
+ }
+ $this->locators = $query->orderByDesc('created_at')->get();
+
+ //dd($this->locators);
+ }
+ public function render()
+ {
+ return view('livewire.serial-locator-data-table');
+ }
+}
diff --git a/resources/views/filament/pages/upload-serial-locator.blade.php b/resources/views/filament/pages/upload-serial-locator.blade.php
new file mode 100644
index 000000000..b21851340
--- /dev/null
+++ b/resources/views/filament/pages/upload-serial-locator.blade.php
@@ -0,0 +1,77 @@
+
Do you want to skip these locators?
Press Yes to continue!
Press No to Cancel!
Do you want to skip the duplicate serial numbers?
Press Yes to continue!
Press No to Cancel!
| No | +Created Datetime | +Created By | +Pallet Number | +Serial Number | +Locator Number | +Locator Quantity | +Updated Datetime | +Updated 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 records found. + | +||||||||
| + @if ($locatorNumber && $serialNumber) + Serial Number "{{ $serialNumber }}" and Locator Number "{{ $locatorNumber }}" not found. + @elseif ($locatorNumber) + Locator Number "{{ $locatorNumber }}" not found. + @elseif ($serialNumber) + Serial Number "{{ $serialNumber }}" not found. + @else + No records found. + @endif + | +||||||||