From e1fe17cc3d438cedbe69542a7338d6ca50dbd81a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 28 Apr 2024 13:52:44 +1000 Subject: [PATCH] improved logic for post payment actions --- app/Services/Credit/ApplyPayment.php | 2 +- app/Services/Invoice/ApplyPayment.php | 2 +- app/Services/Invoice/ApplyPaymentAmount.php | 2 +- app/Services/Invoice/AutoBillInvoice.php | 2 +- app/Services/Invoice/MarkPaid.php | 2 +- app/Services/Payment/PaymentService.php | 2 +- app/Services/Payment/UpdateInvoicePayment.php | 13 ++++++------- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index 1d3838ee11fd..284450b1c0f1 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -122,7 +122,7 @@ class ApplyPayment $this->payment ->ledger() - ->updatePaymentBalance($this->amount_applied * -1); + ->updatePaymentBalance($this->amount_applied * -1, "ApplyPaymentCredit"); $this->payment ->client diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index 7a26a3c9d242..2fdcc6c7b3fc 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -73,7 +73,7 @@ class ApplyPayment extends AbstractService $this->payment ->ledger() - ->updatePaymentBalance($amount_paid); + ->updatePaymentBalance($amount_paid, "ApplyPaymentInvoice"); $this->invoice ->client diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index dfd44d36903c..11241b09a0a3 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -101,7 +101,7 @@ class ApplyPaymentAmount extends AbstractService /* Update Invoice balance */ $payment->ledger() - ->updatePaymentBalance($payment->amount * -1); + ->updatePaymentBalance($payment->amount * -1, "ApplyPaymentInvoice-"); $this->invoice->service()->workFlow()->save(); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 341d6990ef3f..67fe56aacfd8 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -213,7 +213,7 @@ class AutoBillInvoice extends AbstractService } $payment->ledger() - ->updatePaymentBalance($amount * -1) + ->updatePaymentBalance($amount * -1, "AutoBill") ->save(); $this->invoice diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 49b757ccdc0d..30d8311c7a25 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -107,7 +107,7 @@ class MarkPaid extends AbstractService ->save(); $payment->ledger() - ->updatePaymentBalance($this->payable_balance * -1); + ->updatePaymentBalance($this->payable_balance * -1, "Marked Paid Activity"); //06-09-2022 $this->invoice diff --git a/app/Services/Payment/PaymentService.php b/app/Services/Payment/PaymentService.php index ed4e165a3d84..0fdf542dd046 100644 --- a/app/Services/Payment/PaymentService.php +++ b/app/Services/Payment/PaymentService.php @@ -69,7 +69,7 @@ class PaymentService $this->payment ->ledger() - ->updatePaymentBalance($this->payment->amount); + ->updatePaymentBalance($this->payment->amount, "PaymentService"); $client->service() ->updateBalance($this->payment->amount) diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index a73fb578f9ae..1000086b6985 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -78,19 +78,18 @@ class UpdateInvoicePayment //caution what if we amount paid was less than partial - we wipe it! $invoice->balance -= $paid_amount; $invoice->paid_to_date += $paid_amount; - $invoice->save(); + $invoice->saveQuietly(); - $invoice_service = $invoice->service() + $invoice = $invoice->service() ->clearPartial() ->updateStatus() - ->workFlow(); + ->workFlow() + ->save(); if ($has_partial) { - $invoice_service->checkReminderStatus(); + $invoice->service()->checkReminderStatus()->save(); } - $invoice = $invoice_service->save(); - if ($invoice->is_proforma) { //keep proforma's hidden if (property_exists($this->payment_hash->data, 'pre_payment') && $this->payment_hash->data->pre_payment == "1") { @@ -145,7 +144,7 @@ class UpdateInvoicePayment /* Updates the company ledger */ $this->payment ->ledger() - ->updatePaymentBalance($paid_amount * -1); + ->updatePaymentBalance($paid_amount * -1, "UpdateInvoicePayment"); $pivot_invoice = $this->payment->invoices->first(function ($inv) use ($paid_invoice) { return $inv->hashed_id == $paid_invoice->invoice_id;