Enhance pallet validation logic in ReworkLocatorInvoiceValidationResource form to include detailed notifications for invalid pallet and serial numbers, and handle pallet status updates more effectively.
This commit is contained in:
@@ -194,7 +194,48 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
|||||||
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
|
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
|
||||||
$plantId = $get('plant');
|
$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!<br><br>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)
|
$rows = PalletValidation::where('pallet_number', $palletNumber)
|
||||||
->where('plant_id', $plantId)
|
->where('plant_id', $plantId)
|
||||||
@@ -209,18 +250,96 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(count($rows) <= 0) {
|
||||||
|
$isScanningComplete = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$isScanningComplete)
|
if (!$isScanningComplete)
|
||||||
{
|
{
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title("Scanned pallet number '$palletNumber' does not completed the master packing!<br>Please, scan the valid completed pallet number to proceed...")
|
->title('Pallet Not Completed')
|
||||||
|
->body("Scanned pallet number '$palletNumber' doesn't completed the master packing!<br><br>Please, scan the valid completed pallet number to proceed..!")
|
||||||
->danger()
|
->danger()
|
||||||
->duration(5000)
|
->duration(5000)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
|
$livewire->dispatch('loadData', '', '', $plantId, 'pallet');
|
||||||
|
$set('scan_serial_no', null);
|
||||||
$set('scan_pallet_no', null);
|
$set('scan_pallet_no', null);
|
||||||
$set('update_pallet', null);
|
$set('update_pallet', null);
|
||||||
return;
|
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'.<br><br>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.<br><br>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')
|
Forms\Components\Hidden::make('created_by')
|
||||||
->default(Filament::auth()->user()?->name),
|
->default(Filament::auth()->user()?->name),
|
||||||
|
|||||||
Reference in New Issue
Block a user