Prepare PEC obligation total and calendar with private recovery and reports
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import {SimulationIrpcPecObligation} from './simulation-irpc-pec-obligation';
|
||||
import { SimulationIrpcPpcObligation } from './simulation-irpc-ppc-obligation';
|
||||
import { SimulationIrpcInvestment } from './simulation-irpc-investment';
|
||||
import { SimulationIrpcEconomic } from './simulation-irpc-economic';
|
||||
@@ -341,6 +342,7 @@ export function SimulationIrpcAnnual({ draft, onChange }: Props) {
|
||||
</fieldset>
|
||||
<fieldset className="space-y-2 rounded border p-3">
|
||||
<legend>PPC efectivamente pagos</legend>
|
||||
<SimulationIrpcPecObligation book={b} onChange={pecObligation=>patch({pecObligation})}/>
|
||||
<SimulationIrpcPpcObligation book={b} onChange={ppcObligation=>patch({ppcObligation})}/>
|
||||
{group('ppc', 'PPC efectuados')}
|
||||
<p>
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import {
|
||||
newPecObligation,
|
||||
calculatePecObligation,
|
||||
pecObligationSource,
|
||||
type PecObligation,
|
||||
} from '@/lib/irpc-pec-obligation';
|
||||
import { fractionPresentation } from '@/lib/fiscal-rational';
|
||||
import type { AnnualBook } from '@/lib/irpc-annual-settlement';
|
||||
export function SimulationIrpcPecObligation({
|
||||
book,
|
||||
onChange,
|
||||
}: {
|
||||
book: AnnualBook;
|
||||
onChange: (p: PecObligation) => void;
|
||||
}) {
|
||||
const p = book.pecObligation;
|
||||
if (!p)
|
||||
return (
|
||||
<section className="rounded border p-3">
|
||||
<h5>Obrigação PEC</h5>
|
||||
<p>
|
||||
Preparar o total e os meses previstos conserva os
|
||||
comprovativos pagos em separado.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
onChange(newPecObligation(book.subjectNuit, book.year))
|
||||
}
|
||||
>
|
||||
Preparar obrigação PEC
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
const m = calculatePecObligation(
|
||||
p,
|
||||
book.subjectNuit,
|
||||
book.year,
|
||||
book.assessment,
|
||||
),
|
||||
patch = (changes: Partial<PecObligation>) =>
|
||||
onChange({ ...p, ...changes });
|
||||
const field = (
|
||||
key: Exclude<keyof PecObligation, 'version' | 'scope'>,
|
||||
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 PEC"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<h5>Obrigação PEC — preparação</h5>
|
||||
<label className="block">
|
||||
Enquadramento PEC
|
||||
<select
|
||||
aria-label="Enquadramento PEC"
|
||||
value={p.scope}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
scope: e.target.value as PecObligation['scope'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por confirmar</option>
|
||||
<option value="ordinary_resident">
|
||||
Residente geral — comercial,industrial ou agrícola,ano
|
||||
civil
|
||||
</option>
|
||||
<option value="other">
|
||||
Outro enquadramento — separado
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{p.scope === 'ordinary_resident' && (
|
||||
<>
|
||||
{field('subjectNuit', 'NUIT — obrigação PEC')}
|
||||
{field('year', 'Exercício — obrigação PEC')}
|
||||
{field(
|
||||
'activityStartYear',
|
||||
'Ano de início efectivo da actividade — PEC',
|
||||
)}
|
||||
{field(
|
||||
'activityReference',
|
||||
'Fonte do início de actividade — PEC',
|
||||
)}
|
||||
{p.activityStartYear !== book.year && (
|
||||
<>
|
||||
{field('previousYear', 'Exercício anterior — PEC')}
|
||||
{field(
|
||||
'previousTurnover',
|
||||
'Volume de negócios anterior — MZN',
|
||||
)}
|
||||
{field(
|
||||
'turnoverReference',
|
||||
'Fonte do volume de negócios — PEC',
|
||||
)}
|
||||
{field(
|
||||
'previousPpcPaid',
|
||||
'PPC efectivamente pagos no ano anterior — MZN',
|
||||
)}
|
||||
{field(
|
||||
'ppcReference',
|
||||
'Fonte dos PPC anteriores — PEC',
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{m.pending.length ? (
|
||||
<p role="status">{m.pending.join(' ')}</p>
|
||||
) : m.notApplicable ? (
|
||||
<p>Não aplicável no ano de início da actividade29(4).</p>
|
||||
) : (
|
||||
<>
|
||||
<p>
|
||||
Obrigação total:{' '}
|
||||
{fractionPresentation(m.total!).decimal} MZN.
|
||||
</p>
|
||||
<ul>
|
||||
{m.months.map((month) => (
|
||||
<li key={month}>{month}</li>
|
||||
))}
|
||||
</ul>
|
||||
<p>
|
||||
Repartição por prestação e opção de pagamento único por
|
||||
preparar; não se presume dia limite nem arredondamento
|
||||
do PPC para o PEC.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<p>
|
||||
Guardar o rascunho conserva esta preparação. Calcular o fecho
|
||||
anual inclui-a no relatório. Não regista pagamentos,cria
|
||||
deduções ou executa guias. Os comprovativos efectivos permanecem
|
||||
no detalhe PEC existente.
|
||||
</p>
|
||||
<details>
|
||||
<summary>Fonte e limites PEC</summary>
|
||||
<p>{pecObligationSource}</p>
|
||||
</details>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import {validatePecObligation,pecObligationReport,pecObligationVersion,type PecObligation} from './irpc-pec-obligation.ts';
|
||||
import { validatePpcObligation, ppcObligationReport, ppcObligationVersion, type PpcObligation } from './irpc-ppc-obligation.ts';
|
||||
import {
|
||||
newInvestmentCredit,
|
||||
@@ -124,6 +125,7 @@ export type AnnualBook = {
|
||||
economicCredits?: EconomicCredits;
|
||||
investmentCredit?: InvestmentCredit;
|
||||
ppcObligation?: PpcObligation;
|
||||
pecObligation?: PecObligation;
|
||||
result?: AnnualRecord;
|
||||
history: AnnualRecord[];
|
||||
};
|
||||
@@ -293,6 +295,7 @@ function books(d: Record<string, unknown>): Record<string, AnnualBook> {
|
||||
return m;
|
||||
}
|
||||
export function validateAnnual(b: AnnualBook) {
|
||||
if(b?.pecObligation!==undefined)validatePecObligation(b.pecObligation);
|
||||
if (b?.ppcObligation !== undefined) validatePpcObligation(b.ppcObligation);
|
||||
if (b?.investmentCredit !== undefined)
|
||||
validateInvestmentCredit(b.investmentCredit);
|
||||
@@ -569,6 +572,7 @@ function key(d: Record<string, unknown>, b: AnnualBook) {
|
||||
input,
|
||||
dependencies(d, !!b.investmentCredit),
|
||||
...(b.ppcObligation ? [ppcObligationVersion] : []),
|
||||
...(b.pecObligation ? [pecObligationVersion] : []),
|
||||
...(b.investmentCredit && b.creditCarry?.lots.length
|
||||
? ['CBF15-credit-carry-combination/1']
|
||||
: []),
|
||||
@@ -1716,6 +1720,7 @@ export function annualReportRows(
|
||||
indeterminate: 'Indeterminado',
|
||||
}[m.status];
|
||||
return [
|
||||
...(m.input.pecObligation ? pecObligationReport(m.input.pecObligation,m.subjectNuit,m.year,m.input.assessment) : []),
|
||||
...(m.input.ppcObligation ? ppcObligationReport(m.input.ppcObligation,m.subjectNuit,m.year,m.input.assessment) : []),
|
||||
[
|
||||
'IRPC — L8',
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
import {
|
||||
decimalFraction,
|
||||
fraction,
|
||||
subtractFractions,
|
||||
fractionPresentation,
|
||||
type FiscalFraction,
|
||||
} from './fiscal-rational.ts';
|
||||
export const pecObligationVersion = 'IRPC-PEC-obligation/1';
|
||||
export const pecObligationSource =
|
||||
'RIRPC,Decreto9/2008,art29(1–5),BR16/I16-04-2008,original SHA256 fc373ff5637edf75ec6a9595dec8763a8503d4ee786e3b7d8f1c742eae9d80ee.0,5% do volume de negócios anterior,limites30.000/100.000MZN,menos PPC efectivamente pagos no ano anterior.Junho/Agosto/Outubro;opção de pagamento único prevista,sem data ou repartição inventada. Ano de início excluído29(4);sem volume anterior exige último montante29(5). Recorte2026,residente geral comercial/industrial/agrícola,ano civil,MZN. Regimes/períodos especiais,rectificação29(3),base de anos anteriores29(5),guias/juros separados.';
|
||||
export type PecObligation = {
|
||||
version: 1;
|
||||
scope: '' | 'ordinary_resident' | 'other';
|
||||
subjectNuit: string;
|
||||
year: string;
|
||||
activityStartYear: string;
|
||||
activityReference: string;
|
||||
previousYear: string;
|
||||
previousTurnover: string;
|
||||
turnoverReference: string;
|
||||
previousPpcPaid: string;
|
||||
ppcReference: string;
|
||||
};
|
||||
export const newPecObligation = (
|
||||
subjectNuit = '',
|
||||
year = '',
|
||||
): PecObligation => ({
|
||||
version: 1,
|
||||
scope: '',
|
||||
subjectNuit,
|
||||
year,
|
||||
activityStartYear: '',
|
||||
activityReference: '',
|
||||
previousYear: '',
|
||||
previousTurnover: '',
|
||||
turnoverReference: '',
|
||||
previousPpcPaid: '',
|
||||
ppcReference: '',
|
||||
});
|
||||
export function validatePecObligation(p: PecObligation) {
|
||||
if (
|
||||
!p ||
|
||||
p.version !== 1 ||
|
||||
Object.keys(newPecObligation())
|
||||
.filter((k) => k !== 'version')
|
||||
.some(
|
||||
(k) =>
|
||||
typeof (p as unknown as Record<string, unknown>)[k] !==
|
||||
'string',
|
||||
) ||
|
||||
!['', 'ordinary_resident', 'other'].includes(p.scope)
|
||||
)
|
||||
throw Error(
|
||||
'Preparação da obrigação PEC não recuperável;original preservado.',
|
||||
);
|
||||
}
|
||||
export function calculatePecObligation(
|
||||
p: PecObligation,
|
||||
subjectNuit: string,
|
||||
year: string,
|
||||
assessment: string,
|
||||
) {
|
||||
validatePecObligation(p);
|
||||
const pending: string[] = [];
|
||||
let percentage: FiscalFraction | null = null,
|
||||
limited: FiscalFraction | null = null,
|
||||
total: FiscalFraction | null = null,
|
||||
notApplicable = false;
|
||||
if (
|
||||
p.scope !== 'ordinary_resident' ||
|
||||
assessment !== 'normal' ||
|
||||
year !== '2026' ||
|
||||
p.year !== year ||
|
||||
p.subjectNuit !== subjectNuit ||
|
||||
!/^\d{9}$/.test(subjectNuit)
|
||||
)
|
||||
pending.push(
|
||||
'PEC: confirmar titular2026,residente geral com actividade comercial/industrial/agrícola,ano civil e MZN;outros regimes/períodos separados.',
|
||||
);
|
||||
if (
|
||||
!/^\d{4}$/.test(p.activityStartYear) ||
|
||||
Number(p.activityStartYear) < 1 ||
|
||||
Number(p.activityStartYear) > 2026 ||
|
||||
!p.activityReference.trim()
|
||||
)
|
||||
pending.push(
|
||||
'PEC: falta ano de início efectivo da actividade e suporte;constituição da empresa não substitui início.',
|
||||
);
|
||||
if (!pending.length && p.activityStartYear === '2026') {
|
||||
notApplicable = true;
|
||||
total = fraction(0n);
|
||||
} else if (!pending.length) {
|
||||
if (
|
||||
p.previousYear !== '2025' ||
|
||||
!p.turnoverReference.trim() ||
|
||||
!p.ppcReference.trim()
|
||||
)
|
||||
pending.push(
|
||||
'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) =>
|
||||
/^\d{1,18}(\.\d{1,2})?$/.test(v),
|
||||
)
|
||||
)
|
||||
pending.push(
|
||||
'PEC: valores anteriores desconhecidos/inválidos;zero deve ser explícito.',
|
||||
);
|
||||
if (!pending.length) {
|
||||
const v = decimalFraction(p.previousTurnover),
|
||||
ppc = decimalFraction(p.previousPpcPaid);
|
||||
if (BigInt(v.numerator) === 0n)
|
||||
pending.push(
|
||||
'PEC29(5):sem volume de negócios em2025,recuperar último montante dos anos anteriores;zero não determina automaticamente o mínimo.',
|
||||
);
|
||||
else {
|
||||
percentage = fraction(
|
||||
BigInt(v.numerator),
|
||||
BigInt(v.denominator) * 200n,
|
||||
);
|
||||
const n = BigInt(percentage.numerator),
|
||||
d = BigInt(percentage.denominator);
|
||||
limited =
|
||||
n < 30000n * d
|
||||
? fraction(30000n)
|
||||
: n > 100000n * d
|
||||
? fraction(100000n)
|
||||
: percentage;
|
||||
const residual = subtractFractions(limited, ppc);
|
||||
if (BigInt(residual.numerator) < 0n)
|
||||
pending.push(
|
||||
'PEC:PPC anteriores excedem o montante limitado;caso separado para reconciliação,não gera obrigação negativa ou reembolso.',
|
||||
);
|
||||
else total = residual;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
version: pecObligationVersion,
|
||||
source: pecObligationSource,
|
||||
pending,
|
||||
percentage,
|
||||
limited,
|
||||
total,
|
||||
notApplicable,
|
||||
months:
|
||||
total && !notApplicable ? ['2026-06', '2026-08', '2026-10'] : [],
|
||||
instalmentAmountsDetermined: false,
|
||||
paymentExecuted: false,
|
||||
annualDeductionCreated: false,
|
||||
};
|
||||
}
|
||||
export function pecObligationReport(
|
||||
p: PecObligation,
|
||||
subjectNuit: string,
|
||||
year: string,
|
||||
assessment: string,
|
||||
): Array<[string, string, string, string]> {
|
||||
const m = calculatePecObligation(p, subjectNuit, year, assessment),
|
||||
show = (v: FiscalFraction | null) =>
|
||||
v ? fractionPresentation(v).decimal + ' MZN' : 'Indeterminado';
|
||||
return [
|
||||
[
|
||||
'IRPC — L8',
|
||||
'PEC — obrigação preparada',
|
||||
m.pending.length
|
||||
? m.pending.join(' ')
|
||||
: m.notApplicable
|
||||
? 'Não aplicável no ano de início da actividade29(4);total0 MZN.'
|
||||
: '0,5%: ' +
|
||||
show(m.percentage) +
|
||||
';limitado antes de PPC: ' +
|
||||
show(m.limited) +
|
||||
';obrigação total: ' +
|
||||
show(m.total) +
|
||||
';meses: ' +
|
||||
m.months.join(', ') +
|
||||
'. Montantes por prestação e opção de pagamento único não determinados neste recorte. Preparação não é pagamento nem dedução anual.',
|
||||
p.activityReference +
|
||||
'; ' +
|
||||
p.turnoverReference +
|
||||
'; ' +
|
||||
p.ppcReference +
|
||||
'; ' +
|
||||
m.source,
|
||||
],
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user