From e01f100407072e1435b39f5ebc23c36901ec4d54 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 21 May 2024 11:40:12 +1000 Subject: [PATCH] fixes for custom email templates --- app/Jobs/Mail/NinjaMailerJob.php | 7 ++----- app/Jobs/Payment/EmailPayment.php | 1 + app/Mail/Engine/InvoiceEmailEngine.php | 4 ---- app/Mail/Engine/PaymentEmailEngine.php | 1 - app/Models/Presenters/CompanyPresenter.php | 4 ++-- app/Services/Email/Email.php | 2 +- app/Utils/HtmlEngine.php | 11 ++++++++++- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 0406f27ee6..b1b1c94690 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -136,8 +136,8 @@ class NinjaMailerJob implements ShouldQueue $mailable = $this->nmo->mailable; - /** May need to re-build it here */ - if (Ninja::isHosted() && method_exists($mailable, 'build')) { + /** May need to re-build it here @todo explain why we need this? */ + if (Ninja::isHosted() && method_exists($mailable, 'build') && $this->nmo->settings->email_style != "custom") { $mailable->build(); } @@ -675,9 +675,6 @@ class NinjaMailerJob implements ShouldQueue */ private function preFlightChecksFail(): bool { - -(new \Modules\Admin\Jobs\Account\EmailQuality($this->nmo, $this->company))->run(); - /* Always send regardless */ if ($this->override) { return false; diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 9ab74ceae8..1d1c88313e 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -116,6 +116,7 @@ class EmailPayment implements ShouldQueue $invoice->invitations->each(function ($invite) use ($email_builder) { + $cloned_mailable = unserialize(serialize($email_builder)); $nmo = new NinjaMailerObject(); diff --git a/app/Mail/Engine/InvoiceEmailEngine.php b/app/Mail/Engine/InvoiceEmailEngine.php index 9e66b4524f..8f9e15f8db 100644 --- a/app/Mail/Engine/InvoiceEmailEngine.php +++ b/app/Mail/Engine/InvoiceEmailEngine.php @@ -134,10 +134,6 @@ class InvoiceEmailEngine extends BaseEmailEngine $this->setAttachments([['file' => base64_encode($pdf), 'name' => $this->invoice->numberFormatter().'.pdf']]); } - // $hash = Str::uuid(); - // $url = \Illuminate\Support\Facades\URL::temporarySignedRoute('protected_download', now()->addHour(), ['hash' => $hash]); - // Cache::put($hash, $url, now()->addHour()); - //attach third party documents if ($this->client->getSetting('document_email_attachment') !== false && $this->invoice->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { if ($this->invoice->recurring_invoice()->exists()) { diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 32613b80f1..c2d68aef57 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -99,7 +99,6 @@ class PaymentEmailEngine extends BaseEmailEngine ->setViewLink('') ->setViewText(''); - if ($this->client->getSetting('pdf_email_attachment') !== false && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { $template_in_use = false; diff --git a/app/Models/Presenters/CompanyPresenter.php b/app/Models/Presenters/CompanyPresenter.php index 085fc2806d..00fd2ccbc2 100644 --- a/app/Models/Presenters/CompanyPresenter.php +++ b/app/Models/Presenters/CompanyPresenter.php @@ -83,9 +83,9 @@ class CompanyPresenter extends EntityPresenter ]; if (strlen($settings->company_logo) >= 1 && (strpos($settings->company_logo, 'http') !== false)) { - return "data:image/png;base64, ". base64_encode(@file_get_contents($settings->company_logo, false, stream_context_create($context_options))); + return "data:image/png;base64,". base64_encode(@file_get_contents($settings->company_logo, false, stream_context_create($context_options))); } elseif (strlen($settings->company_logo) >= 1) { - return "data:image/png;base64, ". base64_encode(@file_get_contents(url('') . $settings->company_logo, false, stream_context_create($context_options))); + return "data:image/png;base64,". base64_encode(@file_get_contents(url('') . $settings->company_logo, false, stream_context_create($context_options))); } else { return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; } diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 661b8aef52..e56091c909 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -314,7 +314,7 @@ class Email implements ShouldQueue $this->logMailError($e->getMessage(), $this->company->clients()->first()); $this->cleanUpMailers(); -$this->entityEmailFailed($message); + $this->entityEmailFailed($message); return; } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index c3946d6193..111ec0f4f7 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -561,10 +561,19 @@ class HtmlEngine $data['$spc_qr_code'] = ['value' => $this->company->present()->getSpcQrCode($this->client->currency()->code, $this->entity->number, $this->entity->balance, $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client)), 'label' => '']; - $logo = $this->company->present()->logo_base64($this->settings); + if(Ninja::isHosted()) + $logo = $this->company->present()->logo($this->settings); + else + $logo = $this->company->present()->logo_base64($this->settings); + + $logo_url = $this->company->present()->logo($this->settings); + $data['$company.logo'] = ['value' => $logo ?: ' ', 'label' => ctrans('texts.logo')]; $data['$company_logo'] = &$data['$company.logo']; + + $data['$company.logo_url'] = ['value' => $logo_url ?: ' ', 'label' => ctrans('texts.logo')]; + $data['$company1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company1')]; $data['$company2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company2', $this->settings->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company2')]; $data['$company3'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company3', $this->settings->custom_value3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company3')];