Files
compras/resources/js/components/receipt-conversion.tsx
T
nala 12dd6df28a
tests / ci (push) Waiting to run
commit melhorias compras1
2026-11-21 21:04:40 +02:00

71 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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>
);
}