Check for emails prior to attempting a send
This commit is contained in:
parent
9817158076
commit
a089b7809f
|
|
@ -34,6 +34,8 @@ class BulkInvoiceJob implements ShouldQueue
|
|||
|
||||
public $timeout = 3600;
|
||||
|
||||
private bool $contact_has_email = false;
|
||||
|
||||
private array $templates = [
|
||||
'email_template_invoice',
|
||||
'email_template_quote',
|
||||
|
|
@ -80,6 +82,10 @@ class BulkInvoiceJob implements ShouldQueue
|
|||
|
||||
$template = $this->resolveTemplateString($this->reminder_template);
|
||||
|
||||
if($invitation->contact->email)
|
||||
{
|
||||
$this->contact_has_email = true;
|
||||
|
||||
$mo = new EmailObject();
|
||||
$mo->entity_id = $invitation->invoice_id;
|
||||
$mo->template = $template; //full template name in use
|
||||
|
|
@ -92,15 +98,16 @@ class BulkInvoiceJob implements ShouldQueue
|
|||
$mo->vendor_id = $invitation->contact->vendor_id ?? null;
|
||||
|
||||
Email::dispatch($mo, $invitation->company->withoutRelations());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if ($invoice->invitations->count() >= 1) {
|
||||
if ($invoice->invitations->count() >= 1 && $this->contact_has_email) {
|
||||
$invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', $this->reminder_template);
|
||||
$invoice->sendEvent(Webhook::EVENT_SENT_INVOICE, "client");
|
||||
}
|
||||
|
||||
sleep(1); // this is needed to slow down the amount of data that is pushed into cache
|
||||
$this->contact_has_email = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue