diff --git a/pitch-deck/app/api/admin/fp-patch/route.ts b/pitch-deck/app/api/admin/fp-patch/route.ts index 23f23d0..dfb2bce 100644 --- a/pitch-deck/app/api/admin/fp-patch/route.ts +++ b/pitch-deck/app/api/admin/fp-patch/route.ts @@ -1,29 +1,23 @@ import { NextResponse } from 'next/server' import pool from '@/lib/db' -import { computeFinanzplan } from '@/lib/finanzplan/engine' export async function POST() { - const BASE = (await pool.query("SELECT id FROM fp_scenarios WHERE is_default=true LIMIT 1")).rows[0]?.id + // Check ALL scenario IDs + const { rows: scenarios } = await pool.query(`SELECT id, name, is_default FROM fp_scenarios ORDER BY name`) - // 1. Beratung & Service 2027: 300k → 250k (= 20833/month statt 25000) - const { rows: ber } = await pool.query(`SELECT id, values FROM fp_umsatzerloese WHERE scenario_id=$1 AND row_label='Beratung & Service'`, [BASE]) - if (ber.length > 0) { - const vals = ber[0].values - for (let m = 13; m <= 24; m++) vals[`m${m}`] = 20833 // 250k/12 - await pool.query(`UPDATE fp_umsatzerloese SET values=$1 WHERE id=$2`, [JSON.stringify(vals), ber[0].id]) + // Check what the version's fm_scenarios points to + const VER = 'b7204781-aba0-45cc-a655-a0ff88d1173a' + const { rows: verData } = await pool.query(`SELECT data FROM pitch_version_data WHERE version_id=$1 AND table_name='fm_scenarios'`, [VER]) + + // Check row counts per scenario + const results: string[] = [] + results.push(`Global scenarios: ${JSON.stringify(scenarios)}`) + results.push(`Version fm_scenarios: ${JSON.stringify(verData[0]?.data)}`) + + for (const sc of scenarios) { + const { rows: [c] } = await pool.query(`SELECT COUNT(*) as cnt FROM fp_kunden WHERE scenario_id=$1`, [sc.id]) + results.push(`${sc.name} (${sc.id}): ${c.cnt} kunden rows`) } - // 2. Marketing-Agentur: 2027 → 100k (8333/mo), 2028 → 200k (16667/mo) - const agentur: Record = {} - for (let m = 8; m <= 12; m++) agentur[`m${m}`] = 5000 - for (let m = 13; m <= 24; m++) agentur[`m${m}`] = 8333 // 100k/12 - for (let m = 25; m <= 36; m++) agentur[`m${m}`] = 16667 // 200k/12 - for (let m = 37; m <= 48; m++) agentur[`m${m}`] = 20000 - for (let m = 49; m <= 60; m++) agentur[`m${m}`] = 25000 - await pool.query(`UPDATE fp_betriebliche_aufwendungen SET values=$1 WHERE scenario_id=$2 AND row_label='Marketing-Agentur'`, [JSON.stringify(agentur), BASE]) - - const r = await computeFinanzplan(pool, BASE) - const { rows: liq } = await pool.query(`SELECT (values->>'m12')::numeric as dec26, (values->>'m24')::numeric as dec27, (values->>'m36')::numeric as dec28, (values->>'m48')::numeric as dec29, (values->>'m60')::numeric as dec30 FROM fp_liquiditaet WHERE scenario_id=$1 AND row_label='LIQUIDITÄT'`, [BASE]) - - return NextResponse.json({ ok: true, liq: liq[0] }) + return NextResponse.json({ ok: true, results }) }