From 6974841921c78b716ba7ce059974fe1323b16e80 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 17 Feb 2024 19:08:20 +1100 Subject: [PATCH] Refactor for payment processing --- app/Services/Invoice/AutoBillInvoice.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 3c864a6a88f3..22eacad77639 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -279,7 +279,6 @@ class AutoBillInvoice extends AbstractService $this->is_partial_amount = true; } - $payment_repo = new PaymentRepository(new CreditRepository()); foreach ($unapplied_payments as $key => $payment) { @@ -296,7 +295,7 @@ class AutoBillInvoice extends AbstractService $payment_repo->save($payload, $payment); } } else { - //more than needed + //more than needed if ($payment_balance > $this->invoice->balance) { $payload = ['client_id' => $this->invoice->client_id, 'invoices' => [['invoice_id' => $this->invoice->id,'amount' => $this->invoice->balance]]]; @@ -312,6 +311,10 @@ class AutoBillInvoice extends AbstractService } $this->invoice = $this->invoice->fresh(); + + if((int)$this->invoice->balance == 0) { + return $this; + } } return $this;