feat(sync): sync all FDISK members, auto-creating dashboard accounts for users not yet logged in

This commit is contained in:
Matthias Hochmeister
2026-04-15 14:36:57 +02:00
parent dab4a45b79
commit 719b7bfcdb
12 changed files with 1086 additions and 8 deletions

View File

@@ -0,0 +1,101 @@
# Buchhaltung Implementation Plan — 2026-03-30
## Priority Order
1. P1: Transfers (bank → bank) — needs migration first
2. P2: BankkontoDetail page — depends on P1 migration for transfer direction
3. P3: Konto-Typen + Einstellungen UI — pure frontend, self-contained
4. P4: Bestellungen integration — einzelpreis validation + auto-pending
5. P5: Haushaltsplan pages — large feature
6. P6: PDF Export — last, all data endpoints stable
## Key Findings
- `typ='transfer'` is NOT in the current DB CHECK constraint — migration required
- `einzelpreis` on `bestellpositionen` already exists (migration 038) — no schema change for P4
- `buchhaltung_planung` and `buchhaltung_planpositionen` tables exist (migrations 075/077), 2-level hierarchy (not 3-level as in original design sketch)
- All konto-typen and einstellungen backend routes exist — P3 is frontend-only
- Split-booking dialog and Freigaben-from-plan flow (design sections 4/8) are deferred
---
## P1: Transfers [x]
### Migration `082_buchhaltung_transfer.sql`
- Extend CHECK: add `'transfer'` to `typ` enum
- Add column `transfer_ziel_bankkonto_id INT REFERENCES buchhaltung_bankkonten(id) ON DELETE SET NULL`
### Backend
- `buchhaltung.service.ts` — add `createTransfer(data, userId)`: DB transaction creating two rows (debit on source, credit on target)
- `buchhaltung.controller.ts` — add `createTransfer` handler
- `buchhaltung.routes.ts``POST /transfers`
- Update `listTransaktionen` JOIN to include `transfer_ziel_bezeichnung`
### Frontend
- `buchhaltung.types.ts` — add `'transfer'` to `TransaktionTyp`; add `transfer_ziel_bankkonto_id?`, `transfer_ziel_bezeichnung?` to `Transaktion`; add `TransferFormData`
- `buchhaltung.ts` (service) — add `createTransfer` API method
- `Buchhaltung.tsx` — add `TransferDialog` component + "Transfer" button in TransaktionenTab toolbar; show Transfer chip in typ column
---
## P2: BankkontoDetail Page [x]
### Backend
- `buchhaltung.service.ts` — add `getBankkontoStatement(id, filters)`: queries transactions for one bank account, computes running balance per row (einnahme=+, ausgabe=, transfer direction from `transfer_ziel_bankkonto_id`)
- `buchhaltung.controller.ts` — add `getBankkontoStatement` handler
- `buchhaltung.routes.ts``GET /bankkonten/:id/transaktionen`
### Frontend
- `buchhaltung.types.ts` — add `BankkontoStatement` interface
- `buchhaltung.ts` — add `getBankkontoStatement(id, filters?)` API method
- New file `BuchhaltungBankkontoDetail.tsx` — date range filter, summary cards, table with running balance column
- `App.tsx` — add route `/buchhaltung/bankkonto/:id`
- `Buchhaltung.tsx` (KontenTab, Bankkonten sub-tab) — make table rows clickable → navigate to detail
---
## P3: Einstellungen UI [x]
### Frontend only
- `buchhaltung.ts` — add `getEinstellungen` + `setEinstellungen` API methods
- `Buchhaltung.tsx` — add 4th sub-tab "Einstellungen" in KontenTab:
- KontoTypen CRUD table + add/edit dialog
- Default alert threshold TextField + save button
- Gate with `hasPermission('buchhaltung:manage_settings')`
---
## P4: Bestellungen Integration [x]
### Backend
- `bestellung.service.ts` — block `vollstaendig`/`abgeschlossen` transition if any position has null/zero `einzelpreis`
- `buchhaltung.service.ts` — add `createPendingFromBestellung(bestellungId, userId)`: non-fatal, finds open Haushaltsjahr, inserts pending ausgabe transaction
- `bestellung.service.ts` — call `createPendingFromBestellung` after status → `abgeschlossen`
### Frontend
- `BestellungDetail.tsx` — show warning Alert when advancing to `abgeschlossen` but prices missing
---
## P5: Haushaltsplan [x]
### Backend
- `buchhaltung.service.ts` — Planung CRUD + Planposition CRUD + `createHaushaltsjahrFromPlan`
- `buchhaltung.controller.ts` — handlers for all
- `buchhaltung.routes.ts` — full set of Planung + Planposition routes + `POST /planung/:id/create-haushaltsjahr`
### Frontend
- `buchhaltung.types.ts` — add `Planung`, `Planposition`, `PlanungDetail`, form data interfaces
- `buchhaltung.ts` — add all Planung API methods
- New file `Haushaltsplan.tsx` — list view + detail view, position inline editing, "Haushaltsjahr erstellen" action
- `App.tsx` — routes `/haushaltsplan` and `/haushaltsplan/:id`
- `Sidebar.tsx` — add Haushaltsplan sub-item under Buchhaltung group
---
## P6: PDF Export (client-side jsPDF) [x]
### Frontend
- `Buchhaltung.tsx` (UebersichtTab) — add `generatePdf()` using jsPDF + `fetchPdfSettings()` pattern
- Cover: year name + totals summary
- Page 2+: konten tree table with budget/spent/utilization
- Page 3+: full transaction list sorted by date
- "PDF exportieren" button gated by `buchhaltung:export`