Refactor for markpaid to prevent duplicate balance updated

This commit is contained in:
David Bomba 2025-06-04 14:25:14 +10:00
parent fbc3297d43
commit c3711ad226
1 changed files with 24 additions and 1 deletions

View File

@ -41,7 +41,30 @@ class MarkPaid extends AbstractService
}
if ($this->invoice->status_id == Invoice::STATUS_DRAFT) {
$this->invoice = $this->invoice->service()->markSent()->save();
// $this->invoice = $this->invoice->service()->markSent()->save();
/*Set status*/
$this->invoice->status_id = Invoice::STATUS_SENT;
$this->invoice->balance = $this->invoice->amount;
/*Update ledger*/
$this->invoice
->ledger()
->updateInvoiceBalance($this->invoice->amount, "Invoice {$this->invoice->number} marked as sent.");
$this->invoice->client->service()->updateBalance($this->invoice->amount);
/* Perform additional actions on invoice */
$this->invoice
->service()
->applyNumber()
->setDueDate()
->setReminder()
->save();
$this->invoice->markInvitationsSent();
event(new \App\Events\Invoice\InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
}
$already_paid = false;