Files

59 lines
1.9 KiB
PHP

<?php
namespace App\Domains\ParticipantRefund\Actions\ReleaseRefund;
use App\Models\EventParticipant;
use App\ValueObjects\Amount;
class ReleaseRefundRequest
{
public function __construct(
public readonly EventParticipant $participant,
public readonly Amount $amount,
public readonly string $reason,
public readonly ?string $reasonNote = null,
/**
* Die Bankverbindung, wenn sie der Aktionsleitung bereits vorliegt.
*
* Sind beide gesetzt, entfällt der Umweg über den Teili: die Erstattung wird sofort eingereicht.
* Bleiben sie leer, läuft der übliche Weg über den Bestätigungslink.
*/
public readonly ?string $accountOwner = null,
public readonly ?string $accountIban = null,
/**
* Warum ein Teil des Beitrags beim Verband bleibt.
*
* Pflicht, sobald weniger erstattet wird als gezahlt wurde: Ein einbehaltener Betrag ohne Grund
* ist in der Buchhaltung nicht haltbar.
*/
public readonly ?string $retentionReason = null,
public readonly ?string $retentionReasonNote = null,
) {
}
/** Ob die Erstattung ohne Zutun des Teilis eingereicht werden kann. */
public function hasBankDetails(): bool
{
return filled($this->accountOwner) && filled($this->accountIban);
}
/**
* Der Betrag, der beim Verband bleibt.
*
* Die halbe Cent-Toleranz fängt die Rundung des gespeicherten Floats ab -- ohne sie entstünden
* Restbeträge von Bruchteilen eines Cents, die eine Begründung verlangen würden.
*/
public function retainedAmount(): float
{
$paid = $this->participant->amount_paid?->getAmount() ?? 0.0;
$remaining = round($paid - $this->amount->getAmount(), 2);
return $remaining > 0.005 ? $remaining : 0.0;
}
public function hasRetention(): bool
{
return $this->retainedAmount() > 0.0;
}
}