From 96e575755945b1e315a2c7a71b11fa1bbf8bafb5 Mon Sep 17 00:00:00 2001 From: "Mac\\David" Date: Wed, 7 Aug 2024 14:29:54 +0800 Subject: [PATCH] david pending tasks --- src/app/api/financialsummary/actions.ts | 15 ++- .../ProgressByClient/ProgressByClient.tsx | 10 +- .../ProgressByTeam/ProgressByTeam.tsx | 10 +- .../ProjectFinancialSummary.tsx | 98 ++++++++++++++++--- .../ProjectResourceConsumptionRanking.tsx | 10 +- 5 files changed, 114 insertions(+), 29 deletions(-) diff --git a/src/app/api/financialsummary/actions.ts b/src/app/api/financialsummary/actions.ts index 41baac2..eb7bc02 100644 --- a/src/app/api/financialsummary/actions.ts +++ b/src/app/api/financialsummary/actions.ts @@ -54,7 +54,20 @@ export const searchFinancialSummaryByClient = cache(async (teamId?: number) => { }); -export const searchFinancialSummaryByProject = cache(async (teamId?: number, customerId?:number) => { +export const searchFinancialSummaryByProject = cache(async (teamId?: number) => { + if (teamId === undefined) { + return serverFetchJson( + `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject` + ); + } else { + return serverFetchJson( + `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject?teamId=${teamId}` + ); + } + +}); + +export const searchFinancialSummaryByProjectOld = cache(async (teamId?: number, customerId?:number) => { if (teamId === undefined) { return serverFetchJson( `${BASE_API_URL}/dashboard/searchFinancialSummaryByProject` diff --git a/src/components/ProgressByClient/ProgressByClient.tsx b/src/components/ProgressByClient/ProgressByClient.tsx index 17324ee..ffdbb55 100644 --- a/src/components/ProgressByClient/ProgressByClient.tsx +++ b/src/components/ProgressByClient/ProgressByClient.tsx @@ -572,19 +572,19 @@ const ProgressByClient: React.FC = () => {
diff --git a/src/components/ProgressByTeam/ProgressByTeam.tsx b/src/components/ProgressByTeam/ProgressByTeam.tsx index f1bf78c..037d043 100644 --- a/src/components/ProgressByTeam/ProgressByTeam.tsx +++ b/src/components/ProgressByTeam/ProgressByTeam.tsx @@ -663,19 +663,19 @@ const ProgressByTeam: React.FC = () => {
diff --git a/src/components/ProjectFinancialSummary/ProjectFinancialSummary.tsx b/src/components/ProjectFinancialSummary/ProjectFinancialSummary.tsx index b16db56..d99b7ea 100644 --- a/src/components/ProjectFinancialSummary/ProjectFinancialSummary.tsx +++ b/src/components/ProjectFinancialSummary/ProjectFinancialSummary.tsx @@ -19,11 +19,16 @@ import SearchBox, { Criterion } from "../SearchBox"; import ProgressByClientSearch from "@/components/ProgressByClientSearch"; import { Suspense } from "react"; import { fetchFinancialSummaryCard } from "@/app/api/financialsummary"; -import { exportFinancialSummaryByClientExcel, exportFinancialSummaryByProjectExcel, searchFinancialSummaryByClient,searchFinancialSummaryByProject } from "@/app/api/financialsummary/actions"; +import { exportFinancialSummaryByClientExcel, exportFinancialSummaryByProjectExcel, FinancialSummaryByProjectResult, FinancialSummaryByClientResult, searchFinancialSummaryByClient,searchFinancialSummaryByProject } from "@/app/api/financialsummary/actions"; import ProjectFinancialCard from "./ProjectFinancialCard"; import VisibilityIcon from '@mui/icons-material/Visibility'; import { downloadFile } from "@/app/utils/commonUtil"; +type SearchProjectQuery = Partial>; +type SearchClientQuery = Partial>; +type SearchProjectParamNames = keyof SearchProjectQuery; +type SearchClientParamNames = keyof SearchClientQuery; + const ProjectFinancialSummary: React.FC = () => { const [SearchCriteria, setSearchCriteria] = React.useState({}); const { t } = useTranslation("dashboard"); @@ -31,6 +36,24 @@ const ProjectFinancialSummary: React.FC = () => { const [projectFinancialData, setProjectFinancialData]: any[] = React.useState([]); const [clientFinancialRows, setClientFinancialRows]: any[] = React.useState([]); const [projectFinancialRows, setProjectFinancialRows]: any[] = React.useState([]); + const [filteredProjectResult, setFilteredProjectResult]:any[] = useState([]); + const [filteredClientResult, setFilteredClientResult]:any[] = useState([]); + + const projectSearchCriteria: Criterion[] = useMemo( + () => [ + { label: "Project Code", paramName: "projectCode", type: "text" }, + { label: "Project Name", paramName: "projectName", type: "text" }, + ], + [t], + ); + const clientSearchCriteria: Criterion[] = useMemo( + () => [ + { label: "Client Code", paramName: "customerCode", type: "text" }, + { label: "Client Name", paramName: "customerName", type: "text" }, + ], + [t], + ); + const fetchData = async () => { const financialSummaryCard = await fetchFinancialSummaryCard(); setProjectFinancialData(financialSummaryCard) @@ -41,10 +64,11 @@ const ProjectFinancialSummary: React.FC = () => { console.log(financialSummaryByClient) // console.log(financialSummaryByProject) setClientFinancialRows(financialSummaryByClient) + setFilteredClientResult(financialSummaryByClient) } useEffect(() => { fetchData() - fetchTableData(undefined) + // fetchTableData(undefined) }, []); const rows0 = [{id: 1,projectCode:"M1201",projectName:"Consultancy Project C", team:"XXX", teamLeader:"XXX", startDate:"01/08/2022", targetEndDate: "01/05/2024", client:"Client A", subsidiary:"N/A"}, @@ -77,6 +101,7 @@ const ProjectFinancialSummary: React.FC = () => { const handleCardClick = (r: any, index:any) => { fetchTableData(r.teamId) + fetchProjectTableData(r.teamId) setIsCardClickedIndex(index) }; @@ -450,13 +475,14 @@ const columns2 = [ }; const fetchProjectTableData = async (teamId?:any,customerId?:any) => { - const financialSummaryByProject = await searchFinancialSummaryByProject(teamId,customerId); + const financialSummaryByProject = await searchFinancialSummaryByProject(teamId); setProjectFinancialRows(financialSummaryByProject) + setFilteredProjectResult(financialSummaryByProject) } const handleRowClick = (params:any) => { console.log(params.row.teamId); - fetchProjectTableData(params.row.teamId,params.row.cid) + // fetchProjectTableData(params.row.teamId,params.row.cid) }; const handleExportByClient = async () => { @@ -486,37 +512,83 @@ const columns2 = [
))} +
+
-Formula-
+
CPI: Invoiced Amount / Cumulative Expenditure
+
Cash Flow Status: {`Positive when CPI >= 1`}
+
Projected CPI: Project Fee / Cumulative Expenditure
+
Cash Flow Status: {`Positive when Projected CPI >= 1`}
- +
- {clientFinancialRows.length > 0 && ( - )}
+ {projectFinancialRows.length > 0 && ( + { + setFilteredProjectResult( + projectFinancialRows.filter( + (cp:any) => + cp.projectCode.toLowerCase().includes(query.projectCode.toLowerCase()) && + cp.projectName.toLowerCase().includes(query.projectName.toLowerCase()) + ), + ); + }} + /> + )}
- {/* */} - +
+
+
-Formula-
+
CPI: Invoiced Amount / Cumulative Expenditure
+
Cash Flow Status: {`Positive when CPI >= 1`}
+
Projected CPI: Project Fee / Cumulative Expenditure
+
Cash Flow Status: {`Positive when Projected CPI >= 1`}
- +
- {projectFinancialRows.length > 0 && ( - )}
+ {clientFinancialRows.length > 0 && ( + { + setFilteredClientResult( + clientFinancialRows.filter( + (cp:any) => + cp.customerCode.toLowerCase().includes(query.customerCode.toLowerCase()) && + cp.customerName.toLowerCase().includes(query.customerName.toLowerCase()) + ), + ); + }} + /> + )}
- + {/* */} +
+
+
-Formula-
+
CPI: Invoiced Amount / Cumulative Expenditure
+
Cash Flow Status: {`Positive when CPI >= 1`}
+
Projected CPI: Project Fee / Cumulative Expenditure
+
Cash Flow Status: {`Positive when Projected CPI >= 1`}
); diff --git a/src/components/ProjectResourceConsumptionRanking/ProjectResourceConsumptionRanking.tsx b/src/components/ProjectResourceConsumptionRanking/ProjectResourceConsumptionRanking.tsx index 398ef00..636a9fc 100644 --- a/src/components/ProjectResourceConsumptionRanking/ProjectResourceConsumptionRanking.tsx +++ b/src/components/ProjectResourceConsumptionRanking/ProjectResourceConsumptionRanking.tsx @@ -788,19 +788,19 @@ const ProjectResourceConsumptionRanking: React.FC = () => {