Files
mareike/app/Resources/ParticipantRefundResource.php

49 lines
2.2 KiB
PHP

<?php
namespace App\Resources;
use App\Models\ParticipantRefund;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* Der Erstattungsvorgang für das Frontend.
*
* Bewusst NICHT `$this->resource->toArray()` als Basis wie in {@see EventParticipantResource}: die
* Bankverbindung darf nur dorthin, wo sie hingehört (Beleg und Auszahlung), nicht in jede
* Teilnehmerliste. Deshalb werden die Felder hier einzeln aufgeführt.
*/
class ParticipantRefundResource extends JsonResource
{
public function __construct(ParticipantRefund $refund)
{
parent::__construct($refund);
}
public function toArray($request): array
{
return [
'token' => $this->resource->token,
'status' => $this->resource->status,
'amount' => $this->resource->amount?->toString() ?? '0,00 Euro',
'amountValue' => $this->resource->amount?->getAmount() ?? 0.0,
'reason' => $this->resource->reason,
'reasonLabel' => $this->resource->reasonLabel(),
'reasonNote' => $this->resource->reason_note,
// Was beim Verband bleibt. `hasRetention` erspart dem Frontend den Betragsvergleich samt
// Rundungsfrage -- es soll nur entscheiden, ob der Hinweis angezeigt wird.
'hasRetention' => $this->resource->hasRetention(),
'retainedAmount' => $this->resource->retained_amount?->toString() ?? '0,00 Euro',
'retentionReasonLabel' => $this->resource->retentionReasonLabel(),
'retentionReasonNote' => $this->resource->retention_reason_note,
'releasedAt' => $this->resource->released_at?->format('d.m.Y'),
'acceptedAt' => $this->resource->accepted_at?->format('d.m.Y'),
'cancelledAt' => $this->resource->cancelled_at?->format('d.m.Y'),
// Die Abrechnung, über die ausgezahlt wird -- ihr Status ist der Auszahlungsstand.
'invoiceNumber' => $this->resource->invoice()->first()?->invoice_number,
// Ob überhaupt ausgezahlt wird: Bei einer Spende bleibt der Betrag beim Verband. Steht wie
// die Belegnummer in der Abrechnung.
'donation' => $this->resource->isDonation(),
];
}
}