From cdf8f04457fa9f749e198bc6d79db155df85e996 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Mar 2022 13:20:27 +1100 Subject: [PATCH] Fixes for reversing invoice balances on archived invoice --- app/Services/Payment/RefundPayment.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index cdf86f2d0f9b..ac1d0fdf420a 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -263,6 +263,8 @@ class RefundPayment foreach ($this->refund_data['invoices'] as $refunded_invoice) { $invoice = Invoice::withTrashed()->find($refunded_invoice['invoice_id']); + $invoice->restore(); + $invoice->service()->updateBalance($refunded_invoice['amount'])->save(); $invoice->ledger()->updateInvoiceBalance($refunded_invoice['amount'], "Refund of payment # {$this->payment->number}")->save(); $invoice->paid_to_date -= $refunded_invoice['amount']; @@ -292,6 +294,9 @@ class RefundPayment TransactionLog::dispatch(TransactionEvent::PAYMENT_REFUND, $transaction, $invoice->company->db); + if($invoice->is_deleted) + $invoice->delete(); + } $client = $this->payment->client->fresh();