2020-03-11 12:05:05 +01:00
|
|
|
<?php
|
2020-09-21 12:54:58 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-21 12:54:58 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-21 12:54:58 +02:00
|
|
|
*/
|
2020-03-11 12:05:05 +01:00
|
|
|
|
|
|
|
namespace App\Notifications\Admin;
|
|
|
|
|
|
|
|
use App\Utils\Number;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
2021-02-15 06:08:05 +01:00
|
|
|
//@deprecated
|
2021-02-18 11:33:54 +01:00
|
|
|
class EntitySentNotification extends Notification
|
2020-03-11 12:05:05 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $invitation;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $entity;
|
2020-03-11 12:05:05 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $entity_name;
|
2020-03-11 12:05:05 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $settings;
|
2020-03-11 12:05:05 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public $is_system;
|
2020-03-11 12:05:05 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public $method;
|
2020-03-11 12:05:05 +01:00
|
|
|
|
|
|
|
protected $contact;
|
|
|
|
|
|
|
|
protected $company;
|
|
|
|
|
|
|
|
public function __construct($invitation, $entity_name, $is_system = false, $settings = null)
|
|
|
|
{
|
|
|
|
$this->invitation = $invitation;
|
|
|
|
$this->entity_name = $entity_name;
|
|
|
|
$this->entity = $invitation->{$entity_name};
|
|
|
|
$this->contact = $invitation->contact;
|
|
|
|
$this->company = $invitation->company;
|
|
|
|
$this->settings = $this->entity->client->getMergedSettings();
|
|
|
|
$this->is_system = $is_system;
|
|
|
|
$this->method = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
|
|
|
{
|
|
|
|
return $this->method ?: [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return MailMessage
|
2020-03-11 12:05:05 +01:00
|
|
|
*/
|
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the array representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($notifiable)
|
|
|
|
{
|
2021-02-15 11:52:50 +01:00
|
|
|
return [];
|
2020-03-11 12:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function toSlack($notifiable)
|
|
|
|
{
|
|
|
|
$logo = $this->invitation->company->present()->logo();
|
|
|
|
$amount = Number::formatMoney($this->entity->amount, $this->entity->client);
|
|
|
|
|
|
|
|
return (new SlackMessage)
|
|
|
|
->from(ctrans('texts.notification_bot'))
|
|
|
|
->success()
|
|
|
|
->image('https://app.invoiceninja.com/favicon-v2.png')
|
2020-03-21 06:37:30 +01:00
|
|
|
->content(trans(
|
|
|
|
"texts.notification_{$this->entity_name}_sent_subject",
|
|
|
|
[
|
2022-06-21 11:57:17 +02:00
|
|
|
'amount' => $amount,
|
|
|
|
'client' => $this->contact->client->present()->name(),
|
|
|
|
'invoice' => $this->entity->number,
|
|
|
|
]
|
2020-03-21 06:37:30 +01:00
|
|
|
))
|
|
|
|
->attachment(function ($attachment) use ($amount) {
|
2020-03-11 12:05:05 +01:00
|
|
|
$attachment->title(ctrans('texts.invoice_number_placeholder', ['invoice' => $this->entity->number]), $this->invitation->getAdminLink())
|
|
|
|
->fields([
|
2022-06-21 11:57:17 +02:00
|
|
|
ctrans('texts.client') => $this->contact->client->present()->name(),
|
|
|
|
ctrans('texts.amount') => $amount,
|
|
|
|
]);
|
2020-03-11 12:05:05 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|