Imported payments don't update debt balance (balance_delta always NULL) #49

Closed
opened 2026-05-16 21:43:00 -05:00 by null · 0 comments
Owner

Severity: CRITICAL 🔴

Affected Files

  • services/spreadsheetImportService.jscreatePaymentFromImport() and importRelatedPaidMonthsForNewBill()
  • routes/bills.js — import-related payment creation paths
  • client/pages/SnowballPage.jsx — projection reads balance_delta

Problem

Every payment creation path except spreadsheet import correctly computes and stores balance_delta then updates the bill's current_balance:

  • toggle-paid → calls computeBalanceDelta() → updates current_balance
  • quick-pay → calls computeBalanceDelta() → updates current_balance
  • bulk-pay → calls computeBalanceDelta() → updates current_balance
  • restore → checks balance_delta IS NOT NULL → reverses correctly

But imported payments:

  1. INSERT INTO payments never includes balance_delta
  2. Never calls computeBalanceDelta() or updates current_balance
  3. Are permanently orphaned from debt tracking

Impact

  • Snowball page balance stays wrong after an Excel import — the debt payoff timeline and remaining balance are silently incorrect.
  • Delete/restore is broken for imported payments — the restore path checks balance_delta IS NULL and silently skips the balance reversal, so the debt balance never recovers.
  • Any debt-related reporting is wrong — payment history shows payments but the running total ignores them.

Root Cause

spreadsheetImportService.js line ~1439 creates payment rows with:

INSERT INTO payments (bill_id, user_id, amount, paid_date, method, notes, month, year, ...)

No balance_delta column. No call to computeBalanceDelta(). No current_balance update on the parent bill.

Fix

  1. After inserting each imported payment, call the same computeBalanceDelta() logic used by all other payment paths.
  2. Update the bill's current_balance using the delta.
  3. Ensure delete/restore handles balance_delta = 0 correctly (not just NULL checks).

Acceptance Criteria

  • Imported payments compute and store balance_delta correctly
  • Bill current_balance is updated after import
  • Snowball page shows correct balance after import
  • Deleting an imported payment correctly reverses the balance delta
  • Restoring an imported payment correctly re-applies the balance delta
  • No regression in toggle-paid, quick-pay, bulk-pay, or manual payment balance tracking
## Severity: CRITICAL 🔴 ## Affected Files - `services/spreadsheetImportService.js` — `createPaymentFromImport()` and `importRelatedPaidMonthsForNewBill()` - `routes/bills.js` — import-related payment creation paths - `client/pages/SnowballPage.jsx` — projection reads balance_delta ## Problem Every payment creation path **except** spreadsheet import correctly computes and stores `balance_delta` then updates the bill's `current_balance`: - `toggle-paid` → calls `computeBalanceDelta()` → updates `current_balance` - `quick-pay` → calls `computeBalanceDelta()` → updates `current_balance` - `bulk-pay` → calls `computeBalanceDelta()` → updates `current_balance` - `restore` → checks `balance_delta IS NOT NULL` → reverses correctly But imported payments: 1. `INSERT INTO payments` never includes `balance_delta` 2. Never calls `computeBalanceDelta()` or updates `current_balance` 3. Are permanently orphaned from debt tracking ## Impact - **Snowball page balance stays wrong after an Excel import** — the debt payoff timeline and remaining balance are silently incorrect. - **Delete/restore is broken for imported payments** — the restore path checks `balance_delta IS NULL` and silently skips the balance reversal, so the debt balance never recovers. - **Any debt-related reporting is wrong** — payment history shows payments but the running total ignores them. ## Root Cause `spreadsheetImportService.js` line ~1439 creates payment rows with: ```sql INSERT INTO payments (bill_id, user_id, amount, paid_date, method, notes, month, year, ...) ``` No `balance_delta` column. No call to `computeBalanceDelta()`. No `current_balance` update on the parent bill. ## Fix 1. After inserting each imported payment, call the same `computeBalanceDelta()` logic used by all other payment paths. 2. Update the bill's `current_balance` using the delta. 3. Ensure delete/restore handles `balance_delta = 0` correctly (not just NULL checks). ## Acceptance Criteria - [ ] Imported payments compute and store `balance_delta` correctly - [ ] Bill `current_balance` is updated after import - [ ] Snowball page shows correct balance after import - [ ] Deleting an imported payment correctly reverses the balance delta - [ ] Restoring an imported payment correctly re-applies the balance delta - [ ] No regression in toggle-paid, quick-pay, bulk-pay, or manual payment balance tracking
null added the
backend
bug
priority:critical
labels 2026-05-16 21:43:00 -05:00
null closed this issue 2026-06-03 22:16:44 -05:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: null/BillTracker#49
No description provided.