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 pool from '@/lib/db'
import { computeFinanzplan } from '@/lib/finanzplan/engine' import { computeFinanzplan } from '@/lib/finanzplan/engine'
export async function POST() { /** Admin-only: recompute a Finanzplan scenario. */
const WD = 'c0000000-0000-0000-0000-000000000200' export async function POST(request: NextRequest) {
const results: string[] = [] const guard = await requireAdmin(request)
if (guard.kind === 'response') return guard.response
// Check what KFZ labels exist const body = await request.json().catch(() => ({}))
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]) const scenarioId = body.scenarioId || (await pool.query("SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1")).rows[0]?.id
results.push(JSON.stringify(rows)) if (!scenarioId) return NextResponse.json({ error: 'No scenario found' }, { status: 404 })
// Force clear m1-m24 for ALL KFZ-related rows const result = await computeFinanzplan(pool, scenarioId)
const removeKeys = Array.from({length:24},(_,i)=>`m${i+1}`) return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 })
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 })
} }

View File

@@ -254,9 +254,7 @@ export async function computeFinanzplan(pool: Pool, scenarioId: string): Promise
// Formula-based rows: derive from headcount (excl. founders) or customers // Formula-based rows: derive from headcount (excl. founders) or customers
const formulaRows: { label: string; perUnit: number; source: MonthlyValues }[] = [ const formulaRows: { label: string; perUnit: number; source: MonthlyValues }[] = [
{ label: 'Fort-/Weiterbildungskosten (F)', perUnit: 300, source: hcWithoutFounders }, { label: 'Fort-/Weiterbildungskosten (F)', perUnit: 300, source: hcWithoutFounders },
{ label: 'Fahrzeugkosten (F)', perUnit: 200, source: hcWithoutFounders }, // KFZ costs are manual (from Jan 2028), not formula-based
{ label: 'KFZ-Steuern (F)', perUnit: 25, source: hcWithoutFounders },
{ label: 'KFZ-Versicherung (F)', perUnit: 150, source: hcWithoutFounders },
{ label: 'Reisekosten (F)', perUnit: 75, source: headcount }, { label: 'Reisekosten (F)', perUnit: 75, source: headcount },
{ label: 'Bewirtungskosten (F)', perUnit: 50, source: totalBestandskunden }, { label: 'Bewirtungskosten (F)', perUnit: 50, source: totalBestandskunden },
{ label: 'Internet/Mobilfunk (F)', perUnit: 50, source: headcount }, { label: 'Internet/Mobilfunk (F)', perUnit: 50, source: headcount },

View File

@@ -6,7 +6,6 @@ const PUBLIC_PATHS = [
'/auth', // investor login pages '/auth', // investor login pages
'/api/auth', // investor auth API '/api/auth', // investor auth API
'/api/health', '/api/health',
'/api/admin/fp-patch',
'/api/admin-auth', // admin login API '/api/admin-auth', // admin login API
'/pitch-admin/login', // admin login page '/pitch-admin/login', // admin login page
'/_next', '/_next',