diff --git a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx index 4a3942d..d309960 100644 --- a/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx +++ b/src/Pages/BookingScreen/Components/BSBillingTables/BSBillingEditQuantity/BSBillingEditQuantity.jsx @@ -41,6 +41,7 @@ import { import { validateOffers } from '../../BSItemCards/ValidateOffer.jsx'; import { v4 as uuidv4 } from 'uuid'; import WeightCalculatePrice from './WeightCalculatePrice.jsx'; +import { calculateOverAllQtyLimit } from '../../../../../utils/calculations.js'; const BSBillingEditQuantity = (props) => { const dispatch = useDispatch(); @@ -49,7 +50,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); @@ -64,6 +65,14 @@ const BSBillingEditQuantity = (props) => { (state) => state?.BookingOFferNew?.OverAllProductBasedProducts, 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 preferenceOffer = preferenceDatas?.[0]?.['SettingDtlDetails']?.find( (item) => item.SettingIdName === 'Offer' @@ -103,23 +112,23 @@ const BSBillingEditQuantity = (props) => { const OrderType = useSelector(GlobalOrderType); const [BillOrderPre, setBillOrderPre] = useState(null); const SHORTKEY_TO_RADIO = { - price: 'Price', - quantity: 'qty', - Parcel: 'Parcel', - weightAmount: 'weightAmount' -}; -const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { - if (props?.shortKeyMethod && SHORTKEY_TO_RADIO[props.shortKeyMethod]) { - return SHORTKEY_TO_RADIO[props.shortKeyMethod]; - } - if (ItemData?.ScaleType !== 'weight') { - return 'Quantity'; - } - if (PriceChangeaccess) { - return 'Price'; - } - return 'Parcel'; -}); + price: 'Price', + quantity: 'qty', + Parcel: 'Parcel', + weightAmount: 'weightAmount' + }; + const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { + if (props?.shortKeyMethod && SHORTKEY_TO_RADIO[props.shortKeyMethod]) { + return SHORTKEY_TO_RADIO[props.shortKeyMethod]; + } + if (ItemData?.ScaleType !== 'weight') { + return 'Quantity'; + } + if (PriceChangeaccess) { + return 'Price'; + } + return 'Parcel'; + }); // const [RadioBtnSelection, setRadioBtnSelection] = useState( // props?.shortKeyMethod == 'price' // ? 'Price' @@ -334,6 +343,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { }; const calculateOverAllQty = (item, filterItems) => { + if (!item) return 0; const totalUsedQty = @@ -435,6 +445,18 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { (e) => e?.localId == localId ); const editedProduct = CartOrderDetails[editedProductIndex]; + + 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}`); + setMessageType('warning'); + return; + } + } + } + const productBookingType = editedProduct?.BookingTypeName; const isItemInCart = CartOrderDetails?.find( (cartItem) => @@ -728,7 +750,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ); @@ -862,7 +884,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { cartItem?.InwardDtlId === editedProduct?.InwardDtlId && cartItem?.OrderRate === editedProduct?.OrderRate && cartItem?.BookingTypeName !== - editedProduct?.BookingTypeName && + editedProduct?.BookingTypeName && !cartItem?.OfferMode && cartItem?.Offer === 0 ); @@ -876,7 +898,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { cartItem?.InwardDtlId === editedProduct?.InwardDtlId && cartItem?.OrderRate === editedProduct?.OrderRate && cartItem?.BookingTypeName !== - editedProduct?.BookingTypeName && + editedProduct?.BookingTypeName && cartItem?.OfferMode === editedProduct?.OfferMode && cartItem?.Offer > 0 ); @@ -1009,7 +1031,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { const freeQty = @@ -1042,7 +1064,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1125,7 +1147,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { ) ) && product?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && product?.OfferMode === editedProduct?.OfferMode ) { return { @@ -1155,7 +1177,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1342,7 +1364,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1444,7 +1466,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // Also check main offer conditions const isMatchingOffer = offerProduct?.OfferId === - editedProduct?.OfferMessage?.[0]?.OfferId && + editedProduct?.OfferMessage?.[0]?.OfferId && offerProduct?.OfferMode === editedProduct?.OfferMode; if (hasMatchingFreeProduct && isMatchingOffer) { @@ -1598,7 +1620,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { ) && cartItem?.Offer && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -1887,11 +1909,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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, @@ -1925,11 +1947,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // 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 @@ -2070,7 +2092,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { cartItem?.Offer > 0 && isFreeProductApplicable?.OfferMode === cartItem?.OfferMode && isFreeProductApplicable?.OfferId === - cartItem?.OfferMessage?.[0]?.OfferId + cartItem?.OfferMessage?.[0]?.OfferId ); } ); @@ -2173,11 +2195,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2248,12 +2270,12 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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, @@ -2287,13 +2309,13 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // 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 @@ -2375,11 +2397,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2432,11 +2454,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2525,11 +2547,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2558,11 +2580,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2592,11 +2614,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2695,12 +2717,12 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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, @@ -2734,12 +2756,12 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // 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 @@ -2818,11 +2840,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2881,11 +2903,11 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) { @@ -2957,12 +2979,12 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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, @@ -2996,12 +3018,12 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // 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 @@ -3156,17 +3178,17 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { 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 ) ) @@ -3202,10 +3224,10 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { ((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); @@ -3397,8 +3419,8 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { // parseFloat(enteredDiscount) < parseFloat(sellingPrice) || // parseFloat(enteredDiscount) === parseFloat(sellingPrice) // ) { - setEditedPrice(enteredDiscount); - setDisableSubmitButton(true); + setEditedPrice(enteredDiscount); + setDisableSubmitButton(true); // } else { // setMessageType('error'); // setMessageData('Please Give less than value for sell price'); @@ -3467,8 +3489,8 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => { setClearQuantity(false); }; const isKg = - props?.Productdata?.Size == 1 && - ["KG", "KGS"].includes(props?.Productdata?.UomName?.toUpperCase()); + props?.Productdata?.Size == 1 && + ["KG", "KGS"].includes(props?.Productdata?.UomName?.toUpperCase()); return (