Finanzmanager/src/Views/banking/regeln.php
fds2610-bot 057075368c Fix #94: Regel direkt aus einer Buchung anlegen
Toggle „Regel anlegen“ in der Buchungsmaske (Fix #94); beim Speichern
entsteht daraus eine Regel (AbgleichRegel::ausBuchung()), die das
Kontoblatt danach in einem modalen Dialog zum Prüfen und Anpassen zeigt.
Abbruch (auch per Escape) verwirft die Regel wieder, Speichern übernimmt
Änderungen. Die Regelfelder sind aus regeln.php in regelfelder.php
ausgelagert, damit beide Formulare dieselbe Bauart teilen.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-29 23:11:06 +02:00

162 lines
7.3 KiB
PHP
Raw 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
use Finanzmanager\Models\AbgleichRegel;
use Finanzmanager\View;
/**
* @var list<array<string,mixed>> $regeln
* @var list<array<string,mixed>> $kategorien
* @var list<array<string,mixed>> $klassen
* @var list<array<string,mixed>> $konten
* @var string $csrfToken
*/
include __DIR__ . '/../layout/kopf.php';
?>
<div class="tableiste">
<a href="/banking" class="tab">Bankverbindungen</a>
<a href="/banking/umsaetze" class="tab">Umsätze abgleichen</a>
<span class="tab aktiv">Regeln</span>
</div>
<p class="hinweis">
Eine Regel prüft ein Muster gegen Empfänger und Verwendungszweck und hängt bei einem
Treffer Kategorie, Klasse, ein Gegenkonto oder eine Splitbuchung an. Die erste passende
Regel gewinnt – sortiert nach Priorität, kleinere Zahl zuerst.
</p>
<div class="seitenaktionen">
<form method="post" action="/banking/regeln/pruefen" class="inline">
<input type="hidden" name="csrf_token" value="<?= View::h($csrfToken) ?>">
<button type="submit" class="knopf"
data-bestaetigen="Regeln auf alle Buchungen ohne Kategorie anwenden? Buchungen ohne Treffer bleiben unverändert.">
Regeln auf Buchungen ohne Kategorie anwenden
</button>
</form>
<a href="/banking/umsaetze" class="knopf">Zum Abgleich</a>
</div>
<?php if ($regeln === []): ?>
<p class="platzhalter">Noch keine Regel angelegt.</p>
<?php else: ?>
<?php foreach ($regeln as $regel): ?>
<form id="regel-<?= (int)$regel['id'] ?>" method="post"
action="/banking/regeln/<?= (int)$regel['id'] ?>"></form>
<form id="regel-loeschen-<?= (int)$regel['id'] ?>" method="post"
action="/banking/regeln/<?= (int)$regel['id'] ?>/loeschen"
data-bestaetigen="Regel „<?= View::h($regel['name']) ?>“ löschen?"></form>
<?php endforeach; ?>
<table class="liste regeltabelle">
<thead>
<tr>
<th>Name</th><th>Feld</th><th>Vergleich</th><th>Muster</th>
<th>Kategorie</th><th>Klasse</th>
<th class="rechts">Prio</th><th class="rechts">Treffer</th>
<th>Aktiv</th><th class="rechts">Aktion</th>
</tr>
</thead>
<tbody>
<?php foreach ($regeln as $regel): ?>
<?php $f = 'regel-' . (int)$regel['id']; ?>
<tr<?= (int)$regel['aktiv'] === 1 ? '' : ' class="inaktiv"' ?>>
<td>
<input type="hidden" form="<?= $f ?>" name="csrf_token" value="<?= View::h($csrfToken) ?>">
<input type="text" form="<?= $f ?>" name="name" value="<?= View::h($regel['name']) ?>" required>
</td>
<td>
<select form="<?= $f ?>" name="feld">
<?php foreach (AbgleichRegel::FELDER as $k => $v): ?>
<option value="<?= View::h($k) ?>" <?= $regel['feld'] === $k ? 'selected' : '' ?>>
<?= View::h($v) ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<select form="<?= $f ?>" name="vergleich">
<?php foreach (AbgleichRegel::VERGLEICHE as $k => $v): ?>
<option value="<?= View::h($k) ?>" <?= $regel['vergleich'] === $k ? 'selected' : '' ?>>
<?= View::h($v) ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td><input type="text" form="<?= $f ?>" name="muster" value="<?= View::h($regel['muster']) ?>" required></td>
<td>
<select form="<?= $f ?>" name="kategorie_id">
<option value="">–</option>
<?php foreach ($kategorien as $kategorie): ?>
<option value="<?= (int)$kategorie['id'] ?>"
<?= (int)$regel['kategorie_id'] === (int)$kategorie['id'] ? 'selected' : '' ?>>
<?= View::h($kategorie['pfad']) ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td>
<select form="<?= $f ?>" name="klasse_id">
<option value="">–</option>
<?php foreach ($klassen as $klasse): ?>
<option value="<?= (int)$klasse['id'] ?>"
<?= (int)$regel['klasse_id'] === (int)$klasse['id'] ? 'selected' : '' ?>>
<?= View::h($klasse['name']) ?>
</option>
<?php endforeach; ?>
</select>
</td>
<td class="rechts">
<input type="number" form="<?= $f ?>" name="prioritaet" class="schmal"
value="<?= (int)$regel['prioritaet'] ?>">
</td>
<td class="rechts"><?= (int)$regel['treffer'] ?></td>
<td>
<label class="ankreuzfeld">
<input type="checkbox" form="<?= $f ?>" name="aktiv" value="1"
<?= (int)$regel['aktiv'] === 1 ? 'checked' : '' ?>>
</label>
</td>
<td class="rechts nowrap">
<input type="hidden" form="regel-loeschen-<?= (int)$regel['id'] ?>"
name="csrf_token" value="<?= View::h($csrfToken) ?>">
<button type="submit" form="<?= $f ?>" class="knopf klein">Speichern</button>
<button type="submit" form="regel-loeschen-<?= (int)$regel['id'] ?>"
class="knopf klein gefahr">Löschen</button>
</td>
</tr>
<?php $splitZeilen = AbgleichRegel::splitzeilen($regel); ?>
<tr class="regelsplitzeile<?= (int)$regel['aktiv'] === 1 ? '' : ' inaktiv' ?>">
<td colspan="10">
<?php /* Zugeklappt, solange die Regel keine Splitbuchung macht –
sonst stünde unter jeder Regel eine leere Tabelle. */ ?>
<details<?= $splitZeilen === [] ? '' : ' open' ?>>
<summary>
Splitbuchung
<?php if ($splitZeilen !== []): ?>
<span class="nebentext">(<?= count($splitZeilen) ?> Zeilen)</span>
<?php endif; ?>
</summary>
<?php $splitForm = $f; ?>
<?php include __DIR__ . '/regelsplits.php'; ?>
</details>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<form method="post" action="/banking/regeln/neu" class="formular breit">
<input type="hidden" name="csrf_token" value="<?= View::h($csrfToken) ?>">
<h3>Neue Regel</h3>
<?php $regel = ['aktiv' => 1]; $idPrefix = 'neu_'; ?>
<?php include __DIR__ . '/regelfelder.php'; ?>
<div class="knopfleiste">
<button type="submit" class="knopf primaer">Regel anlegen</button>
</div>
</form>
<?php include __DIR__ . '/../layout/fuss.php'; ?>