From d327930dce7e8e0ae764a089ea93e4adc563ec75 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 2 Mar 2026 12:46:12 +0530 Subject: [PATCH] Focus Issue --- .../ComboSalesBillTable.jsx | 148 +-- .../UtillComponents/BSSelectCustomer.jsx | 1076 ++++++++++++----- .../Template/BSLayout7/BSCombo1.jsx | 8 +- 3 files changed, 832 insertions(+), 400 deletions(-) diff --git a/src/Pages/BookingScreen/Components/BSBillingTables/ComboSalesBillTable/ComboSalesBillTable.jsx b/src/Pages/BookingScreen/Components/BSBillingTables/ComboSalesBillTable/ComboSalesBillTable.jsx index c419842..796158a 100644 --- a/src/Pages/BookingScreen/Components/BSBillingTables/ComboSalesBillTable/ComboSalesBillTable.jsx +++ b/src/Pages/BookingScreen/Components/BSBillingTables/ComboSalesBillTable/ComboSalesBillTable.jsx @@ -59,6 +59,7 @@ import { changePreviousOrderPayment, changePreviousOrderOfferDetail, GlobalSalesBillEdit, + changeCombofocus, } from '../../../../../Features/BookingScreen/BookingData/BookingData'; import { ChangeFullFreeProductList, @@ -158,13 +159,13 @@ const ComboSalesBillTable = () => { OrderType === 'Hold' ? tableData?.filter((a, b) => a.BookingTypeName === 'TakeAway') : tableData?.filter( - (a, b) => a.BookingTypeName === 'TakeAway' && !a?.SalesId - ); + (a, b) => a.BookingTypeName === 'TakeAway' && !a?.SalesId + ); const OldtableDataTakeAway = OrderType != 'Hold' ? tableData?.filter( - (a, b) => a.BookingTypeName === 'TakeAway' && a?.SalesId - ) + (a, b) => a.BookingTypeName === 'TakeAway' && a?.SalesId + ) : []; const [EditQuantity, setEditQuantity] = useState(false); @@ -1232,9 +1233,9 @@ const ComboSalesBillTable = () => { )?.map((item, idx) => idx === 0 ? { - ...item, - FreeQty, - } + ...item, + FreeQty, + } : item ), }; @@ -1349,7 +1350,7 @@ const ComboSalesBillTable = () => { InwardDtlId: isPaidproduct?.InwardDtlId, BuyInwardDtlId: null, Offer: 0, - OrderRate:isPaidproduct?.OrderRate + OrderRate: isPaidproduct?.OrderRate, }); } else if (isPaidproduct?.OrderQty > item?.OrderQty) { // Just Decrease Paid Qty @@ -1521,7 +1522,7 @@ const ComboSalesBillTable = () => { InwardDtlId: item?.InwardDtlId, BuyInwardDtlId: null, Offer: item?.Offer, - OrderRate:item?.OrderRate + OrderRate: item?.OrderRate, }); await ChangeFreeprodlistFn({ OverAllFreeQty: isCheckFreeProduct?.OverAllFreeQty, @@ -1600,7 +1601,7 @@ const ComboSalesBillTable = () => { InwardDtlId: item?.InwardDtlId, BuyInwardDtlId: null, Offer: item?.Offer, - OrderRate:item?.OrderRate + OrderRate: item?.OrderRate, }); await ChangeFreeprodlistFn({ OverAllFreeQty: isCheckFreeProduct?.OverAllFreeQty, @@ -1634,7 +1635,7 @@ const ComboSalesBillTable = () => { InwardDtlId: item?.InwardDtlId, BuyInwardDtlId: null, Offer: item?.Offer, - OrderRate:item?.OrderRate + OrderRate: item?.OrderRate, }); await ChangeOfferAppliedProdsFn({ inwardDtlId: item?.InwardDtlId, @@ -1666,7 +1667,7 @@ const ComboSalesBillTable = () => { InwardDtlId: isPaidProductAvailableInCart?.InwardDtlId, BuyInwardDtlId: null, Offer: 0, - OrderRate:isPaidProductAvailableInCart?.OrderRate + OrderRate: isPaidProductAvailableInCart?.OrderRate, }); } else if ( isPaidProductAvailableInCart?.OrderQty > item?.OrderQty @@ -1750,7 +1751,7 @@ const ComboSalesBillTable = () => { InwardDtlId: item?.InwardDtlId, BuyInwardDtlId: null, Offer: item?.Offer, - OrderRate: item?.OrderRate + OrderRate: item?.OrderRate, }); await ChangeFreeprodlistFn({ OverAllFreeQty: freeProdList?.OverAllFreeQty, @@ -1777,7 +1778,7 @@ const ComboSalesBillTable = () => { InwardDtlId: item?.InwardDtlId, BuyInwardDtlId: null, Offer: item?.Offer, - OrderRate: item?.OrderRate + OrderRate: item?.OrderRate, }); await ChangeFreeprodlistFn({ OverAllFreeQty: freeProdList?.OverAllFreeQty, @@ -2114,7 +2115,7 @@ const ComboSalesBillTable = () => { InwardDtlId: item?.InwardDtlId, BuyInwardDtlId: item?.InwardDtlId, Offer: item?.Offer, - OrderRate: item?.OrderRate + OrderRate: item?.OrderRate, }); await ChangeFreeprodlistFn({ OverAllFreeQty: FreeProd?.OverAllFreeQty - item?.OrderQty, @@ -2133,7 +2134,7 @@ const ComboSalesBillTable = () => { InwardDtlId: item?.InwardDtlId, BuyInwardDtlId: item?.InwardDtlId, Offer: item?.Offer, - OrderRate: item?.OrderRate + OrderRate: item?.OrderRate, }); await ChangeFreeprodlistFn({ OverAllFreeQty: item?.OrderQty, @@ -2479,11 +2480,11 @@ const ComboSalesBillTable = () => { tableDataDinein?.length >= PreviousdataLength ? 'wheat' : BookingType !== 'Dine In' && - triggerAnimation && - OldtableDataTakeAway?.length + index === 0 && - tableDataDinein?.length >= PreviousdataLength && - !HoldOrderDtl && - !UnpaidData + triggerAnimation && + OldtableDataTakeAway?.length + index === 0 && + tableDataDinein?.length >= PreviousdataLength && + !HoldOrderDtl && + !UnpaidData ? 'wheat' : 'inherit' : 'none', @@ -2491,9 +2492,9 @@ const ComboSalesBillTable = () => { row?.SalesId && OrderType !== 'Hold' ? 'rgb(243, 248, 213)' : GlobEstBooking === 'ParEst' && - GlobProdwisedata?.includes( - row?.InwardDtlId + ' ' + row?.BookingTypeName - ) + GlobProdwisedata?.includes( + row?.InwardDtlId + ' ' + row?.BookingTypeName + ) ? '#b2d1f7' : (OldtableDataTakeAway?.length + index) % 2 === 0 ? 'white' @@ -2536,44 +2537,45 @@ const ComboSalesBillTable = () => { {/* Product Name / Item */} {(item.OptionName === 'Item' || item.OptionName === 'Product Name') && ( - - row.FullProductIdentifierDtls?.length > 0 || - row.ProductIdentifierDtls?.length > 0 - ? handleImeiDetails(row) - : editField && handleEditQuantity(row) - } - > - {row?.Type !== 'OS' ? row.ProdName : row.ServiceName} - {row?.BrandName ? ` ${row.BrandName}` : ''} - {row?.Type !== 'C' && ( -

- {/* {row?.ProdVariantName} {row?.Size} {row?.UomName} */} - ( - {!row?.ProdVariantName?.toLowerCase()?.includes( - 'variant' - ) && {row?.ProdVariantName} } - {row?.Size} - {row?.SinglePc == 'Y' ? 'PCS' : row?.UomName}) + { + dispatch(changeCombofocus(true)); + row.FullProductIdentifierDtls?.length > 0 || + row.ProductIdentifierDtls?.length > 0 + ? handleImeiDetails(row) + : editField && handleEditQuantity(row); + }} + > + {row?.Type !== 'OS' ? row.ProdName : row.ServiceName} + {row?.BrandName ? ` ${row.BrandName}` : ''} + {row?.Type !== 'C' && ( +

+ {/* {row?.ProdVariantName} {row?.Size} {row?.UomName} */} + ( + {!row?.ProdVariantName?.toLowerCase()?.includes( + 'variant' + ) && {row?.ProdVariantName} } + {row?.Size} + {row?.SinglePc == 'Y' ? 'PCS' : row?.UomName}) +

+ )} + {row?.Type === 'C' && + row.ProdDetail?.map((prod, idx) => ( +

+ {prod.ProdName} - {prod.Size} {prod.UomName}

- )} - {row?.Type === 'C' && - row.ProdDetail?.map((prod, idx) => ( -

- {prod.ProdName} - {prod.Size} {prod.UomName} -

- ))} - - )} + ))} + + )} {/* Barcode */} {item.OptionName === 'Barcode' && ( @@ -2600,13 +2602,15 @@ const ComboSalesBillTable = () => { }} key={`qty-${index}`} tabIndex={0} - className={`${EditQtyCombo && row?.localId === Index + className={`${ + EditQtyCombo && row?.localId === Index ? 'EditQTYcomboTD' : 'qtyTd' - } ${isActiveCell ? 'active-cell' : ''}`} - onClick={() => - editField && handleEditQuantityCombo(row) - } + } ${isActiveCell ? 'active-cell' : ''}`} + onClick={() => { + dispatch(changeCombofocus(true)); + editField && handleEditQuantityCombo(row); + }} > {(!EditQtyCombo || row?.localId !== Index) && ( <>{row.OrderQty} @@ -2666,9 +2670,9 @@ const ComboSalesBillTable = () => { > {row?.Offer > 0 ? `${( - (row.Offer / (row?.OrderQty * row?.OrderRate)) * - 100 - ).toFixed(2)}%` + (row.Offer / (row?.OrderQty * row?.OrderRate)) * + 100 + ).toFixed(2)}%` : '-'} )} @@ -2700,8 +2704,8 @@ const ComboSalesBillTable = () => { > {allowDecimal ? Number(row.TotalAmt - (row?.Offer || 0)).toFixed( - 2 - ) + 2 + ) : Number(row.TotalAmt - (row?.Offer || 0))} )} @@ -2744,7 +2748,7 @@ const ComboSalesBillTable = () => { removeFromCart(row)} diff --git a/src/Pages/BookingScreen/Components/UtillComponents/BSSelectCustomer.jsx b/src/Pages/BookingScreen/Components/UtillComponents/BSSelectCustomer.jsx index e3367ed..58ddafc 100644 --- a/src/Pages/BookingScreen/Components/UtillComponents/BSSelectCustomer.jsx +++ b/src/Pages/BookingScreen/Components/UtillComponents/BSSelectCustomer.jsx @@ -1,4 +1,11 @@ -import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; +import { + useCallback, + useContext, + useEffect, + useMemo, + useRef, + useState, +} from 'react'; import { shallowEqual, useDispatch, useSelector } from 'react-redux'; import { GlobalCustId, @@ -18,16 +25,27 @@ import { GlobalBookingId, changeOrderCardDetails, changeCustomerID, + changeCombofocus, } from '../../../../Features/BookingScreen/BookingData/BookingData'; import Select from 'react-select'; import { getTemplateData, - StoredSessionData + StoredSessionData, } from '../../../../Features/ThemeChange/ThemeChange'; -import { MdCardMembership } from "react-icons/md"; -import { GlobalAddCustomerDetails, GlobalCustomerRefreshTrigger } from '../../../../Features/BookingScreen/Customer/addCustomer'; +import { MdCardMembership } from 'react-icons/md'; +import { + GlobalAddCustomerDetails, + GlobalCustomerRefreshTrigger, +} from '../../../../Features/BookingScreen/Customer/addCustomer'; import { getSession } from '../../../../Services/Others'; -import { FaMobile, FaRegAddressCard, FaUser, FaPlus, FaMinus, FaEye } from 'react-icons/fa'; +import { + FaMobile, + FaRegAddressCard, + FaUser, + FaPlus, + FaMinus, + FaEye, +} from 'react-icons/fa'; import { DefaultModal } from '../../../../Components/Modal/DefaultModal'; import WsPreOrderForm from '../../../Wholesalespreorder/WholesalePreorderForm'; import TooltipWrapper from '../../../../Components/Tooltip/Tooltip'; @@ -40,17 +58,30 @@ import { useApplyOfferto_CardDetail } from './BSNavBarOffer/BSNavBarOffer_Custom import { AuthContext } from '../../../../AuthContext'; import FormHeader from '../../../PageComponents/FormHeader'; import { Popover, Button, Switch } from 'antd'; -import { changeFreeProductForLoyalty, ChangeFullFreeProductList, changeFullOfferAppliedProducts, changeLoyaltyConsumedQuantities, ChangeOfferAppliedProducts, changeTriggerOfferFree, GlobalConsumedLoyaltyQuantitites, GlobalFreeProdList, GlobalOfferAppliedProducts, GlobalOverAllOfferAmt } from '../../../../Features/Offer/Offernew/BookingOffernew'; +import { + changeFreeProductForLoyalty, + ChangeFullFreeProductList, + changeFullOfferAppliedProducts, + changeLoyaltyConsumedQuantities, + ChangeOfferAppliedProducts, + changeTriggerOfferFree, + GlobalConsumedLoyaltyQuantitites, + GlobalFreeProdList, + GlobalOfferAppliedProducts, + GlobalOverAllOfferAmt, +} from '../../../../Features/Offer/Offernew/BookingOffernew'; import { Messages } from '../../../../Components/Notifications/Messages'; -import './BSSelectCustomer.scss' +import './BSSelectCustomer.scss'; import MembershipCard from './MembershipCard.jsx'; import { ApplicationPreferences } from '../../../../Features/BrachLogin/BranchLogin.js'; import FeaturesFunctionalities from '../BookingFunctionality/FeaturesFunctionalities.jsx'; const BSCustomerSelect = ({ TopName = null }) => { - const { freeProductsCount, setFreeProductsCount } = useContext(AuthContext); - const AppType = useMemo(() => getSession('AppType')?.toLowerCase() === 'wholesale', []); + const AppType = useMemo( + () => getSession('AppType')?.toLowerCase() === 'wholesale', + [] + ); const dispatch = useDispatch(); const selectRef = useRef(null); const applyOffer = useApplyOfferto_CardDetail(); @@ -80,60 +111,109 @@ const BSCustomerSelect = ({ TopName = null }) => { const GlobalAddCustomerDetails1 = useSelector(GlobalAddCustomerDetails); const selectStatuscust = useSelector(GlobalfocusStatusCust); const PreferenceDatas = useSelector(PreferenceData); - const OrderOfferDetail = useSelector(Offer.Global_OrderOfferDetail, shallowEqual); - const CoupenCodeAmount = useSelector(Offer.Global_CoupenCodeAmount, shallowEqual); - const OverallOfferAmount = useSelector(Offer.Global_OverallOfferAmount, shallowEqual); + const OrderOfferDetail = useSelector( + Offer.Global_OrderOfferDetail, + shallowEqual + ); + const CoupenCodeAmount = useSelector( + Offer.Global_CoupenCodeAmount, + shallowEqual + ); + const OverallOfferAmount = useSelector( + Offer.Global_OverallOfferAmount, + shallowEqual + ); const GlobalExtraCharge = useSelector(globalExtraTotalAmount, shallowEqual); const OrderCardDetail = useSelector(GlobalOrderCardDetails, shallowEqual); const OverAllOfferAmt = useSelector(GlobalOverAllOfferAmt, shallowEqual); - const TotalCartAmount = useMemo(() => ReausableFunctions.calculateTotal(OrderCardDetail) - OverAllOfferAmt, [OrderCardDetail, OverAllOfferAmt]); - const offerAppliedCartAmount = useMemo(() => ReausableFunctions.calculateTotal(OrderCardDetail), [OrderCardDetail]); + const TotalCartAmount = useMemo( + () => ReausableFunctions.calculateTotal(OrderCardDetail) - OverAllOfferAmt, + [OrderCardDetail, OverAllOfferAmt] + ); + const offerAppliedCartAmount = useMemo( + () => ReausableFunctions.calculateTotal(OrderCardDetail), + [OrderCardDetail] + ); const BSLayout1Data = useSelector(getTemplateData); const selOption = useSelector(GlobalSelOption); const GetCustId = useSelector(GlobalCustId); const Custdisable = useSelector(GlobalSelectedCustDisable); const SessionData = useSelector(StoredSessionData); - const OrderOfferDetails = useSelector(GlobalOfferAppliedProducts, shallowEqual); + const OrderOfferDetails = useSelector( + GlobalOfferAppliedProducts, + shallowEqual + ); const customerRefreshTrigger = useSelector(GlobalCustomerRefreshTrigger); - const consumedLoyaltyQuantities = useSelector(GlobalConsumedLoyaltyQuantitites, shallowEqual); + const consumedLoyaltyQuantities = useSelector( + GlobalConsumedLoyaltyQuantitites, + shallowEqual + ); const freeProductList = useSelector(GlobalFreeProdList, shallowEqual); const appPreferences = useSelector(ApplicationPreferences); const commonModulePreference = appPreferences?.find( - (preference) => preference?.PreferredCatName === "Common Module" + (preference) => preference?.PreferredCatName === 'Common Module' )?.PreferenceCatDetails; const sportsAppPreference = commonModulePreference?.find( - (preference) => preference?.PreferredSubCatName === "SportsApp" && preference?.PreferredStatus === 'Y' + (preference) => + preference?.PreferredSubCatName === 'SportsApp' && + preference?.PreferredStatus === 'Y' ); - const { - offerOption - } = useMemo(() => { + const { offerOption } = useMemo(() => { const navbarOptions = layoutData?.BookingNavbar?.[1]; const comboOptions = layoutData?.BookingCombo1?.[1]; return { - offerOption: navbarOptions?.find( - (option) => option?.OptionName?.toLowerCase() === 'offer' - ) || comboOptions?.find( - (option) => option?.OptionName?.toLowerCase() === 'offer' - ), + offerOption: + navbarOptions?.find( + (option) => option?.OptionName?.toLowerCase() === 'offer' + ) || + comboOptions?.find( + (option) => option?.OptionName?.toLowerCase() === 'offer' + ), }; }, [layoutData]); const { totalDiscountApplied, totalPointsUsed } = useMemo(() => { - const totalDiscountApplied = OrderOfferDetails?.reduce((acc, offer) => offer?.OfferMode === 'L' && offer?.TableUniqueName === "Cash" ? acc + offer?.OfferValue : acc, 0); - const totalPointsUsed = OrderOfferDetails?.reduce((acc, offer) => offer?.OfferMode === 'L' && offer?.TableUniqueName === "Cash" ? acc + (offer?.UsedCount || 0) : acc, 0); + const totalDiscountApplied = OrderOfferDetails?.reduce( + (acc, offer) => + offer?.OfferMode === 'L' && offer?.TableUniqueName === 'Cash' + ? acc + offer?.OfferValue + : acc, + 0 + ); + const totalPointsUsed = OrderOfferDetails?.reduce( + (acc, offer) => + offer?.OfferMode === 'L' && offer?.TableUniqueName === 'Cash' + ? acc + (offer?.UsedCount || 0) + : acc, + 0 + ); return { totalDiscountApplied, totalPointsUsed }; }, [OrderOfferDetails]); const loyaltyFreeProductsInCart = useMemo(() => { - return OrderOfferDetails?.filter((offer) => (offer?.FreeProductsList?.OfferMode === 'L' || offer?.OfferMode === 'L') && (offer?.FreeProductsList?.TableUniqueName === "FreeProduct" || offer?.TableUniqueName === "FreeProduct")) || []; + return ( + OrderOfferDetails?.filter( + (offer) => + (offer?.FreeProductsList?.OfferMode === 'L' || + offer?.OfferMode === 'L') && + (offer?.FreeProductsList?.TableUniqueName === 'FreeProduct' || + offer?.TableUniqueName === 'FreeProduct') + ) || [] + ); }, [OrderOfferDetails]); const filteredLoyaltyFreeProducts = useMemo(() => { - return freeProductList?.filter((product) => product.OfferMode === 'L' && product?.TableUniqueName === "FreeProduct"); + return freeProductList?.filter( + (product) => + product.OfferMode === 'L' && product?.TableUniqueName === 'FreeProduct' + ); }, [freeProductList]); // Calculate total discount value of free products const totalFreeProductDiscount = useMemo(() => { - return loyaltyFreeProductsInCart.reduce((total, product) => total + product.OfferAmount, 0); + return loyaltyFreeProductsInCart.reduce( + (total, product) => total + product.OfferAmount, + 0 + ); }, [loyaltyFreeProductsInCart]); // Calculate cart value based on keepFreeProducts selection @@ -141,9 +221,13 @@ const BSCustomerSelect = ({ TopName = null }) => { if (loyaltyFreeProductsInCart.length > 0 && keepFreeProducts === 'yes') { return (TotalCartAmount || 0) + (totalFreeProductDiscount || 0); } - return (TotalCartAmount || 0); - }, [TotalCartAmount, totalFreeProductDiscount, keepFreeProducts, loyaltyFreeProductsInCart.length]); - + return TotalCartAmount || 0; + }, [ + TotalCartAmount, + totalFreeProductDiscount, + keepFreeProducts, + loyaltyFreeProductsInCart.length, + ]); const preferenceshortcutkey = PreferenceDatas?.[0]?.[ 'SettingDtlDetails' @@ -162,14 +246,16 @@ const BSCustomerSelect = ({ TopName = null }) => { useEffect(() => { dispatch(getAllCustomer({ CompId, AppId, branchId: BranchId })) .unwrap() - .then(res => setAllCustomers(res?.data?.data || [])); + .then((res) => setAllCustomers(res?.data?.data || [])); setProductQuantities({}); }, [CompId, AppId, BranchId, dispatch, customerRefreshTrigger]); // Options for Select const options = useMemo(() => { - const source = allCustomers.length ? allCustomers : GlobalAddCustomerDetails1; - return source.map(item => ({ + const source = allCustomers.length + ? allCustomers + : GlobalAddCustomerDetails1; + return source.map((item) => ({ value: item.CustMobile, label: AppType ? item?.CustShortName || item?.CustName || item?.CustMobile @@ -193,14 +279,20 @@ const BSCustomerSelect = ({ TopName = null }) => { }, [allCustomers, GlobalAddCustomerDetails1, AppType]); // Selected customer data - const selectedCustomerData = useMemo(() => (GetCustId ? { - value: GetCustId?.CustMobile, - label: GetCustId?.CustName || GetCustId?.CustMobile, - CustId: GetCustId?.CustId, - CustName: GetCustId?.CustName, - } : null), [GetCustId]); + const selectedCustomerData = useMemo( + () => + GetCustId + ? { + value: GetCustId?.CustMobile, + label: GetCustId?.CustName || GetCustId?.CustMobile, + CustId: GetCustId?.CustId, + CustName: GetCustId?.CustName, + } + : null, + [GetCustId] + ); - console.log(selOption, "selOption", selectedCustomerData) + console.log(selOption, 'selOption', selectedCustomerData); // Loyalty points const [custLoyaltyPoint, setCustLoyaltyPoint] = useState(0); @@ -210,16 +302,29 @@ const BSCustomerSelect = ({ TopName = null }) => { useEffect(() => { setCustLoyaltyPoint(selOption?.TotalLoyaltyPoints || 0); - setCashLoyaltyPoint(selOption?.LoyaltyPointsDetail?.filter(l => l?.RewardType === 'Cash') || []); - setFreeProductLoyalty(selOption?.LoyaltyPointsDetail?.filter(l => l?.RewardType === 'Free Product') || []); + setCashLoyaltyPoint( + selOption?.LoyaltyPointsDetail?.filter((l) => l?.RewardType === 'Cash') || + [] + ); + setFreeProductLoyalty( + selOption?.LoyaltyPointsDetail?.filter( + (l) => l?.RewardType === 'Free Product' + ) || [] + ); }, [selOption]); useEffect(() => { fetchFreeProducts(); - }, [freeProductLoyalty]) + }, [freeProductLoyalty]); useEffect(() => { - setBestCashLoyaltyOffer(getBestOffer(cashLoyaltyPoint, calculatedCartValue + totalDiscountApplied, custLoyaltyPoint)); + setBestCashLoyaltyOffer( + getBestOffer( + cashLoyaltyPoint, + calculatedCartValue + totalDiscountApplied, + custLoyaltyPoint + ) + ); }, [cashLoyaltyPoint, calculatedCartValue, custLoyaltyPoint]); // Calculate total consumed points @@ -228,13 +333,16 @@ const BSCustomerSelect = ({ TopName = null }) => { return 0; // ✅ return null when nothing selected } - return Object.entries(productQuantities).reduce((total, [compositeKey, quantity]) => { - const [offerId, productId, variantName] = compositeKey.split('|'); - const product = freeProducts.find( - (p) => p.ProductId === productId && p.VariantName === variantName - ); - return total + (product ? product.PointsRequired * quantity : 0); - }, 0); + return Object.entries(productQuantities).reduce( + (total, [compositeKey, quantity]) => { + const [offerId, productId, variantName] = compositeKey.split('|'); + const product = freeProducts.find( + (p) => p.ProductId === productId && p.VariantName === variantName + ); + return total + (product ? product.PointsRequired * quantity : 0); + }, + 0 + ); }, [productQuantities, freeProducts, selectedProducts]); // Calculate remaining points @@ -243,7 +351,9 @@ const BSCustomerSelect = ({ TopName = null }) => { }, [custLoyaltyPoint, totalConsumedPoints]); const appliedCashOffer = useMemo(() => { - const cashOffers = OrderOfferDetails?.filter(offer => offer?.OfferMode === 'L' && offer?.TableUniqueName === "Cash"); + const cashOffers = OrderOfferDetails?.filter( + (offer) => offer?.OfferMode === 'L' && offer?.TableUniqueName === 'Cash' + ); return cashOffers && cashOffers.length > 0 ? cashOffers[0] : null; }, [OrderOfferDetails]); @@ -264,9 +374,9 @@ const BSCustomerSelect = ({ TopName = null }) => { products.push({ OfferId: product.OfferId, - OfferMode: "L", - TableName: "LoyaltyPointsNew", - TableUniqueName: "FreeProduct", + OfferMode: 'L', + TableName: 'LoyaltyPointsNew', + TableUniqueName: 'FreeProduct', FreeProdId: product.ProductId, FreeProdName: product.ProductName, FreeProdVariantName: product.VariantName, @@ -278,7 +388,7 @@ const BSCustomerSelect = ({ TopName = null }) => { StockDetails: [ { ProdOfferId: product.ProdOfferId, - ActiveStatus: "A", + ActiveStatus: 'A', FreeInwardDtlId: product.InwardDtlId, ProdLoyaltyPoint: product.PointsRequired, EligibleFree: quantity, @@ -300,8 +410,13 @@ const BSCustomerSelect = ({ TopName = null }) => { // Keyboard shortcut useEffect(() => { - const handleKeyPress = event => { - if (!Custdisable && event.altKey && event.key === 'z' && preferenceshortcutkey) { + const handleKeyPress = (event) => { + if ( + !Custdisable && + event.altKey && + event.key === 'z' && + preferenceshortcutkey + ) { event.preventDefault(); selectRef.current?.focus(); selectRef.current?.openMenu(); @@ -312,7 +427,6 @@ const BSCustomerSelect = ({ TopName = null }) => { return () => window.removeEventListener('keydown', handleKeyPress); }, [Custdisable, preferenceshortcutkey]); - useEffect(() => { if (appliedCashOffer) { handleApplyPoints(); @@ -320,20 +434,30 @@ const BSCustomerSelect = ({ TopName = null }) => { }, [bestCashLoyaltyOffer]); useEffect(() => { - - const noProductsOtherThanLoyalty = OrderCardDetail?.every(item => item?.OfferMode === 'L'); + const noProductsOtherThanLoyalty = OrderCardDetail?.every( + (item) => item?.OfferMode === 'L' + ); if (noProductsOtherThanLoyalty && OrderCardDetail?.length > 0) { const updatedOrderCardDetails = mergeOrderCardDetails(OrderCardDetail); dispatch(changeLoyaltyConsumedQuantities({})); setProductQuantities({}); dispatch(changeOrderCardDetails(updatedOrderCardDetails)); - dispatch(changeFullOfferAppliedProducts(OrderOfferDetails?.filter(item => item.OfferMode !== 'L'))); - dispatch(ChangeFullFreeProductList(freeProductList?.filter(item => item.OfferMode !== 'L'))); - setMessageData("All free products have been removed as only loyalty products were in the cart."); - setMessageType("error"); + dispatch( + changeFullOfferAppliedProducts( + OrderOfferDetails?.filter((item) => item.OfferMode !== 'L') + ) + ); + dispatch( + ChangeFullFreeProductList( + freeProductList?.filter((item) => item.OfferMode !== 'L') + ) + ); + setMessageData( + 'All free products have been removed as only loyalty products were in the cart.' + ); + setMessageType('error'); } - }, [OrderCardDetail]); // Handle tab change with free product check @@ -349,26 +473,51 @@ const BSCustomerSelect = ({ TopName = null }) => { }; // Offer logic - const handleChange = async selectedOption => { - dispatch(changeCustomerID(selectedOption ? selectedOption?.CustId : null)) + const handleChange = async (selectedOption) => { + dispatch(changeCustomerID(selectedOption ? selectedOption?.CustId : null)); await dispatch(changefocusStatusCustMouse(false)); - const selectedcustomerId = allCustomers.find(item => item?.MobileNo === selectedOption?.value); - const offerEnabled = BSLayout1Data?.BookingNavbar?.[1]?.some(s => s.OptionName === 'Offer') && - PreferenceDatas?.[0]?.SettingDtlDetails?.find(item => item.SettingIdName === 'Offer')?.SettingValue === 'Y'; + const selectedcustomerId = allCustomers.find( + (item) => item?.MobileNo === selectedOption?.value + ); + const offerEnabled = + BSLayout1Data?.BookingNavbar?.[1]?.some( + (s) => s.OptionName === 'Offer' + ) && + PreferenceDatas?.[0]?.SettingDtlDetails?.find( + (item) => item.SettingIdName === 'Offer' + )?.SettingValue === 'Y'; if (offerEnabled) { setCustLoyaltyPoint(selectedOption?.TotalLoyaltyPoints || 0); - setCashLoyaltyPoint(selectedOption?.LoyaltyPointsDetail?.filter(l => l?.RewardType === 'Cash') || []); - setFreeProductLoyalty(selectedOption?.LoyaltyPointsDetail?.filter(l => l?.RewardType === 'Free Product') || []); + setCashLoyaltyPoint( + selectedOption?.LoyaltyPointsDetail?.filter( + (l) => l?.RewardType === 'Cash' + ) || [] + ); + setFreeProductLoyalty( + selectedOption?.LoyaltyPointsDetail?.filter( + (l) => l?.RewardType === 'Free Product' + ) || [] + ); const filteredOrderOfferDetails = OrderOfferDetails?.filter( - item => item.TableName === 'LoyaltyPoints' && item.TableUniqueName === 'UniqueId' && item.Type === 'A' + (item) => + item.TableName === 'LoyaltyPoints' && + item.TableUniqueName === 'UniqueId' && + item.Type === 'A' ); const witoutLoyaltyPointsOrderOfferDetails = OrderOfferDetails?.filter( - item => !(item.TableName === 'LoyaltyPoints' && item.TableUniqueName === 'UniqueId' && item.Type === 'A') + (item) => + !( + item.TableName === 'LoyaltyPoints' && + item.TableUniqueName === 'UniqueId' && + item.Type === 'A' + ) ); await applyOffer( OrderCardDetail, - filteredOrderOfferDetails?.length > 0 ? witoutLoyaltyPointsOrderOfferDetails : OrderOfferDetails, + filteredOrderOfferDetails?.length > 0 + ? witoutLoyaltyPointsOrderOfferDetails + : OrderOfferDetails, selectedOption ); } @@ -376,9 +525,17 @@ const BSCustomerSelect = ({ TopName = null }) => { await dispatch(changeSelectedOption(selectedOption)); await dispatch(changeSelectedCustId(selectedcustomerId?.CustId)); await dispatch(ChangeSearchFocusPreOrder(false)); - await dispatch(ChangeFullFreeProductList(freeProductList?.filter(item => item.OfferMode !== 'L'))); - if (OrderOfferDetails?.some(item => item.OfferMode === 'L')) { - await dispatch(changeFullOfferAppliedProducts(OrderOfferDetails?.filter(item => item.OfferMode !== 'L'))); + await dispatch( + ChangeFullFreeProductList( + freeProductList?.filter((item) => item.OfferMode !== 'L') + ) + ); + if (OrderOfferDetails?.some((item) => item.OfferMode === 'L')) { + await dispatch( + changeFullOfferAppliedProducts( + OrderOfferDetails?.filter((item) => item.OfferMode !== 'L') + ) + ); } setCustomerpreorder(true); }; @@ -394,7 +551,10 @@ const BSCustomerSelect = ({ TopName = null }) => { let remainingCart = cartValue; let totalDiscount = 0; let totalPointsUsed = 0; - while (remainingPoints >= offer.ExchangePoint && remainingCart - offer.RewardValue >= 1) { + while ( + remainingPoints >= offer.ExchangePoint && + remainingCart - offer.RewardValue >= 1 + ) { remainingPoints -= offer.ExchangePoint; remainingCart -= offer.RewardValue; totalDiscount += offer.RewardValue; @@ -420,10 +580,19 @@ const BSCustomerSelect = ({ TopName = null }) => { } // Handle quantity change - const handleQuantityChange = (offerId, productId, variantName, prodOfferId, change) => { + const handleQuantityChange = ( + offerId, + productId, + variantName, + prodOfferId, + change + ) => { const compositeKey = `${offerId}|${productId}|${variantName}|${prodOfferId}`; - const product = freeProducts.find(p => - p.ProductId === productId && p.VariantName === variantName && p.ProdOfferId === prodOfferId + const product = freeProducts.find( + (p) => + p.ProductId === productId && + p.VariantName === variantName && + p.ProdOfferId === prodOfferId ); if (!product) return; @@ -433,76 +602,86 @@ const BSCustomerSelect = ({ TopName = null }) => { const pointsForNewQuantity = product.PointsRequired * newQuantity; // Calculate points used by other products - const otherProductsPoints = totalConsumedPoints - - (product.PointsRequired * currentQuantity); + const otherProductsPoints = + totalConsumedPoints - product.PointsRequired * currentQuantity; // Check if new quantity would exceed available points if (otherProductsPoints + pointsForNewQuantity <= custLoyaltyPoint) { - setProductQuantities(prev => ({ + setProductQuantities((prev) => ({ ...prev, - [compositeKey]: newQuantity + [compositeKey]: newQuantity, })); } }; // Custom styles for Select - const customStyles = useMemo(() => ({ - container: provided => ({ ...provided, position: 'relative' }), - control: (provided, state) => ({ - ...provided, - boxShadow: 'none', - fontFamily: 'Gilroy', - fontWeight: AppType ? '400' : '600', - width: AppType ? '93px' : '168px', - backgroundColor: AppType ? 'transparent' : 'white', - color: AppType ? 'white' : 'black', - borderRadius: '6px', - border: AppType ? 'none' : '1px solid #d9d9d9', - '&:hover': { borderBottomColor: '#1292ee', borderRadius: '6px' }, - }), - option: (provided, state) => ({ - ...provided, - backgroundColor: - state.data?.value === selOption?.value - ? AppType ? '#439FCD' : '#52c41a' - : state.isFocused - ? '#1292ee' - : 'white', - color: state.isFocused ? 'black' : 'black', - borderRadius: '6px', - '&:hover': { - backgroundColor: state.isSelected ? '#52c41a' : AppType ? '#439FCD' : '#1292ee', - color: 'white', + const customStyles = useMemo( + () => ({ + container: (provided) => ({ ...provided, position: 'relative' }), + control: (provided, state) => ({ + ...provided, + boxShadow: 'none', + fontFamily: 'Gilroy', + fontWeight: AppType ? '400' : '600', + width: AppType ? '93px' : '168px', + backgroundColor: AppType ? 'transparent' : 'white', + color: AppType ? 'white' : 'black', borderRadius: '6px', - }, + border: AppType ? 'none' : '1px solid #d9d9d9', + '&:hover': { borderBottomColor: '#1292ee', borderRadius: '6px' }, + }), + option: (provided, state) => ({ + ...provided, + backgroundColor: + state.data?.value === selOption?.value + ? AppType + ? '#439FCD' + : '#52c41a' + : state.isFocused + ? '#1292ee' + : 'white', + color: state.isFocused ? 'black' : 'black', + borderRadius: '6px', + '&:hover': { + backgroundColor: state.isSelected + ? '#52c41a' + : AppType + ? '#439FCD' + : '#1292ee', + color: 'white', + borderRadius: '6px', + }, + }), + indicatorSeparator: () => ({ display: 'none' }), + placeholder: (provided) => ({ + ...provided, + color: AppType ? 'white' : 'blue', + fontSize: '12px', + }), + singleValue: (provided) => ({ + ...provided, + color: AppType ? 'white' : '#52C41A', + }), + menu: (provided) => ({ + ...provided, + boxShadow: + '0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1)', + borderRadius: '6px', + backgroundColor: '#E6F4FF', + background: 'white', + fontFamily: 'Gilroy', + fontWeight: '600', + }), }), - indicatorSeparator: () => ({ display: 'none' }), - placeholder: provided => ({ - ...provided, - color: AppType ? 'white' : 'blue', - fontSize: '12px', - }), - singleValue: provided => ({ - ...provided, - color: AppType ? 'white' : '#52C41A', - }), - menu: provided => ({ - ...provided, - boxShadow: '0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1)', - borderRadius: '6px', - backgroundColor: '#E6F4FF', - background: 'white', - fontFamily: 'Gilroy', - fontWeight: '600', - }), - }), [AppType, selOption]); + [AppType, selOption] + ); // Loyalty modal free products fetch (stub) const fetchFreeProducts = () => { const products = []; - freeProductLoyalty.forEach(offer => { - offer.FreeProductsList?.forEach(prod => { - prod.ProdVariantDetails?.forEach(variant => { - variant.StockDetails?.forEach(stock => { + freeProductLoyalty.forEach((offer) => { + offer.FreeProductsList?.forEach((prod) => { + prod.ProdVariantDetails?.forEach((variant) => { + variant.StockDetails?.forEach((stock) => { products.push({ OfferId: offer.OfferId, TableName: offer.TableName, @@ -516,7 +695,7 @@ const BSCustomerSelect = ({ TopName = null }) => { VariantName: variant.ProdVariantName, FullProductName: `${prod.FreeProdName} - ${variant.ProdVariantName}`, StockAvailable: prod?.StockAvailable, - BalanceQty: stock?.BalanceQty + BalanceQty: stock?.BalanceQty, }); }); }); @@ -535,105 +714,141 @@ const BSCustomerSelect = ({ TopName = null }) => { if (bestCashLoyaltyOffer?.discount === 0) { return; } - const orderOfferDetail = [{ - OfferId: bestCashLoyaltyOffer?.offerId || '', - OfferAmount: bestCashLoyaltyOffer?.discount || 0, - OfferValue: bestCashLoyaltyOffer?.discount || 0, - TableName: bestCashLoyaltyOffer?.tableName, - TableUniqueName: bestCashLoyaltyOffer?.tableUniqueName, - TableUniqueId: '', - Type: '', - BookingType, - OfferType: ['Cash', 'Free Product'].includes(bestCashLoyaltyOffer?.offerType) ? 'L' : null, - OfferMode: ['Cash', 'Free Product'].includes(bestCashLoyaltyOffer?.offerType) ? 'L' : null, - Detail: [{}], - CustId: selOption?.CustId, - UsedCount: bestCashLoyaltyOffer?.pointsUsed || 0, - }]; + const orderOfferDetail = [ + { + OfferId: bestCashLoyaltyOffer?.offerId || '', + OfferAmount: bestCashLoyaltyOffer?.discount || 0, + OfferValue: bestCashLoyaltyOffer?.discount || 0, + TableName: bestCashLoyaltyOffer?.tableName, + TableUniqueName: bestCashLoyaltyOffer?.tableUniqueName, + TableUniqueId: '', + Type: '', + BookingType, + OfferType: ['Cash', 'Free Product'].includes( + bestCashLoyaltyOffer?.offerType + ) + ? 'L' + : null, + OfferMode: ['Cash', 'Free Product'].includes( + bestCashLoyaltyOffer?.offerType + ) + ? 'L' + : null, + Detail: [{}], + CustId: selOption?.CustId, + UsedCount: bestCashLoyaltyOffer?.pointsUsed || 0, + }, + ]; let updatedOrderCardDetails = OrderCardDetail || []; // Handle free products if (loyaltyFreeProductsInCart.length > 0) { if (keepFreeProducts === 'no') { - updatedOrderCardDetails = updatedOrderCardDetails.filter(item => item?.OfferMode !== 'L'); + updatedOrderCardDetails = updatedOrderCardDetails.filter( + (item) => item?.OfferMode !== 'L' + ); } else if (keepFreeProducts === 'yes') { - updatedOrderCardDetails = mergeOrderCardDetails(updatedOrderCardDetails); + updatedOrderCardDetails = mergeOrderCardDetails( + updatedOrderCardDetails + ); } setFreeProductsInCart([]); } // Common dispatches dispatch(changeOrderCardDetails(updatedOrderCardDetails)); - dispatch(changeFullOfferAppliedProducts(OrderOfferDetails?.filter(item => item.OfferMode !== 'L'))); + dispatch( + changeFullOfferAppliedProducts( + OrderOfferDetails?.filter((item) => item.OfferMode !== 'L') + ) + ); dispatch(ChangeOfferAppliedProducts(orderOfferDetail)); - dispatch(ChangeFullFreeProductList(freeProductList?.filter(item => item.OfferMode !== 'L'))); + dispatch( + ChangeFullFreeProductList( + freeProductList?.filter((item) => item.OfferMode !== 'L') + ) + ); setLoyaltyModal(false); }; const handleClearOffer = () => { // Remove the applied cash loyalty offer const updatedOrderOfferDetails = OrderOfferDetails?.filter( - offer => !(offer?.OfferMode === 'L' && offer?.TableUniqueName === "Cash") + (offer) => + !(offer?.OfferMode === 'L' && offer?.TableUniqueName === 'Cash') ); - let updatedOrderCardDetails = OrderCardDetail?.map(item => { - if (item?.OfferMode === 'L') { - return { - ...item, - Offer: null, - OfferMessage: undefined, - OfferMode: undefined, - OfferModeType: false, - OfferType: undefined, - OfferValue: null, + let updatedOrderCardDetails = + OrderCardDetail?.map((item) => { + if (item?.OfferMode === 'L') { + return { + ...item, + Offer: null, + OfferMessage: undefined, + OfferMode: undefined, + OfferModeType: false, + OfferType: undefined, + OfferValue: null, + }; + } else { + return item; } - } else { - return item - } - }) || []; + }) || []; dispatch(changeOrderCardDetails(updatedOrderCardDetails)); dispatch(changeFullOfferAppliedProducts(updatedOrderOfferDetails)); setLoyaltyModal(false); }; - // Handle free products redemption const handleRedeemFreeProducts = () => { if (selectedProducts.length > 0) { - selectedProducts.forEach(product => { - const alreadyExists = freeProductList?.find((f) => f.FreeProdId === product.FreeProdId && - f.OfferId === product.OfferId && - f.OfferMode === product.OfferMode && f.FreeProdVariantName === product.FreeProdVariantName - ) + selectedProducts.forEach((product) => { + const alreadyExists = freeProductList?.find( + (f) => + f.FreeProdId === product.FreeProdId && + f.OfferId === product.OfferId && + f.OfferMode === product.OfferMode && + f.FreeProdVariantName === product.FreeProdVariantName + ); if (alreadyExists) { if (alreadyExists?.OverAllFreeQty === product?.OverAllFreeQty) { - return + return; } else if (alreadyExists?.OverAllFreeQty < product?.OverAllFreeQty) { - const remainingQty = product?.OverAllFreeQty - alreadyExists?.OverAllFreeQty; - dispatch(changeFreeProductForLoyalty({ - ...alreadyExists, - OverAllFreeQty: alreadyExists?.OverAllFreeQty + remainingQty, - RemainingQty: alreadyExists?.RemainingQty + remainingQty - })); + const remainingQty = + product?.OverAllFreeQty - alreadyExists?.OverAllFreeQty; + dispatch( + changeFreeProductForLoyalty({ + ...alreadyExists, + OverAllFreeQty: alreadyExists?.OverAllFreeQty + remainingQty, + RemainingQty: alreadyExists?.RemainingQty + remainingQty, + }) + ); } else if (alreadyExists?.OverAllFreeQty > product?.OverAllFreeQty) { - const qtyDiff = alreadyExists?.OverAllFreeQty - product?.OverAllFreeQty; + const qtyDiff = + alreadyExists?.OverAllFreeQty - product?.OverAllFreeQty; if (alreadyExists?.OverAllFreeQty === alreadyExists?.RemainingQty) { - dispatch(changeFreeProductForLoyalty({ - ...alreadyExists, - RemainingQty: alreadyExists?.RemainingQty - qtyDiff - })) + dispatch( + changeFreeProductForLoyalty({ + ...alreadyExists, + RemainingQty: alreadyExists?.RemainingQty - qtyDiff, + }) + ); } else if (alreadyExists?.FreeQty === product?.OverAllFreeQty) { - dispatch(changeFreeProductForLoyalty({ - ...alreadyExists, - RemainingQty: 0, - })) + dispatch( + changeFreeProductForLoyalty({ + ...alreadyExists, + RemainingQty: 0, + }) + ); } else if (alreadyExists?.FreeQty > product?.OverAllFreeQty) { - dispatch(changeFreeProductForLoyalty({ - ...alreadyExists, - FreeQty: alreadyExists?.FreeQty - qtyDiff, - OverAllFreeQty: alreadyExists?.OverAllFreeQty - qtyDiff, - })) + dispatch( + changeFreeProductForLoyalty({ + ...alreadyExists, + FreeQty: alreadyExists?.FreeQty - qtyDiff, + OverAllFreeQty: alreadyExists?.OverAllFreeQty - qtyDiff, + }) + ); } } } else { @@ -677,17 +892,18 @@ const BSCustomerSelect = ({ TopName = null }) => { const mergeOrderCardDetails = (orderDetails) => { const merged = []; - orderDetails.forEach(item => { + orderDetails.forEach((item) => { if (item?.OfferMode === 'L') { const { OfferMode, OfferMessage, ...rest } = item; merged.push({ ...rest, Offer: 0 }); } else { - const idx = merged.findIndex(o => - o?.ProdId === item?.ProdId && - o?.InwardDtlId === item?.InwardDtlId && - o?.OrderRate === item?.OrderRate && - o?.BookingType === item?.BookingType && - !o.SalesId + const idx = merged.findIndex( + (o) => + o?.ProdId === item?.ProdId && + o?.InwardDtlId === item?.InwardDtlId && + o?.OrderRate === item?.OrderRate && + o?.BookingType === item?.BookingType && + !o.SalesId ); if (idx !== -1) { merged[idx] = { @@ -705,33 +921,41 @@ const BSCustomerSelect = ({ TopName = null }) => { return merged; }; - const handleClearFreeProducts = (keepProduct) => { - let updatedOrderCardDetails = OrderCardDetail || []; if (keepProduct === 'yes') { updatedOrderCardDetails = mergeOrderCardDetails(updatedOrderCardDetails); } else if (keepProduct === 'no') { - updatedOrderCardDetails = updatedOrderCardDetails.filter(item => item?.OfferMode !== 'L'); + updatedOrderCardDetails = updatedOrderCardDetails.filter( + (item) => item?.OfferMode !== 'L' + ); } dispatch(changeOrderCardDetails(updatedOrderCardDetails)); setClearPopoverVisible(false); - dispatch(ChangeFullFreeProductList(freeProductList.filter(item => item.OfferMode !== 'L'))); - dispatch(changeFullOfferAppliedProducts(OrderOfferDetails?.filter(item => { - // if OfferMode exists and is 'L' → remove - if (item?.OfferMode && item.OfferMode === 'L') return false; - - // if FreeProductsList OfferMode exists and is 'L' → remove - if ( - item?.FreeProductsList?.OfferMode && - item.FreeProductsList.OfferMode === 'L' + dispatch( + ChangeFullFreeProductList( + freeProductList.filter((item) => item.OfferMode !== 'L') ) - return false; + ); + dispatch( + changeFullOfferAppliedProducts( + OrderOfferDetails?.filter((item) => { + // if OfferMode exists and is 'L' → remove + if (item?.OfferMode && item.OfferMode === 'L') return false; - return true; - }))); + // if FreeProductsList OfferMode exists and is 'L' → remove + if ( + item?.FreeProductsList?.OfferMode && + item.FreeProductsList.OfferMode === 'L' + ) + return false; + + return true; + }) + ) + ); setSelectedProducts([]); setProductQuantities({}); }; @@ -751,7 +975,6 @@ const BSCustomerSelect = ({ TopName = null }) => { setMessageType(null); }, []); - // Render return ( <> @@ -762,10 +985,17 @@ const BSCustomerSelect = ({ TopName = null }) => { />
{(selOption || selectedCustomerData?.CustId) && selOption?.value && ( - +
- {String(selOption?.value || selectedCustomerData?.value)} + {' '} + {String(selOption?.value || selectedCustomerData?.value)}
{selOption?.CustName && (
@@ -773,19 +1003,42 @@ const BSCustomerSelect = ({ TopName = null }) => {
)}
- {String(selOption?.CustId).match(/-(\d+)$/)?.[1]} + {' '} + {String(selOption?.CustId).match(/-(\d+)$/)?.[1]}
-
- {(offerOption && (PreferenceDatas?.[0]?.['SettingDtlDetails']?.find( - (item) => item.SettingIdName === 'Offer' - )?.SettingValue === 'Y')) &&
0 ? handleLoyaltyPoints : () => { setMessageData("Add products to cart to redeem loyalty points."); setMessageType("error"); }}> - {custLoyaltyPoint || 0} -
} - {sportsAppPreference &&
selOption?.MembershipDetail?.length > 0 && setmembershipModal(true)}> - {/* {custLoyaltyPoint || 0} */} -
} +
+ {offerOption && + PreferenceDatas?.[0]?.['SettingDtlDetails']?.find( + (item) => item.SettingIdName === 'Offer' + )?.SettingValue === 'Y' && ( +
0 + ? handleLoyaltyPoints + : () => { + setMessageData( + 'Add products to cart to redeem loyalty points.' + ); + setMessageType('error'); + } + } + > + {custLoyaltyPoint || 0} +
+ )} + {sportsAppPreference && ( +
+ selOption?.MembershipDetail?.length > 0 && + setmembershipModal(true) + } + > + {/* {custLoyaltyPoint || 0} */} +
+ )}
-
)} @@ -806,17 +1059,28 @@ const BSCustomerSelect = ({ TopName = null }) => { isSearchable styles={customStyles} menuPosition="fixed" - value={AppType ? null : selOption || (selectedCustomerData?.label ? selectedCustomerData : null)} + value={ + AppType + ? null + : selOption || + (selectedCustomerData?.label ? selectedCustomerData : null) + } onChange={handleChange} - onMenuClose={() => dispatch(changefocusStatusCust(!selectStatuscust))} + onMenuOpen={() => dispatch(changeCombofocus(true))} + onMenuClose={() => { + dispatch(changefocusStatusCust(!selectStatuscust)); + dispatch(changeCombofocus(false)); + }} isDisabled={Custdisable} - className='customer-select-option' + className="customer-select-option" onInputChange={(value) => { if (!value) return; const isIndianMobile = /^\d{10}$/.test(value) && /^[6-9]/.test(value); - const existingCustomer = options?.filter((option) => option?.value === value || option?.label === value) + const existingCustomer = options?.filter( + (option) => option?.value === value || option?.label === value + ); if (isIndianMobile && existingCustomer?.length === 0) { handleAddCustomer(value); } @@ -867,7 +1131,13 @@ const BSCustomerSelect = ({ TopName = null }) => { {redemptionType === 'cash' && (
-
+

Cash Redemption

@@ -877,19 +1147,35 @@ const BSCustomerSelect = ({ TopName = null }) => { {/* Show free product handling options when there are free products in cart */} {freeProductsInCart.length > 0 && ( -
-
- You have {freeProductsInCart.length} free product(s) in your cart. What would you like to do? +
+
+ You have {freeProductsInCart.length} free product(s) in your + cart. What would you like to do?
-
-
- Note: If you choose "Yes", the cart value for cash calculation will include the discount value of free products. - If you choose "No", the free products will be removed from your cart. +
+ Note: If you choose "Yes", the cart value + for cash calculation will include the discount value of free + products. If you choose "No", the free products will be + removed from your cart.
)} @@ -932,7 +1232,10 @@ const BSCustomerSelect = ({ TopName = null }) => { // Show applied offer details <>

- Offer Applied for the Cart Value: ₹{(offerAppliedCartAmount || 0) - (OverAllOfferAmt || 0) + (totalDiscountApplied || 0)} + Offer Applied for the Cart Value: ₹ + {(offerAppliedCartAmount || 0) - + (OverAllOfferAmt || 0) + + (totalDiscountApplied || 0)}

@@ -945,7 +1248,7 @@ const BSCustomerSelect = ({ TopName = null }) => { className="loyalty-btn clear-btn" style={{ background: '#ff4d4f', - color: 'white' + color: 'white', }} onClick={handleClearOffer} > @@ -957,17 +1260,28 @@ const BSCustomerSelect = ({ TopName = null }) => { <>

Cart Value: ₹{calculatedCartValue} - {loyaltyFreeProductsInCart.length > 0 && keepFreeProducts === 'yes' && ( - - (includes ₹{totalFreeProductDiscount} from free products) - - )} + {loyaltyFreeProductsInCart.length > 0 && + keepFreeProducts === 'yes' && ( + + (includes ₹{totalFreeProductDiscount} from free + products) + + )}

- You can apply up to {bestCashLoyaltyOffer?.pointsUsed || 0} points + You can apply up to{' '} + {bestCashLoyaltyOffer?.pointsUsed || 0}{' '} + points

- Discount to be applied: ₹{bestCashLoyaltyOffer?.discount || 0} + Discount to be applied:{' '} + ₹{bestCashLoyaltyOffer?.discount || 0}

{ )} {redemptionType === 'free' && (
-
+

Choose Free Products

@@ -992,12 +1314,24 @@ const BSCustomerSelect = ({ TopName = null }) => {
-
+
Consumed: {totalConsumedPoints} points - + Remaining: {remainingPoints} points
@@ -1011,7 +1345,7 @@ const BSCustomerSelect = ({ TopName = null }) => { color: 'white', display: 'flex', alignItems: 'center', - gap: '5px' + gap: '5px', }} onClick={() => setViewModal(true)} > @@ -1021,20 +1355,22 @@ const BSCustomerSelect = ({ TopName = null }) => {
{ - if (totalConsumedPoints === 0 || remainingPoints < 0) return; + if (totalConsumedPoints === 0 || remainingPoints < 0) + return; handleRedeemFreeProducts(); }} > Redeem All
-
)} -
{freeProducts.length > 0 ? ( @@ -1043,15 +1379,23 @@ const BSCustomerSelect = ({ TopName = null }) => { const compositeKey = `${prod.OfferId}|${prod.ProductId}|${prod.VariantName}|${prod?.ProdOfferId}`; const quantity = productQuantities[compositeKey] || 0; const canIncrease = - totalConsumedPoints + prod.PointsRequired <= custLoyaltyPoint && - (prod?.StockAvailable === 'Y' ? quantity < prod.BalanceQty : true); + totalConsumedPoints + prod.PointsRequired <= + custLoyaltyPoint && + (prod?.StockAvailable === 'Y' + ? quantity < prod.BalanceQty + : true); const canDecrease = quantity > 0; const remainingStock = - prod.StockAvailable === 'Y' ? prod.BalanceQty - quantity : null; + prod.StockAvailable === 'Y' + ? prod.BalanceQty - quantity + : null; return (
- + {prod.FullProductName} @@ -1060,33 +1404,51 @@ const BSCustomerSelect = ({ TopName = null }) => { {/* Show stock info only if StockAvailable === 'Y' */} {prod.StockAvailable === 'Y' && ( - - Stock: {remainingStock} / {prod.BalanceQty} available + + Stock: {remainingStock} / {prod.BalanceQty}{' '} + available )} -
+
{ if (canDecrease) { - handleQuantityChange(prod.OfferId, prod.ProductId, prod.VariantName, prod?.ProdOfferId, -1); + handleQuantityChange( + prod.OfferId, + prod.ProductId, + prod.VariantName, + prod?.ProdOfferId, + -1 + ); } }} >
- - {quantity} - + {quantity}
{ if (canIncrease) { - handleQuantityChange(prod.OfferId, prod.ProductId, prod.VariantName, prod?.ProdOfferId, 1); + handleQuantityChange( + prod.OfferId, + prod.ProductId, + prod.VariantName, + prod?.ProdOfferId, + 1 + ); } }} > @@ -1105,19 +1467,29 @@ const BSCustomerSelect = ({ TopName = null }) => { })}
) : ( -

No free products available for your points.

+

+ No free products available for your points. +

)} - {(filteredLoyaltyFreeProducts?.length > 0 || loyaltyFreeProductsInCart?.length > 0) && ( + {(filteredLoyaltyFreeProducts?.length > 0 || + loyaltyFreeProductsInCart?.length > 0) && (
- You have free products for loyalty points in cart.
+ You have free products for loyalty points in cart. +
Do you want to keep them?
-
+