99 lines
2.3 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;
2021-04-16 00:59:43 +03:00
use App\Models\Common\EmailTemplate;
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
*
* @var object
*/
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
*
2019-11-16 10:21:14 +03:00
* @var string
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
*
2019-11-16 10:21:14 +03:00
* @param object $bill
* @param object $template
2017-09-14 22:21:00 +03:00
*/
2019-11-16 10:21:14 +03:00
public function __construct($bill = null, $template = null)
2017-09-14 22:21:00 +03:00
{
2019-11-16 10:21:14 +03:00
parent::__construct();
$this->bill = $bill;
2021-04-16 00:59:43 +03:00
$this->template = EmailTemplate::alias($template)->first();
2017-09-14 22:21:00 +03:00
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
2019-11-16 10:21:14 +03:00
$message = $this->initMessage();
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
* @return array
*/
public function toArray($notifiable)
{
return [
'bill_id' => $this->bill->id,
'amount' => $this->bill->amount,
];
}
2019-11-16 10:21:14 +03:00
public function getTags()
{
return [
'{bill_number}',
'{bill_total}',
2021-01-22 14:24:53 +03:00
'{bill_amount_due}',
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
];
}
public function getTagsReplacement()
{
return [
2021-01-22 14:24:53 +03:00
$this->bill->document_number,
2019-11-16 10:21:14 +03:00
money($this->bill->amount, $this->bill->currency_code, true),
2021-01-22 14:24:53 +03:00
money($this->bill->amount_due, $this->bill->currency_code, true),
2020-02-01 00:14:36 +03:00
company_date($this->bill->due_at),
2019-11-16 10:21:14 +03:00
route('bills.show', $this->bill->id),
$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
}