diff --git a/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php
index 18203d4..3f68f50 100644
--- a/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php
+++ b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php
@@ -194,7 +194,48 @@ class ReworkLocatorInvoiceValidationResource extends Resource
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
$plantId = $get('plant');
- $palletNumber = $get('scan_pallet_no');
+ $palletNumber = trim($get('scan_pallet_no'));
+ $serialNo = trim($get('scan_serial_no'));
+ $updatePalletStatus = $get('update_pallet') ?? null;
+
+ if ($updatePalletStatus == 0)
+ {
+ return;
+ }
+
+ if (strlen($palletNumber) < 10)
+ {
+ Notification::make()
+ ->title("Invalid: Pallet Number")
+ ->body("Pallet number '$palletNumber' must be at least 10 digits.")
+ ->danger()
+ ->duration(5000)
+ ->send();
+
+ $livewire->dispatch('loadData', '', '', $plantId, 'pallet');
+ $set('scan_serial_no', null);
+ $set('scan_pallet_no', null);
+ $set('update_pallet', null);
+ return;
+ }
+
+ $PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->first();
+
+ if (!$PalletSerialNumbers)
+ {
+ Notification::make()
+ ->title('Pallet Not Found')
+ ->body("Pallet number '$palletNumber' doesn't exist in pallet table!
Scan the valid exist 'Pallet Number' to proceed..!")
+ ->danger()
+ ->duration(5000)
+ ->send();
+
+ $livewire->dispatch('loadData', '', '', $plantId, 'pallet');
+ $set('scan_serial_no', null);
+ $set('scan_pallet_no', null);
+ $set('update_pallet', null);
+ return;
+ }
$rows = PalletValidation::where('pallet_number', $palletNumber)
->where('plant_id', $plantId)
@@ -209,18 +250,96 @@ class ReworkLocatorInvoiceValidationResource extends Resource
}
}
+ if(count($rows) <= 0) {
+ $isScanningComplete = false;
+ }
+
if (!$isScanningComplete)
{
Notification::make()
- ->title("Scanned pallet number '$palletNumber' does not completed the master packing!
Please, scan the valid completed pallet number to proceed...")
+ ->title('Pallet Not Completed')
+ ->body("Scanned pallet number '$palletNumber' doesn't completed the master packing!
Please, scan the valid completed pallet number to proceed..!")
->danger()
->duration(5000)
->send();
+ $livewire->dispatch('loadData', '', '', $plantId, 'pallet');
+ $set('scan_serial_no', null);
$set('scan_pallet_no', null);
$set('update_pallet', null);
return;
}
+ else
+ {
+ $locatExist = ($PalletSerialNumbers->locator_number != null && $PalletSerialNumbers->locator_number != '') ? $PalletSerialNumbers->locator_number : '';
+ if ($locatExist)
+ {
+ Notification::make()
+ ->title('Locator Pallet Found')
+ ->body("Scanned pallet number '$palletNumber' exist in locator number '$locatExist'.
Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!")
+ ->danger()
+ ->duration(5000)
+ ->send();
+
+ $livewire->dispatch('loadData', '', '', $plantId, 'pallet');
+ $set('scan_serial_no', null);
+ $set('scan_pallet_no', null);
+ $set('update_pallet', null);
+ return;
+ }
+ else
+ {
+ if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20))
+ {
+ Notification::make()
+ ->title("Invalid: Serial Number")
+ ->body("Serial number '$serialNo' should contain minimum 9 digits and maximum 20 digits.")
+ ->danger()
+ ->duration(5000)
+ ->send();
+
+ $livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
+ $set('scan_serial_no', null);
+ $set('update_pallet', null);
+ return;
+ }
+ else if (strlen($serialNo) > 0 && !ctype_alnum($serialNo))
+ {
+ Notification::make()
+ ->title("Invalid: Serial Number")
+ ->body("Serial number '$serialNo' must contain alpha-numeric values only.")
+ ->danger()
+ ->duration(5000)
+ ->send();
+
+ $livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
+ $set('scan_serial_no', null);
+ $set('update_pallet', null);
+ return;
+ }
+
+ if ($updatePalletStatus == 1)
+ {
+ foreach ($rows as $row)
+ {
+ $row->forceDelete(); // Delete the row from the original table
+ }
+
+ Notification::make()
+ ->title('Completed: Rework Pallet')
+ ->body("Scanned pallet number '$palletNumber' successfully removed from pallet table.
Please, scan the next pallet number to re-master packing..!")
+ ->success()
+ ->duration(800)
+ ->send();
+
+ $livewire->dispatch('loadData', '', '', $plantId, 'pallet');
+ $set('scan_serial_no', null);
+ $set('scan_pallet_no', null);
+ $set('update_pallet', null);
+ return;
+ }
+ }
+ }
}),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),