@@ -12,8 +12,10 @@ export type CommercialTerms = {
|
||||
|
||||
export function QuotationCommercialTerms({
|
||||
terms,
|
||||
currency = 'MZN',
|
||||
}: {
|
||||
terms?: CommercialTerms | null;
|
||||
currency?: string;
|
||||
}) {
|
||||
if (!terms) return null;
|
||||
return (
|
||||
@@ -25,13 +27,13 @@ export function QuotationCommercialTerms({
|
||||
{terms.lines.map((line) => (
|
||||
<p key={line.requisition_item_id}>
|
||||
Linha #{line.requisition_item_id}: preço inicial{' '}
|
||||
{money(line.gross_unit_minor)} · desconto{' '}
|
||||
{money(line.gross_unit_minor, currency)} · desconto{' '}
|
||||
{line.discount_type === 'none'
|
||||
? 'sem desconto'
|
||||
: line.discount_type === 'percent'
|
||||
? `${line.discount_value}%`
|
||||
: `${line.discount_value} MZN/unidade`}{' '}
|
||||
· preço líquido {money(line.net_unit_minor)}
|
||||
: `${line.discount_value} ${currency}/unidade`}{' '}
|
||||
· preço líquido {money(line.net_unit_minor, currency)}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { Input } from '@/components/ui/input';
|
||||
|
||||
export function convertedQuantity(milli: string): string {
|
||||
if (!/^\d+$/.test(milli)) return 'Não disponível';
|
||||
const padded = milli.padStart(4, '0');
|
||||
return `${padded.slice(0, -3)},${padded.slice(-3)}`;
|
||||
}
|
||||
|
||||
export type ReceiptConversion = {
|
||||
numerator: string;
|
||||
denominator: string;
|
||||
source: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export function ReceiptConversionFields({
|
||||
value,
|
||||
onChange,
|
||||
documentUnit,
|
||||
stockUnit,
|
||||
}: {
|
||||
value: ReceiptConversion;
|
||||
onChange: (value: ReceiptConversion) => void;
|
||||
documentUnit: string;
|
||||
stockUnit: string;
|
||||
}) {
|
||||
return (
|
||||
<fieldset className="space-y-3 rounded border p-3">
|
||||
<legend>
|
||||
Conversão de {documentUnit} para {stockUnit}
|
||||
</legend>
|
||||
<p className="text-sm">
|
||||
A compra conserva {documentUnit}. O stock e os lotes usam{' '}
|
||||
{stockUnit}. O factor, fonte e versão ficam congelados nesta
|
||||
linha.
|
||||
</p>
|
||||
{(
|
||||
[
|
||||
['numerator', 'Numerador'],
|
||||
['denominator', 'Denominador'],
|
||||
['source', 'Fonte do factor'],
|
||||
['version', 'Versão da fonte'],
|
||||
] as const
|
||||
).map(([key, label]) => (
|
||||
<label className="block space-y-1" key={key}>
|
||||
<span>{label}</span>
|
||||
<Input
|
||||
required
|
||||
value={value[key]}
|
||||
maxLength={
|
||||
key === 'source' ? 500 : key === 'version' ? 100 : 9
|
||||
}
|
||||
pattern={
|
||||
key === 'numerator' || key === 'denominator'
|
||||
? '[1-9][0-9]{0,8}'
|
||||
: undefined
|
||||
}
|
||||
onChange={(event) =>
|
||||
onChange({ ...value, [key]: event.target.value })
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<p className="text-xs">
|
||||
Quantidade física = quantidade aceite × numerador ÷ denominador.
|
||||
Não há arredondamento automático.
|
||||
</p>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user