feat: qualify treaty interest under governmental financing agreements
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-10 14:18:47 +02:00
parent b10b35f308
commit 7c8d4726e9
10 changed files with 464 additions and 64 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ $identity = $pdo->query('select current_database() as name,inet_server_port() as
if ($identity['name'] !== 'proactive_investment_20261027_test' || (int) $identity['port'] !== 55441) {
throw new RuntimeException('Isolated QA identity required.');
}
$case = ['quota' => 'IrpcEconomicQuotaDraftTest', 'inclusion' => 'IrpcEconomicInclusionDraftTest', 'liquidation' => 'IrpcEconomicLiquidationDraftTest', 'association' => 'IrpcEconomicAssociationDraftTest', 'special-inclusion' => 'IrpcEconomicSpecialInclusionDraftTest', 'pt-royalty' => 'IrpcPtMzCreditDraftTest', 'pt-capital' => 'IrpcPtMzCapitalDraftTest', 'pt-government' => 'IrpcPtMzGovernmentDraftTest', 'economic-fraction' => 'IrpcEconomicFractionDraftTest'][$argv[2] ?? ''] ?? throw new RuntimeException('Choose an explicit supported QA case.');
$case = ['quota' => 'IrpcEconomicQuotaDraftTest', 'inclusion' => 'IrpcEconomicInclusionDraftTest', 'liquidation' => 'IrpcEconomicLiquidationDraftTest', 'association' => 'IrpcEconomicAssociationDraftTest', 'special-inclusion' => 'IrpcEconomicSpecialInclusionDraftTest', 'pt-royalty' => 'IrpcPtMzCreditDraftTest', 'pt-capital' => 'IrpcPtMzCapitalDraftTest', 'pt-government' => 'IrpcPtMzGovernmentDraftTest', 'economic-fraction' => 'IrpcEconomicFractionDraftTest', 'pt-agreement' => 'IrpcPtMzAgreementDraftTest'][$argv[2] ?? ''] ?? throw new RuntimeException('Choose an explicit supported QA case.');
$argv = ['phpunit', '-c', 'phpunit.investmoz.xml', '--do-not-cache-result', 'tests/Feature/'.$case.'.php'];
$argc = count($argv);
$_SERVER['argv'] = $argv;
+6 -4
View File
@@ -3,17 +3,18 @@ import fs from 'node:fs';
import { internationalCase } from '../tests/frontend/helpers/irpc-international-case.mjs';
import { recordAnnual, saveAnnualBook, annualBook, calculateAnnual, annualHtml } from '../resources/js/lib/irpc-annual-settlement.ts';
import assert from 'node:assert/strict';
const government = process.argv.includes('government');
const agreement = process.argv.includes('agreement');
const government = agreement || process.argv.includes('government');
const capital = government ? 'interest' : ['dividend','interest'].find(k=>process.argv.includes(k));
const out = new URL(government ? '../outputs/irpc-pt-mz-government-20261110/' : capital ? '../outputs/irpc-pt-mz-'+capital+'-20261110/' : '../outputs/irpc-pt-mz-credit-20261110/', import.meta.url);
const out = new URL(agreement ? '../outputs/irpc-pt-mz-agreement-20261110/' : government ? '../outputs/irpc-pt-mz-government-20261110/' : capital ? '../outputs/irpc-pt-mz-'+capital+'-20261110/' : '../outputs/irpc-pt-mz-credit-20261110/', import.meta.url);
fs.mkdirSync(out, { recursive: true });
if (process.argv[2] === 'recovered') {
const d = JSON.parse(fs.readFileSync(new URL('recovered.json', out), 'utf8'));
const b = annualBook(d), m = b.result.model;
assert.deepEqual(calculateAnnual(d, b).internationalCredit, m.internationalCredit);
const html = annualHtml(d);assert.match(html, /IRPC-PT-MZ-(royalty-credit|capital-credit|government-interest)\/1/);
const html = annualHtml(d);assert.match(html, /IRPC-PT-MZ-(royalty-credit|capital-credit|government-interest|agreement-interest)\/1/);
const report=createProjectDossierReport(d,{selectedSections:new Set(['finance']),generatedAt:'2026-11-10T17:10:00+02:00'});
assert.match(JSON.stringify(report),/IRPC-PT-MZ-(royalty-credit|capital-credit|government-interest)\/1/);
assert.match(JSON.stringify(report),/IRPC-PT-MZ-(royalty-credit|capital-credit|government-interest|agreement-interest)\/1/);
fs.writeFileSync(new URL('report.html', out), html);
fs.writeFileSync(new URL('verification.json', out), JSON.stringify({ synthetic: true, apiRecovered: true, dossierReport: true, currentRecalculation: true, html: true, quota: m.internationalCredit.positions[0].treatyLimit, balance: m.arithmeticBalance, activeChanged: false }, null, 2));
} else {
@@ -21,6 +22,7 @@ if (process.argv[2] === 'recovered') {
Object.assign(c.b.internationalCredits.positions[0],{country:'PT',qualificationCountry:'PT',incomeAmount:'40',treaty:'yes',treatyMethod:'ptMzRoyalty',treatyReference:'SYNTHETIC QA qualified PT-MZ12/23(3)a ordinary royalties',treatyPreparation:{gross:'60',from:'2026-01-01',to:'2026-12-31',reference:'SYNTHETIC QA residence certificate and royalty agreement covering conditions',residentMz:'yes',beneficialOwner:'yes',sourcePortugal:'yes',payerResidentPt:'yes',noLinkedEstablishment:'yes',armLength:'yes',royaltyDefinition:'yes',nonDigital:'yes'}});
if(capital) {const p=c.b.internationalCredits.positions[0];p.treatyMethod=capital==='dividend'?'ptMzDividend':'ptMzInterest';p.treatyReference='SYNTHETIC QA explicit PT-MZ article'+(capital==='dividend'?'10 updated2009':'11 ordinary non-governmental')+'/23(3)a qualification';p.treatyPreparation.reference='SYNTHETIC QA residence certificate and '+capital+' contract, source and conditions documented';Object.assign(p.treatyPreparation,{capitalDefinition:'yes',governmentInterestExemption:'no'});}
if(government){const p=c.b.internationalCredits.positions[0];p.treatyReference='SYNTHETIC QA PT-MZ11(3)a and23(3)a';Object.assign(p.treatyPreparation,{governmentInterestExemption:'yes',governmentPayer:'state',governmentPayerReference:'SYNTHETIC Portuguese state is actual payer of documented interest'});}
if(agreement){const p=c.b.internationalCredits.positions[0];p.treatyReference='SYNTHETIC QA explicit PT-MZ11(3)b/23(3)a';Object.assign(p.treatyPreparation,{governmentBasis:'agreement',governmentPayer:'',governmentPayerReference:'',institutionRecipient:'yes',financingGranted:'yes',bilateralAgreement:'yes',institutionReference:'SYNTHETIC current subject123456789 qualifying institution',financingReference:'SYNTHETIC financing granted by this institution, linked to interest',agreementReference:'SYNTHETIC PT-MZ governmental agreement and financing clause'});}
const b = recordAnnual(c.d, c.b, '2026-11-10T14:00:00+02:00');
fs.writeFileSync(new URL('fixture.json', out), JSON.stringify({ ...c.d, modelo_a_snapshot: saveAnnualBook(c.d, b) }));
}