"use client"; import { FinancialSummaryByProject, FinancialSummaryByClient, FinancialByProject, } from "@/app/api/financialsummary"; import SearchBox, { Criterion } from "../SearchBox"; import { useEffect, useMemo, useState } from "react"; import CustomDatagrid from "../CustomDatagrid"; import { useTranslation } from "react-i18next"; import { useRouter } from "next/navigation"; import { Box, Grid } from "@mui/material"; import { SumOfByClient } from "./gptFn"; // import { summarizeFinancialData } from "./gptFn"; interface Props { financialSummByProject: FinancialByProject[]; financialSummByClient: SumOfByClient[]; } type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; type SearchQuery2 = Partial>; type SearchParamNames2 = keyof SearchQuery2; const FinancialStatusByProject: React.FC = ({ financialSummByProject, financialSummByClient }) => { console.log(financialSummByProject); // console.log(financialSummByClient); const { t } = useTranslation("dashboard"); const router = useRouter(); const [filteredByProjectRows, setFilteredByProjectRows] = useState(financialSummByProject); const [filteredByClientRows, setFilteredByClientRows] = useState(financialSummByClient); console.log(filteredByProjectRows); console.log(filteredByClientRows); // const testing = useMemo(() => summarizeFinancialData(filteredByProjectRows), []) const greenColor = "text-lime-500"; const redColor = "text-red-500"; const searchCriteria: Criterion[] = useMemo( () => [ { label: t("Project Code"), paramName: "projectCode", type: "text" }, { label: t("Project Name"), paramName: "projectName", type: "text" }, ], [t], ); const searchCriteria2: Criterion[] = useMemo( () => [ { label: t("Client Code"), paramName: "customerCode", type: "text" }, { label: t("Client Name"), paramName: "customerName", type: "text" }, ], [t], ); useEffect(() => { setFilteredByProjectRows(financialSummByProject); setFilteredByClientRows(financialSummByClient) }, [financialSummByProject, financialSummByClient]); const columns1 = [ { id: "projectCode", field: "projectCode", headerName: t("Project Code"), minWidth: 50, renderCell: (params: any) => (
{ router.push( `/dashboard/ProjectCashFlow?projectId=${params.row.id}` ); }} > {params.value}
), }, { id: "projectName", field: "projectName", headerName: t("Project Name"), minWidth: 50, }, { id: "customerName", field: "customerName", headerName: t("Client Name"), minWidth: 50, }, { id: "subsidiaryName", field: "subsidiaryName", headerName: t("Subsidiary"), minWidth: 50, }, { id: "cashFlowStatus", field: "cashFlowStatus", headerName: t("Cash Flow Status"), minWidth: 80, renderCell: (params: any) => { if (params.row.invoicedAmount >= params.row.cumulativeExpenditure) { return {t("Positive")}; } else { return {t("Negative")}; } }, }, { id: "cpi", field: "cpi", headerName: "CPI", minWidth: 50, renderCell: (params: any) => { var cpi = params.invoicedAmount/(params.projectExpense + params.invoicedAmount) || 0 return ( = 1 ? greenColor : redColor}> {cpi.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "projectedCashFlowStatus", field: "projectedCashFlowStatus", headerName: t("Projected Cash Flow Status"), minWidth: 100, renderCell: (params: any) => { var cumulativeExpenditure = params.row.projectExpense + params.row.invoicedAmount if (params.row.totalFee >= cumulativeExpenditure) { return {t("Positive")}; } else { return {t("Negative")}; } }, }, { id: "projectedCpi", field: "projectedCpi", headerName: t("Projected CPI"), minWidth: 50, renderCell: (params: any) => { var projectedCpi = params.row.totalFee/(params.row.projectExpense + params.row.invoicedAmount) return ( = 1 ? greenColor : redColor} > {projectedCpi.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "totalFee", field: "totalFee", headerName: t("Total Fees") + t("HKD"), type: "number", minWidth: 50, renderCell: (params: any) => { return ( $ {params.row.totalFee.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "totalBudget", field: "totalBudget", headerName: t("Total Budget") + t("HKD"), minWidth: 50, type: "number", renderCell: (params: any) => { return ( $ {params.row.totalBudget.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "cumulativeExpenditure", field: "cumulativeExpenditure", headerName: t("Total Cumulative Expenditure") + t("HKD"), minWidth: 250, type: "number", renderCell: (params: any) => { var cumulativeExpenditure = params.row.projectExpense + params.row.invoicedAmount return ( $ {cumulativeExpenditure.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "manhourExpense", field: "manhourExpense", headerName: t("Manpower Expenses") + t("HKD"), minWidth: 280, type: "number", renderCell: (params: any) => { return ( $ {params.row.manhourExpense.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "projectExpense", field: "projectExpense", headerName: t("Project Expense") + t("HKD"), minWidth: 280, type: "number", renderCell: (params: any) => { return ( $ {(params.row.projectExpense ?? 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "invoicedAmount", field: "invoicedAmount", headerName: t("Total Invoiced Amount") + t("HKD"), minWidth: 250, type: "number", renderCell: (params: any) => { return ( $ {params.row.invoicedAmount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "nonInvoicedAmount", field: "nonInvoicedAmount", headerName: t("Total Un-Invoiced Amount") + t("HKD"), minWidth: 250, type: "number", renderCell: (params: any) => { var nonInvoiced = params.row.totalFee - params.row.invoicedAmount return ( $ {nonInvoiced.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "paidAmount", field: "paidAmount", headerName: t("Total Received Amount") + t("HKD"), minWidth: 250, type: "number", renderCell: (params: any) => { return ( $ {params.row.paidAmount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, ]; const columns2 = [ { id: "customerCode", field: "customerCode", headerName: t("Client Code"), minWidth: 50, renderCell: (params: any) => (
{ router.push( `/dashboard/ProjectStatusByClient?customerId=${params.row.id}` ); }} > {params.value}
), }, { id: "customerName", field: "customerName", headerName: t("Client Name"), minWidth: 80, }, { id: "sumOfProjects", field: "sumOfProjects", headerName: t("Total Project Involved"), minWidth: 80, }, { id: "cashFlowStatus", field: "cashFlowStatus", headerName: t("Cash Flow Status"), minWidth: 100, renderCell: (params: any) => { var cumulativeExpenditure = params.row.projectExpense + params.row.invoicedAmount return params.row.invoicedAmount >= cumulativeExpenditure ? {t("Positive")} : {t("Negative")} }, }, { id: "cpi", field: "cpi", headerName: t("CPI"), minWidth: 50, renderCell: (params: any) => { var cumulativeExpenditure = params.row.projectExpense + params.row.invoicedAmount var cpi = cumulativeExpenditure != 0 ? params.row.invoicedAmount/cumulativeExpenditure : 0 var cpiString = cpi.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, }) return (cpi >= 1) ? {cpiString}: {cpiString} }, }, { id: "projectedCashFlowStatus", field: "projectedCashFlowStatus", headerName: t("Projected Cash Flow Status"), minWidth: 100, renderCell: (params: any) => { var cumulativeExpenditure = params.row.projectExpense + params.row.invoicedAmount var status = params.row.invoiceAmount >= cumulativeExpenditure return status ? {t("Positive")} : {t("Negative")} }, }, { id: "projectedCpi", field: "projectedCpi", headerName: t("Projected CPI"), minWidth: 50, renderCell: (params: any) => { var cumulativeExpenditure = params.row.projectExpense + params.row.invoicedAmount var projectCpi = cumulativeExpenditure != 0 ? params.row.totalFee/cumulativeExpenditure : 0 var projectCpiString = projectCpi.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, }) if (projectCpi >= 1) { return {projectCpiString}; } else { return {projectCpiString}; } }, }, { id: "totalFee", field: "totalFee", headerName: t("Total Fees") + t("HKD"), minWidth: 50, type: "number", renderCell: (params: any) => { return ( $ {params.row.totalFee.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "totalBudget", field: "totalBudget", headerName: t("Total Budget") + t("HKD"), minWidth: 50, type: "number", renderCell: (params: any) => { return ( $ {params.row.totalBudget.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "cumulativeExpenditure", field: "cumulativeExpenditure", headerName: t("Total Cumulative Expenditure") + t("HKD"), minWidth: 280, type: "number", renderCell: (params: any) => { var cumulativeExpenditure = params.row.projectExpense + params.row.invoicedAmount return ( $ {cumulativeExpenditure.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "manhourExpense", field: "manhourExpense", headerName: t("Manpower Expenses") + t("HKD"), minWidth: 280, type: "number", renderCell: (params: any) => { return ( $ {params.row.manhourExpense.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "projectExpense", field: "projectExpense", headerName: t("Project Expense") + t("HKD"), minWidth: 280, type: "number", renderCell: (params: any) => { return ( $ {(params.row.projectExpense ?? 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "invoicedAmount", field: "invoicedAmount", headerName: t("Total Invoiced Amount") + t("HKD"), minWidth: 250, type: "number", renderCell: (params: any) => { return ( $ {params.row.invoicedAmount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "nonInvoicedAmount", field: "nonInvoicedAmount", headerName: t("Total Un-Invoiced Amount") + t("HKD"), minWidth: 250, type: "number", renderCell: (params: any) => { var uninvoiced = params.row.totalFee - params.row.invoicedAmount return ( $ {uninvoiced.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, { id: "paidAmount", field: "paidAmount", headerName: t("Total Received Amount") + t("HKD"), minWidth: 250, type: "number", renderCell: (params: any) => { return ( $ {params.row.paidAmount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ); }, }, ]; return ( <> { setFilteredByProjectRows( filteredByProjectRows.filter( (cp:any) => cp.projectCode.toLowerCase().includes(query.projectCode.toLowerCase()) && cp.projectName.toLowerCase().includes(query.projectName.toLowerCase()) ), ); }} />
{/* items={filteredStaff} columns={columns} /> */}
{ setFilteredByClientRows( filteredByClientRows.filter( (cp:any) => cp.customerCode.toLowerCase().includes(query.customerCode.toLowerCase()) && cp.customerName.toLowerCase().includes(query.customerName.toLowerCase()) ), ); }} />
); }; export default FinancialStatusByProject;