Merge pull request 'Added logic for remove serial number in panel pallet validation' (#1574) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 15s

Reviewed-on: #1574
This commit was merged in pull request #1574.
This commit is contained in:
2026-12-01 03:00:34 +00:00

View File

@@ -559,9 +559,9 @@ class CreatePanelPalletValidation extends CreateRecord
$palletNumber = trim($palletNumber) ?? null;
$serialNumber = trim($this->form->getState()['removeSno_number']) ?? null;
$serNo = trim($this->form->getState()['removeSno_number']) ?? null;
$serialNumber = trim($serialNumber) ?? null;
$serNo = trim($serNo) ?? null;
$user = Filament::auth()->user();
@@ -577,226 +577,233 @@ class CreatePanelPalletValidation extends CreateRecord
return;
}
$count = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count('pallet_number');
if (!$serialNumber)
{
if (!preg_match('/^(\d+)\/(\d+)\/(\d+)\/(\d+)$/', $serNo, $matches)) {
Notification::make()
->title('Serial number is required to remove.')
->title("Invalid Panel Box QR format: $serNo <br>Sample Format '1070107/398679/2611/000001'")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
else if (strlen($serialNumber) < 9 || strlen($serialNumber) > 20)
{
Notification::make()
->title('Serial number should contain minimum 9 digits and maximum 20 digits.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
else if (!ctype_alnum($serialNumber))
{
Notification::make()
->title('Serial number must contain alpha-numeric values only.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$invoiceExist = LocatorInvoiceValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->where('scanned_status', '=', 'Scanned')
->first();
if (preg_match('/^(\d+)\/(\d+)\/(\d+)\/(\d+)$/', $serNo, $matches)) {
$itemCode = $matches[2];
$serialNumber = $matches[1] . $matches[3] . $matches[4];
if ($invoiceExist)
{
Notification::make()
->title("Scanned serial number '{$serialNumber}' already completed the scanning process and exist in invoice number '{$invoiceExist->invoice_number}'.<br>Scan the valid exist serial number to remove!")
->danger()
->duration(5000)
->send();
$supplierNo = $matches[1];
$supplierSNo = implode('/', array_slice($matches, 3));
$panelBoxCode = $matches[2];
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$pBoxSNo = $matches[3] . '/' . $matches[4];
$serialexist = PanelPalletValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->first();
if (!$serialexist)
{
Notification::make()
->title('Serial number not exists in pallet table.')
->danger()
->duration(5000)
->send();
$itemExists = Item::where('code', $panelBoxCode)->first();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$plantName = Plant::find($plantId)?->name;
$palletExist = PanelPalletValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->where('pallet_number', '!=', '')
->where('pallet_number', '!=', null)
->first();
if ($palletExist && $palletExist->pallet_number != $palletNumber)
{
Notification::make()
->title("Scanned serial number exist in pallet number '$palletExist->pallet_number'.<br>Scan the valid exist serial number to remove!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$locatorExist = PanelPalletValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->where('locator_number', '!=', '')
->where('locator_number', '!=', null)
->first();
if ($locatorExist && $locatorExist->locator_number)
{
Notification::make()
->title("Scanned serial number exist in locator number '$locatorExist->locator_number'.<br>Scan the valid exist serial number to remove!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$deleted = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->where('serial_number', $serialNumber)
->forceDelete();
if ($deleted)
{
// Notification::make()
// ->title("Scanned serial number '$serialNumber' successfully removed from pallet table!<br>Scan the next exist serial number to remove...")
// ->success()
// ->duration(600)
// ->send();
$this->snoCount = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count();
$this->form->fill([
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'removeSno_number' => null,
'pending_pallet_list' => $this->pendingPallet,
'Sno_quantity' => $this->snoCount,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
$this->dispatch('loadData', $palletNumber, $plantId);
}
else
{
if (!$itemExists) {
Notification::make()
->title("Failed to remove scanned serial number '$serialNumber' from pallet table!")
->title("Item code '$panelBoxCode' does not exist.")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
$itemExistsAgaPlant = Item::where('plant_id', $plantId)->where('code', $panelBoxCode)->first();
if (!$itemExistsAgaPlant) {
Notification::make()
->title("Item code '$panelBoxCode' does not exist against plant $plantName.")
->danger()
->duration(5000)
->send();
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
$panelBoxExist = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->where('panel_box_code', $panelBoxCode)->first();
if(!$panelBoxExist){
Notification::make()
->title('Unknwon : Serial Number')
->body("Scanned Panel Box Serial Number '$serNo' was not found in Panel Box Validation.<br>Please complete the testing process for this Panel Box before proceeding.")
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
$panelBoxExistStatus = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->where('panel_box_code', $panelBoxCode)->first();
if(!$panelBoxExistStatus){
Notification::make()
->title('Serial Number')
->body("Scanned Panel Box Serial Number '$serNo' not found in Panel Box Validation")
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
$panelBoxExistPallet = PanelPalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->where('panel_box_code', $panelBoxCode)->first();
if(!$panelBoxExistPallet){
$panelBoxExistOtherPallet = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', '!=', $palletNumber)
->where('panel_box_supplier', $supplierNo)
->where('panel_box_serial_number', $pBoxSNo)
->where('panel_box_code', $panelBoxCode)
->first();
if ($panelBoxExistOtherPallet) {
$message = "Scanned Panel Box Serial Number '$serNo' already exists in another pallet: {$panelBoxExistOtherPallet->pallet_number}.";
} else {
$message = "Scanned Panel Box Serial Number '$serNo' not found in selected pallet number '$palletNumber'.";
}
Notification::make()
->title('Serial Number')
->body($message)
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
}
$deleted = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->where('panel_box_serial_number', $pBoxSNo)
->where('panel_box_supplier', $supplierNo)
->where('panel_box_code', $panelBoxCode)
->forceDelete();
if ($deleted)
{
$this->snoCount = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count();
$this->form->fill([
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'removeSno_number' => null,
'pending_pallet_list' => $this->pendingPallet,
'Sno_quantity' => $this->snoCount,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
$this->dispatch('loadData', $palletNumber, $plantId);
}
else
{
Notification::make()
->title("Failed to remove scanned serial number '$serialNumber' from pallet table!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
}
//$this->dispatch('removeSno', $serialNumber, $palletNumber, $plantId);
}