-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
234 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { parseAsStringLiteral, useQueryState } from "nuqs"; | ||
|
||
import { CASH_FLOW_VIEWS } from "@/containers/projects/custom-project/annual-project-cash-flow/header/tabs"; | ||
|
||
export function useProjectCashFlowTab() { | ||
return useQueryState( | ||
"cashflowTab", | ||
parseAsStringLiteral(CASH_FLOW_VIEWS).withDefault("chart"), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
client/src/containers/projects/custom-project/annual-project-cash-flow/header/tabs/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
client/src/containers/projects/custom-project/annual-project-cash-flow/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { YearlyBreakdown } from "@shared/dtos/custom-projects/custom-project-output.dto"; | ||
|
||
function getBreakdownYears(data: YearlyBreakdown[]): string[] { | ||
if (data.length === 0) return []; | ||
|
||
return Object.keys(data[0].costValues) | ||
.map((y) => y) | ||
.sort((a, b) => Number(a) - Number(b)); | ||
} | ||
|
||
// TODO: This functionality will be used when backend API response is updated | ||
// function parseYearlyBreakdownForChart( | ||
// data: YearlyBreakdown[], | ||
// years: string[], | ||
// ) { | ||
// if (data.length === 0) return []; | ||
|
||
// let estimatedRenevueValues = {}; | ||
// let annualNetCashFlowValues = {}; | ||
|
||
// data.forEach((d) => { | ||
// switch (d.costName) { | ||
// case "estimatedRenevue": | ||
// estimatedRenevueValues = d.costValues; | ||
// break; | ||
// case "annualNetCashFlow": | ||
// annualNetCashFlowValues = d.costValues; | ||
// break; | ||
// default: | ||
// break; | ||
// } | ||
// }); | ||
|
||
// return years.map((y) => ({ | ||
// year: y, | ||
// estimatedRevenue: estimatedRenevueValues[y], | ||
// annualNetCashFlow: annualNetCashFlowValues[y], | ||
// })); | ||
// } | ||
|
||
export { getBreakdownYears }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
client/src/containers/projects/custom-project/cost-details/table/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { CustomProjectCostDetails } from "@shared/dtos/custom-projects/custom-project-output.dto"; | ||
|
||
import { formatCurrency } from "@/lib/format"; | ||
|
||
import { CostItem } from "@/containers/projects/custom-project/cost-details/table"; | ||
|
||
const capitalExpenditurePattern = | ||
/^(capitalExpenditure|feasibilityAnalysis|conservationPlanningAndAdmin|dataCollectionAndFieldCost|communityRepresentation|blueCarbonProjectPlanning|establishingCarbonRights|validation|implementationLabor)$/; | ||
const operationalExpenditurePattern = | ||
/^(operationalExpenditure|monitoring|maintenance|communityBenefitSharingFund|carbonStandardFees|baselineReassessment|mrv|longTermProjectOperatingCost)$/; | ||
const currencySettings = { maximumFractionDigits: 0 }; | ||
const customProjectCostDetailsLabelMap: Record< | ||
keyof CustomProjectCostDetails, | ||
string | ||
> = { | ||
capitalExpenditure: "Capital expenditure", | ||
operationalExpenditure: "Operating expenditure", | ||
totalCost: "Total cost", | ||
feasibilityAnalysis: "Feasibility analysis", | ||
conservationPlanningAndAdmin: "Conservation planning and admin", | ||
dataCollectionAndFieldCost: "Data collection and field costs", | ||
communityRepresentation: "Community representation", | ||
blueCarbonProjectPlanning: "Blue carbon project planning", | ||
establishingCarbonRights: "Establishing carbon rights", | ||
validation: "Validation", | ||
implementationLabor: "Implementation labor", | ||
monitoring: "Monitoring", | ||
maintenance: "Maintenance", | ||
communityBenefitSharingFund: "Community benefit sharing fund", | ||
carbonStandardFees: "Carbon standard fees", | ||
baselineReassessment: "Baseline reassessment", | ||
mrv: "MRV", | ||
longTermProjectOperatingCost: "Long-term project operating", | ||
} as const; | ||
|
||
function parseCostDetailsForTable(data: CustomProjectCostDetails): CostItem[] { | ||
const capitalItems: CostItem[] = []; | ||
const operationalItems: CostItem[] = []; | ||
|
||
Object.entries(data).forEach(([key, value]) => { | ||
if (key === "totalCost") { | ||
return; | ||
} | ||
|
||
const costItem: CostItem = { | ||
costName: key, | ||
label: | ||
customProjectCostDetailsLabelMap[key as keyof CustomProjectCostDetails], | ||
value: formatCurrency(value, currencySettings), | ||
}; | ||
|
||
if (capitalExpenditurePattern.test(key)) { | ||
capitalItems.push(costItem); | ||
} else if (operationalExpenditurePattern.test(key)) { | ||
operationalItems.push(costItem); | ||
} | ||
}); | ||
|
||
const totalCostItem: CostItem = { | ||
costName: "totalCost", | ||
label: "Total cost", | ||
value: formatCurrency(data.totalCost, currencySettings), | ||
}; | ||
|
||
// Array should be in this order | ||
return [...capitalItems, ...operationalItems, totalCostItem]; | ||
} | ||
|
||
export { parseCostDetailsForTable }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.