E-Invoice - Automapping Issues, Receive Payment for Booking Report (Import) Partial Completion

This commit is contained in:
Dillon Ngo
2025-08-13 04:41:12 +08:00
parent bdd54cbe31
commit c0b5c5f6d7
2 changed files with 123 additions and 50 deletions
@@ -58,7 +58,14 @@ class ImportExcelLogic extends AbstractControllerLogic
$reportType = $request->input('report_type');
$object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports');
foreach ($object->getFiles() as $file){
$files = $object->getFiles();
if (count($files) > 1) {
throw new MalformedRequestException('Import function can only process one file at a time.');
}
foreach ($files as $file) {
$collection = Excel::toCollection(null, json_decode($file)->file_info->original->file, null, null, true);
$sheet = $collection->first();
@@ -75,6 +82,15 @@ class ImportExcelLogic extends AbstractControllerLogic
'businessactivitydesc', 'debtorcode', 'tradename', 'address', 'postcode',
'phone', 'emailaddress', 'city', 'countrycode', 'statecode'
];
$paymentReportHeader = [
'docno',
'docdate',
'debtorcode',
'description',
'paymentmethod',
'paymentamt',
'knockoffdocno'
];
if ($reportType === 'Sales Invoice Report') {
$optionalColumn = 'einvoicevalidationlink';
@@ -89,53 +105,18 @@ class ImportExcelLogic extends AbstractControllerLogic
} elseif ($reportType === 'Customers Report' && $normalizedHeader !== $customersReportHeader) {
throw new MalformedRequestException('Uploaded Excel file format is incorrect. Column headers do not match expected format.');
}
elseif ($reportType === '01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]' && $normalizedHeader !== $paymentReportHeader) {
throw new MalformedRequestException('Uploaded Excel file format is incorrect. Column headers do not match expected format.');
}
$rows = $sheet->skip(1);
foreach ($rows as $index => $details) {
$docNo = $details[0] ?? null;
$docDate = $details[1] ?? null;
$debtorCode = $details[2] ?? null;
$ref = $details[3] ?? null;
$shipInfo = $details[4] ?? null;
$accNo = $details[5] ?? null;
$detailDescription = $details[6] ?? null;
$furtherDescription = $details[7] ?? null;
$classification = $details[8] ?? null;
$deptNo = $details[9] ?? null;
$qty = $details[10] ?? null;
$unitPrice = $details[11] ?? null;
$submitEinvoice = $details[12] ?? null;
$consolidatedEinvoice = $details[13] ?? null;
$eInvoiceValidationLink = $details[14] ?? null; // Safe access for the new column
Log::info("Row {$index} Details:", [
'DocNo' => $docNo,
'DocDate' => $docDate,
'DebtorCode' => $debtorCode,
'Ref' => $ref,
'ShipInfo' => $shipInfo,
'AccNo' => $accNo,
'DetailDescription' => $detailDescription,
'FurtherDescription' => $furtherDescription,
'Classification' => $classification,
'DeptNo' => $deptNo,
'Qty' => $qty,
'UnitPrice' => $unitPrice,
'SubmitEinvoice' => $submitEinvoice,
'ConsolidatedEinvoice' => $consolidatedEinvoice,
'EInvoiceValidationLink' => $eInvoiceValidationLink,
]);
$booking = Booking::where('marking', $ref)->first();
if($booking){
if($docNo != "" && $docNo != "<<New>>"){
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO, $docNo);
}
if($eInvoiceValidationLink){
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
}
}
if ($reportType === 'Sales Invoice Report') {
$this->processSalesInvoiceReport($sheet);
}
else if ($reportType === '01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]'){
$this->processPaymentReport($sheet);
}
else{
throw new MalformedRequestException('Cannot process report type: ' . $reportType);
}
}
@@ -153,4 +134,88 @@ class ImportExcelLogic extends AbstractControllerLogic
$this->createsKeyValuePair->execute($booking, $keyValuePairObject);
}
}
private function processSalesInvoiceReport($sheet){
$rows = $sheet->skip(1);
foreach ($rows as $index => $details) {
$docNo = $details[0] ?? null;
$docDate = $details[1] ?? null;
$debtorCode = $details[2] ?? null;
$ref = $details[3] ?? null;
$shipInfo = $details[4] ?? null;
$accNo = $details[5] ?? null;
$detailDescription = $details[6] ?? null;
$furtherDescription = $details[7] ?? null;
$classification = $details[8] ?? null;
$deptNo = $details[9] ?? null;
$qty = $details[10] ?? null;
$unitPrice = $details[11] ?? null;
$submitEinvoice = $details[12] ?? null;
$consolidatedEinvoice = $details[13] ?? null;
$eInvoiceValidationLink = $details[14] ?? null; // Safe access for the new column
Log::info("Row {$index} Details:", [
'DocNo' => $docNo,
'DocDate' => $docDate,
'DebtorCode' => $debtorCode,
'Ref' => $ref,
'ShipInfo' => $shipInfo,
'AccNo' => $accNo,
'DetailDescription' => $detailDescription,
'FurtherDescription' => $furtherDescription,
'Classification' => $classification,
'DeptNo' => $deptNo,
'Qty' => $qty,
'UnitPrice' => $unitPrice,
'SubmitEinvoice' => $submitEinvoice,
'ConsolidatedEinvoice' => $consolidatedEinvoice,
'EInvoiceValidationLink' => $eInvoiceValidationLink,
]);
$booking = Booking::where('marking', $ref)->first();
if($booking){
if($docNo != "" && $docNo != "<<New>>"){
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO, $docNo);
}
if($eInvoiceValidationLink){
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
}
}
}
}
private function processPaymentReport($sheet){
$rows = $sheet->skip(1);
foreach ($rows as $index => $details) {
$docNo = $details[0] ?? null;
$docDate = $details[1] ?? null;
$debtorCode = $details[2] ?? null;
$description = $details[3] ?? null;
$paymentMethod = $details[4] ?? null;
$paymentAmt = $details[5] ?? null;
$knockOffDocNo = $details[6] ?? null;
Log::info("Row {$index} Payment Details:", [
'DocNo' => $docNo,
'DocDate' => $docDate,
'DebtorCode' => $debtorCode,
'Description' => $description,
'PaymentMethod' => $paymentMethod,
'PaymentAmt' => $paymentAmt,
'KnockOffDocNo' => $knockOffDocNo,
]);
// $booking = Booking::where('marking', $ref)->first();
// if($booking){
// if($docNo != "" && $docNo != "<<New>>"){
// $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO, $docNo);
// }
// if($eInvoiceValidationLink){
// $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
// }
// }
}
}
}
@@ -33,9 +33,13 @@
<div class="col-12 col-md-auto pl-md-0">
<button
class="btn btn-lg fs-11 w-100 h-100 d-flex justify-content-center align-items-center"
:class="parameters.reportType === 'Sales Invoice Report' ? 'btn-primary requestModal pointer' : 'btn-secondary'"
:disabled="parameters.reportType !== 'Sales Invoice Report'"
:data-type="parameters.reportType === 'Sales Invoice Report' ? 'uploadDocumentModel' : null"
:class="allowedReportTypes.includes(parameters.reportType)
? 'btn-primary requestModal pointer'
: 'btn-secondary'"
:disabled="!allowedReportTypes.includes(parameters.reportType)"
:data-type="allowedReportTypes.includes(parameters.reportType)
? 'uploadDocumentModel'
: null"
>
<span>Import</span>
</button>
@@ -95,6 +99,10 @@ export default {
},
isDownloading: false,
generateEInvoicesUrl: null,
allowedReportTypes: [
'Sales Invoice Report',
'01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]',
]
}
},
validations: {