71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
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>
|
||
);
|
||
}
|