chore: diagnose scenario ID mismatch
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m15s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-consent (push) Successful in 29s
CI / test-python-voice (push) Successful in 32s
CI / test-bqas (push) Has been cancelled

This commit is contained in:
Benjamin Admin
2026-04-23 10:21:02 +02:00
parent 92c272bbea
commit 93f8e85568

View File

@@ -1,29 +1,23 @@
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
import pool from '@/lib/db' import pool from '@/lib/db'
import { computeFinanzplan } from '@/lib/finanzplan/engine'
export async function POST() { 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) // Check what the version's fm_scenarios points to
const { rows: ber } = await pool.query(`SELECT id, values FROM fp_umsatzerloese WHERE scenario_id=$1 AND row_label='Beratung & Service'`, [BASE]) const VER = 'b7204781-aba0-45cc-a655-a0ff88d1173a'
if (ber.length > 0) { const { rows: verData } = await pool.query(`SELECT data FROM pitch_version_data WHERE version_id=$1 AND table_name='fm_scenarios'`, [VER])
const vals = ber[0].values
for (let m = 13; m <= 24; m++) vals[`m${m}`] = 20833 // 250k/12 // Check row counts per scenario
await pool.query(`UPDATE fp_umsatzerloese SET values=$1 WHERE id=$2`, [JSON.stringify(vals), ber[0].id]) 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) return NextResponse.json({ ok: true, results })
const agentur: Record<string,number> = {}
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] })
} }