From cdaaec297108d0e44f57000efe2da524c4f4c20d Mon Sep 17 00:00:00 2001 From: Matthias Hochmeister Date: Mon, 30 Mar 2026 10:51:55 +0200 Subject: [PATCH] fix: auto-select open fiscal year on load, derive sub-account number from parent, replace flat konten table with collapsible tree --- frontend/src/pages/Buchhaltung.tsx | 131 ++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 30 deletions(-) diff --git a/frontend/src/pages/Buchhaltung.tsx b/frontend/src/pages/Buchhaltung.tsx index 7317326..7b4b7c0 100644 --- a/frontend/src/pages/Buchhaltung.tsx +++ b/frontend/src/pages/Buchhaltung.tsx @@ -18,6 +18,7 @@ import { FormControl, FormControlLabel, IconButton, + InputAdornment, InputLabel, LinearProgress, MenuItem, @@ -199,6 +200,25 @@ function KontoDialog({ const empty: KontoFormData = { haushaltsjahr_id: haushaltsjahrId, kontonummer: '', bezeichnung: '', budget_gwg: 0, budget_anlagen: 0, budget_instandhaltung: 0, parent_id: null, notizen: '' }; const [form, setForm] = useState(empty); + const selectedParent = konten.find(k => k.id === form.parent_id); + const parentPrefix = selectedParent ? selectedParent.kontonummer : ''; + // suffix = part of kontonummer after parent prefix + const kontonummerSuffix = form.kontonummer.startsWith(parentPrefix) ? form.kontonummer.slice(parentPrefix.length) : form.kontonummer; + + const handleParentChange = (parentId: number | null) => { + const parent = konten.find(k => k.id === parentId); + const prefix = parent ? parent.kontonummer : ''; + // strip old prefix, re-apply new one + const oldPrefix = selectedParent ? selectedParent.kontonummer : ''; + const suffix = form.kontonummer.startsWith(oldPrefix) ? form.kontonummer.slice(oldPrefix.length) : form.kontonummer; + setForm(f => ({ ...f, parent_id: parentId, kontonummer: prefix + suffix })); + }; + + const handleSuffixChange = (suffix: string) => { + const digits = suffix.replace(/\D/g, ''); + setForm(f => ({ ...f, kontonummer: parentPrefix + digits })); + }; + useEffect(() => { if (existing) { setForm({ haushaltsjahr_id: haushaltsjahrId, konto_typ_id: existing.konto_typ_id ?? undefined, kontonummer: existing.kontonummer, bezeichnung: existing.bezeichnung, budget_gwg: existing.budget_gwg, budget_anlagen: existing.budget_anlagen, budget_instandhaltung: existing.budget_instandhaltung, parent_id: existing.parent_id, notizen: existing.notizen || '' }); @@ -213,7 +233,17 @@ function KontoDialog({ {existing ? 'Konto bearbeiten' : 'Neues Konto'} - setForm(f => ({ ...f, kontonummer: e.target.value }))} required /> + handleSuffixChange(e.target.value)} + required + inputProps={{ inputMode: 'numeric', pattern: '[0-9]*' }} + InputProps={parentPrefix ? { + startAdornment: {parentPrefix}, + } : undefined} + helperText={parentPrefix ? `Vollständige Nummer: ${form.kontonummer || parentPrefix + '…'}` : undefined} + /> setForm(f => ({ ...f, bezeichnung: e.target.value }))} required /> Kontotyp @@ -226,7 +256,7 @@ function KontoDialog({ Elternkonto (optional)