fix(qa): clarify and deduplicate V12 financial inconsistency messages
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import {
|
||||
buildIntegralFinancialTables,
|
||||
displayReportMoney,
|
||||
isReportAssumptions,
|
||||
type InvestmentReportTable,
|
||||
} from './integral-financial-report.ts';
|
||||
import type { BusinessFinancialPlanInput } from './business-financial-plan.ts';
|
||||
|
||||
/** Do not hide a forecast error when the report editor itself cannot show the tables. */
|
||||
export function forecastErrorShownInReport(
|
||||
plan: BusinessFinancialPlanInput,
|
||||
error: string,
|
||||
) {
|
||||
return (
|
||||
plan.reportSource !== 'annual_example' &&
|
||||
(!plan.reportAssumptions ||
|
||||
isReportAssumptions(plan.reportAssumptions)) &&
|
||||
buildIntegralFinancialTables(plan).some((table) =>
|
||||
table.issues.includes(error),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** Presentation only: preserve the validation result, source issue and every financial value. */
|
||||
export function financialIssueMessage(issue: string): string {
|
||||
if (
|
||||
issue ===
|
||||
'O capital discriminado não corresponde ao capital introduzido. Confira os campos de financiamento.'
|
||||
)
|
||||
return 'Financiamento — Capital próprio: este valor não coincide com a soma de Capital do proprietário, Capital do investidor e Capital adicional angariado. Corrija o Capital próprio ou a discriminação em «Crescimento, despesas discriminadas, capital e dividendos».';
|
||||
if (
|
||||
issue ===
|
||||
'A soma das existencias iniciais por produto deve coincidir com as existencias iniciais do plano.'
|
||||
)
|
||||
return 'Balanço / Existências iniciais: este valor não coincide com a soma das existências iniciais por produto em «Planear stock por produto». Corrija o total do plano ou as linhas dos produtos.';
|
||||
if (
|
||||
issue ===
|
||||
'As aquisições do cenário não correspondem às necessidades de activos. Confira os valores e adopte as aquisições calculadas.'
|
||||
)
|
||||
return 'Arranque / Aquisição de activos: este valor não coincide com as aquisições calculadas em «Caixa e activos necessários ao arranque». Confira os activos requeridos e disponíveis e adopte as aquisições calculadas, ou corrija os pressupostos.';
|
||||
const opening =
|
||||
/^Saldos de abertura não reconciliados: diferença (-?\d+\.\d{2})\./.exec(
|
||||
issue,
|
||||
);
|
||||
if (opening)
|
||||
return `Balanço projectado / Saldos de abertura: diferença ${displayReportMoney(opening[1])}. Confira «Capital e resultados anteriores» face aos saldos anteriores de caixa, activos, existências, valores a receber e valores a pagar. A diferença não permite identificar automaticamente qual saldo está errado; corrija os campos de origem, sem compensação automática.`;
|
||||
if (
|
||||
issue ===
|
||||
'O mapa de pessoal diverge da despesa de pessoal do plano. Reveja os pressupostos; nenhum valor financeiro foi sobrescrito.'
|
||||
)
|
||||
return 'Mapa de pessoal / Folha salarial prevista: este valor não coincide com «Pessoal» em Lucros e perdas («Custo mensal de pessoal» no editor). Confira quantidade, remuneração mensal e meses activos de cada função, ou a despesa de pessoal do plano. Consulte a linha «Diferença face à despesa de pessoal no plano»; nenhum valor financeiro foi sobrescrito.';
|
||||
return issue;
|
||||
}
|
||||
|
||||
/** Group identical issues across tables; callers keep the original issues for validity checks. */
|
||||
export function financialIssuesForDisplay(tables: InvestmentReportTable[]) {
|
||||
const groups = new Map<string, { message: string; tables: string[] }>();
|
||||
for (const table of tables) {
|
||||
for (const issue of table.issues) {
|
||||
if (
|
||||
issue ===
|
||||
'Existem períodos não reconciliados; reveja as rubricas indicadas.' &&
|
||||
table.issues.some((detail) =>
|
||||
detail.startsWith(
|
||||
'Saldos de abertura não reconciliados: diferença ',
|
||||
),
|
||||
)
|
||||
)
|
||||
continue;
|
||||
const message = financialIssueMessage(issue);
|
||||
const group = groups.get(message) ?? { message, tables: [] };
|
||||
if (!group.tables.includes(table.title))
|
||||
group.tables.push(table.title);
|
||||
groups.set(message, group);
|
||||
}
|
||||
}
|
||||
return [...groups.values()];
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
TextRun,
|
||||
WidthType,
|
||||
} from 'docx';
|
||||
import { financialIssuesForDisplay } from './financial-issue-presentation.ts';
|
||||
import JSZip from 'jszip';
|
||||
import { investmentReportTableSlices } from './integral-financial-report.ts';
|
||||
import {
|
||||
@@ -451,6 +452,17 @@ export async function generateProjectDossierDocx(
|
||||
);
|
||||
const table = sectionTable(section);
|
||||
if (table) children.push(table);
|
||||
for (const issue of financialIssuesForDisplay(section.tables ?? [])) {
|
||||
children.push(
|
||||
new Paragraph({ text: issue.message, keepNext: true }),
|
||||
);
|
||||
children.push(
|
||||
new Paragraph({
|
||||
text: `Tabelas afectadas: ${issue.tables.join('; ')}.`,
|
||||
keepNext: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
for (const entry of section.tables ?? []) {
|
||||
children.push(
|
||||
new Paragraph({
|
||||
@@ -459,7 +471,7 @@ export async function generateProjectDossierDocx(
|
||||
keepNext: true,
|
||||
}),
|
||||
);
|
||||
for (const note of [...entry.issues, ...entry.notes])
|
||||
for (const note of entry.notes)
|
||||
children.push(new Paragraph({ text: note, keepNext: true }));
|
||||
for (const slice of investmentReportTableSlices(entry)) {
|
||||
// Word merges adjacent tables and then repeats the first
|
||||
@@ -640,9 +652,15 @@ export async function createProjectDossierPrintHtml(
|
||||
]),
|
||||
),
|
||||
);
|
||||
for (const issue of financialIssuesForDisplay(section.tables ?? [])) {
|
||||
content.push(`<p>${escapeHtml(issue.message)}</p>`);
|
||||
content.push(
|
||||
`<p>Tabelas afectadas: ${escapeHtml(issue.tables.join('; '))}.</p>`,
|
||||
);
|
||||
}
|
||||
for (const entry of section.tables ?? []) {
|
||||
content.push(`<h3>${escapeHtml(entry.title)}</h3>`);
|
||||
for (const note of [...entry.issues, ...entry.notes])
|
||||
for (const note of entry.notes)
|
||||
content.push(`<p>${escapeHtml(note)}</p>`);
|
||||
for (const slice of investmentReportTableSlices(entry))
|
||||
content.push(htmlTable(slice.headers, slice.rows));
|
||||
|
||||
Reference in New Issue
Block a user