2019-12-10 21:25:54 +01:00
|
|
|
<?php
|
2020-08-06 05:04:09 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-08-06 05:04:09 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-08-06 05:04:09 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
2019-12-10 21:25:54 +01:00
|
|
|
namespace App\Mail;
|
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
use App\Models\Client;
|
2021-02-02 09:51:12 +01:00
|
|
|
use App\Models\ClientContact;
|
2020-02-15 12:49:31 +01:00
|
|
|
use App\Models\User;
|
2019-12-10 21:25:54 +01:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Mail\Mailable;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
class TemplateEmail extends Mailable
|
|
|
|
{
|
|
|
|
use Queueable, SerializesModels;
|
2020-02-15 12:49:31 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
private $build_email;
|
2020-02-15 12:49:31 +01:00
|
|
|
|
|
|
|
private $client;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2021-02-02 06:11:33 +01:00
|
|
|
private $contact;
|
|
|
|
|
|
|
|
public function __construct($build_email, ClientContact $contact)
|
2019-12-10 21:25:54 +01:00
|
|
|
{
|
2020-02-15 10:01:15 +01:00
|
|
|
$this->build_email = $build_email;
|
2020-02-15 12:49:31 +01:00
|
|
|
|
2021-02-02 06:11:33 +01:00
|
|
|
$this->contact = $contact;
|
|
|
|
|
|
|
|
$this->client = $contact->client;
|
2019-12-10 21:25:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the message.
|
|
|
|
*
|
|
|
|
* @return $this
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Laracasts\Presenter\Exceptions\PresenterException
|
2019-12-10 21:25:54 +01:00
|
|
|
*/
|
|
|
|
public function build()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$template_name = 'email.template.'.$this->build_email->getTemplate();
|
2019-12-16 12:34:38 +01:00
|
|
|
|
2020-02-15 12:49:31 +01:00
|
|
|
$settings = $this->client->getMergedSettings();
|
|
|
|
|
|
|
|
$company = $this->client->company;
|
2019-12-16 12:34:38 +01:00
|
|
|
|
2020-12-02 04:08:35 +01:00
|
|
|
$this->from(config('mail.from.address'), config('mail.from.name'));
|
2020-11-12 02:43:32 +01:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (strlen($settings->reply_to_email) > 1) {
|
2020-11-12 02:43:32 +01:00
|
|
|
$this->replyTo($settings->reply_to_email, $settings->reply_to_email);
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-11-12 02:43:32 +01:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
if (strlen($settings->bcc_email) > 1) {
|
2020-11-12 02:43:32 +01:00
|
|
|
$this->bcc($settings->bcc_email, $settings->bcc_email);
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-11-12 02:43:32 +01:00
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
$this->subject($this->build_email->getSubject())
|
2020-02-15 12:49:31 +01:00
|
|
|
->text('email.template.plain', [
|
2020-03-21 06:37:30 +01:00
|
|
|
'body' => $this->build_email->getBody(),
|
2020-09-06 11:38:10 +02:00
|
|
|
'footer' => $this->build_email->getFooter(),
|
2020-10-20 01:37:33 +02:00
|
|
|
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
|
|
|
|
'settings' => $settings,
|
2020-02-15 12:49:31 +01:00
|
|
|
])
|
2019-12-10 21:25:54 +01:00
|
|
|
->view($template_name, [
|
2021-02-02 06:11:33 +01:00
|
|
|
'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]),
|
2020-02-15 10:01:15 +01:00
|
|
|
'body' => $this->build_email->getBody(),
|
|
|
|
'footer' => $this->build_email->getFooter(),
|
2020-04-15 02:30:52 +02:00
|
|
|
'view_link' => $this->build_email->getViewLink(),
|
|
|
|
'view_text' => $this->build_email->getViewText(),
|
2020-11-08 06:21:18 +01:00
|
|
|
'title' => '',
|
2020-04-16 10:41:25 +02:00
|
|
|
'signature' => $settings->email_signature,
|
2019-12-16 12:34:38 +01:00
|
|
|
'settings' => $settings,
|
2020-09-06 11:38:10 +02:00
|
|
|
'company' => $company,
|
2020-09-28 23:54:12 +02:00
|
|
|
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
|
2019-12-10 21:25:54 +01:00
|
|
|
]);
|
|
|
|
|
2020-02-15 12:51:05 +01:00
|
|
|
//conditionally attach files
|
2020-09-06 11:38:10 +02:00
|
|
|
if ($settings->pdf_email_attachment !== false && ! empty($this->build_email->getAttachments())) {
|
2021-01-08 11:19:26 +01:00
|
|
|
|
2021-01-09 05:15:53 +01:00
|
|
|
//hosted | plan check here
|
2020-02-15 12:51:05 +01:00
|
|
|
foreach ($this->build_email->getAttachments() as $file) {
|
2021-01-08 11:19:26 +01:00
|
|
|
|
2021-01-09 05:10:48 +01:00
|
|
|
if(is_string($file))
|
2021-01-08 11:19:26 +01:00
|
|
|
$this->attach($file);
|
2021-01-09 05:10:48 +01:00
|
|
|
elseif(is_array($file))
|
|
|
|
$this->attach($file['path'], ['as' => $file['name'], 'mime' => $file['mime']]);
|
2021-01-08 11:19:26 +01:00
|
|
|
|
2020-02-15 12:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-22 11:28:41 +01:00
|
|
|
|
2020-11-12 02:43:32 +01:00
|
|
|
return $this;
|
2019-12-10 21:25:54 +01:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|