From 3139539f46d463802110d04bb455ee658e28ef6e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 23 Oct 2020 12:57:54 +1100 Subject: [PATCH] Fixes for paid to date when refund is applied --- app/Services/Invoice/AutoBillInvoice.php | 2 +- app/Services/Payment/RefundPayment.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index ebaebbaf3cdf..b15071a40c49 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -56,7 +56,7 @@ class AutoBillInvoice extends AbstractService //if the credits cover the payments, we stop here, build the payment with credits and exit early - if($this->invoice->company->use_credits_payment == 'always' || $this->invoice->company->use_credits_payment == 'option') + if($this->invoice->company->use_credits_payment != 'off') $this->applyCreditPayment(); info("partial = {$this->invoice->partial}"); diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index 250b4229518b..1826f7297460 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -241,6 +241,7 @@ class RefundPayment $adjustment_amount += $refunded_invoice['amount']; $client->balance += $refunded_invoice['amount']; + //$client->paid_to_date -= $refunded_invoice['amount'];//todo refund balancing $client->save(); //todo adjust ledger balance here? or after and reference the credit and its total @@ -251,7 +252,8 @@ class RefundPayment // $this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string); $client = $this->payment->client->fresh(); - $client->service()->updatePaidToDate(-1 * $this->total_refund)->save(); + //$client->service()->updatePaidToDate(-1 * $this->total_refund)->save(); + $client->service()->updatePaidToDate(-1 * $refunded_invoice['amount'])->save(); } return $this;