feat(pitch-deck): Use of Funds computed from fp_* spending data
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m20s
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) Failing after 22s
CI / test-python-voice (push) Successful in 32s
CI / test-bqas (push) Successful in 35s
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m20s
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) Failing after 22s
CI / test-python-voice (push) Successful in 32s
CI / test-bqas (push) Successful in 35s
Use of Funds pie chart now shows actual spending breakdown from fp_* tables (months 8-24) instead of manually set percentages: - Engineering & Personal: from fp_personalkosten - Vertrieb & Marketing: from fp_betriebliche (marketing category) - Betrieb & Infrastruktur: from fp_betriebliche (other categories) - Hardware & Ausstattung: from fp_investitionen Falls back to funding.use_of_funds if fp_* data not yet loaded. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -104,6 +104,72 @@ export function useFpKPIs(isWandeldarlehen?: boolean) {
|
||||
load()
|
||||
}, [isWandeldarlehen])
|
||||
|
||||
// Use of Funds: compute spending breakdown m8-m24 (funding period)
|
||||
const [useOfFunds, setUseOfFunds] = useState<Array<{ category: string; label_de: string; label_en: string; percentage: number }>>([])
|
||||
|
||||
useEffect(() => {
|
||||
async function loadUoF() {
|
||||
try {
|
||||
const param = isWandeldarlehen ? '?scenarioId=c0000000-0000-0000-0000-000000000200' : ''
|
||||
const [persRes, betriebRes, investRes] = await Promise.all([
|
||||
fetch(`/api/finanzplan/personalkosten${param}`, { cache: 'no-store' }),
|
||||
fetch(`/api/finanzplan/betriebliche${param}`, { cache: 'no-store' }),
|
||||
fetch(`/api/finanzplan/investitionen${param}`, { cache: 'no-store' }),
|
||||
])
|
||||
const [pers, betrieb, invest] = await Promise.all([persRes.json(), betriebRes.json(), investRes.json()])
|
||||
|
||||
// Sum spending m8-m24
|
||||
const sumRange = (rows: SheetRow[], field: string, m1: number, m2: number) => {
|
||||
let total = 0
|
||||
for (const row of (rows || [])) {
|
||||
const vals = (row as Record<string, unknown>)[field] as Record<string, number> || row.values || {}
|
||||
for (let m = m1; m <= m2; m++) total += vals[`m${m}`] || 0
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
const personalTotal = sumRange(pers.rows || [], 'values_total', 8, 24)
|
||||
|
||||
// Marketing rows from betriebliche
|
||||
const betriebRows: SheetRow[] = betrieb.rows || []
|
||||
const marketingRows = betriebRows.filter((r: SheetRow) =>
|
||||
(r as Record<string, unknown>).category === 'marketing' && !(r as Record<string, unknown>).is_sum_row
|
||||
)
|
||||
const marketingTotal = sumRange(marketingRows, 'values', 8, 24)
|
||||
|
||||
// All other betriebliche (excl. personal, marketing, abschreibungen, sum rows)
|
||||
const otherBetrieb = betriebRows.filter((r: SheetRow) => {
|
||||
const any = r as Record<string, unknown>
|
||||
return any.category !== 'marketing' && any.category !== 'personal' && any.category !== 'abschreibungen' &&
|
||||
!any.is_sum_row && !(r.row_label || '').includes('Summe') && !(r.row_label || '').includes('SUMME')
|
||||
})
|
||||
const operationsTotal = sumRange(otherBetrieb, 'values', 8, 24)
|
||||
|
||||
// Investitionen
|
||||
const investTotal = sumRange(invest.rows || [], 'values_invest', 8, 24)
|
||||
|
||||
const grandTotal = personalTotal + marketingTotal + operationsTotal + investTotal
|
||||
if (grandTotal <= 0) return
|
||||
|
||||
const pctPersonal = Math.round((personalTotal / grandTotal) * 100)
|
||||
const pctMarketing = Math.round((marketingTotal / grandTotal) * 100)
|
||||
const pctOps = Math.round((operationsTotal / grandTotal) * 100)
|
||||
const pctInvest = Math.round((investTotal / grandTotal) * 100)
|
||||
// Adjust rounding to 100%
|
||||
const pctReserve = 100 - pctPersonal - pctMarketing - pctOps - pctInvest
|
||||
|
||||
setUseOfFunds([
|
||||
{ category: 'engineering', label_de: 'Engineering & Personal', label_en: 'Engineering & Personnel', percentage: pctPersonal },
|
||||
{ category: 'sales', label_de: 'Vertrieb & Marketing', label_en: 'Sales & Marketing', percentage: pctMarketing },
|
||||
{ category: 'operations', label_de: 'Betrieb & Infrastruktur', label_en: 'Operations & Infrastructure', percentage: pctOps },
|
||||
{ category: 'hardware', label_de: 'Hardware & Ausstattung', label_en: 'Hardware & Equipment', percentage: pctInvest },
|
||||
...(pctReserve > 0 ? [{ category: 'reserve', label_de: 'Reserve', label_en: 'Reserve', percentage: pctReserve }] : []),
|
||||
].filter(f => f.percentage > 0))
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
loadUoF()
|
||||
}, [isWandeldarlehen])
|
||||
|
||||
const last = kpis.y2030
|
||||
return { kpis, loading, last }
|
||||
return { kpis, loading, last, useOfFunds }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user