same product offer message display

This commit is contained in:
unknown 2026-03-26 09:35:26 +05:30
parent e69d2844ff
commit 7f0f1112f8
3 changed files with 412 additions and 344 deletions

View File

@ -522,7 +522,15 @@ const BSBillingEditQuantity = (props) => {
cartItem?.InwardDtlId === editedProduct?.InwardDtlId &&
cartItem?.OrderRate === editedProduct?.OrderRate &&
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
const isItemInCartfilter = CartOrderDetails?.filter(
@ -530,7 +538,15 @@ const BSBillingEditQuantity = (props) => {
cartItem?.ProdId === editedProduct?.ProdId &&
cartItem?.InwardDtlId === editedProduct?.InwardDtlId &&
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(
@ -538,7 +554,15 @@ const BSBillingEditQuantity = (props) => {
cartItem?.ProdId === editedProduct?.ProdId &&
cartItem?.InwardDtlId === editedProduct.InwardDtlId &&
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
const isItemInCartHoldfilter = CartOrderDetails?.filter(
(cartItem) =>
@ -547,7 +571,15 @@ const BSBillingEditQuantity = (props) => {
!(
(cartItem?.OrderRate === editedProduct?.OrderRate)
// && 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 (

View File

@ -3155,7 +3155,7 @@ const BSBillingTable3 = (Props) => {
} = section;
if (!data?.length) return null;
console.log(data, "OrderCart")
// Disabled check
const isDisabled = (item) => {
if (isOld) {
@ -3427,7 +3427,7 @@ const BSBillingTable3 = (Props) => {
<p
className={`offermessageTag ${!isMobile ? 'desktop' : ''}`}
>
{item.OfferMessage?.split('>')?.[0] +
{item?.OfferModeType === true ? item.OfferMessage : item.OfferMessage?.split('>')?.[0] +
`> ${item?.OrderQty} Eligible Free`}
</p>
)}

View File

@ -2671,6 +2671,7 @@ const BSItemCard = (props) => {
let OfferNeedToApply = true;
let updatedFreeProductList = [];
let sameProduct = false;
let TotalDiscount = 0;
for (const offer of offers) {
if (offer.OfferMode === 'B') {
const {
@ -2679,6 +2680,7 @@ const BSItemCard = (props) => {
OfferApply,
updatedFreeProdList,
ProductOfferType,
otherTotalDiscount
} = applyBuyNGetFreeOffer(cartData, offer, item);
offer.OfferAmount = OfferAmount;
@ -2686,6 +2688,7 @@ const BSItemCard = (props) => {
OfferNeedToApply = OfferApply;
updatedFreeProductList = updatedFreeProdList;
sameProduct = ProductOfferType;
TotalDiscount = otherTotalDiscount;
}
if (!bestOffer || offer.OfferAmount > bestOffer.OfferAmount) {
bestOffer = offer;
@ -2701,9 +2704,9 @@ const BSItemCard = (props) => {
? bestOffer?.OfferAmount || item.Offer
: item.Offer || bestOffer?.OfferAmount,
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,
OfferModeType: sameProduct,
OfferModeType: sameProduct
};
const shouldRemove = (c) =>
@ -2728,6 +2731,12 @@ const BSItemCard = (props) => {
: [...filteredCart, UpdatedCartItemWithOffer];
if (bestOffer && OfferNeedToApply) {
if (TotalDiscount > 0) {
bestOffer = {
...bestOffer,
OfferAmount: TotalDiscount
}
}
dispatch(ChangeOfferAppliedProducts(bestOffer));
}
@ -3117,6 +3126,7 @@ const BSItemCard = (props) => {
function applyBuyNGetFreeOffer(cartItem, offer, item) {
const freeList = offer.FreeProductsList || [];
let otherTotalDiscount = 0;
let totalDiscount = 0;
let offerMessage = '';
let OfferApply = true;
@ -3170,20 +3180,45 @@ const BSItemCard = (props) => {
0.5;
sameProductOffer = true;
} else if (isSameProduct) {
// 🔥 Buy N Get M (same product)
const buyQty = offer.BuyQty || 1;
// 🔥 Buy N Get N (same product)
const totalQty = freeCartItem?.reduce(
(acc, fc) => acc + (fc?.OrderQty || 0),
0
);
const buyQty = offer.MinQty || 1;
const getQty = freeProd.FreeQty || 0;
const cycleSize = buyQty + getQty;
const fullCycles = Math.floor(
freeCartItem?.reduce((acc, fc) => acc + (fc?.OrderQty || 0), 0) /
cycleSize
);
const totalFreeQty = fullCycles * getQty;
const groupSize = buyQty + getQty;
// Discount logic (your existing correct logic)
const paidQty = Math.ceil(totalQty / groupSize);
const totalFreeQty = totalQty - paidQty;
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;
// 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 {
// 🔥 Different product free
const buyQty = offer.BuyQty || 1;
@ -3283,6 +3318,7 @@ const BSItemCard = (props) => {
OfferApply: OfferApply,
updatedFreeProdList: updatedFreeProdList,
ProductOfferType: sameProductOffer ? true : false,
otherTotalDiscount: otherTotalDiscount,
};
}