fix: use correct payment_source 'file_import' for imported spreadsheet payments

This commit is contained in:
null 2026-06-03 22:23:07 -05:00
parent 4188a2059d
commit 6da43c5e92
2 changed files with 4 additions and 2 deletions

View File

@ -30,6 +30,8 @@
### 🐛 Fixed
- **Imported payments use correct `payment_source = 'file_import'`** — When issue #49 was fixed (imported payments not updating debt balance), `payment_source` was set to `'import'` — a value not in the canonical `VALID_PAYMENT_SOURCES` set (`manual`, `file_import`, `provider_sync`). Corrected to `'file_import'` in both INSERT paths in `spreadsheetImportService.js`. Payment history now shows the correct source for imported payments and the value round-trips correctly through the import/export and user DB import paths.
- **Mortgage and housing categories now auto-detected as debt**`DEBT_LIKE_CLAUSES` in `routes/snowball.js` matched `%credit%`, `%loan%`, and `%debt%` category names but not `%mortgage%` or `%housing%`. A real user who created a bill under a "Mortgage" or "Housing" category would never see it on the Snowball page unless they manually toggled `snowball_include`. Demo data hid the bug because the seed bill has `snowball_include` pre-set. The frontend's `mortgageIncluded` warning in `SnowballPage.jsx` already checked for mortgage/housing in category and bill name — it just never fired because those bills were filtered out before reaching the page. Added both patterns to `DEBT_LIKE_CLAUSES`; the warning now works as intended, correctly flagging when a mortgage is present so users see the Ramsey Baby Step 2 note about excluding the house.
- **Imported payments now update debt balance** — Every payment creation path except spreadsheet import correctly computed `balance_delta` and updated `bills.current_balance`. Imported payments were permanently orphaned from debt tracking: the snowball page balance stayed wrong after an Excel import, delete/restore was broken (the restore path checks `balance_delta IS NULL` and silently skips the reversal), and any debt-related reporting was incorrect. Three paths were fixed. In `spreadsheetImportService.js` `createPaymentFromImport()`: added `computeBalanceDelta` import, fetches the bill fresh on every call (critical for sequential month imports so each payment sees the post-previous-payment balance), includes `balance_delta` in the INSERT, updates `bills.current_balance`, and sets `payment_source = 'import'` (was null). The `create_payment` action path in the same file had the identical gap and received the same treatment. `routes/matches.js` manual transaction confirm also had no `balance_delta` or `current_balance` update — fixed with the same `computeBalanceDelta` call inside the existing transaction block.

View File

@ -1446,7 +1446,7 @@ function createPaymentFromImport(db, billId, amount, paidDate, notes, allowOverw
db.prepare(`
INSERT INTO payments (bill_id, amount, paid_date, method, notes, balance_delta, payment_source)
VALUES (?, ?, ?, ?, ?, ?, 'import')
VALUES (?, ?, ?, ?, ?, ?, 'file_import')
`).run(billId, amount, paidDate, null, notes, balCalc?.balance_delta ?? null);
if (balCalc) {
@ -1687,7 +1687,7 @@ function applyOneDecision(db, userId, decision, previewRow, sessionData, allowOv
db.prepare(`
INSERT INTO payments (bill_id, amount, paid_date, method, notes, balance_delta, payment_source)
VALUES (?, ?, ?, ?, ?, ?, 'import')
VALUES (?, ?, ?, ?, ?, ?, 'file_import')
`).run(billId, payAmount, payDate, decision.payment_method ?? null, decision.payment_notes ?? null, balCalcCp?.balance_delta ?? null);
if (balCalcCp) {