mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 13:42:49 +01:00
6d5d1da472
* Client and System Notifications * Fix for group settings currency not applying correctly. * Split head out of design in order to reuse headers and footers * export the designs * Fixes for pdf_variables
125 lines
3.3 KiB
PHP
125 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications\Admin;
|
|
|
|
use App\Utils\Number;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class InvoiceViewedNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
|
|
protected $invitation;
|
|
|
|
protected $invoice;
|
|
|
|
protected $company;
|
|
|
|
protected $settings;
|
|
|
|
public $is_system;
|
|
|
|
protected $contact;
|
|
|
|
public function __construct($invitation, $company, $is_system = false, $settings = null)
|
|
{
|
|
$this->invoice = $invitation->invoice;
|
|
$this->contact = $invitation->contact;
|
|
$this->company = $company;
|
|
$this->settings = $invoice->client->getMergedSettings();
|
|
$this->is_system = $is_system;
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return array
|
|
*/
|
|
public function via($notifiable)
|
|
{
|
|
|
|
return $this->is_system ? ['slack'] : ['mail'];
|
|
}
|
|
|
|
/**
|
|
* Get the mail representation of the notification.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
*/
|
|
public function toMail($notifiable)
|
|
{
|
|
|
|
$amount = Number::formatMoney($this->invoice->amount, $this->invoice->client);
|
|
$subject = ctrans('texts.notification_invoice_viewed_subject',
|
|
[
|
|
'client' => $this->contact->present()->name(),
|
|
'invoice' => $this->invoice->number,
|
|
]);
|
|
|
|
$data = [
|
|
'title' => $subject,
|
|
'message' => ctrans('texts.notification_invoice_viewed',
|
|
[
|
|
'amount' => $amount,
|
|
'client' => $this->contact->present()->name(),
|
|
'invoice' => $this->invoice->number,
|
|
]),
|
|
'url' => config('ninja.site_url') . '/invoices/' . $this->invoice->hashed_id,
|
|
'button' => ctrans('texts.view_invoice'),
|
|
'signature' => $this->settings->email_signature,
|
|
'logo' => $this->company->present()->logo(),
|
|
];
|
|
|
|
|
|
return (new MailMessage)
|
|
->subject($subject)
|
|
->markdown('email.admin.generic', $data);
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification.
|
|
*
|
|
* @param mixed $notifiable
|
|
* @return array
|
|
*/
|
|
public function toArray($notifiable)
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public function toSlack($notifiable)
|
|
{
|
|
$logo = $this->company->present()->logo();
|
|
$amount = Number::formatMoney($this->invoice->amount, $this->invoice->client);
|
|
|
|
return (new SlackMessage)
|
|
->success()
|
|
->from(ctrans('texts.notification_bot'))
|
|
->image($logo)
|
|
->content(ctrans('texts.notification_invoice_viewed',
|
|
[
|
|
'amount' => $amount,
|
|
'client' => $this->contact->present()->name(),
|
|
'invoice' => $this->invoice->number
|
|
]));
|
|
|
|
}
|
|
|
|
}
|