feat: reconcile L6 economic income and extend L8 credits
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-10 13:23:11 +02:00
parent c359364de3
commit ac67f9c13a
27 changed files with 1828 additions and 30 deletions
+41
View File
@@ -1,4 +1,9 @@
import { inputText } from './input-text.ts';
import {
calculateEconomicInclusions,
validateEconomicInclusions,
type EconomicInclusions,
} from './irpc-normal-economic.ts';
import { irpcSpecialCombinationsVersion } from './irpc-special-combinations.ts';
import {
irpcSpecialVersion,
@@ -104,6 +109,7 @@ export type NormalAdjustment = {
reference: string;
};
export type NormalBook = {
economicInclusions?: EconomicInclusions;
version: 1;
year: string;
mappingReference: string;
@@ -123,6 +129,7 @@ export type NormalBook = {
history?: NormalRecord[];
};
export type NormalModel = {
economicInclusions?: ReturnType<typeof calculateEconomicInclusions>;
special?: SpecialModel;
formPreparation?: NormalFormPreparationModel;
periodsFx?: NormalPeriodFxModel;
@@ -213,6 +220,8 @@ function store(d: Record<string, unknown>) {
return s;
}
export function validateNormal(b: NormalBook) {
if (b?.economicInclusions !== undefined)
validateEconomicInclusions(b.economicInclusions);
if (b?.special !== undefined) validateSpecial(b.special);
if (b?.forms !== undefined) validateNormalFormPreparation(b.forms);
if (b?.periodsFx !== undefined) validateNormalPeriodFx(b.periodsFx);
@@ -333,6 +342,7 @@ function key(d: Record<string, unknown>, b: NormalBook) {
b.scopeReference,
b.rows,
...(b.profit ? [b.profit] : []),
...(b.economicInclusions ? [b.economicInclusions] : []),
...(b.base ? [b.base] : []),
...(b.assessment ? [b.assessment] : []),
...(b.schedules ? [b.schedules] : []),
@@ -569,6 +579,23 @@ export function calculateNormal(
!!periodsFx?.short,
)
: undefined;
const economicInclusions = b.economicInclusions
? calculateEconomicInclusions(
b.economicInclusions,
b.base?.subjectNuit ?? '',
b.year,
)
: undefined;
if (
economicInclusions &&
(b.special ||
b.periodsFx ||
(b.schedules && b.schedules.period.kind !== 'calendar') ||
b.scope !== 'resident_general')
)
economicInclusions.pending.push(
'Inclusão económica automática delimitada à base ordinária residente/ano civil2026/MZN; este âmbito exige correspondência própria.',
);
const profit = b.profit
? closeNormalProfit(
b.profit,
@@ -580,6 +607,7 @@ export function calculateNormal(
schedules,
costs,
depreciation,
economicInclusions,
)
: undefined;
if (profit && periodsFx)
@@ -677,6 +705,7 @@ export function calculateNormal(
? addFractions([accountingProfit, additions])
: null,
taxableProfit: profit?.taxableProfit ?? null,
...(economicInclusions ? { economicInclusions } : {}),
taxableBase: base?.taxableBase ?? null,
tax: null,
rows,
@@ -774,6 +803,18 @@ export function normalReportRows(
if (!r) return [];
const m = r.model;
return [
...(m.economicInclusions?.effects.map(
(e) =>
[
'IRPC normal — L6',
'Inclusão/correcção económica — ' + e.id,
'Parcela reconciliada: ' +
money(e.amount) +
'; efeito com sinal: ' +
money(e.effect),
e.reason,
] as [string, string, string, string],
) ?? []),
[
'IRPC normal — L6',
'Ajustamentos ao resultado financeiro',