Fixes for credit reversals

This commit is contained in:
David Bomba 2025-03-25 11:32:50 +11:00
parent 12981de1ca
commit d754d2f79a
1 changed files with 8 additions and 3 deletions

View File

@ -214,9 +214,14 @@ class CreditController extends BaseController
if ($credit->invoice_id) { if ($credit->invoice_id) {
$credit = $credit->service()->markSent()->save(); $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. $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 = $credit->invoice;
$invoice->status_id = \App\Models\Invoice::STATUS_REVERSED;
$invoice->save(); $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))); event(new CreditWasCreated($credit, $credit->company, Ninja::eventVars($user->id)));