diff --git a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx index 6a86902..51b1605 100644 --- a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx +++ b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx @@ -12,9 +12,6 @@ import { GlobalReorderProductDetails, PreferenceData, getConfigType, - changefocusStatusCust, - changeCombofocus, - GlobalfocusStatusCust, } from '../../../../../Features/BookingScreen/BookingData/BookingData'; import { ArrowRightOutlined } from '@ant-design/icons'; import { Messages } from '../../../../../Components/Notifications/Messages'; @@ -49,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 { setIndex = () => { } } = props; const [disableSubmitButton, setDisableSubmitButton] = useState(false); + console.log(disableSubmitButton, "disableSubmitButton") const SessionData = useSelector(StoredSessionData); // const AppId = SessionData?.AppId; // const CompId = SessionData?.CompId; @@ -69,24 +68,13 @@ const BSBillingEditQuantity = (props) => { shallowEqual ); - const overAllLimitPreferenece = preferenceDatas?.[0]?.[ - 'SettingDtlDetails' - ]?.find( - (item) => - item.SettingIdName?.toLowerCase() === 'overalllimit' && - item?.SettingValue === 'Y' - ); - const itemWiseLimitPreferenece = preferenceDatas?.[0]?.[ - 'SettingDtlDetails' - ]?.find( - (item) => - item.SettingIdName?.toLowerCase() === 'itemwiselimit' && - item?.SettingValue === 'Y' - ); - const maxQtyLimit = - itemWiseLimitPreferenece?.SettingCount || - overAllLimitPreferenece?.SettingCount || - null; + const overAllLimitPreferenece = + preferenceDatas?.[0]?.['SettingDtlDetails']?.find( + (item) => (item.SettingIdName?.toLowerCase() === 'overalllimit') && item?.SettingValue === 'Y'); + const itemWiseLimitPreferenece = + preferenceDatas?.[0]?.['SettingDtlDetails']?.find( + (item) => item.SettingIdName?.toLowerCase() === 'itemwiselimit' && item?.SettingValue === 'Y'); + const maxQtyLimit = itemWiseLimitPreferenece?.SettingCount || overAllLimitPreferenece?.SettingCount || null; const preferenceOffer = preferenceDatas?.[0]?.['SettingDtlDetails']?.find( (item) => item.SettingIdName === 'Offer' @@ -100,7 +88,7 @@ const BSBillingEditQuantity = (props) => { ); console.log(preferenceshortcutkey, 'preferenceshortcutkey'); const [PriceChangeaccess, setPriceChangeaccess] = useState(true); - const selectStatuscust = useSelector(GlobalfocusStatusCust); + const [ConfigDataList, setConfigDataList] = useState([]); const [messageType, setMessageType] = useState(null); const [messageData, setMessageData] = useState(null); @@ -129,7 +117,7 @@ const BSBillingEditQuantity = (props) => { price: 'Price', quantity: 'qty', Parcel: 'Parcel', - weightAmount: 'weightAmount', + weightAmount: 'weightAmount' }; const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { if (props?.shortKeyMethod && SHORTKEY_TO_RADIO[props.shortKeyMethod]) { @@ -155,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' && @@ -170,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' @@ -197,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(() => { @@ -278,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' }) @@ -316,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 = () => { @@ -357,6 +357,7 @@ const BSBillingEditQuantity = (props) => { }; const calculateOverAllQty = (item, filterItems) => { + if (!item) return 0; const totalUsedQty = @@ -437,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)); @@ -459,18 +461,11 @@ const BSBillingEditQuantity = (props) => { ); const editedProduct = CartOrderDetails[editedProductIndex]; - if ( - (overAllLimitPreferenece || itemWiseLimitPreferenece) && - maxQtyLimit - ) { + if ((overAllLimitPreferenece || itemWiseLimitPreferenece) && maxQtyLimit) { if (overAllLimitPreferenece) { - const calculatedOverAllQty = calculateOverAllQtyLimit( - CartOrderDetails?.filter((_, index) => index !== editedProductIndex) - ); - if (calculatedOverAllQty + editedQty > maxQtyLimit) { - setMessageData( - `Overall Quantity Limit Exceeds than ${maxQtyLimit}` - ); + const calculatedOverAllQty = calculateOverAllQtyLimit(CartOrderDetails?.filter((_, index) => index !== editedProductIndex)); + if ((calculatedOverAllQty + editedQty) > maxQtyLimit) { + setMessageData(`Overall Quantity Limit Exceeds than ${maxQtyLimit}`); setMessageType('warning'); return; } @@ -742,12 +737,11 @@ const BSBillingEditQuantity = (props) => { newPrice, overrideQty = null ) => { - const editedQty = - overrideQty !== null - ? overrideQty - : props?.Productdata?.ScaleType !== 'weight' - ? parseInt(Quantity) - : props.Productdata.OrderQty; + const editedQty = overrideQty !== null + ? overrideQty + : props?.Productdata?.ScaleType !== 'weight' + ? parseInt(Quantity) + : props.Productdata.OrderQty; const addFirst = BillOrderPre === 'Y'; const isExistsInFreeProdList = FreeProdList?.find( (product) => @@ -771,7 +765,7 @@ const BSBillingEditQuantity = (props) => { return ( cartItem?.InwardDtlId === editedProduct?.InwardDtlId && cartItem?.OfferMessage?.[0]?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && cartItem?.OfferMode === editedProduct?.OfferMode && cartItem?.BookingTypeName !== editedProduct?.BookingTypeName ); @@ -905,7 +899,7 @@ const BSBillingEditQuantity = (props) => { cartItem?.InwardDtlId === editedProduct?.InwardDtlId && cartItem?.OrderRate === editedProduct?.OrderRate && cartItem?.BookingTypeName !== - editedProduct?.BookingTypeName && + editedProduct?.BookingTypeName && !cartItem?.OfferMode && cartItem?.Offer === 0 ); @@ -919,7 +913,7 @@ const BSBillingEditQuantity = (props) => { cartItem?.InwardDtlId === editedProduct?.InwardDtlId && cartItem?.OrderRate === editedProduct?.OrderRate && cartItem?.BookingTypeName !== - editedProduct?.BookingTypeName && + editedProduct?.BookingTypeName && cartItem?.OfferMode === editedProduct?.OfferMode && cartItem?.Offer > 0 ); @@ -1052,7 +1046,7 @@ const BSBillingEditQuantity = (props) => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { const freeQty = @@ -1085,7 +1079,7 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1168,7 +1162,7 @@ const BSBillingEditQuantity = (props) => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { return { @@ -1198,7 +1192,7 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1385,7 +1379,7 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1487,7 +1481,7 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1641,7 +1635,7 @@ const BSBillingEditQuantity = (props) => { ) && cartItem?.Offer && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -1930,11 +1924,11 @@ const BSBillingEditQuantity = (props) => { product?.ProdId === editedProduct?.ProdId && product?.InwardDtlId === editedProduct?.InwardDtlId && product?.OfferId === - (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || - otherBookingTypeProduct?.OfferMessage?.[0]?.OfferId) && + (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || + otherBookingTypeProduct?.OfferMessage?.[0]?.OfferId) && product?.OfferMode === - (sameBookingTypeProduct?.OfferMode || - otherBookingTypeProduct?.OfferMode) + (sameBookingTypeProduct?.OfferMode || + otherBookingTypeProduct?.OfferMode) ) { return { ...product, @@ -1968,11 +1962,11 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || - otherBookingTypeProduct?.OfferMessage?.[0]?.OfferId) && + (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || + otherBookingTypeProduct?.OfferMessage?.[0]?.OfferId) && offerProduct?.OfferMode === - (sameBookingTypeProduct?.OfferMode || - otherBookingTypeProduct?.OfferMode); + (sameBookingTypeProduct?.OfferMode || + otherBookingTypeProduct?.OfferMode); if (hasMatchingFreeProduct && isMatchingOffer) { // Get loyalty points from the matching free product @@ -2113,7 +2107,7 @@ const BSBillingEditQuantity = (props) => { cartItem?.Offer > 0 && isFreeProductApplicable?.OfferMode === cartItem?.OfferMode && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -2216,11 +2210,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === otherBookingTypeProduct.ProdId && cartItem.InwardDtlId === - otherBookingTypeProduct.InwardDtlId && + otherBookingTypeProduct.InwardDtlId && cartItem.BookingTypeName === - otherBookingTypeProduct.BookingTypeName && + otherBookingTypeProduct.BookingTypeName && cartItem.OrderRate === - otherBookingTypeProduct.OrderRate && + otherBookingTypeProduct.OrderRate && cartItem.OfferMode && cartItem.Offer > 0 ) { @@ -2291,12 +2285,12 @@ const BSBillingEditQuantity = (props) => { product?.ProdId === editedProduct?.ProdId && product?.InwardDtlId === editedProduct?.InwardDtlId && product?.OfferId === - (sameBookingTypeFreeProduct?.OfferMessage?.[0]?.OfferId || - otherBookingTypeFreeProduct?.OfferMessage?.[0] - ?.OfferId) && + (sameBookingTypeFreeProduct?.OfferMessage?.[0]?.OfferId || + otherBookingTypeFreeProduct?.OfferMessage?.[0] + ?.OfferId) && product?.OfferMode === - (sameBookingTypeFreeProduct?.OfferMode || - otherBookingTypeFreeProduct?.OfferMode) + (sameBookingTypeFreeProduct?.OfferMode || + otherBookingTypeFreeProduct?.OfferMode) ) { return { ...product, @@ -2330,13 +2324,13 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - (sameBookingTypeFreeProduct?.OfferMessage?.[0] - ?.OfferId || - otherBookingTypeFreeProduct?.OfferMessage?.[0] - ?.OfferId) && + (sameBookingTypeFreeProduct?.OfferMessage?.[0] + ?.OfferId || + otherBookingTypeFreeProduct?.OfferMessage?.[0] + ?.OfferId) && offerProduct?.OfferMode === - (sameBookingTypeFreeProduct?.OfferMode || - otherBookingTypeFreeProduct?.OfferMode); + (sameBookingTypeFreeProduct?.OfferMode || + otherBookingTypeFreeProduct?.OfferMode); if (hasMatchingFreeProduct && isMatchingOffer) { // Get loyalty points from the matching free product @@ -2418,11 +2412,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === sameBookingTypeProduct.ProdId && cartItem.InwardDtlId === - sameBookingTypeProduct.InwardDtlId && + sameBookingTypeProduct.InwardDtlId && cartItem.BookingTypeName === - sameBookingTypeProduct.BookingTypeName && + sameBookingTypeProduct.BookingTypeName && cartItem.OrderRate === - sameBookingTypeProduct.OrderRate && + sameBookingTypeProduct.OrderRate && cartItem.OfferMode && cartItem.Offer > 0 ) { @@ -2475,11 +2469,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === sameBookingTypeProduct.ProdId && cartItem.InwardDtlId === - sameBookingTypeProduct.InwardDtlId && + sameBookingTypeProduct.InwardDtlId && cartItem.BookingTypeName === - sameBookingTypeProduct.BookingTypeName && + sameBookingTypeProduct.BookingTypeName && cartItem.OrderRate === - sameBookingTypeProduct.OrderRate && + sameBookingTypeProduct.OrderRate && cartItem.OfferMode && cartItem.Offer > 0 ) { @@ -2568,11 +2562,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === otherBookingTypeProduct.ProdId && cartItem?.InwardDtlId === - otherBookingTypeProduct.InwardDtlId && + otherBookingTypeProduct.InwardDtlId && cartItem?.BookingTypeName === - otherBookingTypeProduct.BookingTypeName && + otherBookingTypeProduct.BookingTypeName && cartItem?.OrderRate === - otherBookingTypeProduct.OrderRate && + otherBookingTypeProduct.OrderRate && cartItem?.OfferMode && cartItem?.Offer > 0 ) { @@ -2601,11 +2595,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === otherBookingTypeProduct.ProdId && cartItem.InwardDtlId === - otherBookingTypeProduct.InwardDtlId && + otherBookingTypeProduct.InwardDtlId && cartItem.BookingTypeName === - otherBookingTypeProduct.BookingTypeName && + otherBookingTypeProduct.BookingTypeName && cartItem.OrderRate === - otherBookingTypeProduct.OrderRate && + otherBookingTypeProduct.OrderRate && cartItem.OfferMode && cartItem.Offer > 0 ) { @@ -2635,11 +2629,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === otherBookingTypeProduct.ProdId && cartItem.InwardDtlId === - otherBookingTypeProduct.InwardDtlId && + otherBookingTypeProduct.InwardDtlId && cartItem.BookingTypeName === - otherBookingTypeProduct.BookingTypeName && + otherBookingTypeProduct.BookingTypeName && cartItem.OrderRate === - otherBookingTypeProduct.OrderRate && + otherBookingTypeProduct.OrderRate && cartItem.OfferMode && cartItem.Offer > 0 ) { @@ -2738,12 +2732,12 @@ const BSBillingEditQuantity = (props) => { product?.ProdId === editedProduct?.ProdId && product?.InwardDtlId === editedProduct?.InwardDtlId && product?.OfferId === - (sameBookingTypeFreeProduct?.OfferMessage?.[0]?.OfferId || - otherBookingTypeFreeProduct?.OfferMessage?.[0] - ?.OfferId) && + (sameBookingTypeFreeProduct?.OfferMessage?.[0]?.OfferId || + otherBookingTypeFreeProduct?.OfferMessage?.[0] + ?.OfferId) && product?.OfferMode === - (sameBookingTypeFreeProduct?.OfferMode || - otherBookingTypeFreeProduct?.OfferMode) + (sameBookingTypeFreeProduct?.OfferMode || + otherBookingTypeFreeProduct?.OfferMode) ) { return { ...product, @@ -2777,12 +2771,12 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || - otherBookingTypeProduct?.OfferMessage?.[0] - ?.OfferId) && + (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || + otherBookingTypeProduct?.OfferMessage?.[0] + ?.OfferId) && offerProduct?.OfferMode === - (sameBookingTypeProduct?.OfferMode || - otherBookingTypeProduct?.OfferMode); + (sameBookingTypeProduct?.OfferMode || + otherBookingTypeProduct?.OfferMode); if (hasMatchingFreeProduct && isMatchingOffer) { // Get loyalty points from the matching free product @@ -2861,11 +2855,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === sameBookingTypeProduct.ProdId && cartItem.InwardDtlId === - sameBookingTypeProduct.InwardDtlId && + sameBookingTypeProduct.InwardDtlId && cartItem.BookingTypeName === - sameBookingTypeProduct.BookingTypeName && + sameBookingTypeProduct.BookingTypeName && cartItem.OrderRate === - sameBookingTypeProduct.OrderRate && + sameBookingTypeProduct.OrderRate && cartItem.OfferMode && cartItem.Offer > 0 ) { @@ -2924,11 +2918,11 @@ const BSBillingEditQuantity = (props) => { if ( cartItem.ProdId === otherBookingTypeProduct.ProdId && cartItem.InwardDtlId === - otherBookingTypeProduct.InwardDtlId && + otherBookingTypeProduct.InwardDtlId && cartItem.BookingTypeName === - otherBookingTypeProduct.BookingTypeName && + otherBookingTypeProduct.BookingTypeName && cartItem.OrderRate === - otherBookingTypeProduct.OrderRate && + otherBookingTypeProduct.OrderRate && cartItem.OfferMode && cartItem.Offer > 0 ) { @@ -3000,12 +2994,12 @@ const BSBillingEditQuantity = (props) => { product?.ProdId === editedProduct?.ProdId && product?.InwardDtlId === editedProduct?.InwardDtlId && product?.OfferId === - (sameBookingTypeFreeProduct?.OfferMessage?.[0]?.OfferId || - otherBookingTypeFreeProduct?.OfferMessage?.[0] - ?.OfferId) && + (sameBookingTypeFreeProduct?.OfferMessage?.[0]?.OfferId || + otherBookingTypeFreeProduct?.OfferMessage?.[0] + ?.OfferId) && product?.OfferMode === - (sameBookingTypeFreeProduct?.OfferMode || - otherBookingTypeFreeProduct?.OfferMode) + (sameBookingTypeFreeProduct?.OfferMode || + otherBookingTypeFreeProduct?.OfferMode) ) { return { ...product, @@ -3039,12 +3033,12 @@ const BSBillingEditQuantity = (props) => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || - otherBookingTypeProduct?.OfferMessage?.[0] - ?.OfferId) && + (sameBookingTypeProduct?.OfferMessage?.[0]?.OfferId || + otherBookingTypeProduct?.OfferMessage?.[0] + ?.OfferId) && offerProduct?.OfferMode === - (sameBookingTypeProduct?.OfferMode || - otherBookingTypeProduct?.OfferMode); + (sameBookingTypeProduct?.OfferMode || + otherBookingTypeProduct?.OfferMode); if (hasMatchingFreeProduct && isMatchingOffer) { // Get loyalty points from the matching free product @@ -3175,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) { @@ -3199,17 +3213,17 @@ const BSBillingEditQuantity = (props) => { changeOrderCardDetails( CartOrderDetails?.map((i) => i?.InwardDtlId == updatedProduct?.InwardDtlId && - i?.BookingTypeName == updatedProduct?.BookingTypeName && - i?.localId === updatedProduct?.localId + i?.BookingTypeName == updatedProduct?.BookingTypeName && + i?.localId === updatedProduct?.localId ? { - ...updatedProduct, - Offer: 0, - OfferType: - updatedProduct?.Type === 'C' - ? updatedProduct?.OfferType - : null, - OfferMessage: null, - } + ...updatedProduct, + Offer: 0, + OfferType: + updatedProduct?.Type === 'C' + ? updatedProduct?.OfferType + : null, + OfferMessage: null, + } : i ) ) @@ -3234,6 +3248,7 @@ const BSBillingEditQuantity = (props) => { OfferMessage: updatedProduct?.OfferMessage || bestOffer?.OfferMessage, }; + console.log(updatedProduct, 'updatedProduct'); const shouldRemove = (c) => @@ -3245,10 +3260,10 @@ const BSBillingEditQuantity = (props) => { ((c?.OfferModeType && c?.OfferMode === 'B' ? true : c?.OfferMode !== 'B') && - c?.OfferMode !== 'P' && - c?.OfferMode !== 'C' && - c?.OfferMode !== 'O' && - c?.OfferMode !== 'L' + c?.OfferMode !== 'P' && + c?.OfferMode !== 'C' && + c?.OfferMode !== 'O' && + c?.OfferMode !== 'L' ? true : c?.Offer === 0); @@ -3313,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); @@ -3429,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 ( @@ -3441,6 +3501,7 @@ const BSBillingEditQuantity = (props) => { // parseFloat(enteredDiscount) === parseFloat(sellingPrice) // ) { setEditedPrice(enteredDiscount); + formRef.current?.setFieldsValue({ SellPrice: enteredDiscount }); setDisableSubmitButton(true); // } else { // setMessageType('error'); @@ -3461,7 +3522,8 @@ const BSBillingEditQuantity = (props) => { } if (enteredDiscount === maxDiscount) { - setEditedPrice(data?.target.value); + setEditedPrice(data); + formRef.current?.setFieldsValue({ SellPrice: data }); setDisableSubmitButton(true); return; } @@ -3470,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(); } }; @@ -3502,21 +3570,16 @@ const BSBillingEditQuantity = (props) => { ); const editedProduct = { ...CartOrderDetails[editedProductIndex], - OrderQty: qty, + OrderQty: qty }; - await handleEditQuantity( - editedProduct, - editedProductIndex, - editedProduct.OrderRate, - qty - ); + await handleEditQuantity(editedProduct, editedProductIndex, editedProduct.OrderRate, qty); props.handleEditQuantityCancel(); setClearQuantity(false); }; const isKg = props?.Productdata?.Size == 1 && - ['KG', 'KGS'].includes(props?.Productdata?.UomName?.toUpperCase()); + ["KG", "KGS"].includes(props?.Productdata?.UomName?.toUpperCase()); return (
@@ -3599,7 +3662,7 @@ const BSBillingEditQuantity = (props) => { } }} > - Price Change + OverRide / Discount )} @@ -3615,30 +3678,23 @@ const BSBillingEditQuantity = (props) => { Packing - {isKg && ( - - )} + {isKg && ()} +
{RadioBtnSelection == 'Quantity' && ( <> -
{ - dispatch(changefocusStatusCust(!selectStatuscust)); - dispatch(changeCombofocus(false)); - }} - > +
@@ -3647,10 +3703,6 @@ const BSBillingEditQuantity = (props) => { type="number" value={Quantity} onChange={(e) => setQuantity(e.target.value)} - onBlur={() => { - dispatch(changefocusStatusCust(!selectStatuscust)); - dispatch(changeCombofocus(false)); - }} className="EditQuantity-Quantitybox" />