diff --git a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx index e91957c..9c84e49 100644 --- a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx +++ b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx @@ -12,6 +12,8 @@ import { GlobalReorderProductDetails, PreferenceData, getConfigType, + changeCombofocus, + changefocusStatusCust, } from '../../../../../Features/BookingScreen/BookingData/BookingData'; import { ArrowRightOutlined } from '@ant-design/icons'; import { Messages } from '../../../../../Components/Notifications/Messages'; @@ -48,13 +50,14 @@ const BSBillingEditQuantity = (props) => { const formRef = useRef(null); const detailedFormRef = useRef(null); const itemDiscountFormRef = useRef(null); + const discountRef = 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") + console.log(disableSubmitButton, 'disableSubmitButton'); const SessionData = useSelector(StoredSessionData); // const AppId = SessionData?.AppId; // const CompId = SessionData?.CompId; @@ -68,13 +71,30 @@ 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 itemDiscount = preferenceDatas?.[0]?.['SettingDtlDetails']?.find( + (item) => + item.SettingIdName?.toLowerCase() === 'itemdiscount' && + 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' @@ -117,7 +137,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]) { @@ -142,9 +162,10 @@ 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 [editedPrice, setEditedPrice] = useState(''); + const [itemDiscountPercentageSelection, setItemDiscountPercentageSelection] = + useState('Fixed'); + const [itemDiscountPrice, setItemDiscountPrice] = useState(''); const allowDecimal = preferenceDatas?.[0]?.SettingDtlDetails?.find( (setting) => setting?.SettingIdName?.toLowerCase() === 'decimal' && @@ -178,19 +199,18 @@ const BSBillingEditQuantity = (props) => { } }, []); - useEffect( - () => { - setEditOpen(props.BSBillingEditQuantity); - setItemData(props.Productdata); - setQuantity( - props?.Productdata?.ScaleType !== 'weight' - ? parseInt(props.Productdata.OrderQty) - : props.Productdata.OrderQty - ); - SellingPriceChange(parseFloat(props.Productdata?.SellingPrice || 0)); - }, - [props.BSBillingEditQuantity, props.Productdata] - ); + useEffect(() => { + dispatch(changeCombofocus(true)); + dispatch(changefocusStatusCust(true)); + setEditOpen(props.BSBillingEditQuantity); + setItemData(props.Productdata); + setQuantity( + props?.Productdata?.ScaleType !== 'weight' + ? parseInt(props.Productdata.OrderQty) + : props.Productdata.OrderQty + ); + SellingPriceChange(parseFloat(props.Productdata?.SellingPrice || 0)); + }, [props.BSBillingEditQuantity, props.Productdata]); useEffect(() => { if (preferenceshortcutkey) { @@ -272,7 +292,6 @@ const BSBillingEditQuantity = (props) => { if (RadioBtnSelection === 'Price' && !RadioDetails) { setEditedPrice(parseFloat(props.Productdata?.SellingPrice || 0)); } - }, [RadioBtnSelection, RadioDetails]); const getBookingTypeId = async () => { @@ -315,9 +334,9 @@ const BSBillingEditQuantity = (props) => { const openRadioDetails = () => { // setDisableSubmitButton(false); setRadioDetails(!RadioDetails); - setEditedPrice(0); + // setEditedPrice(""); // Clear ItemDiscount field and reset discount price - setItemDiscountPrice(0); + setItemDiscountPrice(''); itemDiscountFormRef.current?.resetFields(); }; @@ -357,7 +376,6 @@ const BSBillingEditQuantity = (props) => { }; const calculateOverAllQty = (item, filterItems) => { - if (!item) return 0; const totalUsedQty = @@ -438,8 +456,10 @@ const BSBillingEditQuantity = (props) => { }; const AddProductQuantity = async () => { - let disCountprice = safeRound(editedPrice) - itemDiscountPrice - let newPrice = safeRound(disCountprice > 0 ? disCountprice : props.Productdata.OrderRate); + let disCountprice = safeRound(editedPrice) - itemDiscountPrice; + let newPrice = safeRound( + disCountprice > 0 ? disCountprice : props.Productdata.OrderRate + ); await dispatch(changeHoldOrderDtl(false)); await dispatch(changePreviousOrderLength(CartOrderDetails?.length)); @@ -461,17 +481,32 @@ 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; } } else if (itemWiseLimitPreferenece) { - const exceptEditedItemCart = calculateOverAllQtyLimit(CartOrderDetails?.filter((_, index) => index !== editedProductIndex && _.ProdId === editedProduct?.ProdId && _.InwardDtlId === editedProduct?.InwardDtlId)); - const totalQtyForItem = ((exceptEditedItemCart || 0) + (editedQty || 0)); + const exceptEditedItemCart = calculateOverAllQtyLimit( + CartOrderDetails?.filter( + (_, index) => + index !== editedProductIndex && + _.ProdId === editedProduct?.ProdId && + _.InwardDtlId === editedProduct?.InwardDtlId + ) + ); + const totalQtyForItem = + (exceptEditedItemCart || 0) + (editedQty || 0); if (totalQtyForItem > maxQtyLimit) { setMessageData(`Item Quantity Limit Exceeds than ${maxQtyLimit}`); setMessageType('warning'); @@ -745,11 +780,12 @@ 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) => @@ -773,7 +809,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 ); @@ -907,7 +943,7 @@ const BSBillingEditQuantity = (props) => { cartItem?.InwardDtlId === editedProduct?.InwardDtlId && cartItem?.OrderRate === editedProduct?.OrderRate && cartItem?.BookingTypeName !== - editedProduct?.BookingTypeName && + editedProduct?.BookingTypeName && !cartItem?.OfferMode && cartItem?.Offer === 0 ); @@ -921,7 +957,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 ); @@ -1054,7 +1090,7 @@ const BSBillingEditQuantity = (props) => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { const freeQty = @@ -1087,7 +1123,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) { @@ -1170,7 +1206,7 @@ const BSBillingEditQuantity = (props) => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { return { @@ -1200,7 +1236,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) { @@ -1387,7 +1423,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) { @@ -1489,7 +1525,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) { @@ -1643,7 +1679,7 @@ const BSBillingEditQuantity = (props) => { ) && cartItem?.Offer && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -1932,11 +1968,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, @@ -1970,11 +2006,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 @@ -2115,7 +2151,7 @@ const BSBillingEditQuantity = (props) => { cartItem?.Offer > 0 && isFreeProductApplicable?.OfferMode === cartItem?.OfferMode && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -2218,11 +2254,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 ) { @@ -2293,12 +2329,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, @@ -2332,13 +2368,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 @@ -2420,11 +2456,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 ) { @@ -2477,11 +2513,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 ) { @@ -2570,11 +2606,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 ) { @@ -2603,11 +2639,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 ) { @@ -2637,11 +2673,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 ) { @@ -2740,12 +2776,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, @@ -2779,12 +2815,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 @@ -2863,11 +2899,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 ) { @@ -2926,11 +2962,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 ) { @@ -3002,12 +3038,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, @@ -3041,12 +3077,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 @@ -3164,10 +3200,12 @@ const BSBillingEditQuantity = (props) => { const updatedProduct = { ...editedProduct, OrderQty: fixedQty, - OrderRate: editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate, + OrderRate: + editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate, ...calculateTaxAmounts({ qty: qty, - rate: editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate, + rate: + editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate, taxPercentage: editedProduct?.TaxPercentage, type: editedProduct?.Type, product: editedProduct, @@ -3177,26 +3215,23 @@ const BSBillingEditQuantity = (props) => { ...(offerApply && { Offer: qty * (editedPrice > 0 ? editedPrice : editedProduct?.OrderRate), }), - ...( - !offerApply && itemDiscountPrice > 0 - ? { - DiscountAmt: safeRound(itemDiscountPrice*fixedQty ), - DiscountType: itemDiscountPercentageSelection === 'Fixed' ? 'F' : 'P', + ...(!offerApply && itemDiscountPrice > 0 + ? { + DiscountAmt: safeRound(itemDiscountPrice * fixedQty), + DiscountType: + itemDiscountPercentageSelection === 'Fixed' ? 'F' : 'P', DiscountValue: itemDiscountPercentageSelection === 'Fixed' - ? itemDiscountPrice*fixedQty - : ( - (itemDiscountPrice*fixedQty / - (newPrice > 0 ? newPrice : editedProduct?.OrderRate)) * 100 - ) + ? itemDiscountPrice * fixedQty + : ((itemDiscountPrice * fixedQty) / + (newPrice > 0 ? newPrice : editedProduct?.OrderRate)) * + 100, } - : { + : { DiscountAmt: null, DiscountType: null, - DiscountValue: null - } - ) - + DiscountValue: null, + }), }; if (hasOffer) { @@ -3221,17 +3256,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 ) ) @@ -3256,7 +3291,6 @@ const BSBillingEditQuantity = (props) => { OfferMessage: updatedProduct?.OfferMessage || bestOffer?.OfferMessage, }; - console.log(updatedProduct, 'updatedProduct'); const shouldRemove = (c) => @@ -3268,10 +3302,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); @@ -3299,9 +3333,9 @@ const BSBillingEditQuantity = (props) => { isOfferApply = false, }) => { const { OfferType = null, OfferPrice = 0 } = product; - - let totalAmount = qty * rate; - totalAmount = totalAmount - (itemDiscountPrice*qty|| 0); + + let totalAmount = qty * rate; + totalAmount = totalAmount - (itemDiscountPrice * qty || 0); const taxAmount = ( (totalAmount * taxPercentage) / (100 + taxPercentage) @@ -3317,7 +3351,7 @@ const BSBillingEditQuantity = (props) => { return { TotalAmt: type === 'C' && OfferPrice > 0 - ? totalAmount - (offerValue || 0) + ? totalAmount - (offerValue || 0) : totalAmount, TaxAmt: parseFloat(taxAmount), WithoutTaxRate: parseFloat(withoutTaxRate), @@ -3327,6 +3361,8 @@ const BSBillingEditQuantity = (props) => { const CloseModal = () => { props.handleEditQuantityCancel(); setClearQuantity(false); + dispatch(changeCombofocus(false)); + dispatch(changefocusStatusCust(false)); }; const onComplete = useCallback(() => { setMessageData(null); @@ -3347,12 +3383,13 @@ const BSBillingEditQuantity = (props) => { 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); + 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)); @@ -3364,7 +3401,8 @@ const BSBillingEditQuantity = (props) => { } } else { if (parseFloat(enteredDiscount) < 100) { - let discountAmt = (parseFloat(enteredDiscount) * parseFloat(sellingPrice)) / 100; + let discountAmt = + (parseFloat(enteredDiscount) * parseFloat(sellingPrice)) / 100; setItemDiscountPrice(parseFloat(discountAmt)); } else { setMessageType('error'); @@ -3379,8 +3417,13 @@ const BSBillingEditQuantity = (props) => { }; const PriceChangefun = (data) => { const enteredDiscount = parseFloat(data?.target.value); - - // Clear ItemDiscount field and reset discount price + const value = data?.target?.value; + if (value === '') { + setEditedPrice(''); + setDisableSubmitButton(false); + formRef.current?.resetFields(); + return; + } setItemDiscountPrice(0); itemDiscountFormRef.current?.resetFields(); @@ -3490,11 +3533,20 @@ const BSBillingEditQuantity = (props) => { } } else { setDisableSubmitButton(false); - setEditedPrice(0); + setEditedPrice(''); formRef.current?.resetFields(); } }; const SellingPriceChange = (data) => { + if (data === '') { + setEditedPrice(''); + setDisableSubmitButton(false); + formRef.current?.setFieldsValue({ SellPrice: '' }); + + setItemDiscountPrice(''); + itemDiscountFormRef.current?.resetFields(); + return; + } if (data) { const sellingPrice = parseFloat(props.Productdata?.SellingPrice || 0); const limit = parseFloat(props.Productdata?.DiscountLimit || 0); @@ -3580,16 +3632,21 @@ 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 (