akaunting 3.0 (the last dance)
This commit is contained in:
@ -3,9 +3,12 @@
|
||||
namespace App\Notifications\Sale;
|
||||
|
||||
use App\Abstracts\Notification;
|
||||
use App\Models\Common\EmailTemplate;
|
||||
use App\Models\Setting\EmailTemplate;
|
||||
use App\Models\Document\Document;
|
||||
use App\Traits\Documents;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Invoice extends Notification
|
||||
{
|
||||
@ -21,7 +24,7 @@ class Invoice extends Notification
|
||||
/**
|
||||
* The email template.
|
||||
*
|
||||
* @var \App\Models\Common\EmailTemplate
|
||||
* @var EmailTemplate
|
||||
*/
|
||||
public $template;
|
||||
|
||||
@ -34,29 +37,29 @@ class Invoice extends Notification
|
||||
|
||||
/**
|
||||
* Create a notification instance.
|
||||
*
|
||||
* @param object $invoice
|
||||
* @param object $template_alias
|
||||
* @param object $attach_pdf
|
||||
*/
|
||||
public function __construct($invoice = null, $template_alias = null, $attach_pdf = false)
|
||||
public function __construct(Document $invoice = null, string $template_alias = null, bool $attach_pdf = false, array $custom_mail = [])
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->invoice = $invoice;
|
||||
$this->template = EmailTemplate::alias($template_alias)->first();
|
||||
$this->attach_pdf = $attach_pdf;
|
||||
$this->custom_mail = $custom_mail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
public function toMail($notifiable): MailMessage
|
||||
{
|
||||
$message = $this->initMessage();
|
||||
if (!empty($this->custom_mail['to'])) {
|
||||
$notifiable->email = $this->custom_mail['to'];
|
||||
}
|
||||
|
||||
$message = $this->initMailMessage();
|
||||
|
||||
// Attach the PDF file
|
||||
if ($this->attach_pdf) {
|
||||
@ -72,12 +75,13 @@ class Invoice extends Notification
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
public function toArray($notifiable): array
|
||||
{
|
||||
return [
|
||||
'template_alias' => $this->template->alias,
|
||||
'title' => trans('notifications.menu.' . $this->template->alias . '.title'),
|
||||
'description' => trans('notifications.menu.' . $this->template->alias . '.description', $this->getTagsBinding()),
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'invoice_number' => $this->invoice->document_number,
|
||||
'customer_name' => $this->invoice->contact_name,
|
||||
@ -88,7 +92,7 @@ class Invoice extends Notification
|
||||
];
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
public function getTags(): array
|
||||
{
|
||||
return [
|
||||
'{invoice_number}',
|
||||
@ -108,7 +112,7 @@ class Invoice extends Notification
|
||||
];
|
||||
}
|
||||
|
||||
public function getTagsReplacement()
|
||||
public function getTagsReplacement(): array
|
||||
{
|
||||
return [
|
||||
$this->invoice->document_number,
|
||||
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Sale;
|
||||
|
||||
use App\Abstracts\Notification;
|
||||
use App\Models\Common\EmailTemplate;
|
||||
use App\Traits\Transactions;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class Revenue extends Notification
|
||||
{
|
||||
use Transactions;
|
||||
|
||||
/**
|
||||
* The revenue model.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $revenue;
|
||||
|
||||
/**
|
||||
* The email template.
|
||||
*
|
||||
* @var \App\Models\Common\EmailTemplate
|
||||
*/
|
||||
public $template;
|
||||
|
||||
/**
|
||||
* Should attach pdf or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $attach_pdf;
|
||||
|
||||
/**
|
||||
* Create a notification instance.
|
||||
*
|
||||
* @param object $revenue
|
||||
* @param object $template_alias
|
||||
* @param object $attach_pdf
|
||||
*/
|
||||
public function __construct($revenue = null, $template_alias = null, $attach_pdf = false)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->revenue = $revenue;
|
||||
$this->template = EmailTemplate::alias($template_alias)->first();
|
||||
$this->attach_pdf = $attach_pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$message = $this->initMessage();
|
||||
|
||||
// Attach the PDF file
|
||||
if ($this->attach_pdf) {
|
||||
$message->attach($this->storeTransactionPdfAndGetPath($this->revenue), [
|
||||
'mime' => 'application/pdf',
|
||||
]);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'template_alias' => $this->template->alias,
|
||||
'revenue_id' => $this->revenue->id,
|
||||
'customer_name' => $this->revenue->contact->name,
|
||||
'amount' => $this->revenue->amount,
|
||||
'revenue_date' => company_date($this->revenue->paid_at),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
{
|
||||
return [
|
||||
'{revenue_amount}',
|
||||
'{revenue_date}',
|
||||
'{revenue_guest_link}',
|
||||
'{revenue_admin_link}',
|
||||
'{revenue_portal_link}',
|
||||
'{customer_name}',
|
||||
'{company_name}',
|
||||
'{company_email}',
|
||||
'{company_tax_number}',
|
||||
'{company_phone}',
|
||||
'{company_address}',
|
||||
];
|
||||
}
|
||||
|
||||
public function getTagsReplacement()
|
||||
{
|
||||
return [
|
||||
money($this->revenue->amount, $this->revenue->currency_code, true),
|
||||
company_date($this->revenue->paid_at),
|
||||
URL::signedRoute('signed.payments.show', [$this->revenue->id]),
|
||||
route('revenues.show', $this->revenue->id),
|
||||
route('portal.payments.show', $this->revenue->id),
|
||||
$this->revenue->contact->name,
|
||||
$this->revenue->company->name,
|
||||
$this->revenue->company->email,
|
||||
$this->revenue->company->tax_number,
|
||||
$this->revenue->company->phone,
|
||||
nl2br(trim($this->revenue->company->address)),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user