diff --git a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx index 9e5df58..6a86902 100644 --- a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx +++ b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx @@ -12,6 +12,9 @@ import { GlobalReorderProductDetails, PreferenceData, getConfigType, + changefocusStatusCust, + changeCombofocus, + GlobalfocusStatusCust, } from '../../../../../Features/BookingScreen/BookingData/BookingData'; import { ArrowRightOutlined } from '@ant-design/icons'; import { Messages } from '../../../../../Components/Notifications/Messages'; @@ -50,7 +53,7 @@ const BSBillingEditQuantity = (props) => { const priceChangeInputRef = useRef(null); const reductionInputRef = useRef(null); - const { setIndex = () => { } } = props; + const { setIndex = () => {} } = props; const [disableSubmitButton, setDisableSubmitButton] = useState(false); const SessionData = useSelector(StoredSessionData); @@ -66,13 +69,24 @@ 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' @@ -86,7 +100,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); @@ -115,7 +129,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]) { @@ -343,7 +357,6 @@ const BSBillingEditQuantity = (props) => { }; const calculateOverAllQty = (item, filterItems) => { - if (!item) return 0; const totalUsedQty = @@ -446,11 +459,18 @@ 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; } @@ -722,11 +742,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) => @@ -750,7 +771,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 ); @@ -884,7 +905,7 @@ const BSBillingEditQuantity = (props) => { cartItem?.InwardDtlId === editedProduct?.InwardDtlId && cartItem?.OrderRate === editedProduct?.OrderRate && cartItem?.BookingTypeName !== - editedProduct?.BookingTypeName && + editedProduct?.BookingTypeName && !cartItem?.OfferMode && cartItem?.Offer === 0 ); @@ -898,7 +919,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 ); @@ -1031,7 +1052,7 @@ const BSBillingEditQuantity = (props) => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { const freeQty = @@ -1064,7 +1085,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) { @@ -1147,7 +1168,7 @@ const BSBillingEditQuantity = (props) => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { return { @@ -1177,7 +1198,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) { @@ -1364,7 +1385,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) { @@ -1466,7 +1487,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) { @@ -1620,7 +1641,7 @@ const BSBillingEditQuantity = (props) => { ) && cartItem?.Offer && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -1909,11 +1930,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, @@ -1947,11 +1968,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 @@ -2092,7 +2113,7 @@ const BSBillingEditQuantity = (props) => { cartItem?.Offer > 0 && isFreeProductApplicable?.OfferMode === cartItem?.OfferMode && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -2195,11 +2216,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 ) { @@ -2270,12 +2291,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, @@ -2309,13 +2330,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 @@ -2397,11 +2418,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 ) { @@ -2454,11 +2475,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 ) { @@ -2547,11 +2568,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 ) { @@ -2580,11 +2601,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 ) { @@ -2614,11 +2635,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 ) { @@ -2717,12 +2738,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, @@ -2756,12 +2777,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 @@ -2840,11 +2861,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 ) { @@ -2903,11 +2924,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 ) { @@ -2979,12 +3000,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, @@ -3018,12 +3039,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 @@ -3178,17 +3199,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 ) ) @@ -3224,10 +3245,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); @@ -3481,16 +3502,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 (