priceoveride

This commit is contained in:
Tamilselvan 2026-03-04 17:32:24 +05:30
parent 2bdba61c17
commit 6720cc48ab
3 changed files with 437 additions and 258 deletions

View File

@ -46,13 +46,15 @@ import { calculateOverAllQtyLimit } from '../../../../../utils/calculations.js';
const BSBillingEditQuantity = (props) => {
const dispatch = useDispatch();
const formRef = useRef(null);
const detailedFormRef = useRef(null);
const itemDiscountFormRef = useRef(null);
const quantityInputRef = useRef(null);
const priceChangeInputRef = useRef(null);
const reductionInputRef = useRef(null);
const { setIndex = () => { } } = props;
const [disableSubmitButton, setDisableSubmitButton] = useState(false);
console.log(disableSubmitButton, "disableSubmitButton")
const SessionData = useSelector(StoredSessionData);
// const AppId = SessionData?.AppId;
// const CompId = SessionData?.CompId;
@ -141,6 +143,8 @@ const BSBillingEditQuantity = (props) => {
const [PercentageSelection, setPercentageSelection] = useState('Fixed');
const [RadioDetails, setRadioDetails] = useState(false);
const [editedPrice, setEditedPrice] = useState(0);
const [itemDiscountPercentageSelection, setItemDiscountPercentageSelection] = useState('Fixed');
const [itemDiscountPrice, setItemDiscountPrice] = useState(0);
const allowDecimal = preferenceDatas?.[0]?.SettingDtlDetails?.find(
(setting) =>
setting?.SettingIdName?.toLowerCase() === 'decimal' &&
@ -156,7 +160,7 @@ const BSBillingEditQuantity = (props) => {
shallowEqual
);
const FreeProdList = useSelector(GlobalFreeProdList);
console.log(CartOrderDetails, 'CartOrderDetails');
console.log(editedPrice, 'editedPrice');
const TakAwayId = ConfigDataList?.find(
(a) => a?.ConfigName === 'TakeAway'
@ -183,9 +187,9 @@ const BSBillingEditQuantity = (props) => {
? parseInt(props.Productdata.OrderQty)
: props.Productdata.OrderQty
);
SellingPriceChange(parseFloat(props.Productdata?.SellingPrice || 0));
},
[props.BSBillingEditQuantity],
[props.Productdata]
[props.BSBillingEditQuantity, props.Productdata]
);
useEffect(() => {
@ -264,6 +268,13 @@ const BSBillingEditQuantity = (props) => {
}
}, [PackageDtl]);
useEffect(() => {
if (RadioBtnSelection === 'Price' && !RadioDetails) {
setEditedPrice(parseFloat(props.Productdata?.SellingPrice || 0));
}
}, [RadioBtnSelection, RadioDetails]);
const getBookingTypeId = async () => {
let tempconfigdata = await dispatch(
getConfigType({ TypeName: 'Booking Type' })
@ -302,9 +313,12 @@ const BSBillingEditQuantity = (props) => {
setQuantity(tempremovedata);
};
const openRadioDetails = () => {
setDisableSubmitButton(false);
// setDisableSubmitButton(false);
setRadioDetails(!RadioDetails);
setEditedPrice(0);
// Clear ItemDiscount field and reset discount price
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
};
// const AddQuantityonly = () => {
@ -424,7 +438,8 @@ const BSBillingEditQuantity = (props) => {
};
const AddProductQuantity = async () => {
let newPrice = editedPrice > 0 ? editedPrice : props.Productdata.OrderRate;
let disCountprice = editedPrice - itemDiscountPrice
let newPrice = safeRound(disCountprice > 0 ? disCountprice : props.Productdata.OrderRate);
await dispatch(changeHoldOrderDtl(false));
await dispatch(changePreviousOrderLength(CartOrderDetails?.length));
@ -3154,6 +3169,26 @@ const BSBillingEditQuantity = (props) => {
...(offerApply && {
Offer: qty * (newPrice > 0 ? newPrice : editedProduct?.OrderRate),
}),
...(
!offerApply && itemDiscountPrice > 0
? {
DiscountAmt: safeRound(itemDiscountPrice),
DiscountType: itemDiscountPercentageSelection === 'Fixed' ? 'F' : 'P',
DiscountValue:
itemDiscountPercentageSelection === 'Fixed'
? itemDiscountPrice
: (
(itemDiscountPrice /
(newPrice > 0 ? newPrice : editedProduct?.OrderRate)) * 100
)
}
: {
DiscountAmt: null,
DiscountType: null,
DiscountValue: null
}
)
};
if (hasOffer) {
@ -3213,6 +3248,7 @@ const BSBillingEditQuantity = (props) => {
OfferMessage: updatedProduct?.OfferMessage || bestOffer?.OfferMessage,
};
console.log(updatedProduct, 'updatedProduct');
const shouldRemove = (c) =>
@ -3292,11 +3328,52 @@ const BSBillingEditQuantity = (props) => {
const onPercentageSelectionChange = (data) => {
setPercentageSelection(data);
setEditedPrice(0);
formRef.current?.resetFields();
detailedFormRef.current?.resetFields();
setDisableSubmitButton(false);
};
const onItemDiscountPercentageChange = (data) => {
setItemDiscountPercentageSelection(data);
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
};
const ItemDiscountChangefun = (data) => {
const enteredDiscount = parseFloat(data?.target.value);
if (enteredDiscount) {
let roundedrice = safeRound(editedPrice ? editedPrice : 0)
const sellingPrice = parseFloat(roundedrice || props.Productdata?.SellingPrice || 0);
if (itemDiscountPercentageSelection === 'Fixed') {
if (parseFloat(enteredDiscount) < parseFloat(sellingPrice)) {
setItemDiscountPrice(parseFloat(enteredDiscount));
} else {
setMessageType('error');
setMessageData('Discount cannot exceed selling price');
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
}
} else {
if (parseFloat(enteredDiscount) < 100) {
let discountAmt = (parseFloat(enteredDiscount) * parseFloat(sellingPrice)) / 100;
setItemDiscountPrice(parseFloat(discountAmt));
} else {
setMessageType('error');
setMessageData('Percentage cannot exceed 100%');
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
}
}
} else {
setItemDiscountPrice(0);
}
};
const PriceChangefun = (data) => {
const enteredDiscount = parseFloat(data?.target.value);
// Clear ItemDiscount field and reset discount price
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
if (enteredDiscount) {
const sellingPrice = parseFloat(props.Productdata?.SellingPrice || 0);
const limit = parseFloat(props.Productdata?.DiscountLimit || 0);
@ -3408,11 +3485,15 @@ const BSBillingEditQuantity = (props) => {
}
};
const SellingPriceChange = (data) => {
if (data?.target.value) {
if (data) {
const sellingPrice = parseFloat(props.Productdata?.SellingPrice || 0);
const limit = parseFloat(props.Productdata?.DiscountLimit || 0);
const limitType = props.Productdata?.DiscountLimitType;
const enteredDiscount = parseFloat(data?.target.value);
const enteredDiscount = parseFloat(data);
// Clear ItemDiscount field and reset discount price
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
if (limit === null || limit === undefined || limit === 0) {
// if (
@ -3420,6 +3501,7 @@ const BSBillingEditQuantity = (props) => {
// parseFloat(enteredDiscount) === parseFloat(sellingPrice)
// ) {
setEditedPrice(enteredDiscount);
formRef.current?.setFieldsValue({ SellPrice: enteredDiscount });
setDisableSubmitButton(true);
// } else {
// setMessageType('error');
@ -3440,7 +3522,8 @@ const BSBillingEditQuantity = (props) => {
}
if (enteredDiscount === maxDiscount) {
setEditedPrice(data?.target.value);
setEditedPrice(data);
formRef.current?.setFieldsValue({ SellPrice: data });
setDisableSubmitButton(true);
return;
}
@ -3449,14 +3532,20 @@ const BSBillingEditQuantity = (props) => {
setMessageType('error');
setMessageData(`You cannot sell below ₹${maxDiscount.toFixed(2)}`);
setEditedPrice(0);
formRef.current?.setFieldsValue({ SellPrice: 0 });
setDisableSubmitButton(false);
return;
}
setDisableSubmitButton(true);
setEditedPrice(data?.target.value);
setEditedPrice(data);
formRef.current?.setFieldsValue({ SellPrice: data });
} else {
setDisableSubmitButton(false);
setEditedPrice(0);
formRef.current?.setFieldsValue({ SellPrice: 0 });
// Clear ItemDiscount field and reset discount price
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
}
};
@ -3573,7 +3662,7 @@ const BSBillingEditQuantity = (props) => {
}
}}
>
Price Change
OverRide / Discount
</button>
)}
@ -3663,6 +3752,7 @@ const BSBillingEditQuantity = (props) => {
</>
)}
{RadioBtnSelection == 'Price' && (
<div style={{ display: "flex" }} >
<div className="EditQuantity-PriceChange">
<label className="EditQuantity-itemname">
Item Price: {safeRound(props.Productdata.SellingPrice)} /
@ -3670,8 +3760,10 @@ const BSBillingEditQuantity = (props) => {
</label>
{!RadioDetails && (
<Form ref={formRef}>
<Form.Item
name="SellPrice"
initialValue={editedPrice}
rules={[
{
pattern: /^(0\d+|[1-9]\d*)(\.\d+)?$/,
@ -3695,10 +3787,11 @@ const BSBillingEditQuantity = (props) => {
<InputField
ref={priceChangeInputRef}
value={editedPrice}
label="Selling Price"
label="Price Override"
autocomplete="off"
onChange={SellingPriceChange}
onChange={(e) => { SellingPriceChange(e?.target?.value) }}
inputMode="decimal"
isOnChange={editedPrice > 0 ? true : false}
onInput={(e) => {
const cleanedValue = e.target.value.replace(
/[^0-9.]/g,
@ -3713,6 +3806,7 @@ const BSBillingEditQuantity = (props) => {
// isOnChange={formType == "edit" || formRef.current?.getFieldsValue()?.CustName ? true : false}
/>
</Form.Item>
</Form>
)}
<div className="prodAddDetails" onClick={openRadioDetails}>
@ -3734,12 +3828,13 @@ const BSBillingEditQuantity = (props) => {
/>
</div>
<div className="EditQuantity-Quantity">
<Form ref={formRef}>
<Form ref={detailedFormRef}>
<Form.Item
name="SellPrice"
initialValue={editedPrice}
rules={[
{
pattern: /^[1-9]\d*(\.\d+)?$/,
pattern: /^[0-9]\d*(\.\d+)?$/,
message: 'Please Enter Number Only',
},
{
@ -3762,6 +3857,7 @@ const BSBillingEditQuantity = (props) => {
autocomplete="off"
onChange={(e) => PriceChangefun(e)}
inputMode="decimal"
isOnChange={editedPrice > 0 ? true : false}
onInput={(e) => {
const cleanedValue = e.target.value.replace(
/[^0-9.]/g,
@ -3782,15 +3878,89 @@ const BSBillingEditQuantity = (props) => {
/> */}
</Form>
</div>
<div className="EditQuantity-Quantity">
{editedPrice > 0 && <div className="EditQuantity-Quantity">
<div className="EditQuantity-itemname">
{' '}
Price: {safeRound(editedPrice ? editedPrice : 0)}
</div>
</div>
</div>}
</>
)}
</div>
<div style={{ borderLeft: "1px solid #ddd", paddingLeft: "15px", marginLeft: "15px" }}>
<label className="EditQuantity-itemname">
Item Discount
</label>
<>
<div className="EditQuantity-Quantity">
<RadioGrpButton
content={[
{ value: 'Fixed', label: 'Fixed' },
{ value: 'Percentage', label: 'Percentage' },
]}
fieldState={true}
defaultSelect={itemDiscountPercentageSelection}
onSelectFuntion={(e) => {
onItemDiscountPercentageChange(e);
}}
/>
</div>
<div className="EditQuantity-Quantity">
<Form ref={itemDiscountFormRef}>
<Form.Item
name="ItemDiscount"
rules={[
{
pattern: /^[1-9]\d*(\.\d+)?$/,
message: 'Please Enter Number Only',
},
{
validator: async (_, value) => {
await validateSafeInput(value);
return Promise.resolve();
},
},
]}
>
<InputField
field="ItemDiscount"
name="ItemDiscount"
value={itemDiscountPrice}
label="Discount Amount"
fieldState={true}
fieldApi={true}
autocomplete="off"
onChange={(e) => ItemDiscountChangefun(e)}
inputMode="decimal"
onInput={(e) => {
const cleanedValue = e.target.value.replace(
/[^0-9.]/g,
''
);
const parts = cleanedValue.split('.');
e.target.value =
parts.length > 2
? `${parts[0]}.${parts.slice(1).join('')}`
: cleanedValue;
}}
/>
</Form.Item>
</Form>
</div>
{itemDiscountPrice > 0 && editedPrice > 0 && <div className="EditQuantity-Quantity">
<div className="EditQuantity-itemname">
{' '}
{console.log(editedPrice, itemDiscountPrice, "itemDiscountPrice")}
Final Price: {safeRound(editedPrice) - (itemDiscountPrice || 0)}
</div>
</div>}
</>
</div>
</div>
)}
{RadioBtnSelection == 'Parcel' && (
<>

View File

@ -2596,7 +2596,7 @@ const BSBillingTable3 = () => {
{item?.Type != 'C'
? item.Offer && item.Offer > 0
? item.Offer
: '-'
:item.DiscountAmt ? item.DiscountAmt : '-'
: item?.OfferPrice && item?.OfferPrice > 0
? item?.OfferType === 'F'
? `${safeRound(item.OfferPrice)}`
@ -2873,7 +2873,7 @@ const BSBillingTable3 = () => {
{item?.Type != 'C'
? item.Offer && item.Offer > 0
? item.Offer
: '-'
: item.DiscountAmt ? item.DiscountAmt : '-'
: item?.OfferPrice && item?.OfferPrice > 0
? item?.OfferType === 'F'
? `${safeRound(item.OfferPrice)}`
@ -3198,7 +3198,7 @@ const BSBillingTable3 = () => {
{item?.Type != 'C'
? item.Offer && item.Offer > 0
? item.Offer
: '-'
: item.DiscountAmt ? item.DiscountAmt : '-'
: item?.OfferPrice && item?.OfferPrice > 0
? item?.OfferType === 'F'
? `${safeRound(item.OfferPrice)}`
@ -3508,7 +3508,7 @@ const BSBillingTable3 = () => {
{item?.Type != 'C'
? item.Offer && item.Offer > 0
? item.Offer
: '-'
: item.DiscountAmt ? item.DiscountAmt : '-'
: item?.OfferPrice && item?.OfferPrice > 0
? item?.OfferType === 'F'
? `${safeRound(item.OfferPrice)}`

View File

@ -321,7 +321,7 @@ const BSBillingTable3Pay = () => {
const ProdSubCat = useSelector(GlobalProductSubCategorie);
const BSLayoutData = useSelector(getTemplateData);
const Combodata = useSelector(GlobalCombocarddata, shallowEqual);
console.log(PaymentOptions, "PaymentOptions")
const Custdisable = useSelector(GlobalSelectedCustDisable);
const SettingDataSelector = useSelector(PreferenceData);
@ -379,7 +379,7 @@ const BSBillingTable3Pay = () => {
const OrderCardDetail = useSelector(GlobalOrderCardDetails);
const [customerPreviesOrders, setCustomerPreviesOrders] = useState(false);
console.log(OrderCardDetail, 'OrderCardDetail');
console.log(paybtns, 'paybtns');
//Total calculation
const TotalItems = OrderCardDetail?.length;
const [formattedDate, setFormattedDate] = useState('');
@ -423,6 +423,7 @@ const BSBillingTable3Pay = () => {
const [PaymentgatewayUPI, setPaymentgatewayUPI] = useState([]);
const [PaymentDeviceUPI, setPaymentDeviceUPI] = useState([]);
const [UpiPayOption, setUpiPayOption] = useState([]);
console.log(UpiPayOption, "UpiPayOption")
const [BusinessPayOption, setBusinessPayoption] = useState([]);
const [CardPayOption, setCardPayOption] = useState([]);
const [Splitpayment, setSplitpayment] = useState(false);
@ -469,6 +470,7 @@ const BSBillingTable3Pay = () => {
const [OrderStatus, setOrderStatus] = useState(true);
const GlobaluseOptions = useSelector(GlobalCommonPaymentOptions);
console.log(GlobaluseOptions, "GlobaluseOptions")
const [useOptions, setuseOptions] = useState([]);
const paymentloader = useSelector(GlobalPayementloader);
const [UnpaidConfirmation, setUnpaidConfirmation] = useState(false);
@ -1072,9 +1074,9 @@ const BSBillingTable3Pay = () => {
setDefaultPaymentMode([]);
}
};
if (salesBillEdit) {
// if (salesBillEdit) {
setDefaultPaymentOption();
}
// }
}, [defaultPaymentTrigger, salesBillEdit]);
const TokenPrint = async (index) => {
@ -1614,6 +1616,7 @@ const BSBillingTable3Pay = () => {
//dhana
const getPaymentOptionFeature = async () => {
const FiltersalesPayment = GlobaluseOptions?.filter(
(item) => item.FlowName?.toLowerCase() === 'sales'
);
@ -1648,6 +1651,7 @@ const BSBillingTable3Pay = () => {
filterpaymentdevice?.[0]?.ModeDetails?.filter((item) =>
item?.ModeName?.toLowerCase()?.includes('upi')
) || [];
setPaymentOptions(filterpaycounter?.[0]?.ModeDetails);
setPaymentUpiOptions(
FiltersalesPayment?.[0]?.PaymentDetails?.Payatthecounter
@ -2189,6 +2193,7 @@ const BSBillingTable3Pay = () => {
};
const Booking = async (value, pay) => {
const TakAwayId = ConfigDataList?.find(
(a) => a?.ConfigName === 'TakeAway'
)?.ConfigId;
@ -2239,6 +2244,10 @@ const BSBillingTable3Pay = () => {
BatchRef: a.BatchRef,
PackageDtl: a.PackageDtl,
SetCount: a.SetCount,
...(a?.DiscountValue && { DiscountValue: a.DiscountValue }),
...(a?.DiscountType && { DiscountType: a.DiscountType }),
...(a?.DiscountAmt && { DiscountAmt: a.DiscountAmt })
}));
const NotSlectedTypeFind = temporderdetail?.find(
(a) => a?.BookingType != SelectedBookingType