feat: support public-payer treaty exemption and exact economic adjustments
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -50,7 +50,9 @@ export function SimulationIrpcEconomicInclusion({
|
||||
deste mapa; zero deve ser indicado expressamente. A prévia
|
||||
propõe apenas a diferença e conserva o resultado anterior.
|
||||
Depois de confirmar, calcule e guarde L6 pelo percurso
|
||||
existente; L8 exige nova conferência da colecta.
|
||||
existente; L8 exige nova conferência da colecta. Valores
|
||||
derivados mantêm as fracções exactas, sem arredondamento fiscal
|
||||
presumido.
|
||||
</p>
|
||||
<label className="block">
|
||||
Origem dos lucros
|
||||
|
||||
@@ -52,17 +52,17 @@ export function SimulationIrpcPtCdt({
|
||||
if (p.treatyMethod === 'ptMzInterest')
|
||||
facts.push([
|
||||
'governmentInterestExemption',
|
||||
'Juros abrangidos pela isenção governamental do art.11(3) (o cálculo ordinário exige Não)',
|
||||
'Juros abrangidos pela isenção governamental do art.11(3)',
|
||||
]);
|
||||
return (
|
||||
<fieldset className="space-y-2 rounded border p-3">
|
||||
<legend>Portugal — correspondência CDT</legend>
|
||||
<p>
|
||||
Confirme rendimento bruto em MZN, residência convencional,
|
||||
natureza e período coberto pelos documentos. A taxa de 10%
|
||||
limita o imposto estrangeiro elegível; não altera a parcela
|
||||
líquida nacional nem prova pagamento. O limite manual anterior
|
||||
fica conservado.
|
||||
natureza e período coberto pelos documentos. O limite
|
||||
convencional do caso qualificado restringe o imposto estrangeiro
|
||||
elegível; não altera a parcela líquida nacional nem prova
|
||||
pagamento. O limite manual anterior fica conservado.
|
||||
</p>
|
||||
{(
|
||||
[
|
||||
@@ -84,6 +84,63 @@ export function SimulationIrpcPtCdt({
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
{p.treatyMethod === 'ptMzInterest' &&
|
||||
p.treatyPreparation?.governmentInterestExemption === 'yes' && (
|
||||
<fieldset className="rounded border p-3">
|
||||
<legend>
|
||||
Isenção por devedor público português — art.11(3)a
|
||||
</legend>
|
||||
<p>
|
||||
Escolha a qualificação documentada do devedor.
|
||||
Beneficiários públicos e acordos entre governos do
|
||||
art.11(3)b exigem correspondência própria. A isenção
|
||||
na fonte não gera reembolso de imposto pago pelo
|
||||
portal.
|
||||
</p>
|
||||
<label className="block">
|
||||
Devedor dos juros
|
||||
<select
|
||||
aria-label={
|
||||
prefix + 'Devedor público português'
|
||||
}
|
||||
value={
|
||||
p.treatyPreparation.governmentPayer ?? ''
|
||||
}
|
||||
onChange={(e) =>
|
||||
change('governmentPayer', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Por documentar</option>
|
||||
<option value="state">Estado português</option>
|
||||
<option value="subdivision">
|
||||
Subdivisão política ou administrativa
|
||||
portuguesa
|
||||
</option>
|
||||
<option value="local">
|
||||
Autarquia portuguesa
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
Suporte da qualificação do devedor
|
||||
<input
|
||||
aria-label={
|
||||
prefix + 'Suporte do devedor público'
|
||||
}
|
||||
value={
|
||||
p.treatyPreparation
|
||||
.governmentPayerReference ?? ''
|
||||
}
|
||||
onChange={(e) =>
|
||||
change(
|
||||
'governmentPayerReference',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
)}
|
||||
{facts.map(([key, label]) => (
|
||||
<label key={key} className="block">
|
||||
{label}
|
||||
|
||||
@@ -27,6 +27,8 @@ export type InternationalTaxProof = AnnualPpc & {
|
||||
exerciseReference: string;
|
||||
};
|
||||
export type PtMzRoyaltyPreparation = {
|
||||
governmentPayer?: '' | 'state' | 'subdivision' | 'local';
|
||||
governmentPayerReference?: string;
|
||||
capitalDefinition?: '' | 'yes' | 'no';
|
||||
governmentInterestExemption?: '' | 'yes' | 'no';
|
||||
gross: string;
|
||||
@@ -244,6 +246,13 @@ export function validateInternational(c: InternationalCredits) {
|
||||
);
|
||||
},
|
||||
)) ||
|
||||
(p.treatyPreparation?.governmentPayer !== undefined &&
|
||||
!['', 'state', 'subdivision', 'local'].includes(
|
||||
p.treatyPreparation.governmentPayer,
|
||||
)) ||
|
||||
(p.treatyPreparation?.governmentPayerReference !== undefined &&
|
||||
typeof p.treatyPreparation.governmentPayerReference !==
|
||||
'string') ||
|
||||
!evidenceValid(p.previousUse) ||
|
||||
!Array.isArray(p.payments)
|
||||
)
|
||||
@@ -408,13 +417,25 @@ export function ptMzTreatyLimit(p: InternationalPosition) {
|
||||
throw Error(
|
||||
'Definição convencional de dividendos/juros por documentar.',
|
||||
);
|
||||
if (
|
||||
p.treatyMethod === 'ptMzInterest' &&
|
||||
q.governmentInterestExemption !== 'no'
|
||||
)
|
||||
throw Error(
|
||||
'Juros abrangidos ou por corresponder à isenção governamental11(3) exigem tratamento próprio; não presumir limite ordinário.',
|
||||
);
|
||||
let governmentExemption: {
|
||||
payer: 'state' | 'subdivision' | 'local';
|
||||
reference: string;
|
||||
} | null = null;
|
||||
if (p.treatyMethod === 'ptMzInterest') {
|
||||
if (q.governmentInterestExemption === 'yes') {
|
||||
if (!q.governmentPayer || !q.governmentPayerReference?.trim())
|
||||
throw Error(
|
||||
'Isenção11(3)a exige devedor documentado: Estado português, subdivisão política/administrativa ou autarquia; beneficiários/acordos11(3)b permanecem separados.',
|
||||
);
|
||||
governmentExemption = {
|
||||
payer: q.governmentPayer,
|
||||
reference: q.governmentPayerReference,
|
||||
};
|
||||
} else if (q.governmentInterestExemption !== 'no')
|
||||
throw Error(
|
||||
'Corresponda a aplicação ou não aplicação da isenção11(3); desconhecido não significa limite ordinário10%.',
|
||||
);
|
||||
}
|
||||
if (
|
||||
!validDate(q.from) ||
|
||||
!validDate(q.to) ||
|
||||
@@ -433,33 +454,44 @@ export function ptMzTreatyLimit(p: InternationalPosition) {
|
||||
'Rendimento bruto inferior à parcela líquida incluída; reconcilie custos/perdas e base.',
|
||||
);
|
||||
return {
|
||||
version:
|
||||
p.treatyMethod === 'ptMzRoyalty'
|
||||
? 'IRPC-PT-MZ-royalty-credit/1'
|
||||
: 'IRPC-PT-MZ-capital-credit/1',
|
||||
version: governmentExemption
|
||||
? 'IRPC-PT-MZ-government-interest/1'
|
||||
: p.treatyMethod === 'ptMzRoyalty'
|
||||
? 'IRPC-PT-MZ-royalty-credit/1'
|
||||
: 'IRPC-PT-MZ-capital-credit/1',
|
||||
...(p.treatyMethod !== 'ptMzRoyalty' ? { nature: p.treatyMethod } : {}),
|
||||
gross,
|
||||
rate: '10',
|
||||
limit: fraction(
|
||||
BigInt(gross.numerator),
|
||||
BigInt(gross.denominator) * 10n,
|
||||
),
|
||||
...(governmentExemption ? { governmentExemption } : {}),
|
||||
rate: governmentExemption ? '0' : '10',
|
||||
limit: governmentExemption
|
||||
? zero()
|
||||
: fraction(
|
||||
BigInt(gross.numerator),
|
||||
BigInt(gross.denominator) * 10n,
|
||||
),
|
||||
from: q.from,
|
||||
to: q.to,
|
||||
reference: q.reference,
|
||||
source:
|
||||
p.treatyMethod === 'ptMzRoyalty'
|
||||
? 'CDT PT–MZ, RAR36/1992 art12(2/4–6),PDF13–14 e23(3)a,PDF21; Protocolo RAR36/2009 arts1/7,PDF1–2; CIRPC65(2). Royalties ordinárias não digitais, sem EP/instalação fixa ligada nem excesso por relações especiais. Não confundir com retenção L5 paga por devedor moçambicano; sem isenção ou tax sparing presumidos.'
|
||||
: 'CDT PT–MZ, RAR36/1992 art23(3)a,PDF21; CIRPC65(2). ' +
|
||||
(p.treatyMethod === 'ptMzDividend'
|
||||
? 'Dividendos10(2–4),PDF10; taxa10% actualizada pelo Protocolo RAR36/2009 art6,PDF2; IRPC/art2 actualizado pelo art1.'
|
||||
: p.treatyMethod === 'ptMzInterest'
|
||||
? 'Juros11(2–7),PDF11–12, excluída a isenção11(3); IRPC/art2 actualizado pelo Protocolo RAR36/2009 art1.'
|
||||
: 'Royalties12(2/4–6),PDF13–14; definição actualizada pelo Protocolo RAR36/2009 art7,PDF2; IRPC/art2 actualizado pelo art1. Recorte ordinário não digital.') +
|
||||
(p.treatyMethod === 'ptMzDividend'
|
||||
? ' Sem EP/instalação fixa ligada.'
|
||||
: ' Sem EP/instalação fixa ligada ou excesso convencional por relações especiais.') +
|
||||
' Não confundir com retenção L5 de devedor moçambicano; sem isenção ou tax sparing presumidos.',
|
||||
reference: governmentExemption
|
||||
? q.reference +
|
||||
'; devedor ' +
|
||||
governmentExemption.payer +
|
||||
'; ' +
|
||||
governmentExemption.reference
|
||||
: q.reference,
|
||||
source: governmentExemption
|
||||
? 'CDT PT–MZ, RAR36/1992 art11(3)a,PDF11, e23(3)a,PDF21; CIRPC65(2). Devedor Estado português/subdivisão/autarquia documentado. Juros isentos no Estado da fonte; limite convencional zero, sem crédito ou reembolso do imposto indevidamente pago pelo portal. Art11(3)b e demais situações permanecem separados.'
|
||||
: p.treatyMethod === 'ptMzRoyalty'
|
||||
? 'CDT PT–MZ, RAR36/1992 art12(2/4–6),PDF13–14 e23(3)a,PDF21; Protocolo RAR36/2009 arts1/7,PDF1–2; CIRPC65(2). Royalties ordinárias não digitais, sem EP/instalação fixa ligada nem excesso por relações especiais. Não confundir com retenção L5 paga por devedor moçambicano; sem isenção ou tax sparing presumidos.'
|
||||
: 'CDT PT–MZ, RAR36/1992 art23(3)a,PDF21; CIRPC65(2). ' +
|
||||
(p.treatyMethod === 'ptMzDividend'
|
||||
? 'Dividendos10(2–4),PDF10; taxa10% actualizada pelo Protocolo RAR36/2009 art6,PDF2; IRPC/art2 actualizado pelo art1.'
|
||||
: p.treatyMethod === 'ptMzInterest'
|
||||
? 'Juros11(2–7),PDF11–12, excluída a isenção11(3); IRPC/art2 actualizado pelo Protocolo RAR36/2009 art1.'
|
||||
: 'Royalties12(2/4–6),PDF13–14; definição actualizada pelo Protocolo RAR36/2009 art7,PDF2; IRPC/art2 actualizado pelo art1. Recorte ordinário não digital.') +
|
||||
(p.treatyMethod === 'ptMzDividend'
|
||||
? ' Sem EP/instalação fixa ligada.'
|
||||
: ' Sem EP/instalação fixa ligada ou excesso convencional por relações especiais.') +
|
||||
' Não confundir com retenção L5 de devedor moçambicano; sem isenção ou tax sparing presumidos.',
|
||||
};
|
||||
}
|
||||
export function internationalPosition(
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
} from './irpc-international-credit.ts';
|
||||
import {
|
||||
addFractions,
|
||||
fractionPresentation,
|
||||
subtractFractions,
|
||||
fraction,
|
||||
type FiscalFraction,
|
||||
@@ -48,20 +49,10 @@ export function validateEconomicInclusions(input: EconomicInclusions) {
|
||||
});
|
||||
}
|
||||
export function economicInclusionMoney(value: FiscalFraction): string {
|
||||
const n = BigInt(value.numerator) * 100n,
|
||||
d = BigInt(value.denominator);
|
||||
if (n % d !== 0n)
|
||||
throw Error(
|
||||
'Correcção com fracção de cêntimo exige tratamento próprio; não arredondar por presunção.',
|
||||
);
|
||||
const cents = n / d,
|
||||
absolute = cents < 0n ? -cents : cents;
|
||||
return (
|
||||
(cents < 0n ? '-' : '') +
|
||||
absolute / 100n +
|
||||
'.' +
|
||||
(absolute % 100n).toString().padStart(2, '0')
|
||||
);
|
||||
const presentation = fractionPresentation(value);
|
||||
return presentation.approximate
|
||||
? value.numerator + '/' + value.denominator
|
||||
: presentation.decimal;
|
||||
}
|
||||
export function calculateEconomicInclusions(
|
||||
input: EconomicInclusions,
|
||||
@@ -148,7 +139,7 @@ export function calculateEconomicInclusions(
|
||||
const targets = [creditMoney(r.income), nominal];
|
||||
const included = [
|
||||
creditMoney(row.profitAlreadyIncluded),
|
||||
creditMoney(row.creditAlreadyIncluded),
|
||||
creditLimit(row.creditAlreadyIncluded),
|
||||
];
|
||||
if (
|
||||
r.incomeIncluded === 'yes' &&
|
||||
@@ -178,7 +169,7 @@ export function calculateEconomicInclusions(
|
||||
BigInt(effect.denominator),
|
||||
),
|
||||
effect,
|
||||
reason: `${economicInclusionVersion}; CIRPC64(1–2)/53(1)a; ${index ? 'acréscimo nominal' : 'lucros'}: alvo ${economicInclusionMoney(target)}; já considerado ${economicInclusionMoney(included[index])}; diferença ${economicInclusionMoney(effect)}. ${row.reference}${specialReference ? ' ' + specialReference : ''}`,
|
||||
reason: `${economicInclusionVersion}${[target, included[index], effect].some((v) => (BigInt(v.numerator) * 100n) % BigInt(v.denominator) !== 0n) ? '; IRPC-economic-inclusion-exact/1: fracções conservadas, sem arredondamento fiscal' : ''}; CIRPC64(1–2)/53(1)a; ${index ? 'acréscimo nominal' : 'lucros'}: alvo ${economicInclusionMoney(target)}; já considerado ${economicInclusionMoney(included[index])}; diferença ${economicInclusionMoney(effect)}. ${row.reference}${specialReference ? ' ' + specialReference : ''}`,
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -241,7 +232,11 @@ export function prepareEconomicInclusion(
|
||||
'Reconcilie as outras correcções aos proveitos antes de substituir parcelas.',
|
||||
);
|
||||
const current =
|
||||
topic.state === 'absent' ? fraction(0n) : creditMoney(topic.amount);
|
||||
topic.state === 'absent'
|
||||
? fraction(0n)
|
||||
: old.rows.length
|
||||
? creditLimit(topic.amount)
|
||||
: creditMoney(topic.amount);
|
||||
const remaining = subtractFractions(
|
||||
current,
|
||||
addFractions(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { creditLimit, creditCompare } from './irpc-international-credit.ts';
|
||||
import type { NormalDepreciationModel } from './irpc-normal-depreciation.ts';
|
||||
import type { NormalCostsModel } from './irpc-normal-costs.ts';
|
||||
import type { SchedulesModel } from './irpc-normal-schedules.ts';
|
||||
@@ -126,7 +127,13 @@ export type NormalProfitModel = {
|
||||
source: string;
|
||||
};
|
||||
const zero = () => fraction(0n, 1n);
|
||||
function money(s: string) {
|
||||
function money(s: string, exact = false) {
|
||||
if (exact) {
|
||||
const v = creditLimit(s.startsWith('-') ? s.slice(1) : s);
|
||||
return s.startsWith('-')
|
||||
? fraction(-BigInt(v.numerator), BigInt(v.denominator))
|
||||
: v;
|
||||
}
|
||||
if (!/^-?\d+(?:\.\d{1,2})?$/.test(s)) throw Error('Montante inválido');
|
||||
const v = decimalFraction(s.startsWith('-') ? s.slice(1) : s);
|
||||
return s.startsWith('-')
|
||||
@@ -288,8 +295,11 @@ export function closeNormalProfit(
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
value = money(t.amount);
|
||||
if (units(value) !== 0n)
|
||||
value = money(
|
||||
t.amount,
|
||||
key === 'incomeCorrections' && !!economic,
|
||||
);
|
||||
if (BigInt(value.numerator) !== 0n)
|
||||
reason =
|
||||
'Montante conhecido,mas tratamento específico ainda por corresponder;conservado sem aplicação presumida.';
|
||||
else
|
||||
@@ -304,23 +314,24 @@ export function closeNormalProfit(
|
||||
...(costs?.effects ?? []),
|
||||
...(economic?.effects ?? []),
|
||||
].filter((e) => e.topic === key);
|
||||
const mappedAmount = addFractions(
|
||||
mapped.flatMap((e) => (e.amount ? [e.amount] : [])),
|
||||
);
|
||||
const covered =
|
||||
(schedules || costs || economic) &&
|
||||
mapped.length > 0 &&
|
||||
mapped.every((e) => e.effect !== null) &&
|
||||
value !== null &&
|
||||
t.state === 'known' &&
|
||||
units(
|
||||
addFractions(
|
||||
mapped.flatMap((e) => (e.amount ? [e.amount] : [])),
|
||||
),
|
||||
) === units(value);
|
||||
(economic && key === 'incomeCorrections'
|
||||
? creditCompare(mappedAmount, value) === 0n
|
||||
: units(mappedAmount) === units(value));
|
||||
if (covered)
|
||||
reason =
|
||||
'Montante reconciliado com as regras do mapa complementar; efeito fiscal discriminado por linha.';
|
||||
if (
|
||||
value === null ||
|
||||
(units(value) !== 0n && !covered) ||
|
||||
(BigInt(value.numerator) !== 0n && !covered) ||
|
||||
(t.state === 'absent' && !!t.amount.trim()) ||
|
||||
(mapped.length > 0 && !covered)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user