@@ -0,0 +1,252 @@
|
||||
import { controlClass } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { estimateMoney } from '@/lib/import-estimate-money';
|
||||
import { money } from '@/types/procurement';
|
||||
|
||||
export type LegalCharge = {
|
||||
key: string;
|
||||
kind: string;
|
||||
label: string;
|
||||
method: string;
|
||||
rate_percent: string | null;
|
||||
specific_minor: number | null;
|
||||
quantity_unit: string | null;
|
||||
basis_reference: string;
|
||||
};
|
||||
export type LegalChargeDraft = {
|
||||
key: string;
|
||||
kind: string;
|
||||
label: string;
|
||||
method: string;
|
||||
rate_percent: string;
|
||||
specific_amount: string;
|
||||
quantity_unit: string;
|
||||
basis_reference: string;
|
||||
};
|
||||
export const chargeDrafts = (charges: LegalCharge[]) =>
|
||||
charges.map((charge): LegalChargeDraft => ({
|
||||
key: charge.key,
|
||||
kind: charge.kind,
|
||||
label: charge.label,
|
||||
method: charge.method,
|
||||
rate_percent: charge.rate_percent ?? '',
|
||||
specific_amount: estimateMoney(charge.specific_minor),
|
||||
quantity_unit: charge.quantity_unit ?? '',
|
||||
basis_reference: charge.basis_reference,
|
||||
}));
|
||||
export function LegalChargeSummary({ charges }: { charges: LegalCharge[] }) {
|
||||
const methods: Record<string, string> = {
|
||||
unknown: 'Por determinar',
|
||||
not_applicable: 'Não aplicável segundo a fonte',
|
||||
ad_valorem: 'Percentagem sobre base em MZN',
|
||||
specific: 'Montante por unidade',
|
||||
maximum: 'Maior valor entre percentagem e montante por unidade',
|
||||
};
|
||||
if (charges.length === 0)
|
||||
return <p>Imposições ainda por parametrizar nesta regra.</p>;
|
||||
return (
|
||||
<div className="grid gap-3">
|
||||
{charges.map((charge) => (
|
||||
<dl key={charge.key} className="rounded border p-3">
|
||||
<dt className="font-medium">{charge.label}</dt>
|
||||
<dd>{methods[charge.method]}</dd>
|
||||
{charge.rate_percent !== null && (
|
||||
<dd>Taxa: {charge.rate_percent}%</dd>
|
||||
)}
|
||||
{charge.specific_minor !== null && (
|
||||
<dd>
|
||||
Taxa específica: {money(charge.specific_minor)} por{' '}
|
||||
{charge.quantity_unit}
|
||||
</dd>
|
||||
)}
|
||||
<dt>Base e condições</dt>
|
||||
<dd>{charge.basis_reference}</dd>
|
||||
</dl>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default function LegalChargeFields({
|
||||
charges,
|
||||
onChange,
|
||||
}: {
|
||||
charges: LegalChargeDraft[];
|
||||
onChange: (charges: LegalChargeDraft[]) => void;
|
||||
}) {
|
||||
const change = (index: number, values: Partial<LegalChargeDraft>) =>
|
||||
onChange(
|
||||
charges.map((charge, at) =>
|
||||
at === index ? { ...charge, ...values } : charge,
|
||||
),
|
||||
);
|
||||
return (
|
||||
<fieldset className="space-y-4 rounded border p-4">
|
||||
<legend>Imposições documentadas para estimativa</legend>
|
||||
<p>
|
||||
Sem taxas parametrizadas, os montantes permanecem por
|
||||
determinar. Registe a base legal de cada método; não aplique
|
||||
isenções sem os seus requisitos.
|
||||
</p>
|
||||
{charges.map((charge, index) => (
|
||||
<div
|
||||
key={charge.key}
|
||||
className="grid gap-3 border-b pb-4 sm:grid-cols-2"
|
||||
>
|
||||
<label className="grid gap-1">
|
||||
Imposição
|
||||
<select
|
||||
className={controlClass}
|
||||
value={charge.kind}
|
||||
onChange={(e) =>
|
||||
change(index, { kind: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="duty">Direitos aduaneiros</option>
|
||||
<option value="ice">ICE</option>
|
||||
<option value="vat">IVA da importação</option>
|
||||
<option value="other">Outro encargo</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Designação
|
||||
<input
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={2}
|
||||
maxLength={120}
|
||||
value={charge.label}
|
||||
onChange={(e) =>
|
||||
change(index, { label: e.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Método previsto na fonte
|
||||
<select
|
||||
className={controlClass}
|
||||
value={charge.method}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
method: e.target.value,
|
||||
rate_percent: '',
|
||||
specific_amount: '',
|
||||
quantity_unit: '',
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="unknown">Por determinar</option>
|
||||
<option value="not_applicable">
|
||||
Não aplicável segundo a fonte
|
||||
</option>
|
||||
<option value="ad_valorem">
|
||||
Percentagem sobre base expressa em MZN
|
||||
</option>
|
||||
<option value="specific">
|
||||
Montante em MZN por unidade
|
||||
</option>
|
||||
<option value="maximum">
|
||||
Maior valor entre percentagem e taxa por unidade
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{['ad_valorem', 'maximum'].includes(charge.method) && (
|
||||
<label className="grid gap-1">
|
||||
Taxa percentual
|
||||
<input
|
||||
required
|
||||
inputMode="decimal"
|
||||
pattern="[0-9]+([.][0-9]{1,6})?"
|
||||
className={controlClass}
|
||||
value={charge.rate_percent}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
rate_percent: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
{['specific', 'maximum'].includes(charge.method) && (
|
||||
<>
|
||||
<label className="grid gap-1">
|
||||
Taxa específica em MZN por unidade
|
||||
<input
|
||||
required
|
||||
inputMode="decimal"
|
||||
className={controlClass}
|
||||
value={charge.specific_amount}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
specific_amount: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className="grid gap-1">
|
||||
Unidade da taxa específica
|
||||
<input
|
||||
required
|
||||
maxLength={40}
|
||||
className={controlClass}
|
||||
value={charge.quantity_unit}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
quantity_unit: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
<label className="grid gap-1 sm:col-span-2">
|
||||
Artigo e condições da base de incidência ou da não
|
||||
aplicação
|
||||
<textarea
|
||||
required
|
||||
minLength={3}
|
||||
maxLength={4000}
|
||||
className={controlClass}
|
||||
value={charge.basis_reference}
|
||||
onChange={(e) =>
|
||||
change(index, {
|
||||
basis_reference: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() =>
|
||||
onChange(charges.filter((_, at) => at !== index))
|
||||
}
|
||||
>
|
||||
Retirar desta preparação
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
disabled={charges.length >= 20}
|
||||
onClick={() =>
|
||||
onChange([
|
||||
...charges,
|
||||
{
|
||||
key: crypto.randomUUID(),
|
||||
kind: 'duty',
|
||||
label: '',
|
||||
method: 'unknown',
|
||||
rate_percent: '',
|
||||
specific_amount: '',
|
||||
quantity_unit: '',
|
||||
basis_reference: '',
|
||||
},
|
||||
])
|
||||
}
|
||||
>
|
||||
Acrescentar imposição documentada
|
||||
</Button>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user