Preparar obriga??o PPC ordin?ria com recupera??o e relat?rio no dossier
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import { newPpcObligation } from '../../../resources/js/lib/irpc-ppc-obligation.ts';
|
||||
export const plan = () => ({
|
||||
...newPpcObligation('123456789', '2026'),
|
||||
scope: 'ordinary_resident',
|
||||
previousYear: '2025',
|
||||
previousFullCalendarYear: 'yes',
|
||||
previousTax: '100000',
|
||||
previousWithholdings: '10000',
|
||||
assessmentReference: 'SYNTHETIC prior assessment21(1)',
|
||||
withholdingReference: 'SYNTHETIC prior RF reconciliation',
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import { compileFunction } from 'node:vm';
|
||||
import { createRequire } from 'node:module';
|
||||
import React from 'react';
|
||||
import ts from 'typescript';
|
||||
import * as annual from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import * as investment from '../../resources/js/lib/irpc-ppc-obligation.ts';
|
||||
import * as rational from '../../resources/js/lib/fiscal-rational.ts';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {plan} from './helpers/irpc-ppc-obligation-case.mjs';
|
||||
import { investmentCase } from './helpers/irpc-investment-case.mjs';
|
||||
|
||||
const require = createRequire(import.meta.url),
|
||||
module = { exports: {} };
|
||||
const source = fs.readFileSync(
|
||||
new URL(
|
||||
'../../resources/js/components/simulation-irpc-ppc-obligation.tsx',
|
||||
import.meta.url,
|
||||
),
|
||||
'utf8',
|
||||
);
|
||||
const output = ts.transpileModule(source, {
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022,
|
||||
jsx: ts.JsxEmit.ReactJSX,
|
||||
},
|
||||
}).outputText;
|
||||
compileFunction(output, ['require', 'module', 'exports'])(
|
||||
(name) =>
|
||||
name === '@/lib/irpc-annual-settlement'
|
||||
? annual
|
||||
: name === '@/lib/irpc-ppc-obligation'
|
||||
? investment
|
||||
: name === '@/lib/fiscal-rational'
|
||||
? rational
|
||||
: name === './simulation-irpc-special'
|
||||
? { QualificationFields: () => null }
|
||||
: name === './fiscal-proof-parcel'
|
||||
? { FiscalProofParcelFields: () => null }
|
||||
: require(name),
|
||||
module,
|
||||
module.exports,
|
||||
);
|
||||
const Component = module.exports.SimulationIrpcPpcObligation;
|
||||
const text = (node) =>
|
||||
typeof node === 'string' || typeof node === 'number'
|
||||
? String(node)
|
||||
: React.isValidElement(node)
|
||||
? React.Children.toArray(node.props.children).map(text).join('')
|
||||
: '';
|
||||
const all = (node) =>
|
||||
React.isValidElement(node)
|
||||
? [node, ...React.Children.toArray(node.props.children).flatMap(all)]
|
||||
: [];
|
||||
function harness(c) {
|
||||
let b = c.b;
|
||||
return {
|
||||
book: () => b,
|
||||
render: () =>
|
||||
Component({
|
||||
draft: c.d,
|
||||
book: b,
|
||||
onChange: (next) => {
|
||||
b = {...b,ppcObligation:next};
|
||||
},
|
||||
}),
|
||||
click(label) {
|
||||
const button = all(this.render()).find(
|
||||
(n) => n.type === 'button' && text(n) === label,
|
||||
);
|
||||
assert.ok(button, label);
|
||||
button.props.onClick();
|
||||
},
|
||||
change(label, value) {
|
||||
const input = all(this.render()).find(
|
||||
(n) => n.props['aria-label'] === label,
|
||||
);
|
||||
assert.ok(input, label);
|
||||
input.props.onChange({ target: { value } });
|
||||
},
|
||||
};
|
||||
}
|
||||
test('actual progressive PPC form reuses subject, retains deliberate edits and exposes calendar separately from paid proofs',()=>{
|
||||
const c=investmentCase(),h=harness(c);h.click('Preparar obrigação PPC');assert.equal(h.book().ppcObligation.subjectNuit,c.b.subjectNuit);assert.equal(h.book().ppcObligation.previousTax,'');
|
||||
h.change('Enquadramento PPC','ordinary_resident');h.change('Exercício anterior — PPC','2025');h.change('Exercício anterior civil completo','yes');h.change('Imposto liquidado anterior21(1) — MZN','100001');h.change('Retenções na fonte anteriores — MZN','10000');h.change('Fonte da liquidação anterior — PPC','SYNTHETIC tax');h.change('Fonte das retenções anteriores — PPC','SYNTHETIC RF');
|
||||
assert.match(text(h.render()),/75000/);assert.match(text(h.render()),/2026-05/);assert.deepEqual(h.book().ppc,c.b.ppc);
|
||||
h.change('Enquadramento PPC','other');assert.equal(h.book().ppcObligation.previousTax,'100001');assert.match(text(h.render()),/Outros períodos/);h.change('Enquadramento PPC','ordinary_resident');assert.match(text(h.render()),/75000/);
|
||||
const html=renderToStaticMarkup(Component({book:{...c.b,ppcObligation:{...plan(),subjectNuit:c.b.subjectNuit}},onChange:()=>{}}));assert.match(html,/2026-09/);assert.match(html,/Fonte e limites/);
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
calculatePpcObligation,
|
||||
validatePpcObligation,
|
||||
} from '../../resources/js/lib/irpc-ppc-obligation.ts';
|
||||
import { combinedCase } from './helpers/irpc-investment-combination-case.mjs';
|
||||
import {
|
||||
calculateAnnual,
|
||||
recordAnnual,
|
||||
annualCurrent,
|
||||
saveAnnualBook,
|
||||
annualBook,
|
||||
annualHtml,
|
||||
} from '../../resources/js/lib/irpc-annual-settlement.ts';
|
||||
import { plan } from './helpers/irpc-ppc-obligation-case.mjs';
|
||||
const f = (n) => ({ numerator: String(n), denominator: '1' });
|
||||
const calculate = (p) =>
|
||||
calculatePpcObligation(p, '123456789', '2026', 'normal');
|
||||
test('PPC applies80% then three equal instalments rounded upwards to1000, not rounding annual first', () => {
|
||||
let m = calculate(plan());
|
||||
assert.deepEqual(m.base, f(90000));
|
||||
assert.deepEqual(m.annualBeforeRounding, f(72000));
|
||||
assert.deepEqual(m.instalment, f(24000));
|
||||
assert.deepEqual(m.total, f(72000));
|
||||
assert.deepEqual(
|
||||
m.schedule.map((s) => s.month),
|
||||
['2026-05', '2026-07', '2026-09'],
|
||||
);
|
||||
m = calculate({ ...plan(), previousTax: '100001' });
|
||||
assert.deepEqual(m.instalment, f(25000));
|
||||
assert.deepEqual(m.total, f(75000));
|
||||
assert.equal(m.paymentExecuted, false);
|
||||
assert.equal(m.annualDeductionCreated, false);
|
||||
});
|
||||
test('explicit zero and cents retain exact statutory rounding', () => {
|
||||
assert.deepEqual(
|
||||
calculate({ ...plan(), previousTax: '10000' }).total,
|
||||
f(0),
|
||||
);
|
||||
assert.deepEqual(
|
||||
calculate({ ...plan(), previousTax: '10000.01' }).total,
|
||||
f(3000),
|
||||
);
|
||||
});
|
||||
test('unknown,negative base,other periods,wrong subject/year and absent evidence remain indeterminate', () => {
|
||||
for (const change of [
|
||||
{ previousTax: '' },
|
||||
{ previousTax: '1,00' },
|
||||
{ previousTax: '9999' },
|
||||
{ scope: 'other' },
|
||||
{ previousFullCalendarYear: 'no' },
|
||||
{ previousYear: '2024' },
|
||||
{ subjectNuit: '999999999' },
|
||||
{ year: '2027' },
|
||||
{ assessmentReference: '' },
|
||||
{ withholdingReference: '' },
|
||||
]) {
|
||||
const m = calculate({ ...plan(), ...change });
|
||||
assert.ok(m.pending.length);
|
||||
assert.equal(m.instalment, null);
|
||||
assert.deepEqual(m.schedule, []);
|
||||
}
|
||||
assert.throws(() =>
|
||||
validatePpcObligation({ ...plan(), previousTax: null }),
|
||||
);
|
||||
});
|
||||
test('preparation survives existing book, versions/history/report; obligation never becomes paid PPC deduction', () => {
|
||||
const { d, b } = combinedCase(),
|
||||
before = calculateAnnual(d, b);
|
||||
let old = recordAnnual(d, b, '2026-11-11T10:00:00Z');
|
||||
old.ppcObligation = { ...plan(), subjectNuit: b.subjectNuit, year: b.year };
|
||||
assert.equal(annualCurrent(d, old), false);
|
||||
const current = recordAnnual(d, old, '2026-11-11T10:01:00Z');
|
||||
d.modelo_a_snapshot = saveAnnualBook(d, current);
|
||||
const recovered = annualBook(d);
|
||||
assert.deepEqual(recovered.ppcObligation, current.ppcObligation);
|
||||
assert.deepEqual(
|
||||
recovered.result.model.arithmeticBalance,
|
||||
before.arithmeticBalance,
|
||||
);
|
||||
assert.deepEqual(recovered.ppc, b.ppc);
|
||||
assert.equal(annualCurrent(d, recovered), true);
|
||||
assert.equal(recovered.history.length, 1);
|
||||
assert.match(annualHtml(d), /PPC — obrigação preparada/);
|
||||
assert.match(annualHtml(d), /2026-05/);
|
||||
});
|
||||
Reference in New Issue
Block a user