Dev 4.8.0 #15
@@ -388,6 +388,14 @@ function saveParticipant() {
|
|||||||
<small v-else-if="props.participant.refund.status === 'accepted'">
|
<small v-else-if="props.participant.refund.status === 'accepted'">
|
||||||
bestätigt am {{ props.participant.refund.acceptedAt }}
|
bestätigt am {{ props.participant.refund.acceptedAt }}
|
||||||
</small>
|
</small>
|
||||||
|
|
||||||
|
<!-- Was beim Verband geblieben ist und warum. -->
|
||||||
|
<small v-if="props.participant.refund.hasRetention" class="retention-note">
|
||||||
|
<br />Einbehalten: {{ props.participant.refund.retainedAmount }} –
|
||||||
|
{{ props.participant.refund.retentionReasonLabel }}<template
|
||||||
|
v-if="props.participant.refund.retentionReasonNote"
|
||||||
|
> ({{ props.participant.refund.retentionReasonNote }})</template>
|
||||||
|
</small>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -541,4 +549,8 @@ textarea {
|
|||||||
select {
|
select {
|
||||||
width: 262px;
|
width: 262px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.retention-note {
|
||||||
|
color: #8a6d00;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -51,15 +51,82 @@ const openRefundDialogSwitch = ref(false);
|
|||||||
// Der Erstattungsdialog. `captureMode` steuert den Weg: 'participant' schickt dem Teili einen Link, über
|
// Der Erstattungsdialog. `captureMode` steuert den Weg: 'participant' schickt dem Teili einen Link, über
|
||||||
// den er seine Bankverbindung selbst einträgt; 'management' heißt, sie liegt der Aktionsleitung bereits
|
// den er seine Bankverbindung selbst einträgt; 'management' heißt, sie liegt der Aktionsleitung bereits
|
||||||
// vor -- dann wird die Erstattung sofort eingereicht.
|
// vor -- dann wird die Erstattung sofort eingereicht.
|
||||||
const refundForm = reactive({amount: '', reason: '', reasonNote: '', captureMode: 'participant', accountOwner: '', accountIban: ''});
|
const refundForm = reactive({
|
||||||
|
amount: '', reason: '', reasonNote: '',
|
||||||
|
captureMode: 'participant', accountOwner: '', accountIban: '',
|
||||||
|
retentionReason: '', retentionReasonNote: '',
|
||||||
|
});
|
||||||
const refundErrors = reactive({amount: '', reason: '', reasonNote: '', accountOwner: '', accountIban: ''});
|
const refundErrors = reactive({amount: '', reason: '', reasonNote: '', accountOwner: '', accountIban: ''});
|
||||||
const refundReasons = ref([]);
|
const refundReasons = ref([]);
|
||||||
|
const retentionReasons = ref([]);
|
||||||
const refundSaving = ref(false);
|
const refundSaving = ref(false);
|
||||||
|
|
||||||
const selectedRefundReason = computed(
|
const selectedRefundReason = computed(
|
||||||
() => refundReasons.value.find(r => r.value === refundForm.reason) ?? null
|
() => refundReasons.value.find(r => r.value === refundForm.reason) ?? null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const selectedRetentionReason = computed(
|
||||||
|
() => retentionReasons.value.find(r => r.value === refundForm.retentionReason) ?? null
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Was nach der Erstattung beim Verband bleibt -- die Grundlage für den Einbehaltungsblock. */
|
||||||
|
const retainedAmount = computed(() => {
|
||||||
|
const paid = Number(showParticipant.value?.amountPaidValue ?? 0);
|
||||||
|
const refunded = Number((refundForm.amount ?? '').replace(',', '.'));
|
||||||
|
|
||||||
|
if (!Number.isFinite(refunded)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const remaining = Math.round((paid - refunded) * 100) / 100;
|
||||||
|
|
||||||
|
return remaining > 0.005 ? remaining : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasRetention = computed(() => retainedAmount.value > 0);
|
||||||
|
|
||||||
|
const retainedAmountReadable = computed(
|
||||||
|
() => retainedAmount.value.toFixed(2).replace('.', ',') + ' Euro'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ob abgesendet werden kann. Der Knopf erscheint erst dann -- was noch fehlt, soll die Aktionsleitung
|
||||||
|
* sehen, bevor sie klickt, statt danach eine Fehlermeldung zu lesen.
|
||||||
|
*/
|
||||||
|
const refundFormComplete = computed(() => {
|
||||||
|
const amount = Number((refundForm.amount ?? '').replace(',', '.'));
|
||||||
|
const paid = Number(showParticipant.value?.amountPaidValue ?? 0);
|
||||||
|
|
||||||
|
if (!refundForm.amount || !(amount > 0) || amount > paid + 0.005) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!refundForm.reason) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedRefundReason.value?.requiresNote && !refundForm.reasonNote.trim()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bleibt etwas beim Verband, muss begründet sein, warum.
|
||||||
|
if (hasRetention.value) {
|
||||||
|
if (!refundForm.retentionReason) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedRetentionReason.value?.requiresNote && !refundForm.retentionReasonNote.trim()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (refundForm.captureMode === 'management') {
|
||||||
|
return refundForm.accountOwner.trim() !== '' && refundForm.accountIban.trim() !== '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
defineEmits(['showParticipantDetails', 'markCocExisting', 'paymentComplete'])
|
defineEmits(['showParticipantDetails', 'markCocExisting', 'paymentComplete'])
|
||||||
|
|
||||||
function openParticipantDetails(input) {
|
function openParticipantDetails(input) {
|
||||||
@@ -323,6 +390,8 @@ async function openRefundDialog(participant) {
|
|||||||
refundForm.captureMode = 'participant';
|
refundForm.captureMode = 'participant';
|
||||||
refundForm.accountOwner = '';
|
refundForm.accountOwner = '';
|
||||||
refundForm.accountIban = '';
|
refundForm.accountIban = '';
|
||||||
|
refundForm.retentionReason = '';
|
||||||
|
refundForm.retentionReasonNote = '';
|
||||||
|
|
||||||
Object.keys(refundErrors).forEach(key => refundErrors[key] = '');
|
Object.keys(refundErrors).forEach(key => refundErrors[key] = '');
|
||||||
|
|
||||||
@@ -331,6 +400,11 @@ async function openRefundDialog(participant) {
|
|||||||
refundReasons.value = reasons ?? [];
|
refundReasons.value = reasons ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (retentionReasons.value.length === 0) {
|
||||||
|
const reasons = await request('/api/v1/core/retrieve-retention-reasons', {method: 'GET'});
|
||||||
|
retentionReasons.value = reasons ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
openRefundDialogSwitch.value = true;
|
openRefundDialogSwitch.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +458,9 @@ async function execRefund() {
|
|||||||
// Leer beim Weg über den Teili -- dann verschickt der Server nur den Link.
|
// Leer beim Weg über den Teili -- dann verschickt der Server nur den Link.
|
||||||
accountOwner: refundForm.captureMode === 'management' ? refundForm.accountOwner : '',
|
accountOwner: refundForm.captureMode === 'management' ? refundForm.accountOwner : '',
|
||||||
accountIban: refundForm.captureMode === 'management' ? refundForm.accountIban : '',
|
accountIban: refundForm.captureMode === 'management' ? refundForm.accountIban : '',
|
||||||
|
// Leer bei voller Erstattung -- dann gibt es nichts zu begründen.
|
||||||
|
retentionReason: hasRetention.value ? refundForm.retentionReason : '',
|
||||||
|
retentionReasonNote: hasRetention.value ? refundForm.retentionReasonNote : '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -479,6 +556,15 @@ function mailToGroup(groupKey) {
|
|||||||
<td class="pl-amount" :id="'participant-' + participant.identifier +'-payment'" :class="participant.amount_left_value != 0 && !participant.unregistered ? 'not-paid' : ''">
|
<td class="pl-amount" :id="'participant-' + participant.identifier +'-payment'" :class="participant.amount_left_value != 0 && !participant.unregistered ? 'not-paid' : ''">
|
||||||
Gezahlt: <label :id="'participant-' + participant.identifier + '-paid'">{{ participant?.amountPaid.readable }}</label> /<br />
|
Gezahlt: <label :id="'participant-' + participant.identifier + '-paid'">{{ participant?.amountPaid.readable }}</label> /<br />
|
||||||
Gesamt: <label :id="'participant-' + participant.identifier + '-expected'">{{ participant?.amountExpected.readable }}</label>
|
Gesamt: <label :id="'participant-' + participant.identifier + '-expected'">{{ participant?.amountExpected.readable }}</label>
|
||||||
|
|
||||||
|
<!-- Warum ein Teil des Beitrags beim Verband geblieben ist. -->
|
||||||
|
<span v-if="participant.refund?.hasRetention" class="retention-note">
|
||||||
|
Einbehalten: {{ participant.refund.retainedAmount }}<br />
|
||||||
|
{{ participant.refund.retentionReasonLabel }}<template
|
||||||
|
v-if="participant.refund.retentionReasonNote"
|
||||||
|
> – {{ participant.refund.retentionReasonNote }}</template>
|
||||||
|
</span>
|
||||||
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<span v-if="participant.amount_left_value != 0 && !participant.unregistered" :id="'participant-' + participant.identifier + '-actions'">
|
<span v-if="participant.amount_left_value != 0 && !participant.unregistered" :id="'participant-' + participant.identifier + '-actions'">
|
||||||
<span class="link" style="font-size:10pt;" @click="paymentComplete(participant)">Zahlung buchen</span>
|
<span class="link" style="font-size:10pt;" @click="paymentComplete(participant)">Zahlung buchen</span>
|
||||||
@@ -655,6 +741,36 @@ function mailToGroup(groupKey) {
|
|||||||
<ErrorText :message="refundErrors.reasonNote" />
|
<ErrorText :message="refundErrors.reasonNote" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Bleibt ein Teil beim Verband, muss begründet sein, warum -- ein einbehaltener Betrag ohne
|
||||||
|
Grund ist in der Buchhaltung nicht haltbar. Bei voller Erstattung gibt es nichts zu zeigen.
|
||||||
|
-->
|
||||||
|
<template v-if="hasRetention">
|
||||||
|
<p class="refund-hint">
|
||||||
|
<strong>{{ retainedAmountReadable }}</strong> verbleiben beim Verband.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="refund-field">
|
||||||
|
<label for="refund_retention_reason">Grund der Einbehaltung</label>
|
||||||
|
<select id="refund_retention_reason" v-model="refundForm.retentionReason" class="form-input">
|
||||||
|
<option value="">Bitte auswählen …</option>
|
||||||
|
<option v-for="reason in retentionReasons" :key="reason.value" :value="reason.value">
|
||||||
|
{{ reason.label }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="selectedRetentionReason?.requiresNote" class="refund-field">
|
||||||
|
<label for="refund_retention_note">Erläuterung zur Einbehaltung</label>
|
||||||
|
<textarea
|
||||||
|
id="refund_retention_note"
|
||||||
|
v-model="refundForm.retentionReasonNote"
|
||||||
|
class="form-input"
|
||||||
|
rows="3"
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Liegt die Bankverbindung schon vor, entfällt der Umweg über den Teili: die Erstattung wird
|
Liegt die Bankverbindung schon vor, entfällt der Umweg über den Teili: die Erstattung wird
|
||||||
sofort eingereicht. Er bekommt den Beleg trotzdem.
|
sofort eingereicht. Er bekommt den Beleg trotzdem.
|
||||||
@@ -694,7 +810,13 @@ function mailToGroup(groupKey) {
|
|||||||
</p>
|
</p>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<button class="button" :disabled="refundSaving" @click="execRefund()">
|
<!-- Erscheint erst, wenn alles ausgefüllt ist; während des Speicherns gesperrt statt weg. -->
|
||||||
|
<button
|
||||||
|
v-if="refundFormComplete"
|
||||||
|
class="button"
|
||||||
|
:disabled="refundSaving"
|
||||||
|
@click="execRefund()"
|
||||||
|
>
|
||||||
<template v-if="refundSaving">Wird gespeichert…</template>
|
<template v-if="refundSaving">Wird gespeichert…</template>
|
||||||
<template v-else-if="refundForm.captureMode === 'management'">Erstattung einreichen</template>
|
<template v-else-if="refundForm.captureMode === 'management'">Erstattung einreichen</template>
|
||||||
<template v-else>Erstattung freigeben</template>
|
<template v-else>Erstattung freigeben</template>
|
||||||
@@ -749,6 +871,14 @@ function mailToGroup(groupKey) {
|
|||||||
margin-right: 6px;
|
margin-right: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.retention-note {
|
||||||
|
display: block;
|
||||||
|
margin-top: 6px;
|
||||||
|
font-size: 10pt;
|
||||||
|
color: #ca5a0a;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
.refund-hint {
|
.refund-hint {
|
||||||
margin-bottom: 14px;
|
margin-bottom: 14px;
|
||||||
padding: 8px 10px;
|
padding: 8px 10px;
|
||||||
|
|||||||
@@ -68,6 +68,17 @@ const props = defineProps({
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Beiträge, die trotz Abmeldung beim Verband geblieben sind. Eigene Zeile, weil die
|
||||||
|
Zeilen darüber nur aktive Anmeldungen führen.
|
||||||
|
-->
|
||||||
|
<tr v-if="props.event.retainedFromUnregistered.value > 0">
|
||||||
|
<th style="padding-bottom: 20px" colspan="2">Einbehalten von Abmeldungen</th>
|
||||||
|
<td style="padding-bottom: 20px" colspan="2">
|
||||||
|
{{ props.event.retainedFromUnregistered.readable }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2" style="border-width: 1px; border-top-style: solid">Gesamt</th>
|
<th colspan="2" style="border-width: 1px; border-top-style: solid">Gesamt</th>
|
||||||
<td style="font-weight: bold; border-width: 1px; border-top-style: solid">
|
<td style="font-weight: bold; border-width: 1px; border-top-style: solid">
|
||||||
|
|||||||
@@ -120,8 +120,8 @@ class AcceptRefundCommand
|
|||||||
$invoice = $this->createInvoice($refund, $costUnit, $document);
|
$invoice = $this->createInvoice($refund, $costUnit, $document);
|
||||||
|
|
||||||
// Erst jetzt, nicht früher: Beleg und Anmerkung der Abrechnung weisen den gezahlten Beitrag
|
// Erst jetzt, nicht früher: Beleg und Anmerkung der Abrechnung weisen den gezahlten Beitrag
|
||||||
// aus und läsen sonst bereits die 0.
|
// aus und läsen sonst bereits den verrechneten Stand.
|
||||||
$this->clearAmountPaid($refund);
|
$this->settleAmountPaid($refund);
|
||||||
|
|
||||||
$refund->invoice_id = $invoice->id;
|
$refund->invoice_id = $invoice->id;
|
||||||
$refund->save();
|
$refund->save();
|
||||||
@@ -255,16 +255,23 @@ class AcceptRefundCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setzt den gezahlten Beitrag des Teilis auf 0.
|
* Zieht den erstatteten Betrag vom gezahlten Beitrag ab.
|
||||||
*
|
*
|
||||||
* Mit der eingereichten Abrechnung ist der Beitrag nicht mehr beim Verband, sondern auf dem Weg
|
* Danach führt `amount_paid` genau das, was beim Verband geblieben ist -- bei voller Erstattung also
|
||||||
* zurück -- die Zahlungsübersichten der Aktionsleitung sollen ihn nicht länger als offen führen. Der
|
* 0, bei einer Teilerstattung den einbehaltenen Rest. Auf diesem Feld baut die Einnahmenrechnung der
|
||||||
* ursprüngliche Betrag steht zur Kontrolle in der Anmerkung der Abrechnung und auf dem Beleg.
|
* Veranstaltung auf; es muss deshalb den tatsächlichen Bestand abbilden und nicht die Zahlung von
|
||||||
|
* einst. Der ursprüngliche Betrag steht zur Kontrolle in der Anmerkung der Abrechnung und auf dem
|
||||||
|
* Beleg.
|
||||||
*/
|
*/
|
||||||
private function clearAmountPaid(ParticipantRefund $refund): void
|
private function settleAmountPaid(ParticipantRefund $refund): void
|
||||||
{
|
{
|
||||||
$participant = $refund->participant;
|
$participant = $refund->participant;
|
||||||
$participant->amount_paid = new Amount(0.0, 'Euro');
|
|
||||||
|
$paid = $participant->amount_paid?->getAmount() ?? 0.0;
|
||||||
|
$refunded = $refund->amount?->getAmount() ?? 0.0;
|
||||||
|
|
||||||
|
// `max` gegen Rundungsreste: Ein negativer gezahlter Betrag wäre in jeder Auswertung Unsinn.
|
||||||
|
$participant->amount_paid = new Amount(max(0.0, round($paid - $refunded, 2)), 'Euro');
|
||||||
$participant->save();
|
$participant->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+30
@@ -104,6 +104,26 @@ class CreateRefundDocumentCommand
|
|||||||
* Fallback stünde hier ein Fatal Error auf `null` -- so steht es heute im Deckblatt-Code der
|
* Fallback stünde hier ein Fatal Error auf `null` -- so steht es heute im Deckblatt-Code der
|
||||||
* Auslagenerstattung, und daran soll sich der Beleg kein Beispiel nehmen.
|
* Auslagenerstattung, und daran soll sich der Beleg kein Beispiel nehmen.
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* Der Hinweis, warum ein Teil des Beitrags beim Verband bleibt -- leer bei voller Erstattung.
|
||||||
|
*
|
||||||
|
* Der Beleg wandert in die Buchhaltung und ins Archiv; dort muss die Differenz zwischen gezahltem
|
||||||
|
* und erstattetem Betrag ohne Rückfrage erklärt sein.
|
||||||
|
*/
|
||||||
|
private function retentionNote(): string
|
||||||
|
{
|
||||||
|
if (!$this->refund->hasRetention()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = trim($this->refund->retentionReasonText());
|
||||||
|
$label = $this->refund->retentionReasonLabel();
|
||||||
|
|
||||||
|
return $text !== '' && $text !== $label
|
||||||
|
? sprintf('%s (%s)', $label, $text)
|
||||||
|
: $label;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Der Vermerk, wenn die Aktionsleitung die Angaben aufgenommen hat.
|
* Der Vermerk, wenn die Aktionsleitung die Angaben aufgenommen hat.
|
||||||
*
|
*
|
||||||
@@ -199,6 +219,9 @@ class CreateRefundDocumentCommand
|
|||||||
'account_owner' => (string) $refund->account_owner,
|
'account_owner' => (string) $refund->account_owner,
|
||||||
'account_iban' => $this->formatIban((string) $refund->account_iban),
|
'account_iban' => $this->formatIban((string) $refund->account_iban),
|
||||||
|
|
||||||
|
'retained_amount' => $this->money($refund->retained_amount?->getAmount() ?? 0.0),
|
||||||
|
'retention_note' => $this->retentionNote(),
|
||||||
|
|
||||||
'declaration_text' => $this->declarationText(),
|
'declaration_text' => $this->declarationText(),
|
||||||
'capture_note' => $this->captureNote(),
|
'capture_note' => $this->captureNote(),
|
||||||
|
|
||||||
@@ -242,6 +265,13 @@ class CreateRefundDocumentCommand
|
|||||||
$rows[] = ['Begründung', e($reasonText)];
|
$rows[] = ['Begründung', e($reasonText)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nur bei einer Teilerstattung: Ohne diese Zeile bliebe die Differenz zwischen gezahltem und
|
||||||
|
// erstattetem Betrag im Beleg unerklärt.
|
||||||
|
if ($refund->hasRetention()) {
|
||||||
|
$rows[] = ['Einbehalten', $this->money($refund->retained_amount?->getAmount() ?? 0.0)];
|
||||||
|
$rows[] = ['Grund der Einbehaltung', e($this->retentionNote())];
|
||||||
|
}
|
||||||
|
|
||||||
$rows[] = ['Kontoinhaber*in', e((string) $refund->account_owner)];
|
$rows[] = ['Kontoinhaber*in', e((string) $refund->account_owner)];
|
||||||
$rows[] = ['IBAN', e($this->formatIban((string) $refund->account_iban))];
|
$rows[] = ['IBAN', e($this->formatIban((string) $refund->account_iban))];
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Domains\ParticipantRefund\Actions\ReleaseRefund;
|
|||||||
use App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundCommand;
|
use App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundCommand;
|
||||||
use App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundRequest;
|
use App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundRequest;
|
||||||
use App\Enumerations\RefundReason;
|
use App\Enumerations\RefundReason;
|
||||||
|
use App\Enumerations\RetentionReason;
|
||||||
use App\Mail\ParticipantRefundMails\RefundReleasedMail;
|
use App\Mail\ParticipantRefundMails\RefundReleasedMail;
|
||||||
use App\Models\EventParticipant;
|
use App\Models\EventParticipant;
|
||||||
use App\Models\ParticipantRefund;
|
use App\Models\ParticipantRefund;
|
||||||
@@ -57,6 +58,11 @@ class ReleaseRefundCommand
|
|||||||
'amount' => $this->request->amount,
|
'amount' => $this->request->amount,
|
||||||
'reason' => $this->request->reason,
|
'reason' => $this->request->reason,
|
||||||
'reason_note' => $this->reasonNote(),
|
'reason_note' => $this->reasonNote(),
|
||||||
|
// Was beim Verband bleibt, wird hier festgeschrieben: Nach dem Einreichen führt
|
||||||
|
// `amount_paid` bereits diesen Rest, eine spätere Differenz wäre falsch.
|
||||||
|
'retained_amount' => $this->request->retainedAmount(),
|
||||||
|
'retention_reason' => $this->retentionReason(),
|
||||||
|
'retention_reason_note' => $this->retentionReasonNote(),
|
||||||
'released_by' => auth()->id(),
|
'released_by' => auth()->id(),
|
||||||
'released_at' => now(),
|
'released_at' => now(),
|
||||||
]);
|
]);
|
||||||
@@ -141,7 +147,32 @@ class ReleaseRefundCommand
|
|||||||
return 'Für diesen Grund ist eine Erläuterung erforderlich.';
|
return 'Für diesen Grund ist eine Erläuterung erforderlich.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->rejectBankDetails();
|
return $this->rejectRetention() ?? $this->rejectBankDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüfungen zum einbehaltenen Teil.
|
||||||
|
*
|
||||||
|
* Sicherheitsnetz hinter der Oberfläche: Dort erscheint der Absende-Knopf erst, wenn ein Grund
|
||||||
|
* gewählt ist. Über einen direkten Aufruf ginge das sonst vorbei, und ein einbehaltener Betrag ohne
|
||||||
|
* Begründung ist in der Buchhaltung nicht haltbar.
|
||||||
|
*/
|
||||||
|
private function rejectRetention(): ?string
|
||||||
|
{
|
||||||
|
if (!$this->request->hasRetention()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reason = RetentionReason::find($this->request->retentionReason);
|
||||||
|
if ($reason === null) {
|
||||||
|
return 'Bitte gib an, warum ein Teil des Beitrags einbehalten wird.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reason->requires_note && trim((string) $this->request->retentionReasonNote) === '') {
|
||||||
|
return 'Für diesen Einbehaltungsgrund ist eine Erläuterung erforderlich.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,6 +215,33 @@ class ReleaseRefundCommand
|
|||||||
return trim((string) $this->request->reasonNote);
|
return trim((string) $this->request->reasonNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der Einbehaltungsgrund -- nur, wenn tatsächlich etwas beim Verband bleibt.
|
||||||
|
*
|
||||||
|
* Bei voller Erstattung wird ein mitgeschickter Grund verworfen: In der Oberfläche ist das Feld dann
|
||||||
|
* gar nicht sichtbar, und ein Wert ohne Bezug hätte in der Datenbank nichts zu suchen.
|
||||||
|
*/
|
||||||
|
private function retentionReason(): ?string
|
||||||
|
{
|
||||||
|
return $this->request->hasRetention() ? $this->request->retentionReason : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Der Freitext dazu -- wie beim Erstattungsgrund nur bei Gründen, die ihn verlangen. */
|
||||||
|
private function retentionReasonNote(): ?string
|
||||||
|
{
|
||||||
|
if (!$this->request->hasRetention()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reason = RetentionReason::find($this->request->retentionReason);
|
||||||
|
|
||||||
|
if ($reason === null || !$reason->requires_note) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim((string) $this->request->retentionReasonNote);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teili und Kontaktperson bekommen je eine eigene Mail -- dasselbe Muster wie bei der Abmeldung
|
* Teili und Kontaktperson bekommen je eine eigene Mail -- dasselbe Muster wie bei der Abmeldung
|
||||||
* (siehe SetParticipationStateCommand).
|
* (siehe SetParticipationStateCommand).
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ class ReleaseRefundRequest
|
|||||||
*/
|
*/
|
||||||
public readonly ?string $accountOwner = null,
|
public readonly ?string $accountOwner = null,
|
||||||
public readonly ?string $accountIban = 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,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,4 +36,23 @@ class ReleaseRefundRequest
|
|||||||
{
|
{
|
||||||
return filled($this->accountOwner) && filled($this->accountIban);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ class ReleaseRefundController extends CommonController
|
|||||||
// Leer, wenn der Teili die Bankverbindung selbst eintragen soll.
|
// Leer, wenn der Teili die Bankverbindung selbst eintragen soll.
|
||||||
accountOwner: Text::nullIfBlank($request->input('accountOwner')),
|
accountOwner: Text::nullIfBlank($request->input('accountOwner')),
|
||||||
accountIban: Text::nullIfBlank($request->input('accountIban')),
|
accountIban: Text::nullIfBlank($request->input('accountIban')),
|
||||||
|
// Leer, wenn der volle Beitrag erstattet wird -- dann gibt es nichts zu begründen.
|
||||||
|
retentionReason: Text::nullIfBlank($request->input('retentionReason')),
|
||||||
|
retentionReasonNote: Text::nullIfBlank($request->input('retentionReasonNote')),
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = new ReleaseRefundCommand($refundRequest)->execute();
|
$response = new ReleaseRefundCommand($refundRequest)->execute();
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ final class ParticipantRefundTokens
|
|||||||
'paid_amount' => ['description' => 'Bereits gezahlter Teilnahmebeitrag', 'sample' => '300,00 €'],
|
'paid_amount' => ['description' => 'Bereits gezahlter Teilnahmebeitrag', 'sample' => '300,00 €'],
|
||||||
'invoice_number' => ['description' => 'Nummer der Teilnahmerechnung', 'sample' => 'WM-V-20260701-0005'],
|
'invoice_number' => ['description' => 'Nummer der Teilnahmerechnung', 'sample' => 'WM-V-20260701-0005'],
|
||||||
'refund_amount' => ['description' => 'Erstattungsbetrag', 'sample' => '220,00 €'],
|
'refund_amount' => ['description' => 'Erstattungsbetrag', 'sample' => '220,00 €'],
|
||||||
|
'retained_amount' => ['description' => 'Betrag, der beim Verband bleibt — 0,00 € bei voller Erstattung', 'sample' => '80,00 €'],
|
||||||
|
'retention_note' => ['description' => 'Grund der Einbehaltung — leer bei voller Erstattung', 'sample' => 'Stornogebühr laut Ausschreibung'],
|
||||||
'refund_reason' => ['description' => 'Bezeichnung des Grundes', 'sample' => 'Krankheitsbedingte Absage'],
|
'refund_reason' => ['description' => 'Bezeichnung des Grundes', 'sample' => 'Krankheitsbedingte Absage'],
|
||||||
'refund_reason_text' => ['description' => 'Erläuterung des Grundes (bei „Sonstiger Grund" der Freitext)', 'sample' => 'Die Teilnahme konnte krankheitsbedingt nicht angetreten werden.'],
|
'refund_reason_text' => ['description' => 'Erläuterung des Grundes (bei „Sonstiger Grund" der Freitext)', 'sample' => 'Die Teilnahme konnte krankheitsbedingt nicht angetreten werden.'],
|
||||||
'account_owner' => ['description' => 'Kontoinhaber*in', 'sample' => 'Mika Muster'],
|
'account_owner' => ['description' => 'Kontoinhaber*in', 'sample' => 'Mika Muster'],
|
||||||
@@ -111,6 +113,8 @@ final class ParticipantRefundTokens
|
|||||||
. '<tr><td class="detail-key">Erstattungsbetrag</td><td class="detail-val">220,00 €</td></tr>'
|
. '<tr><td class="detail-key">Erstattungsbetrag</td><td class="detail-val">220,00 €</td></tr>'
|
||||||
. '<tr><td class="detail-key">Grund</td><td class="detail-val">Krankheitsbedingte Absage</td></tr>'
|
. '<tr><td class="detail-key">Grund</td><td class="detail-val">Krankheitsbedingte Absage</td></tr>'
|
||||||
. '<tr><td class="detail-key">Begründung</td><td class="detail-val">Die Teilnahme konnte krankheitsbedingt nicht angetreten werden.</td></tr>'
|
. '<tr><td class="detail-key">Begründung</td><td class="detail-val">Die Teilnahme konnte krankheitsbedingt nicht angetreten werden.</td></tr>'
|
||||||
|
. '<tr><td class="detail-key">Einbehalten</td><td class="detail-val">80,00 €</td></tr>'
|
||||||
|
. '<tr><td class="detail-key">Grund der Einbehaltung</td><td class="detail-val">Stornogebühr laut Ausschreibung</td></tr>'
|
||||||
. '<tr><td class="detail-key">Kontoinhaber*in</td><td class="detail-val">Mika Muster</td></tr>'
|
. '<tr><td class="detail-key">Kontoinhaber*in</td><td class="detail-val">Mika Muster</td></tr>'
|
||||||
. '<tr><td class="detail-key">IBAN</td><td class="detail-val">DE02 1203 0000 0000 2020 51</td></tr>'
|
. '<tr><td class="detail-key">IBAN</td><td class="detail-val">DE02 1203 0000 0000 2020 51</td></tr>'
|
||||||
. '</table>';
|
. '</table>';
|
||||||
|
|||||||
@@ -32,11 +32,13 @@ class InvoiceType extends CommonModel {
|
|||||||
'name',
|
'name',
|
||||||
'sort_order',
|
'sort_order',
|
||||||
'selectable',
|
'selectable',
|
||||||
|
'counts_as_expense',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'sort_order' => 'integer',
|
'sort_order' => 'integer',
|
||||||
'selectable' => 'boolean',
|
'selectable' => 'boolean',
|
||||||
|
'counts_as_expense' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,4 +53,18 @@ class InvoiceType extends CommonModel {
|
|||||||
{
|
{
|
||||||
return self::where('selectable', true)->orderBy('sort_order')->get();
|
return self::where('selectable', true)->orderBy('sort_order')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Typen, die in der Ausgabenrechnung einer Veranstaltung zählen -- nach Sortierung.
|
||||||
|
*
|
||||||
|
* Ausgenommen ist, was fachlich keine Ausgabe ist, sondern die Rücknahme einer Einnahme: Eine
|
||||||
|
* Beitragserstattung mindert bereits die Einnahmenseite, weil der abgemeldete Teili dort herausfällt.
|
||||||
|
* Als Ausgabe gezählt, ginge derselbe Vorgang ein zweites Mal in die Bilanz.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Collection<int, self>
|
||||||
|
*/
|
||||||
|
public static function countingAsExpense(): \Illuminate\Database\Eloquent\Collection
|
||||||
|
{
|
||||||
|
return self::where('counts_as_expense', true)->orderBy('sort_order')->get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enumerations;
|
||||||
|
|
||||||
|
use App\Scopes\CommonModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gründe, aus denen ein Teil des gezahlten Teilnahmebeitrags beim Verband bleibt.
|
||||||
|
*
|
||||||
|
* Gegenstück zu {@see RefundReason}: Jener sagt, warum erstattet wird, dieser, warum nicht alles.
|
||||||
|
*
|
||||||
|
* @property string $slug
|
||||||
|
* @property string $name
|
||||||
|
* @property string|null $document_text
|
||||||
|
* @property bool $requires_note
|
||||||
|
* @property int $sort_order
|
||||||
|
*/
|
||||||
|
class RetentionReason extends CommonModel
|
||||||
|
{
|
||||||
|
public const string CANCELLATION_FEE = 'cancellation_fee';
|
||||||
|
public const string INCURRED_COSTS = 'incurred_costs';
|
||||||
|
public const string MATERIAL = 'material';
|
||||||
|
public const string CUSTOM = 'custom';
|
||||||
|
|
||||||
|
protected $table = 'retention_reasons';
|
||||||
|
protected $primaryKey = 'slug';
|
||||||
|
public $incrementing = false;
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'slug',
|
||||||
|
'name',
|
||||||
|
'document_text',
|
||||||
|
'requires_note',
|
||||||
|
'sort_order',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'requires_note' => 'boolean',
|
||||||
|
'sort_order' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der Text, der auf dem Beleg unter „Einbehalten" steht. Bei einem Grund, der einen Freitext
|
||||||
|
* verlangt, ist es der Text der Aktionsleitung.
|
||||||
|
*/
|
||||||
|
public function documentText(?string $note = null): string
|
||||||
|
{
|
||||||
|
return $this->requires_note ? trim((string) $note) : (string) $this->document_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optionen für das Frontend. `requiresNote` steuert dort das Freitextfeld.
|
||||||
|
*
|
||||||
|
* @return array<int, array{value: string, label: string, requiresNote: bool}>
|
||||||
|
*/
|
||||||
|
public static function options(): array
|
||||||
|
{
|
||||||
|
return self::orderBy('sort_order')->get()
|
||||||
|
->map(static fn (self $reason): array => [
|
||||||
|
'value' => $reason->slug,
|
||||||
|
'label' => $reason->name,
|
||||||
|
'requiresNote' => $reason->requires_note,
|
||||||
|
])
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,6 +54,11 @@ class RefundAcceptedMail extends Mailable
|
|||||||
'accountIban' => Iban::format((string) $this->refund->account_iban),
|
'accountIban' => Iban::format((string) $this->refund->account_iban),
|
||||||
'hasDocument' => $this->pdfContent !== null,
|
'hasDocument' => $this->pdfContent !== null,
|
||||||
'invoiceNumber' => $invoice?->invoice_number,
|
'invoiceNumber' => $invoice?->invoice_number,
|
||||||
|
// 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
|
// Hat die Aktionsleitung die Bankverbindung aufgenommen, hat der Teili selbst nichts
|
||||||
// eingetragen -- dann darf die Mail sich nicht für seine Angaben bedanken.
|
// eingetragen -- dann darf die Mail sich nicht für seine Angaben bedanken.
|
||||||
'capturedByManagement' => $this->refund->wasCapturedByManagement(),
|
'capturedByManagement' => $this->refund->wasCapturedByManagement(),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
|||||||
|
|
||||||
use App\Casts\AmountCast;
|
use App\Casts\AmountCast;
|
||||||
use App\Enumerations\RefundReason;
|
use App\Enumerations\RefundReason;
|
||||||
|
use App\Enumerations\RetentionReason;
|
||||||
use App\Scopes\InstancedModel;
|
use App\Scopes\InstancedModel;
|
||||||
use App\ValueObjects\Amount;
|
use App\ValueObjects\Amount;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@@ -20,6 +21,9 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
* @property Amount|null $amount
|
* @property Amount|null $amount
|
||||||
* @property string|null $reason
|
* @property string|null $reason
|
||||||
* @property string|null $reason_note
|
* @property string|null $reason_note
|
||||||
|
* @property string|null $retention_reason
|
||||||
|
* @property string|null $retention_reason_note
|
||||||
|
* @property Amount|null $retained_amount
|
||||||
* @property string|null $account_owner
|
* @property string|null $account_owner
|
||||||
* @property string|null $account_iban
|
* @property string|null $account_iban
|
||||||
* @property int|null $captured_by
|
* @property int|null $captured_by
|
||||||
@@ -51,6 +55,9 @@ class ParticipantRefund extends InstancedModel
|
|||||||
'amount',
|
'amount',
|
||||||
'reason',
|
'reason',
|
||||||
'reason_note',
|
'reason_note',
|
||||||
|
'retention_reason',
|
||||||
|
'retention_reason_note',
|
||||||
|
'retained_amount',
|
||||||
'account_owner',
|
'account_owner',
|
||||||
'account_iban',
|
'account_iban',
|
||||||
'captured_by',
|
'captured_by',
|
||||||
@@ -63,6 +70,7 @@ class ParticipantRefund extends InstancedModel
|
|||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'amount' => AmountCast::class,
|
'amount' => AmountCast::class,
|
||||||
|
'retained_amount' => AmountCast::class,
|
||||||
'released_at' => 'datetime',
|
'released_at' => 'datetime',
|
||||||
'accepted_at' => 'datetime',
|
'accepted_at' => 'datetime',
|
||||||
'cancelled_at' => 'datetime',
|
'cancelled_at' => 'datetime',
|
||||||
@@ -129,4 +137,32 @@ class ParticipantRefund extends InstancedModel
|
|||||||
{
|
{
|
||||||
return (string) ($this->reasonRelation()->first()?->name ?? '');
|
return (string) ($this->reasonRelation()->first()?->name ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Der Einbehaltungsgrund als Stammdatensatz -- leer, wenn voll erstattet wurde. */
|
||||||
|
public function retentionReasonRelation(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(RetentionReason::class, 'retention_reason', 'slug');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function retentionReasonLabel(): string
|
||||||
|
{
|
||||||
|
return (string) ($this->retentionReasonRelation()->first()?->name ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Der auf dem Beleg auszuweisende Text zur Einbehaltung. */
|
||||||
|
public function retentionReasonText(): string
|
||||||
|
{
|
||||||
|
return $this->retentionReasonRelation()->first()?->documentText($this->retention_reason_note) ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ob etwas beim Verband bleibt -- die halbe Cent-Toleranz fängt die Float-Rundung ab.
|
||||||
|
*
|
||||||
|
* Der Betrag steht in `retained_amount` und wird beim Einreichen festgeschrieben. Ihn zur Laufzeit
|
||||||
|
* aus `amount_paid` zu rechnen ginge schief: Danach führt das Feld bereits den Rest.
|
||||||
|
*/
|
||||||
|
public function hasRetention(): bool
|
||||||
|
{
|
||||||
|
return ($this->retained_amount?->getAmount() ?? 0.0) > 0.005;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Providers;
|
|||||||
use App\Enumerations\EatingHabit;
|
use App\Enumerations\EatingHabit;
|
||||||
use App\Enumerations\InvoiceType;
|
use App\Enumerations\InvoiceType;
|
||||||
use App\Enumerations\RefundReason;
|
use App\Enumerations\RefundReason;
|
||||||
|
use App\Enumerations\RetentionReason;
|
||||||
use App\Enumerations\UserRole;
|
use App\Enumerations\UserRole;
|
||||||
use App\Models\AvailablePaymentMethod;
|
use App\Models\AvailablePaymentMethod;
|
||||||
use App\Models\Tenant;
|
use App\Models\Tenant;
|
||||||
@@ -202,6 +203,11 @@ class GlobalDataProvider {
|
|||||||
return response()->json(RefundReason::options());
|
return response()->json(RefundReason::options());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Auswahl der Gründe, aus denen ein Teil des Beitrags beim Verband bleibt. */
|
||||||
|
public function getRetentionReasons() : JsonResponse {
|
||||||
|
return response()->json(RetentionReason::options());
|
||||||
|
}
|
||||||
|
|
||||||
public function getEventSettingData(Request $request) : JsonResponse {
|
public function getEventSettingData(Request $request) : JsonResponse {
|
||||||
return response()->json(
|
return response()->json(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ class CostUnitResource {
|
|||||||
$amounts = [];
|
$amounts = [];
|
||||||
$overAllAmount = new Amount(0, 'Euro');
|
$overAllAmount = new Amount(0, 'Euro');
|
||||||
$overAllEstimatedAmount = new Amount(0, 'Euro');
|
$overAllEstimatedAmount = new Amount(0, 'Euro');
|
||||||
foreach (InvoiceType::orderBy('sort_order')->get() as $invoiceType) {
|
// Nur echte Aufwandsarten: Eine Beitragserstattung ist die Rücknahme einer Einnahme und wird auf
|
||||||
|
// der Einnahmenseite bereits berücksichtigt -- hier gezählt, stünde sie ein zweites Mal in der
|
||||||
|
// Bilanz. `totalAmount` weiter oben bleibt davon unberührt, das ist die Kassensicht.
|
||||||
|
foreach (InvoiceType::countingAsExpense() as $invoiceType) {
|
||||||
$overAllAmount->addAmount($costUnitRepository->sumupByInvoiceType($this->costUnit, $invoiceType));
|
$overAllAmount->addAmount($costUnitRepository->sumupByInvoiceType($this->costUnit, $invoiceType));
|
||||||
$overAllEstimatedAmount->addAmount($costUnitRepository->sumupEstimatedByInvoiceType($this->costUnit, $invoiceType));
|
$overAllEstimatedAmount->addAmount($costUnitRepository->sumupEstimatedByInvoiceType($this->costUnit, $invoiceType));
|
||||||
$amounts[$invoiceType->slug]['string'] = $costUnitRepository->sumupByInvoiceType($this->costUnit, $invoiceType)->toString();
|
$amounts[$invoiceType->slug]['string'] = $costUnitRepository->sumupByInvoiceType($this->costUnit, $invoiceType)->toString();
|
||||||
|
|||||||
@@ -96,6 +96,14 @@ class EventResource extends JsonResource{
|
|||||||
|
|
||||||
$returnArray['income'] = $this->calculateIncomes($returnArray['participants'], $returnArray['supportPerson']['amount']);
|
$returnArray['income'] = $this->calculateIncomes($returnArray['participants'], $returnArray['supportPerson']['amount']);
|
||||||
|
|
||||||
|
// Eigene Zeile in der Übersicht: In den Zeilen je Teilnahmeart hätte der Betrag nichts zu suchen,
|
||||||
|
// dort stehen nur aktive Anmeldungen.
|
||||||
|
$retainedFromUnregistered = $this->sumPaidOfUnregistered();
|
||||||
|
$returnArray['retainedFromUnregistered'] = [
|
||||||
|
'value' => $retainedFromUnregistered->getAmount(),
|
||||||
|
'readable' => $retainedFromUnregistered->toString(),
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
$totalBalanceReal = new Amount(0, 'Euro');
|
$totalBalanceReal = new Amount(0, 'Euro');
|
||||||
$totalBalanceExpected = new Amount(0, 'Euro');
|
$totalBalanceExpected = new Amount(0, 'Euro');
|
||||||
@@ -272,6 +280,13 @@ class EventResource extends JsonResource{
|
|||||||
$realAmount->addAmount(new Amount($participantData['amount']['paid']['value'], 'Euro'));
|
$realAmount->addAmount(new Amount($participantData['amount']['paid']['value'], 'Euro'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Was abgemeldete Teilis gezahlt haben und nicht zurückbekommen, gehört in beide Spalten: Das
|
||||||
|
// Geld liegt beim Verband (real) und fließt nicht mehr ab (erwartet). Ohne diese Zeile stünde
|
||||||
|
// jede Veranstaltung mit Abmeldungen dauerhaft schlechter da, als sie ist.
|
||||||
|
$retained = $this->sumPaidOfUnregistered();
|
||||||
|
$realAmount->addAmount($retained);
|
||||||
|
$expectedAmount->addAmount($retained);
|
||||||
|
|
||||||
return ['real' => [
|
return ['real' => [
|
||||||
'amount' => $realAmount,
|
'amount' => $realAmount,
|
||||||
'readable' => $realAmount->toString()
|
'readable' => $realAmount->toString()
|
||||||
@@ -283,6 +298,28 @@ class EventResource extends JsonResource{
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Was von abgemeldeten Teilis beim Verband geblieben ist.
|
||||||
|
*
|
||||||
|
* `amount_paid` führt nach einer Erstattung genau den einbehaltenen Rest; wurde nie erstattet, steht
|
||||||
|
* dort der volle gezahlte Beitrag. Beides ist Geld, das der Veranstaltung zusteht.
|
||||||
|
*
|
||||||
|
* Bewusst eine direkte Abfrage wie in {@see self::getParticipants()} nebenan -- ein einzelner
|
||||||
|
* Repository-Aufruf zwischen den Inline-Queries dieser Klasse würde sie uneinheitlicher machen.
|
||||||
|
*/
|
||||||
|
public function sumPaidOfUnregistered() : Amount
|
||||||
|
{
|
||||||
|
$sum = new Amount(0, 'Euro');
|
||||||
|
|
||||||
|
foreach ($this->event->participants()->whereNotNull('unregistered_at')->get() as $participant) {
|
||||||
|
if ($participant->amount_paid !== null) {
|
||||||
|
$sum->addAmount($participant->amount_paid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sum;
|
||||||
|
}
|
||||||
|
|
||||||
public function getParticipants(string $participationType) : array {
|
public function getParticipants(string $participationType) : array {
|
||||||
$returnData = [];
|
$returnData = [];
|
||||||
$returnData['amount'] = [
|
$returnData['amount'] = [
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ class ParticipantRefundResource extends JsonResource
|
|||||||
'reason' => $this->resource->reason,
|
'reason' => $this->resource->reason,
|
||||||
'reasonLabel' => $this->resource->reasonLabel(),
|
'reasonLabel' => $this->resource->reasonLabel(),
|
||||||
'reasonNote' => $this->resource->reason_note,
|
'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'),
|
'releasedAt' => $this->resource->released_at?->format('d.m.Y'),
|
||||||
'acceptedAt' => $this->resource->accepted_at?->format('d.m.Y'),
|
'acceptedAt' => $this->resource->accepted_at?->format('d.m.Y'),
|
||||||
'cancelledAt' => $this->resource->cancelled_at?->format('d.m.Y'),
|
'cancelledAt' => $this->resource->cancelled_at?->format('d.m.Y'),
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trennt die Abrechnungstypen, die in der Ausgabenrechnung einer Veranstaltung zählen, von denen, die es
|
||||||
|
* nicht tun.
|
||||||
|
*
|
||||||
|
* Anlass ist die Beitragserstattung: Sie ist keine Aufwandsposition, sondern die Rücknahme einer
|
||||||
|
* Einnahme. Die Einnahmenseite berücksichtigt sie bereits -- ein abgemeldeter Teili fällt aus
|
||||||
|
* `EventResource::getParticipants()` heraus, sein gezahlter Beitrag verschwindet also dort schon. Als
|
||||||
|
* Ausgabe gezählt, ginge derselbe Vorgang ein zweites Mal in die Bilanz.
|
||||||
|
*
|
||||||
|
* Betroffen ist nur die Budgetrechnung der Veranstaltung. In der Kassensicht (Kostenstellen-Liste,
|
||||||
|
* Dashboard) bleibt der Betrag stehen -- dort fließt er tatsächlich ab.
|
||||||
|
*/
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('invoice_types', function (Blueprint $table) {
|
||||||
|
$table->boolean('counts_as_expense')->default(true)->after('selectable');
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::table('invoice_types')
|
||||||
|
->where('slug', 'participation_refund')
|
||||||
|
->update(['counts_as_expense' => false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('invoice_types', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('counts_as_expense');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gründe, aus denen ein Teil des gezahlten Beitrags beim Verband bleibt.
|
||||||
|
*
|
||||||
|
* Wird nicht der volle Beitrag erstattet, ist der Rest eine Einnahme, die begründet sein muss -- in der
|
||||||
|
* Buchhaltung ist ein einbehaltener Betrag ohne Grund nicht haltbar. Aufgebaut wie
|
||||||
|
* {@see \App\Enumerations\RefundReason}: app-weite Stammdaten, `slug` als Schlüssel.
|
||||||
|
*/
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('retention_reasons', function (Blueprint $table) {
|
||||||
|
$table->string('slug')->primary();
|
||||||
|
$table->string('name');
|
||||||
|
$table->text('document_text')->nullable();
|
||||||
|
$table->boolean('requires_note')->default(false);
|
||||||
|
$table->integer('sort_order')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::table('retention_reasons')->insert([
|
||||||
|
[
|
||||||
|
'slug' => 'cancellation_fee',
|
||||||
|
'name' => 'Stornogebühr laut Ausschreibung',
|
||||||
|
'document_text' => 'Einbehalten wurde die in der Ausschreibung genannte Stornogebühr.',
|
||||||
|
'requires_note' => false,
|
||||||
|
'sort_order' => 10,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'slug' => 'incurred_costs',
|
||||||
|
'name' => 'Bereits entstandene Kosten',
|
||||||
|
'document_text' => 'Einbehalten wurden Kosten, die zum Zeitpunkt der Abmeldung bereits entstanden waren.',
|
||||||
|
'requires_note' => false,
|
||||||
|
'sort_order' => 20,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'slug' => 'material',
|
||||||
|
'name' => 'Bereits beschafftes Material',
|
||||||
|
'document_text' => 'Einbehalten wurden Kosten für Material, das bereits beschafft wurde.',
|
||||||
|
'requires_note' => false,
|
||||||
|
'sort_order' => 30,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// Der Text entsteht erst aus dem Freitext der Aktionsleitung -- deshalb hier leer.
|
||||||
|
'slug' => 'custom',
|
||||||
|
'name' => 'Sonstiger Grund',
|
||||||
|
'document_text' => null,
|
||||||
|
'requires_note' => true,
|
||||||
|
'sort_order' => 40,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('retention_reasons');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Was beim Verband bleibt und warum.
|
||||||
|
*
|
||||||
|
* Nur belegt, wenn weniger erstattet wird als gezahlt wurde. Bei voller Erstattung bleiben die Felder
|
||||||
|
* leer bzw. auf 0 -- dann gibt es nichts zu begründen.
|
||||||
|
*
|
||||||
|
* `retained_amount` wird beim Einreichen festgeschrieben und nicht zur Laufzeit gerechnet: Danach führt
|
||||||
|
* `event_participants.amount_paid` bereits den Rest, eine Differenz daraus wäre ab dem Moment falsch.
|
||||||
|
*/
|
||||||
|
return new class extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('participant_refunds', function (Blueprint $table) {
|
||||||
|
$table->string('retention_reason')->nullable()->after('reason_note');
|
||||||
|
$table->text('retention_reason_note')->nullable()->after('retention_reason');
|
||||||
|
$table->float('retained_amount', 2)->default(0)->after('retention_reason_note');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Der Fremdschlüssel in einem eigenen Aufruf: zusammen mit dem Anlegen der Spalte hat MariaDB ihn
|
||||||
|
// hier stillschweigend übergangen, und ein `down()` lief anschließend ins Leere.
|
||||||
|
Schema::table('participant_refunds', function (Blueprint $table) {
|
||||||
|
$table->foreign('retention_reason')->references('slug')->on('retention_reasons')
|
||||||
|
->restrictOnDelete()->cascadeOnUpdate();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('participant_refunds', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['retention_reason']);
|
||||||
|
$table->dropColumn(['retention_reason', 'retention_reason_note', 'retained_amount']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -44,6 +44,13 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@if ($hasRetention)
|
||||||
|
<p style="padding: 10px 12px; border-left: 3px solid #f5c400; background-color: #fffef5;">
|
||||||
|
Von deinem gezahlten Beitrag verbleiben <strong>{{$retainedAmount}}</strong> beim Verband.<br />
|
||||||
|
Grund: {{$retentionReason}}@if ($retentionReasonNote) – {{$retentionReasonNote}}@endif
|
||||||
|
</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
@if ($hasDocument)
|
@if ($hasDocument)
|
||||||
<p>
|
<p>
|
||||||
Im Anhang findest du deinen Beleg über die Rückerstattung als PDF – nur zu deiner
|
Im Anhang findest du deinen Beleg über die Rückerstattung als PDF – nur zu deiner
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ Route::middleware(IdentifyTenant::class)->group(function () {
|
|||||||
Route::get('/retrieve-invoice-types-all', [GlobalDataProvider::class, 'getAllInvoiceTypes']);
|
Route::get('/retrieve-invoice-types-all', [GlobalDataProvider::class, 'getAllInvoiceTypes']);
|
||||||
Route::get('/retrieve-event-setting-data', [GlobalDataProvider::class, 'getEventSettingData']);
|
Route::get('/retrieve-event-setting-data', [GlobalDataProvider::class, 'getEventSettingData']);
|
||||||
Route::get('/retrieve-refund-reasons', [GlobalDataProvider::class, 'getRefundReasons']);
|
Route::get('/retrieve-refund-reasons', [GlobalDataProvider::class, 'getRefundReasons']);
|
||||||
|
Route::get('/retrieve-retention-reasons', [GlobalDataProvider::class, 'getRetentionReasons']);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,324 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Enumerations\CostUnitType;
|
||||||
|
use App\Enumerations\EfzStatus;
|
||||||
|
use App\Enumerations\InvoiceStatus;
|
||||||
|
use App\Enumerations\InvoiceType;
|
||||||
|
use App\Models\CostUnit;
|
||||||
|
use App\Models\Event;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\PaymentMethod;
|
||||||
|
use App\Models\Tenant;
|
||||||
|
use App\RelationModels\EventParticipationFee;
|
||||||
|
use App\Resources\CostUnitResource;
|
||||||
|
use App\Resources\EventResource;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Ausgabenrechnung der Veranstaltungsübersicht.
|
||||||
|
*
|
||||||
|
* Eine Beitragserstattung gehört dort nicht hinein: Sie ist die Rücknahme einer Einnahme, und die
|
||||||
|
* Einnahmenseite hat sie bereits berücksichtigt -- ein abgemeldeter Teili fällt aus `getParticipants()`
|
||||||
|
* heraus. Als Ausgabe gezählt, ginge derselbe Vorgang ein zweites Mal in die Bilanz.
|
||||||
|
*/
|
||||||
|
class EventBudgetTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private Tenant $tenant;
|
||||||
|
|
||||||
|
private CostUnit $costUnit;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->tenant = Tenant::create([
|
||||||
|
'slug' => 'wm',
|
||||||
|
'name' => 'Wilde Möhre',
|
||||||
|
'email' => 't@example.com',
|
||||||
|
'email_finance' => 'finance@example.com',
|
||||||
|
'url' => parse_url(config('app.url'), PHP_URL_HOST),
|
||||||
|
'account_name' => 'Test e.V.',
|
||||||
|
'account_iban' => 'DE00',
|
||||||
|
'account_bic' => 'XY',
|
||||||
|
'city' => 'Stadt',
|
||||||
|
'postcode' => '00000',
|
||||||
|
'invoice_prefix' => 'WM',
|
||||||
|
'is_active_local_group' => true,
|
||||||
|
'has_active_instance' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
app()->instance('tenant', $this->tenant);
|
||||||
|
|
||||||
|
DB::table('participation_types')->insert(['slug' => 'participant', 'name' => 'Teilnehmer']);
|
||||||
|
DB::table('participation_fee_types')->insert(['slug' => 'fixed', 'name' => 'Fix']);
|
||||||
|
DB::table('cost_unit_types')->insert(['slug' => CostUnitType::COST_UNIT_TYPE_EVENT, 'name' => 'Veranstaltung']);
|
||||||
|
DB::table('invoice_status')->insert(['slug' => InvoiceStatus::INVOICE_STATUS_NEW]);
|
||||||
|
PaymentMethod::create(['slug' => PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION]);
|
||||||
|
EfzStatus::create(['slug' => EfzStatus::EFZ_STATUS_NOT_REQUIRED, 'name' => 'Nicht erforderlich']);
|
||||||
|
|
||||||
|
// Ein gewöhnlicher Aufwandstyp zum Vergleich; die Beitragserstattung bringt die Migration mit.
|
||||||
|
DB::table('invoice_types')->insert([
|
||||||
|
'slug' => InvoiceType::INVOICE_TYPE_PROGRAM,
|
||||||
|
'name' => 'Programmkosten',
|
||||||
|
'sort_order' => 1,
|
||||||
|
'selectable' => true,
|
||||||
|
'counts_as_expense' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->costUnit = CostUnit::create([
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'name' => 'Sommerlager',
|
||||||
|
'type' => CostUnitType::COST_UNIT_TYPE_EVENT,
|
||||||
|
'distance_allowance' => 0.25,
|
||||||
|
'mail_on_new' => false,
|
||||||
|
'allow_new' => true,
|
||||||
|
'archived' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeEvent(): Event
|
||||||
|
{
|
||||||
|
$fee = EventParticipationFee::create([
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'type' => 'participant',
|
||||||
|
'name' => 'Sippe',
|
||||||
|
'description' => null,
|
||||||
|
'amount_standard' => 60.0,
|
||||||
|
'amount_reduced' => null,
|
||||||
|
'amount_solidarity' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return Event::create([
|
||||||
|
'cost_unit_id' => $this->costUnit->id,
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'name' => 'Sommerlager',
|
||||||
|
'identifier' => 'evt-' . uniqid(),
|
||||||
|
'location' => 'Ort',
|
||||||
|
'postal_code' => '00000',
|
||||||
|
'email' => 'e@example.com',
|
||||||
|
'start_date' => '2026-07-16',
|
||||||
|
'end_date' => '2026-07-20',
|
||||||
|
'early_bird_end' => '2026-06-20',
|
||||||
|
'registration_final_end' => '2026-07-01',
|
||||||
|
'early_bird_end_amount_increase' => 0,
|
||||||
|
'account_owner' => 'Owner',
|
||||||
|
'account_iban' => 'DE00',
|
||||||
|
'participation_fee_type' => 'fixed',
|
||||||
|
'participation_fee_1' => $fee->id,
|
||||||
|
'pay_per_day' => true,
|
||||||
|
'pay_direct' => false,
|
||||||
|
'tax_liable' => false,
|
||||||
|
'vat_rate' => 0,
|
||||||
|
'vat_pricing_mode' => 'inclusive',
|
||||||
|
'invoice_key' => 'WM-V-20260701',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeInvoice(string $type, float $amount): Invoice
|
||||||
|
{
|
||||||
|
return Invoice::create([
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'cost_unit_id' => $this->costUnit->id,
|
||||||
|
'invoice_number' => '2026-' . str_pad((string) Invoice::count() + 1, 4, '0', STR_PAD_LEFT),
|
||||||
|
'status' => InvoiceStatus::INVOICE_STATUS_NEW,
|
||||||
|
'type' => $type,
|
||||||
|
'donation' => false,
|
||||||
|
'contact_name' => 'Mika Muster',
|
||||||
|
'amount' => $amount,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
private function costUnitData(): array
|
||||||
|
{
|
||||||
|
return new CostUnitResource($this->costUnit->fresh())->toArray(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Die Ausgabenliste
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function test_a_refund_does_not_appear_as_an_expense_row(): void
|
||||||
|
{
|
||||||
|
$this->makeInvoice(InvoiceType::INVOICE_TYPE_PARTICIPATION_REFUND, 220.0);
|
||||||
|
|
||||||
|
$amounts = $this->costUnitData()['amounts'];
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey(InvoiceType::INVOICE_TYPE_PARTICIPATION_REFUND, $amounts);
|
||||||
|
$this->assertArrayHasKey(InvoiceType::INVOICE_TYPE_PROGRAM, $amounts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_refund_is_not_part_of_the_expense_total(): void
|
||||||
|
{
|
||||||
|
$this->makeInvoice(InvoiceType::INVOICE_TYPE_PARTICIPATION_REFUND, 220.0);
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta(0.0, $this->costUnitData()['overAllAmount']['value']->getAmount(), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_ordinary_invoice_of_the_same_amount_does_count(): void
|
||||||
|
{
|
||||||
|
// Gegenprobe: Es liegt am Typ, nicht am Betrag.
|
||||||
|
$this->makeInvoice(InvoiceType::INVOICE_TYPE_PROGRAM, 220.0);
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta(220.0, $this->costUnitData()['overAllAmount']['value']->getAmount(), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_cash_view_still_shows_the_refund(): void
|
||||||
|
{
|
||||||
|
// `totalAmount` speist Kostenstellen-Liste und Dashboard -- dort fließt das Geld tatsächlich ab.
|
||||||
|
$this->makeInvoice(InvoiceType::INVOICE_TYPE_PARTICIPATION_REFUND, 220.0);
|
||||||
|
|
||||||
|
$this->assertStringContainsString('220,00', $this->costUnitData()['totalAmount']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Die Bilanz der Veranstaltung
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function test_the_balance_is_not_reduced_by_a_refund(): void
|
||||||
|
{
|
||||||
|
// `fresh()`, weil die DB-Vorgaben (Förderung, Höchstbetrag) im frisch erzeugten Model noch nicht
|
||||||
|
// geladen sind und EventResource sie als Amount erwartet.
|
||||||
|
$event = $this->makeEvent()->fresh();
|
||||||
|
$before = new EventResource($event)->toArray(new Request())['totalBalance']['real']['value'];
|
||||||
|
|
||||||
|
$this->makeInvoice(InvoiceType::INVOICE_TYPE_PARTICIPATION_REFUND, 220.0);
|
||||||
|
|
||||||
|
$after = new EventResource($event->fresh())->toArray(new Request())['totalBalance']['real']['value'];
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta($before, $after, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_balance_is_reduced_by_an_ordinary_invoice(): void
|
||||||
|
{
|
||||||
|
// `fresh()`, weil die DB-Vorgaben (Förderung, Höchstbetrag) im frisch erzeugten Model noch nicht
|
||||||
|
// geladen sind und EventResource sie als Amount erwartet.
|
||||||
|
$event = $this->makeEvent()->fresh();
|
||||||
|
$before = new EventResource($event)->toArray(new Request())['totalBalance']['real']['value'];
|
||||||
|
|
||||||
|
$this->makeInvoice(InvoiceType::INVOICE_TYPE_PROGRAM, 220.0);
|
||||||
|
|
||||||
|
$after = new EventResource($event->fresh())->toArray(new Request())['totalBalance']['real']['value'];
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta($before - 220.0, $after, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Beiträge abgemeldeter Teilis
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function test_money_left_by_unregistered_participants_counts_as_income(): void
|
||||||
|
{
|
||||||
|
$event = $this->makeEvent();
|
||||||
|
$before = new EventResource($event->fresh())->toArray(new Request());
|
||||||
|
|
||||||
|
// 80 € sind nach einer Teilerstattung beim Verband geblieben.
|
||||||
|
$this->makeUnregisteredParticipant($event, 80.0);
|
||||||
|
|
||||||
|
$after = new EventResource($event->fresh())->toArray(new Request());
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta(80.0, $after['retainedFromUnregistered']['value'], 0.001);
|
||||||
|
|
||||||
|
// In beide Spalten: Das Geld ist da (real) und fließt nicht mehr ab (erwartet).
|
||||||
|
$this->assertEqualsWithDelta(
|
||||||
|
$before['income']['real']['amount']->getAmount() + 80.0,
|
||||||
|
$after['income']['real']['amount']->getAmount(),
|
||||||
|
0.001
|
||||||
|
);
|
||||||
|
$this->assertEqualsWithDelta(
|
||||||
|
$before['income']['expected']['amount']->getAmount() + 80.0,
|
||||||
|
$after['income']['expected']['amount']->getAmount(),
|
||||||
|
0.001
|
||||||
|
);
|
||||||
|
$this->assertEqualsWithDelta(
|
||||||
|
$before['totalBalance']['real']['value'] + 80.0,
|
||||||
|
$after['totalBalance']['real']['value'],
|
||||||
|
0.001
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_unregistered_participants_stay_out_of_lists_and_counts(): void
|
||||||
|
{
|
||||||
|
$event = $this->makeEvent();
|
||||||
|
$this->makeUnregisteredParticipant($event, 80.0);
|
||||||
|
|
||||||
|
$participantData = new EventResource($event->fresh())
|
||||||
|
->toArray(new Request())['participants']['participant'];
|
||||||
|
|
||||||
|
// Nur die Geldsumme kommt hinzu -- in Listen und Zahlen bleiben Abgemeldete außen vor.
|
||||||
|
$this->assertSame(0, $participantData['count']);
|
||||||
|
$this->assertArrayNotHasKey('participants', $participantData);
|
||||||
|
$this->assertEqualsWithDelta(0.0, $participantData['amount']['paid']['value'], 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_funding_does_not_grow_with_unregistered_participants(): void
|
||||||
|
{
|
||||||
|
$event = $this->makeEvent();
|
||||||
|
$before = new EventResource($event->fresh())->toArray(new Request())['supportPerson']['amount']->getAmount();
|
||||||
|
|
||||||
|
$this->makeUnregisteredParticipant($event, 80.0);
|
||||||
|
|
||||||
|
$after = new EventResource($event->fresh())->toArray(new Request())['supportPerson']['amount']->getAmount();
|
||||||
|
|
||||||
|
// Die wichtigste Gegenprobe: Wer nicht da war, bringt keine Förderung.
|
||||||
|
$this->assertEqualsWithDelta($before, $after, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_row_is_hidden_when_nothing_was_retained(): void
|
||||||
|
{
|
||||||
|
$event = $this->makeEvent();
|
||||||
|
$this->makeUnregisteredParticipant($event, 0.0);
|
||||||
|
|
||||||
|
// Die Zeile in der Übersicht hängt an diesem Wert -- bei 0 soll sie nicht erscheinen.
|
||||||
|
$this->assertEqualsWithDelta(
|
||||||
|
0.0,
|
||||||
|
new EventResource($event->fresh())->toArray(new Request())['retainedFromUnregistered']['value'],
|
||||||
|
0.001
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ein abgemeldeter Teili, bei dem der übergebene Betrag beim Verband geblieben ist. */
|
||||||
|
private function makeUnregisteredParticipant(Event $event, float $remaining): void
|
||||||
|
{
|
||||||
|
$event->participants()->create([
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'identifier' => 'p-' . uniqid(),
|
||||||
|
'invoice_sequence' => $event->participants()->count() + 1,
|
||||||
|
'firstname' => 'Mika',
|
||||||
|
'lastname' => 'Muster',
|
||||||
|
'participation_type' => 'participant',
|
||||||
|
'fee_type' => 'standard',
|
||||||
|
'sibling_reduction' => false,
|
||||||
|
'local_group' => $this->tenant->slug,
|
||||||
|
'birthday' => '2000-01-01',
|
||||||
|
'address_1' => 'Beispielstraße 3',
|
||||||
|
'postcode' => '11111',
|
||||||
|
'city' => 'Beispielstadt',
|
||||||
|
'email_1' => 'mika@example.com',
|
||||||
|
'phone_1' => '0170 0000000',
|
||||||
|
'arrival_date' => '2026-07-16',
|
||||||
|
'departure_date' => '2026-07-20',
|
||||||
|
'arrival_eating' => 1,
|
||||||
|
'departure_eating' => 1,
|
||||||
|
'amount' => 300.0,
|
||||||
|
'amount_paid' => $remaining,
|
||||||
|
'unregistered_at' => '2026-06-12',
|
||||||
|
'payment_purpose' => 'Sommerlager',
|
||||||
|
'payment_method' => PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION,
|
||||||
|
'efz_status' => EfzStatus::EFZ_STATUS_NOT_REQUIRED,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,4 +90,16 @@ class InvoiceTypeSelectionTest extends TestCase
|
|||||||
InvoiceType::selectable()->pluck('slug')->all()
|
InvoiceType::selectable()->pluck('slug')->all()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_the_refund_type_does_not_count_as_an_expense(): void
|
||||||
|
{
|
||||||
|
// Sie mindert die Einnahmenseite bereits -- als Ausgabe gezählt, stünde sie zweimal in der Bilanz.
|
||||||
|
$this->assertSame(
|
||||||
|
[InvoiceType::INVOICE_TYPE_PROGRAM, InvoiceType::INVOICE_TYPE_OTHER],
|
||||||
|
InvoiceType::countingAsExpense()->pluck('slug')->all()
|
||||||
|
);
|
||||||
|
|
||||||
|
$type = InvoiceType::where('slug', InvoiceType::INVOICE_TYPE_PARTICIPATION_REFUND)->first();
|
||||||
|
$this->assertFalse($type->counts_as_expense);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use App\Enumerations\CostUnitType;
|
|||||||
use App\Enumerations\InvoiceStatus;
|
use App\Enumerations\InvoiceStatus;
|
||||||
use App\Enumerations\InvoiceType;
|
use App\Enumerations\InvoiceType;
|
||||||
use App\Enumerations\RefundReason;
|
use App\Enumerations\RefundReason;
|
||||||
|
use App\Enumerations\RetentionReason;
|
||||||
use App\Enumerations\UserRole;
|
use App\Enumerations\UserRole;
|
||||||
use App\Mail\ParticipantRefundMails\RefundAcceptedMail;
|
use App\Mail\ParticipantRefundMails\RefundAcceptedMail;
|
||||||
use App\Mail\ParticipantRefundMails\RefundReleasedMail;
|
use App\Mail\ParticipantRefundMails\RefundReleasedMail;
|
||||||
@@ -206,17 +207,23 @@ class ParticipantRefundTest extends TestCase
|
|||||||
], $attributes));
|
], $attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der Vorgabewert 300,00 € entspricht dem gezahlten Beitrag -- es bleibt also nichts einbehalten und
|
||||||
|
* es braucht keinen Einbehaltungsgrund. Bei kleineren Beträgen muss einer mitgegeben werden.
|
||||||
|
*/
|
||||||
private function release(
|
private function release(
|
||||||
EventParticipant $participant,
|
EventParticipant $participant,
|
||||||
float $amount = 300.0,
|
float $amount = 300.0,
|
||||||
string $reason = RefundReason::SICKNESS,
|
string $reason = RefundReason::SICKNESS,
|
||||||
?string $note = null,
|
?string $note = null,
|
||||||
|
?string $retentionReason = null,
|
||||||
) {
|
) {
|
||||||
return new ReleaseRefundCommand(new ReleaseRefundRequest(
|
return new ReleaseRefundCommand(new ReleaseRefundRequest(
|
||||||
participant: $participant,
|
participant: $participant,
|
||||||
amount: new Amount($amount, 'Euro'),
|
amount: new Amount($amount, 'Euro'),
|
||||||
reason: $reason,
|
reason: $reason,
|
||||||
reasonNote: $note,
|
reasonNote: $note,
|
||||||
|
retentionReason: $retentionReason,
|
||||||
))->execute();
|
))->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,10 +303,12 @@ class ParticipantRefundTest extends TestCase
|
|||||||
{
|
{
|
||||||
$participant = $this->makeParticipant($this->makeEvent());
|
$participant = $this->makeParticipant($this->makeEvent());
|
||||||
|
|
||||||
$response = $this->release($participant, 220.0);
|
$response = $this->release($participant, 220.0, retentionReason: RetentionReason::CANCELLATION_FEE);
|
||||||
|
|
||||||
$this->assertTrue($response->success);
|
$this->assertTrue($response->success);
|
||||||
$this->assertEqualsWithDelta(220.0, $response->refund->amount->getAmount(), 0.001);
|
$this->assertEqualsWithDelta(220.0, $response->refund->amount->getAmount(), 0.001);
|
||||||
|
// Der Rest wird am Vorgang festgeschrieben, nicht später gerechnet.
|
||||||
|
$this->assertEqualsWithDelta(80.0, $response->refund->retained_amount->getAmount(), 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_release_is_rejected_without_an_amount(): void
|
public function test_release_is_rejected_without_an_amount(): void
|
||||||
@@ -626,6 +635,8 @@ class ParticipantRefundTest extends TestCase
|
|||||||
$response = $this->postJson('/api/v1/participant-refund/' . $participant->identifier . '/release', [
|
$response = $this->postJson('/api/v1/participant-refund/' . $participant->identifier . '/release', [
|
||||||
'amount' => '220,50',
|
'amount' => '220,50',
|
||||||
'reason' => RefundReason::SICKNESS,
|
'reason' => RefundReason::SICKNESS,
|
||||||
|
// Weniger als gezahlt -- der Rest bleibt beim Verband und braucht eine Begründung.
|
||||||
|
'retentionReason' => RetentionReason::CANCELLATION_FEE,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertOk()->assertJsonPath('status', 'success');
|
$response->assertOk()->assertJsonPath('status', 'success');
|
||||||
@@ -768,7 +779,13 @@ class ParticipantRefundTest extends TestCase
|
|||||||
public function test_the_release_mail_renders_with_the_link(): void
|
public function test_the_release_mail_renders_with_the_link(): void
|
||||||
{
|
{
|
||||||
$participant = $this->makeParticipant($this->makeEvent());
|
$participant = $this->makeParticipant($this->makeEvent());
|
||||||
$refund = $this->release($participant, 220.0, RefundReason::OTHER, 'Umzug')->refund;
|
$refund = $this->release(
|
||||||
|
$participant,
|
||||||
|
220.0,
|
||||||
|
RefundReason::OTHER,
|
||||||
|
'Umzug',
|
||||||
|
RetentionReason::CANCELLATION_FEE
|
||||||
|
)->refund;
|
||||||
|
|
||||||
$html = new RefundReleasedMail($participant, $refund)->render();
|
$html = new RefundReleasedMail($participant, $refund)->render();
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Enumerations\CostUnitType;
|
|||||||
use App\Enumerations\EfzStatus;
|
use App\Enumerations\EfzStatus;
|
||||||
use App\Enumerations\InvoiceStatus;
|
use App\Enumerations\InvoiceStatus;
|
||||||
use App\Enumerations\RefundReason;
|
use App\Enumerations\RefundReason;
|
||||||
|
use App\Enumerations\RetentionReason;
|
||||||
use App\Enumerations\UserRole;
|
use App\Enumerations\UserRole;
|
||||||
use App\Mail\ParticipantRefundMails\RefundAcceptedMail;
|
use App\Mail\ParticipantRefundMails\RefundAcceptedMail;
|
||||||
use App\Mail\ParticipantRefundMails\RefundReleasedMail;
|
use App\Mail\ParticipantRefundMails\RefundReleasedMail;
|
||||||
@@ -204,12 +205,18 @@ class RefundDirectCaptureTest extends TestCase
|
|||||||
], $attributes));
|
], $attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Freigabe mit bereits bekannter Bankverbindung. */
|
/**
|
||||||
|
* Freigabe mit bereits bekannter Bankverbindung.
|
||||||
|
*
|
||||||
|
* 220 von 300 gezahlten Euro: Es bleibt etwas beim Verband, deshalb gehört ein Einbehaltungsgrund
|
||||||
|
* dazu.
|
||||||
|
*/
|
||||||
private function releaseWithBankDetails(
|
private function releaseWithBankDetails(
|
||||||
?EventParticipant $participant = null,
|
?EventParticipant $participant = null,
|
||||||
string $owner = 'Mika Muster',
|
string $owner = 'Mika Muster',
|
||||||
string $iban = 'DE02120300000000202051',
|
string $iban = 'DE02120300000000202051',
|
||||||
float $amount = 220.0,
|
float $amount = 220.0,
|
||||||
|
?string $retentionReason = RetentionReason::CANCELLATION_FEE,
|
||||||
) {
|
) {
|
||||||
return new ReleaseRefundCommand(new ReleaseRefundRequest(
|
return new ReleaseRefundCommand(new ReleaseRefundRequest(
|
||||||
participant: $participant ?? $this->makeParticipant(),
|
participant: $participant ?? $this->makeParticipant(),
|
||||||
@@ -217,6 +224,7 @@ class RefundDirectCaptureTest extends TestCase
|
|||||||
reason: RefundReason::SICKNESS,
|
reason: RefundReason::SICKNESS,
|
||||||
accountOwner: $owner,
|
accountOwner: $owner,
|
||||||
accountIban: $iban,
|
accountIban: $iban,
|
||||||
|
retentionReason: $retentionReason,
|
||||||
))->execute();
|
))->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +260,7 @@ class RefundDirectCaptureTest extends TestCase
|
|||||||
$this->assertTrue($refund->wasCapturedByManagement());
|
$this->assertTrue($refund->wasCapturedByManagement());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_the_invoice_exists_and_the_paid_amount_is_cleared(): void
|
public function test_the_invoice_exists_and_the_paid_amount_is_settled(): void
|
||||||
{
|
{
|
||||||
$participant = $this->makeParticipant();
|
$participant = $this->makeParticipant();
|
||||||
|
|
||||||
@@ -263,7 +271,19 @@ class RefundDirectCaptureTest extends TestCase
|
|||||||
$this->assertEqualsWithDelta(220.0, $invoice->amount, 0.001);
|
$this->assertEqualsWithDelta(220.0, $invoice->amount, 0.001);
|
||||||
$this->assertSame($invoice->id, ParticipantRefund::first()->invoice_id);
|
$this->assertSame($invoice->id, ParticipantRefund::first()->invoice_id);
|
||||||
|
|
||||||
|
// 300 gezahlt, 220 erstattet -- die restlichen 80 bleiben beim Verband und werden dort geführt.
|
||||||
|
$this->assertEqualsWithDelta(80.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_full_refund_leaves_nothing_behind(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
|
||||||
|
$this->releaseWithBankDetails($participant, amount: 300.0, retentionReason: null);
|
||||||
|
|
||||||
$this->assertEqualsWithDelta(0.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
|
$this->assertEqualsWithDelta(0.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
|
||||||
|
$this->assertEqualsWithDelta(0.0, ParticipantRefund::first()->retained_amount->getAmount(), 0.001);
|
||||||
|
$this->assertNull(ParticipantRefund::first()->retention_reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_only_the_receipt_mail_goes_out(): void
|
public function test_only_the_receipt_mail_goes_out(): void
|
||||||
@@ -299,6 +319,7 @@ class RefundDirectCaptureTest extends TestCase
|
|||||||
participant: $this->makeParticipant(),
|
participant: $this->makeParticipant(),
|
||||||
amount: new Amount(220.0, 'Euro'),
|
amount: new Amount(220.0, 'Euro'),
|
||||||
reason: RefundReason::SICKNESS,
|
reason: RefundReason::SICKNESS,
|
||||||
|
retentionReason: RetentionReason::CANCELLATION_FEE,
|
||||||
))->execute()->refund;
|
))->execute()->refund;
|
||||||
|
|
||||||
$refund->update([
|
$refund->update([
|
||||||
@@ -379,6 +400,8 @@ class RefundDirectCaptureTest extends TestCase
|
|||||||
$this->postJson('/api/v1/participant-refund/' . $participant->identifier . '/release', [
|
$this->postJson('/api/v1/participant-refund/' . $participant->identifier . '/release', [
|
||||||
'amount' => '220,00',
|
'amount' => '220,00',
|
||||||
'reason' => RefundReason::SICKNESS,
|
'reason' => RefundReason::SICKNESS,
|
||||||
|
// 220 von 300 -- der Rest bleibt beim Verband und braucht eine Begründung.
|
||||||
|
'retentionReason' => RetentionReason::CANCELLATION_FEE,
|
||||||
'accountOwner' => 'Mika Muster',
|
'accountOwner' => 'Mika Muster',
|
||||||
'accountIban' => 'DE02 1203 0000 0000 2020 51',
|
'accountIban' => 'DE02 1203 0000 0000 2020 51',
|
||||||
])
|
])
|
||||||
@@ -396,6 +419,8 @@ class RefundDirectCaptureTest extends TestCase
|
|||||||
$this->postJson('/api/v1/participant-refund/' . $participant->identifier . '/release', [
|
$this->postJson('/api/v1/participant-refund/' . $participant->identifier . '/release', [
|
||||||
'amount' => '220,00',
|
'amount' => '220,00',
|
||||||
'reason' => RefundReason::SICKNESS,
|
'reason' => RefundReason::SICKNESS,
|
||||||
|
// 220 von 300 -- der Rest bleibt beim Verband und braucht eine Begründung.
|
||||||
|
'retentionReason' => RetentionReason::CANCELLATION_FEE,
|
||||||
'accountOwner' => '',
|
'accountOwner' => '',
|
||||||
'accountIban' => '',
|
'accountIban' => '',
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use App\Enumerations\EfzStatus;
|
|||||||
use App\Enumerations\InvoiceStatus;
|
use App\Enumerations\InvoiceStatus;
|
||||||
use App\Enumerations\InvoiceType;
|
use App\Enumerations\InvoiceType;
|
||||||
use App\Enumerations\RefundReason;
|
use App\Enumerations\RefundReason;
|
||||||
|
use App\Enumerations\RetentionReason;
|
||||||
use App\Enumerations\UserRole;
|
use App\Enumerations\UserRole;
|
||||||
use App\Mail\InvoiceMails\InvoiceMailsSubmittedConfirmationMail;
|
use App\Mail\InvoiceMails\InvoiceMailsSubmittedConfirmationMail;
|
||||||
use App\Models\CostUnit;
|
use App\Models\CostUnit;
|
||||||
@@ -200,11 +201,16 @@ class RefundInvoiceTest extends TestCase
|
|||||||
], $attributes));
|
], $attributes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Der ganze Ablauf: Freigabe durch die Aktionsleitung, Bestätigung durch den Teili. */
|
/**
|
||||||
|
* Der ganze Ablauf: Freigabe durch die Aktionsleitung, Bestätigung durch den Teili.
|
||||||
|
*
|
||||||
|
* 220 von 300 gezahlten Euro -- es bleibt etwas beim Verband, deshalb der Einbehaltungsgrund.
|
||||||
|
*/
|
||||||
private function runRefund(
|
private function runRefund(
|
||||||
?EventParticipant $participant = null,
|
?EventParticipant $participant = null,
|
||||||
float $amount = 220.0,
|
float $amount = 220.0,
|
||||||
string $reason = RefundReason::SICKNESS,
|
string $reason = RefundReason::SICKNESS,
|
||||||
|
?string $retentionReason = RetentionReason::CANCELLATION_FEE,
|
||||||
): ParticipantRefund {
|
): ParticipantRefund {
|
||||||
$participant ??= $this->makeParticipant($this->makeEvent());
|
$participant ??= $this->makeParticipant($this->makeEvent());
|
||||||
|
|
||||||
@@ -212,6 +218,7 @@ class RefundInvoiceTest extends TestCase
|
|||||||
participant: $participant,
|
participant: $participant,
|
||||||
amount: new Amount($amount, 'Euro'),
|
amount: new Amount($amount, 'Euro'),
|
||||||
reason: $reason,
|
reason: $reason,
|
||||||
|
retentionReason: $retentionReason,
|
||||||
))->execute()->refund;
|
))->execute()->refund;
|
||||||
|
|
||||||
new AcceptRefundCommand(new AcceptRefundRequest(
|
new AcceptRefundCommand(new AcceptRefundRequest(
|
||||||
@@ -359,6 +366,7 @@ class RefundInvoiceTest extends TestCase
|
|||||||
participant: $participant,
|
participant: $participant,
|
||||||
amount: new Amount(220.0, 'Euro'),
|
amount: new Amount(220.0, 'Euro'),
|
||||||
reason: RefundReason::SICKNESS,
|
reason: RefundReason::SICKNESS,
|
||||||
|
retentionReason: RetentionReason::CANCELLATION_FEE,
|
||||||
))->execute()->refund;
|
))->execute()->refund;
|
||||||
|
|
||||||
$response = new AcceptRefundCommand(new AcceptRefundRequest(
|
$response = new AcceptRefundCommand(new AcceptRefundRequest(
|
||||||
@@ -403,25 +411,26 @@ class RefundInvoiceTest extends TestCase
|
|||||||
Mail::assertSent(InvoiceMailsSubmittedConfirmationMail::class);
|
Mail::assertSent(InvoiceMailsSubmittedConfirmationMail::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_amount_paid_is_cleared_once_the_invoice_exists(): void
|
public function test_amount_paid_is_settled_once_the_invoice_exists(): void
|
||||||
{
|
{
|
||||||
$participant = $this->makeParticipant($this->makeEvent());
|
$participant = $this->makeParticipant($this->makeEvent());
|
||||||
$this->runRefund($participant);
|
$this->runRefund($participant);
|
||||||
|
|
||||||
// Mit der eingereichten Abrechnung ist der Beitrag auf dem Weg zurück und darf in den
|
// 300 gezahlt, 220 erstattet: `amount_paid` führt danach den Rest, der beim Verband bleibt.
|
||||||
// Zahlungsübersichten nicht länger als eingegangen stehen.
|
$this->assertEqualsWithDelta(80.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
|
||||||
$this->assertEqualsWithDelta(0.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
|
|
||||||
|
// Der Sollbetrag bleibt: was der Teili hätte zahlen müssen, ändert die Erstattung nicht.
|
||||||
$this->assertEqualsWithDelta(300.0, $participant->fresh()->amount->getAmount(), 0.001);
|
$this->assertEqualsWithDelta(300.0, $participant->fresh()->amount->getAmount(), 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_the_receipt_is_written_before_the_amount_is_cleared(): void
|
public function test_the_receipt_is_written_before_the_amount_is_settled(): void
|
||||||
{
|
{
|
||||||
$refund = $this->runRefund();
|
$refund = $this->runRefund();
|
||||||
|
|
||||||
// Reihenfolge-Falle: Beleg und Anmerkung weisen den gezahlten Beitrag aus. Wird zu früh genullt,
|
// Reihenfolge-Falle: Beleg und Anmerkung weisen den gezahlten Beitrag aus. Wird zu früh
|
||||||
// stünde dort 0,00 €. Der Beleg selbst liegt als PDF vor; nachprüfbar ist die Reihenfolge an der
|
// verrechnet, stünden dort 80,00 € statt 300,00 €. Der Beleg selbst liegt als PDF vor;
|
||||||
// Anmerkung, die im selben Schritt und aus derselben Quelle entsteht.
|
// nachprüfbar ist die Reihenfolge an der Anmerkung, die im selben Schritt entsteht.
|
||||||
$this->assertStringContainsString('300,00 Euro', Invoice::first()->comment);
|
$this->assertStringContainsString('300,00 Euro', Invoice::first()->comment);
|
||||||
$this->assertEqualsWithDelta(0.0, $refund->participant->fresh()->amount_paid->getAmount(), 0.001);
|
$this->assertEqualsWithDelta(80.0, $refund->participant->fresh()->amount_paid->getAmount(), 0.001);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,407 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundCommand;
|
||||||
|
use App\Domains\ParticipantRefund\Actions\AcceptRefund\AcceptRefundRequest;
|
||||||
|
use App\Domains\ParticipantRefund\Actions\CreateRefundDocument\CreateRefundDocumentCommand;
|
||||||
|
use App\Domains\ParticipantRefund\Actions\CreateRefundDocument\CreateRefundDocumentRequest;
|
||||||
|
use App\Domains\ParticipantRefund\Actions\ReleaseRefund\ReleaseRefundCommand;
|
||||||
|
use App\Domains\ParticipantRefund\Actions\ReleaseRefund\ReleaseRefundRequest;
|
||||||
|
use App\Enumerations\CostUnitType;
|
||||||
|
use App\Enumerations\EfzStatus;
|
||||||
|
use App\Enumerations\InvoiceStatus;
|
||||||
|
use App\Enumerations\RefundReason;
|
||||||
|
use App\Enumerations\RetentionReason;
|
||||||
|
use App\Enumerations\UserRole;
|
||||||
|
use App\Mail\ParticipantRefundMails\RefundAcceptedMail;
|
||||||
|
use App\Models\CostUnit;
|
||||||
|
use App\Models\DocumentTemplate;
|
||||||
|
use App\Models\Event;
|
||||||
|
use App\Models\EventParticipant;
|
||||||
|
use App\Models\ParticipantRefund;
|
||||||
|
use App\Models\PaymentMethod;
|
||||||
|
use App\Models\Tenant;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Providers\DocumentTemplateRenderProvider;
|
||||||
|
use App\RelationModels\EventParticipationFee;
|
||||||
|
use App\ValueObjects\Amount;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use ReflectionMethod;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Der einbehaltene Teil einer Erstattung.
|
||||||
|
*
|
||||||
|
* Wird weniger erstattet als gezahlt wurde, bleibt Geld beim Verband. Das muss begründet sein und überall
|
||||||
|
* sichtbar bleiben -- und `amount_paid` muss es weiter führen, weil die Einnahmenrechnung darauf aufbaut.
|
||||||
|
*/
|
||||||
|
class RefundRetentionTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private Tenant $tenant;
|
||||||
|
|
||||||
|
private int $sequence = 0;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->tenant = Tenant::create([
|
||||||
|
'slug' => 'wm',
|
||||||
|
'name' => 'Wilde Möhre',
|
||||||
|
'address_1' => 'Musterweg 1',
|
||||||
|
'email' => 't@example.com',
|
||||||
|
'email_finance' => 'finance@example.com',
|
||||||
|
'url' => parse_url(config('app.url'), PHP_URL_HOST),
|
||||||
|
'account_name' => 'Test e.V.',
|
||||||
|
'account_iban' => 'DE00',
|
||||||
|
'account_bic' => 'XY',
|
||||||
|
'city' => 'Stadt',
|
||||||
|
'postcode' => '00000',
|
||||||
|
'invoice_prefix' => 'WM',
|
||||||
|
'is_active_local_group' => true,
|
||||||
|
'has_active_instance' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
app()->instance('tenant', $this->tenant);
|
||||||
|
|
||||||
|
DB::table('participation_types')->insert(['slug' => 'participant', 'name' => 'Teilnehmer']);
|
||||||
|
DB::table('participation_fee_types')->insert(['slug' => 'fixed', 'name' => 'Fix']);
|
||||||
|
DB::table('cost_unit_types')->insert(['slug' => CostUnitType::COST_UNIT_TYPE_EVENT, 'name' => 'Veranstaltung']);
|
||||||
|
DB::table('invoice_status')->insert(['slug' => InvoiceStatus::INVOICE_STATUS_NEW]);
|
||||||
|
PaymentMethod::create(['slug' => PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION]);
|
||||||
|
EfzStatus::create(['slug' => EfzStatus::EFZ_STATUS_NOT_REQUIRED, 'name' => 'Nicht erforderlich']);
|
||||||
|
|
||||||
|
foreach ([UserRole::USER_ROLE_ADMIN, UserRole::USER_ROLE_GROUP_LEADER, UserRole::USER_ROLE_USER] as $role) {
|
||||||
|
UserRole::create(['slug' => $role, 'name' => $role]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->seedTemplate();
|
||||||
|
|
||||||
|
Storage::fake('local');
|
||||||
|
Mail::fake();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Die Vorlage setzt den Datenblock ein -- daran lassen sich die Belegzeilen prüfen. */
|
||||||
|
private function seedTemplate(): void
|
||||||
|
{
|
||||||
|
DocumentTemplate::create([
|
||||||
|
'document_type' => DocumentTemplate::TYPE_PARTICIPANT_REFUND,
|
||||||
|
'block' => DocumentTemplate::BLOCK_LAYOUT,
|
||||||
|
'content' => '<div>{block:body}</div>',
|
||||||
|
'sort_order' => 10,
|
||||||
|
]);
|
||||||
|
|
||||||
|
DocumentTemplate::create([
|
||||||
|
'document_type' => DocumentTemplate::TYPE_PARTICIPANT_REFUND,
|
||||||
|
'block' => DocumentTemplate::BLOCK_BODY,
|
||||||
|
'content' => '{details_table}<p>{retained_amount} / {retention_note}</p>',
|
||||||
|
'sort_order' => 20,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeEvent(): Event
|
||||||
|
{
|
||||||
|
$fee = EventParticipationFee::create([
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'type' => 'participant',
|
||||||
|
'name' => 'Sippe',
|
||||||
|
'description' => null,
|
||||||
|
'amount_standard' => 60.0,
|
||||||
|
'amount_reduced' => null,
|
||||||
|
'amount_solidarity' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$costUnit = CostUnit::create([
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'name' => 'Sommerlager',
|
||||||
|
'type' => CostUnitType::COST_UNIT_TYPE_EVENT,
|
||||||
|
'distance_allowance' => 0.25,
|
||||||
|
'mail_on_new' => false,
|
||||||
|
'allow_new' => true,
|
||||||
|
'archived' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return Event::create([
|
||||||
|
'cost_unit_id' => $costUnit->id,
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'name' => 'Sommerlager',
|
||||||
|
'identifier' => 'evt-' . uniqid(),
|
||||||
|
'location' => 'Ort',
|
||||||
|
'postal_code' => '00000',
|
||||||
|
'email' => 'e@example.com',
|
||||||
|
'start_date' => '2026-07-16',
|
||||||
|
'end_date' => '2026-07-20',
|
||||||
|
'early_bird_end' => '2026-06-20',
|
||||||
|
'registration_final_end' => '2026-07-01',
|
||||||
|
'early_bird_end_amount_increase' => 0,
|
||||||
|
'account_owner' => 'Owner',
|
||||||
|
'account_iban' => 'DE00',
|
||||||
|
'participation_fee_type' => 'fixed',
|
||||||
|
'participation_fee_1' => $fee->id,
|
||||||
|
'pay_per_day' => true,
|
||||||
|
'pay_direct' => false,
|
||||||
|
'tax_liable' => false,
|
||||||
|
'vat_rate' => 0,
|
||||||
|
'vat_pricing_mode' => 'inclusive',
|
||||||
|
// Je Test können mehrere Veranstaltungen entstehen; der Schlüssel ist eindeutig.
|
||||||
|
'invoice_key' => 'WM-V-2026070' . ($this->sequence + 1),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeParticipant(array $attributes = []): EventParticipant
|
||||||
|
{
|
||||||
|
$this->sequence++;
|
||||||
|
|
||||||
|
$user = User::create([
|
||||||
|
'username' => 'teili-' . uniqid() . '@example.com',
|
||||||
|
'email' => 'teili-' . uniqid() . '@example.com',
|
||||||
|
'firstname' => 'Mika',
|
||||||
|
'lastname' => 'Muster',
|
||||||
|
'password' => bcrypt('secret'),
|
||||||
|
'local_group' => $this->tenant->slug,
|
||||||
|
'user_role_main' => UserRole::USER_ROLE_USER,
|
||||||
|
'user_role_local_group' => UserRole::USER_ROLE_USER,
|
||||||
|
'active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->makeEvent()->participants()->create(array_merge([
|
||||||
|
'tenant' => $this->tenant->slug,
|
||||||
|
'identifier' => 'p-' . uniqid(),
|
||||||
|
'invoice_sequence' => $this->sequence,
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'firstname' => 'Mika',
|
||||||
|
'lastname' => 'Muster',
|
||||||
|
'participation_type' => 'participant',
|
||||||
|
'fee_type' => 'standard',
|
||||||
|
'sibling_reduction' => false,
|
||||||
|
'local_group' => $this->tenant->slug,
|
||||||
|
'birthday' => '2000-01-01',
|
||||||
|
'address_1' => 'Beispielstraße 3',
|
||||||
|
'postcode' => '11111',
|
||||||
|
'city' => 'Beispielstadt',
|
||||||
|
'email_1' => 'mika@example.com',
|
||||||
|
'phone_1' => '0170 0000000',
|
||||||
|
'arrival_date' => '2026-07-16',
|
||||||
|
'departure_date' => '2026-07-20',
|
||||||
|
'arrival_eating' => 1,
|
||||||
|
'departure_eating' => 1,
|
||||||
|
'amount' => 300.0,
|
||||||
|
'amount_paid' => 300.0,
|
||||||
|
'unregistered_at' => '2026-06-12',
|
||||||
|
'payment_purpose' => 'Sommerlager',
|
||||||
|
'payment_method' => PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION,
|
||||||
|
'efz_status' => EfzStatus::EFZ_STATUS_NOT_REQUIRED,
|
||||||
|
], $attributes));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function release(
|
||||||
|
EventParticipant $participant,
|
||||||
|
float $amount,
|
||||||
|
?string $retentionReason = null,
|
||||||
|
?string $retentionNote = null,
|
||||||
|
) {
|
||||||
|
return new ReleaseRefundCommand(new ReleaseRefundRequest(
|
||||||
|
participant: $participant,
|
||||||
|
amount: new Amount($amount, 'Euro'),
|
||||||
|
reason: RefundReason::SICKNESS,
|
||||||
|
retentionReason: $retentionReason,
|
||||||
|
retentionReasonNote: $retentionNote,
|
||||||
|
))->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function accept(ParticipantRefund $refund): void
|
||||||
|
{
|
||||||
|
new AcceptRefundCommand(new AcceptRefundRequest(
|
||||||
|
refund: $refund,
|
||||||
|
accountOwner: 'Mika Muster',
|
||||||
|
accountIban: 'DE02120300000000202051',
|
||||||
|
declarationAccepted: true,
|
||||||
|
))->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Der Grund ist Pflicht, sobald etwas bleibt
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function test_a_partial_refund_without_a_reason_is_refused(): void
|
||||||
|
{
|
||||||
|
$response = $this->release($this->makeParticipant(), 220.0);
|
||||||
|
|
||||||
|
$this->assertFalse($response->success);
|
||||||
|
$this->assertStringContainsString('einbehalten', $response->message);
|
||||||
|
$this->assertSame(0, ParticipantRefund::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_full_refund_needs_no_reason(): void
|
||||||
|
{
|
||||||
|
$response = $this->release($this->makeParticipant(), 300.0);
|
||||||
|
|
||||||
|
$this->assertTrue($response->success);
|
||||||
|
$this->assertNull($response->refund->retention_reason);
|
||||||
|
$this->assertEqualsWithDelta(0.0, $response->refund->retained_amount->getAmount(), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_free_text_retention_reason_needs_its_note(): void
|
||||||
|
{
|
||||||
|
$response = $this->release($this->makeParticipant(), 220.0, RetentionReason::CUSTOM, ' ');
|
||||||
|
|
||||||
|
$this->assertFalse($response->success);
|
||||||
|
$this->assertStringContainsString('Erläuterung', $response->message);
|
||||||
|
$this->assertSame(0, ParticipantRefund::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_unknown_retention_reason_is_refused(): void
|
||||||
|
{
|
||||||
|
$response = $this->release($this->makeParticipant(), 220.0, 'erfunden');
|
||||||
|
|
||||||
|
$this->assertFalse($response->success);
|
||||||
|
$this->assertSame(0, ParticipantRefund::count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_reason_sent_with_a_full_refund_is_not_stored(): void
|
||||||
|
{
|
||||||
|
// Im Formular ist das Feld dann gar nicht sichtbar -- ein Wert ohne Bezug gehört nicht in die DB.
|
||||||
|
$response = $this->release($this->makeParticipant(), 300.0, RetentionReason::CANCELLATION_FEE);
|
||||||
|
|
||||||
|
$this->assertTrue($response->success);
|
||||||
|
$this->assertNull($response->refund->retention_reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_note_is_only_stored_for_reasons_that_require_it(): void
|
||||||
|
{
|
||||||
|
$withNote = $this->release($this->makeParticipant(), 220.0, RetentionReason::CUSTOM, 'Bereits gebuchte Bahnfahrt');
|
||||||
|
$this->assertSame('Bereits gebuchte Bahnfahrt', $withNote->refund->retention_reason_note);
|
||||||
|
|
||||||
|
$ignored = $this->release($this->makeParticipant(), 220.0, RetentionReason::MATERIAL, 'wird verworfen');
|
||||||
|
$this->assertNull($ignored->refund->retention_reason_note);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Was beim Verband bleibt
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function test_the_retained_amount_is_recorded_at_release(): void
|
||||||
|
{
|
||||||
|
$response = $this->release($this->makeParticipant(), 220.0, RetentionReason::CANCELLATION_FEE);
|
||||||
|
|
||||||
|
// Festgeschrieben, nicht gerechnet: Nach dem Einreichen führt `amount_paid` bereits den Rest.
|
||||||
|
$this->assertEqualsWithDelta(80.0, $response->refund->retained_amount->getAmount(), 0.001);
|
||||||
|
$this->assertTrue($response->refund->hasRetention());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_amount_paid_keeps_the_retained_share(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$refund = $this->release($participant, 220.0, RetentionReason::CANCELLATION_FEE)->refund;
|
||||||
|
|
||||||
|
$this->accept($refund);
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta(80.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_full_refund_leaves_nothing(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$refund = $this->release($participant, 300.0)->refund;
|
||||||
|
|
||||||
|
$this->accept($refund);
|
||||||
|
|
||||||
|
$this->assertEqualsWithDelta(0.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_second_refund_is_capped_at_the_remainder(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$this->accept($this->release($participant, 220.0, RetentionReason::CANCELLATION_FEE)->refund);
|
||||||
|
|
||||||
|
// Es liegen noch 80 € beim Verband -- mehr kann nicht zurückgehen.
|
||||||
|
$tooMuch = $this->release($participant->fresh(), 100.0, RetentionReason::CANCELLATION_FEE);
|
||||||
|
$this->assertFalse($tooMuch->success);
|
||||||
|
|
||||||
|
$fits = $this->release($participant->fresh(), 80.0);
|
||||||
|
$this->assertTrue($fits->success);
|
||||||
|
$this->assertEqualsWithDelta(0.0, $fits->refund->retained_amount->getAmount(), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Sichtbarkeit
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function test_the_receipt_names_the_retained_amount_and_reason(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$refund = $this->release($participant, 220.0, RetentionReason::CANCELLATION_FEE)->refund;
|
||||||
|
$this->accept($refund);
|
||||||
|
|
||||||
|
$html = $this->renderReceipt($refund->fresh());
|
||||||
|
|
||||||
|
$this->assertStringContainsString('Einbehalten', $html);
|
||||||
|
$this->assertStringContainsString('80,00', $html);
|
||||||
|
$this->assertStringContainsString('Stornogebühr laut Ausschreibung', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_receipt_stays_silent_on_a_full_refund(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$refund = $this->release($participant, 300.0)->refund;
|
||||||
|
$this->accept($refund);
|
||||||
|
|
||||||
|
$this->assertStringNotContainsString('Einbehalten', $this->renderReceipt($refund->fresh()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_mail_explains_the_retention(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$refund = $this->release($participant, 220.0, RetentionReason::CUSTOM, 'Bereits gebuchte Bahnfahrt')->refund;
|
||||||
|
$this->accept($refund);
|
||||||
|
|
||||||
|
$html = new RefundAcceptedMail($participant, $refund->fresh())->render();
|
||||||
|
|
||||||
|
$this->assertStringContainsString('80,00 Euro', $html);
|
||||||
|
$this->assertStringContainsString('Sonstiger Grund', $html);
|
||||||
|
$this->assertStringContainsString('Bereits gebuchte Bahnfahrt', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_mail_stays_silent_on_a_full_refund(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$refund = $this->release($participant, 300.0)->refund;
|
||||||
|
$this->accept($refund);
|
||||||
|
|
||||||
|
$this->assertStringNotContainsString('verbleiben beim Verband', new RefundAcceptedMail($participant, $refund->fresh())->render());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_resource_carries_the_retention_for_the_lists(): void
|
||||||
|
{
|
||||||
|
$participant = $this->makeParticipant();
|
||||||
|
$refund = $this->release($participant, 220.0, RetentionReason::CANCELLATION_FEE)->refund;
|
||||||
|
$this->accept($refund);
|
||||||
|
|
||||||
|
$data = $refund->fresh()->toResource()->toArray(request());
|
||||||
|
|
||||||
|
$this->assertTrue($data['hasRetention']);
|
||||||
|
$this->assertSame('80,00 Euro', $data['retainedAmount']);
|
||||||
|
$this->assertSame('Stornogebühr laut Ausschreibung', $data['retentionReasonLabel']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function renderReceipt(ParticipantRefund $refund): string
|
||||||
|
{
|
||||||
|
$command = new CreateRefundDocumentCommand(new CreateRefundDocumentRequest($refund));
|
||||||
|
$number = new ReflectionMethod($command, 'documentNumber')->invoke($command);
|
||||||
|
$tokens = new ReflectionMethod($command, 'buildTokens')->invoke($command, $number);
|
||||||
|
|
||||||
|
return new DocumentTemplateRenderProvider(DocumentTemplate::TYPE_PARTICIPANT_REFUND)->render($tokens);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user