fix: remove KFZ formula rows from engine (now manual from Jan 2028)
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m10s
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 35s
CI / test-python-voice (push) Successful in 34s
CI / test-bqas (push) Successful in 33s

This commit is contained in:
Benjamin Admin
2026-04-22 13:44:17 +02:00
parent 4e34fa6da9
commit 31e1420cdc
3 changed files with 12 additions and 28 deletions

View File

@@ -1,30 +1,17 @@
import { NextResponse } from 'next/server'
import { NextRequest, NextResponse } from 'next/server'
import { requireAdmin } from '@/lib/admin-auth'
import pool from '@/lib/db'
import { computeFinanzplan } from '@/lib/finanzplan/engine'
export async function POST() {
const WD = 'c0000000-0000-0000-0000-000000000200'
const results: string[] = []
/** Admin-only: recompute a Finanzplan scenario. */
export async function POST(request: NextRequest) {
const guard = await requireAdmin(request)
if (guard.kind === 'response') return guard.response
// Check what KFZ labels exist
const { rows } = await pool.query(`SELECT id, row_label, category, (values->>'m8')::numeric as m8, (values->>'m12')::numeric as m12, (values->>'m24')::numeric as m24, (values->>'m25')::numeric as m25 FROM fp_betriebliche_aufwendungen WHERE scenario_id=$1 AND (row_label ILIKE '%KFZ%' OR row_label ILIKE '%Fahrzeug%' OR row_label ILIKE '%Kraftstoff%') ORDER BY sort_order`, [WD])
results.push(JSON.stringify(rows))
const body = await request.json().catch(() => ({}))
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 })
// Force clear m1-m24 for ALL KFZ-related rows
const removeKeys = Array.from({length:24},(_,i)=>`m${i+1}`)
for (const r of rows) {
let sql = `UPDATE fp_betriebliche_aufwendungen SET values = values`
for (const k of removeKeys) sql += ` - '${k}'`
sql += ` WHERE id=$1`
await pool.query(sql, [r.id])
results.push(`CLEARED ${r.row_label} (id=${r.id})`)
}
// Also remove the old formula rows if they still exist
await pool.query(`DELETE FROM fp_betriebliche_aufwendungen WHERE scenario_id=$1 AND row_label IN ('KFZ-Steuern (F)', 'KFZ-Versicherung (F)', 'Fahrzeugkosten (F)')`, [WD])
const result = await computeFinanzplan(pool, WD)
results.push(`cash_m60=${result.liquiditaet?.endstand?.m60}`)
return NextResponse.json({ ok: true, results })
const result = await computeFinanzplan(pool, scenarioId)
return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 })
}