2020-03-03 10:44:26 +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-03 10:44:26 +01:00
|
|
|
|
2020-03-04 12:09:43 +01:00
|
|
|
namespace App\Notifications\Admin;
|
2020-03-03 10:44:26 +01:00
|
|
|
|
|
|
|
use App\Utils\Number;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
2021-02-18 11:33:54 +01:00
|
|
|
class EntityViewedNotification extends Notification
|
2020-03-03 10:44:26 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @return void
|
2020-03-04 12:09:43 +01:00
|
|
|
* @
|
2020-03-03 10:44:26 +01:00
|
|
|
*/
|
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_name;
|
2020-03-04 12:09:43 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $entity;
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $company;
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $settings;
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public $method;
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
protected $contact;
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-03-04 12:09:43 +01:00
|
|
|
public function __construct($invitation, $entity_name, $is_system = false, $settings = null)
|
2020-03-03 10:44:26 +01:00
|
|
|
{
|
2020-03-05 08:14:57 +01:00
|
|
|
$this->entity_name = $entity_name;
|
2020-03-04 12:09:43 +01:00
|
|
|
$this->entity = $invitation->{$entity_name};
|
2020-03-03 10:44:26 +01:00
|
|
|
$this->contact = $invitation->contact;
|
2020-03-04 12:09:43 +01:00
|
|
|
$this->company = $invitation->company;
|
2020-10-21 11:24:33 +02:00
|
|
|
$this->settings = $invitation->contact->client->getMergedSettings();
|
2020-03-03 10:44:26 +01:00
|
|
|
$this->is_system = $is_system;
|
2020-03-05 09:36:52 +01:00
|
|
|
$this->invitation = $invitation;
|
2020-03-10 23:20:09 +01:00
|
|
|
$this->method = null;
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
|
|
|
{
|
2020-03-10 23:20:09 +01:00
|
|
|
return $this->method ?: [];
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return MailMessage
|
2020-03-03 10:44:26 +01:00
|
|
|
*/
|
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
2020-03-04 12:09:43 +01:00
|
|
|
$amount = Number::formatMoney($this->entity->amount, $this->entity->client);
|
2020-03-03 10:44:26 +01:00
|
|
|
|
|
|
|
return (new SlackMessage)
|
2020-03-05 08:14:57 +01:00
|
|
|
->from(ctrans('texts.notification_bot'))
|
|
|
|
->success()
|
|
|
|
->image('https://app.invoiceninja.com/favicon-v2.png')
|
2020-03-21 06:37:30 +01:00
|
|
|
->content(ctrans(
|
|
|
|
"texts.notification_{$this->entity_name}_viewed",
|
2020-03-03 10:44:26 +01:00
|
|
|
[
|
2020-03-21 06:37:30 +01:00
|
|
|
'amount' => $amount,
|
|
|
|
'client' => $this->contact->present()->name(),
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->entity_name => $this->entity->number,
|
2020-03-21 06:37:30 +01:00
|
|
|
]
|
|
|
|
))
|
|
|
|
->attachment(function ($attachment) use ($amount) {
|
2020-03-05 08:14:57 +01:00
|
|
|
$attachment->title(ctrans('texts.entity_number_placeholder', ['entity' => ucfirst($this->entity_name), 'entity_number' => $this->entity->number]), $this->invitation->getAdminLink())
|
|
|
|
->fields([
|
2022-06-21 11:57:17 +02:00
|
|
|
ctrans('texts.client') => $this->contact->present()->name(),
|
|
|
|
ctrans('texts.status_viewed') => $this->invitation->viewed_date,
|
|
|
|
]);
|
2020-03-05 08:14:57 +01:00
|
|
|
});
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 12:09:43 +01:00
|
|
|
private function buildDataArray()
|
|
|
|
{
|
|
|
|
$amount = Number::formatMoney($this->entity->amount, $this->entity->client);
|
|
|
|
|
|
|
|
$data = [
|
2020-03-05 09:36:52 +01:00
|
|
|
'title' => $this->buildSubject(),
|
2020-03-21 06:37:30 +01:00
|
|
|
'message' => ctrans(
|
|
|
|
"texts.notification_{$this->entity_name}_viewed",
|
2020-03-04 12:09:43 +01:00
|
|
|
[
|
2020-03-21 06:37:30 +01:00
|
|
|
'amount' => $amount,
|
|
|
|
'client' => $this->contact->present()->name(),
|
2020-03-04 12:09:43 +01:00
|
|
|
$this->entity_name => $this->entity->number,
|
2020-03-21 06:37:30 +01:00
|
|
|
]
|
|
|
|
),
|
2020-03-11 12:05:05 +01:00
|
|
|
'url' => $this->invitation->getAdminLink(),
|
2020-03-04 12:09:43 +01:00
|
|
|
'button' => ctrans("texts.view_{$this->entity_name}"),
|
|
|
|
'signature' => $this->settings->email_signature,
|
|
|
|
'logo' => $this->company->present()->logo(),
|
2020-09-27 11:22:34 +02:00
|
|
|
'settings' => $this->settings,
|
|
|
|
|
2020-03-04 12:09:43 +01:00
|
|
|
];
|
|
|
|
|
2020-03-05 08:14:57 +01:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildSubject()
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
$subject = ctrans(
|
|
|
|
"texts.notification_{$this->entity_name}_viewed_subject",
|
|
|
|
[
|
2022-06-21 11:57:17 +02:00
|
|
|
'client' => $this->contact->present()->name(),
|
|
|
|
$this->entity_name => $this->entity->number,
|
|
|
|
]
|
2020-03-21 06:37:30 +01:00
|
|
|
);
|
2020-03-05 08:14:57 +01:00
|
|
|
|
|
|
|
return $subject;
|
2020-03-04 12:09:43 +01:00
|
|
|
}
|
2020-03-03 10:44:26 +01:00
|
|
|
}
|