2020-04-12 13:51:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
use App\Utils\TempFile;
|
2020-04-12 13:51:27 +02:00
|
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
|
|
class BaseNotification extends Notification implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
use MakesInvoiceHtml;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
|
|
|
{
|
|
|
|
return ['mail'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
|
*/
|
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
|
|
|
return (new MailMessage)
|
|
|
|
->line('The introduction to the notification.')
|
|
|
|
->action('Notification Action', url('/'))
|
|
|
|
->line('Thank you for using our application!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the array representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($notifiable)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildMailMessageSettings(MailMessage $mail_message) :MailMessage
|
|
|
|
{
|
|
|
|
$mail_message->subject($this->generateEmailEntityHtml($this->entity, $this->subject, $this->contact));
|
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
if (strlen($this->settings->reply_to_email) > 1) {
|
2020-04-12 13:51:27 +02:00
|
|
|
$mail_message->replyTo($this->settings->reply_to_email);
|
2020-04-15 02:30:52 +02:00
|
|
|
}
|
2020-04-12 13:51:27 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
if (strlen($this->settings->bcc_email) > 1) {
|
2020-04-12 13:51:27 +02:00
|
|
|
$mail_message->bcc($this->settings->bcc_email);
|
2020-04-15 02:30:52 +02:00
|
|
|
}
|
2020-04-12 13:51:27 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
if ($this->settings->pdf_email_attachment) {
|
2020-04-16 10:41:25 +02:00
|
|
|
$mail_message->attach(TempFile::path($this->invitation->pdf_file_path()), ['as' => basename($this->invitation->pdf_file_path())]);
|
2020-04-15 02:30:52 +02:00
|
|
|
}
|
2020-04-12 13:51:27 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
foreach ($this->entity->documents as $document) {
|
2020-04-16 10:41:25 +02:00
|
|
|
$mail_message->attach(TempFile::path($document->generateUrl()), ['as' => $document->name]);
|
2020-04-12 13:51:27 +02:00
|
|
|
}
|
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
if ($this->entity instanceof Invoice && $this->settings->ubl_email_attachment) {
|
2020-04-12 13:51:27 +02:00
|
|
|
$ubl_string = CreateUbl::dispatchNow($this->entity);
|
|
|
|
$mail_message->attachData($ubl_string, $this->entity->getFileName('xml'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
return $mail_message->withSwiftMessage(function ($message) {
|
|
|
|
$message->getHeaders()->addTextHeader('Tag', $this->invitation->company->company_key);
|
|
|
|
});
|
2020-04-12 13:51:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildMailMessageData() :array
|
|
|
|
{
|
|
|
|
$body = $this->generateEmailEntityHtml($this->entity, $this->body, $this->contact);
|
|
|
|
|
|
|
|
$design_style = $this->settings->email_style;
|
|
|
|
|
|
|
|
if ($design_style == 'custom') {
|
|
|
|
$email_style_custom = $this->settings->email_style_custom;
|
2020-04-15 02:30:52 +02:00
|
|
|
$body = strtr($email_style_custom, "$body", $body);
|
2020-04-12 13:51:27 +02:00
|
|
|
}
|
2020-07-29 04:13:12 +02:00
|
|
|
|
2020-04-12 13:51:27 +02:00
|
|
|
$data = [
|
|
|
|
'body' => $body,
|
|
|
|
'design' => $design_style,
|
|
|
|
'footer' => '',
|
|
|
|
'title' => '',
|
|
|
|
'settings' => '',
|
|
|
|
'company' => '',
|
2020-04-16 10:41:25 +02:00
|
|
|
'view_link' => $this->invitation->getLink(),
|
|
|
|
'view_text' => ctrans('texts.view_'.$this->entity_string),
|
2020-04-12 13:51:27 +02:00
|
|
|
'logo' => $this->entity->company->present()->logo(),
|
2020-04-16 10:41:25 +02:00
|
|
|
'signature' => $this->settings->email_signature,
|
2020-04-12 13:51:27 +02:00
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2020-07-29 04:13:12 +02:00
|
|
|
|
|
|
|
public function getTemplateView()
|
|
|
|
{
|
|
|
|
|
|
|
|
switch ($this->settings->email_style) {
|
|
|
|
case 'plain':
|
|
|
|
return 'email.template.plain';
|
|
|
|
break;
|
|
|
|
case 'custom':
|
|
|
|
return 'email.template.custom';
|
|
|
|
break;
|
2020-08-02 11:59:32 +02:00
|
|
|
case 'light':
|
|
|
|
return 'email.template.light';
|
|
|
|
break;
|
|
|
|
case 'dark':
|
|
|
|
return 'email.template.dark';
|
|
|
|
break;
|
2020-07-29 04:13:12 +02:00
|
|
|
default:
|
|
|
|
return 'email.admin.generic_email';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
}
|