Preserve documented turnover corrections in PEC viability estimates
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
newPecCorrection,
|
||||
type PecCorrection,
|
||||
} from '@/lib/irpc-pec-correction';
|
||||
export function SimulationIrpcPecCorrection({
|
||||
value,
|
||||
original,
|
||||
subjectNuit,
|
||||
onChange,
|
||||
}: {
|
||||
value?: PecCorrection;
|
||||
original: string;
|
||||
subjectNuit: string;
|
||||
onChange: (c: PecCorrection) => void;
|
||||
}) {
|
||||
if (!value)
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
onChange(newPecCorrection(original, subjectNuit))
|
||||
}
|
||||
>
|
||||
Rectificar volume na simulação PEC
|
||||
</button>
|
||||
);
|
||||
const patch = (c: Partial<PecCorrection>) => onChange({ ...value, ...c }),
|
||||
field = (
|
||||
key: Exclude<keyof PecCorrection, 'version' | 'apply'>,
|
||||
label: string,
|
||||
) => (
|
||||
<label className="block">
|
||||
{label}
|
||||
<input
|
||||
aria-label={label}
|
||||
value={value[key]}
|
||||
onChange={(e) => patch({ [key]: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
<section
|
||||
aria-label="Rectificação da estimativa PEC"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<h6>Volume de negócios corrigido</h6>
|
||||
<p>
|
||||
O volume original permanece {original || 'por indicar'} MZN. A
|
||||
nova fonte fundamenta a correcção da simulação2026; não submete
|
||||
declaração fiscal.
|
||||
</p>
|
||||
<label className="block">
|
||||
Aplicar rectificação PEC
|
||||
<select
|
||||
aria-label="Aplicar rectificação PEC"
|
||||
value={value.apply}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
apply: e.target.value as PecCorrection['apply'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por decidir</option>
|
||||
<option value="yes">
|
||||
Usar volume corrigido na estimativa
|
||||
</option>
|
||||
<option value="no">Conservar volume original</option>
|
||||
</select>
|
||||
</label>
|
||||
<details open={value.apply !== 'no'}>
|
||||
<summary>Alterar rectificação PEC</summary>
|
||||
{field('originalTurnover', 'Volume original analisado — PEC')}
|
||||
{field('revisedTurnover', 'Volume corrigido — PEC')}
|
||||
{field('subjectNuit', 'NUIT da rectificação PEC')}
|
||||
{field('turnoverYear', 'Ano do volume corrigido — PEC')}
|
||||
{field('reference', 'Fonte e fundamento da rectificação PEC')}
|
||||
</details>
|
||||
<p>
|
||||
Trocar a opção conserva os dois valores. Uma alteração da base
|
||||
original exige nova conferência; recalcule o fecho e a hipótese
|
||||
de tesouraria para reflectir a estimativa corrigida.
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import {SimulationIrpcPecCorrection} from './simulation-irpc-pec-correction';
|
||||
import {SimulationIrpcPecPlan} from './simulation-irpc-pec-plan';
|
||||
import {
|
||||
newPecObligation,
|
||||
calculatePecObligation,
|
||||
pecObligationSource,
|
||||
type PecObligation,
|
||||
} from '@/lib/irpc-pec-obligation';
|
||||
import { fractionPresentation } from '@/lib/fiscal-rational';
|
||||
@@ -42,7 +42,7 @@ export function SimulationIrpcPecObligation({
|
||||
patch = (changes: Partial<PecObligation>) =>
|
||||
onChange({ ...p, ...changes });
|
||||
const field = (
|
||||
key: Exclude<keyof PecObligation, 'version' | 'scope' | 'plan'>,
|
||||
key: Exclude<keyof PecObligation, 'version' | 'scope' | 'plan' | 'correction'>,
|
||||
label: string,
|
||||
) => (
|
||||
<label className="block">
|
||||
@@ -104,6 +104,7 @@ export function SimulationIrpcPecObligation({
|
||||
'turnoverReference',
|
||||
'Fonte do volume de negócios — PEC',
|
||||
)}
|
||||
<SimulationIrpcPecCorrection value={p.correction} original={p.previousTurnover} subjectNuit={p.subjectNuit} onChange={correction=>patch({correction})}/>
|
||||
{field(
|
||||
'previousPpcPaid',
|
||||
'PPC efectivamente pagos no ano anterior — MZN',
|
||||
@@ -143,7 +144,7 @@ export function SimulationIrpcPecObligation({
|
||||
</p>
|
||||
<details>
|
||||
<summary>Fonte e limites PEC</summary>
|
||||
<p>{pecObligationSource}</p>
|
||||
<p>{m.source}</p>
|
||||
</details>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {pecCorrectionVersion} from './irpc-pec-correction.ts';
|
||||
import {pecPlanVersion} from './irpc-pec-plan.ts';
|
||||
import {validatePecObligation,pecObligationReport,pecObligationVersion,type PecObligation} from './irpc-pec-obligation.ts';
|
||||
import { validatePpcObligation, ppcObligationReport, ppcObligationVersion, type PpcObligation } from './irpc-ppc-obligation.ts';
|
||||
@@ -575,6 +576,7 @@ function key(d: Record<string, unknown>, b: AnnualBook) {
|
||||
...(b.ppcObligation ? [ppcObligationVersion] : []),
|
||||
...(b.pecObligation ? [pecObligationVersion] : []),
|
||||
...(b.pecObligation?.plan ? [pecPlanVersion] : []),
|
||||
...(b.pecObligation?.correction ? [pecCorrectionVersion] : []),
|
||||
...(b.investmentCredit && b.creditCarry?.lots.length
|
||||
? ['CBF15-credit-carry-combination/1']
|
||||
: []),
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
export const pecCorrectionVersion = 'IRPC-PEC-turnover-correction/1';
|
||||
export const pecCorrectionSource =
|
||||
'RIRPC,Decreto9/2008,art29(3),BR16/I16-04-2008:volume de negócios determinado pelas vendas/serviços até ao final do exercício anterior,podendo ser rectificado no ano seguinte se distinto do usado no cálculo. Recorte:correcção documental do volume2025 na simulação2026;original,fundamento e diferença conservados. Não é declaração fiscal rectificativa submetida.';
|
||||
export type PecCorrection = {
|
||||
version: 1;
|
||||
apply: '' | 'yes' | 'no';
|
||||
originalTurnover: string;
|
||||
revisedTurnover: string;
|
||||
subjectNuit: string;
|
||||
turnoverYear: string;
|
||||
reference: string;
|
||||
};
|
||||
export const newPecCorrection = (
|
||||
originalTurnover: string,
|
||||
subjectNuit: string,
|
||||
): PecCorrection => ({
|
||||
version: 1,
|
||||
apply: '',
|
||||
originalTurnover,
|
||||
revisedTurnover: '',
|
||||
subjectNuit,
|
||||
turnoverYear: '2025',
|
||||
reference: '',
|
||||
});
|
||||
export function validatePecCorrection(c: PecCorrection) {
|
||||
if (
|
||||
!c ||
|
||||
c.version !== 1 ||
|
||||
!['', 'yes', 'no'].includes(c.apply) ||
|
||||
[
|
||||
'originalTurnover',
|
||||
'revisedTurnover',
|
||||
'subjectNuit',
|
||||
'turnoverYear',
|
||||
'reference',
|
||||
].some(
|
||||
(k) =>
|
||||
typeof (c as unknown as Record<string, unknown>)[k] !==
|
||||
'string',
|
||||
)
|
||||
)
|
||||
throw Error('Rectificação PEC não recuperável;original preservado.');
|
||||
}
|
||||
export function correctedPecTurnover(
|
||||
c: PecCorrection | undefined,
|
||||
original: string,
|
||||
subjectNuit: string,
|
||||
previousYear: string,
|
||||
) {
|
||||
if (!c) return { value: original, pending: [] as string[], applied: false };
|
||||
validatePecCorrection(c);
|
||||
if (c.apply === 'no')
|
||||
return { value: original, pending: [] as string[], applied: false };
|
||||
const pending: string[] = [];
|
||||
if (c.apply !== 'yes')
|
||||
pending.push(
|
||||
'PEC:escolha aplicar a rectificação ou conservar o volume original.',
|
||||
);
|
||||
if (
|
||||
c.originalTurnover !== original ||
|
||||
c.subjectNuit !== subjectNuit ||
|
||||
c.turnoverYear !== previousYear ||
|
||||
previousYear !== '2025'
|
||||
)
|
||||
pending.push(
|
||||
'PEC:origem,titular ou exercício da rectificação divergem da base;reconfira sem sobrescrever os valores.',
|
||||
);
|
||||
if (
|
||||
!/^\d{1,18}(\.\d{1,2})?$/.test(c.revisedTurnover) ||
|
||||
!c.reference.trim()
|
||||
)
|
||||
pending.push(
|
||||
'PEC:rectificação exige volume corrigido2025 em MZN e fonte/fundamento;valor desconhecido não equivale a zero.',
|
||||
);
|
||||
return {
|
||||
value: pending.length ? '' : c.revisedTurnover,
|
||||
pending,
|
||||
applied: pending.length === 0,
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import {validatePecCorrection,correctedPecTurnover,pecCorrectionSource,type PecCorrection} from './irpc-pec-correction.ts';
|
||||
import {validatePecPlan,pecPlanReport,type PecPlan} from './irpc-pec-plan.ts';
|
||||
import {
|
||||
decimalFraction,
|
||||
@@ -12,6 +13,7 @@ export const pecObligationSource =
|
||||
export type PecObligation = {
|
||||
version: 1;
|
||||
plan?: PecPlan;
|
||||
correction?: PecCorrection;
|
||||
scope: '' | 'ordinary_resident' | 'other';
|
||||
subjectNuit: string;
|
||||
year: string;
|
||||
@@ -40,6 +42,7 @@ export const newPecObligation = (
|
||||
ppcReference: '',
|
||||
});
|
||||
export function validatePecObligation(p: PecObligation) {
|
||||
if(p?.correction!==undefined)validatePecCorrection(p.correction);
|
||||
if(p?.plan!==undefined)validatePecPlan(p.plan);
|
||||
if (
|
||||
!p ||
|
||||
@@ -65,6 +68,7 @@ export function calculatePecObligation(
|
||||
) {
|
||||
validatePecObligation(p);
|
||||
const pending: string[] = [];
|
||||
const turnover=correctedPecTurnover(p.correction,p.previousTurnover,p.subjectNuit,p.previousYear);
|
||||
let percentage: FiscalFraction | null = null,
|
||||
limited: FiscalFraction | null = null,
|
||||
total: FiscalFraction | null = null,
|
||||
@@ -93,6 +97,7 @@ export function calculatePecObligation(
|
||||
notApplicable = true;
|
||||
total = fraction(0n);
|
||||
} else if (!pending.length) {
|
||||
pending.push(...turnover.pending);
|
||||
if (
|
||||
p.previousYear !== '2025' ||
|
||||
!p.turnoverReference.trim() ||
|
||||
@@ -102,7 +107,7 @@ export function calculatePecObligation(
|
||||
'PEC: falta exercício anterior2025 e fontes do volume de negócios e PPC efectivamente pagos,mesmo quando zero.',
|
||||
);
|
||||
if (
|
||||
![p.previousTurnover, p.previousPpcPaid].every((v) =>
|
||||
![turnover.value, p.previousPpcPaid].every((v) =>
|
||||
/^\d{1,18}(\.\d{1,2})?$/.test(v),
|
||||
)
|
||||
)
|
||||
@@ -110,7 +115,7 @@ export function calculatePecObligation(
|
||||
'PEC: valores anteriores desconhecidos/inválidos;zero deve ser explícito.',
|
||||
);
|
||||
if (!pending.length) {
|
||||
const v = decimalFraction(p.previousTurnover),
|
||||
const v = decimalFraction(turnover.value),
|
||||
ppc = decimalFraction(p.previousPpcPaid);
|
||||
if (BigInt(v.numerator) === 0n)
|
||||
pending.push(
|
||||
@@ -140,12 +145,13 @@ export function calculatePecObligation(
|
||||
}
|
||||
return {
|
||||
version: pecObligationVersion,
|
||||
source: pecObligationSource,
|
||||
source: p.correction ? pecObligationSource.replace('rectificação29(3),','')+' '+pecCorrectionSource : pecObligationSource,
|
||||
pending,
|
||||
percentage,
|
||||
limited,
|
||||
total,
|
||||
notApplicable,
|
||||
turnoverCorrection: p.correction ? {original:p.correction.originalTurnover,revised:p.correction.revisedTurnover,applied:!notApplicable&&turnover.applied,pending:turnover.pending,reference:p.correction.reference,source:pecCorrectionSource}:null,
|
||||
months:
|
||||
total && !notApplicable ? ['2026-06', '2026-08', '2026-10'] : [],
|
||||
instalmentAmountsDetermined: false,
|
||||
@@ -162,7 +168,10 @@ export function pecObligationReport(
|
||||
const m = calculatePecObligation(p, subjectNuit, year, assessment),
|
||||
show = (v: FiscalFraction | null) =>
|
||||
v ? fractionPresentation(v).decimal + ' MZN' : 'Indeterminado';
|
||||
const originalEstimate=p.correction ? calculatePecObligation({...p,correction:undefined},subjectNuit,year,assessment).total:null;
|
||||
const correctionEffect=originalEstimate&&m.total ? fractionPresentation(subtractFractions(m.total,originalEstimate)).decimal+' MZN':'por determinar';
|
||||
return [
|
||||
...(p.correction ? [['IRPC — L8','PEC — rectificação do volume','Original: '+p.correction.originalTurnover+' MZN;corrigido: '+p.correction.revisedTurnover+' MZN;'+(m.turnoverCorrection?.applied?'aplicada à estimativa.':'conservada sem aplicação à estimativa.')+' Estimativa original: '+show(originalEstimate)+';efeito na estimativa: '+correctionEffect+'. '+turnoverCorrectionNotice(m.turnoverCorrection),p.correction.reference+'; '+pecCorrectionSource] as [string,string,string,string]]:[]),
|
||||
...(p.plan ? pecPlanReport(p.plan,m.total,m.notApplicable,year) : []),
|
||||
[
|
||||
'IRPC — L8',
|
||||
@@ -190,3 +199,5 @@ export function pecObligationReport(
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
function turnoverCorrectionNotice(c:{pending:string[]}|null){return c?.pending.join(' ')??'';}
|
||||
|
||||
Reference in New Issue
Block a user