From dc6031ef1a06437580e02b0360d1554d4efe480c Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Tue, 26 Aug 2025 17:03:10 +0800 Subject: [PATCH] E-Invoice - Fix a timeout problem when processing import for E-Invoice --- .../V2/ProcessPaymentReportV2CommandJob.php | 92 +++++++++++++++++++ .../ControllersLogic/ImportExcelLogic.php | 38 ++++---- 2 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 app/Classes/Jobs/Commands/V2/ProcessPaymentReportV2CommandJob.php diff --git a/app/Classes/Jobs/Commands/V2/ProcessPaymentReportV2CommandJob.php b/app/Classes/Jobs/Commands/V2/ProcessPaymentReportV2CommandJob.php new file mode 100644 index 00000000..b390a0a6 --- /dev/null +++ b/app/Classes/Jobs/Commands/V2/ProcessPaymentReportV2CommandJob.php @@ -0,0 +1,92 @@ +details = $details; + } + + public function handle() + { + Log::info(Carbon::now() . ': Start job - Processing single record from 01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT] Import.'); + $start = new Carbon(); + + $docNo = $this->details[0] ?? null; + $docDate = $this->details[1] ?? null; + $debtorCode = $this->details[2] ?? null; + $description = $this->details[3] ?? null; + $paymentMethod = $this->details[4] ?? null; + $paymentAmt = $this->details[5] ?? null; + $knockOffDocNo = $this->details[6] ?? null; + + Log::info("Row Payment Details:", [ + 'DocNo' => $docNo, + 'DocDate' => $docDate, + 'DebtorCode' => $debtorCode, + 'Description' => $description, + 'PaymentMethod' => $paymentMethod, + 'PaymentAmt' => $paymentAmt, + 'KnockOffDocNo' => $knockOffDocNo, + ]); + + if($knockOffDocNo){ + $kvp = KeyValuePair::where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->where('value', $knockOffDocNo)->first(); + if($kvp){ + $booking = $kvp->owner; + if($booking){ + if($docNo != "" && $docNo != "<>"){ + $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT, $docNo); + } + // if($eInvoiceValidationLink){ + // $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink); + // } + } + } + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + Log::info(Carbon::now() . ': End job - Processing single record from 01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT] Import. ElapsedTime: ' . $elapsedTime . '.'); + } + + + private function updateOrCreateKeyValuePair($booking, $key, $value) + { + $keyValuePairObject = new KeyValuePairObject($key, $value); + $metadata = $booking->attributesKVP()->where('key', $key)->first(); + + if ($metadata) { + (App()->make(UpdatesKeyValuePair::class))->execute($metadata, $keyValuePairObject); + } else { + (App()->make(CreatesKeyValuePair::class))->execute($booking, $keyValuePairObject); + } + } +} diff --git a/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php b/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php index 8793474e..1a57aec9 100644 --- a/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php +++ b/app/Classes/Modules/Imports/ControllersLogic/ImportExcelLogic.php @@ -5,6 +5,7 @@ namespace App\Classes\Modules\Imports\ControllersLogic; use App\Classes\Exceptions\MalformedRequestException; use App\Classes\General\Abstracts\AbstractControllerLogic; +use App\Classes\Jobs\Commands\V2\ProcessPaymentReportV2CommandJob; use App\Classes\Jobs\Commands\V2\ProcessSalesInvoiceReportV2CommandJob; use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair; use App\Classes\Modules\Accounts\Services\UpdatesKeyValuePair; @@ -221,24 +222,25 @@ class ImportExcelLogic extends AbstractControllerLogic if($knockOffDocNo) { - $kvp = KeyValuePair::where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->where('value', $knockOffDocNo)->first(); - if($kvp){ - $booking = $kvp->owner; - if($booking){ - if($docNo != "" && $docNo != "<>"){ - $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT, $docNo); - } - // if($eInvoiceValidationLink){ - // $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink); - // } - } - else{ - $unprocessedKnockOffs[] = $knockOffDocNo; - } - } - else{ - $unprocessedKnockOffs[] = $knockOffDocNo; - } + ProcessPaymentReportV2CommandJob::dispatch($details); + // $kvp = KeyValuePair::where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->where('value', $knockOffDocNo)->first(); + // if($kvp){ + // $booking = $kvp->owner; + // if($booking){ + // if($docNo != "" && $docNo != "<>"){ + // $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT, $docNo); + // } + // // if($eInvoiceValidationLink){ + // // $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink); + // // } + // } + // else{ + // $unprocessedKnockOffs[] = $knockOffDocNo; + // } + // } + // else{ + // $unprocessedKnockOffs[] = $knockOffDocNo; + // } } }