import { useEffect, useState, useMemo } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { FaChartLine, FaRupeeSign } from 'react-icons/fa'; import { Badge, DatePicker, Popconfirm, Tooltip } from 'antd'; import { isMobile } from 'react-device-detect'; import { ApplicationPreferences } from '../../../Features/BrachLogin/BranchLogin'; import { getPreferenceData, GlobalOrderStatus, GlobalOtherSevices, GlobalSalesDetailData, } from '../../../Features/BookingScreen/BookingData/BookingData'; import { extractLastNumberOrderId, getSession } from '../../../Services/Others'; import { useDateStore } from '../../../Features/BookingScreen/BookingData/DateStore'; import dayjs from 'dayjs'; import moment from 'moment'; import { BsUiChecks } from 'react-icons/bs'; import { FaCheckToSlot } from 'react-icons/fa6'; import PozoKioskIcon from '../Components/UtillComponents/Pozo retail icons/PozoKioskIcon'; import { globalKioskSalesCount } from '../../../Features/Kiosk/kiosk'; import BSKioskCounterPayment from '../Components/UtillComponents/BSKioskCounterPayment'; import BSExpireProductsList from '../Components/UtillComponents/BSExpireProductsList'; import TooltipWrapper from '../../../Components/Tooltip/Tooltip'; import { StoredSessionData } from '../../../Features/ThemeChange/ThemeChange'; import BookingCloseIcon from '../Components/UtillComponents/BookingCloseIcon'; import RetailBookingClosing from './RetailBookingClose'; import { getBookingStatus, GlobalBookingStatus, } from '../../../Features/Payment/PaymentReceivedRetail/PaymentReceivedRetail'; import { PutBookingClose } from '../../../Features/BookingScreen/RetailBookingClose'; import BSEwayBillicon from '../../BookingScreen/Components/UtillComponents/BSEwayBillicon.jsx'; import ListOfSalesInvoices from '../Components/BSBillingTables/ListofInvoices/ListOfSalesInvoices.jsx'; import { DefaultModal } from '../../../Components/Modal/DefaultModal.jsx'; const SalesCountForStandard = ({ DineInAccess, GlobalsalesDetailData, PricingAppPricingName, }) => { const dispatch = useDispatch(); const AppId = getSession('AppId'); const CompId = getSession('CompId'); const BranchId = getSession('BranchId'); const UserId = getSession('UserId'); const [allowDecimal, setAllowDecimal] = useState(false); const [BookingModalOpen, setBookingModalOpen] = useState(false); const [ListOfInvoices, setListOfInvoices] = useState(false); const { selectedDate, setSelectedDate } = useDateStore(); const [Kioskopen, setKioskopen] = useState(false); const badgeCount = useSelector(globalKioskSalesCount); const OtherServicesglobal = useSelector(GlobalOtherSevices); const appPreferences = useSelector(ApplicationPreferences); const SessionData = useSelector(StoredSessionData); const OrderStatus = useSelector(GlobalOrderStatus); const dailySalesData = useSelector(GlobalSalesDetailData); const [isModalOpen, setIsModalOpen] = useState(false); const [isNetAmtModalOpen, setIsNetAmtModalOpen] = useState(false); const bookings = dailySalesData?.[0]?.BookedDetails; const orderDetails = dailySalesData?.[0]?.OrderDetails; const [currentPage, setCurrentPage] = useState(1); const rowsPerPage = 10; const totalPages = Math.ceil((bookings?.length || 0) / rowsPerPage); const startIndex = (currentPage - 1) * rowsPerPage; const currentData = bookings?.slice(startIndex, startIndex + rowsPerPage); console.log(dailySalesData, 'dailySalesDatadailySalesData', bookings); const bookingTypePreference = appPreferences?.find((p) => p?.PreferredCatName === 'Booking Type') ?.PreferenceCatDetails || []; const dinePreference = bookingTypePreference.find( (p) => p?.PreferredSubCatName?.toLowerCase() === 'dine in' && p?.PreferredStatus === 'Y' ); const takeAwayPreference = bookingTypePreference.find( (p) => p?.PreferredSubCatName?.toLowerCase() === 'take away' && p?.PreferredStatus === 'Y' ); const commonModulePreference = appPreferences?.find( (preference) => preference?.PreferredCatName === 'Common Module' )?.PreferenceCatDetails; const sportsAppPreference = commonModulePreference?.find( (preference) => preference?.PreferredSubCatName === 'SportsApp' && preference?.PreferredStatus === 'Y' ); const salespagefields = appPreferences?.find( (pref) => pref?.PreferredCatName === 'Sales Page Fields' )?.PreferenceCatDetails; const AvailableDate = salespagefields?.find( (type) => type?.PreferredSubCatName?.toLowerCase() === 'available date' && type?.PreferredStatus === 'Y' ); const { isBulk, setIsBulk } = useDateStore(); const BookingStatus = useSelector(GlobalBookingStatus); const CheckBookingStatus = BookingStatus?.find((item) => item.ScreenType === 'Booking') ?.ScreenStatus ?? 'Open'; const sales = GlobalsalesDetailData?.[0] || {}; const { DineInOrderCount = 0, TakeAwayOrderCount = 0, OverAllOrderCount = 0, SelfDineInOrderCount = 0, SelfTakeAwayOrderCount = 0, DineInAmount = 0, TakeAwayAmount = 0, OverAllTakeAwayOfferAmount = 0, OverAllDineInOfferAmount = 0, SelfTakeAwayAmount = 0, SelfDineInAmount = 0, PreOrderAmount = 0, } = sales; useEffect(() => { (async () => { const { data: res } = await dispatch( getPreferenceData({ AppId, CompId, BranchId }) ).unwrap(); const decimalSetting = res?.data?.[0]?.SettingDtlDetails?.find( (s) => s?.SettingIdName?.toLowerCase() === 'decimal' && s?.SettingValue === 'Y' ); setAllowDecimal(!!decimalSetting); })(); }, []); // useEffect(() => { // if (!selectedDate || (Array.isArray(selectedDate) && selectedDate.length === 0)) { // setSelectedDate(dayjs()); // } // }, [selectedDate, setSelectedDate]); useEffect(() => { if (AppId && CompId && BranchId && UserId) { fetchBookingStatus(); } }, [AppId, CompId, BranchId, UserId]); const safeRound = (value) => { const num = Number(String(value).replace(/[^0-9.-]+/g, '')); if (isNaN(num)) return allowDecimal ? '0.00' : '0'; return allowDecimal ? num.toFixed(2) : Math.round(num).toString(); }; const disablePastDates = (current) => { return current && current < moment().startOf('day'); }; const totalTakeAway = TakeAwayAmount + SelfTakeAwayAmount + PreOrderAmount - OverAllTakeAwayOfferAmount; const totalDineIn = DineInAmount + SelfDineInAmount - OverAllDineInOfferAmount; const netAmount = totalTakeAway + totalDineIn; const showSalesTooltip = useMemo(() => { return ( DineInAccess?.SettingValue === 'Y' && DineInOrderCount + TakeAwayOrderCount + SelfTakeAwayOrderCount + SelfDineInOrderCount > 0 && (takeAwayPreference || dinePreference) ); }, [DineInAccess, sales, dinePreference, takeAwayPreference]); const renderBreakdown = (labelMap) => (
{labelMap.map( (item) => item.value !== 0 &&

{item.label}

)}
{labelMap.map( (item) => item.value !== 0 && (

{safeRound(item.value)}

) )}
Total
{safeRound( labelMap.reduce( (sum, item) => sum + (item.includeInTotal ? item.value : 0), 0 ) )}
); // Fix: Convert string dates to dayjs objects for the DatePicker const getDatePickerValue = () => { if (!selectedDate) return isBulk ? [] : null; console.log(selectedDate, 'selectedDate'); if (isBulk) { // For bulk mode, convert string array to dayjs objects array if (Array.isArray(selectedDate)) { return selectedDate.map((date) => dayjs(date)); } return []; } else { // For single date mode, handle both string and dayjs object if (Array.isArray(selectedDate) && selectedDate.length > 0) { return dayjs(selectedDate[0]); } return dayjs(selectedDate); } }; const handleDateChange = (dateOrDates) => { if (isBulk) { // For bulk mode, convert dayjs objects to string format const formattedDates = dateOrDates ? dateOrDates.map((d) => d.format('YYYY-MM-DD')) : []; setSelectedDate(formattedDates); } else { // For single date mode if (dateOrDates) { setSelectedDate(dateOrDates); } else { setSelectedDate([]); } } }; const fetchBookingStatus = async () => { let data = { CompId: CompId, BranchId: BranchId, AppId: AppId, UserId: UserId, }; await dispatch(getBookingStatus(data)); }; const BookingOpenFun = async (status) => { let Postdata = { AppId: AppId, CompId: CompId, BranchId: BranchId, UserId: UserId, ScreenType: 'Booking', ScreenStatus: status, CreatedBy: UserId, Date: new Date(), }; let Postresponse = await dispatch(PutBookingClose(Postdata)).unwrap(); if (Postresponse?.data?.statusCode === 1) { fetchBookingStatus(); } else { } }; const openModalKiosk = () => { setKioskopen(true); }; const closeModalKiosk = () => { setKioskopen(false); }; const OpenBookingModal = () => { setBookingModalOpen(true); }; const HandleBookingModalClose = () => { setBookingModalOpen(false); }; const OpenListOfInvoices = () => { setListOfInvoices(true); }; const handleInvoiceClose = () => { setListOfInvoices(false); }; return (
{/* { AvailableDate &&
{isBulk ? { setIsBulk(!isBulk); setSelectedDate([]); }} /> : { setIsBulk(!isBulk); setSelectedDate([]); }} />}
} */} {/*
{AvailableDate && !isBulk &&
} {isBulk && AvailableDate && (
)}
*/}
{showSalesTooltip ? ( {takeAwayPreference && (
Takeaway:
{TakeAwayOrderCount + SelfTakeAwayOrderCount}
)} {dinePreference && (
Dine-in:
{DineInOrderCount + SelfDineInOrderCount}
)}
} onClick={() => OverAllOrderCount || (0 > 0 && setIsModalOpen(true)) } >
{isMobile ? 'Count' : 'Sales Count'} : {OverAllOrderCount}
) : (
OverAllOrderCount || (0 > 0 && setIsModalOpen(true)) } >
{isMobile ? 'Count' : 'Sales Count'} : {OverAllOrderCount}
)}
{/* Rest of your component remains the same */} {DineInAccess?.SettingValue === 'Y' && takeAwayPreference && (TakeAwayOrderCount || SelfTakeAwayOrderCount || PreOrderAmount) > 0 && (
{isMobile ? 'TA' : 'Take Away'} :
{`₹ ${safeRound(totalTakeAway)}`}
)} {DineInAccess?.SettingValue === 'Y' && dinePreference && (DineInOrderCount || SelfDineInOrderCount) > 0 && (
{isMobile ? 'DI' : 'Dine In'} :
{`₹ ${safeRound(totalDineIn)}`}
)}
netAmount > 0 && setIsNetAmtModalOpen(true)} style={{ cursor: 'pointer' }} >
{isMobile ? 'NA' : 'Net Amount'} : ₹ {safeRound(netAmount)}
{SessionData?.FeatureAddonData?.FeatureDtls?.find( (item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales' ) && !sportsAppPreference && (
0 ? 'none' : 'auto', opacity: OrderStatus > 0 ? 0.5 : 1, }} > {!OtherServicesglobal && ( openModalKiosk()} style={{ cursor: 'pointer', fontSize: '1.5rem' }} className="iconsize" /> )}
)} {Kioskopen && ( )} {!OtherServicesglobal && !sportsAppPreference && ( {' '} )} {!OtherServicesglobal && ( <> {CheckBookingStatus == 'Open' ? (
{' '}
) : (
BookingOpenFun('Open')} > {/* */} {/* */}
)} {!sportsAppPreference && (
{''}
)} )} {BookingModalOpen && ( )} {ListOfInvoices && ( )}
{/* Modal with table for multiple bookings */} setIsModalOpen(false)} handleSubmit={() => setIsModalOpen(false)} width={700} footer={false} >
{/* */} {currentData?.length > 0 ? ( currentData?.map((item, index) => ( (e.currentTarget.style.backgroundColor = '#d6e4ff') } onMouseLeave={(e) => (e.currentTarget.style.backgroundColor = index % 2 === 0 ? '#f7faff' : '#e9f1ff') } > {/* */} )) ) : ( )}
S.No Order ID Customer Mobile Booked By Payment Type Amount (₹)
{startIndex + index + 1} {extractLastNumberOrderId(item.OrderId)} {item.CustName || '—'} {item.CustMobile || '—'} {item.BookedBy || "—"} {item.PaymentTypeName || '—'} ₹{item.Amount?.toLocaleString()}
No booking data available
{/* Pagination */} {totalPages > 1 && (
{currentPage == 1 ? ( '' ) : ( )} Page {currentPage} of {totalPages}
)}
{/* Modal with table for multiple Net Amt */} setIsNetAmtModalOpen(false)} handleSubmit={() => setIsNetAmtModalOpen(false)} width={800} footer={false} >
{orderDetails?.map((item, index) => { const total = (item.CashAmount || 0) + (item.UpiAmount || 0) + (item.CardAmount || 0) + (item.CreditAmount || 0); return ( (e.currentTarget.style.backgroundColor = '#e6f2ff') } onMouseLeave={(e) => (e.currentTarget.style.backgroundColor = index % 2 === 0 ? '#f7faff' : '#ffffff') } > ); })}
Cash UPI Card Credit Business UPI Total
Count Amt Count Amt Count Amt Count Amt Count Amt
{item.CashCount} {item.CashAmount} {item.UpiCount} {item.UpiAmount} {item.CardCount} {item.CardAmount} {item.CreditCount} {item.CreditAmount} {item.BusinessUpiCount} {item.BusinessUpiAmount} {total}
); }; export default SalesCountForStandard;