49 lines
1.9 KiB
PHP
49 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Finanzmanager\Models\Buchung;
|
|
use Finanzmanager\Models\Konto;
|
|
|
|
/**
|
|
* Neue Buchungen ohne Nummer bekommen automatisch die nächste laufende Nummer
|
|
* ihres Kontos; eine vorgegebene Nummer bleibt erhalten.
|
|
*/
|
|
class BuchungsnummerTest extends TestCase
|
|
{
|
|
protected string $testName = 'Test 53: Automatische Buchungsnummer';
|
|
|
|
public function run(): void
|
|
{
|
|
$this->mandantAnlegen();
|
|
|
|
$a = Konto::anlegen(['name' => 'Nummer A', 'kontoart' => 'bank', 'anfangssaldo' => 0, 'aktiv' => 1]);
|
|
$b = Konto::anlegen(['name' => 'Nummer B', 'kontoart' => 'bank', 'anfangssaldo' => 0, 'aktiv' => 1]);
|
|
|
|
$erste = $this->buche($a);
|
|
$this->assertEquals('1', Buchung::find($erste)['nummer'], 'Die erste Buchung eines Kontos bekommt die 1');
|
|
$zweite = $this->buche($a);
|
|
$this->assertEquals('2', Buchung::find($zweite)['nummer'], 'Die nächste zählt hoch');
|
|
$this->assertEquals('1', Buchung::find($this->buche($b))['nummer'], 'Jedes Konto zählt für sich');
|
|
|
|
$fest = $this->buche($a, '603');
|
|
$this->assertEquals('603', Buchung::find($fest)['nummer'], 'Eine vorgegebene Nummer bleibt');
|
|
$this->assertEquals('604', Buchung::find($this->buche($a))['nummer'], 'Danach geht es hinter der höchsten weiter');
|
|
|
|
$this->buche($a, 'Scheck-A');
|
|
$this->assertEquals('605', Buchung::find($this->buche($a))['nummer'], 'Nichtnumerische Nummern stören nicht');
|
|
|
|
Buchung::speichern($erste, [
|
|
'konto_id' => $a, 'datum' => '2026-05-01', 'betrag' => -1.0, 'nummer' => '',
|
|
]);
|
|
$this->assertEquals('', Buchung::find($erste)['nummer'], 'Beim Ändern wird nichts nachvergeben');
|
|
}
|
|
|
|
private function buche(int $konto, string $nummer = ''): int
|
|
{
|
|
return Buchung::anlegen([
|
|
'konto_id' => $konto, 'datum' => '2026-05-01', 'betrag' => -1.0,
|
|
'empfaenger' => 'Test', 'nummer' => $nummer,
|
|
]);
|
|
}
|
|
}
|