diff --git a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/WeightCalculatePrice.jsx b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/WeightCalculatePrice.jsx index 7b80bf0..ce68e60 100644 --- a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/WeightCalculatePrice.jsx +++ b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/WeightCalculatePrice.jsx @@ -1,123 +1,158 @@ import { useState, useEffect, useRef } from 'react'; import { InputField } from '../../../../../Components/Forms/InputField.jsx'; -import { Form } from 'antd'; +import { Form, Radio } from 'antd'; import Buttons from '../../../../../Components/Forms/Buttons.jsx'; import { ArrowRightOutlined } from '@ant-design/icons'; +import "./WeightCalculatePrice.scss" const WeightCalculatePrice = ({ itemData, CartOrderDetails, onSubmit }) => { const [enteredPrice, setEnteredPrice] = useState(''); + const [enteredQty, setEnteredQty] = useState(''); const [calculatedQty, setCalculatedQty] = useState(0); + const [calcMode, setCalcMode] = useState('amt'); + const priceInputRef = useRef(null); const [form] = Form.useForm(); - const basePrice = parseFloat(itemData?.OrderRate || itemData?.SellingPrice || 0); + const basePrice = parseFloat( + itemData?.OrderRate || itemData?.SellingPrice || 0 + ); + // Auto focus input useEffect(() => { setTimeout(() => { - const inputElement = priceInputRef.current?.querySelector('input'); - if (inputElement) { - inputElement.focus(); - } + const input = priceInputRef.current?.querySelector('input'); + if (input) input.focus(); }, 100); - }, []); + }, [calcMode]); - // Calculate quantity based on entered price + // AMT → calculate QTY const handlePriceChange = (e) => { const value = e.target.value; setEnteredPrice(value); if (value && basePrice > 0) { - const price = parseFloat(value); - const qty = price / basePrice; + const qty = parseFloat(value) / basePrice; setCalculatedQty(qty); } else { setCalculatedQty(0); } }; - const handleSubmit = (e) => { - if (e && e.preventDefault) { - e.preventDefault(); + // KGS → calculate AMT + const handleQtyChange = (e) => { + const value = e.target.value; + setEnteredQty(value); + + if (value && basePrice > 0) { + const qty = parseFloat(value); + const price = qty * basePrice; + setEnteredPrice(price.toFixed(2)); + setCalculatedQty(qty); + } else { + setEnteredPrice(''); + setCalculatedQty(0); } + }; - if (enteredPrice && calculatedQty > 0) { - console.log('Submitting weight calculation:', { + const handleSubmit = (e) => { + if (e && e.preventDefault) e.preventDefault(); + + if (calculatedQty > 0 && enteredPrice > 0) { + onSubmit?.({ price: parseFloat(enteredPrice), - quantity: calculatedQty, + quantity: parseFloat(calculatedQty), }); - - // Pass the calculated values back to parent component - if (onSubmit) { - onSubmit({ - price: parseFloat(enteredPrice), - quantity: calculatedQty, - }); - } } }; return (