schneespur/app/Mail/JobCompletedMail.php
Michael ee3dbba6cc Initial release v1.0.0
Schneespur — Open-source winter service documentation software (PWA + Admin).
GPS tracking via OwnTracks, weather data, photo evidence, and legally
compliant service records for winter maintenance operators.

License: AGPL-3.0-or-later
2026-05-17 13:33:51 +00:00

70 lines
2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Mail;
use App\Models\Job;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class JobCompletedMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public function __construct(
public Job $job,
public bool $weatherAvailable,
public ?string $pdfContent = null,
public string $pdfFilename = '',
public bool $isWeatherUpdate = false,
) {}
public function envelope(): Envelope
{
$subjectKey = $this->isWeatherUpdate
? 'notification.job_completed_updated_subject'
: 'notification.job_completed_subject';
$objectName = $this->job->customerObject?->name;
$customerLabel = $objectName
? $this->job->customer->name . ' ' . $objectName
: $this->job->customer->name;
return new Envelope(
subject: __($subjectKey, [
'customer' => $customerLabel,
'date' => $this->job->started_at->format(__('notification.date_format')),
]),
);
}
public function content(): Content
{
return new Content(
markdown: 'mail.job-completed',
with: [
'job' => $this->job,
'weatherAvailable' => $this->weatherAvailable,
'isWeatherUpdate' => $this->isWeatherUpdate,
'pdfAttached' => $this->pdfContent !== null,
'pdfSkipped' => $this->pdfContent === null && $this->pdfFilename !== '',
],
);
}
public function build(): static
{
$this->locale($this->job->customer->locale ?? 'de');
if ($this->pdfContent !== null) {
$this->attachData($this->pdfContent, $this->pdfFilename, [
'mime' => 'application/pdf',
]);
}
return $this;
}
}