Faza 2 (din continuare): Email notifications

4 Mailables auto-trigger pe model events:
- WorkOrderReadyMail: la WO.status → 'ready', către client.email
  • Atașat PDF fișa lucru (via WorkOrderPdfService)
  • Total/achitat/rest, recomandări (warning box)
- PaymentReceivedMail: la Payment::created, confirmare cu sumă/metodă/ref
- AppointmentConfirmedMail: la Appointment::created status='scheduled'
- ServiceReminderMail: dispatch manual (vehicle, type=itp/oil/general, note)

Layout email branded (resources/views/emails/layout.blade.php):
- Header cu logo tenant + theme_color border-bottom
- Footer cu telefon/email/disclaimer
- Stiluri inline (compatibil tot mail client)

Settings page extins cu 4 toggle:
- 'Mașina e gata de ridicat'
- 'Confirmare plată primită'
- 'Programare confirmată'
- 'Reminder ITP / revizie'
Salvate în companies.settings.notify (JSON), default true.

NotificationDispatcher service centralizat:
- Verifică isEnabled() pe settings.notify[$key]
- Skip dacă client n-are email
- Try/catch + Log::warning pe eșec (nu crapă request-ul)

Mailables folosesc UsesTenantBranding trait pentru context unitar.
Test prin Mailpit: https://mailpit.service.mir.md (capturează toate).
This commit is contained in:
2026-05-07 13:20:19 +00:00
parent bfe58ed286
commit 09fd0bada2
15 changed files with 608 additions and 0 deletions
+20
View File
@@ -34,6 +34,7 @@ class Settings extends Page
$settings = (array) ($company->settings ?? []);
// Filament v5: fill via $this->form->fill() (initializes the schema state).
$notify = (array) ($settings['notify'] ?? []);
$this->form->fill([
'display_name' => $company->display_name ?? $company->name,
'city' => $company->city,
@@ -45,6 +46,10 @@ class Settings extends Page
'labor_rate' => $settings['labor_rate'] ?? 400,
'services' => isset($settings['services']) ? implode(', ', (array) $settings['services']) : '',
'cars' => isset($settings['cars']) ? implode(', ', (array) $settings['cars']) : '',
'notify_wo_ready' => $notify['wo_ready'] ?? true,
'notify_payment' => $notify['payment'] ?? true,
'notify_appointment' => $notify['appointment'] ?? true,
'notify_reminder' => $notify['reminder'] ?? true,
]);
}
@@ -106,6 +111,15 @@ class Settings extends Page
->maxSize(512)
->helperText('PNG/ICO, max 512 KB.'),
]),
Schemas\Components\Section::make('Notificări email')
->description('Activează / dezactivează emailurile auto către clienți.')
->columns(2)
->schema([
Forms\Components\Toggle::make('notify_wo_ready')->label('Mașina e gata de ridicat')->default(true),
Forms\Components\Toggle::make('notify_payment')->label('Confirmare plată primită')->default(true),
Forms\Components\Toggle::make('notify_appointment')->label('Programare confirmată')->default(true),
Forms\Components\Toggle::make('notify_reminder')->label('Reminder ITP / revizie')->default(true),
]),
])
->statePath('data');
}
@@ -131,6 +145,12 @@ class Settings extends Page
'labor_rate' => (float) ($data['labor_rate'] ?? 400),
'services' => array_values(array_filter(array_map('trim', explode(',', (string) ($data['services'] ?? ''))))),
'cars' => array_values(array_filter(array_map('trim', explode(',', (string) ($data['cars'] ?? ''))))),
'notify' => [
'wo_ready' => (bool) ($data['notify_wo_ready'] ?? true),
'payment' => (bool) ($data['notify_payment'] ?? true),
'appointment' => (bool) ($data['notify_appointment'] ?? true),
'reminder' => (bool) ($data['notify_reminder'] ?? true),
],
]),
]);