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'), ); } 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 }; }