Entrega dashboard e correccoes transversais preservando Ofertas instalado
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { pathStates, type PathResult } from './investor-path.ts';
|
||||
import type { SupplyAggregate } from './investor-context';
|
||||
import { restoreFinancialToolsSnapshot } from './financial-calculators.ts';
|
||||
import { restoreOperatingAssumptions } from './investment-operating-assistance.ts';
|
||||
import { buildProjectDossierRows } from './project-dossier.ts';
|
||||
import type { SwotDraft } from './investment-preparation.ts';
|
||||
import type {
|
||||
@@ -34,6 +36,7 @@ export type PreparationReport = {
|
||||
swot_review_required: boolean;
|
||||
};
|
||||
export type InvestorDossierReportInput = {
|
||||
supply_aggregates?: SupplyAggregate[];
|
||||
case: { id: string; title: string; version: number };
|
||||
context_opportunity: string | null;
|
||||
opportunity_options: unknown[];
|
||||
@@ -322,6 +325,7 @@ export function createInvestorDossierReport(
|
||||
generatedAt = new Date().toISOString(),
|
||||
): DossierReportModel {
|
||||
const index = investorDossierReportIndex(input);
|
||||
const supply = input.supply_aggregates?.at(-1);
|
||||
const row = (
|
||||
field: string,
|
||||
value: string,
|
||||
@@ -339,11 +343,101 @@ export function createInvestorDossierReport(
|
||||
result.context_state !== 'review_required'
|
||||
? 'Estimativa guardada'
|
||||
: 'Histórico — rever antes de utilizar';
|
||||
const preparation = result.preparation_snapshot ?? {};
|
||||
for (const [key, label] of Object.entries({
|
||||
total_investment: 'Investimento declarado do cenário',
|
||||
secured_amount: 'Financiamento efectivamente mobilizado',
|
||||
planned_funding: 'Financiamento previsto — não mobilizado',
|
||||
requested_funding: 'Financiamento solicitado — não mobilizado',
|
||||
approved_funding: 'Financiamento aprovado — não mobilizado',
|
||||
annual_revenue: 'Receitas anuais estimadas',
|
||||
annual_operating_costs: 'Custos anuais estimados',
|
||||
investment_budget_min: 'Orçamento previsto — mínimo do intervalo',
|
||||
investment_budget_max: 'Orçamento previsto — máximo do intervalo',
|
||||
})) {
|
||||
if (typeof preparation[key] === 'string' && preparation[key].trim())
|
||||
finance.push(
|
||||
row(
|
||||
label,
|
||||
`${preparation[key]} ${result.currency ?? ''}`.trim(),
|
||||
reference,
|
||||
state,
|
||||
),
|
||||
);
|
||||
}
|
||||
const assumptions = restoreOperatingAssumptions(
|
||||
preparation.planning_assumptions_snapshot ?? '',
|
||||
);
|
||||
if (assumptions.model) {
|
||||
const assumptionLabels = {
|
||||
model: 'Modelo escolhido para estimar receitas',
|
||||
capacity:
|
||||
assumptions.model === 'hotel'
|
||||
? 'Quartos disponíveis'
|
||||
: 'Unidades vendáveis por ciclo',
|
||||
price: 'Preço declarado',
|
||||
occupancy: 'Ocupação prevista (%)',
|
||||
frequency:
|
||||
assumptions.model === 'hotel'
|
||||
? 'Dias de funcionamento no ano'
|
||||
: 'Ciclos ou períodos no ano',
|
||||
source: 'Fundamento dos pressupostos',
|
||||
};
|
||||
for (const [key, label] of Object.entries(assumptionLabels)) {
|
||||
const value =
|
||||
key === 'model'
|
||||
? {
|
||||
hotel: 'Hotel',
|
||||
agriculture: 'Agronegócio',
|
||||
other: 'Outra actividade',
|
||||
}[assumptions.model]
|
||||
: assumptions[key as keyof typeof assumptionLabels];
|
||||
finance.push(
|
||||
row(
|
||||
label,
|
||||
value || 'Por confirmar',
|
||||
reference,
|
||||
'Pressuposto declarado, não comprova procura ou rentabilidade',
|
||||
),
|
||||
);
|
||||
}
|
||||
for (const cost of assumptions.costs)
|
||||
finance.push(
|
||||
row(
|
||||
`Custo anual — ${cost.label}`,
|
||||
cost.annual || 'Por confirmar',
|
||||
reference,
|
||||
state,
|
||||
),
|
||||
);
|
||||
}
|
||||
try {
|
||||
if (
|
||||
result.engine !== 'financial-calculators:v1' ||
|
||||
!restoreFinancialToolsSnapshot(result.financial_snapshot)
|
||||
)
|
||||
const budget = JSON.parse(
|
||||
preparation.initial_budget_snapshot ?? '{}',
|
||||
);
|
||||
if (budget.version === 1 && Array.isArray(budget.rows))
|
||||
for (const part of budget.rows) {
|
||||
if (
|
||||
typeof part?.label === 'string' &&
|
||||
typeof part?.amount === 'string'
|
||||
)
|
||||
finance.push(
|
||||
row(
|
||||
`Investimento inicial — ${part.label}`,
|
||||
part.amount || 'Por confirmar',
|
||||
reference,
|
||||
state,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
/* The original remains stored; malformed optional details do not become invented amounts. */
|
||||
}
|
||||
try {
|
||||
const tools = restoreFinancialToolsSnapshot(
|
||||
result.financial_snapshot,
|
||||
);
|
||||
if (result.engine !== 'financial-calculators:v1' || !tools)
|
||||
throw new Error('Versão não recuperável');
|
||||
const currency = result.currency ?? '';
|
||||
const baseline = new Set(
|
||||
@@ -358,6 +452,25 @@ export function createInvestorDossierReport(
|
||||
'Financiamento',
|
||||
'Orçamento',
|
||||
]);
|
||||
if (
|
||||
preparation.planning_loan === 'no' ||
|
||||
[
|
||||
tools.loan.principal,
|
||||
tools.loan.rate,
|
||||
tools.loan.months,
|
||||
].every((value) => !value.trim())
|
||||
)
|
||||
sections.delete('Empréstimo educativo');
|
||||
if (Object.values(tools.breakEven).every((value) => !value.trim()))
|
||||
sections.delete('Ponto de equilíbrio');
|
||||
if (
|
||||
[...tools.incomes, ...tools.expenses].every(
|
||||
(value) => !value.amount.trim(),
|
||||
)
|
||||
)
|
||||
sections.delete('Orçamento');
|
||||
if (Object.values(tools.funding).every((value) => !value.trim()))
|
||||
sections.delete('Financiamento');
|
||||
const rows = buildProjectDossierRows({
|
||||
currency,
|
||||
financial_tools_snapshot: result.financial_snapshot,
|
||||
@@ -400,6 +513,50 @@ export function createInvestorDossierReport(
|
||||
'O índice referencia os originais; não incorpora automaticamente os seus anexos nem envia dados a entidades externas.',
|
||||
],
|
||||
sections: [
|
||||
{
|
||||
id: 'supply',
|
||||
title: 'Actividades existentes — análise agregada',
|
||||
private: true,
|
||||
paragraphs: supply
|
||||
? [
|
||||
`Consulta de ${supply.recorded_at}; contexto v${supply.context_revision}.`,
|
||||
`Âmbito: ${supply.scope.name} (${supply.scope.level}). Local escolhido: ${supply.requested_territory.name}.`,
|
||||
supply.broader_context
|
||||
? 'Contexto administrativo mais amplo; não representa apenas a localidade escolhida.'
|
||||
: 'Âmbito da localização escolhida.',
|
||||
supply.context_revision !==
|
||||
input.investment_context?.revision
|
||||
? 'Contexto alterado; análise anterior preservada e por rever.'
|
||||
: 'Análise guardada para esta revisão do contexto.',
|
||||
supply.interpretation,
|
||||
supply.limitations,
|
||||
]
|
||||
: ['Análise agregada ainda não guardada neste dossier.'],
|
||||
rows: supply
|
||||
? [
|
||||
row(
|
||||
'Entidades identificadas administrativamente',
|
||||
String(supply.entities),
|
||||
),
|
||||
row(
|
||||
'Observações repetidas, separadas do total',
|
||||
String(supply.repeated),
|
||||
),
|
||||
row(
|
||||
'Identificações incertas, separadas do total',
|
||||
String(supply.uncertain),
|
||||
),
|
||||
...supply.groups.map((group) =>
|
||||
row(
|
||||
group.label,
|
||||
String(group.total),
|
||||
`${group.first_year ?? 'Período por confirmar'}–${group.last_year ?? ''}; ${supply.scope.name}`,
|
||||
'Actividade actual e relação económica por confirmar',
|
||||
),
|
||||
),
|
||||
]
|
||||
: [],
|
||||
},
|
||||
{
|
||||
id: 'project',
|
||||
title: 'Investimento e localização em preparação',
|
||||
@@ -410,11 +567,16 @@ export function createInvestorDossierReport(
|
||||
rows: Object.entries({
|
||||
project_title: 'Projecto',
|
||||
project_summary: 'Descrição',
|
||||
products_services: 'Actividade e produtos ou serviços',
|
||||
sector: 'Sector',
|
||||
province: 'Província',
|
||||
district: 'Distrito',
|
||||
location: 'Localização',
|
||||
total_investment: 'Investimento previsto',
|
||||
investment_budget_min:
|
||||
'Orçamento previsto — mínimo do intervalo',
|
||||
investment_budget_max:
|
||||
'Orçamento previsto — máximo do intervalo',
|
||||
currency: 'Moeda',
|
||||
expected_start_date: 'Início previsto',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user