fix(v12): complete currency schedule and import diagnostics
This commit is contained in:
@@ -87,10 +87,12 @@ export function ProjectTeamPlanner({
|
||||
value,
|
||||
onChange,
|
||||
financialPlanSnapshot = '',
|
||||
projectCurrency = '',
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
financialPlanSnapshot?: string;
|
||||
projectCurrency?: string;
|
||||
}) {
|
||||
const rows = readRows<TeamNeed>(value, teamKeys);
|
||||
const persist = (next: TeamNeed[]) => onChange(JSON.stringify(next));
|
||||
@@ -297,7 +299,10 @@ export function ProjectTeamPlanner({
|
||||
<InvestmentReportTables
|
||||
tables={[
|
||||
buildComplementaryTables(
|
||||
{ project_team_snapshot: value },
|
||||
{
|
||||
project_team_snapshot: value,
|
||||
currency: projectCurrency,
|
||||
},
|
||||
restoreBusinessPlanSnapshot(financialPlanSnapshot),
|
||||
)[2],
|
||||
]}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
businessPlanNumberError,
|
||||
exportBusinessPlanCsv,
|
||||
forecastBusinessPlan,
|
||||
financialPlanImportMessage,
|
||||
MAX_BUSINESS_PLAN_SNAPSHOT_LENGTH,
|
||||
restoreBusinessPlanSnapshot,
|
||||
serializeBusinessPlanSnapshot,
|
||||
@@ -196,10 +197,7 @@ export function SimulationBusinessPlan({
|
||||
try {
|
||||
const source = await file.text();
|
||||
const imported = restoreBusinessPlanSnapshot(source);
|
||||
if (!imported)
|
||||
throw new Error(
|
||||
'O ficheiro não contém um plano JSON reconhecido pelo InvestMoz.',
|
||||
);
|
||||
if (!imported) throw new Error(financialPlanImportMessage(source));
|
||||
savePlan(imported);
|
||||
setSnapshotError('');
|
||||
} catch (cause) {
|
||||
|
||||
@@ -3473,6 +3473,7 @@ export function SimulationForm() {
|
||||
{current.id === 'team' && (
|
||||
<>
|
||||
<ProjectTeamPlanner
|
||||
projectCurrency={String(draft.currency ?? '')}
|
||||
financialPlanSnapshot={String(
|
||||
draft.business_plan_snapshot ?? '',
|
||||
)}
|
||||
|
||||
@@ -1651,7 +1651,7 @@ export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
|
||||
throw new Error('A agenda de recuperação deve ter até 60 parcelas.');
|
||||
const recoveryMonths = new Set<number>();
|
||||
const salesRecoveryRates = new Map<number, bigint>();
|
||||
salesRecoverySchedule.forEach((entry) => {
|
||||
salesRecoverySchedule.forEach((entry, index) => {
|
||||
if (
|
||||
!Number.isSafeInteger(entry.month) ||
|
||||
entry.month < 1 ||
|
||||
@@ -1659,7 +1659,11 @@ export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
|
||||
recoveryMonths.has(entry.month)
|
||||
)
|
||||
throw new Error(
|
||||
'Cada recuperação deve ter um mês único dentro do horizonte.',
|
||||
Number.isSafeInteger(entry.month) &&
|
||||
entry.month >= 1 &&
|
||||
entry.month <= periods
|
||||
? 'Cada recuperação deve ter um mês único dentro do horizonte.'
|
||||
: `Fluxo de Caixa / Recuperação de vendas vencidas, linha ${index + 1} / Mês (${entry.month}): seleccione um mês inteiro entre 1 e ${periods}, dentro do horizonte do plano. Corrija este campo ou remova a linha inválida.`,
|
||||
);
|
||||
recoveryMonths.add(entry.month);
|
||||
const rate = percentMicro(
|
||||
@@ -1770,7 +1774,15 @@ export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
|
||||
);
|
||||
return {
|
||||
units:
|
||||
unitsByPeriod?.map(quantity) ??
|
||||
unitsByPeriod?.map((value, month) => {
|
||||
try {
|
||||
return quantity(value);
|
||||
} catch {
|
||||
throw new Error(
|
||||
`Previsão de Vendas / Unidades do produto ${index + 1}, mês ${month + 1}: preencha uma quantidade não negativa com até três casas decimais; indique zero apenas quando aplicável.`,
|
||||
);
|
||||
}
|
||||
}) ??
|
||||
Array.from({ length: periods }, (_, month) =>
|
||||
projectedUnits(input, product, month),
|
||||
),
|
||||
@@ -3487,3 +3499,4 @@ export function exportBusinessPlanCsv(
|
||||
.map((row) => row.map(csvCell).join(','))
|
||||
.join('\r\n')}`;
|
||||
}
|
||||
export { financialPlanImportMessage } from './financial-plan-import-message.ts';
|
||||
|
||||
@@ -119,7 +119,7 @@ export function buildComplementaryTables(
|
||||
staff.notes.push(`Moeda das remunerações: ${declaredCurrency}.`);
|
||||
if (!sameCurrency)
|
||||
staff.issues.push(
|
||||
'A moeda do projecto difere da moeda do plano financeiro. A reconciliação fica por determinar, sem conversão automática.',
|
||||
`Pessoal / Moeda das remunerações (${declaredCurrency}) difere de Plano financeiro / Moeda (${plan?.currency}). Confira a moeda e os montantes de origem e corrija apenas os campos incorrectos. Enquanto forem moedas diferentes, a reconciliação fica por determinar, sem conversão automática.`,
|
||||
);
|
||||
market.notes.push(
|
||||
'O total é a soma aritmética dos segmentos, sem deduplicação de clientes. Confirme eventuais sobreposições antes de o interpretar como dimensão única do mercado.',
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/** Explain a rejected snapshot only; never relax the snapshot validator. */
|
||||
export function financialPlanImportMessage(source: string): string {
|
||||
const fallback =
|
||||
'Importação / Plano financeiro: o ficheiro não contém um plano JSON reconhecido pelo InvestMoz. Seleccione um plano exportado pelo portal; o plano actual foi conservado.';
|
||||
try {
|
||||
const decoded = JSON.parse(source);
|
||||
const plan = decoded?.plan;
|
||||
if (
|
||||
!plan ||
|
||||
!Number.isSafeInteger(plan.periods) ||
|
||||
plan.periods < 1 ||
|
||||
plan.periods > 60
|
||||
)
|
||||
return fallback;
|
||||
if (
|
||||
plan.useSupplierPaymentTerms === true &&
|
||||
plan.useProductInventorySchedule !== true
|
||||
)
|
||||
return 'Importação / Fluxo de Caixa / Calcular pagamentos pelo prazo do fornecedor: este modo exige «Planear stock por produto». Active o stock por produto ou desactive os prazos do fornecedor no plano de origem e volte a importar. O plano actual foi conservado.';
|
||||
const schedules: [string, unknown][] = [
|
||||
[
|
||||
'Fluxo de Caixa / Compras para existências',
|
||||
plan.inventoryPurchaseSchedule,
|
||||
],
|
||||
[
|
||||
'Fluxo de Caixa / Pagamento de compras/variáveis',
|
||||
plan.monthlyVariableCostPaymentsByPeriod,
|
||||
],
|
||||
[
|
||||
'Lucros e Perdas / Despesas operacionais reconhecidas',
|
||||
plan.monthlyOperatingExpensesByPeriod,
|
||||
],
|
||||
[
|
||||
'Fluxo de Caixa / Pagamento de despesas operacionais',
|
||||
plan.monthlyOperatingPaymentsByPeriod,
|
||||
],
|
||||
[
|
||||
'Lucros e Perdas / Custo de pessoal reconhecido',
|
||||
plan.monthlyPayrollExpenseByPeriod,
|
||||
],
|
||||
[
|
||||
'Fluxo de Caixa / Pagamento de pessoal',
|
||||
plan.monthlyPayrollPaymentsByPeriod,
|
||||
],
|
||||
];
|
||||
if (Array.isArray(plan.products))
|
||||
plan.products.forEach(
|
||||
(product: Record<string, unknown>, index: number) => {
|
||||
if (!product || typeof product !== 'object') return;
|
||||
schedules.push(
|
||||
[
|
||||
`Previsão de Vendas / Unidades do produto ${index + 1}`,
|
||||
product.monthlyUnitsByPeriod,
|
||||
],
|
||||
[
|
||||
`Previsão de Vendas / Preço do produto ${index + 1}`,
|
||||
product.unitPriceByPeriod,
|
||||
],
|
||||
[
|
||||
`Lucros e Perdas / Custo variável do produto ${index + 1}`,
|
||||
product.unitVariableCostByPeriod,
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
for (const [label, schedule] of schedules) {
|
||||
if (
|
||||
Array.isArray(schedule) &&
|
||||
(schedule.length < plan.periods || schedule.length > 60)
|
||||
)
|
||||
return `Importação / ${label}: a agenda contém ${schedule.length} meses; deve cobrir os ${plan.periods} meses do horizonte e ter no máximo 60. Corrija a agenda no plano de origem e volte a importar. O plano actual foi conservado.`;
|
||||
}
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
Reference in New Issue
Block a user