Merge pull request 'same product offer message display' (#312) from bug-fix-260326 into main

Reviewed-on: Pozomind/pozo-retail-app#312
This commit is contained in:
karthikalakshmi 2026-03-26 10:01:33 +05:30
commit 5c4f867a4a
3 changed files with 412 additions and 344 deletions

View File

@ -54,7 +54,7 @@ const BSBillingEditQuantity = (props) => {
const quantityInputRef = useRef(null);
const priceChangeInputRef = useRef(null);
const reductionInputRef = useRef(null);
const { setIndex = () => {} } = props;
const { setIndex = () => { } } = props;
const [disableSubmitButton, setDisableSubmitButton] = useState(false);
console.log(disableSubmitButton, 'disableSubmitButton');
@ -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

@ -2672,6 +2672,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 {
@ -2680,6 +2681,7 @@ const BSItemCard = (props) => {
OfferApply,
updatedFreeProdList,
ProductOfferType,
otherTotalDiscount
} = applyBuyNGetFreeOffer(cartData, offer, item);
offer.OfferAmount = OfferAmount;
@ -2687,6 +2689,7 @@ const BSItemCard = (props) => {
OfferNeedToApply = OfferApply;
updatedFreeProductList = updatedFreeProdList;
sameProduct = ProductOfferType;
TotalDiscount = otherTotalDiscount;
}
if (!bestOffer || offer.OfferAmount > bestOffer.OfferAmount) {
bestOffer = offer;
@ -2702,9 +2705,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) =>
@ -2729,6 +2732,12 @@ const BSItemCard = (props) => {
: [...filteredCart, UpdatedCartItemWithOffer];
if (bestOffer && OfferNeedToApply) {
if (TotalDiscount > 0) {
bestOffer = {
...bestOffer,
OfferAmount: TotalDiscount
}
}
dispatch(ChangeOfferAppliedProducts(bestOffer));
}
@ -3118,6 +3127,7 @@ const BSItemCard = (props) => {
function applyBuyNGetFreeOffer(cartItem, offer, item) {
const freeList = offer.FreeProductsList || [];
let otherTotalDiscount = 0;
let totalDiscount = 0;
let offerMessage = '';
let OfferApply = true;
@ -3171,20 +3181,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;
@ -3284,6 +3319,7 @@ const BSItemCard = (props) => {
OfferApply: OfferApply,
updatedFreeProdList: updatedFreeProdList,
ProductOfferType: sameProductOffer ? true : false,
otherTotalDiscount: otherTotalDiscount,
};
}