feat(qa): integrate official Mozambique CAE into saved financial plans

This commit is contained in:
2026-11-20 14:07:27 +02:00
parent e13fd2755d
commit 4c221e0f8f
10 changed files with 3154 additions and 1 deletions
@@ -0,0 +1,59 @@
import CatalogueChoiceSelect from './catalogue-choice-select';
import {
describePlanCae,
mozambiqueCaeSource,
planCaeChoices,
selectPlanCae,
} from '@/lib/cae-mozambique';
import type { BusinessFinancialPlanInput } from '@/lib/business-financial-plan';
export function PlanEconomicClassification({
plan,
onChange,
}: {
plan: BusinessFinancialPlanInput;
onChange: (plan: BusinessFinancialPlanInput) => void;
}) {
const classification = describePlanCae(plan.economicClassification);
return (
<section
className="my-4 min-w-0 space-y-3 rounded border p-3"
aria-label="Classificação económica do plano"
>
<h3 className="font-semibold">
Actividade económica — CAE de Moçambique
</h3>
<p className="text-sm">
Escolha a subclasse correspondente à actividade efectivamente
prevista. Quando houver alternativas, confirme a actividade
principal; o sector do portal e as vendas projectadas não
determinam automaticamente a CAE.
</p>
<CatalogueChoiceSelect
label="Actividade CAE do plano"
options={planCaeChoices}
value={plan.economicClassification?.code ?? ''}
onChange={(code) =>
onChange({
...plan,
economicClassification: selectPlanCae(code),
})
}
/>
<p role="status">{classification.value}</p>
<p className="text-sm">
Escolha declarada pelo investidor, a confirmar documentalmente.
Não altera cálculos, impostos, licenças ou financiamento. Pode
continuar com «Não documentado».
</p>
<a
className="text-sm underline"
href={mozambiqueCaeSource.url}
target="_blank"
rel="noopener noreferrer"
>
Consultar CAE-Rev.2 — INE, 2008
</a>
</section>
);
}
@@ -23,6 +23,7 @@ import { SimulationAnnualExample } from '@/components/simulation-annual-example'
import { IntegralFinancialPlan } from '@/components/integral-financial-plan';
import { MarketAnalysisPlan } from '@/components/market-analysis-plan';
import { FinancialRatiosPlan } from '@/components/financial-ratios-plan';
import { PlanEconomicClassification } from '@/components/plan-economic-classification';
const emptyPlan: BusinessFinancialPlanInput = {
currency: '',
@@ -941,6 +942,7 @@ export function SimulationBusinessPlan({
}
/>
)}
<PlanEconomicClassification plan={plan} onChange={savePlan} />
<IntegralFinancialPlan plan={plan} onChange={savePlan} />
<MarketAnalysisPlan plan={plan} onChange={savePlan} />
<FinancialRatiosPlan plan={plan} onChange={savePlan} />
@@ -82,6 +82,11 @@ function validCurrency(value: string): boolean {
}
export type BusinessFinancialPlanInput = {
economicClassification?: {
code: string;
revision: string;
sourceSha256: string;
};
ratioCurrentBalances?: {
assetsByMonth: string[];
liabilitiesByMonth: string[];
File diff suppressed because it is too large Load Diff
+60
View File
@@ -0,0 +1,60 @@
import { mozambiqueCaeSubclasses } from './cae-mozambique-data.ts';
export const mozambiqueCaeSource = {
revision: 'CAE-Rev.2',
title: 'Classificação das Actividades Económicas de Moçambique — INE, 2008',
url: 'https://www.ine.gov.mz/documents/20119/280028/Classificacao%20Das%20Actividades%20Economicas%20de%20Mocambique%20-CAE-REV.2.pdf/2d0e4657-e55c-3254-e815-5d0a8cb513bd?download=true&t=1725451130089&version=1.0',
sha256: 'cb3dee56db5b2c3f12e3071615725051828a9e1eba17662aa5e78d5f3356b0fc',
} as const;
export type PlanCaeSelection = {
code: string;
revision: string;
sourceSha256: string;
};
export const planCaeChoices = mozambiqueCaeSubclasses.map((node) => ({
value: node.code,
label: `${node.code} — ${node.label}`,
keywords: /hotéis/i.test(node.label) ? ['hotel'] : [],
}));
/** An explicit choice only; a sector, product name or forecast never assigns a CAE. */
export function selectPlanCae(code: string): PlanCaeSelection | undefined {
if (!code) return undefined;
if (!mozambiqueCaeSubclasses.some((node) => node.code === code))
throw Error('Seleccione uma subclasse da referência CAE apresentada.');
return {
code,
revision: mozambiqueCaeSource.revision,
sourceSha256: mozambiqueCaeSource.sha256,
};
}
export function describePlanCae(selection: unknown) {
if (selection === undefined || selection === null)
return {
value: 'Não documentado',
source: mozambiqueCaeSource.title,
confirmed: false,
};
const item = selection as Partial<PlanCaeSelection>;
const node = mozambiqueCaeSubclasses.find(
(node) => node.code === item.code,
);
if (
!node ||
item.revision !== mozambiqueCaeSource.revision ||
item.sourceSha256 !== mozambiqueCaeSource.sha256
)
return {
value: 'Classificação guardada por conferir — escolha novamente na referência oficial',
source: mozambiqueCaeSource.title,
confirmed: false,
};
return {
value: `${node.code} — ${node.label}`,
source: `${mozambiqueCaeSource.title}, página PDF ${node.page}. ${mozambiqueCaeSource.url}#page=${node.page}`,
confirmed: true,
};
}
@@ -1,4 +1,5 @@
import { displayValue } from './display-value.ts';
import { describePlanCae } from './cae-mozambique.ts';
import { buildComplementaryTables } from './complementary-report.ts';
import { buildFinancialRatiosTable } from './financial-ratios-report.ts';
import {
@@ -526,6 +527,17 @@ function makeSections(
const financialPlan = restoreBusinessPlanSnapshot(
text(draft, 'business_plan_snapshot'),
);
if (finance) {
const cae = describePlanCae(financialPlan?.economicClassification);
finance.rows.push({
field: 'Classificação CAE do plano',
value: cae.value,
classification: cae.confirmed
? 'Escolha declarada pelo investidor; a confirmar documentalmente'
: 'Não documentado ou por conferir',
origin: cae.source,
});
}
const complementaryTables = buildComplementaryTables(draft, financialPlan);
for (const [i, id] of ['market', 'execution', 'team'].entries()) {
const section = sections.get(id as DossierReportSectionId);
@@ -894,6 +906,7 @@ export function createIntegralFinancialReport(
)?.currency;
const declaredCurrency = text(draft, 'currency');
const summary = new Set([
'Classificação CAE do plano',
'Moeda do plano',
'Horizonte',
'Facturação no horizonte',