From a88d5c4647376161e7832c4dbb6c649ea41b5cc2 Mon Sep 17 00:00:00 2001 From: null Date: Wed, 3 Jun 2026 23:08:20 -0500 Subject: [PATCH] fix: move cashflow calculations before the cashflow block reference --- services/trackerService.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/trackerService.js b/services/trackerService.js index 3ac4d71..665b298 100644 --- a/services/trackerService.js +++ b/services/trackerService.js @@ -373,6 +373,11 @@ function getTracker(userId, query = {}, now = new Date()) { const periodEndDay = activeRemainingPeriod === '1st' ? 14 : lastDayOfMonth; const periodEndLabel = `${['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][month - 1]} ${periodEndDay}`; + const activeTotalPaid = roundMoney(activeRows.reduce((s, r) => s + r.total_paid, 0)); + const activePaidTowardDue = roundMoney(activeRows.reduce((s, r) => s + rowPaidTowardDue(r), 0)); + const activeTotalExpected = roundMoney(activeRows.reduce((s, r) => s + rowDueAmount(r), 0)); + const activeOutstandingBalance = roundMoney(activeRows.reduce((s, r) => s + Math.max(r.balance || 0, 0), 0)); + const periodBillsTotal = roundMoney(periodRows.reduce((s, r) => s + rowDueAmount(r), 0)); const periodPaidCount = periodRows.filter(r => ['paid', 'autodraft'].includes(r.status)).length; const periodTotalCount = periodRows.length; @@ -406,10 +411,6 @@ function getTracker(userId, query = {}, now = new Date()) { month_total_count: monthTotalCount, month_projected: monthProjected, }; - const activeTotalPaid = roundMoney(activeRows.reduce((s, r) => s + r.total_paid, 0)); - const activePaidTowardDue = roundMoney(activeRows.reduce((s, r) => s + rowPaidTowardDue(r), 0)); - const activeTotalExpected = roundMoney(activeRows.reduce((s, r) => s + rowDueAmount(r), 0)); - const activeOutstandingBalance = roundMoney(activeRows.reduce((s, r) => s + Math.max(r.balance || 0, 0), 0)); const totalOverdue = roundMoney(rows .filter(r => !r.is_skipped && (r.status === 'late' || r.status === 'missed')) .reduce((s, r) => s + r.balance, 0));