import axios from 'axios'; const tenid = localStorage.getItem('tenantid'); // ==============================|| fetchOrderSummary (orders)||============================== // export const fetchOrderSummary = async () => { const response = await axios.get(`${process.env.REACT_APP_URL}/orders/getordersummary`); console.log('fetchOrderSummary', response.data.details); return response.data.details; }; // ==============================|| fetchLocationSummary (orders)||============================== // export const fetchLocationSummary = async () => { const response = await axios.get(`${process.env.REACT_APP_URL}/orders/getlocationsummary`); console.log('fetchLocationSummary', response.data.details); return response.data.details; }; // ==============================|| fetchOrderInsight (orders)||============================== // export const fetchOrderInsight = async () => { const response = await axios.get(`${process.env.REACT_APP_URL}/orders/getorderinsight`); console.log('fetchOrderInsight', response.data.details); return response.data.details; }; // ==============================|| fetchDeliverySummary (delivery)||============================== // export const fetchDeliverySummary = async () => { const response = await axios.get(`${process.env.REACT_APP_URL}/deliveries/deliverysummary`); console.log('fetchDeliverySummary', response.data.details); return response.data.details; }; // ==============================|| fetchDeliveryInsight (delivery)||============================== // export const fetchDeliveryInsight = async () => { const response = await axios.get(`${process.env.REACT_APP_URL}/deliveries/getdeliveryinsight`); console.log('fetchDeliveryInsight', response.data.details); return response.data.details; }; // ==============================|| fetchDeliveryLocationSummary (delivery)||============================== // export const fetchDeliveryLocationSummary = async () => { const response = await axios.get(`${process.env.REACT_APP_URL}/deliveries/getlocationsummary`); console.log('fetchDeliveryLocationSummary', response.data.details); return response.data.details; }; // ==============================|| fetchAllTenants (clients)||============================== // export const fetchAllTenants = async ({ queryKey }) => { const [size, status, pageno, search, rough] = queryKey; let url = ''; if (search) { // url = `https://jupiter.nearle.app/live/api/v1/tenants/search/?keyword=${search}`; url = `${process.env.REACT_APP_URL}/tenants/search/?keyword=${search}`; } else { // url = `https://jupiter.nearle.app/live/api/v1/tenants/getalltenants?pageno=${pageno}&pagesize=${size}`; url = `${process.env.REACT_APP_URL}/tenants/getalltenants?pageno=${pageno}&pagesize=${size}`; } const response = await axios.get(url); // tenants/search/?keyword=${search} console.log('fetchAllTenants', response.data.details); return response.data.details; }; // ==============================|| fetchCustomersList (customers)||============================== // export const fetchCustomersList = async ({ queryKey }) => { const [pages] = queryKey; const response = await axios.get(`${process.env.REACT_APP_URL}/customers/getallcustomers/?pageno=${pages}&pagesize=10`); console.log('fetchCustomersList', response.data.details); return response.data.details; }; // ==============================|| fetchCustomersListBySearch (customers)||============================== // export const fetchCustomersListBySearch = async ({ queryKey }) => { const [search] = queryKey; const response = await axios.get(search.lenght > 3 && `${process.env.REACT_APP_URL}/customers/search/?keyword=${search}`); console.log('fetchCustomersListBySearch', response.data.details); return response.data.details; }; // ==============================|| fetchOrdersSummary (orders summary)||============================== // export const fetchOrdersSummary = async ({ queryKey }) => { console.log('queryKey for fetchOrdersSummary', queryKey); const [id, startdate, enddate] = queryKey; const response = await axios.get( id == -1 ? `${process.env.REACT_APP_URL}/deliveries/getreportsummary/?&fromdate=${startdate}&todate=${enddate}` : `${process.env.REACT_APP_URL}/deliveries/getreportsummary/?partnerid=${id}&fromdate=${startdate}&todate=${enddate}` ); console.log('fetchOrdersSummary', response.data.details); return response.data.details; }; // ==============================|| fetchLocations (orders summary))||============================== // export const fetchLocations = async ({ queryKey }) => { const response = await axios.get(`${process.env.REACT_APP_URL}/partners/getpartners`); const updatedLocations = [ ...response.data.details, { partnername: 'All', partnerid: -1 } // Add your new object here ]; console.log('fetchLocations', updatedLocations); return updatedLocations; }; // ==============================|| fetchAppLocations (report summary))||============================== // export const fetchAppLocations = async ({ queryKey }) => { const response = await axios.get(`${process.env.REACT_APP_URL}/partners/getpartners`); const updatedLocations = [ ...response.data.details, { partnername: 'All', applocationid: -1 } // Add your new object here ]; console.log('fetchAppLocations', updatedLocations); return updatedLocations; }; // ==============================|| fetchRidersSummary (riders summary)||============================== // export const fetchRidersSummary = async ({ queryKey }) => { console.log('queryKey for fetchRidersSummary', queryKey); const [id, startdate, enddate] = queryKey; const response = await axios.get( id == -1 ? `${process.env.REACT_APP_URL}/deliveries/getridersummary/?&fromdate=${startdate}&todate=${enddate}` : `${process.env.REACT_APP_URL}/deliveries/getridersummary/?applocationid=${id}&fromdate=${startdate}&todate=${enddate}` ); console.log('fetchRidersSummary', response.data.details); return response.data.details; }; // ==============================|| fetchorderdetails (orders detail)||============================== // export const fetchorderdetails = async ({ queryKey }) => { console.log('queryKey of fetchorderdetails', queryKey); const [tabValue, appId, startdate, enddate] = queryKey; let status = tabValue === 0 ? 'delivered' : tabValue === 1 ? 'pending' : 'cancelled'; const response = await axios.get( // appId == -1 // ? `https://jupiter.nearle.app/live/api/v1/orders/getorders/?fromdate=${startdate}&todate=${enddate}` // : `https://jupiter.nearle.app/live/api/v1/orders/getorders/?fromdate=${startdate}&todate=${enddate}&applocationid=${appId}` `https://jupiter.nearle.app/live/api/v1/deliveries/getdeliveries/?tenantid=${tenid}&fromdate=${startdate}&todate=${enddate}` ); console.log('fetchorderdetails', response.data.details); return response.data.details; }; // ==============================|| fetchCount (orders detail)||============================== // export const fetchCount = async ({ queryKey }) => { console.log('queryKey of fetchCount', queryKey); const [startdate, enddate] = queryKey; const response = await axios.get(`https://jupiter.nearle.app/live/api/v1/orders/getorders/?fromdate=${startdate}&todate=${enddate}`); const calculateOrderCounts = () => { let deliveredCount = 0; let pendingCount = 0; let cancelledCount = 0; response.data.details.forEach((order) => { const status = order.orderstatus; if (status === 'delivered') { deliveredCount++; } else if (status === 'pending') { pendingCount++; } else if (status === 'cancelled') { cancelledCount++; } }); return { deliveredCount, pendingCount, cancelledCount }; }; console.log('fetchCount', calculateOrderCounts()); return calculateOrderCounts(); };