diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 5c7c53200665..292521ea5a7f 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -47,12 +47,6 @@ class MarkSent extends AbstractService ->updateBalance($adjustment, true) ->save(); - /*Adjust client balance*/ - $this->client - ->service() - ->updateBalance($adjustment) - ->save(); - /*Update ledger*/ $this->invoice ->ledger() @@ -68,6 +62,12 @@ class MarkSent extends AbstractService ->setReminder() ->save(); + /*Adjust client balance*/ + $this->client->fresh(); + $this->client->balance += $adjustment; + $this->client->save(); + + $this->invoice->markInvitationsSent(); event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/tests/Integration/CompanyLedgerTest.php b/tests/Integration/CompanyLedgerTest.php index c5ece3e949f6..01d87f9fce9c 100644 --- a/tests/Integration/CompanyLedgerTest.php +++ b/tests/Integration/CompanyLedgerTest.php @@ -182,7 +182,8 @@ class CompanyLedgerTest extends TestCase //client->balance should = 10 $invoice->service()->markSent()->save(); - $this->assertEquals($invoice->client->balance, 10); + $this->client = Client::find($this->client->id); + $this->assertEquals($this->client->balance, 10); $invoice_ledger = $invoice->company_ledger->sortByDesc('id')->first();