From 55f96e035ba6ad051ce251a72ff47322ca81945e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 15 Dec 2021 07:05:12 +1100 Subject: [PATCH] Create recurring invoice with invitations for draft --- app/Jobs/RecurringInvoice/SendRecurring.php | 47 +++++++++++---------- app/Repositories/BaseRepository.php | 11 ----- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 0f722256a3c1..4d992607a054 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -83,8 +83,6 @@ class SendRecurring implements ShouldQueue //->createInvitations() //need to only link invitations to those in the recurring invoice ->fillDefaults() ->save(); - - $invoice = $this->createRecurringInvitations($invoice); } else{ @@ -94,6 +92,8 @@ class SendRecurring implements ShouldQueue ->save(); } + $invoice = $this->createRecurringInvitations($invoice); + nlog("updating recurring invoice dates"); /* Set next date here to prevent a recurring loop forming */ $this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate(); @@ -122,27 +122,30 @@ class SendRecurring implements ShouldQueue event('eloquent.created: App\Models\Invoice', $invoice); - //Admin notification for recurring invoice sent. - if ($invoice->invitations->count() >= 1 ) { - $invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', 'email_template_invoice'); - } - - nlog("Invoice {$invoice->number} created"); - - $invoice->invitations->each(function ($invitation) use ($invoice) { - if ($invitation->contact && !$invitation->contact->trashed() && strlen($invitation->contact->email) >=1 && $invoice->client->getSetting('auto_email_invoice')) { - - try{ - EmailEntity::dispatch($invitation, $invoice->company)->delay(now()->addSeconds(1)); - } - catch(\Exception $e) { - nlog($e->getMessage()); - } - - nlog("Firing email for invoice {$invoice->number}"); + if($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'); } - }); - + + nlog("Invoice {$invoice->number} created"); + + $invoice->invitations->each(function ($invitation) use ($invoice) { + if ($invitation->contact && !$invitation->contact->trashed() && strlen($invitation->contact->email) >=1 && $invoice->client->getSetting('auto_email_invoice')) { + + try{ + EmailEntity::dispatch($invitation, $invoice->company)->delay(now()->addSeconds(1)); + } + catch(\Exception $e) { + nlog($e->getMessage()); + } + + nlog("Firing email for invoice {$invoice->number}"); + } + }); + } + if ($invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->auto_bill_enabled) { nlog("attempting to autobill {$invoice->number}"); $invoice->service()->autoBill(); diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 9d6d31e1d09c..8858e0133284 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -222,17 +222,6 @@ class BaseRepository if (array_key_exists('documents', $data)) $this->saveDocuments($data['documents'], $model); - /* Marks whether the client contact should receive emails based on the send_email property */ - // if (isset($data['client_contacts'])) { - // foreach ($data['client_contacts'] as $contact) { - // if ($contact['send_email'] == 1 && is_string($contact['id'])) { - // $client_contact = ClientContact::find($this->decodePrimaryKey($contact['id'])); - // $client_contact->send_email = true; - // $client_contact->save(); - // } - // } - // } - /* If invitations are present we need to filter existing invitations with the new ones */ if (isset($data['invitations'])) { $invitations = collect($data['invitations']);