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();
|
||||
|
|
@ -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'
|
||||
|
|
@ -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();
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
export const calculateOverAllQtyLimit = (orders) => {
|
||||
return orders?.reduce((acc, cartItem) => {
|
||||
return acc + (cartItem?.OrderQty || 0);
|
||||
}, 0)
|
||||
}
|
||||
Loading…
Reference in New Issue