CRITICAL: fix version fm_scenarios to point to correct Base Case ID
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m7s
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 33s
CI / test-python-voice (push) Successful in 35s
CI / test-bqas (push) Has been cancelled
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m7s
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 33s
CI / test-python-voice (push) Successful in 35s
CI / test-bqas (push) Has been cancelled
This commit is contained in:
@@ -1,23 +1,27 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import pool from '@/lib/db'
|
||||
import { computeFinanzplan } from '@/lib/finanzplan/engine'
|
||||
|
||||
export async function POST() {
|
||||
// Check ALL scenario IDs
|
||||
const { rows: scenarios } = await pool.query(`SELECT id, name, is_default FROM fp_scenarios ORDER BY name`)
|
||||
|
||||
// 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])
|
||||
const BASE_ID = '4b8a6fac-0105-499e-8946-80bc4e3c2476'
|
||||
|
||||
// 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)}`)
|
||||
// Update version's fm_scenarios to point to the correct Base Case ID
|
||||
const newScenarios = [
|
||||
{ id: BASE_ID, name: 'Base Case', color: '#6366f1', is_default: true, description: 'Konservative Schätzung mit realistischen Wachstumsraten' },
|
||||
{ id: 'd0000000-0000-0000-0000-000000000301', name: '1 Mio Bear', color: '#ef4444', is_default: false, description: 'Pessimistisches Szenario' },
|
||||
{ id: 'd0000000-0000-0000-0000-000000000302', name: '1 Mio Bull', color: '#22c55e', is_default: false, description: 'Optimistisches Szenario' },
|
||||
]
|
||||
|
||||
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`)
|
||||
}
|
||||
await pool.query(
|
||||
`UPDATE pitch_version_data SET data=$1 WHERE version_id=$2 AND table_name='fm_scenarios'`,
|
||||
[JSON.stringify(newScenarios), VER]
|
||||
)
|
||||
|
||||
return NextResponse.json({ ok: true, results })
|
||||
// Recompute Base Case
|
||||
const r = await computeFinanzplan(pool, BASE_ID)
|
||||
const { rows: liq } = await pool.query(
|
||||
`SELECT (values->>'m24')::numeric as dec27, (values->>'m36')::numeric as dec28, (values->>'m60')::numeric as dec30 FROM fp_liquiditaet WHERE scenario_id=$1 AND row_label='LIQUIDITÄT'`, [BASE_ID])
|
||||
|
||||
return NextResponse.json({ ok: true, fixed: true, liq: liq[0], cash_m60: r.liquiditaet?.endstand?.m60 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user