93 lines
3.8 KiB
TypeScript
93 lines
3.8 KiB
TypeScript
import type { BusinessFinancialPlanInput } from '@/lib/business-financial-plan';
|
|
import { buildFinancialRatiosTable } from '@/lib/financial-ratios-report';
|
|
import { InvestmentReportTables } from './investment-report-tables';
|
|
export function FinancialRatiosPlan({
|
|
plan,
|
|
onChange,
|
|
}: {
|
|
plan: BusinessFinancialPlanInput;
|
|
onChange: (p: BusinessFinancialPlanInput) => void;
|
|
}) {
|
|
const periods = plan.periods ?? 12,
|
|
s = plan.ratioCurrentBalances;
|
|
if (
|
|
s &&
|
|
(!Array.isArray(s.assetsByMonth) ||
|
|
!Array.isArray(s.liabilitiesByMonth) ||
|
|
s.assetsByMonth.some((x) => typeof x !== 'string') ||
|
|
s.liabilitiesByMonth.some((x) => typeof x !== 'string'))
|
|
)
|
|
return (
|
|
<p role="alert">
|
|
A classificação corrente guardada tem uma estrutura
|
|
desconhecida. O original foi preservado.
|
|
</p>
|
|
);
|
|
const save = (
|
|
key: 'assetsByMonth' | 'liabilitiesByMonth',
|
|
index: number,
|
|
value: string,
|
|
) =>
|
|
onChange({
|
|
...plan,
|
|
ratioCurrentBalances: {
|
|
assetsByMonth: s?.assetsByMonth ?? Array(periods).fill(''),
|
|
liabilitiesByMonth:
|
|
s?.liabilitiesByMonth ?? Array(periods).fill(''),
|
|
[key]: Array.from(
|
|
{ length: Math.max(periods, s?.[key].length ?? 0) },
|
|
(_, i) => (i === index ? value : (s?.[key][i] ?? '')),
|
|
),
|
|
},
|
|
});
|
|
return (
|
|
<details className="my-4 rounded border p-3">
|
|
<summary>Rácios financeiros e classificação corrente</summary>
|
|
<p className="my-2 text-sm">
|
|
Para a liquidez, declare os totais classificados como activo e
|
|
passivo correntes no fecho de cada mês, segundo os vencimentos
|
|
aplicáveis. Não alteram o balanço. Vazio permanece por
|
|
determinar; zero só quando aplicável. Os restantes rácios
|
|
utilizam as demonstrações já guardadas.
|
|
</p>
|
|
<details>
|
|
<summary>Classificar saldos correntes para liquidez</summary>
|
|
{Array.from({ length: periods }, (_, i) => (
|
|
<fieldset
|
|
key={i}
|
|
className="my-2 grid gap-2 rounded border p-2 sm:grid-cols-2"
|
|
>
|
|
<legend>Mês {i + 1}</legend>
|
|
{(['assetsByMonth', 'liabilitiesByMonth'] as const).map(
|
|
(key) => (
|
|
<label
|
|
key={key}
|
|
className="grid min-w-0 gap-1 text-sm"
|
|
>
|
|
{key === 'assetsByMonth'
|
|
? 'Activo corrente'
|
|
: 'Passivo corrente'}{' '}
|
|
— mês {i + 1}
|
|
<input
|
|
className="min-w-0 rounded border p-2"
|
|
type="number"
|
|
min="0"
|
|
step="0.01"
|
|
value={s?.[key][i] ?? ''}
|
|
onChange={(e) =>
|
|
save(key, i, e.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
),
|
|
)}
|
|
</fieldset>
|
|
))}
|
|
</details>
|
|
<InvestmentReportTables
|
|
tables={[buildFinancialRatiosTable(plan)]}
|
|
/>
|
|
</details>
|
|
);
|
|
}
|