From c0b5c5f6d714ac6f9084008a766d085bb9061fac Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 13 Aug 2025 04:41:12 +0800 Subject: [PATCH] E-Invoice - Automapping Issues, Receive Payment for Booking Report (Import) Partial Completion --- .../ControllersLogic/ImportExcelLogic.php | 159 ++++++++++++------ .../elements/DownloadUploadComponent.vue | 14 +- 2 files changed, 123 insertions(+), 50 deletions(-) diff --git a/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php b/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php index c9b43488..248d09c1 100644 --- a/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php +++ b/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php @@ -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 != "<>"){ - $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 != "<>"){ + $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 != "<>"){ + // $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO, $docNo); + // } + // if($eInvoiceValidationLink){ + // $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink); + // } + // } + } + } } diff --git a/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue b/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue index 4d350be7..6766d83a 100644 --- a/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue +++ b/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue @@ -33,9 +33,13 @@
@@ -95,6 +99,10 @@ export default { }, isDownloading: false, generateEInvoicesUrl: null, + allowedReportTypes: [ + 'Sales Invoice Report', + '01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]', + ] } }, validations: {