Besseres Handling Rückerstattungen

This commit is contained in:
2026-09-06 20:11:50 +02:00
parent e730d6db63
commit b9795f08f0
26 changed files with 927 additions and 104 deletions
+81 -2
View File
@@ -221,6 +221,7 @@ class RefundInvoiceTest extends TestCase
float $amount = 220.0,
string $reason = RefundReason::SICKNESS,
?string $retentionReason = RetentionReason::CANCELLATION_FEE,
bool $donation = false,
): ParticipantRefund {
$participant ??= $this->makeParticipant($this->makeEvent());
@@ -231,11 +232,14 @@ class RefundInvoiceTest extends TestCase
retentionReason: $retentionReason,
))->execute()->refund;
// Wer spendet, gibt keine Bankverbindung an -- der Server verlangt sie dann auch nicht.
new AcceptRefundCommand(new AcceptRefundRequest(
refund: $refund,
accountOwner: 'Mika Muster',
accountIban: 'DE02120300000000202051',
accountOwner: $donation ? '' : 'Mika Muster',
accountIban: $donation ? '' : 'DE02120300000000202051',
declarationAccepted: true,
donation: $donation,
accountDeclarationAccepted: !$donation,
))->execute();
return $refund->fresh();
@@ -262,6 +266,80 @@ class RefundInvoiceTest extends TestCase
$this->assertFalse((bool) $invoice->donation);
}
/*
|--------------------------------------------------------------------------
| Spenden statt auszahlen
|--------------------------------------------------------------------------
*/
public function test_a_donated_refund_becomes_a_donated_invoice(): void
{
$this->runRefund(donation: true);
$invoice = Invoice::first();
$this->assertNotNull($invoice);
$this->assertTrue((bool) $invoice->donation);
// Derselbe Weg wie sonst: Nummernkreis, Status und Typ der Abrechnung ändern sich nicht.
$this->assertSame(InvoiceStatus::INVOICE_STATUS_NEW, $invoice->status);
$this->assertSame(InvoiceType::INVOICE_TYPE_PARTICIPATION_REFUND, $invoice->type);
$this->assertEqualsWithDelta(220.0, $invoice->amount, 0.001);
}
public function test_a_donation_carries_no_bank_details(): void
{
$refund = $this->runRefund(donation: true);
// Weder am Vorgang noch an der Abrechnung -- und `null`, nicht Leerstring: Der SEPA-Export
// unterscheidet daran, ob es etwas auszuzahlen gibt.
$this->assertNull($refund->account_owner);
$this->assertNull($refund->account_iban);
$this->assertNull(Invoice::first()->contact_bank_owner);
$this->assertNull(Invoice::first()->contact_bank_iban);
}
public function test_the_refund_reads_the_donation_from_its_invoice(): void
{
// Am Vorgang steht sie nicht: Die Abrechnung führt sie, damit beide nicht auseinanderlaufen.
$this->assertTrue($this->runRefund(donation: true)->isDonation());
}
public function test_a_payout_is_no_donation(): void
{
$this->assertFalse($this->runRefund()->isDonation());
}
public function test_a_donation_still_gets_a_receipt(): void
{
$this->runRefund(donation: true);
$invoice = Invoice::first();
$this->assertNotNull($invoice->document_filename);
Storage::disk('local')->assertExists($invoice->document_filename);
$this->assertStringStartsWith('%PDF', Storage::disk('local')->get($invoice->document_filename));
}
public function test_a_donation_settles_the_amount_paid_like_a_payout(): void
{
$participant = $this->makeParticipant($this->makeEvent());
$this->runRefund($participant, donation: true);
// Was einbehalten wurde, bleibt einbehaltener Teilnahmebeitrag; der erstattungsfähige Teil ist
// ab jetzt eine Spende und wird über die Abrechnung geführt, nicht mehr über den Beitrag.
$this->assertEqualsWithDelta(80.0, $participant->fresh()->amount_paid->getAmount(), 0.001);
}
public function test_the_notice_of_a_donation_names_it(): void
{
$this->runRefund(donation: true);
// Die Schatzmeisterei sieht die Abrechnung ohne den Vorgang dahinter -- warum keine
// Bankverbindung dabei ist, steht nur hier.
$this->assertStringContainsString('Spende statt Rückerstattung', Invoice::first()->comment);
$this->assertStringContainsString('Gezahlter Beitrag vor Erstattung: 300,00 Euro', Invoice::first()->comment);
}
public function test_contact_details_come_from_the_participant(): void
{
$this->runRefund();
@@ -384,6 +462,7 @@ class RefundInvoiceTest extends TestCase
accountOwner: 'Mika Muster',
accountIban: 'DE02120300000000202051',
declarationAccepted: true,
accountDeclarationAccepted: true,
))->execute();
$this->assertFalse($response->success);