fix: complete InvesteMoz validation and error corrections

This commit is contained in:
2026-10-29 21:47:33 +02:00
parent 63147312e2
commit daf8623441
718 changed files with 127308 additions and 20959 deletions
+57 -18
View File
@@ -1,27 +1,66 @@
import {internationalCase} from './irpc-international-case.mjs';
import {prepareCreditCarry} from '../../../resources/js/lib/irpc-annual-settlement.ts';
import {newCarryLot} from '../../../resources/js/lib/irpc-credit-carry.ts';
import { internationalCase } from './irpc-international-case.mjs';
import { prepareCreditCarry } from '../../../resources/js/lib/irpc-annual-settlement.ts';
import { newCarryLot } from '../../../resources/js/lib/irpc-credit-carry.ts';
export function carryCase() {
const c = internationalCase();
c.b = prepareCreditCarry(c.b);
Object.assign(c.b.creditCarry, {
state: 'known', reference: 'SYNTHETIC QA complete prior balance inventory',
currentInternational: '8', currentPec: '200', assessmentKey: c.b.assessmentKey,
allocationReference: 'SYNTHETIC QA explicit allocation: current international8, prior international50, currentPEC200, priorPEC100',
state: 'known',
reference: 'SYNTHETIC QA complete prior balance inventory',
currentInternational: '8',
currentPec: '200',
assessmentKey: c.b.assessmentKey,
allocationReference:
'SYNTHETIC QA explicit allocation: current international8, prior international50, currentPEC200, priorPEC100',
lots: [
{...newCarryLot('international-2021'), kind: 'international', country: 'ZA', subjectNuit: c.b.subjectNuit,
year: '2021', ordinary: 'yes', originDocument: 'SYNTHETIC foreign-credit-assessment2021',
originReference: 'SYNTHETIC QA origin inclusion, eligible tax, national/CDT limits, insufficient collecta',
ruleReference: 'SYNTHETIC QA documented ordinary origin rule art65, no real foreign treaty claim',
eligible: '200', originDeducted: '100', insufficient: 'yes', usesState: 'known',
usesReference: 'SYNTHETIC QA all actual uses reconciled through current exercise',
uses: [{id: 'use-2023', year: '2023', amount: '30', document: 'SYNTHETIC use2023', reference: 'SYNTHETIC QA actual documented use, not simulated'}], selected: '50'},
{...newCarryLot('pec-2023'), kind: 'pec', subjectNuit: c.b.subjectNuit,
year: '2023', ordinary: 'yes', originDocument: 'SYNTHETIC PEC2023 assessment and receipts',
originReference: 'SYNTHETIC QA actual PEC paid, initial deduction and collecta insufficiency',
ruleReference: 'SYNTHETIC QA origin ordinary art66', eligible: '300', originDeducted: '150',
insufficient: 'yes', usesState: 'absent', usesReference: 'SYNTHETIC QA no actual subsequent use', selected: '100'},
{
...newCarryLot('international-2021'),
kind: 'international',
country: 'ZA',
subjectNuit: c.b.subjectNuit,
year: '2021',
ordinary: 'yes',
originDocument: 'SYNTHETIC foreign-credit-assessment2021',
originReference:
'SYNTHETIC QA origin inclusion, eligible tax, national/CDT limits, insufficient collecta',
ruleReference:
'SYNTHETIC QA documented ordinary origin rule art65, no real foreign treaty claim',
eligible: '200',
originDeducted: '100',
insufficient: 'yes',
usesState: 'known',
usesReference:
'SYNTHETIC QA all actual uses reconciled through current exercise',
uses: [
{
id: 'use-2023',
year: '2023',
amount: '30',
document: 'SYNTHETIC use2023',
reference:
'SYNTHETIC QA actual documented use, not simulated',
},
],
selected: '50',
},
{
...newCarryLot('pec-2023'),
kind: 'pec',
subjectNuit: c.b.subjectNuit,
year: '2023',
ordinary: 'yes',
originDocument: 'SYNTHETIC PEC2023 assessment and receipts',
originReference:
'SYNTHETIC QA actual PEC paid, initial deduction and collecta insufficiency',
ruleReference: 'SYNTHETIC QA origin ordinary art66',
eligible: '300',
originDeducted: '150',
insufficient: 'yes',
usesState: 'absent',
usesReference: 'SYNTHETIC QA no actual subsequent use',
selected: '100',
},
],
});
return c;
+58 -19
View File
@@ -1,25 +1,64 @@
import {internationalCase} from './irpc-international-case.mjs';
import {carryCase} from './irpc-carry-case.mjs';
import {prepareEconomicBook} from '../../../resources/js/lib/irpc-annual-settlement.ts';
import {newEconomicPosition} from '../../../resources/js/lib/irpc-economic-credit.ts';
import { internationalCase } from './irpc-international-case.mjs';
import { carryCase } from './irpc-carry-case.mjs';
import { prepareEconomicBook } from '../../../resources/js/lib/irpc-annual-settlement.ts';
import { newEconomicPosition } from '../../../resources/js/lib/irpc-economic-credit.ts';
export function economicCase(withCarry = false) {
const c = withCarry ? carryCase() : internationalCase();
c.b = prepareEconomicBook(c.b);
Object.assign(c.b.economicCredits, {state: 'known', reference: 'SYNTHETIC QA full ordinary economic-credit inventory', rows: [{
...newEconomicPosition('economic-1'), subjectNuit: c.b.subjectNuit, year: c.b.year, assessmentKey: c.b.assessmentKey,
kind: 'ordinary_profit', payerNuit: '111222333', recipientResident: 'yes', payerResident: 'yes', payerIrpc: 'yes', payerExempt: 'no',
article40: 'no', qualificationReference: 'SYNTHETIC QA entities seated/effectively managed in MZ; payer subject nonexempt IRPC',
article40Reference: 'SYNTHETIC QA explicit nonapplication of40(1), including2009 participation/period/recipient conditions',
distributionDocument: 'SYNTHETIC-DIVIDEND2026', distributionParcel: 'distribution-1', distributionDate: '2026-09-30',
income: '100', incomeIncluded: 'yes', incomeReference: 'SYNTHETIC QA100 gross of beneficiary withholding already included in current L6; no actual dividend assertion',
taxIssuer: 'SYNTHETIC domestic IRPC issuer', taxDocument: 'SYNTHETIC-SOURCE-IRPC2026', taxParcel: 'underlying-tax-1',
parcelReference: 'SYNTHETIC QA underlying domestic IRPC parcel, distinct from recipient withholding or foreign income tax',
proofAmount: '20', taxAmount: '20', attributionReference: 'SYNTHETIC QA documented IRPC20 corresponding to included profits100, not inferred by applying a rate to dividends',
previouslyAttributed: '0', priorAttributionReference: 'SYNTHETIC QA actual previous attribution to other profits known zero',
grossUpIncluded: '12', grossUpReference: 'SYNTHETIC QA53 nominal credit12 already included in reconciled current base4400; no base mutation',
nationalLimit: '32', nationalLimitReference: 'SYNTHETIC QA documented proportional current collecta ceiling32 after credit addition; not an automatic fraction derivation',
previousUse: {state: 'known', amount: '0', reference: 'SYNTHETIC QA actual prior economic-credit use known zero'},
}]});
Object.assign(c.b.economicCredits, {
state: 'known',
reference: 'SYNTHETIC QA full ordinary economic-credit inventory',
rows: [
{
...newEconomicPosition('economic-1'),
subjectNuit: c.b.subjectNuit,
year: c.b.year,
assessmentKey: c.b.assessmentKey,
kind: 'ordinary_profit',
payerNuit: '111222333',
recipientResident: 'yes',
payerResident: 'yes',
payerIrpc: 'yes',
payerExempt: 'no',
article40: 'no',
qualificationReference:
'SYNTHETIC QA entities seated/effectively managed in MZ; payer subject nonexempt IRPC',
article40Reference:
'SYNTHETIC QA explicit nonapplication of40(1), including2009 participation/period/recipient conditions',
distributionDocument: 'SYNTHETIC-DIVIDEND2026',
distributionParcel: 'distribution-1',
distributionDate: '2026-09-30',
income: '100',
incomeIncluded: 'yes',
incomeReference:
'SYNTHETIC QA100 gross of beneficiary withholding already included in current L6; no actual dividend assertion',
taxIssuer: 'SYNTHETIC domestic IRPC issuer',
taxDocument: 'SYNTHETIC-SOURCE-IRPC2026',
taxParcel: 'underlying-tax-1',
parcelReference:
'SYNTHETIC QA underlying domestic IRPC parcel, distinct from recipient withholding or foreign income tax',
proofAmount: '20',
taxAmount: '20',
attributionReference:
'SYNTHETIC QA documented IRPC20 corresponding to included profits100, not inferred by applying a rate to dividends',
previouslyAttributed: '0',
priorAttributionReference:
'SYNTHETIC QA actual previous attribution to other profits known zero',
grossUpIncluded: '12',
grossUpReference:
'SYNTHETIC QA53 nominal credit12 already included in reconciled current base4400; no base mutation',
nationalLimit: '32',
nationalLimitReference:
'SYNTHETIC QA documented proportional current collecta ceiling32 after credit addition; not an automatic fraction derivation',
previousUse: {
state: 'known',
amount: '0',
reference:
'SYNTHETIC QA actual prior economic-credit use known zero',
},
},
],
});
return c;
}
@@ -1,9 +1,61 @@
import {pecCase} from './irpc-pec-case.mjs';
import {prepareInternationalBook,newInternationalProof} from '../../../resources/js/lib/irpc-annual-settlement.ts';
import {newInternationalPosition} from '../../../resources/js/lib/irpc-international-credit.ts';
export function internationalCase(tax='10',national='8',pec='200',ppc='500',rf='0') {
const c=pecCase(pec,ppc,rf);c.b=prepareInternationalBook(c.b);
const p={...newInternationalPosition('country-za'),country:'ZA',qualificationCountry:'ZA',subjectNuit:c.b.subjectNuit,year:c.b.year,assessmentKey:c.b.assessmentKey,incomeAmount:'100',incomeIncluded:'yes',incomeReference:'SYNTHETIC QA: foreign income included in valid 2026 base',nationalLimit:national,nationalLimitReference:'SYNTHETIC QA: documented national fraction, no automatic derivation',treaty:'no',treatyReference:'SYNTHETIC QA assumption only; not an assertion about actual ZA convention applicability',previousUse:{state:'known',amount:'0',reference:'SYNTHETIC QA: actual previous credit use known zero'},payments:[{...newInternationalProof('foreign-tax'),document:'SYNTHETIC-FOREIGN-TAX-2026',issuer:'SYNTHETIC QA foreign authority',date:'2026-09-30',subjectNuit:c.b.subjectNuit,year:c.b.year,proofAmount:tax,amount:tax,effective:'yes',incomeTax:'yes',reference:'SYNTHETIC QA paid MZN tax amount, no real receipt',taxReference:'SYNTHETIC QA income tax nature and entitlement'}]};
Object.assign(c.b.internationalCredits,{state:'known',reference:'SYNTHETIC QA complete inventory for entity/year',positions:[p]});
import { pecCase } from './irpc-pec-case.mjs';
import {
prepareInternationalBook,
newInternationalProof,
} from '../../../resources/js/lib/irpc-annual-settlement.ts';
import { newInternationalPosition } from '../../../resources/js/lib/irpc-international-credit.ts';
export function internationalCase(
tax = '10',
national = '8',
pec = '200',
ppc = '500',
rf = '0',
) {
const c = pecCase(pec, ppc, rf);
c.b = prepareInternationalBook(c.b);
const p = {
...newInternationalPosition('country-za'),
country: 'ZA',
qualificationCountry: 'ZA',
subjectNuit: c.b.subjectNuit,
year: c.b.year,
assessmentKey: c.b.assessmentKey,
incomeAmount: '100',
incomeIncluded: 'yes',
incomeReference:
'SYNTHETIC QA: foreign income included in valid 2026 base',
nationalLimit: national,
nationalLimitReference:
'SYNTHETIC QA: documented national fraction, no automatic derivation',
treaty: 'no',
treatyReference:
'SYNTHETIC QA assumption only; not an assertion about actual ZA convention applicability',
previousUse: {
state: 'known',
amount: '0',
reference: 'SYNTHETIC QA: actual previous credit use known zero',
},
payments: [
{
...newInternationalProof('foreign-tax'),
document: 'SYNTHETIC-FOREIGN-TAX-2026',
issuer: 'SYNTHETIC QA foreign authority',
date: '2026-09-30',
subjectNuit: c.b.subjectNuit,
year: c.b.year,
proofAmount: tax,
amount: tax,
effective: 'yes',
incomeTax: 'yes',
reference: 'SYNTHETIC QA paid MZN tax amount, no real receipt',
taxReference: 'SYNTHETIC QA income tax nature and entitlement',
},
],
};
Object.assign(c.b.internationalCredits, {
state: 'known',
reference: 'SYNTHETIC QA complete inventory for entity/year',
positions: [p],
});
return c;
}
+142 -21
View File
@@ -1,25 +1,146 @@
import {irpcBook,newIrpcRow,saveIrpcBook,recordIrpc} from '../../../resources/js/lib/irpc-withholdings.ts';
import {
irpcBook,
newIrpcRow,
saveIrpcBook,
recordIrpc,
} from '../../../resources/js/lib/irpc-withholdings.ts';
import fs from 'node:fs';
import {newPecPayment} from '../../../resources/js/lib/irpc-pec.ts';
import {newAnnualBook,newAnnualPpc,reuseAnnualAssessment,reuseAnnualWithholding} from '../../../resources/js/lib/irpc-annual-settlement.ts';
export function pecCase(amount='200',ppc='500',rf='0') {
const d=JSON.parse(fs.readFileSync(new URL('../fixtures/irpc-assessment-preserved.json',import.meta.url),'utf8'));
if(rf!=='0'){
const l5=irpcBook(d);
l5.rows.push({...newIrpcRow('pec-rf'),direction:'received',origin:'effective',counterparty:'QA AT',documentRef:'QA rendimento próprio 2026',base:String(Number(rf)*5),currency:'MZN',kind:'royalty',recipientIrpc:'yes',payerIrpc:'yes',residence:'resident',mozambique:'yes',qualificationRef:'QA royalties próprios incluídos no resultado anual',specialRelief:'none',eventsComplete:'yes',events:[{kind:'payment',date:'2026-10-02',reference:'QA rendimento primeiro evento'}],settlement:'complete',settlementRef:'QA retenção sofrida reconciliada',allocations:[{paymentId:'pec-rf-proof',amount:rf}],ordinary:{nonDigital:'yes',capitalType:'',rentOwnPropertyManagement:'',specialFacts:'no',capitalSeatAndManagement:'',reference:'QA royalties não digitais de residente'}});
l5.payments.push({id:'pec-rf-proof',kind:'withholding_proof',reference:'QA-RF-PEC-2026',date:'2026-10-02',amount:rf,currency:'MZN'});
d.modelo_a_snapshot=saveIrpcBook(d,recordIrpc(d,l5,'2026-10-27T15:00:00+02:00'));
import { newPecPayment } from '../../../resources/js/lib/irpc-pec.ts';
import {
newAnnualBook,
newAnnualPpc,
reuseAnnualAssessment,
reuseAnnualWithholding,
} from '../../../resources/js/lib/irpc-annual-settlement.ts';
export function pecCase(amount = '200', ppc = '500', rf = '0') {
const d = JSON.parse(
fs.readFileSync(
new URL(
'../fixtures/irpc-assessment-preserved.json',
import.meta.url,
),
'utf8',
),
);
if (rf !== '0') {
const l5 = irpcBook(d);
l5.rows.push({
...newIrpcRow('pec-rf'),
direction: 'received',
origin: 'effective',
counterparty: 'QA AT',
documentRef: 'QA rendimento próprio 2026',
base: String(Number(rf) * 5),
currency: 'MZN',
kind: 'royalty',
recipientIrpc: 'yes',
payerIrpc: 'yes',
residence: 'resident',
mozambique: 'yes',
qualificationRef:
'QA royalties próprios incluídos no resultado anual',
specialRelief: 'none',
eventsComplete: 'yes',
events: [
{
kind: 'payment',
date: '2026-10-02',
reference: 'QA rendimento primeiro evento',
},
],
settlement: 'complete',
settlementRef: 'QA retenção sofrida reconciliada',
allocations: [{ paymentId: 'pec-rf-proof', amount: rf }],
ordinary: {
nonDigital: 'yes',
capitalType: '',
rentOwnPropertyManagement: '',
specialFacts: 'no',
capitalSeatAndManagement: '',
reference: 'QA royalties não digitais de residente',
},
});
l5.payments.push({
id: 'pec-rf-proof',
kind: 'withholding_proof',
reference: 'QA-RF-PEC-2026',
date: '2026-10-02',
amount: rf,
currency: 'MZN',
});
d.modelo_a_snapshot = saveIrpcBook(
d,
recordIrpc(d, l5, '2026-10-27T15:00:00+02:00'),
);
}
let b=reuseAnnualAssessment(d,newAnnualBook());
b.reference='QA PEC: inventário completo da entidade/exercício';b.assessmentReference='QA colecta válida já demonstrada';
b.withholdings={state:'absent',reference:'QA sem retenções próprias neste caso',rows:[]};
b.ppc={state:ppc==='0'?'absent':'known',reference:'QA inventário de PPC efectivo',rows:ppc==='0'?[]:[{...newAnnualPpc('ppc'),document:'QA-PPC-PEC-2026',issuer:'QA AT',date:'2026-06-30',subjectNuit:b.subjectNuit,year:b.year,proofAmount:ppc,amount:ppc,effective:'yes',reference:'QA prova efectiva de natureza PPC'}]};
b.pec={state:'absent',amount:'',reference:'QA resumo anterior preservado'};
b.credits={state:'known',amount:'0',reference:'QA créditos precedentes conhecidos zero'};
b.pecPayments={version:1,state:'known',reference:'QA inventário de pagamentos PEC 2026',rows:[{...newPecPayment('pec'),document:'QA-PEC-2026',issuer:'QA AT',date:'2026-08-31',subjectNuit:b.subjectNuit,year:b.year,proofAmount:amount,amount,effective:'yes',previouslyUsed:'0',priorUseReference:'QA reconciliação: zero utilizações fora destas parcelas',reference:'QA comprovativo pago de natureza PEC'}]};
if(rf!=='0'){
b.withholdings.state='known';b=reuseAnnualWithholding(d,b,'pec-rf','pec-rf-proof','rf-claim');
Object.assign(b.withholdings.rows[0],{incomeIncluded:'yes',reference:'QA titular e rendimento incluído no exercício'});
let b = reuseAnnualAssessment(d, newAnnualBook());
b.reference = 'QA PEC: inventário completo da entidade/exercício';
b.assessmentReference = 'QA colecta válida já demonstrada';
b.withholdings = {
state: 'absent',
reference: 'QA sem retenções próprias neste caso',
rows: [],
};
b.ppc = {
state: ppc === '0' ? 'absent' : 'known',
reference: 'QA inventário de PPC efectivo',
rows:
ppc === '0'
? []
: [
{
...newAnnualPpc('ppc'),
document: 'QA-PPC-PEC-2026',
issuer: 'QA AT',
date: '2026-06-30',
subjectNuit: b.subjectNuit,
year: b.year,
proofAmount: ppc,
amount: ppc,
effective: 'yes',
reference: 'QA prova efectiva de natureza PPC',
},
],
};
b.pec = {
state: 'absent',
amount: '',
reference: 'QA resumo anterior preservado',
};
b.credits = {
state: 'known',
amount: '0',
reference: 'QA créditos precedentes conhecidos zero',
};
b.pecPayments = {
version: 1,
state: 'known',
reference: 'QA inventário de pagamentos PEC 2026',
rows: [
{
...newPecPayment('pec'),
document: 'QA-PEC-2026',
issuer: 'QA AT',
date: '2026-08-31',
subjectNuit: b.subjectNuit,
year: b.year,
proofAmount: amount,
amount,
effective: 'yes',
previouslyUsed: '0',
priorUseReference:
'QA reconciliação: zero utilizações fora destas parcelas',
reference: 'QA comprovativo pago de natureza PEC',
},
],
};
if (rf !== '0') {
b.withholdings.state = 'known';
b = reuseAnnualWithholding(d, b, 'pec-rf', 'pec-rf-proof', 'rf-claim');
Object.assign(b.withholdings.rows[0], {
incomeIncluded: 'yes',
reference: 'QA titular e rendimento incluído no exercício',
});
}
return {d,b};
return { d, b };
}