2e8cbfff3f
Build pitch-deck / build-push-deploy (push) Successful in 1m49s
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 40s
CI / test-python-voice (push) Successful in 29s
CI / test-bqas (push) Successful in 29s
Adds /pitch-print/[versionId] — a server-rendered, print-CSS-optimized page that generates investor-ready PDFs via the browser's native print dialog (Save as PDF). Two variants per version: - Standard PDF (9 pages): Cover, Problem, Solution, Products, Market, Team, Milestones, The Ask - Financial PDF (+4 pages): adds Financials P&L table (aggregated from pitch_fm_results), Assumptions, Cap Table, Legal Disclaimer White background with indigo accents, A4 landscape via @page CSS, all color-rendered in print via print-color-adjust: exact. Auto-triggers window.print() 900ms after load. Admin toolbar visible on screen only. Export buttons added to /pitch-admin/versions/[id] detail page. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
102 lines
3.6 KiB
TypeScript
102 lines
3.6 KiB
TypeScript
import { redirect, notFound } from 'next/navigation'
|
|
import pool from '@/lib/db'
|
|
import { getAdminFromCookie } from '@/lib/admin-auth'
|
|
import {
|
|
Language, PitchData, PitchCompany, PitchTeamMember, PitchFinancial, PitchMarket,
|
|
PitchCompetitor, PitchFeature, PitchMilestone, PitchMetric, PitchFunding, PitchProduct,
|
|
FpScenarioRef, FMResult, FMAssumption,
|
|
} from '@/lib/types'
|
|
import PrintDeck from './_components/PrintDeck'
|
|
|
|
interface Ctx {
|
|
params: Promise<{ versionId: string }>
|
|
searchParams: Promise<{ financial?: string; lang?: string }>
|
|
}
|
|
|
|
export default async function PitchPrintPage({ params, searchParams }: Ctx) {
|
|
const admin = await getAdminFromCookie()
|
|
if (!admin) redirect('/pitch-admin/login')
|
|
|
|
const { versionId } = await params
|
|
const { financial: finParam, lang: langParam } = await searchParams
|
|
const financial = finParam === 'true' || finParam === '1'
|
|
const lang: Language = langParam === 'en' ? 'en' : 'de'
|
|
|
|
// Version metadata
|
|
const verRes = await pool.query(
|
|
`SELECT name FROM pitch_versions WHERE id = $1`,
|
|
[versionId],
|
|
)
|
|
if (verRes.rows.length === 0) notFound()
|
|
const versionName: string = verRes.rows[0].name
|
|
|
|
// Version data tables (snapshot)
|
|
const dataRes = await pool.query(
|
|
`SELECT table_name, data FROM pitch_version_data WHERE version_id = $1`,
|
|
[versionId],
|
|
)
|
|
|
|
const map: Record<string, unknown[]> = {}
|
|
for (const row of dataRes.rows) {
|
|
map[row.table_name] = typeof row.data === 'string' ? JSON.parse(row.data) : row.data
|
|
}
|
|
|
|
if (Object.keys(map).length === 0) {
|
|
return (
|
|
<div style={{ padding: '40px', fontFamily: 'system-ui', color: '#374151' }}>
|
|
<h2>Version has no data</h2>
|
|
<p>Please make sure the version has been populated with pitch data before exporting.</p>
|
|
<a href={`/pitch-admin/versions/${versionId}`} style={{ color: '#6366f1' }}>← Back to version</a>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const pitchData: PitchData = {
|
|
company: ((map.company || [])[0] || {}) as PitchCompany,
|
|
team: (map.team || []) as PitchTeamMember[],
|
|
financials: (map.financials || []) as PitchFinancial[],
|
|
market: (map.market || []) as PitchMarket[],
|
|
competitors: (map.competitors || []) as PitchCompetitor[],
|
|
features: (map.features || []) as PitchFeature[],
|
|
milestones: (map.milestones || []) as PitchMilestone[],
|
|
metrics: (map.metrics || []) as PitchMetric[],
|
|
funding: ((map.funding || [])[0] || {}) as PitchFunding,
|
|
products: (map.products || []) as PitchProduct[],
|
|
fp_scenarios: (map.fm_scenarios || []) as FpScenarioRef[],
|
|
}
|
|
|
|
// Financial variant: fetch FM results + parse assumptions
|
|
let fmResults: FMResult[] = []
|
|
let fmAssumptions: FMAssumption[] = []
|
|
|
|
if (financial) {
|
|
const scenarios = (map.fm_scenarios || []) as FpScenarioRef[]
|
|
const defaultScenario = scenarios.find(s => s.is_default) ?? scenarios[0] ?? null
|
|
|
|
if (defaultScenario?.id) {
|
|
const resultsRes = await pool.query(
|
|
`SELECT * FROM pitch_fm_results WHERE scenario_id = $1 ORDER BY month`,
|
|
[defaultScenario.id],
|
|
)
|
|
fmResults = resultsRes.rows as FMResult[]
|
|
}
|
|
|
|
const rawAssumptions = (map.fm_assumptions || []) as Array<Record<string, unknown>>
|
|
fmAssumptions = rawAssumptions.map(a => ({
|
|
...a,
|
|
value: typeof a.value === 'string' ? JSON.parse(a.value as string) : a.value,
|
|
})) as FMAssumption[]
|
|
}
|
|
|
|
return (
|
|
<PrintDeck
|
|
pitchData={pitchData}
|
|
versionName={versionName}
|
|
fmResults={fmResults}
|
|
fmAssumptions={fmAssumptions}
|
|
financial={financial}
|
|
lang={lang}
|
|
/>
|
|
)
|
|
}
|