Preparar obriga??o PPC ordin?ria com recupera??o e relat?rio no dossier
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { SimulationIrpcPpcObligation } from './simulation-irpc-ppc-obligation';
|
||||
import { SimulationIrpcInvestment } from './simulation-irpc-investment';
|
||||
import { SimulationIrpcEconomic } from './simulation-irpc-economic';
|
||||
import { FiscalProofParcelFields } from './fiscal-proof-parcel';
|
||||
@@ -340,6 +341,7 @@ export function SimulationIrpcAnnual({ draft, onChange }: Props) {
|
||||
</fieldset>
|
||||
<fieldset className="space-y-2 rounded border p-3">
|
||||
<legend>PPC efectivamente pagos</legend>
|
||||
<SimulationIrpcPpcObligation book={b} onChange={ppcObligation=>patch({ppcObligation})}/>
|
||||
{group('ppc', 'PPC efectuados')}
|
||||
<p>
|
||||
Regista comprovativos de pagamentos por conta; não
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
import {
|
||||
newPpcObligation,
|
||||
calculatePpcObligation,
|
||||
ppcObligationSource,
|
||||
type PpcObligation,
|
||||
} from '@/lib/irpc-ppc-obligation';
|
||||
import { fractionPresentation } from '@/lib/fiscal-rational';
|
||||
import type { AnnualBook } from '@/lib/irpc-annual-settlement';
|
||||
export function SimulationIrpcPpcObligation({
|
||||
book,
|
||||
onChange,
|
||||
}: {
|
||||
book: AnnualBook;
|
||||
onChange: (value: PpcObligation) => void;
|
||||
}) {
|
||||
const p = book.ppcObligation;
|
||||
if (!p)
|
||||
return (
|
||||
<section className="rounded border p-3">
|
||||
<h5>Obrigação PPC</h5>
|
||||
<p>
|
||||
Preparar a obrigação e os meses previstos não regista
|
||||
pagamentos nem cria deduções na liquidação.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
onChange(newPpcObligation(book.subjectNuit, book.year))
|
||||
}
|
||||
>
|
||||
Preparar obrigação PPC
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
const m = calculatePpcObligation(
|
||||
p,
|
||||
book.subjectNuit,
|
||||
book.year,
|
||||
book.assessment,
|
||||
);
|
||||
const patch = (changes: Partial<PpcObligation>) =>
|
||||
onChange({ ...p, ...changes });
|
||||
const field = (
|
||||
key:
|
||||
| 'subjectNuit'
|
||||
| 'year'
|
||||
| 'previousYear'
|
||||
| 'previousTax'
|
||||
| 'previousWithholdings'
|
||||
| 'assessmentReference'
|
||||
| 'withholdingReference',
|
||||
label: string,
|
||||
) => (
|
||||
<label className="block">
|
||||
{label}
|
||||
<input
|
||||
aria-label={label}
|
||||
value={p[key]}
|
||||
onChange={(e) => patch({ [key]: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
<section
|
||||
aria-label="Preparação da obrigação PPC"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<h5>Obrigação PPC — exercício anterior</h5>
|
||||
<p>
|
||||
Reutiliza o titular e exercício ao iniciar. Complete a
|
||||
liquidação anterior e as retenções documentadas; campos vazios
|
||||
não equivalem a zero.
|
||||
</p>
|
||||
<label className="block">
|
||||
Enquadramento PPC
|
||||
<select
|
||||
aria-label="Enquadramento PPC"
|
||||
value={p.scope}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
scope: e.target.value as PpcObligation['scope'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por confirmar</option>
|
||||
<option value="ordinary_resident">
|
||||
Residente geral — actividade comercial, industrial ou
|
||||
agrícola, ano civil
|
||||
</option>
|
||||
<option value="other">
|
||||
Outro enquadramento — cálculo separado
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{p.scope === 'ordinary_resident' && (
|
||||
<>
|
||||
{field('subjectNuit', 'NUIT — obrigação PPC')}
|
||||
{field('year', 'Exercício — obrigação PPC')}
|
||||
{field('previousYear', 'Exercício anterior — PPC')}
|
||||
<label className="block">
|
||||
Exercício anterior civil completo
|
||||
<select
|
||||
aria-label="Exercício anterior civil completo"
|
||||
value={p.previousFullCalendarYear}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
previousFullCalendarYear: e.target
|
||||
.value as PpcObligation['previousFullCalendarYear'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por confirmar</option>
|
||||
<option value="yes">Sim</option>
|
||||
<option value="no">
|
||||
Não — anualização/período especial separado
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{field(
|
||||
'previousTax',
|
||||
'Imposto liquidado anterior21(1) — MZN',
|
||||
)}
|
||||
{field(
|
||||
'assessmentReference',
|
||||
'Fonte da liquidação anterior — PPC',
|
||||
)}
|
||||
{field(
|
||||
'previousWithholdings',
|
||||
'Retenções na fonte anteriores — MZN',
|
||||
)}
|
||||
{field(
|
||||
'withholdingReference',
|
||||
'Fonte das retenções anteriores — PPC',
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{m.pending.length ? (
|
||||
<p role="status">{m.pending.join(' ')}</p>
|
||||
) : (
|
||||
<>
|
||||
<p>
|
||||
80% antes de arredondar:{' '}
|
||||
{fractionPresentation(m.annualBeforeRounding!).decimal}{' '}
|
||||
MZN. Total das três prestações arredondadas:{' '}
|
||||
{fractionPresentation(m.total!).decimal} MZN.
|
||||
</p>
|
||||
<ul>
|
||||
{m.schedule.map((s) => (
|
||||
<li key={s.month}>
|
||||
{s.month}:{' '}
|
||||
{fractionPresentation(s.amount).decimal} MZN
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
<p>
|
||||
Guardar o rascunho conserva esta preparação; calcular o fecho
|
||||
anual inclui-a no relatório. Só comprovativos efectivos podem
|
||||
alimentar as deduções PPC abaixo. Não executa pagamento,
|
||||
dispensa, guia ou juros.
|
||||
</p>
|
||||
<details>
|
||||
<summary>Fonte e limites</summary>
|
||||
<p>{ppcObligationSource}</p>
|
||||
</details>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { validatePpcObligation, ppcObligationReport, ppcObligationVersion, type PpcObligation } from './irpc-ppc-obligation.ts';
|
||||
import {
|
||||
newInvestmentCredit,
|
||||
validateInvestmentCredit,
|
||||
@@ -122,6 +123,7 @@ export type AnnualBook = {
|
||||
creditCarry?: CreditCarry;
|
||||
economicCredits?: EconomicCredits;
|
||||
investmentCredit?: InvestmentCredit;
|
||||
ppcObligation?: PpcObligation;
|
||||
result?: AnnualRecord;
|
||||
history: AnnualRecord[];
|
||||
};
|
||||
@@ -291,6 +293,7 @@ function books(d: Record<string, unknown>): Record<string, AnnualBook> {
|
||||
return m;
|
||||
}
|
||||
export function validateAnnual(b: AnnualBook) {
|
||||
if (b?.ppcObligation !== undefined) validatePpcObligation(b.ppcObligation);
|
||||
if (b?.investmentCredit !== undefined)
|
||||
validateInvestmentCredit(b.investmentCredit);
|
||||
if (b?.economicCredits !== undefined) validateEconomic(b.economicCredits);
|
||||
@@ -565,6 +568,7 @@ function key(d: Record<string, unknown>, b: AnnualBook) {
|
||||
acquisitionScope(d),
|
||||
input,
|
||||
dependencies(d, !!b.investmentCredit),
|
||||
...(b.ppcObligation ? [ppcObligationVersion] : []),
|
||||
...(b.investmentCredit && b.creditCarry?.lots.length
|
||||
? ['CBF15-credit-carry-combination/1']
|
||||
: []),
|
||||
@@ -1712,6 +1716,7 @@ export function annualReportRows(
|
||||
indeterminate: 'Indeterminado',
|
||||
}[m.status];
|
||||
return [
|
||||
...(m.input.ppcObligation ? ppcObligationReport(m.input.ppcObligation,m.subjectNuit,m.year,m.input.assessment) : []),
|
||||
[
|
||||
'IRPC — L8',
|
||||
'Fecho anual — âmbito e origem',
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
import {
|
||||
decimalFraction,
|
||||
fraction,
|
||||
subtractFractions,
|
||||
fractionPresentation,
|
||||
type FiscalFraction,
|
||||
} from './fiscal-rational.ts';
|
||||
|
||||
export const ppcObligationVersion = 'IRPC-PPC-obligation/1';
|
||||
export const ppcObligationSource =
|
||||
'RIRPC, Decreto 9/2008, arts.27(1)(a) e28(1–3), BR16/I,16-04-2008,exemplar preservado SHA256 fc373ff5637edf75ec6a9595dec8763a8503d4ee786e3b7d8f1c742eae9d80ee: imposto liquidado no exercício anterior nos termos21(1), líquido das retenções na fonte;80%, dividido em três montantes iguais arredondados por excesso ao milhar de meticais. Maio,Julho,Setembro. Recorte2026,residente geral,actividade comercial/industrial/agrícola,ano civil e exercício anterior completo2025,MZN. Períodos especiais,anualização28(3),dispensas,juros e guias separados.';
|
||||
export type PpcObligation = {
|
||||
version: 1;
|
||||
scope: '' | 'ordinary_resident' | 'other';
|
||||
subjectNuit: string;
|
||||
year: string;
|
||||
previousYear: string;
|
||||
previousFullCalendarYear: '' | 'yes' | 'no';
|
||||
previousTax: string;
|
||||
previousWithholdings: string;
|
||||
assessmentReference: string;
|
||||
withholdingReference: string;
|
||||
};
|
||||
export const newPpcObligation = (
|
||||
subjectNuit = '',
|
||||
year = '',
|
||||
): PpcObligation => ({
|
||||
version: 1,
|
||||
scope: '',
|
||||
subjectNuit,
|
||||
year,
|
||||
previousYear: '',
|
||||
previousFullCalendarYear: '',
|
||||
previousTax: '',
|
||||
previousWithholdings: '',
|
||||
assessmentReference: '',
|
||||
withholdingReference: '',
|
||||
});
|
||||
export function validatePpcObligation(p: PpcObligation) {
|
||||
if (
|
||||
!p ||
|
||||
p.version !== 1 ||
|
||||
Object.keys(newPpcObligation())
|
||||
.filter((k) => k !== 'version')
|
||||
.some(
|
||||
(k) =>
|
||||
typeof (p as unknown as Record<string, unknown>)[k] !==
|
||||
'string',
|
||||
) ||
|
||||
!['', 'ordinary_resident', 'other'].includes(p.scope) ||
|
||||
!['', 'yes', 'no'].includes(p.previousFullCalendarYear)
|
||||
)
|
||||
throw Error('Preparação PPC não recuperável; original preservado.');
|
||||
}
|
||||
export function calculatePpcObligation(
|
||||
p: PpcObligation,
|
||||
subjectNuit: string,
|
||||
year: string,
|
||||
assessment: string,
|
||||
) {
|
||||
validatePpcObligation(p);
|
||||
const pending: string[] = [];
|
||||
let base: FiscalFraction | null = null,
|
||||
annualBeforeRounding: FiscalFraction | null = null,
|
||||
instalment: FiscalFraction | null = null;
|
||||
if (
|
||||
p.scope !== 'ordinary_resident' ||
|
||||
assessment !== 'normal' ||
|
||||
p.previousFullCalendarYear !== 'yes' ||
|
||||
year !== '2026' ||
|
||||
p.year !== year ||
|
||||
p.previousYear !== '2025' ||
|
||||
!/^\d{9}$/.test(subjectNuit) ||
|
||||
p.subjectNuit !== subjectNuit
|
||||
)
|
||||
pending.push(
|
||||
'PPC: confirmar titular,2026,residente geral com actividade comercial/industrial/agrícola e exercício civil completo2025. Outros períodos/regimes e anualização permanecem separados.',
|
||||
);
|
||||
if (!p.assessmentReference.trim() || !p.withholdingReference.trim())
|
||||
pending.push(
|
||||
'PPC: falta suporte do imposto liquidado anterior21(1) e das retenções na fonte, incluindo zero conhecido. Colecta projectada corrente não substitui liquidação anterior.',
|
||||
);
|
||||
if (
|
||||
![p.previousTax, p.previousWithholdings].every((v) =>
|
||||
/^\d{1,18}(\.\d{1,2})?$/.test(v),
|
||||
)
|
||||
)
|
||||
pending.push(
|
||||
'PPC: montantes anteriores em MZN desconhecidos ou inválidos; zero deve ser explícito.',
|
||||
);
|
||||
if (!pending.length) {
|
||||
base = subtractFractions(
|
||||
decimalFraction(p.previousTax),
|
||||
decimalFraction(p.previousWithholdings),
|
||||
);
|
||||
if (BigInt(base.numerator) < 0n)
|
||||
pending.push(
|
||||
'PPC: retenções superiores ao imposto anterior; reconciliar o caso antes de determinar a obrigação.',
|
||||
);
|
||||
else {
|
||||
annualBeforeRounding = fraction(
|
||||
BigInt(base.numerator) * 4n,
|
||||
BigInt(base.denominator) * 5n,
|
||||
);
|
||||
const n = BigInt(annualBeforeRounding.numerator),
|
||||
d = BigInt(annualBeforeRounding.denominator) * 3n * 1000n;
|
||||
instalment = fraction(((n + d - 1n) / d) * 1000n);
|
||||
}
|
||||
}
|
||||
return {
|
||||
version: ppcObligationVersion,
|
||||
source: ppcObligationSource,
|
||||
pending,
|
||||
base,
|
||||
annualBeforeRounding,
|
||||
instalment,
|
||||
total: instalment
|
||||
? fraction(
|
||||
BigInt(instalment.numerator) * 3n,
|
||||
BigInt(instalment.denominator),
|
||||
)
|
||||
: null,
|
||||
schedule: instalment
|
||||
? ['2026-05', '2026-07', '2026-09'].map((month) => ({
|
||||
month,
|
||||
amount: instalment,
|
||||
}))
|
||||
: [],
|
||||
paymentExecuted: false,
|
||||
annualDeductionCreated: false,
|
||||
};
|
||||
}
|
||||
export function ppcObligationReport(
|
||||
p: PpcObligation,
|
||||
subjectNuit: string,
|
||||
year: string,
|
||||
assessment: string,
|
||||
): Array<[string, string, string, string]> {
|
||||
const m = calculatePpcObligation(p, subjectNuit, year, assessment),
|
||||
show = (v: FiscalFraction | null) =>
|
||||
v ? fractionPresentation(v).decimal + ' MZN' : 'Indeterminado';
|
||||
return [
|
||||
[
|
||||
'IRPC — L8',
|
||||
'PPC — obrigação preparada',
|
||||
m.pending.length
|
||||
? m.pending.join(' ')
|
||||
: 'Base líquida anterior: ' +
|
||||
show(m.base) +
|
||||
';80% antes de arredondar: ' +
|
||||
show(m.annualBeforeRounding) +
|
||||
'; cada prestação: ' +
|
||||
show(m.instalment) +
|
||||
'; total arredondado: ' +
|
||||
show(m.total) +
|
||||
'. ' +
|
||||
m.schedule
|
||||
.map((s) => s.month + ': ' + show(s.amount))
|
||||
.join('; ') +
|
||||
'. Previsão de obrigação; não é pagamento nem dedução anual.',
|
||||
p.assessmentReference +
|
||||
'; ' +
|
||||
p.withholdingReference +
|
||||
'; ' +
|
||||
m.source,
|
||||
],
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user