fix: preserve scoped V12 diagnostics pending interrupted QA proof

This commit is contained in:
2026-11-20 22:36:41 +02:00
parent a5f3714cac
commit 74ba0bd0d2
10 changed files with 349 additions and 14 deletions
@@ -82,7 +82,11 @@ export function IntegralFinancialPlan({
em falta permanecem por determinar; indique zero apenas quando
aplicável.
</p>
<StartupAssetRequirements plan={plan} onChange={onChange} />
<StartupAssetRequirements
plan={plan}
onChange={onChange}
showError={false}
/>
<div className="grid gap-3 sm:grid-cols-2">
<label className="grid gap-1 text-sm">
Ano inicial
@@ -26,7 +26,10 @@ import { FinancialRatiosPlan } from '@/components/financial-ratios-plan';
import { PlanEconomicClassification } from '@/components/plan-economic-classification';
import { FinancialPlanDetails } from '@/components/financial-plan-details';
import { StartupAssetRequirements } from '@/components/startup-asset-requirements';
import { forecastErrorShownInReport } from '@/lib/financial-issue-presentation';
import {
forecastErrorShownInReport,
startupErrorMessage,
} from '@/lib/financial-issue-presentation';
const emptyPlan: BusinessFinancialPlanInput = {
currency: '',
@@ -947,7 +950,13 @@ export function SimulationBusinessPlan({
)}
<PlanEconomicClassification plan={plan} onChange={savePlan} />
<FinancialPlanDetails plan={plan} onChange={savePlan} />
<StartupAssetRequirements plan={plan} onChange={savePlan} />
<StartupAssetRequirements
plan={plan}
onChange={savePlan}
showError={
!forecastErrorShownInReport(plan, startupErrorMessage(plan))
}
/>
<IntegralFinancialPlan plan={plan} onChange={savePlan} />
<MarketAnalysisPlan plan={plan} onChange={savePlan} />
<FinancialRatiosPlan plan={plan} onChange={savePlan} />
@@ -2532,11 +2541,13 @@ export function SimulationBusinessPlan({
)}
</details>
{error && !forecastErrorShownInReport(plan, error) && (
<p role="alert" className="my-3 text-sm text-red-800">
{error}
</p>
)}
{error &&
error !== startupErrorMessage(plan) &&
!forecastErrorShownInReport(plan, error) && (
<p role="alert" className="my-3 text-sm text-red-800">
{error}
</p>
)}
{result && isSimulationCurrency(currency) && (
<div className="mt-4 space-y-3">
<h4 className="font-semibold">Resumo ({currency})</h4>
@@ -8,9 +8,11 @@ import { newReportAssumptions } from '@/lib/integral-financial-report';
export function StartupAssetRequirements({
plan,
onChange,
showError = true,
}: {
plan: BusinessFinancialPlanInput;
onChange: (plan: BusinessFinancialPlanInput) => void;
showError?: boolean;
}) {
const a =
plan.reportAssumptions ?? newReportAssumptions(plan.periods ?? 12);
@@ -166,7 +168,7 @@ export function StartupAssetRequirements({
não se presumem vendas de activos excedentários. A
depreciação mantém a base e a vida útil declaradas.
</p>
{error && <p role="alert">{error}</p>}
{showError && error && <p role="alert">{error}</p>}
{budget && (
<>
<p>
+29 -1
View File
@@ -1837,10 +1837,38 @@ export function forecastBusinessPlan(input: BusinessFinancialPlanInput) {
entry.paymentLagMonths! < 0 ||
entry.paymentLagMonths! > 12)),
)
)
) {
// Diagnose only an already-rejected schedule; preserve every validation
// condition above and all payment calculations below.
if (useSupplierPaymentTerms && Array.isArray(schedule)) {
const overflowMonth = schedule.findIndex((entry) => {
if (!entry || !Array.isArray(entry.paymentInstallments))
return false;
try {
return (
entry.paymentInstallments.reduce(
(sum, part) =>
sum +
percentMicro(
part.percent,
'Percentagem da parcela',
),
0n,
) > 100_000_000n
);
} catch {
return false;
}
});
if (overflowMonth >= 0)
throw new Error(
`${product.label} — encomenda do mês ${overflowMonth + 1}: a soma das percentagens em «Parcelas ao fornecedor» excede 100%. Corrija os campos «Percentagem» desta encomenda; o plano não pode ser calculado com esta distribuição.`,
);
}
throw new Error(
`${product.label}: declare encomendas e prazos de entrega para todos os ${periods} meses.`,
);
}
return {
opening,
orders: schedule.slice(0, periods).map((entry, month) => ({
@@ -5,6 +5,20 @@ import {
type InvestmentReportTable,
} from './integral-financial-report.ts';
import type { BusinessFinancialPlanInput } from './business-financial-plan.ts';
import { calculateStartupAssetRequirements } from './startup-asset-requirements.ts';
/** The local startup editor owns this error when report tables are unavailable. */
export function startupErrorMessage(plan: BusinessFinancialPlanInput): string {
if (plan.startupAssetRequirements)
try {
calculateStartupAssetRequirements(plan);
} catch (cause) {
return cause instanceof Error
? cause.message
: 'Confira os dados de arranque.';
}
return '';
}
/** Do not hide a forecast error when the report editor itself cannot show the tables. */
export function forecastErrorShownInReport(
@@ -537,9 +537,13 @@ export function buildIntegralFinancialTables(
table('balance').issues.push(
`Mês ${i + 1}: existências insuficientes para as vendas declaradas.`,
);
if (depreciation > fixed || principal > loans)
if (depreciation > fixed)
table('balance').issues.push(
`Mês ${i + 1}: depreciação superior aos activos ou reembolso superior à dívida; confira os dados.`,
`Balanço Projectado — mês ${i + 1}: a depreciação acumulada excede os activos fixos disponíveis. Confira «Base depreciável contabilística» e «Vida útil (meses)» face a «Aquisição de activos» e «Activos fixos anteriores (valor líquido)»; corrija os pressupostos inconsistentes.`,
);
if (principal > loans)
table('balance').issues.push(
`Balanço Projectado — mês ${i + 1}: o capital reembolsado acumulado excede a dívida declarada. Confira «Reembolso de capital» face a «Empréstimo recebido» e «Suprimentos»; corrija os pressupostos inconsistentes.`,
);
const assets =
cash +