Files
L-Ami-Fiduciaire/app/Notifications/DeclarationOverdueNotification.php
Saad Zoubir 1d4f3bcd0f feat: add bulk client notifications and email enhancements with review fixes (Stories 3.4 & 3.5)
Story 3-4: Bulk client notification scheduling — BulkNotificationController,
BulkActionBar component, checkbox selection on declarations index.

Story 3-5: Email notification enhancement — observer-driven email on
en_attente_client, cache invalidation on ferme, workspace branding on
all email templates, 11 feature tests.

Code review fixes:
- Move bulk-notify route above resource wildcard to prevent shadowing
- Add static $suppressEmail flag to prevent observer double-sending
  when DeclarationMessageController already sends the email
- Fix canBulkNotify logic (was granting workers access)
- Add WorkspaceUserRole check to BulkNotifyRequest::authorize()
- Replace firstOrCreate with explicit invitation lookup that syncs
  client email and handles used/expired invitations correctly
- Watch declarations.data instead of current_page to clear selection
  on filter/sort changes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 14:31:36 +01:00

58 lines
1.6 KiB
PHP

<?php
namespace App\Notifications;
use App\Enums\NotificationType;
use App\Models\Declaration;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class DeclarationOverdueNotification extends Notification implements ShouldQueue
{
use Queueable;
public int $tries = 3;
public int $backoff = 60;
public bool $deleteWhenMissingModels = true;
public function __construct(
public Declaration $declaration,
) {}
/**
* @return array<string>
*/
public function via(object $notifiable): array
{
return ['database', 'mail'];
}
/**
* @return array<string, mixed>
*/
public function toDatabase(object $notifiable): array
{
return [
'workspace_id' => $this->declaration->workspace_id,
'declaration_id' => $this->declaration->id,
'notification_type' => NotificationType::DeclarationOverdue,
];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject('Déclaration en retard - '.($this->declaration->title ?? 'Sans titre'))
->markdown('emails.declaration-overdue', [
'declarationTitle' => $this->declaration->title ?? 'Sans titre',
'dueDate' => $this->declaration->due_date?->format('d/m/Y'),
'url' => route('declarations.show', $this->declaration),
'firmName' => $this->declaration->workspace?->name,
]);
}
}