Akaunting/app/Notifications/Sale/Invoice.php

100 lines
2.3 KiB
PHP
Raw Normal View History

2017-09-14 19:21:00 +00:00
<?php
2019-12-31 12:49:09 +00:00
namespace App\Notifications\Sale;
2017-09-14 19:21:00 +00:00
2019-11-16 07:21:14 +00:00
use App\Abstracts\Notification;
use Illuminate\Support\Facades\URL;
2017-09-14 19:21:00 +00:00
2017-11-16 21:37:26 +00:00
class Invoice extends Notification
2017-09-14 19:21:00 +00:00
{
2017-11-16 21:37:26 +00:00
/**
2019-11-16 07:21:14 +00:00
* The invoice model.
2017-11-16 21:37:26 +00:00
*
* @var object
*/
2017-09-14 19:21:00 +00:00
public $invoice;
/**
2019-11-16 07:21:14 +00:00
* The email template.
2017-09-14 19:21:00 +00:00
*
2019-11-16 07:21:14 +00:00
* @var string
2017-09-14 19:21:00 +00:00
*/
2019-11-16 07:21:14 +00:00
public $template;
2017-09-14 19:21:00 +00:00
/**
2019-11-16 07:21:14 +00:00
* Create a notification instance.
2017-09-14 19:21:00 +00:00
*
2019-11-16 07:21:14 +00:00
* @param object $invoice
* @param object $template
2017-09-14 19:21:00 +00:00
*/
2019-11-16 07:21:14 +00:00
public function __construct($invoice = null, $template = null)
2017-09-14 19:21:00 +00:00
{
2019-11-16 07:21:14 +00:00
parent::__construct();
$this->invoice = $invoice;
$this->template = $template;
2017-09-14 19:21:00 +00:00
}
/**
2019-11-16 07:21:14 +00:00
* Get the mail representation of the notification.
2017-09-14 19:21:00 +00:00
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
2019-11-16 07:21:14 +00:00
$message = $this->initMessage();
2018-02-25 16:00:31 +00:00
2017-11-16 17:27:30 +00: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 19:21:00 +00: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 07:21:14 +00: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),
2020-01-31 21:14:36 +00:00
company_date($this->invoice->due_at),
2019-11-16 07:21:14 +00:00
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 19:21:00 +00:00
}