Clarify viability simulation purpose and preserve PEC cash-flow hypotheses
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -342,6 +342,7 @@ export function SimulationIrpcAnnual({ draft, onChange }: Props) {
|
||||
</fieldset>
|
||||
<fieldset className="space-y-2 rounded border p-3">
|
||||
<legend>PPC efectivamente pagos</legend>
|
||||
<p>Simulação fiscal para avaliar a viabilidade do negócio e as necessidades de tesouraria. Os valores e meses previstos são estimativas; o portal não executa pagamentos nem submete declarações fiscais.</p>
|
||||
<SimulationIrpcPecObligation book={b} onChange={pecObligation=>patch({pecObligation})}/>
|
||||
<SimulationIrpcPpcObligation book={b} onChange={ppcObligation=>patch({ppcObligation})}/>
|
||||
{group('ppc', 'PPC efectuados')}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {SimulationIrpcPecPlan} from './simulation-irpc-pec-plan';
|
||||
import {
|
||||
newPecObligation,
|
||||
calculatePecObligation,
|
||||
@@ -17,7 +18,7 @@ export function SimulationIrpcPecObligation({
|
||||
if (!p)
|
||||
return (
|
||||
<section className="rounded border p-3">
|
||||
<h5>Obrigação PEC</h5>
|
||||
<h5>Estimativa PEC</h5>
|
||||
<p>
|
||||
Preparar o total e os meses previstos conserva os
|
||||
comprovativos pagos em separado.
|
||||
@@ -28,7 +29,7 @@ export function SimulationIrpcPecObligation({
|
||||
onChange(newPecObligation(book.subjectNuit, book.year))
|
||||
}
|
||||
>
|
||||
Preparar obrigação PEC
|
||||
Simular PEC
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
@@ -41,7 +42,7 @@ export function SimulationIrpcPecObligation({
|
||||
patch = (changes: Partial<PecObligation>) =>
|
||||
onChange({ ...p, ...changes });
|
||||
const field = (
|
||||
key: Exclude<keyof PecObligation, 'version' | 'scope'>,
|
||||
key: Exclude<keyof PecObligation, 'version' | 'scope' | 'plan'>,
|
||||
label: string,
|
||||
) => (
|
||||
<label className="block">
|
||||
@@ -55,10 +56,10 @@ export function SimulationIrpcPecObligation({
|
||||
);
|
||||
return (
|
||||
<section
|
||||
aria-label="Preparação da obrigação PEC"
|
||||
aria-label="Preparação da estimativa PEC"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<h5>Obrigação PEC — preparação</h5>
|
||||
<h5>Estimativa PEC — preparação</h5>
|
||||
<label className="block">
|
||||
Enquadramento PEC
|
||||
<select
|
||||
@@ -82,8 +83,8 @@ export function SimulationIrpcPecObligation({
|
||||
</label>
|
||||
{p.scope === 'ordinary_resident' && (
|
||||
<>
|
||||
{field('subjectNuit', 'NUIT — obrigação PEC')}
|
||||
{field('year', 'Exercício — obrigação PEC')}
|
||||
{field('subjectNuit', 'NUIT — estimativa PEC')}
|
||||
{field('year', 'Exercício — estimativa PEC')}
|
||||
{field(
|
||||
'activityStartYear',
|
||||
'Ano de início efectivo da actividade — PEC',
|
||||
@@ -122,7 +123,7 @@ export function SimulationIrpcPecObligation({
|
||||
) : (
|
||||
<>
|
||||
<p>
|
||||
Obrigação total:{' '}
|
||||
Total estimado:{' '}
|
||||
{fractionPresentation(m.total!).decimal} MZN.
|
||||
</p>
|
||||
<ul>
|
||||
@@ -130,13 +131,10 @@ export function SimulationIrpcPecObligation({
|
||||
<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>
|
||||
|
||||
</>
|
||||
)}
|
||||
<SimulationIrpcPecPlan plan={p.plan} total={m.total} notApplicable={m.notApplicable} year={book.year} onChange={plan=>patch({plan})}/>
|
||||
<p>
|
||||
Guardar o rascunho conserva esta preparação. Calcular o fecho
|
||||
anual inclui-a no relatório. Não regista pagamentos,cria
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
import {
|
||||
newPecPlan,
|
||||
calculatePecPlan,
|
||||
pecPlanSource,
|
||||
type PecPlan,
|
||||
} from '@/lib/irpc-pec-plan';
|
||||
import {
|
||||
fractionPresentation,
|
||||
type FiscalFraction,
|
||||
} from '@/lib/fiscal-rational';
|
||||
export function SimulationIrpcPecPlan({
|
||||
plan,
|
||||
total,
|
||||
notApplicable,
|
||||
year,
|
||||
onChange,
|
||||
}: {
|
||||
plan?: PecPlan;
|
||||
total: FiscalFraction | null;
|
||||
notApplicable: boolean;
|
||||
year: string;
|
||||
onChange: (p: PecPlan) => void;
|
||||
}) {
|
||||
if (!plan)
|
||||
return (
|
||||
<div className="rounded border p-3">
|
||||
<p>
|
||||
Prepare os montantes por prestação ou a opção de pagamento
|
||||
único,sem registar pagamento.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
disabled={
|
||||
!total || notApplicable || BigInt(total.numerator) <= 0n
|
||||
}
|
||||
onClick={() => onChange(newPecPlan())}
|
||||
>
|
||||
Simular tesouraria PEC
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
const m = calculatePecPlan(plan, total, notApplicable, year),
|
||||
patch = (p: Partial<PecPlan>) => onChange({ ...plan, ...p });
|
||||
const field = (
|
||||
key: 'reference' | 'june' | 'august' | 'october',
|
||||
label: string,
|
||||
) => (
|
||||
<label className="block">
|
||||
{label}
|
||||
<input
|
||||
aria-label={label}
|
||||
value={plan[key]}
|
||||
onChange={(e) => patch({ [key]: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
<section
|
||||
aria-label="Projecção de tesouraria PEC"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<h6>Projecção PEC</h6>
|
||||
{m.pending.length ? (
|
||||
<p role="status">{m.pending.join(' ')}</p>
|
||||
) : (
|
||||
<p>
|
||||
Soma reconciliada:{' '}
|
||||
{m.rows
|
||||
.map(
|
||||
(r) =>
|
||||
r.month +
|
||||
': ' +
|
||||
fractionPresentation(r.amount).decimal +
|
||||
' MZN',
|
||||
)
|
||||
.join('; ')}
|
||||
. Prazo legal não validado.
|
||||
</p>
|
||||
)}
|
||||
<details open={m.pending.length > 0}>
|
||||
<summary>Alterar projecção PEC</summary>
|
||||
<label className="block">
|
||||
Opção de preparação PEC
|
||||
<select
|
||||
aria-label="Opção de preparação PEC"
|
||||
value={plan.mode}
|
||||
onChange={(e) =>
|
||||
patch({ mode: e.target.value as PecPlan['mode'] })
|
||||
}
|
||||
>
|
||||
<option value="">Por escolher</option>
|
||||
<option value="three">
|
||||
Distribuir a estimativa por três meses
|
||||
</option>
|
||||
<option value="single">
|
||||
Concentrar a estimativa num mês
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{field('reference', 'Fundamento do projecção PEC')}
|
||||
{plan.mode === 'three' && (
|
||||
<>
|
||||
{field('june', 'PEC Junho — MZN')}
|
||||
{field('august', 'PEC Agosto — MZN')}
|
||||
{field('october', 'PEC Outubro — MZN')}
|
||||
</>
|
||||
)}
|
||||
{plan.mode === 'single' && (
|
||||
<label className="block">
|
||||
Mês previsto do PEC único
|
||||
<input
|
||||
aria-label="Mês previsto do PEC único"
|
||||
type="month"
|
||||
value={plan.singleMonth}
|
||||
onChange={(e) =>
|
||||
patch({ singleMonth: e.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
</details>
|
||||
<p>
|
||||
O mês escolhido é uma hipótese de tesouraria para avaliar a
|
||||
viabilidade. A reconciliação da soma não valida os prazos
|
||||
legais,emite guia ou regista pagamento. Alterar a estimativa
|
||||
exige reconferir o plano. Guarde pelo rascunho e recalcule o
|
||||
fecho para actualizar o relatório.
|
||||
</p>
|
||||
<details>
|
||||
<summary>Fonte do projecção PEC</summary>
|
||||
<p>{pecPlanSource}</p>
|
||||
</details>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export function SimulationIrpcPpcObligation({
|
||||
if (!p)
|
||||
return (
|
||||
<section className="rounded border p-3">
|
||||
<h5>Obrigação PPC</h5>
|
||||
<h5>Estimativa PPC</h5>
|
||||
<p>
|
||||
Preparar a obrigação e os meses previstos não regista
|
||||
pagamentos nem cria deduções na liquidação.
|
||||
@@ -28,7 +28,7 @@ export function SimulationIrpcPpcObligation({
|
||||
onChange(newPpcObligation(book.subjectNuit, book.year))
|
||||
}
|
||||
>
|
||||
Preparar obrigação PPC
|
||||
Simular PPC
|
||||
</button>
|
||||
</section>
|
||||
);
|
||||
@@ -62,10 +62,10 @@ export function SimulationIrpcPpcObligation({
|
||||
);
|
||||
return (
|
||||
<section
|
||||
aria-label="Preparação da obrigação PPC"
|
||||
aria-label="Preparação da estimativa PPC"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<h5>Obrigação PPC — exercício anterior</h5>
|
||||
<h5>Estimativa 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
|
||||
@@ -94,8 +94,8 @@ export function SimulationIrpcPpcObligation({
|
||||
</label>
|
||||
{p.scope === 'ordinary_resident' && (
|
||||
<>
|
||||
{field('subjectNuit', 'NUIT — obrigação PPC')}
|
||||
{field('year', 'Exercício — obrigação PPC')}
|
||||
{field('subjectNuit', 'NUIT — estimativa PPC')}
|
||||
{field('year', 'Exercício — estimativa PPC')}
|
||||
{field('previousYear', 'Exercício anterior — PPC')}
|
||||
<label className="block">
|
||||
Exercício anterior civil completo
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
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';
|
||||
import {
|
||||
@@ -573,6 +574,7 @@ function key(d: Record<string, unknown>, b: AnnualBook) {
|
||||
dependencies(d, !!b.investmentCredit),
|
||||
...(b.ppcObligation ? [ppcObligationVersion] : []),
|
||||
...(b.pecObligation ? [pecObligationVersion] : []),
|
||||
...(b.pecObligation?.plan ? [pecPlanVersion] : []),
|
||||
...(b.investmentCredit && b.creditCarry?.lots.length
|
||||
? ['CBF15-credit-carry-combination/1']
|
||||
: []),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {validatePecPlan,pecPlanReport,type PecPlan} from './irpc-pec-plan.ts';
|
||||
import {
|
||||
decimalFraction,
|
||||
fraction,
|
||||
@@ -10,6 +11,7 @@ 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;
|
||||
plan?: PecPlan;
|
||||
scope: '' | 'ordinary_resident' | 'other';
|
||||
subjectNuit: string;
|
||||
year: string;
|
||||
@@ -38,6 +40,7 @@ export const newPecObligation = (
|
||||
ppcReference: '',
|
||||
});
|
||||
export function validatePecObligation(p: PecObligation) {
|
||||
if(p?.plan!==undefined)validatePecPlan(p.plan);
|
||||
if (
|
||||
!p ||
|
||||
p.version !== 1 ||
|
||||
@@ -51,7 +54,7 @@ export function validatePecObligation(p: PecObligation) {
|
||||
!['', 'ordinary_resident', 'other'].includes(p.scope)
|
||||
)
|
||||
throw Error(
|
||||
'Preparação da obrigação PEC não recuperável;original preservado.',
|
||||
'Preparação da estimativa PEC não recuperável;original preservado.',
|
||||
);
|
||||
}
|
||||
export function calculatePecObligation(
|
||||
@@ -129,7 +132,7 @@ export function calculatePecObligation(
|
||||
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.',
|
||||
'PEC:PPC anteriores excedem o montante limitado;caso separado para reconciliação,não gera estimativa negativa ou reembolso.',
|
||||
);
|
||||
else total = residual;
|
||||
}
|
||||
@@ -160,9 +163,10 @@ export function pecObligationReport(
|
||||
show = (v: FiscalFraction | null) =>
|
||||
v ? fractionPresentation(v).decimal + ' MZN' : 'Indeterminado';
|
||||
return [
|
||||
...(p.plan ? pecPlanReport(p.plan,m.total,m.notApplicable,year) : []),
|
||||
[
|
||||
'IRPC — L8',
|
||||
'PEC — obrigação preparada',
|
||||
'PEC — estimativa fiscal',
|
||||
m.pending.length
|
||||
? m.pending.join(' ')
|
||||
: m.notApplicable
|
||||
@@ -171,11 +175,11 @@ export function pecObligationReport(
|
||||
show(m.percentage) +
|
||||
';limitado antes de PPC: ' +
|
||||
show(m.limited) +
|
||||
';obrigação total: ' +
|
||||
';total estimado: ' +
|
||||
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.plan ? '. Plano explícito apresentado separadamente;prazo legal não validado.' : '. 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 +
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import {
|
||||
decimalFraction,
|
||||
addFractions,
|
||||
subtractFractions,
|
||||
fractionPresentation,
|
||||
type FiscalFraction,
|
||||
} from './fiscal-rational.ts';
|
||||
export const pecPlanVersion = 'IRPC-PEC-plan/1';
|
||||
export const pecPlanSource =
|
||||
'RIRPC29(1):mesesJunho/Agosto/Outubro e opção de pagamento único. Montantes repartidos e mês único são hipótese explícita do utilizador,sem regra de igualdade,arredondamento,guia ou prazo legal presumidos. Conferência de prazo da opção única permanece separada.';
|
||||
export type PecPlan = {
|
||||
version: 1;
|
||||
mode: '' | 'three' | 'single';
|
||||
reference: string;
|
||||
singleMonth: string;
|
||||
june: string;
|
||||
august: string;
|
||||
october: string;
|
||||
};
|
||||
export const newPecPlan = (): PecPlan => ({
|
||||
version: 1,
|
||||
mode: '',
|
||||
reference: '',
|
||||
singleMonth: '',
|
||||
june: '',
|
||||
august: '',
|
||||
october: '',
|
||||
});
|
||||
export function validatePecPlan(p: PecPlan) {
|
||||
if (
|
||||
!p ||
|
||||
p.version !== 1 ||
|
||||
Object.keys(newPecPlan())
|
||||
.filter((k) => k !== 'version')
|
||||
.some(
|
||||
(k) =>
|
||||
typeof (p as unknown as Record<string, unknown>)[k] !==
|
||||
'string',
|
||||
) ||
|
||||
!['', 'three', 'single'].includes(p.mode)
|
||||
)
|
||||
throw Error('Projecção PEC não recuperável;original preservado.');
|
||||
}
|
||||
export function calculatePecPlan(
|
||||
p: PecPlan,
|
||||
total: FiscalFraction | null,
|
||||
notApplicable: boolean,
|
||||
year: string,
|
||||
) {
|
||||
validatePecPlan(p);
|
||||
const pending: string[] = [];
|
||||
let rows: Array<{ month: string; amount: FiscalFraction }> = [];
|
||||
if (!total)
|
||||
pending.push(
|
||||
'Projecção PEC:total estimado indeterminada;reconciliar a base antes de preparar os montantes.',
|
||||
);
|
||||
else if (notApplicable || BigInt(total.numerator) === 0n)
|
||||
pending.push(
|
||||
'Projecção PEC:sem estimativa positiva,não se distribuem saídas de caixa.',
|
||||
);
|
||||
if (year !== '2026')
|
||||
pending.push('Projecção PEC:exercício fora do recorte2026.');
|
||||
if (!p.reference.trim())
|
||||
pending.push(
|
||||
'Projecção PEC:identifique o fundamento da opção e dos montantes preparados.',
|
||||
);
|
||||
if (!['three', 'single'].includes(p.mode))
|
||||
pending.push(
|
||||
'Projecção PEC:escolha três prestações ou pagamento único.',
|
||||
);
|
||||
if (!pending.length && total) {
|
||||
if (p.mode === 'three') {
|
||||
const values = [p.june, p.august, p.october];
|
||||
if (!values.every((v) => /^\d{1,18}(\.\d{1,2})?$/.test(v)))
|
||||
pending.push(
|
||||
'Projecção PEC:preencha os três montantes em MZN,com até dois decimais;sem preenchimento automático.',
|
||||
);
|
||||
else {
|
||||
const amounts = values.map(decimalFraction);
|
||||
if (amounts.some((v) => BigInt(v.numerator) <= 0n))
|
||||
pending.push(
|
||||
'Projecção PEC:três prestações exigem três montantes positivos.',
|
||||
);
|
||||
else if (
|
||||
BigInt(
|
||||
subtractFractions(addFractions(amounts), total)
|
||||
.numerator,
|
||||
) !== 0n
|
||||
)
|
||||
pending.push(
|
||||
'Projecção PEC:a soma das três prestações difere do total preparado;sem arredondamento ou compensação silenciosos.',
|
||||
);
|
||||
else
|
||||
rows = amounts.map((amount, i) => ({
|
||||
month: ['2026-06', '2026-08', '2026-10'][i],
|
||||
amount,
|
||||
}));
|
||||
}
|
||||
} else if (!/^2026-(0[1-9]|1[0-2])$/.test(p.singleMonth))
|
||||
pending.push(
|
||||
'Projecção PEC:indique o mês previsto do pagamento único;isto não valida o prazo legal.',
|
||||
);
|
||||
else rows = [{ month: p.singleMonth, amount: total }];
|
||||
}
|
||||
return {
|
||||
version: pecPlanVersion,
|
||||
source: pecPlanSource,
|
||||
mode: p.mode,
|
||||
pending,
|
||||
rows,
|
||||
total,
|
||||
allocationReconciled: pending.length === 0,
|
||||
legalDeadlineValidated: false,
|
||||
paymentExecuted: false,
|
||||
annualDeductionCreated: false,
|
||||
};
|
||||
}
|
||||
export function pecPlanReport(
|
||||
p: PecPlan,
|
||||
total: FiscalFraction | null,
|
||||
notApplicable: boolean,
|
||||
year: string,
|
||||
): Array<[string, string, string, string]> {
|
||||
const m = calculatePecPlan(p, total, notApplicable, year);
|
||||
return [
|
||||
[
|
||||
'IRPC — L8',
|
||||
'PEC — projecção de tesouraria',
|
||||
m.pending.length
|
||||
? m.pending.join(' ')
|
||||
: (m.mode === 'single'
|
||||
? 'Saída de caixa concentrada (hipótese): '
|
||||
: 'Distribuição de caixa (hipótese): ') +
|
||||
m.rows
|
||||
.map(
|
||||
(r) =>
|
||||
r.month +
|
||||
': ' +
|
||||
fractionPresentation(r.amount).decimal +
|
||||
' MZN',
|
||||
)
|
||||
.join('; ') +
|
||||
'. Soma reconciliada;prazo legal não validado. Não é pagamento ou dedução.',
|
||||
p.reference + '; ' + m.source,
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -142,7 +142,7 @@ export function ppcObligationReport(
|
||||
return [
|
||||
[
|
||||
'IRPC — L8',
|
||||
'PPC — obrigação preparada',
|
||||
'PPC — estimativa fiscal',
|
||||
m.pending.length
|
||||
? m.pending.join(' ')
|
||||
: 'Base líquida anterior: ' +
|
||||
|
||||
Reference in New Issue
Block a user