From 16f267bcd4a211807c446fcfa18dd9ab2667028b Mon Sep 17 00:00:00 2001 From: nicoagostini Date: Thu, 22 May 2025 11:09:15 -0700 Subject: [PATCH] fix/calculations capped if you try to retire today --- src/util/calculations.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/calculations.js b/src/util/calculations.js index e521786..148b319 100644 --- a/src/util/calculations.js +++ b/src/util/calculations.js @@ -128,6 +128,10 @@ async function calculateProgress(plan, assets, users, userId) { const monthlyInvestment = (totalUserPlanValue - totalUserAssetValue + totalCostOfRetirement) / monthsUntilRetirement; const percentageCalculated = (totalUserAssetValue / (totalUserPlanValue + totalCostOfRetirement)) * 100; + + if (monthsUntilRetirement <= 0) { + return { monthlyInvestment: 0, totalCostOfRetirement: totalCostOfRetirement, monthsUntilRetirement: 0, yearsRetired: yearsRetired, yearsUntilRetirement: 0, percentage: 0 }; + } const progress = {};