2020-03-29 14:22:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
2020-04-10 07:07:36 +02:00
|
|
|
use App\Jobs\Invoice\CreateUbl;
|
|
|
|
use App\Models\Invoice;
|
2020-03-29 14:22:14 +02:00
|
|
|
use App\Utils\Number;
|
|
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Messages\SlackMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
2020-04-12 13:51:27 +02:00
|
|
|
class SendGenericNotification extends BaseNotification implements ShouldQueue
|
2020-03-29 14:22:14 +02:00
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
use Dispatchable;
|
|
|
|
use SerializesModels;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new notification instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected $invitation;
|
|
|
|
|
|
|
|
protected $entity;
|
|
|
|
|
|
|
|
protected $contact;
|
|
|
|
|
|
|
|
protected $entity_string;
|
|
|
|
|
|
|
|
protected $settings;
|
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
public $is_system;
|
2020-03-29 14:22:14 +02:00
|
|
|
|
|
|
|
protected $body;
|
|
|
|
|
|
|
|
protected $subject;
|
|
|
|
|
|
|
|
public function __construct($invitation, $entity_string, $subject, $body)
|
|
|
|
{
|
|
|
|
$this->entity = $invitation->{$entity_string};
|
|
|
|
$this->contact = $invitation->contact;
|
|
|
|
$this->settings = $this->entity->client->getMergedSettings();
|
|
|
|
$this->subject = $subject;
|
|
|
|
$this->body = $body;
|
2020-04-16 10:41:25 +02:00
|
|
|
$this->invitation = $invitation;
|
|
|
|
$this->entity_string = $entity_string;
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the notification's delivery channels.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function via($notifiable)
|
2020-03-29 14:47:41 +02:00
|
|
|
{
|
|
|
|
return ['mail'];
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mail representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
|
|
|
*/
|
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
2020-04-10 07:07:36 +02:00
|
|
|
$mail_message = (new MailMessage)
|
2020-05-06 13:49:42 +02:00
|
|
|
->withSwiftMessage(function ($message) {
|
|
|
|
$message->getHeaders()->addTextHeader('Tag', $this->invitation->company->company_key);
|
|
|
|
})->markdown('email.admin.generic_email', $this->buildMailMessageData());
|
2020-04-10 07:07:36 +02:00
|
|
|
|
2020-04-12 13:51:27 +02:00
|
|
|
$mail_message = $this->buildMailMessageSettings($mail_message);
|
2020-04-10 07:07:36 +02:00
|
|
|
|
|
|
|
return $mail_message;
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the array representation of the notification.
|
|
|
|
*
|
|
|
|
* @param mixed $notifiable
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($notifiable)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toSlack($notifiable)
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
// $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
|
|
|
|
// ]
|
|
|
|
// ));
|
|
|
|
}
|
|
|
|
}
|