From a09666fb96b3accbe9e20b7b39a93968f6686e03 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 19 Oct 2021 20:04:19 +1100 Subject: [PATCH] Minor fixes for marking an invoice as sent --- app/PaymentDrivers/BaseDriver.php | 2 +- app/Services/Invoice/InvoiceService.php | 2 +- app/Services/Invoice/MarkPaid.php | 4 ++-- app/Services/Invoice/MarkSent.php | 22 +++++++++++++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 57a2882235..e1b0e65fee 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -308,7 +308,7 @@ class BaseDriver extends AbstractPaymentDriver $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) { - $invoice->service()->removeUnpaidGatewayFees(); + $invoice->service()->removeUnpaidGatewayFees()->save(); }); } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index dd0977a55b..d137435866 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -494,6 +494,6 @@ class InvoiceService { $this->invoice->saveQuietly(); - return $this->invoice; + return $this->invoice->fresh(); } } diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index a78ba98b2c..6f6831e0b6 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -86,8 +86,8 @@ class MarkPaid extends AbstractService ->deletePdf() ->save(); - if ($this->invoice->client->getSetting('client_manual_payment_notification')) - $payment->service()->sendEmail(); + // if ($this->invoice->client->getSetting('client_manual_payment_notification')) + // $payment->service()->sendEmail(); /* Update Invoice balance */ event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 198f7dbbd5..fbf874f955 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -33,15 +33,18 @@ class MarkSent extends AbstractService { /* Return immediately if status is not draft */ - if ($this->invoice->status_id != Invoice::STATUS_DRAFT) { + if ($this->invoice->fresh()->status_id != Invoice::STATUS_DRAFT) { return $this->invoice; } - $this->invoice->markInvitationsSent(); - + /*Set status*/ $this->invoice ->service() ->setStatus(Invoice::STATUS_SENT) + ->save(); + + $this->invoice + ->service() ->applyNumber() ->setDueDate() ->updateBalance($this->invoice->amount) @@ -49,9 +52,18 @@ class MarkSent extends AbstractService ->setReminder() ->save(); - $this->client->service()->updateBalance($this->invoice->balance)->save(); + $this->invoice->markInvitationsSent(); - $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, "Invoice {$this->invoice->number} marked as sent."); + /*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)));