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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user