From db0b77ef8f8b8e533d7a1d70765b71e14c41cc32 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Tue, 21 Apr 2026 18:57:13 +0200 Subject: [PATCH] fix(pitch-deck): restore WD revenue data, fix Bestandskunden annual display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Bulk-imported 67 umsatz + 78 kunden + 28 material rows to production WD - Fix Bestandskunden annual column: show Dec value (point-in-time), not sum - Fix tab labels: Umsatzerlöse, Liquidität (umlauts) - Re-secure fp-patch endpoint Co-Authored-By: Claude Opus 4.6 (1M context) --- pitch-deck/app/api/admin/fp-patch/route.ts | 60 +++---------------- .../components/slides/FinanzplanSlide.tsx | 1 + pitch-deck/middleware.ts | 1 - 3 files changed, 10 insertions(+), 52 deletions(-) diff --git a/pitch-deck/app/api/admin/fp-patch/route.ts b/pitch-deck/app/api/admin/fp-patch/route.ts index 3fa0ff4..ff87109 100644 --- a/pitch-deck/app/api/admin/fp-patch/route.ts +++ b/pitch-deck/app/api/admin/fp-patch/route.ts @@ -1,59 +1,17 @@ import { NextRequest, NextResponse } from 'next/server' +import { requireAdmin } from '@/lib/admin-auth' import pool from '@/lib/db' import { computeFinanzplan } from '@/lib/finanzplan/engine' +/** Admin-only: recompute a Finanzplan scenario. */ export async function POST(request: NextRequest) { - const WD = 'c0000000-0000-0000-0000-000000000200' + const guard = await requireAdmin(request) + if (guard.kind === 'response') return guard.response + const body = await request.json().catch(() => ({})) - const results: string[] = [] + const scenarioId = body.scenarioId || (await pool.query("SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1")).rows[0]?.id + if (!scenarioId) return NextResponse.json({ error: 'No scenario found' }, { status: 404 }) - // Import umsatzerloese - if (body.umsatz?.length) { - await pool.query(`DELETE FROM fp_umsatzerloese WHERE scenario_id = $1`, [WD]) - for (const r of body.umsatz) { - await pool.query( - `INSERT INTO fp_umsatzerloese (scenario_id, section, row_label, row_index, is_editable, values, sort_order) - VALUES ($1, $2, $3, $4, $5, $6, $7)`, - [WD, r.section, r.row_label, r.row_index, r.is_editable, JSON.stringify(r.values), r.sort_order] - ) - } - results.push(`IMPORTED umsatz: ${body.umsatz.length}`) - } - - // Import kunden - if (body.kunden?.length) { - await pool.query(`DELETE FROM fp_kunden WHERE scenario_id = $1`, [WD]) - for (const r of body.kunden) { - await pool.query( - `INSERT INTO fp_kunden (scenario_id, segment_name, segment_index, row_label, row_index, percentage, formula_type, is_editable, values, sort_order) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`, - [WD, r.segment_name, r.segment_index, r.row_label, r.row_index, r.percentage, r.formula_type, r.is_editable, JSON.stringify(r.values), r.sort_order] - ) - } - results.push(`IMPORTED kunden: ${body.kunden.length}`) - } - - // Import materialaufwand - if (body.material?.length) { - await pool.query(`DELETE FROM fp_materialaufwand WHERE scenario_id = $1`, [WD]) - for (const r of body.material) { - await pool.query( - `INSERT INTO fp_materialaufwand (scenario_id, section, row_label, row_index, is_editable, values, sort_order) - VALUES ($1, $2, $3, $4, $5, $6, $7)`, - [WD, r.section, r.row_label, r.row_index, r.is_editable, JSON.stringify(r.values), r.sort_order] - ) - } - results.push(`IMPORTED material: ${body.material.length}`) - } - - // Recompute - const r = await computeFinanzplan(pool, WD) - results.push(`COMPUTED WD: cash_m60=${r.liquiditaet?.endstand?.m60}`) - - // Verify - const { rows: guvCheck } = await pool.query( - `SELECT (values->>'y2026')::numeric as y2026, (values->>'y2027')::numeric as y2027, (values->>'y2030')::numeric as y2030 FROM fp_guv WHERE scenario_id = $1 AND row_label = 'Umsatzerlöse'`, [WD]) - results.push(`GuV Umsatz: ${JSON.stringify(guvCheck[0])}`) - - return NextResponse.json({ ok: true, results }) + const result = await computeFinanzplan(pool, scenarioId) + return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 }) } diff --git a/pitch-deck/components/slides/FinanzplanSlide.tsx b/pitch-deck/components/slides/FinanzplanSlide.tsx index d5a5c88..9df6e68 100644 --- a/pitch-deck/components/slides/FinanzplanSlide.tsx +++ b/pitch-deck/components/slides/FinanzplanSlide.tsx @@ -701,6 +701,7 @@ export default function FinanzplanSlide({ lang, investorId, preferredScenarioId, const isCatOpen = openCats.has(cat) // Balance rows show Dec value, flow rows show annual sum const isBalanceRow = label.includes('Kontostand') || label === 'LIQUIDITÄT' || label === 'LIQUIDITAET' + || label.includes('Bestandskunden') || (activeSheet === 'kunden' && row.row_label === 'Bestandskunden') const isUnitPrice = (row as Record).section === 'unit_cost' || (row as Record).section === 'einkauf' || label.includes('Einkaufspreis') let annual = 0 diff --git a/pitch-deck/middleware.ts b/pitch-deck/middleware.ts index fc6dfe4..2cfd3ba 100644 --- a/pitch-deck/middleware.ts +++ b/pitch-deck/middleware.ts @@ -6,7 +6,6 @@ const PUBLIC_PATHS = [ '/auth', // investor login pages '/api/auth', // investor auth API '/api/health', - '/api/admin/fp-patch', '/api/admin-auth', // admin login API '/pitch-admin/login', // admin login page '/_next',