Files
mareike/app/Mail/ParticipantRefundMails/RefundAcceptedMail.php
T

79 lines
2.6 KiB
PHP

<?php
namespace App\Mail\ParticipantRefundMails;
use App\Models\EventParticipant;
use App\Models\ParticipantRefund;
use App\Support\Iban;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
/**
* Bestätigt dem Teili die erfassten Angaben und liefert den Beleg als PDF mit.
*
* Der Beleg wird nicht hier erzeugt, sondern übergeben: er entsteht einmal in
* {@see \App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundCommand} und geht an beide
* Empfänger. Scheitert die Erzeugung, geht die Mail ohne Anhang raus statt gar nicht.
*/
class RefundAcceptedMail extends Mailable
{
public function __construct(
private EventParticipant $participant,
private ParticipantRefund $refund,
private ?string $pdfContent = null,
private ?string $pdfFilename = null,
) {
}
public function envelope(): Envelope
{
return new Envelope(
subject: sprintf(
'Deine Angaben zur Rückerstattung für %s',
$this->participant->event()->first()->name
),
);
}
public function content(): Content
{
$event = $this->participant->event()->first();
$invoice = $this->refund->invoice()->first();
return new Content(
view: 'emails.events.refund_accepted',
with: [
'name' => $this->participant->getNicename(),
'eventTitle' => $event->name,
'eventEmail' => $event->email,
'amount' => $this->refund->amount?->toString() ?? '0,00 Euro',
'reason' => $this->refund->reasonLabel(),
'accountOwner' => $this->refund->account_owner,
'accountIban' => Iban::format((string) $this->refund->account_iban),
'hasDocument' => $this->pdfContent !== null,
'invoiceNumber' => $invoice?->invoice_number,
// Der Hinweis auf "Meine Abrechnungen" nur, wenn die Anmeldung an einem Konto hängt --
// die Seite filtert über die Nutzer-Verknüpfung und bliebe sonst leer.
'myInvoicesUrl' => $invoice?->user_id !== null ? url('/invoice/my-invoices/new') : null,
],
);
}
/**
* @return array<int, Attachment>
*/
public function attachments(): array
{
if ($this->pdfContent === null) {
return [];
}
return [
Attachment::fromData(fn (): string => $this->pdfContent, $this->pdfFilename ?? 'Rueckerstattung.pdf')
->withMime('application/pdf'),
];
}
}