feat(portal): deliver ordinary national credit fraction and education continuity
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -116,6 +116,15 @@ export function SimulationIrpcInternational({
|
||||
<fieldset className="space-y-3 rounded border p-3">
|
||||
<legend>Crédito por dupla tributação internacional</legend>
|
||||
<p>{internationalCreditSource}</p>
|
||||
{c.positions.some((p) => p.nationalMethod === 'proportional') && (
|
||||
<p>
|
||||
No modo de derivação ordinária abaixo, o portal calcula a
|
||||
fracção nacional a partir da colecta e matéria colectável L6
|
||||
correntes e da parcela líquida correspondida. Mantêm-se as
|
||||
restantes condições e limites do modo documentado; não
|
||||
determina a convenção aplicável.
|
||||
</p>
|
||||
)}
|
||||
<p>
|
||||
Reúna os comprovativos de cada país numa posição por exercício.
|
||||
Indique a fracção nacional e a convenção conforme o suporte do
|
||||
@@ -220,6 +229,59 @@ export function SimulationIrpcInternational({
|
||||
onChange={(country) => patch({ country })}
|
||||
allowLegacyValue
|
||||
/>
|
||||
<label className="block">
|
||||
Fracção nacional
|
||||
<select
|
||||
aria-label={
|
||||
'Internacional ' +
|
||||
(index + 1) +
|
||||
' — Método da fracção nacional'
|
||||
}
|
||||
value={p.nationalMethod ?? 'documented'}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
nationalMethod: e.target
|
||||
.value as InternationalPosition['nationalMethod'],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="documented">
|
||||
Limite documentado
|
||||
</option>
|
||||
<option value="proportional">
|
||||
Derivar da colecta L6 ordinária
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{p.nationalMethod === 'proportional' && (
|
||||
<label className="block">
|
||||
Correspondência da parcela líquida estrangeira
|
||||
<textarea
|
||||
aria-label={
|
||||
'Internacional ' +
|
||||
(index + 1) +
|
||||
' — Correspondência da parcela líquida'
|
||||
}
|
||||
value={p.nationalBasisReference ?? ''}
|
||||
onChange={(e) =>
|
||||
patch({
|
||||
nationalBasisReference:
|
||||
e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="block">
|
||||
Indique abaixo a parcela líquida já incluída
|
||||
na matéria colectável, após os custos,
|
||||
perdas e deduções correspondentes. A fracção
|
||||
será colecta L6 × parcela líquida / matéria
|
||||
colectável L6, antes de créditos. O portal
|
||||
não reparte custos ou perdas nem determina
|
||||
convenções. O limite manual anterior é
|
||||
conservado, mas não usado neste modo.
|
||||
</span>
|
||||
</label>
|
||||
)}
|
||||
{(
|
||||
[
|
||||
['subjectNuit', 'NUIT titular'],
|
||||
@@ -238,23 +300,33 @@ export function SimulationIrpcInternational({
|
||||
'Suporte da fracção nacional e exercício',
|
||||
],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<label key={key} className="block">
|
||||
{label}
|
||||
<input
|
||||
aria-label={
|
||||
'Internacional ' +
|
||||
(index + 1) +
|
||||
' — ' +
|
||||
label
|
||||
}
|
||||
value={p[key]}
|
||||
onChange={(e) =>
|
||||
patch({ [key]: e.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
)
|
||||
.filter(
|
||||
([key]) =>
|
||||
p.nationalMethod !== 'proportional' ||
|
||||
(key !== 'nationalLimit' &&
|
||||
key !== 'nationalLimitReference'),
|
||||
)
|
||||
.map(([key, label]) => (
|
||||
<label key={key} className="block">
|
||||
{key === 'incomeAmount' &&
|
||||
p.nationalMethod === 'proportional'
|
||||
? 'Parcela líquida estrangeira incluída — MZN'
|
||||
: label}
|
||||
<input
|
||||
aria-label={
|
||||
'Internacional ' +
|
||||
(index + 1) +
|
||||
' — ' +
|
||||
label
|
||||
}
|
||||
value={p[key]}
|
||||
onChange={(e) =>
|
||||
patch({ [key]: e.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<label className="block">
|
||||
Rendimento incluído na matéria colectável
|
||||
<select
|
||||
|
||||
@@ -1154,12 +1154,28 @@ export function calculateAnnual(d: Record<string, unknown>, b: AnnualBook) {
|
||||
b.subjectNuit,
|
||||
b.year,
|
||||
b.assessmentKey,
|
||||
{
|
||||
ordinary:
|
||||
assessment?.kind === 'normal' &&
|
||||
assessment.current &&
|
||||
assessment.key === b.assessmentKey,
|
||||
taxableBase: assessment?.record?.model.taxableBase ?? null,
|
||||
colecta: assessment?.colecta ?? null,
|
||||
},
|
||||
);
|
||||
pending.push(
|
||||
...m.pending.map((e) => 'País ' + p.country + ': ' + e),
|
||||
);
|
||||
return m;
|
||||
}) ?? [];
|
||||
const derivedNational = positions.flatMap((p) =>
|
||||
p.nationalDerivation ? [p.nationalDerivation.income] : [],
|
||||
);
|
||||
const currentBase = assessment?.record?.model.taxableBase;
|
||||
if (currentBase && cmp(addFractions(derivedNational), currentBase) > 0n)
|
||||
pending.push(
|
||||
'As parcelas estrangeiras com fracção derivada excedem em conjunto a matéria colectável corrente; reconcilie a afectação por país.',
|
||||
);
|
||||
const economicRows =
|
||||
b.economicCredits?.rows.map((r) => {
|
||||
const issues = claims
|
||||
@@ -1384,7 +1400,9 @@ export function calculateAnnual(d: Record<string, unknown>, b: AnnualBook) {
|
||||
: []),
|
||||
...(b.internationalCredits
|
||||
? [
|
||||
'Crédito internacional do próprio exercício:fracção nacional,convenção e montantes MZN são documentados;sem cálculo presumido,transporte ou consumo oficial. ' +
|
||||
(positions.some((p) => p.nationalDerivation)
|
||||
? 'Crédito internacional do próprio exercício:fracção nacional derivada no caso L6 ordinário com parcela líquida correspondida;CDT e montantes MZN documentados;sem repartição presumida de custos/perdas,transporte ou consumo oficial. '
|
||||
: 'Crédito internacional do próprio exercício:fracção nacional,convenção e montantes MZN são documentados;sem cálculo presumido,transporte ou consumo oficial. ') +
|
||||
(b.economicCredits
|
||||
? 'Benefícios positivos ficam separados;crédito económico no detalhe próprio.'
|
||||
: 'Créditos económicos/benefícios positivos ficam separados.'),
|
||||
@@ -1630,6 +1648,21 @@ export function annualReportRows(
|
||||
show(p.paid) +
|
||||
'; fracção nacional: ' +
|
||||
show(p.nationalLimit) +
|
||||
(p.nationalDerivation
|
||||
? '; derivação L6: colecta ' +
|
||||
show(p.nationalDerivation.colecta) +
|
||||
' × parcela líquida ' +
|
||||
show(p.nationalDerivation.income) +
|
||||
' / matéria colectável ' +
|
||||
show(
|
||||
p.nationalDerivation
|
||||
.taxableBase,
|
||||
) +
|
||||
'; exacta ' +
|
||||
p.nationalLimit?.numerator +
|
||||
'/' +
|
||||
p.nationalLimit?.denominator
|
||||
: '; limite documentado') +
|
||||
'; limite CDT: ' +
|
||||
(p.input.treaty === 'no'
|
||||
? 'Não aplicável documentado'
|
||||
@@ -1646,7 +1679,15 @@ export function annualReportRows(
|
||||
p.pending.join(' | '),
|
||||
p.input.incomeReference +
|
||||
'; ' +
|
||||
p.input.nationalLimitReference +
|
||||
(p.nationalDerivation
|
||||
? 'Limite manual anterior conservado, não utilizado nesta derivação'
|
||||
: p.input.nationalLimitReference) +
|
||||
(p.nationalDerivation
|
||||
? '; correspondência: ' +
|
||||
p.nationalDerivation.reference +
|
||||
'; ' +
|
||||
p.nationalDerivation.version
|
||||
: '') +
|
||||
'; ' +
|
||||
p.input.treatyReference +
|
||||
'; ' +
|
||||
|
||||
@@ -38,6 +38,8 @@ export type InternationalPosition = {
|
||||
incomeReference: string;
|
||||
nationalLimit: string;
|
||||
nationalLimitReference: string;
|
||||
nationalMethod?: 'documented' | 'proportional';
|
||||
nationalBasisReference?: string;
|
||||
treaty: '' | 'yes' | 'no';
|
||||
treatyLimit: string;
|
||||
treatyReference: string;
|
||||
@@ -149,6 +151,10 @@ export function validateInternational(c: InternationalCredits) {
|
||||
) ||
|
||||
!yesNo.includes(p.incomeIncluded) ||
|
||||
!yesNo.includes(p.treaty) ||
|
||||
(p.nationalMethod !== undefined &&
|
||||
!['documented', 'proportional'].includes(p.nationalMethod)) ||
|
||||
(p.nationalBasisReference !== undefined &&
|
||||
typeof p.nationalBasisReference !== 'string') ||
|
||||
!evidenceValid(p.previousUse) ||
|
||||
!Array.isArray(p.payments)
|
||||
)
|
||||
@@ -278,6 +284,11 @@ export function internationalPosition(
|
||||
subjectNuit: string,
|
||||
year: string,
|
||||
assessmentKey: string,
|
||||
nationalBasis?: {
|
||||
ordinary: boolean;
|
||||
taxableBase: FiscalFraction | null;
|
||||
colecta: FiscalFraction | null;
|
||||
},
|
||||
) {
|
||||
const pending = [...proofIssues];
|
||||
let nationalLimit: FiscalFraction | null = null,
|
||||
@@ -286,6 +297,13 @@ export function internationalPosition(
|
||||
eligible: FiscalFraction | null = null,
|
||||
available: FiscalFraction | null = null,
|
||||
aboveLimit: FiscalFraction | null = null;
|
||||
let nationalDerivation: {
|
||||
version: string;
|
||||
income: FiscalFraction;
|
||||
taxableBase: FiscalFraction;
|
||||
colecta: FiscalFraction;
|
||||
reference: string;
|
||||
} | null = null;
|
||||
try {
|
||||
if (
|
||||
!p.id.trim() ||
|
||||
@@ -311,8 +329,46 @@ export function internationalPosition(
|
||||
'Falta inclusão documentada do rendimento estrangeiro na matéria colectável.',
|
||||
);
|
||||
const income = creditMoney(p.incomeAmount);
|
||||
nationalLimit = creditLimit(p.nationalLimit);
|
||||
if (!p.nationalLimitReference.trim())
|
||||
if (p.nationalMethod === 'proportional') {
|
||||
const basis = nationalBasis;
|
||||
if (
|
||||
!basis?.ordinary ||
|
||||
!basis.taxableBase ||
|
||||
!basis.colecta ||
|
||||
creditCompare(basis.taxableBase, zero()) <= 0n ||
|
||||
creditCompare(basis.colecta, zero()) < 0n
|
||||
)
|
||||
throw Error(
|
||||
'Derivação da fracção nacional exige matéria colectável positiva e colecta L6 ordinária corrente; efeitos L7 e casos especiais conservam correspondência própria.',
|
||||
);
|
||||
if (!p.nationalBasisReference?.trim())
|
||||
throw Error(
|
||||
'Identifique a correspondência da parcela líquida estrangeira na matéria colectável, incluindo custos/perdas/deduções aplicáveis; o portal não reparte esses valores por presunção.',
|
||||
);
|
||||
if (creditCompare(income, basis.taxableBase) > 0n)
|
||||
throw Error(
|
||||
'Parcela estrangeira excede a matéria colectável corrente; reconcilie custos, perdas e deduções antes de derivar a fracção.',
|
||||
);
|
||||
nationalLimit = fraction(
|
||||
BigInt(basis.colecta.numerator) *
|
||||
BigInt(income.numerator) *
|
||||
BigInt(basis.taxableBase.denominator),
|
||||
BigInt(basis.colecta.denominator) *
|
||||
BigInt(income.denominator) *
|
||||
BigInt(basis.taxableBase.numerator),
|
||||
);
|
||||
nationalDerivation = {
|
||||
version: 'IRPC-national-fraction/1',
|
||||
income,
|
||||
taxableBase: structuredClone(basis.taxableBase),
|
||||
colecta: structuredClone(basis.colecta),
|
||||
reference: p.nationalBasisReference,
|
||||
};
|
||||
} else nationalLimit = creditLimit(p.nationalLimit);
|
||||
if (
|
||||
p.nationalMethod !== 'proportional' &&
|
||||
!p.nationalLimitReference.trim()
|
||||
)
|
||||
throw Error(
|
||||
'Fracção nacional exige suporte próprio; não é calculada nem presumida pelo portal.',
|
||||
);
|
||||
@@ -363,6 +419,7 @@ export function internationalPosition(
|
||||
country: p.country,
|
||||
paid,
|
||||
nationalLimit,
|
||||
...(nationalDerivation ? { nationalDerivation } : {}),
|
||||
treatyLimit,
|
||||
previousUse,
|
||||
eligible,
|
||||
@@ -403,7 +460,11 @@ export function internationalDeduction(
|
||||
: null,
|
||||
}
|
||||
: {}),
|
||||
source: internationalCreditSource,
|
||||
source:
|
||||
internationalCreditSource +
|
||||
(positions.some((p) => p.nationalDerivation)
|
||||
? ' Modo IRPC-national-fraction/1: no caso L6 ordinário corrente com parcela líquida documentada e correspondida, fracção = colecta antes de créditos × parcela líquida estrangeira / matéria colectável. Não efectua repartição de custos/perdas ou qualificação automática de CDT.'
|
||||
: ''),
|
||||
countryAllocationCreated: false,
|
||||
carryCreated: false,
|
||||
officialBalancesConsumed: false,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Link } from '@inertiajs/react';
|
||||
import EducationReview from '@/components/education-review';
|
||||
import type { EducationReviewProps } from '@/lib/education-review';
|
||||
import { Management, Pagination } from '../management/shared';
|
||||
import { Management } from '../management/shared';
|
||||
import type { Paginated } from '../management/shared';
|
||||
|
||||
type ReviewEntry = {
|
||||
@@ -146,7 +146,36 @@ export default function Declaration(
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
<Pagination page={props.history} />
|
||||
<nav
|
||||
aria-label="Paginação do histórico de revisão"
|
||||
className="flex flex-wrap items-center gap-4"
|
||||
>
|
||||
{props.history.prev_page_url && (
|
||||
<Link
|
||||
className="rounded border p-2"
|
||||
href={props.history.prev_page_url}
|
||||
preserveState
|
||||
preserveScroll
|
||||
>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
<span>
|
||||
{props.history.total} registos · Página{' '}
|
||||
{props.history.current_page} de{' '}
|
||||
{props.history.last_page}
|
||||
</span>
|
||||
{props.history.next_page_url && (
|
||||
<Link
|
||||
className="rounded border p-2"
|
||||
href={props.history.next_page_url}
|
||||
preserveState
|
||||
preserveScroll
|
||||
>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</section>
|
||||
)}
|
||||
</Management>
|
||||
|
||||
Reference in New Issue
Block a user