diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 8fe2f2e87a49..a7d0488ce887 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -37,34 +37,37 @@ class MarkSent extends AbstractService return $this->invoice; } + $adjustment = $this->invoice->amount; + /*Set status*/ $this->invoice ->service() ->setStatus(Invoice::STATUS_SENT) + ->updateBalance($adjustment, true) ->save(); - $this->invoice + /*Adjust client balance*/ + $this->client + ->service() + ->updateBalance($adjustment) + ->save(); + + /*Update ledger*/ + $this->invoice + ->ledger() + ->updateInvoiceBalance($adjustment, "Invoice {$this->invoice->number} marked as sent."); + + /* Perform additional actions on invoice */ + $this->invoice ->service() ->applyNumber() ->setDueDate() - ->updateBalance($this->invoice->amount, true) ->deletePdf() ->setReminder() ->save(); $this->invoice->markInvitationsSent(); - /*Adjust client balance*/ - $this->client - ->service() - ->updateBalance($this->invoice->balance) - ->save(); - - /*Update ledger*/ - $this->invoice - ->ledger() - ->updateInvoiceBalance($this->invoice->balance, "Invoice {$this->invoice->number} marked as sent."); - event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); return $this->invoice->fresh();