@@ -0,0 +1,160 @@
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { FormErrors, Panel, controlClass } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
|
||||
export type ExchangeBasis = {
|
||||
id: number;
|
||||
currency: string;
|
||||
rate: string;
|
||||
quoted_on: string;
|
||||
source: string;
|
||||
recorded_by: number;
|
||||
};
|
||||
|
||||
export function ExchangeSummary({ basis }: { basis: ExchangeBasis }) {
|
||||
return (
|
||||
<div className="space-y-1 text-sm">
|
||||
<p>
|
||||
1 {basis.currency} = {basis.rate} MZN · Taxa de{' '}
|
||||
{basis.quoted_on}
|
||||
</p>
|
||||
<p className="whitespace-pre-wrap">Fonte: {basis.source}</p>
|
||||
<p>
|
||||
Taxa congelada neste processo por Finanças (utilizador #
|
||||
{basis.recorded_by}). Subtotal e IVA convertidos separadamente e
|
||||
arredondados ao centavo.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function QuotationExchangePanel({
|
||||
requisitionId,
|
||||
rates,
|
||||
canRecord,
|
||||
}: {
|
||||
requisitionId: number;
|
||||
rates: ExchangeBasis[];
|
||||
canRecord: boolean;
|
||||
}) {
|
||||
const form = useForm({
|
||||
operation_id: crypto.randomUUID(),
|
||||
currency: '',
|
||||
rate: '',
|
||||
quoted_on: '',
|
||||
source: '',
|
||||
});
|
||||
return (
|
||||
<Panel
|
||||
title="Taxas de câmbio do processo"
|
||||
description="Finanças informa a taxa para MZN, com data e fonte. Cada moeda fica congelada neste processo. Os valores originais da proposta são conservados; comparação, alçadas e orçamento usam a referência em MZN."
|
||||
>
|
||||
<p className="mb-4 text-sm">
|
||||
Este percurso usa valores monetários com duas casas decimais.
|
||||
Não há consulta automática de taxas nem conversão bancária.
|
||||
</p>
|
||||
<div className="space-y-4">
|
||||
{rates.map((rate) => (
|
||||
<ExchangeSummary key={rate.id} basis={rate} />
|
||||
))}
|
||||
</div>
|
||||
{rates.length === 0 && (
|
||||
<p className="text-sm">
|
||||
Sem taxa estrangeira registada. Propostas em MZN mantêm o
|
||||
percurso habitual.
|
||||
</p>
|
||||
)}
|
||||
{canRecord && (
|
||||
<form
|
||||
className="mt-5 space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.post(
|
||||
`/requisicoes/${requisitionId}/taxas-cambio`,
|
||||
{
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
form.setData(
|
||||
'operation_id',
|
||||
crypto.randomUUID(),
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<div className="grid gap-4 md:grid-cols-3">
|
||||
<div>
|
||||
<Label htmlFor="exchange-currency">
|
||||
Moeda original (código de 3 letras)
|
||||
</Label>
|
||||
<Input
|
||||
id="exchange-currency"
|
||||
required
|
||||
pattern="[A-Z]{3}"
|
||||
maxLength={3}
|
||||
value={form.data.currency}
|
||||
onChange={(event) =>
|
||||
form.setData(
|
||||
'currency',
|
||||
event.target.value.toUpperCase(),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="exchange-rate">
|
||||
MZN por unidade da moeda original
|
||||
</Label>
|
||||
<Input
|
||||
id="exchange-rate"
|
||||
required
|
||||
inputMode="decimal"
|
||||
value={form.data.rate}
|
||||
onChange={(event) =>
|
||||
form.setData('rate', event.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="exchange-date">Data da taxa</Label>
|
||||
<Input
|
||||
id="exchange-date"
|
||||
type="date"
|
||||
required
|
||||
value={form.data.quoted_on}
|
||||
onChange={(event) =>
|
||||
form.setData(
|
||||
'quoted_on',
|
||||
event.target.value,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor="exchange-source">Fonte da taxa</Label>
|
||||
<textarea
|
||||
id="exchange-source"
|
||||
className={controlClass}
|
||||
required
|
||||
minLength={3}
|
||||
maxLength={1000}
|
||||
value={form.data.source}
|
||||
onChange={(event) =>
|
||||
form.setData('source', event.target.value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<Button disabled={form.processing}>
|
||||
Registar e congelar taxa
|
||||
</Button>
|
||||
</form>
|
||||
)}
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user