52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\ServiceTask;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class ServiceTaskRejectedNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(public ServiceTask $serviceTask, public string $reason)
|
|
{
|
|
}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database', 'mail'];
|
|
}
|
|
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
$agentName = $this->serviceTask->data['agent_name'] ?? 'Agent';
|
|
// Try to fetch agent name if avail
|
|
if ($this->serviceTask->integrationRequest && $this->serviceTask->integrationRequest->agent) {
|
|
$agentName = $this->serviceTask->integrationRequest->agent->first_name . ' ' . $this->serviceTask->integrationRequest->agent->last_name;
|
|
}
|
|
|
|
return (new MailMessage)
|
|
->error()
|
|
->subject("Tâche REJETÉE : {$agentName}")
|
|
->greeting("Bonjour {$notifiable->name},")
|
|
->line("La tâche pour l'agent **{$agentName}** a été rejetée.")
|
|
->line("**Raison du rejet :** {$this->reason}")
|
|
->action('Voir la tâche', route('integrations.show', $this->serviceTask->integrationRequest))
|
|
->line('Merci de corriger les éléments nécessaires puis de valider à nouveau.');
|
|
}
|
|
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
return [
|
|
'service_task_id' => $this->serviceTask->id,
|
|
'integration_request_id' => $this->serviceTask->integration_request_id,
|
|
'message' => "La tâche a été rejetée. Motif : {$this->reason}",
|
|
'type' => 'task_rejected',
|
|
];
|
|
}
|
|
}
|