From 28915d82a4f71ef503a00dfb699662b8ab6d30a7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 7 Sep 2022 08:35:19 +1000 Subject: [PATCH] CLean up code paths for client balance --- app/Services/Invoice/ApplyPayment.php | 1 - app/Services/Invoice/ApplyPaymentAmount.php | 6 ++---- app/Services/Invoice/MarkPaid.php | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index fd818c726428..eea48ba3974e 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -88,7 +88,6 @@ class ApplyPayment extends AbstractService $this->invoice ->client - ->fresh() ->service() ->updateBalance($amount_paid) ->save(); diff --git a/app/Services/Invoice/ApplyPaymentAmount.php b/app/Services/Invoice/ApplyPaymentAmount.php index 3e5db3db72d0..473a3b9591b7 100644 --- a/app/Services/Invoice/ApplyPaymentAmount.php +++ b/app/Services/Invoice/ApplyPaymentAmount.php @@ -43,7 +43,7 @@ class ApplyPaymentAmount extends AbstractService public function run() { if ($this->invoice->status_id == Invoice::STATUS_DRAFT) { - $this->invoice->service()->markSent()->save(); + $this->invoice = $this->invoice->service()->markSent()->save(); } /*Don't double pay*/ @@ -88,10 +88,8 @@ class ApplyPaymentAmount extends AbstractService $this->invoice ->client - ->fresh() ->service() - ->updateBalance($payment->amount * -1) - ->updatePaidToDate($payment->amount) + ->updateBalanceAndPaidToDate($payment->amount * -1, $payment->amount) ->save(); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 9f734d17d802..9c60591515f6 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -50,7 +50,7 @@ class MarkPaid extends AbstractService } if ($this->invoice->status_id == Invoice::STATUS_DRAFT) { - $this->invoice->service()->markSent()->save(); + $this->invoice = $this->invoice->service()->markSent()->save(); } \DB::connection(config('database.default'))->transaction(function () {