Merge pull request 'Updated invoice import functionality to allow unique record' (#422) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 18s

Reviewed-on: #422
This commit was merged in pull request #422.
This commit is contained in:
2026-02-27 09:32:09 +00:00

View File

@@ -322,8 +322,13 @@ class InvoiceValidationImporter extends Importer
$curPanelBoxSerialNumber = null;
}
$record = InvoiceValidation::where('serial_number', $serialNumber)
->where('plant_id', $plantId)
$record = InvoiceValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)->first();
if ($record && $record->sticker_master_id != $stickId) {
$stickId = null;
$warnMsg[] = 'Item code mismatch with existing record!';
} elseif ($record) {
$record = InvoiceValidation::where('serial_number', $serialNumber)->where('plant_id', $plantId)
->whereHas('stickerMasterRelation.item', function ($query) use ($plantId, $iCode) {
$query->where('plant_id', $plantId)->where('code', $iCode);
})
@@ -338,28 +343,32 @@ class InvoiceValidationImporter extends Importer
$hadPumpSetQr = $record->scanned_status_set ?? null;
$hadCapacitorQr = $record->capacitor_scanned_status ?? null;
if ($hadMotorQr) {
if ($hadMotorQr && $hasMotorQr) {
$curMotorQr = $hadMotorQr;
}
if ($hadPumpQr) {
if ($hadPumpQr && $hasPumpQr) {
$curPumpQr = $hadPumpQr;
}
if ($hadPumpSetQr) {
if ($hadPumpSetQr && $hasPumpSetQr) {
$curPumpSetQr = $hadPumpSetQr;
}
if ($hadCapacitorQr) {
if ($hadCapacitorQr && $hasCapacitorQr) {
$curCapacitorQr = $hadCapacitorQr;
$curPanelBoxCode = $record->panel_box_code ?? null;
$curPanelBoxSupplier = $record->panel_box_supplier ?? null;
$curPanelBoxSerialNumber = $record->panel_box_serial_number ?? null;
}
if ($record->scanned_status == 'Scanned') {
return null;
} elseif ($record->invoice_number != $invoiceNumber) {
throw new RowImportFailedException('Invoice number mismatch with existing record!');
}
$warnMsg[] = 'Record Item ID : '.$record->sticker_master_id.' Master Item ID : '.$stickId;
if ($record->invoice_number != $invoiceNumber) {
$stickId = null;
$warnMsg[] = 'Invoice number mismatch with existing record!';
// throw new RowImportFailedException('Invoice number mismatch with existing record!');
} elseif ($record->scanned_status == 'Scanned') {
$stickId = null;
return null;
} else {
// if ($hadPumpQr == $hasPumpQr && $hadPumpSetQr == $hasPumpSetQr)
if ($hasMotorQr || $hasPumpQr || $hasPumpSetQr || $hasCapacitorQr) {
$scanCnt = $curMotorQr ? $scanCnt + 1 : $scanCnt;
@@ -384,6 +393,8 @@ class InvoiceValidationImporter extends Importer
}
}
}
}
}
if ($stickId) {
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
@@ -426,6 +437,7 @@ class InvoiceValidationImporter extends Importer
throw new RowImportFailedException(implode(', ', $warnMsg));
}
if ($stickId) {
if ($hasMotorQr || $hasPumpQr || $hasPumpSetQr || $hasCapacitorQr) {
$scanCnt = $curMotorQr ? $scanCnt + 1 : $scanCnt;
$scanCnt = $curPumpQr ? $scanCnt + 1 : $scanCnt;
@@ -465,6 +477,7 @@ class InvoiceValidationImporter extends Importer
'created_at' => $cDateTime->format('Y-m-d H:i:s'),
'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
]);
}
return null;
// return new InvoiceValidation;