feat(loans): Pending EMI column + one-off July 2026 accrual fix - #36
Merged
Conversation
Shows how many installments are still unpaid (scheduled + partially paid + overdue) per EMI loan; accrual-model loans render a dash. loan_emi_balances exposes overdue/past-due counts but not the remaining-term count, so both list pages tally loan_emi_schedule rows directly — added as a third leg of the existing Promise.all, so no extra latency. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Loans converted to EMI were charged July interest twice: the EOM cron wrote a period_end 2026-07-31 accrual while the loan was still on the accrual model, and installment #1 (due 2026-08-10) already carries July's interest under the 041 due-on-the-10th model. Preview / delete / verify statements, scoped to repayment_model = 'emi' and that single period_end, skipping any accrual with a settlement (the junction FK is ON DELETE RESTRICT). Includes a waive-instead-of-delete variant. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #35.
1. Pending EMI column
New column between EMI and Start date showing the number of installments still unpaid — a plain count, not a rupee value. Accrual-model loans render
—.src/lib/constants.ts—UNPAID_EMI_STATUSES = ['scheduled', 'partially_paid', 'overdue'], matching the filterloan_emi_balancesuses forpending_interest/next_due_date./dashboard/loans,/admin/loans) tallyloan_emi_schedulerows in those statuses per loan.loan_emi_balancesexposes overdue/past-due counts but not the remaining-term count, so this counts schedule rows directly rather than needing a view migration. Added as a third leg of the existingPromise.all— no extra latency.2.
scripts/prod/fix-emi-cutover-duplicate-accruals.sql(one-off, not a migration)Loans converted to the EMI model are charged July 2026 interest twice:
loan_interest_accruals— the EOM cron wrote aperiod_end = 2026-07-31row while the loan was still on the accrual model.loan_emi_schedule— installment Split deployment pipeline per action #1 is due2026-08-10, and under the migration 041 model an installment due on the 10th carries the previous month's interest, i.e. July.The script has preview → delete → verify statements, scoped to
repayment_model = 'emi'and that singleperiod_end. Accruals with any settlement are skipped (loan_interest_payments.accrual_idisON DELETE RESTRICT, so a part-paid row would abort the statement). A waive-instead-of-delete variant is included, commented out, for keeping the month visible in the audit timeline.Going forward the cron is already correct —
fn_compute_loan_interest_forskipsrepayment_model = 'emi'(migration 039, patch E). This only cleans up rows written before each loan was converted. The remaining gap:convertToEmidoesn't waive an existing accrual for the cutover month, so a loan converted after a month-end run will recreate the overlap. Not fixed here.Verification
npm run build✅tsc --noEmit✅npm run lint✅ (only the pre-existing_prevwarning inpending-interest-panel.tsx)npm test✅ 244 passed / 23 filesThe SQL script has not been run against any database.
🤖 Generated with Claude Code