# Berichtsprofile & PDF (technisch) **Stand:** 2026-04-29 ## Begriffe | Begriff | Bedeutung | |--------|-----------| | **Layout-Snapshot** | PDF aus gerasteter DOM-Übersicht (`html2canvas` + `jspdf`), optional Widget `report_export`. | | **Strukturierter Bericht** | Profil mit Blöcken (`section`, `chart`, `ai_insight`), PDF serverseitig via Data Layer + Matplotlib + ReportLab. | Die beiden Wege sind bewusst getrennt, damit das Dashboard nicht die einzige „Wahrheit“ für Dokumente wird. ## Datenbank - Tabelle `report_profiles` (Migration `060_report_profiles.sql`): `profile_id` PK → `profiles`, `payload` JSONB, `updated_at`. Ohne Zeile gilt ein **Code-Standard** (`default_report_profile_dict` in `report_profile_schema.py`). ## API (`/api/reports`) | Methode | Pfad | Zweck | |--------|------|--------| | GET | `/catalog` | Diagramm-Katalog + Blocktypen für UI | | GET | `/profile` | `{ stored, profile }` | | PUT | `/profile` | Vollständiges Profil-JSON (Pydantic-validiert) | | DELETE | `/profile` | DB-Zeile löschen → wieder Standard | | POST | `/generate-pdf` | PDF-Download; `data_export`-Kontingent + `increment_feature_usage` | ## Schema v1 (`report_profile_schema.py`) - `version`: nur `1` - `document_title`: optional - `blocks`: Liste mit Union: - `section`: `title` - `chart`: `chart_id` ∈ `ALLOWED_CHART_IDS`, `window_days` 7–365 - `ai_insight`: optional `insight_id` (UUID, `ai_insights.id`), optional `title` ## Diagrammdaten `report_chart_fetch.fetch_chart_payload` ruft dieselben Bausteine auf wie `/api/charts` (ohne HTTP). Erweiterung: Eintrag in `ALLOWED_CHART_IDS`, Fetcher in `_CHART_FETCHERS`, Zeile in `CHART_CATALOG_FOR_API`. ## PDF-Rendering `report_pdf_render.build_structured_report_pdf`: ReportLab-Flowable-Kette, Diagramme als PNG aus Chart-Payload (Matplotlib, Agg-Backend). ## Frontend - **Einstellungen:** Karte „PDF-Bericht (strukturiert)“ — Blöcke bearbeiten, speichern, Standard, PDF erzeugen. - **Dashboard:** Widget bleibt optionaler **Schnappschuss**; Hinweis verweist auf Einstellungen. ## Nächste sinnvolle Erweiterungen - Dashboard-Layout → Berichtsprofil **einmalig importieren** (Mapping-Tabelle Widget-ID → chart_id). - KI: Insights-Auswahl in der UI statt manueller UUID. - Weitere `chart_id`-Werte / multipage Feintuning (Seitenumbrüche pro Block).