From 55839d66ed9b370e5f016b230e003aee84266f8d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 Feb 2021 16:02:38 +1100 Subject: [PATCH 1/2] Auto archive invoice - Mark Paid --- app/Jobs/Invoice/InvoiceWorkflowSettings.php | 5 +++-- app/Services/Invoice/MarkPaid.php | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Jobs/Invoice/InvoiceWorkflowSettings.php b/app/Jobs/Invoice/InvoiceWorkflowSettings.php index 579a7620f3c4..593ffbb378f3 100644 --- a/app/Jobs/Invoice/InvoiceWorkflowSettings.php +++ b/app/Jobs/Invoice/InvoiceWorkflowSettings.php @@ -35,10 +35,9 @@ class InvoiceWorkflowSettings implements ShouldQueue * @param Invoice $invoice * @param Client|null $client */ - public function __construct(Invoice $invoice, Client $client = null) + public function __construct(Invoice $invoice) { $this->invoice = $invoice; - $this->client = $client ?? $invoice->client; $this->base_repository = new BaseRepository(); } @@ -49,6 +48,8 @@ class InvoiceWorkflowSettings implements ShouldQueue */ public function handle() { + $this->client = $this->invoice->client; + if ($this->client->getSetting('auto_archive_invoice')) { /* Throws: Payment amount xxx does not match invoice totals. */ $this->base_repository->archive($this->invoice); diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 55c7e18016b8..e3f2c1c5bb54 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -14,6 +14,7 @@ namespace App\Services\Invoice; use App\Events\Invoice\InvoiceWasPaid; use App\Events\Payment\PaymentWasCreated; use App\Factory\PaymentFactory; +use App\Jobs\Invoice\InvoiceWorkflowSettings; use App\Jobs\Payment\EmailPayment; use App\Models\Invoice; use App\Models\Payment; @@ -90,6 +91,8 @@ class MarkPaid extends AbstractService ->updatePaidToDate($payment->amount) ->save(); + InvoiceWorkflowSettings::dispatchNow($this->invoice); + return $this->invoice; } } From 47eabf5434461381de405330aedacd4cff5fe84c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 Feb 2021 16:03:34 +1100 Subject: [PATCH 2/2] Invoice Actions --- app/Services/Invoice/InvoiceService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 543d034feab0..b45e5eb19b6e 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -12,6 +12,7 @@ namespace App\Services\Invoice; use App\Jobs\Entity\CreateEntityPdf; +use App\Jobs\Invoice\InvoiceWorkflowSettings; use App\Jobs\Util\UnlinkFile; use App\Models\CompanyGateway; use App\Models\Expense; @@ -239,6 +240,9 @@ class InvoiceService public function updateStatus() { if ((int)$this->invoice->balance == 0) { + + InvoiceWorkflowSettings::dispatch($this->invoice); + $this->setStatus(Invoice::STATUS_PAID); }