findAccountId('1200'); $umbuchungId = $this->findAccountId('1800'); $ausgabeId = $this->findAccountId('4920'); if (!$bankId || !$umbuchungId || !$ausgabeId) { $this->assert(false, 'Benötigte Konten (1200, 1800, 4920) fehlen – SKR03-Seed vorhanden?'); return; } $datum = date('Y-m-d'); $belegId = Beleg::create([ 'beleg_nr' => 'TEST-1800-' . uniqid(), 'filename' => 'umbuchung-test.pdf', 'storage_path' => '', 'mime_type' => 'application/pdf', 'file_hash' => hash('sha256', 'umbuchung-test-' . uniqid()), 'beleg_datum' => $datum, 'belegtyp' => 'Eingangsrechnung', ]); $this->assertGreaterThan(0, $belegId, 'Beleg angelegt'); // Normale Buchung: 100 € netto + 19 % = 119 € brutto Booking::create([ 'beleg_id' => $belegId, 'buchungs_datum' => $datum, 'buchungstyp' => 'Ausgabe', 'kategorie_konto_id' => $ausgabeId, 'zahlungskonto_id' => $bankId, 'betrag_netto' => 100.00, 'ust_satz' => 19.0, 'buchungstext' => 'Normale Buchung', ]); // Steuerliche Umbuchung auf Konto 1800 (darf nicht in Belegsumme einfließen) Booking::create([ 'beleg_id' => $belegId, 'buchungs_datum' => $datum, 'buchungstyp' => 'Ausgabe', 'kategorie_konto_id' => $ausgabeId, 'zahlungskonto_id' => $umbuchungId, 'betrag_netto' => 50.00, 'ust_satz' => 0.0, 'buchungstext' => 'Steuerliche Umbuchung 1800', ]); // Beleg::find() darf nur 119,00 liefern (nicht 169,00) $beleg = Beleg::find($belegId); $this->assertEquals( 119.00, round((float)($beleg['betrag_brutto'] ?? 0), 2), 'Beleg::find() – betrag_brutto = 119,00 (ohne Konto-1800-Umbuchung)' ); // Beleg::all() – dieselbe Filterung in der Listenansicht $result = Beleg::all([], 1, 9999); $found = null; foreach ($result['rows'] as $row) { if ((int)$row['id'] === $belegId) { $found = $row; break; } } $this->assert($found !== null, 'Beleg erscheint in Beleg::all()'); $this->assertEquals( 119.00, round((float)($found['betrag_brutto'] ?? 0), 2), 'Beleg::all() – betrag_brutto = 119,00 (ohne Konto-1800-Umbuchung)' ); // Brutto-Suche findet den Beleg über 119,00 – nicht über 169,00 $resHit = Beleg::all(['search' => '119.00'], 1, 9999); $foundByBrutto = false; foreach ($resHit['rows'] as $row) { if ((int)$row['id'] === $belegId) { $foundByBrutto = true; break; } } $this->assert($foundByBrutto, 'Brutto-Suche nach 119.00 findet den Beleg'); $resMiss = Beleg::all(['search' => '169.00'], 1, 9999); $foundByWrong = false; foreach ($resMiss['rows'] as $row) { if ((int)$row['id'] === $belegId) { $foundByWrong = true; break; } } $this->assert(!$foundByWrong, 'Brutto-Suche nach 169.00 findet den Beleg NICHT'); } }