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));