| @@ -23,11 +23,6 @@ type DateParams = { | |||||
| [key: number]: InputDate; | [key: number]: InputDate; | ||||
| } | } | ||||
| type ComboParams = { | |||||
| [key: number]: string; | |||||
| } | |||||
| const FinancialSummaryPage: React.FC<Props> = ({ | const FinancialSummaryPage: React.FC<Props> = ({ | ||||
| _teamId, | _teamId, | ||||
| financialSummByProject | financialSummByProject | ||||
| @@ -41,7 +36,7 @@ const FinancialSummaryPage: React.FC<Props> = ({ | |||||
| // currYear = 2024 | // currYear = 2024 | ||||
| const startDate = "10-01" | const startDate = "10-01" | ||||
| const endDate = "09-30" | const endDate = "09-30" | ||||
| const lengthOfCombo = 10 | |||||
| const lengthOfYear = 5 | |||||
| const currFinancialYear = useMemo(() => currDate > `${currYear}-${startDate}` ? currYear + 1 : currYear, [currYear]) | const currFinancialYear = useMemo(() => currDate > `${currYear}-${startDate}` ? currYear + 1 : currYear, [currYear]) | ||||
| const [mainData, setMainData] = useState<FinancialByProject[]>(financialSummByProject) | const [mainData, setMainData] = useState<FinancialByProject[]>(financialSummByProject) | ||||
| const [byTeam, setByTeam] = useState<SumOfByTeam[]>(() => sumUpByTeam(mainData)) // do fetch to set | const [byTeam, setByTeam] = useState<SumOfByTeam[]>(() => sumUpByTeam(mainData)) // do fetch to set | ||||
| @@ -85,16 +80,16 @@ const FinancialSummaryPage: React.FC<Props> = ({ | |||||
| const map: DateParams = { | const map: DateParams = { | ||||
| 0: {startDate: "", endDate: ""}, | 0: {startDate: "", endDate: ""}, | ||||
| 1: thisYear, | 1: thisYear, | ||||
| [lengthOfCombo - 1]: {startDate: "", endDate: `${currFinancialYear-(lengthOfCombo - 2)}-${endDate}`} | |||||
| [lengthOfYear - 1]: {startDate: "", endDate: `${currFinancialYear-(lengthOfYear - 2)}-${endDate}`} | |||||
| } | } | ||||
| for (let i = 2; i < lengthOfCombo - 1; i++) { | |||||
| for (let i = 2; i < lengthOfYear - 1; i++) { | |||||
| map[i] = { | map[i] = { | ||||
| startDate: `${currFinancialYear-i}-${startDate}`, | startDate: `${currFinancialYear-i}-${startDate}`, | ||||
| endDate: `${currFinancialYear-(i - 1)}-${endDate}` | endDate: `${currFinancialYear-(i - 1)}-${endDate}` | ||||
| } | } | ||||
| } | } | ||||
| return map | return map | ||||
| }, [currDate, currYear, currFinancialYear, startDate, endDate, lengthOfCombo]) | |||||
| }, [currDate, currYear, currFinancialYear, startDate, endDate, lengthOfYear]) | |||||
| // const comboList: string[] = useMemo(() => { | // const comboList: string[] = useMemo(() => { | ||||
| // const list = ["All"] | // const list = ["All"] | ||||
| @@ -113,15 +108,15 @@ const FinancialSummaryPage: React.FC<Props> = ({ | |||||
| const comboList: string[] = useMemo(() => { | const comboList: string[] = useMemo(() => { | ||||
| const list = ["All"]; | const list = ["All"]; | ||||
| for (let i = 1; i < lengthOfCombo - 1; i++) { | |||||
| for (let i = 1; i < lengthOfYear - 1; i++) { | |||||
| const yearRange = `${currFinancialYear - i} - ${currFinancialYear - i + 1}`; | const yearRange = `${currFinancialYear - i} - ${currFinancialYear - i + 1}`; | ||||
| const label = i === 1 ? `${yearRange} ${t("(current year)")}` : yearRange; | const label = i === 1 ? `${yearRange} ${t("(current year)")}` : yearRange; | ||||
| list.push(label); | list.push(label); | ||||
| } | } | ||||
| const oldestYear = currFinancialYear - (lengthOfCombo - 2); | |||||
| const oldestYear = currFinancialYear - (lengthOfYear - 2); | |||||
| list.push(`< ${oldestYear}`); | list.push(`< ${oldestYear}`); | ||||
| return list; | return list; | ||||
| }, [currFinancialYear, lengthOfCombo, t]); | |||||
| }, [currFinancialYear, lengthOfYear, t]); | |||||
| const fetchFinancialSummaryByProject = useCallback(async (endDate: string, startDate: string) => { | const fetchFinancialSummaryByProject = useCallback(async (endDate: string, startDate: string) => { | ||||
| setIsLoading(true) | setIsLoading(true) | ||||
| @@ -158,7 +153,7 @@ const FinancialSummaryPage: React.FC<Props> = ({ | |||||
| setByClient(sumUpByClient(mainData)) | setByClient(sumUpByClient(mainData)) | ||||
| } | } | ||||
| }, [teamId]) | }, [teamId]) | ||||
| return ( | return ( | ||||
| <> | <> | ||||
| <Card sx={{ display: "block" }}> | <Card sx={{ display: "block" }}> | ||||
| @@ -189,7 +184,7 @@ const FinancialSummaryPage: React.FC<Props> = ({ | |||||
| <CardContent component={Stack} spacing={4}> | <CardContent component={Stack} spacing={4}> | ||||
| <div className="ml-10 mr-10" style={{ display: 'flex', flexWrap: 'wrap', justifyContent: 'start'}}> | <div className="ml-10 mr-10" style={{ display: 'flex', flexWrap: 'wrap', justifyContent: 'start'}}> | ||||
| {_teamId == 0 && allTeam && | {_teamId == 0 && allTeam && | ||||
| <div className="hover:cursor-pointer ml-4 inline-block" key={0} onClick={() => handleCardClick(0)}> | |||||
| <div className="hover:cursor-pointer ml-4 mb-2 inline-block" key={0} onClick={() => handleCardClick(0)}> | |||||
| <ProjectFinancialCard | <ProjectFinancialCard | ||||
| Title={t("All Team")} | Title={t("All Team")} | ||||
| TeamId={0} | TeamId={0} | ||||
| @@ -203,14 +198,14 @@ const FinancialSummaryPage: React.FC<Props> = ({ | |||||
| // TotalUnInvoicedAmount={allTeam.uninvoicedAmount} | // TotalUnInvoicedAmount={allTeam.uninvoicedAmount} | ||||
| TotalReceivedAmount={allTeam.paidAmount} | TotalReceivedAmount={allTeam.paidAmount} | ||||
| CashFlowStatus={allTeam.invoicedAmount >= (allTeam.projectExpense + allTeam.manhourExpense) ? "Positive" : "Negative"} | CashFlowStatus={allTeam.invoicedAmount >= (allTeam.projectExpense + allTeam.manhourExpense) ? "Positive" : "Negative"} | ||||
| CostPerformanceIndex={isFinite(allTeam.invoicedAmount/(allTeam.projectExpense + allTeam.manhourExpense)) ? 0 : allTeam.invoicedAmount/(allTeam.projectExpense + allTeam.manhourExpense) || 0} | |||||
| CostPerformanceIndex={!isFinite(allTeam.invoicedAmount/(allTeam.projectExpense + allTeam.manhourExpense)) ? 0 : allTeam.invoicedAmount/(allTeam.projectExpense + allTeam.manhourExpense) || 0} | |||||
| ProjectedCashFlowStatus={allTeam.totalFee >= (allTeam.projectExpense + allTeam.manhourExpense) ? "Positive" : "Negative"} | ProjectedCashFlowStatus={allTeam.totalFee >= (allTeam.projectExpense + allTeam.manhourExpense) ? "Positive" : "Negative"} | ||||
| ProjectedCPI={isFinite(allTeam.totalFee/(allTeam.projectExpense + allTeam.manhourExpense)) ? 0 : allTeam.totalFee/(allTeam.projectExpense + allTeam.manhourExpense) || 0} | |||||
| ProjectedCPI={!isFinite(allTeam.totalFee/(allTeam.projectExpense + allTeam.manhourExpense)) ? 0 : allTeam.totalFee/(allTeam.projectExpense + allTeam.manhourExpense) || 0} | |||||
| ClickedIndex={isCardClickedIndex} | ClickedIndex={isCardClickedIndex} | ||||
| Index={0}/> | Index={0}/> | ||||
| </div>} | </div>} | ||||
| {byTeam.length > 0 && byTeam.map((record) => ( | {byTeam.length > 0 && byTeam.map((record) => ( | ||||
| <div className="hover:cursor-pointer ml-4 inline-block" key={record.id} onClick={() => handleCardClick(record.id)}> | |||||
| <div className="hover:cursor-pointer ml-4 mb-2 inline-block" key={record.id} onClick={() => handleCardClick(record.id)}> | |||||
| <ProjectFinancialCard | <ProjectFinancialCard | ||||
| Title={record.team} | Title={record.team} | ||||
| TeamId={record.id} | TeamId={record.id} | ||||
| @@ -224,9 +219,9 @@ const FinancialSummaryPage: React.FC<Props> = ({ | |||||
| // TotalUnInvoicedAmount={Math.abs(record.uninvoicedAmount)} | // TotalUnInvoicedAmount={Math.abs(record.uninvoicedAmount)} | ||||
| TotalReceivedAmount={record.paidAmount} | TotalReceivedAmount={record.paidAmount} | ||||
| CashFlowStatus={record.invoicedAmount >= (record.projectExpense + record.manhourExpense) ? "Positive" : "Negative"} | CashFlowStatus={record.invoicedAmount >= (record.projectExpense + record.manhourExpense) ? "Positive" : "Negative"} | ||||
| CostPerformanceIndex={record.invoicedAmount/(record.projectExpense + record.manhourExpense) || 0} | |||||
| CostPerformanceIndex={!isFinite(record.invoicedAmount/(record.projectExpense + record.manhourExpense)) ? 0 : record.invoicedAmount/(record.projectExpense + record.manhourExpense) || 0} | |||||
| ProjectedCashFlowStatus={record.totalFee >= (record.projectExpense + record.manhourExpense) ? "Positive" : "Negative"} | ProjectedCashFlowStatus={record.totalFee >= (record.projectExpense + record.manhourExpense) ? "Positive" : "Negative"} | ||||
| ProjectedCPI={record.totalFee/(record.projectExpense + record.manhourExpense) || 0} | |||||
| ProjectedCPI={!isFinite(record.totalFee/(record.projectExpense + record.manhourExpense)) ? 0 : record.totalFee/(record.projectExpense + record.manhourExpense) || 0} | |||||
| ClickedIndex={isCardClickedIndex} | ClickedIndex={isCardClickedIndex} | ||||
| Index={record.id}/> | Index={record.id}/> | ||||
| </div> | </div> | ||||