Skip to content

fix(loans): Pending EMI counts installments due as of this month - #37

Merged
parameshjava merged 1 commit into
mainfrom
fix/pending-emi-current-month
Aug 6, 2026
Merged

fix(loans): Pending EMI counts installments due as of this month#37
parameshjava merged 1 commit into
mainfrom
fix/pending-emi-current-month

Conversation

@parameshjava

Copy link
Copy Markdown
Owner

Follow-up to #36.

Problem

The Pending EMI column was counting every unpaid installment on the schedule — i.e. the remaining term. A loan converted at the cutover with a 12-month term read 12, which says nothing about what the member owes now.

Change

It now counts unpaid installments (scheduled + partially_paid + overdue) with due_date <= last day of the current month (IST). That's carry-over from earlier months plus this month's installment. For the five converted loans today (06-08-2026, next EMI 10-08-2026) it reads 1 instead of 12.

Why month-end and not today's date: with a due_date <= today cut-off the column would read 0 for every loan for the first nine days of each month, since installments fall due on the 10th. Month-end makes "1" mean "one EMI to pay this month".

  • src/lib/due.ts — new endOfMonth(iso) helper + 5 tests (leap year, 30/31-day months, idempotence at month end).
  • Both list pages now derive todayIso once — it was being computed twice per render — and pass the month-end cut-off to the count query.
  • Counts above 1 render amber with a tooltip ("N installments payable as of this month"); 0 gets "Nothing due this month".

Verification

  • npm run build
  • tsc --noEmit
  • npm run lint ✅ (only the pre-existing _prev warning in pending-interest-panel.tsx)
  • npm test ✅ 249 passed / 23 files (up from 244 — the 5 new endOfMonth cases)

🤖 Generated with Claude Code

The column was showing the whole remaining term (12 for a freshly converted
loan). It now counts unpaid installments due on or before the current month's
end (IST) — carry-over from earlier months plus this month's — so it answers
"how many EMIs does this member owe right now".

Month-end rather than today's date is the cut-off, so an installment due on
the 10th counts from the 1st instead of reading 0 for the first nine days of
every month.

- New endOfMonth() helper in lib/due.ts, with tests.
- Both list pages derive todayIso once (it was computed twice) and pass the
  month-end cut-off to the count query.
- Counts above 1 render amber with a tooltip, so a member falling behind is
  visible at a glance.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aits-fcf-tracker Ready Ready Preview Aug 6, 2026 3:12pm

@parameshjava
parameshjava merged commit a4433a6 into main Aug 6, 2026
2 of 3 checks passed
@parameshjava
parameshjava deleted the fix/pending-emi-current-month branch August 6, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant