117 lines
4.3 KiB
JavaScript
117 lines
4.3 KiB
JavaScript
import {
|
|
calculatePecPlan,
|
|
newPecPlan,
|
|
} from '../resources/js/lib/irpc-pec-plan.ts';
|
|
import fs from 'node:fs';
|
|
import assert from 'node:assert/strict';
|
|
import { combinedCase } from '../tests/frontend/helpers/irpc-investment-combination-case.mjs';
|
|
import { plan } from '../tests/frontend/helpers/irpc-pec-obligation-case.mjs';
|
|
import { calculatePecObligation } from '../resources/js/lib/irpc-pec-obligation.ts';
|
|
import {
|
|
recordAnnual,
|
|
saveAnnualBook,
|
|
annualBook,
|
|
annualCurrent,
|
|
annualHtml,
|
|
} from '../resources/js/lib/irpc-annual-settlement.ts';
|
|
import { createProjectDossierReport } from '../resources/js/lib/project-dossier-report.ts';
|
|
const out = new URL('../outputs/irpc-pec-plan-20261111/', import.meta.url);
|
|
fs.mkdirSync(out, { recursive: true });
|
|
const allocation = {
|
|
...newPecPlan(),
|
|
mode: 'three',
|
|
reference: 'SYNTHETIC cash-flow hypothesis for viability',
|
|
june: '10000',
|
|
august: '15000',
|
|
october: '15000',
|
|
};
|
|
const scenarios = {
|
|
three: { plan: allocation },
|
|
single: { plan: { ...allocation, mode: 'single', singleMonth: '2026-06' } },
|
|
mismatch: { plan: { ...allocation, october: '14000' } },
|
|
changed_total: { previousTurnover: '20000000', plan: allocation },
|
|
};
|
|
for (const [name, changes] of Object.entries(scenarios)) {
|
|
if (process.argv[2] === 'generate') {
|
|
const { d, b } = combinedCase();
|
|
const prior = recordAnnual(d, b, '2026-11-11T10:00:00Z');
|
|
prior.pecObligation = {
|
|
...plan(),
|
|
subjectNuit: b.subjectNuit,
|
|
year: b.year,
|
|
...changes,
|
|
};
|
|
const next = recordAnnual(d, prior, '2026-11-11T10:01:00Z');
|
|
d.modelo_a_snapshot = saveAnnualBook(d, next);
|
|
fs.writeFileSync(new URL(name + '.json', out), JSON.stringify(d));
|
|
} else {
|
|
const d = JSON.parse(
|
|
fs.readFileSync(
|
|
new URL('recovered-' + name + '.json', out),
|
|
'utf8',
|
|
),
|
|
),
|
|
b = annualBook(d),
|
|
m = calculatePecObligation(
|
|
b.pecObligation,
|
|
b.subjectNuit,
|
|
b.year,
|
|
b.assessment,
|
|
);
|
|
assert.equal(annualCurrent(d, b), true);
|
|
assert.equal(b.history.length, 1);
|
|
assert.deepEqual(b.result.model.arithmeticBalance, {
|
|
numerator: '138',
|
|
denominator: '1',
|
|
});
|
|
const html = annualHtml(d),
|
|
report = createProjectDossierReport(d, {
|
|
selectedSections: new Set(['finance']),
|
|
generatedAt: '2026-11-11T10:02:00Z',
|
|
});
|
|
assert.match(html, /PEC — estimativa fiscal/);
|
|
assert.match(JSON.stringify(report), /PEC — estimativa fiscal/);
|
|
assert.equal(m.paymentExecuted, false);
|
|
assert.equal(m.annualDeductionCreated, false);
|
|
const allocationModel = calculatePecPlan(
|
|
b.pecObligation.plan,
|
|
m.total,
|
|
m.notApplicable,
|
|
b.year,
|
|
);
|
|
assert.equal(
|
|
allocationModel.allocationReconciled,
|
|
['three', 'single'].includes(name),
|
|
);
|
|
assert.equal(allocationModel.legalDeadlineValidated, false);
|
|
assert.equal(allocationModel.paymentExecuted, false);
|
|
assert.equal(allocationModel.annualDeductionCreated, false);
|
|
assert.match(html, /PEC — projecção de tesouraria/);
|
|
assert.match(JSON.stringify(report), /PEC — projecção de tesouraria/);
|
|
fs.writeFileSync(new URL(name + '-report.html', out), html);
|
|
fs.writeFileSync(
|
|
new URL(name + '-verification.json', out),
|
|
JSON.stringify(
|
|
{
|
|
synthetic: true,
|
|
apiRecovered: true,
|
|
current: true,
|
|
historyPreserved: true,
|
|
annualBalanceUnchanged: true,
|
|
report: true,
|
|
visualReview: false,
|
|
model: m,
|
|
allocationModel,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
console.log(
|
|
process.argv[2] === 'generate'
|
|
? 'Four synthetic PEC cash-flow scenarios prepared.'
|
|
: 'Four native recovered PEC cash-flow scenarios recalculated and reported without creating deductions.',
|
|
);
|