part1
This commit is contained in:
@@ -18,8 +18,18 @@ type Props = {
|
|||||||
onChangeSearchFinal?: (value: string) => void;
|
onChangeSearchFinal?: (value: string) => void;
|
||||||
} & InputHTMLAttributes<HTMLInputElement>
|
} & InputHTMLAttributes<HTMLInputElement>
|
||||||
|
|
||||||
|
const formatNumber = (value: string | number): string => {
|
||||||
|
if (!value) return '';
|
||||||
|
const inputValue = String(value).replace(/,/g, '');
|
||||||
|
return inputValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||||
|
};
|
||||||
|
|
||||||
const Input: FC<Props> = (props: Props) => {
|
const Input: FC<Props> = (props: Props) => {
|
||||||
|
|
||||||
|
const [formattedValue, setFormattedValue] = useState<string>(
|
||||||
|
props.value ? formatNumber(props.value as string) : ''
|
||||||
|
);
|
||||||
|
|
||||||
const [showPassword, setShowPassword] = useState<boolean>(false)
|
const [showPassword, setShowPassword] = useState<boolean>(false)
|
||||||
const [search, setSearch] = useState<string>('')
|
const [search, setSearch] = useState<string>('')
|
||||||
|
|
||||||
@@ -30,6 +40,33 @@ const Input: FC<Props> = (props: Props) => {
|
|||||||
props.className
|
props.className
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
if (props.seprator) {
|
||||||
|
const inputValue = event.target.value.replace(/,/g, ''); // حذف کاماها
|
||||||
|
const formatted = formatNumber(inputValue);
|
||||||
|
|
||||||
|
// بهروزرسانی مقدار قالببندیشده
|
||||||
|
setFormattedValue(formatted);
|
||||||
|
|
||||||
|
// ارسال مقدار خام به `onChange` والد
|
||||||
|
props.onChange?.({
|
||||||
|
...event,
|
||||||
|
target: {
|
||||||
|
...event.target,
|
||||||
|
value: inputValue,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
props.onChange?.(event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (props.value) {
|
||||||
|
setFormattedValue(formatNumber(props.value as string));
|
||||||
|
}
|
||||||
|
}, [props.value])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.variant === 'search' && props.onChangeSearchFinal) {
|
if (props.variant === 'search' && props.onChangeSearchFinal) {
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
@@ -47,10 +84,10 @@ const Input: FC<Props> = (props: Props) => {
|
|||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className='w-full relative mt-1'>
|
<div className='w-full relative mt-1'>
|
||||||
<input onChange={(e) => {
|
<input {...props} onChange={(e) => {
|
||||||
setSearch(e.target.value)
|
setSearch(e.target.value)
|
||||||
props.onChange?.(e)
|
handleInputChange(e)
|
||||||
}} {...props} type={props.type === 'password' && showPassword ? 'text' : props.type === 'password' ? 'password' : undefined} className={inputClass} />
|
}} value={props.seprator ? formattedValue : props.value} type={props.type === 'password' && showPassword ? 'text' : props.type === 'password' ? 'password' : undefined} className={inputClass} />
|
||||||
|
|
||||||
{
|
{
|
||||||
props.type === 'password' &&
|
props.type === 'password' &&
|
||||||
|
|||||||
+1
-1
@@ -388,7 +388,7 @@
|
|||||||
"unit_amount": "مبلغ واحد",
|
"unit_amount": "مبلغ واحد",
|
||||||
"discount": "تخفیف(٪)",
|
"discount": "تخفیف(٪)",
|
||||||
"total_amount": "مبلغ کل(ریال)",
|
"total_amount": "مبلغ کل(ریال)",
|
||||||
"tax": "مالیات بر ارزش افزوده (۰.۹ درصد)",
|
"tax": "مالیات بر ارزش افزوده (۱۰ درصد)",
|
||||||
"total": "جمع",
|
"total": "جمع",
|
||||||
"error_empty": "همه فیلد ها را پر کنید",
|
"error_empty": "همه فیلد ها را پر کنید",
|
||||||
"date_receipt": "تاریخ صورتحساب",
|
"date_receipt": "تاریخ صورتحساب",
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ const CreateReceipt: FC = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('as', formik.values);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mt-4'>
|
<div className='mt-4'>
|
||||||
@@ -221,7 +224,8 @@ const CreateReceipt: FC = () => {
|
|||||||
className='text-center'
|
className='text-center'
|
||||||
name='unitPrice'
|
name='unitPrice'
|
||||||
value={formik.values.unitPrice}
|
value={formik.values.unitPrice}
|
||||||
onChange={formik.handleChange}
|
onChange={(e) => formik.setFieldValue('unitPrice', e.target.value)}
|
||||||
|
seprator
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -308,6 +312,7 @@ const CreateReceipt: FC = () => {
|
|||||||
name='unitPrice'
|
name='unitPrice'
|
||||||
readOnly
|
readOnly
|
||||||
value={item.unitPrice}
|
value={item.unitPrice}
|
||||||
|
seprator
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -332,6 +337,7 @@ const CreateReceipt: FC = () => {
|
|||||||
className='text-center bg-[#EBEDF5]'
|
className='text-center bg-[#EBEDF5]'
|
||||||
readOnly
|
readOnly
|
||||||
value={((Number(item.unitPrice) || 0) * (Number(item.count) || 0) - (Number(item.unitPrice) || 0) * (Number(item.count) || 0) * (Number(item.discount) / 100 || 0)).toFixed(1)}
|
value={((Number(item.unitPrice) || 0) * (Number(item.count) || 0) - (Number(item.unitPrice) || 0) * (Number(item.count) || 0) * (Number(item.discount) / 100 || 0)).toFixed(1)}
|
||||||
|
seprator
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -357,7 +363,7 @@ const CreateReceipt: FC = () => {
|
|||||||
{t('receip.tax')}
|
{t('receip.tax')}
|
||||||
</div>
|
</div>
|
||||||
<div className='text-black'>
|
<div className='text-black'>
|
||||||
{((items.reduce((acc, item) => acc + (Number(item.unitPrice) || 0) * (Number(item.count) || 0) - (Number(item.unitPrice) || 0) * (Number(item.count) || 0) * (Number(item.discount) / 100 || 0), 0)) * 0.09).toFixed(1)}
|
{((items.reduce((acc, item) => acc + (Number(item.unitPrice) || 0) * (Number(item.count) || 0) - (Number(item.unitPrice) || 0) * (Number(item.count) || 0) * (Number(item.discount) / 100 || 0), 0)) * 0.10).toFixed(1)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='xl:w-1/2 h-12 w-full rounded-xl flex px-4 bg-[#EBEDF5] text-sm text-description justify-between items-center'>
|
<div className='xl:w-1/2 h-12 w-full rounded-xl flex px-4 bg-[#EBEDF5] text-sm text-description justify-between items-center'>
|
||||||
@@ -366,7 +372,7 @@ const CreateReceipt: FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className='text-black'>
|
<div className='text-black'>
|
||||||
{(
|
{(
|
||||||
items.reduce((acc, item) => acc + (Number(item.unitPrice) || 0) * (Number(item.count) || 0) - (Number(item.unitPrice) || 0) * (Number(item.count) || 0) * (Number(item.discount) / 100 || 0), 0) * 1.09
|
items.reduce((acc, item) => acc + (Number(item.unitPrice) || 0) * (Number(item.count) || 0) - (Number(item.unitPrice) || 0) * (Number(item.count) || 0) * (Number(item.discount) / 100 || 0), 0) * 1.10
|
||||||
).toFixed(1)}
|
).toFixed(1)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user