@@ -1,7 +1,9 @@
|
||||
import { controlClass } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { estimateMoney } from '@/lib/import-estimate-money';
|
||||
import { money } from '@/types/procurement';
|
||||
import {
|
||||
specificRateLabel,
|
||||
specificRateMoney,
|
||||
} from '@/lib/import-legal-specific-rate';
|
||||
|
||||
export type LegalCharge = {
|
||||
key: string;
|
||||
@@ -9,7 +11,7 @@ export type LegalCharge = {
|
||||
label: string;
|
||||
method: string;
|
||||
rate_percent: string | null;
|
||||
specific_minor: number | null;
|
||||
specific_minor: number | string | null;
|
||||
quantity_unit: string | null;
|
||||
basis_reference: string;
|
||||
};
|
||||
@@ -30,7 +32,7 @@ export const chargeDrafts = (charges: LegalCharge[]) =>
|
||||
label: charge.label,
|
||||
method: charge.method,
|
||||
rate_percent: charge.rate_percent ?? '',
|
||||
specific_amount: estimateMoney(charge.specific_minor),
|
||||
specific_amount: specificRateMoney(charge.specific_minor),
|
||||
quantity_unit: charge.quantity_unit ?? '',
|
||||
basis_reference: charge.basis_reference,
|
||||
}));
|
||||
@@ -55,7 +57,8 @@ export function LegalChargeSummary({ charges }: { charges: LegalCharge[] }) {
|
||||
)}
|
||||
{charge.specific_minor !== null && (
|
||||
<dd>
|
||||
Taxa específica: {money(charge.specific_minor)} por{' '}
|
||||
Taxa específica:{' '}
|
||||
{specificRateLabel(charge.specific_minor)} por{' '}
|
||||
{charge.quantity_unit}
|
||||
</dd>
|
||||
)}
|
||||
@@ -181,6 +184,11 @@ export default function LegalChargeFields({
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Até oito casas decimais. A taxa é
|
||||
preservada; apenas o montante calculado é
|
||||
arredondado a cêntimos.
|
||||
</span>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Unidade da taxa específica
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/** Exact documentary coefficients; monetary amounts keep their existing cent precision. */
|
||||
export const specificRateMinor = (value: string): number | string | null => {
|
||||
if (!/^\d{1,13}(?:[.,]\d{1,8})?$/.test(value)) return null;
|
||||
const [whole, fraction = ''] = value.replace(',', '.').split('.');
|
||||
const digits = BigInt(whole + fraction.padEnd(2, '0')).toString();
|
||||
const scale = Math.max(fraction.length - 2, 0);
|
||||
if (scale === 0) return Number(digits);
|
||||
const padded = digits.padStart(scale + 1, '0');
|
||||
const decimals = padded.slice(-scale).replace(/0+$/, '');
|
||||
return decimals
|
||||
? `${padded.slice(0, -scale)}.${decimals}`
|
||||
: Number(padded.slice(0, -scale));
|
||||
};
|
||||
|
||||
export const specificRateMoney = (value: number | string | null): string => {
|
||||
if (value === null) return '';
|
||||
const raw = String(value);
|
||||
if (!/^\d{1,15}(?:\.\d{1,6})?$/.test(raw)) return '';
|
||||
const [whole, fraction = ''] = raw.split('.');
|
||||
const scale = fraction.length + 2;
|
||||
const digits = BigInt(whole + fraction)
|
||||
.toString()
|
||||
.padStart(scale + 1, '0');
|
||||
const decimals = digits.slice(-scale).replace(/0+$/, '').padEnd(2, '0');
|
||||
return `${digits.slice(0, -scale)}.${decimals}`;
|
||||
};
|
||||
|
||||
export const specificRateLabel = (value: number | string | null): string => {
|
||||
const amount = specificRateMoney(value);
|
||||
return amount === '' ? 'Por determinar' : `${amount.replace('.', ',')} MZN`;
|
||||
};
|
||||
@@ -242,10 +242,12 @@ export const journeyHelp: JourneyHelp[] = [
|
||||
'Indique o contexto e a data. Sem correspondência publicada, a regra permanece por determinar.',
|
||||
'Seleccione o artigo e prepare uma proposta com a fonte escolhida; confirme ou justifique o desvio na classificação pautal.',
|
||||
'A área aduaneira conserva exemplar, diploma, citação e vigência antes de validar e publicar a preparação.',
|
||||
'Quando o exemplar conferido tem propostas documentais disponíveis, escolha deliberadamente o código para preencher uma preparação editável. Conclua ou limpe primeiro uma preparação já preenchida.',
|
||||
'Uma revisão conserva a publicação anterior até nova validação. A retirada impede novas sugestões.',
|
||||
],
|
||||
[
|
||||
'Publicar uma fonte não activa cálculos, isenções, pagamentos ou submissões JUE.',
|
||||
'As propostas do anexo da Lei 8/2025, páginas 2180-(4) a (7), transcrevem apenas as taxas gerais dessa edição, com início em 01/01/2026. Não consolidam alterações posteriores nem determinam preferências, isenções, ICE ou IVA.',
|
||||
'Uma mudança da regra sinaliza a decisão anterior, conservando a fonte e o histórico aplicados.',
|
||||
],
|
||||
'Se a regra mudou ou o exemplar divergiu, preserve a preparação e seleccione uma fonte actual antes da confirmação.',
|
||||
|
||||
@@ -477,8 +477,8 @@ export default function Show({
|
||||
</ActionBar>
|
||||
</div>
|
||||
))}
|
||||
<div className="grid gap-6 lg:grid-cols-3">
|
||||
<div className="space-y-6 lg:col-span-2">
|
||||
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
|
||||
<div className="min-w-0 space-y-6 lg:col-span-2">
|
||||
<Panel title="Detalhes do pedido">
|
||||
<dl className="grid gap-5 text-sm sm:grid-cols-3">
|
||||
<div>
|
||||
@@ -715,7 +715,7 @@ export default function Show({
|
||||
</Panel>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-6">
|
||||
<div className="min-w-0 space-y-6">
|
||||
{approvalRouting &&
|
||||
approvalRouting.status !== 'inactive' && (
|
||||
<Panel
|
||||
|
||||
@@ -14,6 +14,10 @@ import LegalChargeFields, {
|
||||
type LegalChargeDraft,
|
||||
} from '@/components/import-legal-charges';
|
||||
import { estimateMinor, estimateMoney } from '@/lib/import-estimate-money';
|
||||
import {
|
||||
specificRateLabel,
|
||||
specificRateMinor,
|
||||
} from '@/lib/import-legal-specific-rate';
|
||||
import { date, money } from '@/types/procurement';
|
||||
|
||||
type LegalData = {
|
||||
@@ -427,7 +431,8 @@ function ChargeEstimate({
|
||||
{['specific', 'maximum'].includes(charge.method) && (
|
||||
<label className="grid gap-1">
|
||||
Quantidade em {charge.quantity_unit} · taxa{' '}
|
||||
{money(charge.specific_minor)} por unidade
|
||||
{specificRateLabel(charge.specific_minor)} por
|
||||
unidade
|
||||
<input
|
||||
inputMode="decimal"
|
||||
className={controlClass}
|
||||
@@ -750,11 +755,15 @@ export default function ImportLegal(props: Props) {
|
||||
))}
|
||||
</Panel>
|
||||
<Panel
|
||||
title="Regras e fontes preservadas"
|
||||
title="Regras preparadas e publicadas"
|
||||
description="Uma nova preparação conserva a última publicação até ser validada. Retirar uma regra impede novas sugestões e conserva as decisões anteriores."
|
||||
>
|
||||
{props.rules.data.length === 0 && (
|
||||
<p>Ainda não existem fontes neste âmbito.</p>
|
||||
<p>
|
||||
Ainda não existem regras neste âmbito. Os diplomas
|
||||
disponíveis para consulta são apresentados
|
||||
separadamente.
|
||||
</p>
|
||||
)}
|
||||
{props.rules.data.map((rule) => (
|
||||
<article key={rule.id} className="space-y-2 border-b py-4">
|
||||
@@ -893,12 +902,13 @@ export default function ImportLegal(props: Props) {
|
||||
Preparar a partir do exemplar oficial
|
||||
</h3>
|
||||
<p className="text-sm">
|
||||
Transcrição da página 2180-(4) da Lei 8/2025,
|
||||
com início em 01/01/2026. Inclui apenas a taxa
|
||||
geral dessa edição; não é uma pauta consolidada
|
||||
nem determina isenções, preferências ou outras
|
||||
imposições. A preparação continua editável e
|
||||
exige gravação e decisão expressas.
|
||||
Transcrição do anexo da Lei 8/2025, páginas
|
||||
2180-(4) a (7), com início em 01/01/2026. Inclui
|
||||
apenas a taxa geral dessa edição; não é uma
|
||||
pauta consolidada nem determina isenções,
|
||||
preferências ou outras imposições. A preparação
|
||||
continua editável e exige gravação e decisão
|
||||
expressas.
|
||||
</p>
|
||||
{form.isDirty && (
|
||||
<p className="text-sm">
|
||||
@@ -907,56 +917,75 @@ export default function ImportLegal(props: Props) {
|
||||
existente será conservado.
|
||||
</p>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
{props.referenceDrafts?.map((draft) => (
|
||||
<Button
|
||||
key={`${draft.source_id}:${draft.code}`}
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="h-auto justify-start text-left whitespace-normal"
|
||||
disabled={
|
||||
<label className="grid gap-1">
|
||||
Código do anexo e fonte
|
||||
<select
|
||||
className={controlClass}
|
||||
value=""
|
||||
disabled={
|
||||
form.isDirty ||
|
||||
form.processing ||
|
||||
form.data.record_key !== null
|
||||
}
|
||||
onChange={(event) => {
|
||||
if (
|
||||
form.isDirty ||
|
||||
form.processing ||
|
||||
form.data.record_key !== null
|
||||
}
|
||||
onClick={() => {
|
||||
form.setData({
|
||||
...form.data,
|
||||
operation_key: '',
|
||||
record_key: null,
|
||||
version: 0,
|
||||
action: 'save',
|
||||
title: draft.title,
|
||||
official_reference:
|
||||
draft.official_reference,
|
||||
official_url:
|
||||
draft.official_url ?? '',
|
||||
citation: draft.citation,
|
||||
valid_from: draft.valid_from,
|
||||
valid_until: '',
|
||||
match_code: draft.code,
|
||||
suggested_code: draft.code,
|
||||
origin_country: '',
|
||||
sector: '',
|
||||
obligations: draft.obligations,
|
||||
document_types: [],
|
||||
reason: '',
|
||||
file: null,
|
||||
source_id: String(
|
||||
draft.source_id,
|
||||
),
|
||||
charges: chargeDrafts(
|
||||
draft.charges,
|
||||
),
|
||||
});
|
||||
form.clearErrors();
|
||||
}}
|
||||
>
|
||||
{draft.code} — {draft.description} —
|
||||
taxa geral {draft.rate_percent}%
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
return;
|
||||
const draft =
|
||||
props.referenceDrafts?.find(
|
||||
(item) =>
|
||||
`${item.source_id}:${item.code}` ===
|
||||
event.target.value,
|
||||
);
|
||||
if (!draft) return;
|
||||
form.setData({
|
||||
...form.data,
|
||||
operation_key: '',
|
||||
record_key: null,
|
||||
version: 0,
|
||||
action: 'save',
|
||||
title: draft.title,
|
||||
official_reference:
|
||||
draft.official_reference,
|
||||
official_url:
|
||||
draft.official_url ?? '',
|
||||
citation: draft.citation,
|
||||
valid_from: draft.valid_from,
|
||||
valid_until: '',
|
||||
match_code: draft.code,
|
||||
suggested_code: draft.code,
|
||||
origin_country: '',
|
||||
sector: '',
|
||||
obligations: draft.obligations,
|
||||
document_types: [],
|
||||
reason: '',
|
||||
file: null,
|
||||
source_id: String(draft.source_id),
|
||||
charges: chargeDrafts(
|
||||
draft.charges,
|
||||
),
|
||||
});
|
||||
form.clearErrors();
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Seleccione para preencher uma preparação
|
||||
</option>
|
||||
{props.referenceDrafts?.map((draft) => (
|
||||
<option
|
||||
key={`${draft.source_id}:${draft.code}`}
|
||||
value={`${draft.source_id}:${draft.code}`}
|
||||
>
|
||||
{draft.code} — {draft.description} —
|
||||
taxa geral {draft.rate_percent}% —
|
||||
fonte #{draft.source_id}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
<form
|
||||
@@ -983,7 +1012,7 @@ export default function ImportLegal(props: Props) {
|
||||
specific_minor:
|
||||
charge.specific_amount === ''
|
||||
? null
|
||||
: estimateMinor(
|
||||
: specificRateMinor(
|
||||
charge.specific_amount,
|
||||
),
|
||||
quantity_unit: charge.quantity_unit || null,
|
||||
@@ -1151,13 +1180,15 @@ export default function ImportLegal(props: Props) {
|
||||
<Button disabled={form.processing}>
|
||||
Guardar preparação para validação aduaneira
|
||||
</Button>
|
||||
{form.data.record_key && (
|
||||
{(form.isDirty || form.data.record_key) && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => form.reset()}
|
||||
>
|
||||
Preparar outra regra
|
||||
{form.data.record_key
|
||||
? 'Preparar outra regra'
|
||||
: 'Limpar preparação'}
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user