chore: fp-patch — KFZ-Leasing 3 Fahrzeuge ab Jan 2028
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m21s
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 41s
CI / test-bqas (push) Has been cancelled
CI / test-python-voice (push) Has been cancelled

This commit is contained in:
Benjamin Admin
2026-04-22 09:16:31 +02:00
parent 4265f5175a
commit ced3333430

View File

@@ -1,30 +1,33 @@
import { NextResponse } from 'next/server'
import { NextRequest, NextResponse } from 'next/server'
import pool from '@/lib/db'
import { computeFinanzplan } from '@/lib/finanzplan/engine'
export async function POST() {
export async function POST(request: NextRequest) {
const WD = 'c0000000-0000-0000-0000-000000000200'
const results: string[] = []
try {
// Rename umsatzerloese labels
const renames: [string,string,string][] = [
['price','Cloud Starter','Preis/Monat (Starter)'],
['price','Cloud Professional','Preis/Monat (Professional)'],
['price','Cloud Enterprise','Preis/Monat (Enterprise)'],
['quantity','Cloud Starter','Anzahl Kunden (Starter)'],
['quantity','Cloud Professional','Anzahl Kunden (Professional)'],
['quantity','Cloud Enterprise','Anzahl Kunden (Enterprise)'],
['revenue','Cloud Starter','Umsatz (Starter)'],
['revenue','Cloud Professional','Umsatz (Professional)'],
['revenue','Cloud Enterprise','Umsatz (Enterprise)'],
]
for (const [sec, old, neu] of renames) {
await pool.query(`UPDATE fp_umsatzerloese SET row_label=$1 WHERE scenario_id=$2 AND section=$3 AND row_label=$4`, [neu, WD, sec, old])
}
results.push('Umsatz labels renamed')
// KFZ-Leasing rename + values
const leasing = Object.fromEntries(Array.from({length:36},(_,i)=>[`m${i+25}`,1050]))
await pool.query(`UPDATE fp_betriebliche_aufwendungen SET row_label='KFZ-Leasing (3 Fahrzeuge)', values=$1 WHERE scenario_id=$2 AND row_label IN ('Fahrzeugkosten','Fahrzeugkosten (F)')`, [JSON.stringify(leasing), WD])
// Kraftstoff (add if missing)
const fuel = Object.fromEntries(Array.from({length:36},(_,i)=>[`m${i+25}`,450]))
const {rows:ex} = await pool.query(`SELECT id FROM fp_betriebliche_aufwendungen WHERE scenario_id=$1 AND row_label='Kraftstoff / Ladestrom'`, [WD])
if (ex.length === 0) {
await pool.query(`INSERT INTO fp_betriebliche_aufwendungen (scenario_id,category,row_label,row_index,is_editable,is_sum_row,values,sort_order) VALUES ($1,'fahrzeug','Kraftstoff / Ladestrom',24,true,false,$2,24)`, [WD, JSON.stringify(fuel)])
}
// KFZ-Versicherung fix
const vers = Object.fromEntries(Array.from({length:36},(_,i)=>[`m${i+25}`,300]))
await pool.query(`UPDATE fp_betriebliche_aufwendungen SET values=$1 WHERE scenario_id=$2 AND row_label='KFZ-Versicherung'`, [JSON.stringify(vers), WD])
// KFZ-Steuern fix
const steuern = Object.fromEntries(Array.from({length:36},(_,i)=>[`m${i+25}`,45]))
await pool.query(`UPDATE fp_betriebliche_aufwendungen SET values=$1 WHERE scenario_id=$2 AND row_label ILIKE 'KFZ-Steuern%'`, [JSON.stringify(steuern), WD])
results.push('KFZ updated')
// Recompute
const r = await computeFinanzplan(pool, WD)
results.push(`WD cash_m60=${r.liquiditaet?.endstand?.m60}`)
} catch (err) {