feat: complete administration and reporting
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Domain\Administration\Services\NotificationTemplateService;
|
||||
use App\Domain\Reservations\Models\Reservation;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@@ -28,10 +29,11 @@ class ReservationDecisionNotification extends Notification implements ShouldQueu
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$template = $this->template();
|
||||
$message = (new MailMessage)
|
||||
->subject($this->subject())
|
||||
->subject($template['subject'])
|
||||
->greeting("Atualização da requisição {$this->reservation->reference}")
|
||||
->line($this->message());
|
||||
->line($template['message']);
|
||||
|
||||
if (filled($this->comment)) {
|
||||
$message->line("Comentário: {$this->comment}");
|
||||
@@ -43,35 +45,21 @@ class ReservationDecisionNotification extends Notification implements ShouldQueu
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
$template = $this->template();
|
||||
|
||||
return [
|
||||
'reservation_uuid' => $this->reservation->uuid,
|
||||
'reference' => $this->reservation->reference,
|
||||
'event' => $this->event,
|
||||
'message' => $this->message(),
|
||||
'message' => $template['message'],
|
||||
'comment' => $this->comment,
|
||||
'url' => '/requisicoes',
|
||||
];
|
||||
}
|
||||
|
||||
private function subject(): string
|
||||
/** @return array{subject:string,message:string} */
|
||||
private function template(): array
|
||||
{
|
||||
return match ($this->event) {
|
||||
'approved' => "Requisição {$this->reservation->reference} aprovada",
|
||||
'rejected' => "Requisição {$this->reservation->reference} rejeitada",
|
||||
'information_requested' => "Esclarecimentos necessários para {$this->reservation->reference}",
|
||||
'asset_substituted' => "Equipamento alterado em {$this->reservation->reference}",
|
||||
default => "Atualização da requisição {$this->reservation->reference}",
|
||||
};
|
||||
}
|
||||
|
||||
private function message(): string
|
||||
{
|
||||
return match ($this->event) {
|
||||
'approved' => 'A sua requisição foi aprovada.',
|
||||
'rejected' => 'A sua requisição foi rejeitada.',
|
||||
'information_requested' => 'O aprovador pediu informações adicionais.',
|
||||
'asset_substituted' => 'Um equipamento da sua requisição foi substituído por outro equivalente.',
|
||||
default => 'O estado da sua requisição foi atualizado.',
|
||||
};
|
||||
return app(NotificationTemplateService::class)->render($this->event, $this->reservation, $this->comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Domain\Administration\Services\NotificationTemplateService;
|
||||
use App\Domain\Reservations\Models\Reservation;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@@ -27,28 +28,27 @@ class ReservationSubmittedNotification extends Notification implements ShouldQue
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$template = app(NotificationTemplateService::class)->render($this->event, $this->reservation);
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($this->event === 'information_provided'
|
||||
? "Resposta recebida para {$this->reservation->reference}"
|
||||
: "Nova requisição {$this->reservation->reference}")
|
||||
->subject($template['subject'])
|
||||
->greeting($this->event === 'information_provided'
|
||||
? 'O requisitante respondeu ao pedido de esclarecimentos'
|
||||
: 'Nova requisição para aprovação')
|
||||
->line("{$this->reservation->requester->name} submeteu a requisição {$this->reservation->reference} para decisão.")
|
||||
->line("Período: {$this->reservation->starts_at->format('d/m/Y H:i')} — {$this->reservation->ends_at->format('d/m/Y H:i')}.")
|
||||
->line($template['message'])
|
||||
->action('Analisar requisição', url('/aprovacoes'));
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
$template = app(NotificationTemplateService::class)->render($this->event, $this->reservation);
|
||||
|
||||
return [
|
||||
'reservation_uuid' => $this->reservation->uuid,
|
||||
'reference' => $this->reservation->reference,
|
||||
'event' => $this->event,
|
||||
'message' => $this->event === 'information_provided'
|
||||
? "Foram prestados esclarecimentos para {$this->reservation->reference}."
|
||||
: "Nova requisição {$this->reservation->reference} aguarda decisão.",
|
||||
'message' => $template['message'],
|
||||
'url' => '/aprovacoes',
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user