From 632948477104956631f1330ad78ed016e3072588 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 18 Apr 2023 18:56:01 +1000 Subject: [PATCH] Reorder events when sending recurring invoice and only send a payment receipt if auto bill is enabled. --- app/Jobs/RecurringInvoice/SendRecurring.php | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 2b9269fd1a7a..7358ee20b5c8 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -84,11 +84,13 @@ class SendRecurring implements ShouldQueue } //12-01-2023 i moved this block after fillDefaults to handle if standard invoice auto bill config has been enabled, recurring invoice should override. - if ($this->recurring_invoice->auto_bill === 'always') { + if ($this->recurring_invoice->auto_bill == 'always') { $invoice->auto_bill_enabled = true; - } elseif ($this->recurring_invoice->auto_bill === 'optout' || $this->recurring_invoice->auto_bill === 'optin') { - } elseif ($this->recurring_invoice->auto_bill === 'off') { + $invoice->saveQuietly(); + } elseif ($this->recurring_invoice->auto_bill == 'optout' || $this->recurring_invoice->auto_bill == 'optin') { + } elseif ($this->recurring_invoice->auto_bill == 'off') { $invoice->auto_bill_enabled = false; + $invoice->saveQuietly(); } $invoice = $this->createRecurringInvitations($invoice); @@ -111,7 +113,16 @@ class SendRecurring implements ShouldQueue event('eloquent.created: App\Models\Invoice', $invoice); - if ($invoice->client->getSetting('auto_email_invoice')) { + //auto bill, BUT NOT DRAFTS!! + if ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->client->getSetting('auto_email_invoice')) { + nlog("attempting to autobill {$invoice->number}"); + AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2)); + } + elseif ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->client->getSetting('auto_email_invoice') && ($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay()))) { + nlog("attempting to autobill {$invoice->number}"); + AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2)); + } + elseif ($invoice->client->getSetting('auto_email_invoice')) { //Admin notification for recurring invoice sent. if ($invoice->invitations->count() >= 1) { $invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', 'email_template_invoice'); @@ -130,16 +141,7 @@ class SendRecurring implements ShouldQueue }); } - //auto bill, BUT NOT DRAFTS!! - if ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->client->getSetting('auto_email_invoice')) { - nlog("attempting to autobill {$invoice->number}"); - AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2)); - } elseif ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->client->getSetting('auto_email_invoice')) { - if ($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay())) { - nlog("attempting to autobill {$invoice->number}"); - AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2)); - } - } + } /**