same product offer message display
This commit is contained in:
parent
e69d2844ff
commit
7f0f1112f8
|
|
@ -522,7 +522,15 @@ const BSBillingEditQuantity = (props) => {
|
||||||
cartItem?.InwardDtlId === editedProduct?.InwardDtlId &&
|
cartItem?.InwardDtlId === editedProduct?.InwardDtlId &&
|
||||||
cartItem?.OrderRate === editedProduct?.OrderRate &&
|
cartItem?.OrderRate === editedProduct?.OrderRate &&
|
||||||
cartItem?.BookingTypeName === editedProduct?.BookingTypeName &&
|
cartItem?.BookingTypeName === editedProduct?.BookingTypeName &&
|
||||||
!cartItem?.SalesId
|
!cartItem?.SalesId && ((cartItem?.OfferModeType && cartItem?.OfferMode === 'B'
|
||||||
|
? true
|
||||||
|
: cartItem?.OfferMode !== 'B') &&
|
||||||
|
cartItem?.OfferMode !== 'P' &&
|
||||||
|
cartItem?.OfferMode !== 'C' &&
|
||||||
|
cartItem?.OfferMode !== 'O' &&
|
||||||
|
cartItem?.OfferMode !== 'L'
|
||||||
|
? true
|
||||||
|
: cartItem?.Offer === 0)
|
||||||
);
|
);
|
||||||
// changing for one piece stock checking
|
// changing for one piece stock checking
|
||||||
const isItemInCartfilter = CartOrderDetails?.filter(
|
const isItemInCartfilter = CartOrderDetails?.filter(
|
||||||
|
|
@ -530,7 +538,15 @@ const BSBillingEditQuantity = (props) => {
|
||||||
cartItem?.ProdId === editedProduct?.ProdId &&
|
cartItem?.ProdId === editedProduct?.ProdId &&
|
||||||
cartItem?.InwardDtlId === editedProduct?.InwardDtlId &&
|
cartItem?.InwardDtlId === editedProduct?.InwardDtlId &&
|
||||||
cartItem?.OrderRate !== editedProduct?.OrderRate &&
|
cartItem?.OrderRate !== editedProduct?.OrderRate &&
|
||||||
!cartItem?.SalesId
|
!cartItem?.SalesId && ((cartItem?.OfferModeType && cartItem?.OfferMode === 'B'
|
||||||
|
? true
|
||||||
|
: cartItem?.OfferMode !== 'B') &&
|
||||||
|
cartItem?.OfferMode !== 'P' &&
|
||||||
|
cartItem?.OfferMode !== 'C' &&
|
||||||
|
cartItem?.OfferMode !== 'O' &&
|
||||||
|
cartItem?.OfferMode !== 'L'
|
||||||
|
? true
|
||||||
|
: cartItem?.Offer === 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
const isItemInCartHold = CartOrderDetails?.find(
|
const isItemInCartHold = CartOrderDetails?.find(
|
||||||
|
|
@ -538,7 +554,15 @@ const BSBillingEditQuantity = (props) => {
|
||||||
cartItem?.ProdId === editedProduct?.ProdId &&
|
cartItem?.ProdId === editedProduct?.ProdId &&
|
||||||
cartItem?.InwardDtlId === editedProduct.InwardDtlId &&
|
cartItem?.InwardDtlId === editedProduct.InwardDtlId &&
|
||||||
cartItem?.OrderRate === editedProduct?.OrderRate &&
|
cartItem?.OrderRate === editedProduct?.OrderRate &&
|
||||||
cartItem?.BookingTypeName === editedProduct?.BookingTypeName
|
cartItem?.BookingTypeName === editedProduct?.BookingTypeName && ((cartItem?.OfferModeType && cartItem?.OfferMode === 'B'
|
||||||
|
? true
|
||||||
|
: cartItem?.OfferMode !== 'B') &&
|
||||||
|
cartItem?.OfferMode !== 'P' &&
|
||||||
|
cartItem?.OfferMode !== 'C' &&
|
||||||
|
cartItem?.OfferMode !== 'O' &&
|
||||||
|
cartItem?.OfferMode !== 'L'
|
||||||
|
? true
|
||||||
|
: cartItem?.Offer === 0)
|
||||||
); // check if the item is already in the cart
|
); // check if the item is already in the cart
|
||||||
const isItemInCartHoldfilter = CartOrderDetails?.filter(
|
const isItemInCartHoldfilter = CartOrderDetails?.filter(
|
||||||
(cartItem) =>
|
(cartItem) =>
|
||||||
|
|
@ -547,7 +571,15 @@ const BSBillingEditQuantity = (props) => {
|
||||||
!(
|
!(
|
||||||
(cartItem?.OrderRate === editedProduct?.OrderRate)
|
(cartItem?.OrderRate === editedProduct?.OrderRate)
|
||||||
// && cartItem?.BookingTypeName === editedProduct?.BookingTypeName
|
// && cartItem?.BookingTypeName === editedProduct?.BookingTypeName
|
||||||
)
|
) && ((cartItem?.OfferModeType && cartItem?.OfferMode === 'B'
|
||||||
|
? true
|
||||||
|
: cartItem?.OfferMode !== 'B') &&
|
||||||
|
cartItem?.OfferMode !== 'P' &&
|
||||||
|
cartItem?.OfferMode !== 'C' &&
|
||||||
|
cartItem?.OfferMode !== 'O' &&
|
||||||
|
cartItem?.OfferMode !== 'L'
|
||||||
|
? true
|
||||||
|
: cartItem?.Offer === 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
|
|
@ -3155,7 +3155,7 @@ const BSBillingTable3 = (Props) => {
|
||||||
} = section;
|
} = section;
|
||||||
|
|
||||||
if (!data?.length) return null;
|
if (!data?.length) return null;
|
||||||
|
console.log(data, "OrderCart")
|
||||||
// ── Disabled check ──────────────────────────────────────────────────────────
|
// ── Disabled check ──────────────────────────────────────────────────────────
|
||||||
const isDisabled = (item) => {
|
const isDisabled = (item) => {
|
||||||
if (isOld) {
|
if (isOld) {
|
||||||
|
|
@ -3427,7 +3427,7 @@ const BSBillingTable3 = (Props) => {
|
||||||
<p
|
<p
|
||||||
className={`offermessageTag ${!isMobile ? 'desktop' : ''}`}
|
className={`offermessageTag ${!isMobile ? 'desktop' : ''}`}
|
||||||
>
|
>
|
||||||
{item.OfferMessage?.split('>')?.[0] +
|
{item?.OfferModeType === true ? item.OfferMessage : item.OfferMessage?.split('>')?.[0] +
|
||||||
`> ${item?.OrderQty} Eligible Free`}
|
`> ${item?.OrderQty} Eligible Free`}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -2671,6 +2671,7 @@ const BSItemCard = (props) => {
|
||||||
let OfferNeedToApply = true;
|
let OfferNeedToApply = true;
|
||||||
let updatedFreeProductList = [];
|
let updatedFreeProductList = [];
|
||||||
let sameProduct = false;
|
let sameProduct = false;
|
||||||
|
let TotalDiscount = 0;
|
||||||
for (const offer of offers) {
|
for (const offer of offers) {
|
||||||
if (offer.OfferMode === 'B') {
|
if (offer.OfferMode === 'B') {
|
||||||
const {
|
const {
|
||||||
|
|
@ -2679,6 +2680,7 @@ const BSItemCard = (props) => {
|
||||||
OfferApply,
|
OfferApply,
|
||||||
updatedFreeProdList,
|
updatedFreeProdList,
|
||||||
ProductOfferType,
|
ProductOfferType,
|
||||||
|
otherTotalDiscount
|
||||||
} = applyBuyNGetFreeOffer(cartData, offer, item);
|
} = applyBuyNGetFreeOffer(cartData, offer, item);
|
||||||
|
|
||||||
offer.OfferAmount = OfferAmount;
|
offer.OfferAmount = OfferAmount;
|
||||||
|
|
@ -2686,6 +2688,7 @@ const BSItemCard = (props) => {
|
||||||
OfferNeedToApply = OfferApply;
|
OfferNeedToApply = OfferApply;
|
||||||
updatedFreeProductList = updatedFreeProdList;
|
updatedFreeProductList = updatedFreeProdList;
|
||||||
sameProduct = ProductOfferType;
|
sameProduct = ProductOfferType;
|
||||||
|
TotalDiscount = otherTotalDiscount;
|
||||||
}
|
}
|
||||||
if (!bestOffer || offer.OfferAmount > bestOffer.OfferAmount) {
|
if (!bestOffer || offer.OfferAmount > bestOffer.OfferAmount) {
|
||||||
bestOffer = offer;
|
bestOffer = offer;
|
||||||
|
|
@ -2701,9 +2704,9 @@ const BSItemCard = (props) => {
|
||||||
? bestOffer?.OfferAmount || item.Offer
|
? bestOffer?.OfferAmount || item.Offer
|
||||||
: item.Offer || bestOffer?.OfferAmount,
|
: item.Offer || bestOffer?.OfferAmount,
|
||||||
OfferType: item?.OfferType || bestOffer?.OfferType,
|
OfferType: item?.OfferType || bestOffer?.OfferType,
|
||||||
OfferMessage: item?.OfferMessage || bestOffer?.OfferMessage,
|
OfferMessage: sameProduct ? (bestOffer?.OfferMessage || item?.OfferMessage) : (item?.OfferMessage || bestOffer?.OfferMessage),
|
||||||
OfferMode: item?.OfferMode || bestOffer?.OfferMode,
|
OfferMode: item?.OfferMode || bestOffer?.OfferMode,
|
||||||
OfferModeType: sameProduct,
|
OfferModeType: sameProduct
|
||||||
};
|
};
|
||||||
|
|
||||||
const shouldRemove = (c) =>
|
const shouldRemove = (c) =>
|
||||||
|
|
@ -2728,6 +2731,12 @@ const BSItemCard = (props) => {
|
||||||
: [...filteredCart, UpdatedCartItemWithOffer];
|
: [...filteredCart, UpdatedCartItemWithOffer];
|
||||||
|
|
||||||
if (bestOffer && OfferNeedToApply) {
|
if (bestOffer && OfferNeedToApply) {
|
||||||
|
if (TotalDiscount > 0) {
|
||||||
|
bestOffer = {
|
||||||
|
...bestOffer,
|
||||||
|
OfferAmount: TotalDiscount
|
||||||
|
}
|
||||||
|
}
|
||||||
dispatch(ChangeOfferAppliedProducts(bestOffer));
|
dispatch(ChangeOfferAppliedProducts(bestOffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3117,6 +3126,7 @@ const BSItemCard = (props) => {
|
||||||
|
|
||||||
function applyBuyNGetFreeOffer(cartItem, offer, item) {
|
function applyBuyNGetFreeOffer(cartItem, offer, item) {
|
||||||
const freeList = offer.FreeProductsList || [];
|
const freeList = offer.FreeProductsList || [];
|
||||||
|
let otherTotalDiscount = 0;
|
||||||
let totalDiscount = 0;
|
let totalDiscount = 0;
|
||||||
let offerMessage = '';
|
let offerMessage = '';
|
||||||
let OfferApply = true;
|
let OfferApply = true;
|
||||||
|
|
@ -3170,20 +3180,45 @@ const BSItemCard = (props) => {
|
||||||
0.5;
|
0.5;
|
||||||
sameProductOffer = true;
|
sameProductOffer = true;
|
||||||
} else if (isSameProduct) {
|
} else if (isSameProduct) {
|
||||||
// 🔥 Buy N Get M (same product)
|
// 🔥 Buy N Get N (same product)
|
||||||
const buyQty = offer.BuyQty || 1;
|
const totalQty = freeCartItem?.reduce(
|
||||||
|
(acc, fc) => acc + (fc?.OrderQty || 0),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
const buyQty = offer.MinQty || 1;
|
||||||
const getQty = freeProd.FreeQty || 0;
|
const getQty = freeProd.FreeQty || 0;
|
||||||
|
|
||||||
const cycleSize = buyQty + getQty;
|
const groupSize = buyQty + getQty;
|
||||||
const fullCycles = Math.floor(
|
|
||||||
freeCartItem?.reduce((acc, fc) => acc + (fc?.OrderQty || 0), 0) /
|
// ✅ Discount logic (your existing correct logic)
|
||||||
cycleSize
|
const paidQty = Math.ceil(totalQty / groupSize);
|
||||||
);
|
const totalFreeQty = totalQty - paidQty;
|
||||||
const totalFreeQty = fullCycles * getQty;
|
|
||||||
|
|
||||||
totalDiscount += totalFreeQty * freeCartItem?.[0].OrderRate;
|
totalDiscount += totalFreeQty * freeCartItem?.[0].OrderRate;
|
||||||
|
|
||||||
|
// check the offer applied for same product in different booking type
|
||||||
|
const differentBookTypeProd = freeCartItem?.filter((prod) => prod?.BookingTypeName !== item?.BookingTypeName && (prod?.Offer || 0) > 0 && prod?.OfferMode === offer?.OfferMode);
|
||||||
|
if (differentBookTypeProd?.length > 0) {
|
||||||
|
const diffBookTypeDis = differentBookTypeProd?.reduce(
|
||||||
|
(acc, fc) => acc + (fc?.Offer || 0),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
otherTotalDiscount = totalDiscount;
|
||||||
|
totalDiscount = totalDiscount - diffBookTypeDis;
|
||||||
|
}
|
||||||
|
|
||||||
sameProductOffer = true;
|
sameProductOffer = true;
|
||||||
// offerMessage = `${freeProd.FreeProdName} -> ${Math.ceil(totalFreeQty / 2)} qty Free Eligible`;
|
|
||||||
|
// ✅ Message logic (NEW)
|
||||||
|
const messageGroups = Math.ceil(totalQty / groupSize);
|
||||||
|
const eligibleFreeQty = messageGroups * getQty;
|
||||||
|
|
||||||
|
|
||||||
|
offerMessage = `${freeProd.FreeProdName} -> ${eligibleFreeQty} Eligible Free`;
|
||||||
|
// offerMessage = `${freeProd.FreeProdName} ->
|
||||||
|
// ( ${paidQty} Paid + ${eligibleFreeQty} Free Eligible ). \n
|
||||||
|
// saved ₹${otherTotalDiscount > 0 ? otherTotalDiscount : totalDiscount}`;
|
||||||
} else {
|
} else {
|
||||||
// 🔥 Different product free
|
// 🔥 Different product free
|
||||||
const buyQty = offer.BuyQty || 1;
|
const buyQty = offer.BuyQty || 1;
|
||||||
|
|
@ -3283,6 +3318,7 @@ const BSItemCard = (props) => {
|
||||||
OfferApply: OfferApply,
|
OfferApply: OfferApply,
|
||||||
updatedFreeProdList: updatedFreeProdList,
|
updatedFreeProdList: updatedFreeProdList,
|
||||||
ProductOfferType: sameProductOffer ? true : false,
|
ProductOfferType: sameProductOffer ? true : false,
|
||||||
|
otherTotalDiscount: otherTotalDiscount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue