2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications\Income;
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Abstracts\Notification;
|
2017-09-14 22:21:00 +03:00
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
2019-11-16 10:21:14 +03:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2017-11-17 00:37:26 +03:00
|
|
|
class Invoice 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 invoice model.
|
2017-11-17 00:37:26 +03:00
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
2017-09-14 22:21:00 +03:00
|
|
|
public $invoice;
|
|
|
|
|
|
|
|
/**
|
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 $invoice
|
|
|
|
* @param object $template
|
2017-09-14 22:21:00 +03:00
|
|
|
*/
|
2019-11-16 10:21:14 +03:00
|
|
|
public function __construct($invoice = null, $template = null)
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->invoice = $invoice;
|
|
|
|
$this->template = $template;
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-16 10:21:14 +03:00
|
|
|
* Get the mail representation of the notification.
|
2017-09-14 22:21:00 +03:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
2017-11-16 20:27:30 +03:00
|
|
|
// Attach the PDF file if available
|
|
|
|
if (isset($this->invoice->pdf_path)) {
|
|
|
|
$message->attach($this->invoice->pdf_path, [
|
|
|
|
'mime' => 'application/pdf',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 [
|
|
|
|
'invoice_id' => $this->invoice->id,
|
|
|
|
'amount' => $this->invoice->amount,
|
|
|
|
];
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
public function getTags()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'{invoice_number}',
|
|
|
|
'{invoice_total}',
|
|
|
|
'{invoice_due_date}',
|
|
|
|
'{invoice_guest_link}',
|
|
|
|
'{invoice_admin_link}',
|
|
|
|
'{invoice_portal_link}',
|
|
|
|
'{customer_name}',
|
|
|
|
'{company_name}',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTagsReplacement()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
$this->invoice->invoice_number,
|
|
|
|
money($this->invoice->amount, $this->invoice->currency_code, true),
|
|
|
|
$this->invoice->due_at,
|
|
|
|
URL::signedRoute('signed.invoices.show', [$this->invoice->id, 'company_id' => $this->invoice->company_id]),
|
|
|
|
route('invoices.show', $this->invoice->id),
|
|
|
|
route('portal.invoices.show', $this->invoice->id),
|
|
|
|
$this->invoice->contact_name,
|
|
|
|
$this->invoice->company->name
|
|
|
|
];
|
|
|
|
}
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|