2022-06-10 09:04:16 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-06-10 09:04:16 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Mail;
|
|
|
|
|
|
|
|
use App\Models\VendorContact;
|
2023-10-18 08:28:10 +02:00
|
|
|
use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Utils\Ninja;
|
|
|
|
use App\Utils\VendorHtmlEngine;
|
|
|
|
use Illuminate\Mail\Mailable;
|
2022-06-10 09:04:16 +02:00
|
|
|
|
|
|
|
class VendorTemplateEmail extends Mailable
|
|
|
|
{
|
|
|
|
private $build_email;
|
|
|
|
|
|
|
|
private $vendor;
|
|
|
|
|
|
|
|
private $contact;
|
|
|
|
|
|
|
|
private $company;
|
|
|
|
|
|
|
|
private $invitation;
|
|
|
|
|
|
|
|
public function __construct($build_email, VendorContact $contact, $invitation = null)
|
|
|
|
{
|
|
|
|
$this->build_email = $build_email;
|
|
|
|
|
|
|
|
$this->contact = $contact;
|
|
|
|
|
|
|
|
$this->vendor = $contact->vendor;
|
|
|
|
|
|
|
|
$this->company = $contact->company;
|
|
|
|
|
|
|
|
$this->invitation = $invitation;
|
|
|
|
}
|
|
|
|
|
2023-02-09 05:08:53 +01:00
|
|
|
/**
|
2023-02-16 02:36:09 +01:00
|
|
|
* Supports inline attachments for large
|
2023-02-09 05:08:53 +01:00
|
|
|
* attachments in custom designs
|
2023-02-16 02:36:09 +01:00
|
|
|
*
|
2023-02-09 05:08:53 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function buildLinksForCustomDesign(): string
|
|
|
|
{
|
|
|
|
$links = $this->build_email->getAttachmentLinks();
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if (count($links) == 0) {
|
2023-02-09 05:08:53 +01:00
|
|
|
return '';
|
2023-02-16 02:36:09 +01:00
|
|
|
}
|
2023-02-09 05:08:53 +01:00
|
|
|
|
|
|
|
$link_string = '<ul>';
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
foreach ($this->build_email->getAttachmentLinks() as $link) {
|
2023-02-09 05:08:53 +01:00
|
|
|
$link_string .= "<li>{$link}</li>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$link_string .= '</ul>';
|
|
|
|
|
|
|
|
return $link_string;
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2022-06-10 09:04:16 +02:00
|
|
|
public function build()
|
|
|
|
{
|
|
|
|
$template_name = 'email.template.'.$this->build_email->getTemplate();
|
|
|
|
|
|
|
|
if ($this->build_email->getTemplate() == 'light' || $this->build_email->getTemplate() == 'dark') {
|
2024-02-13 07:10:36 +01:00
|
|
|
$template_name = $this->company->account->isPremium() ? 'email.template.client_premium' : 'email.template.client';
|
2022-06-10 09:04:16 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($this->build_email->getTemplate() == 'custom') {
|
2023-02-09 05:08:53 +01:00
|
|
|
$this->build_email->setBody(str_replace('$body', $this->build_email->getBody().$this->buildLinksForCustomDesign(), $this->company->getSetting('email_style_custom')));
|
2022-06-10 09:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$settings = $this->company->settings;
|
|
|
|
|
|
|
|
if ($this->build_email->getTemplate() !== 'custom') {
|
|
|
|
$this->build_email->setBody(
|
|
|
|
DesignHelpers::parseMarkdownToHtml($this->build_email->getBody())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($this->invitation) {
|
2022-06-10 09:04:16 +02:00
|
|
|
$html_variables = (new VendorHtmlEngine($this->invitation))->makeValues();
|
|
|
|
$signature = str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature);
|
2022-06-21 11:57:17 +02:00
|
|
|
} else {
|
2022-06-10 09:04:16 +02:00
|
|
|
$signature = $settings->email_signature;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-06-10 09:04:16 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (property_exists($settings, 'email_from_name') && strlen($settings->email_from_name) > 1) {
|
2022-06-10 09:04:16 +02:00
|
|
|
$email_from_name = $settings->email_from_name;
|
2022-06-21 11:57:17 +02:00
|
|
|
} else {
|
2022-06-10 09:04:16 +02:00
|
|
|
$email_from_name = $this->company->present()->name();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-06-10 09:04:16 +02:00
|
|
|
|
|
|
|
$this->from(config('mail.from.address'), $email_from_name);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (strlen($settings->bcc_email) > 1) {
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-10-18 08:28:10 +02:00
|
|
|
if (Ninja::isHosted()) {
|
|
|
|
|
|
|
|
if($this->company->account->isPaid()) {
|
|
|
|
$bccs = explode(',', str_replace(' ', '', $settings->bcc_email));
|
|
|
|
$this->bcc(array_slice($bccs, 0, 5));
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->bcc(explode(',', str_replace(' ', '', $settings->bcc_email)));
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-10-18 08:28:10 +02:00
|
|
|
}
|
2022-06-10 09:04:16 +02:00
|
|
|
|
|
|
|
$this->subject($this->build_email->getSubject())
|
|
|
|
->text('email.template.text', [
|
|
|
|
'text_body' => $this->build_email->getTextBody(),
|
|
|
|
'whitelabel' => $this->vendor->user->account->isPaid() ? true : false,
|
|
|
|
'settings' => $settings,
|
|
|
|
])
|
|
|
|
->view($template_name, [
|
|
|
|
'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]),
|
|
|
|
'body' => $this->build_email->getBody(),
|
|
|
|
'footer' => $this->build_email->getFooter(),
|
|
|
|
'view_link' => $this->build_email->getViewLink(),
|
|
|
|
'view_text' => $this->build_email->getViewText(),
|
|
|
|
'title' => '',
|
|
|
|
'signature' => $signature,
|
|
|
|
'settings' => $settings,
|
|
|
|
'company' => $this->company,
|
|
|
|
'whitelabel' => $this->vendor->user->account->isPaid() ? true : false,
|
|
|
|
'logo' => $this->company->present()->logo($settings),
|
2023-02-02 23:56:58 +01:00
|
|
|
'links' => $this->build_email->getAttachmentLinks(),
|
2022-08-07 09:34:23 +02:00
|
|
|
]);
|
2022-11-30 06:37:20 +01:00
|
|
|
|
2022-06-10 09:04:16 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
foreach ($this->build_email->getAttachments() as $file) {
|
2023-02-16 02:36:09 +01:00
|
|
|
if (array_key_exists('file', $file)) {
|
2022-12-04 07:37:31 +01:00
|
|
|
$this->attachData(base64_decode($file['file']), $file['name']);
|
2023-02-16 02:36:09 +01:00
|
|
|
} else {
|
2022-12-04 07:37:31 +01:00
|
|
|
$this->attach($file['path'], ['as' => $file['name'], 'mime' => null]);
|
2023-02-16 02:36:09 +01:00
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-06-10 09:04:16 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|