feat(irpc): demonstrate ordinary economic credit and compatible carry in QA

This commit is contained in:
2026-10-28 14:29:55 +02:00
parent 6ededb597a
commit aae67c169d
21 changed files with 882 additions and 37 deletions
+4 -1
View File
@@ -1,8 +1,9 @@
import {subtractFractions, decimalFraction, type FiscalFraction} from './fiscal-rational.ts';
import {validateProofParcel, requireProofParcel, type FiscalProofParcel} from './fiscal-proof-parcel.ts';
export const pecVersion = 'IRPC-PEC/1';
export const pecSource = 'CIRPC, art. 66(1–2), Lei 34/2007, exemplar BR52, p. 768-(72): dedução após créditos anteriores, até à colecta, sem reembolso do PEC. Recorte demonstrado: pagamento efectivo do próprio exercício 2026, residente geral, ano civil, MZN. Não calcula a obrigação PEC, transporte, caducidade ou consumo de saldos oficiais.';
export type PecPayment = {
export type PecPayment = FiscalProofParcel & {
id: string; document: string; issuer: string; date: string; subjectNuit: string;
year: string; currency: string; proofAmount: string; amount: string;
effective: '' | 'yes' | 'no'; reference: string;
@@ -15,6 +16,7 @@ export function validatePec(p: PecPayments) {
if (!p || p.version !== 1 || !['', 'known', 'absent'].includes(p.state) || typeof p.reference !== 'string' || !Array.isArray(p.rows) || new Set(p.rows.map(r => r?.id)).size !== p.rows.length || p.rows.some(r => !r || keys.some(k => typeof (r as unknown as Record<string, unknown>)[k] !== 'string') || !['', 'yes', 'no'].includes(r.effective))) {
throw Error('Comprovativos PEC não recuperáveis; originais conservados.');
}
for (const r of p.rows) validateProofParcel(r);
}
export const pecCompare = (a: FiscalFraction, b: FiscalFraction) => BigInt(a.numerator) * BigInt(b.denominator) - BigInt(b.numerator) * BigInt(a.denominator);
const money = (s: string) => {
@@ -22,6 +24,7 @@ const money = (s: string) => {
return decimalFraction(s);
};
export function pecPaymentValue(r: PecPayment, subjectNuit: string, year: string) {
requireProofParcel(r);
if (!r.id.trim() || !r.document.trim() || !r.issuer.trim() || !r.reference.trim() || !r.priorUseReference.trim() || r.effective !== 'yes' || r.currency !== 'MZN' || !/^20\d{2}-\d{2}-\d{2}$/.test(r.date) || !Number.isFinite(Date.parse(r.date)) || new Date(r.date).toISOString().slice(0, 10) !== r.date || !r.date.startsWith(year + '-') || r.subjectNuit !== subjectNuit || r.year !== year || year !== '2026') {
throw Error('PEC: exige prova efectiva, natureza PEC, titular, exercício 2026, data válida e MZN; saldos anteriores e previsões ficam separados.');
}