From 412dbd64d5d5d7b3e6f5da60a72f01e996ad677c Mon Sep 17 00:00:00 2001 From: edmondlang Date: Fri, 27 Oct 2023 16:12:31 +0800 Subject: [PATCH] fix-payment-status-updated-but-failed-update-invoice --- routes/web.php | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/routes/web.php b/routes/web.php index 55cd1302..7a6df56a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,11 +1,8 @@ '; }); + +Route::get('fix-payment-status-updated-but-failed-update-invoice', function (UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor) { + $invoices = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [2]) + ->whereHas('transactions', function ($query) { + $query->where('type', TransactionType::PAYMENT) + ->whereIn('status', [2, 3]); + })->get(); + + + foreach ($invoices as $invoice) { + echo "Fixing" . $invoice->owner->owner->reference . '
'; + + $totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount'); + + if (($invoice->amount - $totalPaidAmount) < 0.01) { + $updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED); + + $packingList = $invoice->owner; + + $packingList->status = ApprovalStatus::APPROVED; + $packingList->save(); + + if (app()->environment('production')) { + $updateDoFromVTPortalProcessor->execute($packingList); + $updateDoFromYDPortalProcessor->execute($packingList); + } + + echo 'done fix ' . $invoice->owner->owner->reference . '
'; + } + } +}); \ No newline at end of file