From 07eba43901947d79dba81e251b270f4671fefb3f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 19 Nov 2021 17:13:57 +1100 Subject: [PATCH] Minor refactor for update balance --- app/Services/Invoice/InvoiceService.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 5ea2700892..c02946122d 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -136,7 +136,17 @@ class InvoiceService */ public function updateBalance($balance_adjustment, bool $is_draft = false) { - $this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment, $is_draft))->run(); + // $this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment, $is_draft))->run(); + + if ($this->invoice->is_deleted) { + return $this; + } + + $this->invoice->balance += $balance_adjustment; + + if ($this->invoice->balance == 0 && !$is_draft) { + $this->invoice->status_id = Invoice::STATUS_PAID; + } if ((int)$this->invoice->balance == 0) { $this->invoice->next_send_date = null;