feat(qa): integrate financial example, growth, dividends and detailed declarations
This commit is contained in:
@@ -3,20 +3,23 @@ import {
|
||||
businessPlanWarnings,
|
||||
type PlanWarningMetrics,
|
||||
type PlanWarningLimits,
|
||||
type PlanWarning,
|
||||
} from '@/lib/business-plan-guidance';
|
||||
|
||||
export function BusinessPlanWarnings({
|
||||
metrics,
|
||||
metrics = {},
|
||||
limits,
|
||||
warnings: suppliedWarnings,
|
||||
}: {
|
||||
metrics: PlanWarningMetrics;
|
||||
metrics?: PlanWarningMetrics;
|
||||
limits?: PlanWarningLimits;
|
||||
warnings?: PlanWarning[];
|
||||
}) {
|
||||
const [dismissed, setDismissed] = useState<string[]>([]);
|
||||
const scope = JSON.stringify(metrics);
|
||||
const warnings = businessPlanWarnings(metrics, limits).filter(
|
||||
(warning) => !dismissed.includes(`${scope}:${warning.id}`),
|
||||
);
|
||||
const scope = JSON.stringify([metrics, suppliedWarnings, limits]);
|
||||
const warnings = (
|
||||
suppliedWarnings ?? businessPlanWarnings(metrics, limits)
|
||||
).filter((warning) => !dismissed.includes(`${scope}:${warning.id}`));
|
||||
if (!warnings.length) return null;
|
||||
return (
|
||||
<aside
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
import type { BusinessFinancialPlanInput } from '@/lib/business-financial-plan';
|
||||
import {
|
||||
newAnnualReferencePlan,
|
||||
serializeAnnualExampleSnapshot,
|
||||
} from '@/lib/business-plan-guidance';
|
||||
|
||||
/** Optional declarations share the existing plan snapshot; no independent storage. */
|
||||
export function FinancialPlanDetails({
|
||||
plan,
|
||||
onChange,
|
||||
}: {
|
||||
plan: BusinessFinancialPlanInput;
|
||||
onChange: (plan: BusinessFinancialPlanInput) => void;
|
||||
}) {
|
||||
const input = (label: string, value: string, save: (s: string) => void) => (
|
||||
<label className="grid gap-1 text-sm">
|
||||
{label}
|
||||
<input
|
||||
className="min-w-0 rounded border p-2"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
value={value}
|
||||
onChange={(e) => save(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
<details className="my-3 space-y-3 rounded border p-3">
|
||||
<summary className="font-semibold">
|
||||
Crescimento, despesas discriminadas, capital e dividendos
|
||||
</summary>
|
||||
<label className="grid gap-1">
|
||||
Fonte do relatório financeiro consolidado
|
||||
<select
|
||||
className="rounded border p-2"
|
||||
value={plan.reportSource ?? 'investor'}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
...plan,
|
||||
reportSource: e.target.value as
|
||||
| 'investor'
|
||||
| 'annual_example',
|
||||
...(e.target.value === 'annual_example' &&
|
||||
!plan.annualExampleSnapshot
|
||||
? {
|
||||
annualExampleSnapshot:
|
||||
serializeAnnualExampleSnapshot(
|
||||
newAnnualReferencePlan(),
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="investor">Plano do investidor</option>
|
||||
<option value="annual_example">
|
||||
Exemplo sintético anual editável
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<p className="text-sm">
|
||||
A escolha do exemplo muda apenas a fonte do relatório, sem
|
||||
substituir as entradas do investidor. As edições do exemplo são
|
||||
feitas em «Carregar cenário anual de exemplo» e acompanham a
|
||||
mesma versão guardada. Escolha novamente «Plano do investidor»
|
||||
para regressar.
|
||||
</p>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={plan.applyAnnualGrowth ?? false}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
...plan,
|
||||
applyAnnualGrowth: e.target.checked,
|
||||
})
|
||||
}
|
||||
/>
|
||||
Projectar os anos seguintes com o crescimento anual declarado
|
||||
</label>
|
||||
<p className="text-sm">
|
||||
Aplica o crescimento às quantidades a partir do segundo ano,
|
||||
conservando preços e custos unitários. Agendas mensais
|
||||
explícitas prevalecem. A taxa é uma hipótese, não uma previsão
|
||||
de procura.
|
||||
</p>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!plan.operatingExpenseLines}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
...plan,
|
||||
operatingExpenseLines: e.target.checked
|
||||
? [
|
||||
'Rendas',
|
||||
'Seguros',
|
||||
'Utilidades',
|
||||
'Marketing',
|
||||
'Outras despesas',
|
||||
].map((label, i) => ({
|
||||
label,
|
||||
monthlyAmount:
|
||||
i === 4
|
||||
? plan.monthlyOperatingExpenses
|
||||
: '0',
|
||||
...(i === 4 &&
|
||||
plan.monthlyOperatingExpensesByPeriod
|
||||
? {
|
||||
amountsByPeriod: [
|
||||
...plan.monthlyOperatingExpensesByPeriod,
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
}))
|
||||
: undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
Discriminar despesas operacionais
|
||||
</label>
|
||||
{plan.operatingExpenseLines && (
|
||||
<p className="text-sm">
|
||||
O total anterior começa em Outras despesas; redistribua
|
||||
apenas montantes conhecidos. As linhas substituem o total
|
||||
reconhecido, sem alterar pagamentos. Depreciação e juros
|
||||
mantêm os campos próprios. Agendas existentes permanecem nas
|
||||
linhas respectivas.
|
||||
</p>
|
||||
)}
|
||||
{plan.operatingExpenseLines?.map((line, index) => (
|
||||
<div key={index}>
|
||||
{input(line.label, line.monthlyAmount, (value) =>
|
||||
onChange({
|
||||
...plan,
|
||||
operatingExpenseLines:
|
||||
plan.operatingExpenseLines!.map((r, i) =>
|
||||
i === index
|
||||
? { ...r, monthlyAmount: value }
|
||||
: r,
|
||||
),
|
||||
}),
|
||||
)}
|
||||
{line.amountsByPeriod && (
|
||||
<div className="grid gap-2 sm:grid-cols-3">
|
||||
{line.amountsByPeriod.map((value, month) => (
|
||||
<div key={month}>
|
||||
{input(
|
||||
`${line.label}, mês ${month + 1}`,
|
||||
value,
|
||||
(next) =>
|
||||
onChange({
|
||||
...plan,
|
||||
operatingExpenseLines:
|
||||
plan.operatingExpenseLines!.map(
|
||||
(r, i) =>
|
||||
i === index
|
||||
? {
|
||||
...r,
|
||||
amountsByPeriod:
|
||||
r.amountsByPeriod!.map(
|
||||
(
|
||||
v,
|
||||
m,
|
||||
) =>
|
||||
m ===
|
||||
month
|
||||
? next
|
||||
: v,
|
||||
),
|
||||
}
|
||||
: r,
|
||||
),
|
||||
}),
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!plan.fundingBreakdown}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
...plan,
|
||||
fundingBreakdown: e.target.checked
|
||||
? {
|
||||
ownerCapital: '',
|
||||
investorCapital: '',
|
||||
additionalCapital: '',
|
||||
}
|
||||
: undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
Discriminar o capital introduzido
|
||||
</label>
|
||||
{plan.fundingBreakdown && (
|
||||
<>
|
||||
<p className="text-sm">
|
||||
Capital adicional angariado é apenas capital próprio.
|
||||
Empréstimos, suprimentos e subvenções conservam os
|
||||
campos próprios. A soma deve corresponder ao capital
|
||||
introduzido.
|
||||
</p>
|
||||
<div className="grid gap-3 sm:grid-cols-3">
|
||||
{(
|
||||
[
|
||||
['ownerCapital', 'Capital do proprietário'],
|
||||
['investorCapital', 'Capital do investidor'],
|
||||
[
|
||||
'additionalCapital',
|
||||
'Capital adicional angariado',
|
||||
],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<div key={key}>
|
||||
{input(
|
||||
label,
|
||||
plan.fundingBreakdown![key],
|
||||
(value) => {
|
||||
const f = {
|
||||
...plan.fundingBreakdown!,
|
||||
[key]: value,
|
||||
};
|
||||
const values = Object.values(f);
|
||||
const valid = values.every((v) =>
|
||||
/^\d+(?:\.\d{1,2})?$/.test(v),
|
||||
);
|
||||
const total = values.reduce(
|
||||
(sum, v) => {
|
||||
if (
|
||||
!/^\d+(?:\.\d{1,2})?$/.test(
|
||||
v,
|
||||
)
|
||||
)
|
||||
return sum;
|
||||
const [a, b = ''] =
|
||||
v.split('.');
|
||||
return (
|
||||
sum +
|
||||
BigInt(a) * 100n +
|
||||
BigInt(b.padEnd(2, '0'))
|
||||
);
|
||||
},
|
||||
0n,
|
||||
);
|
||||
onChange({
|
||||
...plan,
|
||||
fundingBreakdown: f,
|
||||
...(valid
|
||||
? {
|
||||
equity: `${total / 100n}.${String(total % 100n).padStart(2, '0')}`,
|
||||
}
|
||||
: {}),
|
||||
});
|
||||
},
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={!!plan.dividendsByPeriod}
|
||||
onChange={(e) =>
|
||||
onChange({
|
||||
...plan,
|
||||
dividendsByPeriod: e.target.checked
|
||||
? Array(plan.periods ?? 12).fill('0')
|
||||
: undefined,
|
||||
})
|
||||
}
|
||||
/>
|
||||
Planear dividendos distribuídos por mês
|
||||
</label>
|
||||
{plan.dividendsByPeriod && (
|
||||
<>
|
||||
<p className="text-sm">
|
||||
Começa sem distribuições (zero). Cada dividendo reduz
|
||||
caixa e capital; não é despesa nem reduz o lucro. São
|
||||
hipóteses de distribuição, não pagamentos executados ou
|
||||
autorização jurídica.
|
||||
</p>
|
||||
<div className="grid gap-2 sm:grid-cols-3">
|
||||
{Array.from(
|
||||
{ length: plan.periods ?? 12 },
|
||||
(_, month) => (
|
||||
<div key={month}>
|
||||
{input(
|
||||
`Dividendos, mês ${month + 1}`,
|
||||
plan.dividendsByPeriod?.[month] ?? '',
|
||||
(value) =>
|
||||
onChange({
|
||||
...plan,
|
||||
dividendsByPeriod: Array.from(
|
||||
{
|
||||
length:
|
||||
plan.periods ?? 12,
|
||||
},
|
||||
(_, i) =>
|
||||
i === month
|
||||
? value
|
||||
: (plan
|
||||
.dividendsByPeriod?.[
|
||||
i
|
||||
] ?? ''),
|
||||
),
|
||||
}),
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</details>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import {
|
||||
isReportAssumptions,
|
||||
} from '@/lib/integral-financial-report';
|
||||
import { InvestmentReportTables } from './investment-report-tables';
|
||||
import { BusinessPlanWarnings } from './business-plan-warnings';
|
||||
import { financialPlanWarnings } from '@/lib/financial-plan-warnings';
|
||||
import { buildAnnualExampleTables } from '@/lib/annual-example-report';
|
||||
|
||||
export function IntegralFinancialPlan({
|
||||
plan,
|
||||
@@ -13,6 +16,30 @@ export function IntegralFinancialPlan({
|
||||
plan: BusinessFinancialPlanInput;
|
||||
onChange: (plan: BusinessFinancialPlanInput) => void;
|
||||
}) {
|
||||
if (plan.reportSource === 'annual_example') {
|
||||
try {
|
||||
return (
|
||||
<section aria-label="Relatório do exemplo sintético">
|
||||
<h4>Relatório do exemplo sintético anual</h4>
|
||||
<p>
|
||||
As onze tabelas abaixo usam o exemplo editável. Os dados
|
||||
reais do investimento ficam conservados separadamente.
|
||||
</p>
|
||||
<InvestmentReportTables
|
||||
tables={buildAnnualExampleTables(plan)}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
} catch (error) {
|
||||
return (
|
||||
<p role="alert">
|
||||
{error instanceof Error
|
||||
? error.message
|
||||
: 'Confira o cenário de exemplo.'}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
}
|
||||
if (plan.reportAssumptions && !isReportAssumptions(plan.reportAssumptions))
|
||||
return (
|
||||
<p role="alert">
|
||||
@@ -258,6 +285,12 @@ export function IntegralFinancialPlan({
|
||||
<InvestmentReportTables
|
||||
tables={buildIntegralFinancialTables(plan)}
|
||||
/>
|
||||
<BusinessPlanWarnings
|
||||
warnings={financialPlanWarnings(
|
||||
plan,
|
||||
buildIntegralFinancialTables(plan),
|
||||
)}
|
||||
/>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ 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';
|
||||
import { FinancialPlanDetails } from '@/components/financial-plan-details';
|
||||
|
||||
const emptyPlan: BusinessFinancialPlanInput = {
|
||||
currency: '',
|
||||
@@ -943,6 +944,7 @@ export function SimulationBusinessPlan({
|
||||
/>
|
||||
)}
|
||||
<PlanEconomicClassification plan={plan} onChange={savePlan} />
|
||||
<FinancialPlanDetails plan={plan} onChange={savePlan} />
|
||||
<IntegralFinancialPlan plan={plan} onChange={savePlan} />
|
||||
<MarketAnalysisPlan plan={plan} onChange={savePlan} />
|
||||
<FinancialRatiosPlan plan={plan} onChange={savePlan} />
|
||||
@@ -1901,13 +1903,22 @@ export function SimulationBusinessPlan({
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<MoneyInput
|
||||
label="Despesas operacionais reconhecidas"
|
||||
value={plan.monthlyOperatingExpenses}
|
||||
onChange={(value) =>
|
||||
update('monthlyOperatingExpenses', value)
|
||||
}
|
||||
/>
|
||||
{!plan.operatingExpenseLines ? (
|
||||
<MoneyInput
|
||||
label="Despesas operacionais reconhecidas"
|
||||
value={plan.monthlyOperatingExpenses}
|
||||
onChange={(value) =>
|
||||
update('monthlyOperatingExpenses', value)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<p>
|
||||
Despesas operacionais: calculadas a partir das
|
||||
linhas discriminadas acima. Os pagamentos conservam
|
||||
a sua agenda própria; o total e a agenda agregados
|
||||
anteriores ficam preservados.
|
||||
</p>
|
||||
)}
|
||||
<MoneyInput
|
||||
label="Pagamento de despesas operacionais"
|
||||
value={plan.monthlyOperatingPayments}
|
||||
@@ -1938,6 +1949,11 @@ export function SimulationBusinessPlan({
|
||||
</p>
|
||||
)}
|
||||
{moneyScheduleFields
|
||||
.filter(
|
||||
({ key }) =>
|
||||
!plan.operatingExpenseLines ||
|
||||
key !== 'monthlyOperatingExpensesByPeriod',
|
||||
)
|
||||
.filter(
|
||||
({ key }) =>
|
||||
!plan.useSupplierPaymentTerms ||
|
||||
@@ -2541,15 +2557,19 @@ export function SimulationBusinessPlan({
|
||||
>
|
||||
Exportar plano em CSV
|
||||
</button>
|
||||
<BusinessPlanWarnings
|
||||
metrics={{
|
||||
currency,
|
||||
fundingGap: Number(result.fundingGap),
|
||||
growthPercent: plan.annualGrowthPercent?.trim()
|
||||
? Number(plan.annualGrowthPercent)
|
||||
: undefined,
|
||||
}}
|
||||
/>
|
||||
{!plan.reportAssumptions &&
|
||||
plan.reportSource !== 'annual_example' && (
|
||||
<BusinessPlanWarnings
|
||||
metrics={{
|
||||
currency,
|
||||
fundingGap: Number(result.fundingGap),
|
||||
growthPercent:
|
||||
plan.annualGrowthPercent?.trim()
|
||||
? Number(plan.annualGrowthPercent)
|
||||
: undefined,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{result.fundingStatus !== 'shortfall' && (
|
||||
<p
|
||||
role="status"
|
||||
|
||||
Reference in New Issue
Block a user