added expense filte at api url level
This commit is contained in:
parent
78808ecac0
commit
18ac8e11bd
@ -30,16 +30,6 @@ const Dashboard = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container-xxl flex-grow-1 container-p-y">
|
<div className="container-xxl flex-grow-1 container-p-y">
|
||||||
{/* <div className="col-xxl-6 col-lg-6">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{!isAllProjectsSelected && (
|
|
||||||
<div className="col-xxl-6 col-lg-6">
|
|
||||||
<AttendanceOverview />
|
|
||||||
</div>
|
|
||||||
)} */}
|
|
||||||
|
|
||||||
<div class="row mb-6 g-6">
|
<div class="row mb-6 g-6">
|
||||||
<div class="col-12 col-xl-8">
|
<div class="col-12 col-xl-8">
|
||||||
<div class="card h-100">
|
<div class="card h-100">
|
||||||
@ -53,6 +43,9 @@ const Dashboard = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{isAllProjectsSelected && (<div className="co-12">
|
||||||
|
<AttendanceOverview />
|
||||||
|
</div>)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
import Chart from "react-apexcharts";
|
import Chart from "react-apexcharts";
|
||||||
import { useExpenseAnalysis } from "../../hooks/useDashboard_Data";
|
import { useExpenseAnalysis } from "../../hooks/useDashboard_Data";
|
||||||
import { useSelectedProject } from "../../slices/apiDataManager";
|
import { useSelectedProject } from "../../slices/apiDataManager";
|
||||||
@ -18,21 +18,29 @@ const ExpenseAnalysis = () => {
|
|||||||
|
|
||||||
const { watch } = methods;
|
const { watch } = methods;
|
||||||
|
|
||||||
|
|
||||||
const [startDate, endDate] = watch(["startDate", "endDate"]);
|
const [startDate, endDate] = watch(["startDate", "endDate"]);
|
||||||
const { data, isLoading, isError, error, isFetching } = useExpenseAnalysis(
|
const { data, isLoading, isError, error, isFetching } = useExpenseAnalysis(
|
||||||
projectId,
|
projectId,
|
||||||
localToUtc(startDate),
|
startDate ? localToUtc(startDate) : null,
|
||||||
localToUtc(endDate)
|
endDate ? localToUtc(endDate) : null
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isError) return <div>{error.message}</div>;
|
if (isError) return <div>{error.message}</div>;
|
||||||
|
|
||||||
const report = data?.report || [];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const report = data?.report ?? [];
|
||||||
|
|
||||||
|
const { labels, series, total } = useMemo(() => {
|
||||||
const labels = report.map((item) => item.projectName);
|
const labels = report.map((item) => item.projectName);
|
||||||
const series = report.map((item) => item.totalApprovedAmount || 0);
|
const series = report.map((item) => item.totalApprovedAmount || 0);
|
||||||
const total = formatCurrency(data?.totalAmount || 0);
|
const total = formatCurrency(data?.totalAmount || 0);
|
||||||
|
|
||||||
|
return { labels, series, total };
|
||||||
|
}, [report, data?.totalAmount]);
|
||||||
|
|
||||||
const donutOptions = {
|
const donutOptions = {
|
||||||
chart: { type: "donut" },
|
chart: { type: "donut" },
|
||||||
labels,
|
labels,
|
||||||
|
@ -22,6 +22,14 @@ const ExpenseStatus = () => {
|
|||||||
setProjectName("All Project");
|
setProjectName("All Project");
|
||||||
}
|
}
|
||||||
}, [projectNames, selectedProject]);
|
}, [projectNames, selectedProject]);
|
||||||
|
|
||||||
|
const handleNavigate = (status) => {
|
||||||
|
if (selectedProject) {
|
||||||
|
navigate(`/expenses/${status}/${selectedProject}`);
|
||||||
|
} else {
|
||||||
|
navigate(`/expenses/${status}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="card-header d-flex justify-content-between text-start">
|
<div className="card-header d-flex justify-content-between text-start">
|
||||||
@ -79,7 +87,7 @@ const ExpenseStatus = () => {
|
|||||||
<div
|
<div
|
||||||
key={idx}
|
key={idx}
|
||||||
className="report-list-item rounded-2 mb-4 bg-lighter px-2 py-3 cursor-pointer"
|
className="report-list-item rounded-2 mb-4 bg-lighter px-2 py-3 cursor-pointer"
|
||||||
onClick={() => navigate(`/expenses/${item.status}`)}
|
onClick={()=>handleNavigate(item.status)}
|
||||||
>
|
>
|
||||||
<div className="d-flex align-items-center">
|
<div className="d-flex align-items-center">
|
||||||
<div className="report-list-icon shadow-xs me-4">
|
<div className="report-list-icon shadow-xs me-4">
|
||||||
|
@ -16,7 +16,7 @@ import { ExpenseFilterSkeleton } from "./ExpenseSkeleton";
|
|||||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
||||||
const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
||||||
const { status } = useParams();
|
const { status, project } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const selectedProjectId = useSelector(
|
const selectedProjectId = useSelector(
|
||||||
(store) => store.localVariables.projectId
|
(store) => store.localVariables.projectId
|
||||||
@ -43,7 +43,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
return {
|
return {
|
||||||
...defaultFilter,
|
...defaultFilter,
|
||||||
statusIds: status ? [status] : defaultFilter.statusIds || [],
|
statusIds: status ? [status] : defaultFilter.statusIds || [],
|
||||||
projectIds: defaultFilter.projectIds || [],
|
projectIds: project ? [project] : defaultFilter.projectIds || [],
|
||||||
createdByIds: defaultFilter.createdByIds || [],
|
createdByIds: defaultFilter.createdByIds || [],
|
||||||
paidById: defaultFilter.paidById || [],
|
paidById: defaultFilter.paidById || [],
|
||||||
isTransactionDate: defaultFilter.isTransactionDate ?? true,
|
isTransactionDate: defaultFilter.isTransactionDate ?? true,
|
||||||
@ -99,7 +99,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
const [appliedStatusId, setAppliedStatusId] = useState(null);
|
const [appliedStatusId, setAppliedStatusId] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!status) return;
|
if (!status && !project) return;
|
||||||
|
|
||||||
if (status !== appliedStatusId && data) {
|
if (status !== appliedStatusId && data) {
|
||||||
const filterWithStatus = {
|
const filterWithStatus = {
|
||||||
@ -121,6 +121,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
status,
|
status,
|
||||||
|
project,
|
||||||
data,
|
data,
|
||||||
dynamicDefaultFilter,
|
dynamicDefaultFilter,
|
||||||
onApply,
|
onApply,
|
||||||
|
@ -268,7 +268,10 @@ export const useExpenseAnalysis = (projectId, startDate, endDate) => {
|
|||||||
const resp = await GlobalRepository.getExpenseData(projectId, startDate, endDate);
|
const resp = await GlobalRepository.getExpenseData(projectId, startDate, endDate);
|
||||||
return resp.data;
|
return resp.data;
|
||||||
},
|
},
|
||||||
enabled:shouldFetch
|
enabled:shouldFetch,
|
||||||
|
refetchOnWindowFocus: true, // refetch when you come back
|
||||||
|
refetchOnMount: "always", // always refetch on remount
|
||||||
|
staleTime: 0,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export const useExpenseStatus = (projectId)=>{
|
export const useExpenseStatus = (projectId)=>{
|
||||||
|
@ -94,7 +94,7 @@ const router = createBrowserRouter(
|
|||||||
{ path: "/activities/task", element: <TaskPlannng /> },
|
{ path: "/activities/task", element: <TaskPlannng /> },
|
||||||
{ path: "/activities/reports", element: <Reports /> },
|
{ path: "/activities/reports", element: <Reports /> },
|
||||||
{ path: "/gallary", element: <ComingSoonPage /> },
|
{ path: "/gallary", element: <ComingSoonPage /> },
|
||||||
{ path: "/expenses/:status?", element: <ExpensePage /> },
|
{ path: "/expenses/:status?/:project?", element: <ExpensePage /> },
|
||||||
{ path: "/masters", element: <MasterPage /> },
|
{ path: "/masters", element: <MasterPage /> },
|
||||||
{ path: "/tenants", element: <TenantPage /> },
|
{ path: "/tenants", element: <TenantPage /> },
|
||||||
{ path: "/tenants/new-tenant", element: <CreateTenant /> },
|
{ path: "/tenants/new-tenant", element: <CreateTenant /> },
|
||||||
|
@ -97,7 +97,7 @@ export const formatCurrency = (amount, currency = "INR", locale = "en-US") => {
|
|||||||
return new Intl.NumberFormat(locale, {
|
return new Intl.NumberFormat(locale, {
|
||||||
style: "currency",
|
style: "currency",
|
||||||
currency: currency,
|
currency: currency,
|
||||||
minimumFractionDigits: 2,
|
minimumFractionDigits: 0,
|
||||||
maximumFractionDigits: 2,
|
maximumFractionDigits: 2,
|
||||||
}).format(amount);
|
}).format(amount);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user