92 lines
3.7 KiB
PHP
92 lines
3.7 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(
|
|
$this->refund->isDonation()
|
|
? 'Deine Spende statt Rückerstattung für %s'
|
|
: '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,
|
|
// Wurde gespendet, gibt es keine Bankverbindung und keine Überweisung, die angekündigt
|
|
// werden könnte. Steht in der Abrechnung, die hier ohnehin gelesen wird.
|
|
'donation' => (bool) $invoice?->donation,
|
|
// Wird nur ein Teil erstattet, soll der Teili nicht rätseln, wo der Rest geblieben ist.
|
|
'hasRetention' => $this->refund->hasRetention(),
|
|
'retainedAmount' => $this->refund->retained_amount?->toString() ?? '0,00 Euro',
|
|
'retentionReason' => $this->refund->retentionReasonLabel(),
|
|
'retentionReasonNote' => $this->refund->retention_reason_note,
|
|
// Hat die Aktionsleitung die Bankverbindung aufgenommen, hat der Teili selbst nichts
|
|
// eingetragen -- dann darf die Mail sich nicht für seine Angaben bedanken.
|
|
'capturedByManagement' => $this->refund->wasCapturedByManagement(),
|
|
// 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'),
|
|
];
|
|
}
|
|
}
|