fixed build

This commit is contained in:
Khalim Conn-Kowlessar 2025-08-21 23:06:12 +00:00
parent 05438a8f44
commit 8a5e029b03
4 changed files with 58 additions and 16 deletions

View file

@ -1,6 +1,7 @@
"use client";
import { useState } from "react";
import { convertDaysToWorkingWeeks, formatNumber } from "@/app/utils";
import { formatNumber } from "@/app/utils";
interface SummaryBoxProps {
scenarios: Array<{
@ -8,6 +9,8 @@ interface SummaryBoxProps {
name: string;
budget: number | null;
totalCost: number | null;
funding: number | null;
contingency: number | null;
co2EquivalentSavings: number | null;
propertyValuationIncrease: number | null;
energySavings: number | null;
@ -33,6 +36,15 @@ function SummaryBox({ scenarios, numProperties }: SummaryBoxProps) {
const [totalCostFormatted, setTotalCostFormatted] = useState(
formatMoney(defaultScenario.totalCost)
);
const [funding, setFunding] = useState(
formatMoney(defaultScenario.funding)
);
const [netCost, setNetCost] = useState(
formatMoney((defaultScenario.totalCost || 0) - (defaultScenario.funding || 0))
);
const [contingency, setContingency] = useState(
formatMoney(defaultScenario.contingency)
);
const [totalValueIncreaseFormatted, setTotalValueIncreaseFormatted] =
useState(formatMoney(defaultScenario.propertyValuationIncrease));
const [energyCostSavingsFormatted, setEnergyCostSavingsFormatted] = useState(
@ -56,6 +68,13 @@ function SummaryBox({ scenarios, numProperties }: SummaryBoxProps) {
setBudgetFormatted(formatBudget(selectedScenario.budget));
setTotalCostFormatted(formatMoney(selectedScenario.totalCost));
setFunding(formatMoney(selectedScenario.funding));
setNetCost(
formatMoney(
(selectedScenario.totalCost || 0) - (selectedScenario.funding || 0)
)
);
setContingency(formatMoney(selectedScenario.contingency));
setTotalValueIncreaseFormatted(
formatMoney(selectedScenario.propertyValuationIncrease)
);
@ -119,18 +138,36 @@ function SummaryBox({ scenarios, numProperties }: SummaryBoxProps) {
<table className="w-full">
<tbody>
<tr>
<td className="text-brandblue">Total Budget</td>
<td className="text-brandblue text-end">{budgetFormatted}</td>
<td className="text-brandblue">Budget</td>
<td className="text-brandblue text-end font-bold">{budgetFormatted}</td>
</tr>
<tr>
<td className="text-brandblue">Total Cost</td>
<td className="text-brandblue text-end">
<td className="text-brandblue">Cost</td>
<td className="text-brandblue text-end font-bold">
{totalCostFormatted}
</td>
</tr>
<tr>
<td className="text-brandblue">Funding</td>
<td className="text-brandblue text-end font-bold">
{funding}
</td>
</tr>
<tr>
<td className="text-brandblue ">Cost after funding</td>
<td className="text-brandblue text-end font-bold">
{netCost}
</td>
</tr>
<tr>
<td className="text-brandblue">Contingency</td>
<td className="text-brandblue text-end font-bold">
{contingency}
</td>
</tr>
<tr>
<td className="text-brandblue">Total properties</td>
<td className="text-brandblue text-end">{numProperties}</td>
<td className="text-brandblue text-end font-bold">{numProperties}</td>
</tr>
</tbody>
</table>
@ -149,13 +186,13 @@ function SummaryBox({ scenarios, numProperties }: SummaryBoxProps) {
</span>{" "}
Savings
</td>
<td className="text-brandblue text-end">
<td className="text-brandblue text-end font-bold">
{co2EquivalentSavingsFormatted}
</td>
</tr>
<tr>
<td className="text-brandblue">Annual Energy Savings</td>
<td className="text-brandblue text-end">
<td className="text-brandblue text-end font-bold">
{energySavingsFormatted}
</td>
</tr>
@ -164,19 +201,19 @@ function SummaryBox({ scenarios, numProperties }: SummaryBoxProps) {
</div>
<div className="p-4 bg-gray-50 rounded-lg">
<h3 className="text-lg font-semibold text-brandblue mb-2">
Financial Impact
Bills and Property Valuation
</h3>
<table className="w-full">
<tbody>
<tr>
<td className="text-brandblue">Annual Energy Bill Reduction</td>
<td className="text-brandblue text-end">
<td className="text-brandblue text-end font-bold">
{energyCostSavingsFormatted}
</td>
</tr>
<tr>
<td className="text-brandblue">Total Value Increase</td>
<td className="text-brandblue text-end">
<td className="text-brandblue text-end font-bold">
{totalValueIncreaseFormatted}
</td>
</tr>

View file

@ -199,7 +199,7 @@ export type RecommendationType =
| "extension_cavity_wall_insulation";
export type UnnestedRecommendation = {
quantity: number;
quantity: number | null;
quantityUnit: string | null;
estimatedCost: number;
materialType: string | null;
@ -209,7 +209,7 @@ export type UnnestedRecommendation = {
};
export interface PortfolioPlanRecommendation {
quantity: number;
quantity: number | null; // Allow null for cases where no materials are associated
quantityUnit: string | null;
estimatedCost: number;
materialType: string | null;

View file

@ -44,6 +44,8 @@ export default async function Page(
name: performance.name || "Default Scenario",
budget: performance.budget,
totalCost: performance.cost,
funding: performance.funding,
contingency: performance.contingency,
co2EquivalentSavings: performance.co2EquivalentSavings,
propertyValuationIncrease: performance.propertyValuationIncrease,
energySavings: performance.energySavings,
@ -59,6 +61,8 @@ export default async function Page(
name: "Default",
budget: portfolio.budget,
totalCost: portfolio.cost,
funding: 0,
contingency: 0,
co2EquivalentSavings: portfolio.co2EquivalentSavings,
propertyValuationIncrease: portfolio.propertyValuationIncrease,
energySavings: portfolio.energySavings,

View file

@ -460,7 +460,7 @@ export async function getProperties(
}
interface UnaggregatedPortfolioPlanRecommendation {
quantity: number;
quantity: number | null; // Allow null for cases where no materials are associated
quantityUnit: string | null;
estimatedCost: number;
materialType: string | null;
@ -496,7 +496,8 @@ function aggregateRecommendations(
: new Set(),
};
} else {
grouped[key].quantity += item.quantity;
// if quantity is null previously, set to 0
grouped[key].quantity = (grouped[key].quantity ?? 0) + (item.quantity ?? 0);
grouped[key].estimatedCost += item.estimatedCost;
if (item.propertyId) {
@ -511,7 +512,7 @@ function aggregateRecommendations(
// Round the results to 2 decimal places, compute uniquePropertyCount, and count unique measureTypes
for (const key in grouped) {
grouped[key].quantity = parseFloat(grouped[key].quantity.toFixed(2));
grouped[key].quantity = parseFloat(grouped[key].quantity?.toFixed(2) || "0.00");
grouped[key].estimatedCost = parseFloat(
grouped[key].estimatedCost.toFixed(2)
);