diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index d03a98a11fdd..a96946ca6871 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -136,11 +136,13 @@ class EmailController extends BaseController } $entity_obj->invitations->each(function ($invitation) use ($data, $entity_string, $entity_obj, $template) { + if (! $invitation->contact->trashed() && $invitation->contact->email) { $entity_obj->service()->markSent()->save(); EmailEntity::dispatch($invitation->fresh(), $invitation->company, $template, $data)->delay(now()->addSeconds(2)); } + }); $entity_obj = $entity_obj->fresh(); diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index 6abd46369ed0..cf3cd96bab82 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -90,7 +90,6 @@ class EmailEntity implements ShouldQueue $this->template_data = $template_data; - $this->email_entity_builder = $this->resolveEmailBuilder(); } /** @@ -106,6 +105,8 @@ class EmailEntity implements ShouldQueue return; } + $this->email_entity_builder = $this->resolveEmailBuilder(); + /* Set DB */ MultiDB::setDB($this->company->db); diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 2ff606b4ce21..d99ffa6b1329 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -148,8 +148,12 @@ class ReminderJob implements ShouldQueue (Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) { $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { - EmailEntity::dispatch($invitation, $invitation->company, $reminder_template)->delay(now()->addSeconds(3)); - nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); + + if($invitation->contact && !$invitation->contact->trashed() && $invitation->contact->email) { + EmailEntity::dispatch($invitation, $invitation->company, $reminder_template)->delay(now()->addSeconds(3)); + nlog("Firing reminder email for invoice {$invoice->number} - {$reminder_template}"); + } + }); if ($invoice->invitations->count() > 0) { diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 003d5fb1f79f..a2a98275804e 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -226,6 +226,12 @@ class HtmlEngine $data['$view_url'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_credit')]; // $data['$view_link'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_credit')]; $data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()) ?: ' ', 'label' => ctrans('texts.credit_date')]; + + $data['$credit.custom1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'credit1', $this->entity->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice1')]; + $data['$credit.custom2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'credit2', $this->entity->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice2')]; + $data['$credit.custom3'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'credit3', $this->entity->custom_value3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice3')]; + $data['$credit.custom4'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'credit4', $this->entity->custom_value4, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice4')]; + } $data['$portal_url'] = ['value' => $this->invitation->getPortalLink(), 'label' =>''];