import React, {useCallback, useEffect, useRef, useState } from 'react'; import '../../Styles/DashBoard/RetailDashBoard.scss'; import GraphChart from './Chart/GraphChart'; import { DatePicker, Space, Tooltip } from 'antd'; import dayjs from 'dayjs'; import { IoMdRefresh } from 'react-icons/io'; import { CiShop } from 'react-icons/ci'; import { FiMenu } from 'react-icons/fi'; import PozoMind from '../../Images/pozologowhite.svg'; import { useNavigate, useOutletContext } from 'react-router-dom'; import CalendarDropdown from '../../Components/CalendarDropdown'; import { MdKeyboardArrowDown } from 'react-icons/md'; import { IoMdNotificationsOutline } from 'react-icons/io'; import { getdashboard, getdashboarddate, getpreOrderDashBoard, getSalesHdr, getTopSellingCustomers, } from '../../Features/RetailDashboard/Dashboard.js'; import { FaTimesCircle } from 'react-icons/fa'; import sandClock from '../../Images/sandClock.png'; import { FeatureAddon, getTemplate, GlobalPricingAppPricingName, StoredSessionData, } from '../../Features/ThemeChange/ThemeChange.js'; import { getAllCustomerPendingBalance, getAppSubscriptionDate, getPreferenceData, } from '../../Features/BookingScreen/BookingData/BookingData.js'; import { clearSession, dateFormatChange, encryptedValuesUrlFun, ExtractDateFormate, getSession, } from '../../Services/Others'; import { shallowEqual, useDispatch } from 'react-redux'; import { useSelector } from 'react-redux'; import { getAllprodIds, getExpireProductsList, getLowStockAlertProductsList, getTopSellingProduct, } from '../../Features/ProductPage/ProductPage.js'; import { ApplicationPreferences, checkSession, GenerateLogout, getCompBranchData, getEmpAccesData, GLobalSadminUserData, GlobalSelectedBranchId, PostLoginSuser, PUTLoginuser, } from '../../Features/BrachLogin/BranchLogin.js'; import { getPurchasedAppDetails } from '../../Features/BookingScreen/Pricing/Pricing.js'; import Add from '../../Images/dashboard/Add.png'; import AddPurchase from '../../Images/dashboard/AddPurchase.png'; import invoice from '../../Images/dashboard/invoice.png'; import user from '../../Images/dashboard/user.jpg'; import report from '../../Images/dashboard/report.png'; import Calendar from '../../Components/Calendar/Calendar'; import { PiSignOut } from 'react-icons/pi'; import BSNavBarUserInfo from '../BookingScreen/Components/BSNavbar/BSNavBarUserInfo'; import { DefaultModal } from '../../Components/Modal/DefaultModal'; import { RadioGrpButton } from '../../Components/Forms/RadioGroup.jsx'; import { DropDowns } from '../../Components/Forms/DropDown.jsx'; import { ChangeRedirectStatus, getEmpAccess, GlobalRedirectStatus, } from '../../Features/AppPage/CenterPage.js'; import { UserDataBasedOnBranchId } from '../../Features/Reports/Reports.js'; import { gettableData } from '../../Features/PreferenceMaster/PreferenceMaster.js'; import Loader from '../../Components/Loader/Loader.jsx'; import { getUserProfile } from '../../Features/UserAccount/userData.js'; import TopSellingProductsChart from './TopSellingProductsChart.jsx'; import { Messages } from '../../Components/Notifications/Messages.jsx'; const commonUrl = import.meta.env.ENV_COMMON_BASE_URL; const subDirectory = import.meta.env.ENV_BASE_URL; const RetailDashboard = () => { const today = new Date(); const year = today.getFullYear(); const month = today.getMonth(); const formatDate = (date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; const intialFromDate = `${year}-${String(month + 1).padStart(2, '0')}-01`; const intialToDate = formatDate(today); const navigate = useNavigate(); const dispatch = useDispatch(); const { RangePicker } = DatePicker; const [selectedTab, setSelectedTab] = useState('dashboard'); const tabs = [ { value: 'dashboard', label: 'Dashboard' }, { value: 'top-selling-products', label: 'Top Selling Products' }, ]; const { setCollapse } = useOutletContext(); const SessionData = useSelector(StoredSessionData, shallowEqual); const PricingAppPricingName = useSelector( GlobalPricingAppPricingName, shallowEqual ); const [topSellingProducts, setTopSellingProducts] = useState([]); const [initialDate, setInitialDate] = useState(true); const [dates, setDates] = useState([ dayjs(intialFromDate), dayjs(intialToDate), ]); const [ismounted, setIsmounted] = useState(true); const [customerPendingBalance, setcustomerPendingBalance] = useState([]); console.log(PricingAppPricingName, 'PricingAppPricingName'); // const { // AppId: appId, // CompId: compId, // BranchId: branchId, // } = SessionData || {}; // console.log(appId, compId, branchId, 'SessionData'); const [range1, setRange1] = useState('today'); const [range2, setRange2] = useState('today'); const [range3, setRange3] = useState('today'); const [userprofile, setUserprofile] = useState(false); const userProfileRef = useRef(null); const CompId = getSession('CompId'); const BranchId = getSession('BranchId'); const AppId = getSession('AppId'); const UserId = getSession('UserId'); const UserType = getSession('UserType'); const sessionId = getSession('SessionId'); const BrLength = getSession('BranchLength'); const [selection, setSelection] = useState('dashboard'); const [page, setPage] = useState(1); const [totalPages, setTotalPages] = useState(0); const [loading, setLoading] = useState(false); const [products, setProducts] = useState([]); console.log(selection, 'selection'); const [CompBranchData, setCompBranchData] = useState(); const [EmpAcces, setEmpAccess] = useState(); const [seletedBranchData, setseletedBranchData] = useState(BranchId); const [branchName, setBranchName] = useState('Guest'); const [selectedBranchForFilter, setSelectedBranchForFilter] = useState( BrLength == 1 ? null : 'all' ); const [ApiData, setApiData] = useState([]); console.log(CompBranchData, 'CompBranchData'); const [Zero, SetZero] = useState(false); const [ResponseData, setResponseData] = useState(); const [DateApiData, setDateApiData] = useState([]); const [piedat, setPiedat] = useState([]); const inputRefs = useRef([]); const [pin, setPin] = useState(['', '', '', '']); const [expiredList, setExpiredList] = useState([]); const [lowStockList, setLowStock] = useState([]); const [AllProdIds, setAllProdIds] = useState([]); const [AppDetails, setAppDetails] = useState([]); const [preorderData, setpreorderData] = useState([]); const [TopSellingCus, setTopsellingCus] = useState([]); const [SalesHdr, setSalesHdr] = useState([]); const [modal, setModal] = useState(false); const [SelectType, setSelectType] = useState('O'); const [SelectTypeName, setSelectTypeName] = useState('OTP'); const [pinInput, setpinInput] = useState(false); const [otp, setOtp] = useState(); const [FirstTimeOtp, setFirstTimeOtp] = useState(false); const [FirstTimePin, setFirstTimePin] = useState(false); const [seconds, setSeconds] = useState(0); const [disabled, setDisabled] = useState(false); const clicked = useRef(false); const [selectedUserData, setSelectedUserData] = useState(null); const [userDropDown, setuserDropDown] = useState([]); const [ExpiryDate, setExpiryDate] = useState(); const [EmpData, setEmpData] = useState(); const [messageType, setMessageType] = useState(null); const [messageData, setMessageData] = useState(null); console.log(EmpData, 'EmpDataEmpData'); // Loading states to prevent duplicate API calls const [isLoadingBranchData, setIsLoadingBranchData] = useState(false); const [isLoadingDashboard, setIsLoadingDashboard] = useState(false); const [isLoadingBranchFilter, setIsLoadingBranchFilter] = useState(false); const [isInitialLoad, setIsInitialLoad] = useState(true); const [initialFetchCompleted, setInitialFetchCompleted] = useState(false); // Ref to track if component is mounted const isMountedRef = useRef(true); const RedirectStatus = useSelector(GlobalRedirectStatus); const globalbranchid = useSelector(GlobalSelectedBranchId); const SAdminUserData = useSelector(GLobalSadminUserData); const appPreferences = useSelector(ApplicationPreferences); const isCheckSportsApp = appPreferences ?.find((preference) => preference?.PreferredCatName === 'Common Module') ?.PreferenceCatDetails?.some( (e) => e?.PreferredSubCatName === 'SportsApp' && e?.PreferredStatus === 'Y' ); const bookingTypePreference = appPreferences?.find( (preference) => preference?.PreferredCatName === 'Booking Type' )?.PreferenceCatDetails; const dinePreference = bookingTypePreference?.find( (type) => type?.PreferredSubCatName?.toLowerCase() === 'dine in' && type?.PreferredStatus === 'Y' ); const takeAwayPreference = bookingTypePreference?.find( (type) => type?.PreferredSubCatName?.toLowerCase() === 'take away' && type?.PreferredStatus === 'Y' ); const timerDuration = 30; let EndDate = AppDetails?.[0]?.ValidityEnd; const isoDate = EndDate; // <-- July 24 const date = new Date(isoDate); const options = { year: 'numeric', month: 'long', day: 'numeric' }; const formatted = date.toLocaleDateString('en-US', options); // "July 24, 2025" console.log(expiredList, lowStockList, 'lowStockList'); console.log(TopSellingCus, preorderData, 'preorderData'); let DineInData = ApiData?.[0]?.ChartDtl?.map((item) => { return { label: '', value: item?.OverAllDineInAmount || 0 - item?.OverAllDineInOfferAmount || 0, date: item?.SalesDate, }; }) || []; let TakeAway = ApiData?.[0]?.ChartDtl?.map((item) => { return { label: '', value: item?.OverAllTakeAwayAmount || 0 - item?.OverAllTakeAwayOfferAmount || 0, date: item?.SalesDate, }; }) || []; let selfbooking = ApiData?.[0]?.ChartDtl?.map((item) => { return { label: '', value: 0, date: item?.SalesDate, }; }) || []; console.log(DineInData, 'DineInData'); useEffect(() => { dispatch(getUserProfile({ UserId: UserId, ActiveStatus: 'A' })).unwrap(); }, [UserId]); useEffect(() => { if (isInitialLoad && CompId && AppId && selection === 'dashboard') { // debugger if (dates && dates?.[0] && dates?.[1] && !initialDate) { onRangeChange(dates, [ dates?.[0]?.format('DD-MM-YYYY'), dates?.[1]?.format('DD-MM-YYYY'), ]); } else { setIsInitialLoad(false); initializeData(); getInitialdataForPendingBills(); } } }, [CompId, AppId, isInitialLoad, selection, BranchId]); const getInitialdataForPendingBills = async () => { let data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, }; console.log(data, 'getSalesHdrFn'); dispatch(getSalesHdr(data)) .unwrap() .then((response) => { if (response?.data?.statusCode === 1) { setSalesHdr(response?.data?.data); } else { setSalesHdr([]); console.error('Failed to fetch pre-order dashboard data'); } }) .catch((error) => { console.error('Error fetching pre-order dashboard:', error); }); }; // Initialize all data in proper sequence const initializeData = async () => { try { // First fetch branch data as other calls depend on it await fetchBranchData(); // Then fetch other data that doesn't depend on branch selection await Promise.all([ fetchData(), getAllProdId(), topSellingProductsFn(), CustPendingBalance(), getExpdate(), fetchApi(), ]); setInitialFetchCompleted(true); // Dashboard-specific data will be loaded by SingleBranchFlow or Dashboardshow } catch (error) { console.error('Error initializing dashboard data:', error); } }; // Cleanup effect to handle component unmounting useEffect(() => { return () => { isMountedRef.current = false; }; }, []); useEffect(() => { if ( BranchId != null && BranchId != undefined && CompBranchData?.length > 0 && !isLoadingBranchData ) { // Set branch name if we have branch data const currentBranch = CompBranchData?.filter( (item) => item?.BrId == BranchId )?.[0]; if (currentBranch) { setBranchName(currentBranch.BrName); } // Handle single branch flow only if we have exactly one branch if (CompBranchData?.length == 1) { if (UserType != 'Super Admin User') { SingleBranchFlow(); } else { const checkData = SAdminUserData?.filter( (item) => item?.AppId == AppId && item?.CompId == CompId && item?.BranchId == BranchId ); if ( UserType == 'Super Admin User' && (checkData?.length == 0 || checkData?.[0]?.Status !== 'Y') ) { userDropData(); setModal(true); } else { SingleBranchFlow(); } } } } }, [ BranchId, CompBranchData, isLoadingBranchData, UserType, AppId, CompId, SAdminUserData, ]); useEffect(() => { if ( AppId && CompId && BranchId && dates && selection === 'top-selling-products' ) { const data = { AppId, CompId, BranchId, pageNumber: 1, FromDate: dates[0]?.format('YYYY-MM-DD') || intialFromDate, ToDate: dates[1]?.format('YYYY-MM-DD') || intialToDate, }; setPage(1); fetchProducts(data); setIsInitialLoad(true); } }, [selection]); const userDropData = async () => { const gettinguserDropDown = await dispatch( UserDataBasedOnBranchId(seletedBranchData ? seletedBranchData : BranchId) ).unwrap(); if (gettinguserDropDown?.data?.statusCode === 1) { let finaluserDropDown = gettinguserDropDown?.data?.data?.filter( (value) => value.ActiveStatus === 'A' ); setuserDropDown(finaluserDropDown); } }; const onComplete = useCallback(() => { setMessageData(null); setMessageType(null); }, []); const fetchApi = async () => { let data = { CompId: CompId, BranchId: BranchId, AppId: AppId, EmpId: UserId, }; let response = await dispatch(getEmpAccess(data)).unwrap(); let datas = response?.data?.data?.[0]?.EmpAccessDetails?.filter( (item) => ['Add Product', 'Product Receipt', 'Daily Sales', 'Sales'].includes(item.ConfigName) ); console.log(datas, 'ffsasasf'); setEmpData(datas); }; const getExpdate = async () => { let data = { CompId: CompId, BranchId: BranchId, AppId: AppId, }; let res = await dispatch(getAppSubscriptionDate(data)).unwrap(); if (res?.data?.statusCode === 1 && res?.data?.data?.length > 0) { const remaining = res?.data?.data?.[0]; // let RemainingDays = expData?.RemainingDays; // let RemainingHours=expData?.RemainingHours; // let RemainingMinutes=expData?.RemainingMinutes; // let RemainingSeconds=expData?.RemainingSeconds const now = new Date(); const totalMs = remaining.RemainingDays * 24 * 60 * 60 * 1000 + remaining.RemainingHours * 60 * 60 * 1000 + remaining.RemainingMinutes * 60 * 1000 + remaining.RemainingSeconds * 1000; const futureDate = new Date(now.getTime() + totalMs); const formatted = ExtractDateFormate( futureDate.toISOString().split('T')[0] ); // futureDate.toLocaleString(); setExpiryDate(formatted); } }; const getSalesHdrFn = (FromDate, ToDate) => { let today = new Date().toISOString().split('T')[0].split('-'); let data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, FromDate: FromDate ? FromDate : `${today[0]}-${today[1]}-${today[2]}`, ToDate: ToDate ? ToDate : `${today[0]}-${today[1]}-${today[2]}`, }; console.log(data, 'getSalesHdrFn'); dispatch(getSalesHdr(data)) .unwrap() .then((response) => { if (response?.data?.statusCode === 1) { setSalesHdr(response?.data?.data); } else { setSalesHdr([]); console.error('Failed to fetch pre-order dashboard data'); } }) .catch((error) => { console.error('Error fetching pre-order dashboard:', error); }); }; const getTopBuyingCustomers = (FromDate, ToDate) => { let today = new Date().toISOString().split('T')[0].split('-'); let data = { CompId: CompId, BranchId: BranchId, AppId: AppId, FromDate: FromDate ? FromDate : `${today[2]}-${today[1]}-${today[0]}`, ToDate: ToDate ? ToDate : `${today[2]}-${today[1]}-${today[0]}`, }; dispatch(getTopSellingCustomers(data)) .unwrap() .then((response) => { if (response?.data?.statusCode === 1) { setTopsellingCus(response?.data?.data); } else { console.error('Failed to fetch pre-order dashboard data'); } }) .catch((error) => { console.error('Error fetching pre-order dashboard:', error); }); }; const getpreOrderDashBoardFn = (FromDate, ToDate) => { let today = new Date().toISOString().split('T')[0].split('-'); let data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, FromDate: FromDate ? FromDate : `${today[0]}-${today[1]}-${today[2]}`, ToDate: ToDate ? ToDate : `${today[0]}-${today[1]}-${today[2]}`, }; dispatch(getpreOrderDashBoard(data)) .unwrap() .then((response) => { if (response?.data?.statusCode === 1) { setpreorderData(response?.data?.data); } else { console.error('Failed to fetch pre-order dashboard data'); } }) .catch((error) => { console.error('Error fetching pre-order dashboard:', error); }); }; const fetchBranchData = async () => { // Prevent duplicate calls if (isLoadingBranchData) { return; } setIsLoadingBranchData(true); try { let data = { CompId: CompId, BranchId: BranchId, AppId: AppId, UserId: UserId, }; if (UserType === 'Super Admin' || UserType === 'Super Admin User') { const response = await dispatch( getCompBranchData({ CompId: CompId, AppId: AppId }) ).unwrap(); if (response?.data?.statusCode === 1 && isMountedRef.current) { setBranchName( response?.data?.data?.filter((item) => item?.BrId == BranchId)?.[0] ?.BrName ); setCompBranchData(response?.data?.data); setIsmounted(false); } } else if ( UserType === 'Admin' || UserType === 'Admin User' || UserType == 'Employee' ) { if (UserType == 'Employee') { const EmpAcessRepsonse = await dispatch( getEmpAccesData(data) ).unwrap(); setEmpAccess(EmpAcessRepsonse?.data?.data); } const response = await dispatch( getCompBranchData({ AppId: AppId, UserId: UserId, CompId: CompId }) ).unwrap(); if (response?.data?.statusCode === 1 && isMountedRef.current) { setBranchName( response?.data?.data?.filter((item) => item?.BrId == BranchId)?.[0] ?.BrName ); setCompBranchData(response?.data?.data); if (response?.data?.data?.length > 1) { setIsmounted(false); } } console.log('Branch data fetched successfully:', response?.data?.data); } let AppDetails = await dispatch( getPurchasedAppDetails({ AppId, UserId }) ).unwrap(); //; if (AppDetails?.data?.statusCode === 1 && isMountedRef.current) { setAppDetails(AppDetails?.data?.data); } } catch (error) { console.error('Error fetching branch data:', error); } finally { setIsLoadingBranchData(false); } }; let topSellingProductsFn = async () => { const today = new Date(); const year = today.getFullYear(); const month = today.getMonth(); // 0-based: Jan = 0 // Last day of the current month const lastDay = new Date(year, month + 1, 0); // 0 = last day of previous month const formatDate = (date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; const data = { CompId: CompId, BranchId: BranchId, AppId: AppId, FromDate: `${year}-${String(month + 1).padStart(2, '0')}-01`, // First day ToDate: formatDate(lastDay), // e.g. 2025-07-31 }; dispatch(getTopSellingProduct(data)) .unwrap() .then((response) => { if (response?.data?.statusCode === 1) { setTopSellingProducts(response?.data?.data); } else { console.error('Failed to fetch top selling products'); } }) .catch((error) => { console.error('Error fetching top selling products:', error); }); }; const CustPendingBalance = () => { dispatch( getAllCustomerPendingBalance({ CompId: CompId, BranchId: BranchId, AppId: AppId, }) ) .unwrap() .then((response) => { if (response?.data?.statusCode === 1) { setcustomerPendingBalance(response?.data?.data); } else { console.error('Failed to fetch top selling products'); } }) .catch((error) => { console.error('Error fetching top selling products:', error); }); }; const getAllProdId = async (branchId) => { let data = { CompId: CompId, ...(selectedBranchForFilter !== 'all' ? { BranchId: branchId || BranchId } : {}), AppId: AppId, }; let response = await dispatch(getAllprodIds(data)).unwrap(); if ((response.data.statusCode = 1)) { setAllProdIds(response.data.data); } else { setAllProdIds([]); } }; useEffect(() => { if (selectedBranchForFilter && initialFetchCompleted) { getAllProdId(selectedBranchForFilter); } }, [selectedBranchForFilter]); const fetchData = async () => { try { const [expireRes, lowStockRes] = await Promise.all([ dispatch( getExpireProductsList({ compId: CompId, ...(!selectedBranchForFilter ? { branchId: BranchId } : {}), appId: AppId, }) )?.unwrap(), dispatch( getLowStockAlertProductsList({ compId: CompId, ...(!selectedBranchForFilter ? { branchId: BranchId } : {}), appId: AppId, }) )?.unwrap(), ]); if (expireRes?.data?.statusCode === 1) { setExpiredList(expireRes?.data?.data); } if (lowStockRes?.data?.statusCode === 1) { setLowStock(lowStockRes?.data?.data); } } catch (err) { // setMessage({ type: 'error', data: 'API failed' }); } }; const datasets = [ dinePreference && { name: 'Dine In', color: '#978FED', data: DineInData, }, { name: takeAwayPreference ? 'Takeaway' : 'Sales', color: '#EE89DF', data: TakeAway, }, { name: 'Self booking', color: '#F6CF7D', data: selfbooking, }, ].filter(Boolean); const UserDropDownChange = async (e) => { setSelectedUserData(e); }; const handlePageChange = async () => { if (CompBranchData?.length === 1) { const commonUrl = import.meta.env.ENV_COMMON_BASE_URL; const MobileNo = encryptedValuesUrlFun(getSession('MobileNo')); const userName = encryptedValuesUrlFun(getSession('userName')); const UserId = encryptedValuesUrlFun(getSession('UserId')); const UserType = encryptedValuesUrlFun(getSession('UserType')); const CompId = encryptedValuesUrlFun(getSession('CompId')); const CompName = encryptedValuesUrlFun(getSession('CompName')); const SessionId = encryptedValuesUrlFun(getSession('SessionId')); if (sessionStorage.getItem('BranchId') !== null) { clearSession('BranchId'); } if (sessionStorage.getItem('AppId') !== null) { clearSession('AppId'); } const param = { MN: MobileNo, UN: userName, UD: UserId, UT: UserType, CD: CompId, CN: CompName, SD: SessionId, }; const queryParams = new URLSearchParams(param).toString(); window.location.replace( `${commonUrl}/home/landing-page/home?${queryParams}` ); } else { setseletedBranchData(); if (sessionStorage.getItem('BranchId') !== null) { clearSession('BranchId'); } navigate(`${subDirectory}app-page/branch-login`); } if (sessionStorage.getItem('hasRefreshed') !== null) { sessionStorage.removeItem('hasRefreshed'); } setModal(false); }; const handleUserProfile = () => { setUserprofile((prev) => !prev); }; const handleChange = (index, event) => { const value = event.target.value; if (/^\d$/.test(value)) { const newPin = [...pin]; newPin[index] = value; setPin(newPin); if (index < inputRefs?.current?.length - 1) { inputRefs?.current[index + 1]?.focus(); // Move to next input } if (newPin.every((num) => num !== '')) { handleSubmit(newPin.join('')); // Call function when all 4 digits are entered } // Call function when all 4 digits are entered } else { event.target.value = ''; const newPin = [...pin]; newPin[index] = value; setPin(newPin); // Clear input if more than one digit is entered } }; const handleKeyDown = (index, event) => { if (event.key === 'Backspace' && index > 0 && !event.target.value) { inputRefs?.current[index - 1]?.focus(); // Move to previous input on backspace } }; const handleSubmit = async (enteredPin) => { if (otp == Number(enteredPin)) { let data = { CompId: CompId, BranchId: seletedBranchData != null && seletedBranchData != undefined ? seletedBranchData : BranchId, AppId: AppId, UserId: UserId, SignInType: SelectTypeName, SecurityCode: Number(enteredPin), UpdatedBy: UserId, SessionId: sessionId, EmpId: selectedUserData, }; let response = await dispatch(PUTLoginuser(data)).unwrap(); if (response?.data?.statusCode == 1) { await dispatch(checkSession({ UserId, sessionId })).unwrap(); setModal(false); inputRefs?.current.forEach((ref) => { if (ref) { ref.value = ''; } }); setPin(['', '', '', '']); SingleBranchFlow(); } } else { alert(`Invalid ${SelectType == 'O' ? 'OTP' : 'Pin'}`); } }; const ChangeMethod = (e) => { setSelectType(e); setSelectTypeName(e === 'O' ? 'OTP' : 'PIN'); }; const sentpinfn = async () => { let data = { CompId: CompId, BranchId: seletedBranchData != null && seletedBranchData != undefined ? seletedBranchData : BranchId, AppId: AppId, UserId: UserId, SignInType: SelectTypeName, CreatedBy: UserId, EmpId: selectedUserData, }; let response = await dispatch(PostLoginSuser(data)).unwrap(); if (response?.data?.statusCode == 1) { setOtp(response?.data?.OTP || response?.data?.PIN); setpinInput(true); // Show PIN/OTP input fields setSeconds(timerDuration); // Start the countdown timer setDisabled(true); // Disable the button temporarily if (SelectTypeName === 'OTP') { setFirstTimeOtp(true); // Set OTP as sent } else { setFirstTimePin(true); // Set PIN as sent } } }; const handleClick = async () => { if (selectedUserData) { if (clicked.current) return; clicked.current = true; if (seconds === 0) { // Disable the button temporarily sentpinfn(); // Resend PIN/OTP after 30 seconds } inputRefs?.current.forEach((ref) => { if (ref) { ref.value = ''; // Reset the value of each input } }); setPin(['', '', '', '']); } else { alert('Please select user'); } }; const SingleBranchFlow = async () => { try { let data = { CompId: CompId, BranchId: BranchId ? BranchId : globalbranchid, AppId: AppId, }; let res = await dispatch(getPreferenceData(data)).unwrap(); setIsmounted(false); const filteredDatas = res?.data?.data?.[0]?.SettingDtlDetails?.filter( (item) => item.SettingIdName?.toLowerCase() === 'dashboard' && item.SettingValue === 'N' ); if (!RedirectStatus && filteredDatas?.length > 0) { if ( res?.data?.data?.[0]?.SettingDtlDetails.find( (item) => item.SettingIdName === 'Dashboard' )?.SettingValue === 'N' ) { if (UserType !== 'Employee') { dispatch(ChangeRedirectStatus(true)); // await dispatch(getTemplate({ CompId, BranchId, AppId })).unwrap(); navigate(`${subDirectory}sales`); } else if ( EmpAcces?.length > 0 && EmpAcces?.[0]?.EmpAccessDetails?.find( (item) => item?.ConfigName === 'Sales' )?.ReadAccess === 'Y' ) { dispatch(ChangeRedirectStatus(true)); // await dispatch(getTemplate({ CompId, BranchId, AppId })).unwrap(); navigate(`${subDirectory}sales`); } else { // Only call Dashboardshow if not already loading if (!isLoadingDashboard) { Dashboardshow(); } } } else { // Only call Dashboardshow if not already loading if (!isLoadingDashboard) { Dashboardshow(); } } } else { // Only call Dashboardshow if not already loading if (!isLoadingDashboard) { Dashboardshow(); } } } catch (error) { console.error('Error in SingleBranchFlow:', error); } }; useEffect(() => { if (SessionData && CompId && BranchId && AppId && !isInitialLoad) { Dashboardshow(); } }, [SessionData, CompId, BranchId, AppId, isInitialLoad]); const Dashboardshow = async () => { // Prevent duplicate calls and only call Dashboardshow if not already loading if (isLoadingDashboard) { return; } setIsLoadingDashboard(true); try { let data; if (UserType === 'Employee') { data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, UserId: UserId, }; } else { data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, }; } console.log(data, 'data'); let response = await dispatch(getdashboard(data)).unwrap(); if (isMountedRef.current) { setApiData(response?.data?.data); setPiedat(response?.data?.data); setResponseData(response?.data?.statusCode); } } catch (error) { console.error('Error fetching dashboard data:', error); } finally { setIsLoadingDashboard(false); } }; const dateFormat = 'DD-MM-YYYY'; const onChangeBranchFilter = async (branchId) => { if (isLoadingBranchFilter) { return; } setIsLoadingBranchFilter(true); setSelectedBranchForFilter(branchId); try { if (branchId === 'all') { await fetchAllBranchesData(); } else { await fetchSingleBranchData(branchId); } } catch (error) { console.error('Error changing branch filter:', error); } finally { setIsLoadingBranchFilter(false); } }; const fetchAllBranchesData = async () => { try { if (!CompBranchData || CompBranchData.length === 0) return; let data; if (UserType === 'Employee') { data = { CompId: CompId, AppId: AppId, UserId: UserId, }; } else { data = { CompId: CompId, AppId: AppId }; } let response = await dispatch(getdashboard(data)).unwrap(); if (response?.data?.statusCode === 1) { setApiData(response?.data?.data); setPiedat(response?.data?.data); } setApiData(response?.data?.data); setPiedat(response?.data?.data); } catch (error) { console.error('Error fetching all branches data:', error); } // Also refresh other data for all branches getpreOrderDashBoardFnAllBranches(); getTopBuyingCustomersAllBranches(); getSalesHdrFnAllBranches(); }; const fetchSingleBranchData = async (branchId) => { let data; if (UserType === 'Employee') { data = { CompId: CompId, BranchId: branchId, AppId: AppId, UserId: UserId, }; } else { data = { CompId: CompId, BranchId: branchId, AppId: AppId }; } let response = await dispatch(getdashboard(data)).unwrap(); setApiData(response?.data?.data); setPiedat(response?.data?.data); // Also refresh other data getpreOrderDashBoardFn(); getTopBuyingCustomers(); getSalesHdrFn(); }; // Function to aggregate data from multiple branches const aggregateBranchData = (branchDataArray) => { const aggregated = { DineInOrderCount: 0, TakeAwayOrderCount: 0, SelfTakeAwayOrderCount: 0, OverAllSalesAmt: 0, OverAllDineInAmount: 0, OverAllTakeAwayAmount: 0, ChartDtl: [], }; branchDataArray.forEach((branchData) => { if (branchData) { aggregated.DineInOrderCount += branchData.DineInOrderCount || 0; aggregated.TakeAwayOrderCount += branchData.TakeAwayOrderCount || 0; aggregated.SelfTakeAwayOrderCount += branchData.SelfTakeAwayOrderCount || 0; aggregated.OverAllSalesAmt += branchData.OverAllSalesAmt || 0; aggregated.OverAllDineInAmount += branchData.OverAllDineInAmount || 0; aggregated.OverAllTakeAwayAmount += branchData.OverAllTakeAwayAmount || 0; // Merge chart data (you might want to customize this based on your needs) if (branchData.ChartDtl && branchData.ChartDtl.length > 0) { aggregated.ChartDtl = aggregated.ChartDtl.concat(branchData.ChartDtl); } } }); return aggregated; }; // Helper functions for fetching data from all branches const getpreOrderDashBoardFnAllBranches = async (FromDate, ToDate) => { if (!CompBranchData || CompBranchData.length === 0) return; try { let today = new Date().toISOString().split('T')[0].split('-'); let data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, FromDate: FromDate ? FromDate : `${today[0]}-${today[1]}-${today[2]}`, ToDate: ToDate ? ToDate : `${today[0]}-${today[1]}-${today[2]}`, }; const response = await dispatch(getpreOrderDashBoard(data)).unwrap(); if (response?.data?.statusCode === 1) { setpreorderData(response?.data?.data); } else { setpreorderData([]); console.error('Failed to fetch pre-order dashboard data'); } } catch (error) { console.error('Error fetching preorder data for all branches:', error); } }; const getTopBuyingCustomersAllBranches = async (FromDate, ToDate) => { if (!CompBranchData || CompBranchData.length === 0) return; try { const allBranchPromises = CompBranchData.map(async (branch) => { let today = new Date().toISOString().split('T')[0].split('-'); let data = { CompId: CompId, BranchId: branch.BrId, AppId: AppId, FromDate: FromDate ? FromDate : `${today[2]}-${today[1]}-${today[0]}`, ToDate: ToDate ? ToDate : `${today[2]}-${today[1]}-${today[0]}`, }; const response = await dispatch(getTopSellingCustomers(data)).unwrap(); return response?.data?.data || []; }); const allBranchData = await Promise.all(allBranchPromises); // Flatten and merge customer data from all branches const allCustomers = allBranchData.flat(); // Group by customer and sum amounts const customerMap = {}; allCustomers.forEach((customer) => { if (customer.CustName) { if (customerMap[customer.CustName]) { customerMap[customer.CustName].TotalSalesAmount += customer.TotalSalesAmount || 0; } else { customerMap[customer.CustName] = { ...customer }; } } }); // Convert back to array and sort by total sales const aggregatedCustomers = Object.values(customerMap) .sort((a, b) => (b.TotalSalesAmount || 0) - (a.TotalSalesAmount || 0)) .slice(0, 10); // Top 10 customers setTopsellingCus(aggregatedCustomers); } catch (error) { console.error('Error fetching top customers for all branches:', error); } }; const getSalesHdrFnAllBranches = async (FromDate, ToDate) => { if (!CompBranchData || CompBranchData.length === 0) return; try { let today = new Date().toISOString().split('T')[0].split('-'); let data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, FromDate: FromDate ? FromDate : `${today[0]}-${today[1]}-${today[2]}`, ToDate: ToDate ? ToDate : `${today[0]}-${today[1]}-${today[2]}`, }; const response = await dispatch(getSalesHdr(data)).unwrap(); setSalesHdr(response?.data?.data); } catch (error) { console.error('Error fetching sales header for all branches:', error); } }; const onRangeChange = async (dates, dateStrings) => { SetZero(true); let fromDateVal = dateStrings[0]?.split('-'); let toDateVal = dateStrings[1]?.split('-'); setDates(dates); setInitialDate(false); if (dates && selection === 'dashboard') { const fromDate = fromDateVal[2] + '-' + fromDateVal[1] + '-' + fromDateVal[0]; const toDate = toDateVal[2] + '-' + toDateVal[1] + '-' + toDateVal[0]; if (selectedBranchForFilter === 'all') { // Fetch data for all branches with date range await fetchAllBranchesDataWithDateRange(fromDate, toDate); } else { // Fetch data for specific branch with date range await fetchSingleBranchDataWithDateRange( selectedBranchForFilter ? selectedBranchForFilter : BranchId, fromDate, toDate ); } getpreOrderDashBoardFn(); } else if (selection === 'top-selling-products') { const FromDate = dates?.[0]?.format('YYYY-MM-DD') || intialFromDate; const ToDate = dates?.[1]?.format('YYYY-MM-DD') || intialToDate; await fetchProducts({ AppId, CompId, BranchId, FromDate, ToDate, pageNumber: 1, }); setPage(1); } }; const fetchProducts = async (data) => { setLoading(true); try { const res = await dispatch(getTopSellingProduct(data))?.unwrap(); if (res?.data?.statusCode === 1 && res?.data?.data?.length > 0) { setProducts(res?.data?.data); setTotalPages(Math.ceil(res?.data?.data?.[0]?.TotalCount / 10)); } else { setProducts([]); setTotalPages(0); } } catch (error) { console.error('Error fetching products:', error); } setLoading(false); }; const fetchAllBranchesDataWithDateRange = async (fromDate, toDate) => { try { let data; if (UserType === 'Employee') { data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, FromDate: fromDate, ToDate: toDate, UserId: UserId, }; } else { data = { CompId: CompId, ...(!selectedBranchForFilter ? { BranchId: BranchId } : {}), AppId: AppId, FromDate: fromDate, ToDate: toDate, }; } const response = await dispatch(getdashboarddate(data)).unwrap(); if (response?.data?.statusCode === 1) { setDateApiData(response?.data?.data); setApiData(response?.data?.data); } else { setDateApiData([]); setApiData([]); } // const allBranchData = await Promise.all(allBranchPromises); // // Aggregate the data from all branches // const aggregatedData = aggregateBranchData(allBranchData); // setDateApiData([aggregatedData]); // setApiData([aggregatedData]); // setPiedat([aggregatedData]); // Also refresh other data for all branches with date range getpreOrderDashBoardFnAllBranches(fromDate, toDate); getTopBuyingCustomersAllBranches(fromDate, toDate); getSalesHdrFnAllBranches(fromDate, toDate); getSalesHdrFn(fromDate, toDate); } catch (error) { console.error('Error fetching all branches data with date range:', error); setDateApiData([]); setApiData([]); setPiedat([]); setpreorderData([]); setTopsellingCus([]); setSalesHdr([]); } }; // Function to fetch data for single branch with date range const fetchSingleBranchDataWithDateRange = async ( branchId, fromDate, toDate ) => { try { const targetBranchId = branchId === 'all' ? BranchId : branchId; let data; if (UserType === 'Employee') { data = { CompId: CompId, BranchId: targetBranchId, AppId: AppId, FromDate: fromDate, ToDate: toDate, UserId: UserId, }; } else { data = { CompId: CompId, BranchId: targetBranchId, AppId: AppId, FromDate: fromDate, ToDate: toDate, }; } let response = await dispatch(getdashboarddate(data)).unwrap(); if (response?.data?.statusCode === 1) { setDateApiData(response?.data?.data); setApiData(response?.data?.data); setPiedat(response?.data?.data); getpreOrderDashBoardFn(fromDate, toDate); getTopBuyingCustomers(fromDate, toDate); getSalesHdrFn(fromDate, toDate); } else { setDateApiData([]); setApiData([]); setPiedat([]); setpreorderData([]); setTopsellingCus([]); setSalesHdr([]); } } catch (error) { console.error( 'Error fetching single branch data with date range:', error ); setDateApiData([]); setApiData([]); setPiedat([]); setpreorderData([]); setTopsellingCus([]); setSalesHdr([]); } }; const disabledDate = (current) => { const today = dayjs().endOf('day'); const firstSalesDate = ApiData?.[0]?.Firstsalesdate; // If firstSalesDate exists and is valid, use it as minimum date if (firstSalesDate) { const minDate = dayjs(firstSalesDate).startOf('day'); return current && (current < minDate || current > today); } // If no firstSalesDate, disable future dates only return current && current > today; }; useEffect(() => { const handleResize = () => { setCollapse(window.innerWidth < 768); }; window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, []); useEffect(() => { const handleClickOutside = (event) => { if ( userProfileRef.current && !userProfileRef.current.contains(event.target) ) { setUserprofile(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [userProfileRef]); const Logout = async () => { const status = 'N'; // replace with your actual status const res = await dispatch(GenerateLogout({ UserId, status })).unwrap(); if (res?.data?.statusCode === 1) { sessionStorage.clear(); window.location.replace(`${commonUrl}`); } }; if (ismounted) return (
); const handleSelectChange = (value) => { setSelection(value); }; return (
{branchName}
{(() => { if (!ExpiryDate) return null; const today = new Date(); const expiryDate = new Date(ExpiryDate); const timeDiff = expiryDate.getTime() - today.getTime(); const daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24)); if (daysDiff <= 7 && daysDiff >= 0) { return (
{PricingAppPricingName?.[0]?.PricingName && (
Current Plan:{' '} {PricingAppPricingName?.[0]?.PricingName + ' / ' + PricingAppPricingName?.[0]?.Type}
)}
Plan Expiry on {ExpiryDate}
); } return null; })()}
{(AppDetails?.[0]?.UserName || 'Guest') ?.substring(0, 2) ?.toUpperCase()}
{userprofile && ( )}
{/*
Dashboard
*/} {/* public Login dashboard*/}
{tabs?.map((tab) => ( ))}
{/* Branch Filter Dropdown */} {CompBranchData?.length > 1 && selection !== 'top-selling-products' && (
({ value: option.BrId, label: option.BrName, })), ]} className="branch-filter-select" onChangeFunction={onChangeBranchFilter} valueData={selectedBranchForFilter} defaultValue="all" placeholder="All Branches" />
)}
{/*
{' '} Refresh
10sec auto refresh
*/}
{selection === 'dashboard' ? ( <>

Today's Snapshot

{selectedBranchForFilter === 'all' ? ( <> {ApiData?.[0]?.BranchDtl?.map((item, index) => (
{item.BrName || 'N/A'}
Orders:{' '} {(item.DineInOrderCount || 0) + (item.TakeAwayOrderCount || 0)}
Revenue: ₹{item.OverAllSalesAmt || 0}
))}
} placement="bottom" >
{ApiData?.[0]?.DineInOrderCount + ApiData?.[0]?.TakeAwayOrderCount + ApiData?.[0]?.DineIn_TakeAwayOrderCount || 0}{' '}
Orders
{ApiData?.[0]?.BranchDtl?.map((item, index) => (
{item.BrName || 'N/A'}
Orders:{' '} {(item.DineInOrderCount || 0) + (item.TakeAwayOrderCount || 0)}
Revenue: ₹{item.OverAllSalesAmt || 0}
))}
} placement="bottom" > {!isCheckSportsApp && (
{ApiData?.[0]?.OverAllSalesAmt - ApiData?.[0]?.OverAllOfferAmount || 0}{' '}
Revenue
)}
{SalesHdr?.[0]?.NewCustomers || 0}{' '}
New Customers
{!isCheckSportsApp && (
{SalesHdr?.[0]?.PendingBill || 0}{' '}
Pending Bills
)} ) : ( <>
{ApiData?.[0]?.DineInOrderCount + ApiData?.[0]?.TakeAwayOrderCount + ApiData?.[0]?.DineIn_TakeAwayOrderCount || 0}{' '}
Orders
{!isCheckSportsApp && (
{( (ApiData?.[0]?.OverAllSalesAmt || 0) - (ApiData?.[0]?.OverAllOfferAmount || 0) ).toFixed(2)}{' '}
Revenue
)}
{SalesHdr?.[0]?.NewCustomers || 0}{' '}
New Customers
{!isCheckSportsApp && (
{SalesHdr?.[0]?.PendingBill || 0}{' '}
Pending Bills
)} )}
{ const hasEmpAccess = EmpData?.find( item => item.ConfigName === "Add Product" && item.ReadAccess === "Y" ); if (!hasEmpAccess && UserType === "Employee") { setMessageData("Please contact your admin to get access"); setMessageType('error'); } if (isCheckSportsApp) { navigate(`${subDirectory}setting/products-master/new`); } if ( (UserType === "Employee" && hasEmpAccess) || UserType === "Admin" || UserType === "Super Admin" || UserType === "Super Admin User" ) { navigate(`${subDirectory}setting/product-master/new`); } // setting/product-master/new }} className="quickActionBox" > {!isCheckSportsApp ? (
Add Product
) : (
Add Slot
)}
{!isCheckSportsApp && (
{ const hasEmpAccess = EmpData?.find( item => item.ConfigName === "Product Receipt" && item.ReadAccess === "Y" ); if (!hasEmpAccess && UserType === "Employee") { setMessageData("Please contact your admin to get access"); setMessageType('error'); } if ( (UserType === "Employee" && hasEmpAccess) || UserType === "Admin" || UserType === "Super Admin" || UserType === "Super Admin User" ) { navigate(`${subDirectory}setting/purchase-entry/new`); } }} className="quickActionBox" >
Add Purchase
)}
{ const hasEmpAccess = EmpData?.find( item => item.ConfigName === "Daily Sales" && item.ReadAccess === "Y" ); if (!hasEmpAccess && UserType === "Employee") { setMessageData("Please contact your admin to get access"); setMessageType('error'); } if ( (UserType === "Employee" && hasEmpAccess) || UserType === "Admin" || UserType === "Super Admin" || UserType === "Super Admin User" ) { navigate(`${subDirectory}report/datewisereport`); } }} className="quickActionBox" >
Report
{ const hasEmpAccess = EmpData?.find( item => item.ConfigName === "Sales" && item.ReadAccess === "Y" ); if (!hasEmpAccess && UserType === "Employee") { setMessageData("Please contact your admin to get access"); setMessageType('error'); } if ( (UserType === "Employee" && hasEmpAccess) || UserType === "Admin" || UserType === "Super Admin" || UserType === "Super Admin User" ) { navigate(`${subDirectory}sales`); } }} >
New Bill
{/* ------------------------Dont Delete----------------------------- */} {/*
Electricity
₹1,500
Purchases
₹12,150
Salaries
₹7,500
*/} {/*
DineIn
{ApiData?.[0]?.DineInOrderCount}
Takeaway
{ApiData?.[0]?.TakeAwayOrderCount}
Delivery
{ApiData?.[0]?.SelfTakeAwayOrderCount}
*/}
{dinePreference && (ApiData?.[0]?.BranchDtl?.length > 1 ? ( {ApiData[0].BranchDtl.map((item, index) => (
{item.BrName || 'N/A'}
Orders: {item.DineInOrderCount || 0}
))}
} placement="bottom" >
DineIn
{ApiData?.[0]?.DineInOrderCount || 0}
) : (
DineIn
{ApiData?.[0]?.DineInOrderCount || 0}
))}
{takeAwayPreference ? 'Takeaway' : 'Sales'} {ApiData?.[0]?.BranchDtl?.length > 1 ? ( {ApiData[0].BranchDtl.map((item, index) => (
{item.BrName || 'N/A'}
Orders: {item.TakeAwayOrderCount || 0}
))}
} placement="bottom" >
{ApiData?.[0]?.TakeAwayOrderCount || 0}
) : (
{ApiData?.[0]?.TakeAwayOrderCount || 0}
)}
{dinePreference && takeAwayPreference && (
{'DineIn + Takeaway'} {ApiData?.[0]?.BranchDtl?.length > 1 ? ( {ApiData[0].BranchDtl.map((item, index) => (
{item.BrName || 'N/A'}
Orders: {item.DineIn_TakeAwayOrderCount || 0}
))}
} placement="bottom" >
{ApiData?.[0]?.DineIn_TakeAwayOrderCount || 0}
) : (
{ApiData?.[0]?.DineIn_TakeAwayOrderCount || 0}
)} )} {!isCheckSportsApp && (
{ApiData?.[0]?.BranchDtl?.length > 1 ? ( {ApiData[0].BranchDtl.map((item, index) => (
{item.BrName || 'N/A'}
Delivery: {item.SelfTakeAwayOrderCount || 0}
))}
} placement="bottom" > Delivery
{ApiData?.[0]?.SelfTakeAwayOrderCount || 0}
) : ( <> Delivery
{ApiData?.[0]?.SelfTakeAwayOrderCount || 0}
)} )} {!isCheckSportsApp && (
Product Summary
{AllProdIds?.[0]?.BranchDtl?.length > 1 ? ( {AllProdIds[0].BranchDtl.map((item, index) => (
{item?.BranchName || 'N/A'}
TOTAL PRODUCTS: {item?.ProductCount || 0}
))}
} placement="bottom" >

{AllProdIds?.[0]?.TotalProductCount}

TOTAL PRODUCTS
) : (

{AllProdIds?.[0]?.TotalProductCount || AllProdIds?.length}

TOTAL PRODUCTS
)}
{expiredList?.[0]?.Branchdtl?.length > 1 ? ( {expiredList[0].Branchdtl.map((item, index) => (
{item.BranchName || 'N/A'}
Expiry Stock: {item.ProductsDtl?.length || 0}
))}
} placement="bottom" >

{expiredList?.length}

EXPIRY STOCK
) : (

{expiredList?.length}

EXPIRY STOCK
)}
{lowStockList?.[0]?.BranchDtl?.length > 1 ? ( {lowStockList[0].BranchDtl.map((item, index) => (
{item.BranchName || 'N/A'}
LOW STOCK: {item.lowStockList?.length || 0}
))}
} placement="bottom" >

{lowStockList?.length}

LOW STOCK
) : (

{lowStockList?.length}

LOW STOCK
)}
{SalesHdr?.[0]?.BranchDetails?.length > 1 ? ( {SalesHdr[0].BranchDetails.map((item, index) => (
{item.BranchName || 'N/A'}
NO STOCK: {item.NoStockProduct || 0}
))}
} placement="bottom" >

{SalesHdr?.[0]?.NoStockProduct || 0}

NO STOCK
) : (

{SalesHdr?.[0]?.NoStockProduct || 0}

NO STOCK
)}
Notification Center
{expiredList?.length > 0 && (
{expiredList?.length} Products expiry today!
)} {lowStockList?.length > 0 && (
Low Stock count {lowStockList?.length}
)} {/*
View All
*/}
)} {!isCheckSportsApp && (
Top Selling Product
This Month
{topSellingProducts.map((product, idx) => (
{product.name}
{product.ProdName} - {product.TotalSoldQty}{' '}
))}
Pre Order Summary
{preorderData?.[0]?.BranchDtl ? preorderData?.[0]?.BranchDtl?.map( (item, index) => (
{item.BranchName || 'N/A'}
Total Orders: {item.TotalOrders || 0}
) ) : 'No Data'}
} placement="bottom" > {preorderData?.[0]?.TotalOrders || 0}
Total Orders
{preorderData?.[0]?.BranchDtl ? preorderData?.[0]?.BranchDtl?.map( (item, index) => (
{item.BranchName || 'N/A'}
Total Orders: {item.PendingOrders || 0}
) ) : 'No Data'}
} placement="bottom" > {preorderData?.[0]?.PendingOrders || 0}
Pending
{preorderData?.[0]?.BranchDtl ? preorderData?.[0]?.BranchDtl?.map( (item, index) => (
{item.BranchName || 'N/A'}
Total Orders: {item.CompletedOrders || 0}
) ) : 'No Data'}
} placement="bottom" > {preorderData?.[0]?.CompletedOrders || 0}
Completed
Credit List
Customer
Amount
{customerPendingBalance?.length > 0 ? ( customerPendingBalance.map((customer, idx) => (
{customer?.CustName || customer.CustMobile}
₹{customer.creditBal.toFixed(2)}
)) ) : (
No Pending Balance
₹0.00
)} {/*
View All
*/}
Stock Alerts
Sl.No
Product
Stock Count
{lowStockList?.length > 0 ? ( lowStockList?.map((item, index) => (
{index + 1}
{item?.ProdName || item?.ProdId}
{item?.BalanceQty}
)) ) : (
No Low Stock Product
)} {/*
2
Cotton Blend Mandarin Collar Self One Design Kurta
4
3
Cotton Blend Mandarin Collar Self One Design Kurta
1
*/} {/*
View All
*/}
)} ) : ( <> )}
({ value: option?.UserId, label: option?.UserName, }))} label={} className="field-DropDown" onChangeFunction={(e) => UserDropDownChange(e)} isOnchanges={selectedUserData ? true : false} valueData={selectedUserData} disabled={disabled} />
ChangeMethod(e)} />
{pinInput && (
{[0, 1, 2, 3].map((i) => ( (inputRefs.current[i] = el)} className="inputNumber" type="text" inputMode="numeric" pattern="[0-9]" maxLength={1} onChange={(e) => handleChange(i, e)} onKeyDown={(e) => handleKeyDown(i, e)} style={{ textAlign: 'center', width: '40px', fontSize: '20px', }} /> ))}
)}
} /> ); }; export default RetailDashboard;