Added panel box invoice validation logic to allow only when item category is 'Panel Box'
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s

This commit is contained in:
dhanabalan
2026-12-02 19:17:08 +05:30
parent 236e38f5dd
commit bcf23f99a0

View File

@@ -9,10 +9,10 @@ use App\Models\AlertMailRule;
use App\Models\CoilPacking;
use App\Models\InvoiceValidation;
use App\Models\Item;
use App\Models\PanelBoxValidation;
use App\Models\Plant;
use App\Models\StickerMaster;
use App\Models\WireMasterPacking;
use App\Models\PanelBoxValidation;
use DB;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
@@ -1239,22 +1239,55 @@ class CreateInvoiceValidation extends CreateRecord
->toArray();
if (! empty($missPackCodes)) {
$missingCount = count($missPackCodes);
$hasPanelCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->material_type))
->pluck('item.category', 'item.code')
->toArray();
$hasPanelCodes = array_unique($hasPanelCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes doesn't have valid package type to proceed!" : "The following 'Item Code' doesn't have valid package type:<br>".implode(', ', $missPackCodes);
if (! empty($hasPanelCodes) && in_array('Panel Box', $hasPanelCodes, true)) {
$unknownCategories = array_diff($hasPanelCodes, ['Panel Box']);
$categoryCount = count($unknownCategories);
if ($categoryCount > 0) {
// $message = $categoryCount > 10 ? "'$categoryCount' unknown panel box categories found." : "Unknown panel box categories found:<br>'".implode("', '", $unknownCategories)."'";
$unknownItems = collect($unknownCategories)
->map(fn ($category, $code) => "{$code} : '{$category}'")
->implode('<br>');
$message = $categoryCount > 10 ? "'$categoryCount' unknown panel box categories found." : "Unknown panel box categories found:<br>{$unknownItems}";
Notification::make()
->title('Invalid: Item Codes')
->body($message)
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
Notification::make()
->title('Unknown : Categories')
->body($message)
->danger()
->seconds(3)
->send();
// if ($disk->exists($filePath)) {
// $disk->delete($filePath);
// }
return;
$this->dispatch('playWarnSound');
// if ($disk->exists($filePath)) {
// $disk->delete($filePath);
// }
return;
}
} else {
$missingCount = count($missPackCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes doesn't have valid package type to proceed!" : "The following 'Item Code' doesn't have valid package type:<br>".implode(', ', $missPackCodes);
Notification::make()
->title('Invalid: Item Codes')
->body($message)
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
// if ($disk->exists($filePath)) {
// $disk->delete($filePath);
// }
return;
}
}
$oldQuan = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('plant_id', $plantId)->count();
@@ -2254,23 +2287,55 @@ class CreateInvoiceValidation extends CreateRecord
->toArray();
if (! empty($missPackCodes)) {
$missingCount = count($missPackCodes);
$hasPanelCodes = $matchedItems
->filter(fn ($sticker) => empty($sticker->material_type))
->pluck('item.category', 'item.code')
->toArray();
$hasPanelCodes = array_unique($hasPanelCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes doesn't have valid package type to proceed!" : "The following 'Item Code' doesn't have valid package type:<br>".implode(', ', $missPackCodes);
if (! empty($hasPanelCodes) && in_array('Panel Box', $hasPanelCodes, true)) {
$unknownCategories = array_diff($hasPanelCodes, ['Panel Box']);
$categoryCount = count($unknownCategories);
if ($categoryCount > 0) {
// $message = $categoryCount > 10 ? "'$categoryCount' unknown panel box categories found." : "Unknown panel box categories found:<br>'".implode("', '", $unknownCategories)."'";
$unknownItems = collect($unknownCategories)
->map(fn ($category, $code) => "{$code} : '{$category}'")
->implode('<br>');
$message = $categoryCount > 10 ? "'$categoryCount' unknown panel box categories found." : "Unknown panel box categories found:<br>{$unknownItems}";
Notification::make()
->title('Invalid: Item Codes')
->body($message)
->danger()
->seconds(3)
->send();
Notification::make()
->title('Unknown : Categories')
->body($message)
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
$this->dispatch('playWarnSound');
// if ($disk->exists($filePath)) {
// $disk->delete($filePath);
// }
return;
// if ($disk->exists($filePath)) {
// $disk->delete($filePath);
// }
return;
}
} else {
$missingCount = count($missPackCodes);
$message = $missingCount > 10 ? "'$missingCount' item codes doesn't have valid package type to proceed!" : "The following 'Item Code' doesn't have valid package type:<br>".implode(', ', $missPackCodes);
Notification::make()
->title('Invalid: Item Codes')
->body($message)
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
// if ($disk->exists($filePath)) {
// $disk->delete($filePath);
// }
return;
}
}
$existingSerialNumbers = InvoiceValidation::whereIn('serial_number', $serialNumbers)->where('plant_id', $plantId)->pluck('serial_number')->toArray();
@@ -2554,7 +2619,6 @@ class CreateInvoiceValidation extends CreateRecord
$this->dispatch('refreshMaterialInvoiceData', invoiceNumber: $invoiceNumber, plantId: $plantId);
}
$pattern6 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]*)\|(?<batch_id>[^|]+)\|(?<batch_count>[^|]+)\|(?<batch_quantity>[^|]+)$/i';
$pattern0 = '/^(?<item_code>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>[^|]+)\|(?<batch_quantity>[0-9]+(?:\.[0-9]+)?)\s?kg$/i';
$pattern1 = '/^(?<item_code>[^|]+)\|(?<batch_number>[^|]+)\|(?<batch_id>[^|]+)\|(?<batch_count>[^|]+)\/(?<batch_quantity>.+)$/i';
@@ -2619,8 +2683,7 @@ class CreateInvoiceValidation extends CreateRecord
]);
return;
}
elseif (empty($matches['batch_count']) || ! $matches['batch_count']) {
} elseif (empty($matches['batch_count']) || ! $matches['batch_count']) {
Notification::make()
->danger()
->title('Invalid Material QR Format')
@@ -3570,8 +3633,7 @@ class CreateInvoiceValidation extends CreateRecord
]);
return;
}
else {
} else {
$itemCode = null;
$this->currentItemCode = '';
$batchNumber = null;
@@ -4036,13 +4098,13 @@ class CreateInvoiceValidation extends CreateRecord
if (preg_match('/^(\d+)\/(\d+)\/(\d+)\/(\d+)$/', $serNo, $matches)) {
$itemCode = $matches[2];
$serialNumber = $matches[1] . $matches[3] . $matches[4];
$serialNumber = $matches[1].$matches[3].$matches[4];
$supplierNo = $matches[1];
$supplierSNo = implode('/', array_slice($matches, 3));
$panelBoxCode = $matches[2];
$pBoxSNo = $matches[3] . '/' . $matches[4];
$pBoxSNo = $matches[3].'/'.$matches[4];
$record = InvoiceValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->first();
@@ -4068,14 +4130,14 @@ class CreateInvoiceValidation extends CreateRecord
return;
}
$record1 = InvoiceValidation::where('serial_number', $serialNumber)
$hasValidPanelCode = InvoiceValidation::where('serial_number', $serialNumber)
->where('plant_id', $plantId)
->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode) {
$query->where('plant_id', $this->plantId)->where('code', $itemCode);
})
->first();
if (! $record1) {
if (! $hasValidPanelCode) {
Notification::make()
->title('Unknown: Item Code')
->body("Item code '$itemCode' with serial number '$serialNumber' not found.")
@@ -4097,9 +4159,33 @@ class CreateInvoiceValidation extends CreateRecord
return;
}
$itemCategory = $hasValidPanelCode?->stickerMasterRelation?->item?->category;
if ($itemCategory != 'Panel Box') {
Notification::make()
->title('Unknown : Category')
->body("Unknown panel box categories found:<br>$itemCode : '$itemCategory'")
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
$this->form->fill([
'plant_id' => $plantId,
'invoice_number' => $invoiceNumber,
'serial_number' => null,
'total_quantity' => $totQuan,
'update_invoice' => false,
'scanned_quantity' => $scanSQuan,
]);
return;
}
$panelBoxExist = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->first();
if(!$panelBoxExist){
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.")
@@ -4123,10 +4209,10 @@ class CreateInvoiceValidation extends CreateRecord
$notOkPanelBox = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->first();
if($notOkPanelBox->status == 'NotOk'){
if ($notOkPanelBox->status == 'NotOk') {
Notification::make()
->title('Not Ok Serial Number')
->body("scanned panel box serial number '$serNo' failed testing (NOT OK). Please scan the serial number of an OK panel box..")
->body("scanned panel box serial number '$serNo' failed testing (NOT OK).<br>Please scan the serial number of an OK panel box..")
->danger()
->seconds(3)
->send();
@@ -4147,7 +4233,7 @@ class CreateInvoiceValidation extends CreateRecord
$invoiceUpdate = InvoiceValidation::where('plant_id', $plantId)
->where('invoice_number', $invoiceNumber)
->where('sticker_master_id', $record1->sticker_master_id)
->where('sticker_master_id', $hasValidPanelCode->sticker_master_id)
->where('serial_number', $serialNumber)
->update([
'scanned_status' => 'Scanned',
@@ -4158,13 +4244,13 @@ class CreateInvoiceValidation extends CreateRecord
$scannedQuantity = InvoiceValidation::where('invoice_number', $invoiceNumber)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
if($totQuan == $scannedQuantity){
if ($totQuan == $scannedQuantity) {
Notification::make()
->title('Completed: Panel Box Invoice')
->body("Panel Box invoice '$invoiceNumber' completed the scanning process.<br>Scan the next 'Panel Box Invoice' to proceed!")
->warning()
->seconds(3)
->send();
->title('Completed: Panel Box Invoice')
->body("Panel Box invoice '$invoiceNumber' completed the scanning process.<br>Scan the next 'Panel Box Invoice' to proceed!")
->warning()
->seconds(3)
->send();
$this->dispatch('playNotificationSound');
@@ -4192,9 +4278,9 @@ class CreateInvoiceValidation extends CreateRecord
return;
}
if($invoiceUpdate){
if ($invoiceUpdate) {
Notification::make()
->title("Panel Box Success")
->title('Panel Box Success')
->body("Panel Box Serial '$serialNumber' updated successfully.")
->success()
->seconds(3)
@@ -4207,15 +4293,15 @@ class CreateInvoiceValidation extends CreateRecord
'update_invoice' => false,
'scanned_quantity' => $scannedQuantity,
]);
return;
}
}
else if (! preg_match('/^([a-zA-Z0-9]{6,})\|([1-9][a-zA-Z0-9]{8,})(?:\/[MmPpCc])?\|?$/', $serNo, $matches)) {
} elseif (! preg_match('/^([a-zA-Z0-9]{6,})\|([1-9][a-zA-Z0-9]{8,})(?:\/[MmPpCc])?\|?$/', $serNo, $matches)) {
Notification::make()
->danger()
->title('Invalid Serial QR Format')
->body('Scan valid Serial QR code proceed!<br>Sample formats are:<br>123456|1234567890123/M (or)<br>123456|1234567890123/P (or)<br>123456|1234567890123/C (or)<br>123456|1234567890123')
->body('Scan valid Serial QR code proceed!<br>Sample formats are:<br>123456|1234567890123 (or)<br>123456|1234567890123/M (or)<br>123456|1234567890123/P (or)<br>123456|1234567890123/C (or)<br>1234567/123456/2701/000001')
->seconds(3)
->send();
@@ -4343,6 +4429,22 @@ class CreateInvoiceValidation extends CreateRecord
return;
}
// $recordPanelPackage = InvoiceValidation::where('serial_number', $serialNumber)
// ->where('plant_id', $plantId)
// ->whereHas('stickerMasterRelation.item', function ($query) use ($itemCode, $plantId) {
// $query->where('plant_id', $plantId)
// ->where('code', $itemCode)
// ->whereNotNull('serial_number_motor')
// ->where('serial_number_motor', '!=', '')
// ->whereNotNull('serial_number_pump')
// ->where('serial_number_pump', '!=', '');
// })
// ->first();
// if(!$recordPanelPackage){
// }
$invalidPackage = false;
$hasMotorQr = $record->stickerMasterRelation->tube_sticker_motor ?? null;