From d754d2f79af64caa3dc9e257726327d276965f8e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 25 Mar 2025 11:32:50 +1100 Subject: [PATCH] Fixes for credit reversals --- app/Http/Controllers/CreditController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index c76bfd9e9b..e1bbb1a479 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -214,9 +214,14 @@ class CreditController extends BaseController if ($credit->invoice_id) { $credit = $credit->service()->markSent()->save(); $credit->client->service()->updatePaidToDate(-1 * $credit->balance)->save(); // If we mutate the paid to date, we need to reverse the status of the invoice, this will allow the credit note that has been created to be used and double paid to dates prevented. - $invoice = $credit->invoice; - $invoice->status_id = \App\Models\Invoice::STATUS_REVERSED; - $invoice->save(); + // $invoice = $credit->invoice; + + $invoice = \App\Models\Invoice::withTrashed()->find($credit->invoice_id); + if ($invoice) { + $invoice->status_id = Invoice::STATUS_REVERSED; + $invoice->save(); + } + } event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars($user->id)));