Implemented total cost and contingency

This commit is contained in:
Khalim Conn-Kowlessar 2025-12-08 22:42:46 +00:00
parent 6896307af7
commit eafb2090f9
6 changed files with 4825 additions and 7 deletions

View file

@ -14,13 +14,14 @@ type PlanRow = {
co2_savings: number | null;
energy_bill_savings: number | null;
energy_consumption_savings: number | null;
cost_of_works: number | null;
contingency_cost: number | null;
};
export async function GET(
request: NextRequest,
props: { params: Promise<{ portfolioId: string; scenarioId: string }> }
) {
console.log("In the request ");
const { portfolioId, scenarioId } = await props.params;
const pid = BigInt(portfolioId);
@ -38,7 +39,9 @@ export async function GET(
valuation_increase,
co2_savings,
energy_bill_savings,
energy_consumption_savings
energy_consumption_savings,
cost_of_works,
contingency_cost
FROM plan
WHERE portfolio_id = ${pid}
AND scenario_id = ${sid};
@ -80,8 +83,8 @@ export async function GET(
const total_bills = plans.reduce((s, r) => s + (r.post_energy_bill ?? 0), 0);
// Financial
const totalCost = 0;
const contingency = 0;
const totalCost = plans.reduce((s, r) => s + (r.cost_of_works ?? 0), 0);
const contingency = plans.reduce((s, r) => s + (r.contingency_cost ?? 0), 0);
const funding = Number(fundingRows.rows[0]?.total_funding ?? 0);
const netCost = totalCost - funding;

View file

@ -0,0 +1,6 @@
ALTER TABLE "property_details_epc" ADD COLUMN "lodgement_date" timestamp;--> statement-breakpoint
ALTER TABLE "property_details_epc" ADD COLUMN "is_expired" boolean;--> statement-breakpoint
ALTER TABLE "property_details_epc" ADD COLUMN "sap_05_score" real;--> statement-breakpoint
ALTER TABLE "property_details_epc" ADD COLUMN "sap_05_epc_rating" "epc";--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "cost_of_works" real;--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "contingency_cost" real;

File diff suppressed because it is too large Load diff

View file

@ -946,6 +946,13 @@
"when": 1764886152458,
"tag": "0134_lying_lester",
"breakpoints": true
},
{
"idx": 135,
"version": "7",
"when": 1765214013546,
"tag": "0135_lovely_spectrum",
"breakpoints": true
}
]
}

View file

@ -140,6 +140,9 @@ export const propertyDetailsEpc = pgTable("property_details_epc", {
.notNull()
.references(() => portfolio.id),
fullAddress: text("full_address"),
// Date the EPC was lodged
lodgementDate: timestamp("lodgement_date"),
isExpired: boolean("is_expired"),
totalFloorArea: real("total_floor_area"),
walls: text("walls"),
wallsRating: smallint("walls_rating"),
@ -181,6 +184,9 @@ export const propertyDetailsEpc = pgTable("property_details_epc", {
// We indicate if the property has an overwritten SAP 05 EPC. I.e. there is a valid EPC, however it's a SAP 05
// EPC which isn't particularly useful. This value is defaulted to False
sap05Overwritten: boolean("sap_05_overwritten").default(false),
// When we've overwritten a SAP 05 EPC, we store the SAP 05 score and rating here for reference
sap05Score: real("sap_05_score"),
sap05EpcRating: epcEnum("sap_05_epc_rating"),
// Include current estimates for energy bills, across the different types of energy
// These predictions are based on the EPC predicted consumptions + current energy prices
heatingEnergyCostCurrent: real("heating_cost_current"),

View file

@ -99,9 +99,6 @@ export const plan = pgTable("plan", {
createdAt: timestamp("created_at").notNull().defaultNow(),
isDefault: boolean("is_default").notNull(),
totalCost: real("total_cost"),
contingency: real("contingency"),
// ─────────────────────────────────────────────────────────
// Valuation metrics (existing)
// ─────────────────────────────────────────────────────────
@ -139,6 +136,10 @@ export const plan = pgTable("plan", {
valuationPostRetrofit: real("valuation_post_retrofit"),
valuationIncrease: real("valuation_increase"),
// Plan costing data
costOfWorks: real("cost_of_works"),
contingencyCost: real("contingency_cost"),
// ─────────────────────────────────────────────────────────
// Plan type stays as-is
// ─────────────────────────────────────────────────────────