kisok quantity constrain
This commit is contained in:
parent
70444d3028
commit
608aa917b3
|
|
@ -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'
|
||||
|
|
@ -107,8 +116,8 @@ const BSBillingEditQuantity = (props) => {
|
|||
quantity: 'qty',
|
||||
Parcel: 'Parcel',
|
||||
weightAmount: 'weightAmount'
|
||||
};
|
||||
const [RadioBtnSelection, setRadioBtnSelection] = useState(() => {
|
||||
};
|
||||
const [RadioBtnSelection, setRadioBtnSelection] = useState(() => {
|
||||
if (props?.shortKeyMethod && SHORTKEY_TO_RADIO[props.shortKeyMethod]) {
|
||||
return SHORTKEY_TO_RADIO[props.shortKeyMethod];
|
||||
}
|
||||
|
|
@ -119,7 +128,7 @@ const [RadioBtnSelection, setRadioBtnSelection] = useState(() => {
|
|||
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) =>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import {
|
|||
import { validateOffers } from '../../BSItemCards/ValidateOffer.jsx';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import './ComboBillTableEdit.scss';
|
||||
import { calculateOverAllQtyLimit } from '../../../../../utils/calculations.js';
|
||||
|
||||
const ComboEditQtyAndRate = (props) => {
|
||||
const dispatch = useDispatch();
|
||||
|
|
@ -37,9 +38,9 @@ const ComboEditQtyAndRate = (props) => {
|
|||
const quantityInputRef = useRef(null);
|
||||
const priceChangeInputRef = useRef(null);
|
||||
const {
|
||||
setIndex = () => {},
|
||||
setEditQtyCombo = () => {},
|
||||
setEditRateCombo = () => {},
|
||||
setIndex = () => { },
|
||||
setEditQtyCombo = () => { },
|
||||
setEditRateCombo = () => { },
|
||||
} = props;
|
||||
|
||||
const [disableSubmitButton, setDisableSubmitButton] = useState(false);
|
||||
|
|
@ -51,10 +52,19 @@ const ComboEditQtyAndRate = (props) => {
|
|||
const applyOffer = useApplyOfferto_CardDetail();
|
||||
const preferenceDatas = useSelector(PreferenceData);
|
||||
const EmpAccessDetail = useSelector(GlobalEmpAccessDetail);
|
||||
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 OverAllproductBasedOfferDatas = useSelector(
|
||||
(state) => state?.BookingOFferNew?.OverAllProductBasedProducts,
|
||||
shallowEqual
|
||||
);
|
||||
console.log(overAllLimitPreferenece, "itemWiseLimitPreferenece")
|
||||
const preferenceOffer =
|
||||
preferenceDatas?.[0]?.['SettingDtlDetails']?.find(
|
||||
(item) => item.SettingIdName === 'Offer'
|
||||
|
|
@ -251,7 +261,16 @@ const ComboEditQtyAndRate = (props) => {
|
|||
item?.SinglePc === 'Y' ? item?.OverAllPcs : item?.BalanceQty;
|
||||
return availableQty - totalUsedQty;
|
||||
};
|
||||
|
||||
const quantityValidation = async (val) => {
|
||||
|
||||
setQuantity(val)
|
||||
|
||||
}
|
||||
const AddProductQuantity = async () => {
|
||||
// debugger
|
||||
|
||||
|
||||
let newPrice = editedPrice > 0 ? editedPrice : props.Productdata.OrderRate;
|
||||
await dispatch(changeHoldOrderDtl(false));
|
||||
await dispatch(changePreviousOrderLength(CartOrderDetails?.length));
|
||||
|
|
@ -312,6 +331,20 @@ const ComboEditQtyAndRate = (props) => {
|
|||
let editedProductIndex = CartOrderDetails?.findIndex(
|
||||
(e) => e?.localId == localId
|
||||
);
|
||||
if ((overAllLimitPreferenece || itemWiseLimitPreferenece) && maxQtyLimit) {
|
||||
if (overAllLimitPreferenece) {
|
||||
let removeProds1 = CartOrderDetails?.find((_, index) => index == editedProductIndex)
|
||||
let removeProds = CartOrderDetails?.filter((_, index) => index !== editedProductIndex)
|
||||
|
||||
const calculatedOverAllQty = calculateOverAllQtyLimit(removeProds);
|
||||
if ((calculatedOverAllQty + editedQty) > maxQtyLimit) {
|
||||
setMessageData(`Overall Quantity Limit Exceeds than ${maxQtyLimit}`);
|
||||
setMessageType('warning');
|
||||
setQuantity(removeProds1?.OrderQty || 1)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
const editedProduct = CartOrderDetails[editedProductIndex];
|
||||
const productBookingType = editedProduct?.BookingTypeName;
|
||||
const isItemInCart = CartOrderDetails?.find(
|
||||
|
|
@ -3227,7 +3260,7 @@ const ComboEditQtyAndRate = (props) => {
|
|||
type="number"
|
||||
value={Quantity}
|
||||
min="0"
|
||||
onChange={(e) => setQuantity(e.target.value)}
|
||||
onChange={(e) => quantityValidation(e.target.value)}
|
||||
onBlur={() => {
|
||||
if (Quantity && Quantity.trim() !== '') {
|
||||
AddProductQuantity();
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ import { MdOutlineAddShoppingCart } from 'react-icons/md';
|
|||
import { bulkpostdata } from '../../../../Features/ProductPage/ProductPage.js';
|
||||
import ProductPriceChange from '../UtillComponents/ProductPriceChange.jsx';
|
||||
import ExpireConfirmModal from '../BookingFunctionality/ExpireConfirmModal.jsx';
|
||||
import { calculateOverAllQtyLimit } from '../../../../utils/calculations.js';
|
||||
|
||||
export function SortableCard({ id, children, item }) {
|
||||
const {
|
||||
|
|
@ -164,6 +165,13 @@ const BSItemCard = (props) => {
|
|||
// const applyOffer = useApplyOfferto_CardDetail();
|
||||
const preferenceDatas = useSelector(PreferenceData, shallowEqual);
|
||||
const { selectedDate } = useDateStore();
|
||||
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'
|
||||
|
|
@ -180,7 +188,6 @@ const BSItemCard = (props) => {
|
|||
// GlobalAddCustomerDetails,
|
||||
// shallowEqual
|
||||
// );
|
||||
|
||||
const offerAppliedProducts = useSelector(
|
||||
GlobalOfferAppliedProducts,
|
||||
shallowEqual
|
||||
|
|
@ -2073,6 +2080,18 @@ const BSItemCard = (props) => {
|
|||
};
|
||||
|
||||
const AddOrderDetails = async (item) => {
|
||||
|
||||
if ((overAllLimitPreferenece || itemWiseLimitPreferenece) && maxQtyLimit) {
|
||||
if (overAllLimitPreferenece) {
|
||||
const calculatedOverAllQty = calculateOverAllQtyLimit(CartOrderDetails);
|
||||
if ((calculatedOverAllQty + 1) > maxQtyLimit) {
|
||||
setMessageData(`Overall Quantity Limit Exceeds than ${maxQtyLimit}`);
|
||||
setMessageType('warning');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (preOrder) {
|
||||
await handlePreOrder(item);
|
||||
} else {
|
||||
|
|
@ -3663,7 +3682,7 @@ const BSItemCard = (props) => {
|
|||
parseInt(totalSelectedProductQty || 0) +
|
||||
parseInt(reorderComboConsumed || 0);
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
let getCurrentProdDtl = orderDetails?.filter(
|
||||
(a) => a?.ProdName === ProdName
|
||||
);
|
||||
|
|
@ -3864,7 +3883,7 @@ const BSItemCard = (props) => {
|
|||
parseInt(totalSelectedProductQty || 0) +
|
||||
parseInt(reorderComboConsumed || 0);
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
let getCurrentProdDtl = orderDetails?.filter((a) => a?.ProdId === ProdId);
|
||||
let totalOrderQty = getCurrentProdDtl?.reduce((accumulator, card) => {
|
||||
return (
|
||||
|
|
@ -3900,7 +3919,7 @@ const BSItemCard = (props) => {
|
|||
}, 0);
|
||||
totalOrderQty =
|
||||
parseInt(totalOrderQty || 0) + parseInt(comboConsumed || 0);
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
let OverallProdQty = totalOrderQty - totalSelectedProductQty;
|
||||
if (
|
||||
parseInt(ItemQuantity) >
|
||||
|
|
@ -3986,7 +4005,7 @@ const BSItemCard = (props) => {
|
|||
parseInt(totalSelectedProductQty || 0) +
|
||||
parseInt(reorderComboConsumed || 0);
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
let getCurrentProdDtl = orderDetails?.filter((a) => a?.ProdId === ProdId);
|
||||
let totalOrderQty = getCurrentProdDtl?.reduce((accumulator, card) => {
|
||||
return (
|
||||
|
|
@ -4025,7 +4044,7 @@ const BSItemCard = (props) => {
|
|||
}, 0);
|
||||
totalOrderQty =
|
||||
parseInt(totalOrderQty || 0) + parseInt(comboConsumed || 0);
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
let OverallProdQty = totalOrderQty - totalSelectedProductQty;
|
||||
if (
|
||||
parseInt(ItemQuantity) >
|
||||
|
|
@ -4117,7 +4136,7 @@ const BSItemCard = (props) => {
|
|||
parseInt(totalSelectedProductQty || 0) +
|
||||
parseInt(reorderComboConsumed || 0);
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
let getCurrentProdDtl = orderDetails?.filter(
|
||||
(a) => a?.ProdId === ProdId && a?.InwardDtlId === InwardDtlId
|
||||
);
|
||||
|
|
@ -4160,7 +4179,7 @@ const BSItemCard = (props) => {
|
|||
}, 0);
|
||||
totalOrderQty =
|
||||
parseInt(totalOrderQty || 0) + parseInt(comboConsumed || 0);
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
|
||||
let OverallProdQty = totalOrderQty - totalSelectedProductQty;
|
||||
if (
|
||||
|
|
@ -4244,7 +4263,7 @@ const BSItemCard = (props) => {
|
|||
parseInt(totalSelectedProductQty || 0) +
|
||||
parseInt(reorderComboConsumed || 0);
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
let getCurrentProdDtl = orderDetails?.filter(
|
||||
(a) => a?.ProdId === ProdId && a?.InwardDtlId === InwardDtlId
|
||||
);
|
||||
|
|
@ -4291,7 +4310,7 @@ const BSItemCard = (props) => {
|
|||
}, 0);
|
||||
totalOrderQty =
|
||||
parseInt(totalOrderQty || 0) + parseInt(comboConsumed || 0);
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
|
||||
let OverallProdQty = totalOrderQty - totalSelectedProductQty;
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
export const calculateOverAllQtyLimit = (orders) => {
|
||||
return orders?.reduce((acc, cartItem) => {
|
||||
return acc + (cartItem?.OrderQty || 0);
|
||||
}, 0)
|
||||
}
|
||||
Loading…
Reference in New Issue