114 lines
3.1 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
2019-12-31 15:49:09 +03:00
namespace App\Notifications\Purchase;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
use App\Abstracts\Notification;
2022-06-01 10:15:55 +03:00
use App\Models\Setting\EmailTemplate;
use App\Models\Document\Document;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Str;
2017-09-14 22:21:00 +03:00
2017-11-17 00:37:26 +03:00
class Bill extends Notification
2017-09-14 22:21:00 +03:00
{
2017-11-17 00:37:26 +03:00
/**
2019-11-16 10:21:14 +03:00
* The bill model.
2017-11-17 00:37:26 +03:00
*
2022-06-01 10:15:55 +03:00
* @var Document
2017-11-17 00:37:26 +03:00
*/
2017-09-14 22:21:00 +03:00
public $bill;
/**
2019-11-16 10:21:14 +03:00
* The email template.
2017-09-14 22:21:00 +03:00
*
2022-06-01 10:15:55 +03:00
* @var EmailTemplate
2017-09-14 22:21:00 +03:00
*/
2019-11-16 10:21:14 +03:00
public $template;
2017-09-14 22:21:00 +03:00
/**
2019-11-16 10:21:14 +03:00
* Create a notification instance.
2017-09-14 22:21:00 +03:00
*/
2022-06-01 10:15:55 +03:00
public function __construct(Document $bill = null, string $template_alias = null)
2017-09-14 22:21:00 +03:00
{
2019-11-16 10:21:14 +03:00
parent::__construct();
$this->bill = $bill;
2021-04-29 18:12:37 +03:00
$this->template = EmailTemplate::alias($template_alias)->first();
2017-09-14 22:21:00 +03:00
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
*/
2022-06-01 10:15:55 +03:00
public function toMail($notifiable): MailMessage
2017-09-14 22:21:00 +03:00
{
2022-06-01 10:15:55 +03:00
$message = $this->initMailMessage();
2018-02-25 19:00:31 +03:00
return $message;
2017-09-14 22:21:00 +03:00
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*/
2022-06-01 10:15:55 +03:00
public function toArray($notifiable): array
2017-09-14 22:21:00 +03:00
{
$this->initArrayMessage();
2017-09-14 22:21:00 +03:00
return [
2021-06-19 18:16:09 +03:00
'template_alias' => $this->template->alias,
2022-06-01 10:15:55 +03:00
'title' => trans('notifications.menu.' . $this->template->alias . '.title'),
'description' => trans('notifications.menu.' . $this->template->alias . '.description', $this->getTagsBinding()),
2017-09-14 22:21:00 +03:00
'bill_id' => $this->bill->id,
2021-06-19 18:16:09 +03:00
'bill_number' => $this->bill->document_number,
'vendor_name' => $this->bill->contact_name,
2017-09-14 22:21:00 +03:00
'amount' => $this->bill->amount,
2021-06-19 18:16:09 +03:00
'billed_date' => company_date($this->bill->issued_at),
'bill_due_date' => company_date($this->bill->due_at),
'status' => $this->bill->status,
2017-09-14 22:21:00 +03:00
];
}
2019-11-16 10:21:14 +03:00
2022-06-01 10:15:55 +03:00
public function getTags(): array
2019-11-16 10:21:14 +03:00
{
return [
'{bill_number}',
'{bill_total}',
2021-01-22 14:24:53 +03:00
'{bill_amount_due}',
2021-06-19 18:16:09 +03:00
'{billed_date}',
2019-11-16 10:21:14 +03:00
'{bill_due_date}',
'{bill_admin_link}',
'{vendor_name}',
'{company_name}',
'{company_email}',
'{company_tax_number}',
'{company_phone}',
'{company_address}',
2019-11-16 10:21:14 +03:00
];
}
2022-06-01 10:15:55 +03:00
public function getTagsReplacement(): array
2019-11-16 10:21:14 +03:00
{
2023-03-22 01:33:33 +03:00
$route_params = [
'company_id' => $this->bill->company_id,
'bill' => $this->bill->id,
];
2019-11-16 10:21:14 +03:00
return [
2021-01-22 14:24:53 +03:00
$this->bill->document_number,
money($this->bill->amount, $this->bill->currency_code),
money($this->bill->amount_due, $this->bill->currency_code),
company_date($this->bill->issued_at),
2020-02-01 00:14:36 +03:00
company_date($this->bill->due_at),
2023-03-22 01:33:33 +03:00
route('bills.show', $route_params),
2019-11-16 10:21:14 +03:00
$this->bill->contact_name,
$this->bill->company->name,
$this->bill->company->email,
$this->bill->company->tax_number,
$this->bill->company->phone,
nl2br(trim($this->bill->company->address)),
2019-11-16 10:21:14 +03:00
];
}
2017-09-14 22:21:00 +03:00
}