diff --git a/CLAUDE.md b/CLAUDE.md index a64395b..2293787 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -151,7 +151,7 @@ Four related pieces shipped together, all from `open.md` items surfaced by real - **Admin-Dashboard is now the one-stop nutzer-management view**: `renderAdminDash()`'s Konten table gained `Registriert` (`erstellt_am`) and `Letzter Login` (+ IP) columns, plus a **Bearbeiten** button (`adminNutzerBearbeitenModal()`) that edits name/rolle/aktiv/passwort *and* the Rechnungsanschrift in one modal — previously only the simpler Backend "Nutzerverwaltung" card (still there, still fine for quick account creation) could edit a profile at all, and it had no billing-address or login-history visibility. `letzter_login`/`letzte_ip` (`nutzer` columns) are stamped on every successful login and self-registration in `api_auth_login()`/`api_auth_registrieren()` — `X-Forwarded-For` is honored ahead of `request.remote_addr` for when a reverse proxy sits in front (relevant once the DynDNS/testbench setup is live), taking the first hop only. - **Self-registration** (`POST /api/auth/registrieren`, public — added to the `global_auth_check()` allowlist): a "Noch kein Konto? Jetzt registrieren" link on the login screen (`showRegisterForm()`/`hideRegisterForm()` toggle the same `.lo-box`, no separate page) collects Benutzername/Passwort/Name plus a **mandatory** Rechnungsanschrift (`rg_name`/`rg_strasse`/`rg_plz`/`rg_ort` on `nutzer`) and auto-logs the new account in on success (`doRegister()`). New accounts are marked `selbst_registriert=1` — admin-created accounts (`POST /api/nutzer`, still admin-only) stay `0` and are deliberately unaffected by everything below, so nothing changes for how admin onboards trusted/manual accounts. - **Freemium write-lock for unpaid self-registrations**: `_hat_bezahlten_zugang(u)` (real `abo_bis` check, admin/demo always true) is deliberately separate from `_hat_aktiven_zugang()`/`abo_pflicht` — a self-registered account without a paid/granted subscription can browse and read *everything*, but `global_auth_check()` blocks `POST`/`PUT` to the letter-generation (`.../briefe`), Leistungen-assignment (`.../leistungen/katalog`, `.../deaktivieren`) and Aufgaben-creation (`/api/aufgaben`) endpoints with a 402 regardless of the global `abo_pflicht` toggle. This only applies when `selbst_registriert=1`, so it can go live immediately (no PayPal needed yet) without touching existing admin-created accounts. `GET /api/auth/me` exposes `schreibzugriff_gesperrt` so the frontend can short-circuit before doing client-side work (PDF generation, etc.) rather than relying on the 402 alone — `_schreibgesperrt()` in `templates/index.html` is the shared guard, called at the top of `dlM()`/`dlW()`/`sendMail()`/`assignL()`/`saveAufg()`; it toasts and redirects to `meinabo`. Lifting the lock is just admin granting `abo-freischalten` (existing mechanism) or, eventually, real payment — no separate "unlock" code path needed. -- **Admin can generate a PDF invoice** per account (`rechnungModal()` → `rechnungErstellen()` in `templates/index.html`) — entirely client-side via the same `html2pdf.js` pattern as Musterbrief/Widerspruch (Courier-style text block, `addPageNums()`), pre-filled from the account's Rechnungsanschrift and the `abo_preis` setting, downloaded on demand. No server-side persistence/archival of invoices (unlike patient documents) — these aren't care records under the §630f BGB retention duty, so a simple download suffices for "on customer request." +- **Admin can generate a legally compliant PDF invoice** per account (`rechnungModal()` → `rechnungErstellen()` in `templates/index.html`) — client-side PDF via the same `html2pdf.js` pattern as Musterbrief/Widerspruch (Courier-style text block, `addPageNums()`), but the invoice **number itself is server-issued**: `POST /api/admin/rechnungsnummer/naechste` (admin-only) atomically increments an `einstellungen`-backed counter (`rechnungsnummer_counter` + `rechnungsnummer_jahr`, format `{Jahr}-{Nummer:04d}`, resets to 1 on a new calendar year) so two invoices can never collide on the same number — required by § 14 Abs. 4 Nr. 4 UStG ("fortlaufende, einmalige Nummer"), which a purely client-side/date-based guess couldn't guarantee. The rest of § 14 UStG's Pflichtangaben are covered by a dedicated **"Rechnungsstellung"** card in Backend-Einstellungen (`rechnung_absender_name/_strasse/_plz/_ort`, `rechnung_steuernummer`, `rechnung_ustid`, `rechnung_kleinunternehmer`, `rechnung_ust_satz`) — deliberately **separate from the "Betrieb" card**, since the invoice seller address/tax data can legitimately differ from (or need to be more complete than) the branding address, and isn't needed by the public `/api/einstellungen/public` endpoint the way Impressum/Datenschutz are, so it's fetched fresh from the admin-only `/api/admin/einstellungen` inside `rechnungModal()` instead of the cached `_einstellungen` global. `rechnungErstellen()` refuses to generate a PDF (with a toast, not a silent blank field) if the seller address or a Steuernummer/USt-IdNr is missing. Depending on `rechnung_kleinunternehmer`, the invoice either shows a Netto/USt-Satz/USt-Betrag/Brutto breakdown (`betragBrutto / (1 + ustSatz/100)` for Netto) or the § 19 UStG small-business exemption note instead of a tax line — never both. No server-side persistence/archival of the invoice PDF itself (unlike patient documents) — these aren't care records under the §630f BGB retention duty, so a simple download suffices for "on customer request"; only the invoice *number* counter is persisted, since that's the part that must never repeat or gap. - **Legal pages**: three `rechtstext_impressum`/`rechtstext_datenschutz`/`rechtstext_agb` keys in `einstellungen`, edited as plain textareas in the Backend-Einstellungen card that replaced "KI – Claude API" (same slot, same `saveEinst()` pattern). They're deliberately included in the **public** `/api/einstellungen/public` payload (no login required) since Impressum/Datenschutz shouldn't hide behind a login wall, and `pgRechtstext(typ)` (routed via `go('impressum'|'datenschutz'|'agb')`) reads them straight from the already-cached `_einstellungen` object. A small `.sb-legal` link row was added to the sidebar bottom, and `go()` exempts these three page names from the `aboBlockiert` redirect-to-`meinabo` logic — a payment-blocked account must still be able to read the legal pages. - **The "Betrieb" card was deliberately kept**, not removed, despite the original `open.md` wording ("das kann weg") — `firmenname`/`firmen_logo`/`firmen_strasse`/etc. are actively used for sidebar branding and the "Erstellt mit {firmenname}" footer on generated PDFs (Musterbrief, Widerspruch, Pflegetagebuch, Patientenakte); deleting the only UI to edit them would have been a silent regression unrelated to the actual ask. If this was in fact meant to go, that's a call for the product owner, not something to infer from "veraltet." diff --git a/pflegepilot_alpha_v2/pflegepilot/app.py b/pflegepilot_alpha_v2/pflegepilot/app.py index 08571d9..bf26dee 100644 --- a/pflegepilot_alpha_v2/pflegepilot/app.py +++ b/pflegepilot_alpha_v2/pflegepilot/app.py @@ -980,6 +980,27 @@ def api_admin_logo(): db.commit() return jsonify({"ok": True, "logo": filename, "url": "/static/logo/" + filename}) +# Fortlaufende, luecken- und einmalige Rechnungsnummer je Kalenderjahr (Pflicht +# nach § 14 Abs. 4 Nr. 4 UStG) - serverseitig statt clientseitig, damit zwei +# nacheinander erstellte Rechnungen garantiert nicht dieselbe Nummer bekommen. +@app.route("/api/admin/rechnungsnummer/naechste", methods=["POST"]) +@admin_required +def api_admin_naechste_rechnungsnummer(): + db = get_db() + jahr = str(date.today().year) + gespeichertes_jahr = get_setting("rechnungsnummer_jahr", "") + try: + counter = int(get_setting("rechnungsnummer_counter", "0") or "0") + except Exception: + counter = 0 + if gespeichertes_jahr != jahr: + counter = 0 + counter += 1 + db.execute("INSERT OR REPLACE INTO einstellungen (schluessel, wert) VALUES (?, ?)", ("rechnungsnummer_jahr", jahr)) + db.execute("INSERT OR REPLACE INTO einstellungen (schluessel, wert) VALUES (?, ?)", ("rechnungsnummer_counter", str(counter))) + db.commit() + return jsonify({"ok": True, "nummer": f"{jahr}-{counter:04d}"}) + # ─── API: Patienten ────────────────────────────────────────────────────────── @app.route("/api/patienten", methods=["GET"]) def api_patienten(): diff --git a/pflegepilot_alpha_v2/pflegepilot/changelog.py b/pflegepilot_alpha_v2/pflegepilot/changelog.py index cb63179..f3ea0d2 100644 --- a/pflegepilot_alpha_v2/pflegepilot/changelog.py +++ b/pflegepilot_alpha_v2/pflegepilot/changelog.py @@ -15,6 +15,16 @@ zurücküberschrieben. """ CHANGELOG = [ + { + "version": "1.2.1", + "datum": "2026-07-19", + "titel": "Rechnungen jetzt rechtskonform nach § 14 UStG", + "punkte": [ + "Neue Karte „Rechnungsstellung“ im Backend: eigene Rechnungsanschrift und Steuerdaten (Steuernummer, USt-IdNr., Kleinunternehmerregelung) des Betreibers – unabhängig von der Betrieb-Karte.", + "Rechnungen erhalten jetzt eine echte fortlaufende, einmalige Rechnungsnummer (Jahr + Zähler) statt einer geratenen Nummer.", + "Rechnung weist Netto-/Steuerbetrag/Brutto getrennt aus, oder – bei aktivierter Kleinunternehmerregelung – den gesetzlich vorgeschriebenen Hinweis nach § 19 UStG.", + ], + }, { "version": "1.2.0", "datum": "2026-07-19", diff --git a/pflegepilot_alpha_v2/pflegepilot/templates/index.html b/pflegepilot_alpha_v2/pflegepilot/templates/index.html index d8250c6..cf39bac 100644 --- a/pflegepilot_alpha_v2/pflegepilot/templates/index.html +++ b/pflegepilot_alpha_v2/pflegepilot/templates/index.html @@ -383,10 +383,10 @@ textarea{resize:vertical;min-height:80px}
Rechnungsanschrift und Steuerdaten des Betreibers – erscheinen als Absender auf jeder erstellten Rechnung (Pflichtangaben nach § 14 UStG). Unabhängig von der Betrieb-Karte oben, da eine Rechnung ggf. eine andere/vollständigere Anschrift braucht als das Branding.
Rechnungsanschrift/Steuerdaten des Betreibers sind unvollständig – bitte zuerst unter Backend → „Rechnungsstellung“ ergänzen, sonst ist die Rechnung nicht rechtskonform.
Keine Rechnungsanschrift hinterlegt – bitte vor dem Erstellen ergänzen.
Keine Rechnungsanschrift beim Kunden hinterlegt – bitte vor dem Erstellen ergänzen.