Fix: alloc_betrag und bank_tx_id bleiben bei Validierungsfehlern in der Buchungsmaske erhalten

This commit is contained in:
fds2610-bot 2026-05-15 18:02:09 +02:00
parent d31e5afa57
commit 2034372210
2 changed files with 26 additions and 11 deletions

View file

@ -215,6 +215,13 @@ class BookingController
$accounts = \Steuerkram\Models\Account::all(['aktiv' => 1]); $accounts = \Steuerkram\Models\Account::all(['aktiv' => 1]);
$integrity = \Steuerkram\Models\Beleg::verifyIntegrity($belegId); $integrity = \Steuerkram\Models\Beleg::verifyIntegrity($belegId);
$assets = \Steuerkram\Models\Asset::all(); $assets = \Steuerkram\Models\Asset::all();
$linked = BankTransaction::findByBelegId($belegId);
// Bank-Kontext aus POST-Daten wiederherstellen (damit alloc_betrag nach Validierungsfehler erhalten bleibt)
$bankTx = null;
if (!empty($formData['bank_tx_id'])) {
$bankTx = BankTransaction::find((int)$formData['bank_tx_id']);
}
$view = new View(); $view = new View();
$view->render('layout/base.php', [ $view->render('layout/base.php', [
@ -227,6 +234,9 @@ class BookingController
'assets' => $assets, 'assets' => $assets,
'formErrors' => $errors, 'formErrors' => $errors,
'formData' => $formData, 'formData' => $formData,
'bankTx' => $bankTx,
'bankTxBrutto' => $bankTx ? (float)($formData['alloc_betrag'] ?: abs((float)$bankTx['wert'])) : 0.0,
'linkedBankTx' => $linked,
]), ]),
]); ]);
} }

View file

@ -387,9 +387,14 @@ $suppliers = $suppliers ?? [];
</div> </div>
<?php endif; ?> <?php endif; ?>
<form method="post" action="/belege/<?= $h($beleg['id']) ?>/bookings"> <form method="post" action="/belege/<?= $h($beleg['id']) ?>/bookings">
<?php if ($bankTx ?? null): ?> <?php
<input type="hidden" name="bank_tx_id" value="<?= (int)$bankTx['id'] ?>"> // bank_tx_id und alloc_betrag aus aktiver Session ODER aus POST-Daten beim Re-Render nach Validierungsfehler
<input type="hidden" name="alloc_betrag" value="<?= $h($formData['alloc_betrag'] ?? '') ?>"> $effectiveBankTxId = ($bankTx ?? null) ? (int)$bankTx['id'] : (int)($formData['bank_tx_id'] ?? 0);
$effectiveAllocBetrag = $formData['alloc_betrag'] ?? '';
?>
<?php if ($effectiveBankTxId > 0): ?>
<input type="hidden" name="bank_tx_id" value="<?= $effectiveBankTxId ?>">
<input type="hidden" name="alloc_betrag" value="<?= $h($effectiveAllocBetrag) ?>">
<?php endif; ?> <?php endif; ?>
<!-- Buchungstyp --> <!-- Buchungstyp -->