Steuerkram/tests/22_RechnungZahlungszielTest.php

63 lines
2.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
use Steuerkram\Models\Customer;
use Steuerkram\Models\Setting;
class RechnungZahlungszielTest extends TestCase
{
protected string $testName = 'Test 22: Rechnung – Zahlungsziel aus Kundendatensatz';
public function run(): void
{
$customerId = Customer::create([
'nachname' => 'ZahlungszielTestKunde',
'strasse' => 'Musterstr. 1',
'plz' => '12345',
'ort' => 'Musterstadt',
'land' => 'DE',
'payment_days' => 30,
]);
$customer = Customer::find($customerId);
$this->assert($customer !== false, 'Kunde wurde angelegt');
$this->assertEquals(30, (int)$customer['payment_days'], 'Kundendatensatz enthält payment_days=30');
// Simuliere Controller-Logik: customer_id per GET → payment_days vorbelegen
$preCustomerId = $customerId;
$invoiceDefaults = [
'rechnungs_datum' => date('Y-m-d'),
'leistungszeitraum_von' => date('Y-m-01'),
'leistungszeitraum_bis' => date('Y-m-t'),
];
if ($preCustomerId > 0) {
$c = Customer::find($preCustomerId);
if ($c) {
$invoiceDefaults['customer_id'] = $preCustomerId;
$invoiceDefaults['payment_days'] = $c['payment_days'];
}
}
$this->assertEquals($customerId, $invoiceDefaults['customer_id'], 'customer_id in Rechnungsdefaults gesetzt');
$this->assertEquals(30, (int)$invoiceDefaults['payment_days'], 'payment_days aus Kundendaten vorbelegt');
// Ohne vorausgewählten Kunden bleibt payment_days ungesetzt
$defaultsOhneKunde = [
'rechnungs_datum' => date('Y-m-d'),
];
$this->assert(!isset($defaultsOhneKunde['payment_days']), 'payment_days ohne Kunden nicht gesetzt');
// Anderer Kunde mit abweichendem Zahlungsziel
$customer2Id = Customer::create([
'nachname' => 'ZahlungszielTestKunde2',
'strasse' => 'Testgasse 2',
'plz' => '54321',
'ort' => 'Testdorf',
'land' => 'DE',
'payment_days' => 7,
]);
$c2 = Customer::find($customer2Id);
$this->assertEquals(7, (int)$c2['payment_days'], 'Zweiter Kunde hat payment_days=7');
}
}