chore: import 1M betriebliche + fix founders start
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m5s
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 31s
CI / test-python-voice (push) Successful in 38s
CI / test-bqas (push) Successful in 32s
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m5s
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 31s
CI / test-python-voice (push) Successful in 38s
CI / test-bqas (push) Successful in 32s
This commit is contained in:
@@ -1,38 +1,43 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
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() {
|
export async function POST(request: NextRequest) {
|
||||||
|
const body = await request.json().catch(() => ({}))
|
||||||
const results: string[] = []
|
const results: string[] = []
|
||||||
|
|
||||||
// Get ALL scenarios
|
try {
|
||||||
const { rows: scenarios } = await pool.query(`SELECT id, name FROM fp_scenarios ORDER BY name`)
|
const BASE = (await pool.query("SELECT id FROM fp_scenarios WHERE is_default=true LIMIT 1")).rows[0]?.id
|
||||||
results.push(`Scenarios: ${scenarios.map(s => `${s.name}(${s.id})`).join(', ')}`)
|
if (!BASE) return NextResponse.json({ ok: false, error: 'No base scenario' })
|
||||||
|
|
||||||
for (const sc of scenarios) {
|
// Import betriebliche
|
||||||
const sid = sc.id
|
if (body.betriebliche?.length) {
|
||||||
|
await pool.query(`DELETE FROM fp_betriebliche_aufwendungen WHERE scenario_id=$1`, [BASE])
|
||||||
// Add Mac Studio if missing
|
for (const r of body.betriebliche) {
|
||||||
const { rows: ms } = await pool.query(`SELECT id FROM fp_investitionen WHERE scenario_id=$1 AND item_name ILIKE '%Mac Studio%'`, [sid])
|
await pool.query(
|
||||||
if (ms.length === 0) {
|
`INSERT INTO fp_betriebliche_aufwendungen (scenario_id,category,row_label,row_index,is_editable,is_sum_row,formula_desc,values,sort_order) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)`,
|
||||||
await pool.query(`INSERT INTO fp_investitionen (scenario_id,item_name,category,purchase_amount,purchase_date,afa_years,is_editable,values_invest,values_afa,sort_order) VALUES ($1,'Mac Studio (Development Server)','ausstattung',13000,'2027-01-01',3,true,'{}','{}',10)`, [sid])
|
[BASE, r.category, r.row_label, r.row_index, r.is_editable, r.is_sum_row, r.formula_desc, JSON.stringify(r.values), r.sort_order])
|
||||||
results.push(`${sc.name}: +Mac Studio`)
|
}
|
||||||
|
results.push(`betriebliche: ${body.betriebliche.length}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Markenanmeldung if missing
|
// Fix founders start_date if needed (should be Oct 2026)
|
||||||
const { rows: ma } = await pool.query(`SELECT id FROM fp_investitionen WHERE scenario_id=$1 AND item_name ILIKE '%Marke%'`, [sid])
|
const { rowCount: f1 } = await pool.query(
|
||||||
if (ma.length === 0) {
|
`UPDATE fp_personalkosten SET start_date='2026-10-01' WHERE scenario_id=$1 AND person_name ILIKE '%Benjamin%' AND (start_date IS NULL OR start_date > '2026-10-01')`, [BASE])
|
||||||
await pool.query(`INSERT INTO fp_investitionen (scenario_id,item_name,category,purchase_amount,purchase_date,afa_years,is_editable,values_invest,values_afa,sort_order) VALUES ($1,'Markenanmeldung & Domains (DPMA/EUIPO)','gwg',5000,'2025-11-01',1,true,'{}','{}',11)`, [sid])
|
const { rowCount: f2 } = await pool.query(
|
||||||
results.push(`${sc.name}: +Markenanmeldung`)
|
`UPDATE fp_personalkosten SET start_date='2026-10-01' WHERE scenario_id=$1 AND person_name ILIKE '%Sharang%' AND (start_date IS NULL OR start_date > '2026-10-01')`, [BASE])
|
||||||
}
|
if (f1 || f2) results.push(`Founders start fixed: B=${f1} S=${f2}`)
|
||||||
|
|
||||||
// Check personalkosten for founders Oct-Dec 2026
|
|
||||||
const { rows: founders } = await pool.query(`SELECT id, person_name, start_date, brutto_monthly, (values_total->>'m10')::numeric as m10 FROM fp_personalkosten WHERE scenario_id=$1 AND (person_name ILIKE '%Benjamin%' OR person_name ILIKE '%Sharang%' OR person_name ILIKE '%Boenisch%' OR person_name ILIKE '%Parnerkar%') ORDER BY sort_order`, [sid])
|
|
||||||
results.push(`${sc.name} founders: ${JSON.stringify(founders.map(f => ({name: f.person_name, start: f.start_date, brutto: f.brutto_monthly, m10: f.m10})))}`)
|
|
||||||
|
|
||||||
// Recompute
|
// Recompute
|
||||||
const r = await computeFinanzplan(pool, sid)
|
const r = await computeFinanzplan(pool, BASE)
|
||||||
results.push(`${sc.name}: cash_m60=${r.liquiditaet?.endstand?.m60}`)
|
results.push(`BASE cash_m60=${r.liquiditaet?.endstand?.m60}`)
|
||||||
|
|
||||||
|
// Verify founders
|
||||||
|
const { rows: check } = await pool.query(
|
||||||
|
`SELECT person_name, start_date, brutto_monthly, (values_total->>'m10')::numeric as okt26 FROM fp_personalkosten WHERE scenario_id=$1 AND sort_order <= 2 ORDER BY sort_order`, [BASE])
|
||||||
|
results.push(`Founders: ${JSON.stringify(check)}`)
|
||||||
|
} catch (err) {
|
||||||
|
results.push(`ERROR: ${err instanceof Error ? err.message : String(err)}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({ ok: true, results })
|
return NextResponse.json({ ok: true, results })
|
||||||
|
|||||||
Reference in New Issue
Block a user