This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
import { useState } from 'react';
|
||||
import { annualBook } from '@/lib/irpc-annual-settlement';
|
||||
import type { NormalBook } from '@/lib/irpc-normal';
|
||||
import {
|
||||
prepareEconomicInclusion,
|
||||
calculateEconomicInclusions,
|
||||
economicInclusionMoney,
|
||||
} from '@/lib/irpc-normal-economic';
|
||||
|
||||
export function SimulationIrpcEconomicInclusion({
|
||||
draft,
|
||||
book,
|
||||
save,
|
||||
}: {
|
||||
draft: Record<string, unknown>;
|
||||
book: NormalBook;
|
||||
save: (b: NormalBook) => void;
|
||||
}) {
|
||||
const [selected, setSelected] = useState('');
|
||||
const [profit, setProfit] = useState('');
|
||||
const [credit, setCredit] = useState('');
|
||||
const [reference, setReference] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [preview, setPreview] = useState<{
|
||||
fingerprint: string;
|
||||
book: NormalBook;
|
||||
net: string;
|
||||
} | null>(null);
|
||||
const sources = annualBook(draft)?.economicCredits?.rows ?? [];
|
||||
if (!sources.length) return null;
|
||||
const fingerprint = JSON.stringify([
|
||||
book,
|
||||
sources,
|
||||
selected,
|
||||
profit,
|
||||
credit,
|
||||
reference,
|
||||
]);
|
||||
return (
|
||||
<section
|
||||
className="space-y-3 rounded border p-3"
|
||||
aria-label="Incluir ou corrigir lucros e crédito económico em L6"
|
||||
>
|
||||
<h3 className="font-semibold">
|
||||
Incluir ou corrigir lucros e crédito económico em L6
|
||||
</h3>
|
||||
<p>
|
||||
Escolha a origem preparada em L8. Indique os montantes já
|
||||
considerados na contabilidade e noutros ajustamentos, antes
|
||||
deste mapa; zero deve ser indicado expressamente. A prévia
|
||||
propõe apenas a diferença e conserva o resultado anterior.
|
||||
Depois de confirmar, calcule e guarde L6 pelo percurso
|
||||
existente; L8 exige nova conferência da colecta.
|
||||
</p>
|
||||
<label className="block">
|
||||
Origem dos lucros
|
||||
<select
|
||||
value={selected}
|
||||
onChange={(e) => setSelected(e.target.value)}
|
||||
>
|
||||
<option value="">Escolha a origem</option>
|
||||
{sources.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
{r.distributionDocument} — {r.distributionParcel}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
Rendimentos já considerados — MZN (incluindo eventual mais-valia
|
||||
da partilha)
|
||||
<input
|
||||
value={profit}
|
||||
onChange={(e) => setProfit(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="block">
|
||||
Crédito nominal já acrescido — MZN
|
||||
<input
|
||||
value={credit}
|
||||
onChange={(e) => setCredit(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="block">
|
||||
Suporte da reconciliação
|
||||
<textarea
|
||||
value={reference}
|
||||
onChange={(e) => setReference(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
try {
|
||||
const source = sources.find((r) => r.id === selected);
|
||||
if (!source)
|
||||
throw Error('Escolha explicitamente uma origem.');
|
||||
const next = prepareEconomicInclusion(book, {
|
||||
source,
|
||||
profitAlreadyIncluded: profit,
|
||||
creditAlreadyIncluded: credit,
|
||||
reference,
|
||||
});
|
||||
const model = calculateEconomicInclusions(
|
||||
next.economicInclusions!,
|
||||
next.base!.subjectNuit,
|
||||
next.year,
|
||||
);
|
||||
setPreview({
|
||||
fingerprint,
|
||||
book: next,
|
||||
net: economicInclusionMoney(model.net),
|
||||
});
|
||||
setError('');
|
||||
} catch (e) {
|
||||
setPreview(null);
|
||||
setError(String(e));
|
||||
}
|
||||
}}
|
||||
>
|
||||
Pré-visualizar inclusão/correcção
|
||||
</button>
|
||||
{preview && preview.fingerprint === fingerprint && (
|
||||
<div className="space-y-2 rounded border p-3">
|
||||
<p>
|
||||
Efeito total deste mapa no lucro tributável:{' '}
|
||||
{preview.net} MZN. Substitui as parcelas da mesma
|
||||
origem, sem as acumular.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (preview.fingerprint !== fingerprint) return;
|
||||
save(preview.book);
|
||||
setPreview(null);
|
||||
}}
|
||||
>
|
||||
Confirmar preparação em L6
|
||||
</button>
|
||||
<button type="button" onClick={() => setPreview(null)}>
|
||||
Cancelar prévia
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -110,7 +110,10 @@ export function SimulationIrpcEconomic({
|
||||
rowChange({ ...r, ...v });
|
||||
const prefix = 'Crédito económico ' + (i + 1) + ' — ';
|
||||
const field = (
|
||||
key: Exclude<keyof EconomicPosition, 'previousUse'>,
|
||||
key: Exclude<
|
||||
keyof EconomicPosition,
|
||||
'previousUse' | 'liquidation' | 'association'
|
||||
>,
|
||||
label: string,
|
||||
) => (
|
||||
<label key={key} className="block">
|
||||
@@ -145,9 +148,7 @@ export function SimulationIrpcEconomic({
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
const outside =
|
||||
(!!r.kind && r.kind !== 'ordinary_profit') ||
|
||||
r.article40 === 'yes';
|
||||
const outside = r.article40 === 'yes';
|
||||
const detail = (
|
||||
<>
|
||||
{(
|
||||
@@ -226,7 +227,60 @@ export function SimulationIrpcEconomic({
|
||||
'Suporte da quota proporcional da colecta',
|
||||
],
|
||||
] as const
|
||||
).map(([key, label]) => field(key, label))}
|
||||
)
|
||||
.filter(
|
||||
([key]) =>
|
||||
r.nationalMethod !== 'proportional' ||
|
||||
(key !== 'nationalLimit' &&
|
||||
key !== 'nationalLimitReference'),
|
||||
)
|
||||
.map(([key, label]) => field(key, label))}
|
||||
<label className="block">
|
||||
Quota proporcional
|
||||
<select
|
||||
aria-label={prefix + 'Método da quota'}
|
||||
value={r.nationalMethod ?? 'documented'}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
nationalMethod: e.target
|
||||
.value as EconomicPosition['nationalMethod'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="documented">
|
||||
Limite documentado
|
||||
</option>
|
||||
<option value="proportional">
|
||||
Derivar da colecta L6 ordinária
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{r.nationalMethod === 'proportional' && (
|
||||
<label className="block">
|
||||
Correspondência dos lucros mais acréscimo53 na
|
||||
base corrente
|
||||
<textarea
|
||||
aria-label={
|
||||
prefix + 'Correspondência da quota'
|
||||
}
|
||||
value={r.nationalBasisReference ?? ''}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
nationalBasisReference:
|
||||
e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="block">
|
||||
Quota = colecta L6 × (lucros incluídos +
|
||||
crédito nominal acrescido) / matéria
|
||||
colectável L6. Não altera a base nem
|
||||
acrescenta o crédito novamente. O limite
|
||||
manual anterior fica conservado, mas não é
|
||||
usado neste modo.
|
||||
</span>
|
||||
</label>
|
||||
)}
|
||||
{choice(
|
||||
'incomeIncluded',
|
||||
'Lucros ilíquidos e acréscimo incluídos na base corrente',
|
||||
@@ -339,6 +393,155 @@ export function SimulationIrpcEconomic({
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{r.kind === 'association' && (
|
||||
<fieldset className="space-y-2 rounded border p-3">
|
||||
<legend>Associação — art.64(4)</legend>
|
||||
<label className="block">
|
||||
Modalidade
|
||||
<select
|
||||
aria-label={
|
||||
prefix + 'Modalidade da associação'
|
||||
}
|
||||
value={r.association?.kind ?? ''}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
association: {
|
||||
kind: e.target.value as
|
||||
| ''
|
||||
| 'participation'
|
||||
| 'quota',
|
||||
effectivelyTaxed:
|
||||
r.association
|
||||
?.effectivelyTaxed ??
|
||||
'',
|
||||
reference:
|
||||
r.association
|
||||
?.reference ?? '',
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Escolha a modalidade
|
||||
</option>
|
||||
<option value="participation">
|
||||
Em participação
|
||||
</option>
|
||||
<option value="quota">À quota</option>
|
||||
</select>
|
||||
</label>
|
||||
{r.association?.kind === 'participation' && (
|
||||
<label className="block">
|
||||
Rendimentos distribuídos efectivamente
|
||||
tributados
|
||||
<select
|
||||
aria-label={
|
||||
prefix +
|
||||
'Tributação efectiva da participação'
|
||||
}
|
||||
value={
|
||||
r.association.effectivelyTaxed
|
||||
}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
association: {
|
||||
...r.association!,
|
||||
effectivelyTaxed: e
|
||||
.target.value as
|
||||
| ''
|
||||
| 'yes'
|
||||
| 'no',
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Informação em falta
|
||||
</option>
|
||||
<option value="yes">
|
||||
Sim — documentado
|
||||
</option>
|
||||
<option value="no">
|
||||
Não — documentado
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
<label className="block">
|
||||
Suporte do contrato, rendimentos e adaptação
|
||||
do crédito
|
||||
<input
|
||||
aria-label={
|
||||
prefix + 'Suporte da associação'
|
||||
}
|
||||
value={r.association?.reference ?? ''}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
association: {
|
||||
kind: '',
|
||||
effectivelyTaxed: '',
|
||||
...r.association,
|
||||
reference: e.target.value,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</fieldset>
|
||||
)}
|
||||
{r.kind === 'liquidation' && (
|
||||
<fieldset className="space-y-2 rounded border p-3">
|
||||
<legend>
|
||||
Partilha em liquidação — art.64(3)
|
||||
</legend>
|
||||
<p>
|
||||
No rendimento abaixo indique a diferença
|
||||
positiva classificada documentalmente como
|
||||
aplicação de capitais. O crédito limita-se
|
||||
também ao valor atribuído menos entradas
|
||||
efectivas para capital. O excesso mantém
|
||||
tratamento próprio de mais-valia; não
|
||||
integra a quota económica. Confirme a
|
||||
inclusão L6 e o IRPC correspondente apenas à
|
||||
parcela elegível.
|
||||
</p>
|
||||
{(
|
||||
[
|
||||
[
|
||||
'attributed',
|
||||
'Valor atribuído na partilha — MZN',
|
||||
],
|
||||
[
|
||||
'paidInCapital',
|
||||
'Entradas efectivas para capital na contabilidade da liquidada — MZN',
|
||||
],
|
||||
[
|
||||
'reference',
|
||||
'Suporte da partilha e classificação do rendimento',
|
||||
],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<label key={key} className="block">
|
||||
{label}
|
||||
<input
|
||||
aria-label={prefix + label}
|
||||
value={r.liquidation?.[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
liquidation: {
|
||||
attributed: '',
|
||||
paidInCapital: '',
|
||||
reference: '',
|
||||
...r.liquidation,
|
||||
[key]: e.target.value,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
{residentConfirmed && r.recipientResident === 'yes' ? (
|
||||
<p>
|
||||
Residência do beneficiário reutilizada da
|
||||
|
||||
@@ -4,6 +4,7 @@ import { SimulationIrpcPeriodFx } from '@/components/simulation-irpc-period-fx';
|
||||
import { SimulationIrpcDepreciation } from '@/components/simulation-irpc-depreciation';
|
||||
import { SimulationIrpcCosts } from '@/components/simulation-irpc-costs';
|
||||
import { SimulationIrpcSchedules } from '@/components/simulation-irpc-schedules';
|
||||
import { SimulationIrpcEconomicInclusion } from '@/components/simulation-irpc-economic-inclusion';
|
||||
import { SimulationIrpcAssessment } from '@/components/simulation-irpc-assessment';
|
||||
import { useState } from 'react';
|
||||
import { SimulationIrpcTaxableBase } from '@/components/simulation-irpc-taxable-base';
|
||||
@@ -438,6 +439,16 @@ export function SimulationIrpcNormal({
|
||||
)}
|
||||
<SimulationIrpcPeriodFx draft={draft} book={b} save={save} />
|
||||
<SimulationIrpcSchedules book={b} save={save} />
|
||||
<SimulationIrpcEconomicInclusion
|
||||
key={JSON.stringify([
|
||||
draft.context_opportunity,
|
||||
b.base?.subjectNuit,
|
||||
b.year,
|
||||
])}
|
||||
draft={draft}
|
||||
book={b}
|
||||
save={save}
|
||||
/>
|
||||
<SimulationIrpcDepreciation
|
||||
draft={draft}
|
||||
book={b}
|
||||
|
||||
Reference in New Issue
Block a user