diff --git a/CHANGELOG.md b/CHANGELOG.md index c10e74d..56e23b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.21] — 2026-11-02 + +### Overview and balances +- **A credit card's past balance now moves the right way when you've entered what you owe.** Settings asks for a card's balance as the amount owed, a positive number ("Balance owed today" in Settings → Accounts, "Current balance" in Settings → Credit cards). The card's rows point the other way: a charge is negative, a payment positive. To find the balance at an earlier date, FinLens took the override back as it does a bank balance, minus the transactions after that date. For a card that added a later charge to what was owed before it, and took a later payment off. + - **What went wrong:** `balanceAt()` and `periodEndBalance()` (`aggregation.js`) gave every balance override at an earlier date as the override minus the later transactions. With the samples and $617.33 entered (what the card's rows add up to), a range of Jul 1 – Aug 15, 2026 showed $900.74 owed. The rows give $333.92. Every number built from a card's past amount owed had it: the Overview's card and net worth on a past range, the net worth chart and its change since last month, the card's sparkline in Trends, and the AI summary on a past range. master has it too: its `periodEndBalance()` takes an override back the same way on a range that ended more than 7 days ago. + - **With v1.16.20:** that fix took ranges ending within the last 7 days back the same way, so for a card they agreed with the chart but moved away from the right number. With $700.25 entered, today on Oct 20 and a range ending Oct 19, v1.16.19 showed $700.25 owed, v1.16.20 $727.78; the right amount is $672.72. + - **Fix:** `overrideBalanceAt()` takes an override back the way it points, and `balanceAt()` and `periodEndBalance()` both use it. A bank balance: minus the later transactions, as before. A card's amount owed: plus them. A card balance typed as a negative number still counts as owed (every screen takes its size, `debtOf()`); it points the rows' way, so it's taken back as before. +- **Unchanged:** today's numbers. That's the net worth and every account's balance on All time and on every range reaching the card's last transaction, the Debt tracker (a linked debt reads today's balance), Transactions → Payments, Forecast and Settings → Credit cards. On those ranges the net worth chart's earlier points and the change since last month do move, because they use the card's past amount owed. With the samples and $617.33 entered, All time's "since Sep 30" goes from $2,010.75 to $2,339.71. Bank accounts, with or without a "current balance" saved before v1.16.0, are as before, and so is every account with no override. + +### AI Analysis +- **On a past range, the summary's card balance and Total Debt are the amount owed at the end of the period**, as the Overview now shows it. Only the Accounts and Total Cash lines change, and only with a card balance entered. The Debts section still gives today's balances, as its heading says. +- **The AI Eval's summary is unchanged.** Its sandbox sets no manual balances and uses All time, so the new code never runs there. The summary is byte-identical under every test clock (sha256 `df5557ea…`), and the published results still hold. + +--- + ## [1.16.20] — 2026-11-02 ### Overview and balances diff --git a/CLAUDE.md b/CLAUDE.md index e7210e8..03c3bdd 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,7 +59,7 @@ Until then, this section is the rule. FinLens is a **single-origin, zero-build, vanilla JavaScript personal finance dashboard** that runs entirely in the browser. There is no server, no npm, no bundler, no framework, and no TypeScript. The entry point is `index.html`; everything else is a plain `.js` file in the `js/` folder. -**Current version:** v1.16.20 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.21 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). **What it does:** Imports CSV exports from a bank (checking + savings) and credit cards, parses and normalizes them into a unified transaction model, and renders a multi-tab financial dashboard with budgeting, debt tracking, savings forecasting, investment planning, and Claude-powered AI analysis. @@ -568,7 +568,8 @@ detectRecurringDeposits() // Recurring income detection recurringKey(desc), depositKey(desc) // the grouping keys the two detectors use accountDateRange(accountId) // { min: Date, max: Date } — earliest and latest transaction dates for an account // v1.14.0 (the Finances screens) — new helpers; the ones above give the same output as before -balanceAt(accountId, date) // balance at the end of a day (manual balance minus later rows, or start + rows so far) +balanceAt(accountId, date) // balance at the end of a day (an override taken back past later rows, or start + rows so far) +overrideBalanceAt(accountId, date) // an override at the end of `date`: a bank's less the later rows, a card's amount owed plus them (v1.16.21, §18) dataSpan(txs) // { first, last, days, months } — months = days ÷ 30.44, as the AI summary states monthlyFlow(txs) // [{ key, date, income, expense, net, txs }] per month, sumIncome/sumExpense rules isCardPayment(t) // a payment toward a credit card (its "Payment" row, or the card leg of a paired transfer) @@ -1060,14 +1061,18 @@ Also update **Current version** in §1 of this file. Never close out a change wi |---|---|---| | `bank_checking` | Bank Checking | Computed from transactions + manually entered starting balance (the export has no running balance) | | `bank_savings` | Bank Savings | Computed from transactions + manually entered starting balance (the export has no running balance) | -| `credit_card` | Bank Credit Card(s) | The balance owed entered in Settings → Accounts or Settings → Credit cards; without one, the sum of the card's transactions | +| `credit_card` | Bank Credit Card(s) | The balance owed entered in Settings → Accounts or Settings → Credit cards, as a positive number; without one, the sum of the card's transactions (negative while you owe) | | `unknown` | Any other CSV | Computed from transactions + initial balance | **One balance rule** for `currentBalances()`, `periodEndBalance()` and `balanceAt()`, in every date range, All time included (v1.16.10): -- **A balance override** (`manualBalances[id]`: a card's amount owed, or a bank's current balance saved before v1.16.0) is today's balance. At an earlier date it's the override minus the later transactions, however recent the date. The starting balance doesn't count. An override records no date, so it's always taken as today's. -- **Otherwise:** the starting balance (`manualBalances[id+'_initial']`, read by `startingBalance()`) plus the transactions up to that date. +- **A balance override** (`manualBalances[id]`: a card's amount owed, or a bank's current balance saved before v1.16.0) is today's balance. At an earlier date it's taken back past the later transactions, however recent the date, the way the override points (`overrideBalanceAt()`, v1.16.21): + - **A bank balance** counts the way its rows do (a deposit is positive): the override **minus** the later transactions. + - **A card's amount owed** is entered as a positive number, but its rows are negative for a charge and positive for a payment: the override **plus** the later transactions. A later charge wasn't owed yet; a later payment was still owed. + - **A card override typed as a negative number** still counts as owed (every screen takes a card balance's size, `debtOf()`). It points the rows' way, so it's taken back as a bank's. + - The starting balance doesn't count. An override records no date, so it's always taken as today's. +- **Otherwise:** the starting balance (`manualBalances[id+'_initial']`, read by `startingBalance()`) plus the transactions up to that date. A card has no starting-balance field (Settings → Accounts asks a card for its balance owed), so this adds its rows in their own sign. -Up to v1.16.9, `currentBalances()` left the starting balance out, so All time and the AI summary ignored it while every other range used it. Up to v1.16.19, `periodEndBalance()` showed the override as it is for a range ending within 7 days of today, so a range ending yesterday showed today's balance and the Overview's net worth disagreed with its chart (v1.16.20). Keep the three helpers on this one rule. +Up to v1.16.9, `currentBalances()` left the starting balance out, so All time and the AI summary ignored it while every other range used it. Up to v1.16.19, `periodEndBalance()` showed the override as it is for a range ending within 7 days of today, so a range ending yesterday showed today's balance and the Overview's net worth disagreed with its chart (v1.16.20). Up to v1.16.20, a card's override was taken back as a bank's, so a card's past amount owed moved the wrong way: a charge after the date was added to it instead of taken off (v1.16.21). Keep the three helpers on this one rule. Multiple credit card files can be loaded simultaneously. Each gets a unique `accountId` derived from the filename: `card_` + sanitized filename, and a default name `Bank Credit Card ()`. @@ -1077,7 +1082,7 @@ Multiple credit card files can be loaded simultaneously. Each gets a unique `acc --- -*Last updated: v1.16.20 — 2026-11-02 (§18 a balance override at the end of every range is the override less the later transactions, no 7-day exception; v1.16.19: overlapping exports of one account count each shared row once: §4.5 one transaction per id; §8 `mergeImported()`, `importParsedCsv()`; §10 overlapping exports of one account; §19 the leftover-copy check keeps the import's ids; v1.16.18: a JSON import's transaction edits show at once: §9 `applyImportedEdits()`; §20 what takes effect without a reload; v1.16.17: a file read into another account takes its rows with it: §4.3 the account's `files`, `accountFiles()`; §4.5 the exception to an import never dropping rows; §8 `accountFiles()`, `earlierCopies()`, `moveEarlierCopies()`; §10 Read as changes the ids; §19 `DB.removeTransactions()`, `DB.patchAccount()`; §22 `_rekey()` is also used by imports; v1.16.16: the transaction and transfer drawers store only the fields you change: §4.1 TxOverride, §11 transfer keywords, §12 state mutations; v1.16.15: §1 desktop only; §3 `views-database.js` removed, the Changelog view reads CHANGELOG.md; §6, §18, §19 point to the current screens; v1.16.14: §9 the drawer is a modal dialog: inert page, Tab wraps, first field focused, focus returns after a re-render; v1.16.13: account order: §4.1 `accountOrder` keeps ids not loaded; §8 `orderedAccounts()`; §18 display order; v1.16.12: account names: §4.1 `accountLabels`; §4.3 an account's `name` is its default; §8 `defaultAccountName()`; §9 `acctName()`; §13 the summary lists accounts by `acctName()`; §18 names you type, and clearing them; v1.16.11: AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* +*Last updated: v1.16.21 — 2026-11-02 (§8 `overrideBalanceAt()`, `balanceAt()`; §18 a card's amount owed is taken back plus the later transactions, a bank balance minus them; the sign of a card's balance; v1.16.20: §18 a balance override at the end of every range is the override less the later transactions, no 7-day exception; v1.16.19: overlapping exports of one account count each shared row once: §4.5 one transaction per id; §8 `mergeImported()`, `importParsedCsv()`; §10 overlapping exports of one account; §19 the leftover-copy check keeps the import's ids; v1.16.18: a JSON import's transaction edits show at once: §9 `applyImportedEdits()`; §20 what takes effect without a reload; v1.16.17: a file read into another account takes its rows with it: §4.3 the account's `files`, `accountFiles()`; §4.5 the exception to an import never dropping rows; §8 `accountFiles()`, `earlierCopies()`, `moveEarlierCopies()`; §10 Read as changes the ids; §19 `DB.removeTransactions()`, `DB.patchAccount()`; §22 `_rekey()` is also used by imports; v1.16.16: the transaction and transfer drawers store only the fields you change: §4.1 TxOverride, §11 transfer keywords, §12 state mutations; v1.16.15: §1 desktop only; §3 `views-database.js` removed, the Changelog view reads CHANGELOG.md; §6, §18, §19 point to the current screens; v1.16.14: §9 the drawer is a modal dialog: inert page, Tab wraps, first field focused, focus returns after a re-render; v1.16.13: account order: §4.1 `accountOrder` keeps ids not loaded; §8 `orderedAccounts()`; §18 display order; v1.16.12: account names: §4.1 `accountLabels`; §4.3 an account's `name` is its default; §8 `defaultAccountName()`; §9 `acctName()`; §13 the summary lists accounts by `acctName()`; §18 names you type, and clearing them; v1.16.11: AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* --- diff --git a/README.md b/README.md index 8504077..a1fef32 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > A zero-install, browser-native finance dashboard. Drop in your bank CSVs, get instant clarity on your money. -**Version:** v1.16.20  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.21  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.20 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.21 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index 0b34ed0..6b32dac 100644 --- a/index.html +++ b/index.html @@ -1164,7 +1164,7 @@
- + diff --git a/js/aggregation.js b/js/aggregation.js index db5d893..8e5c16a 100644 --- a/js/aggregation.js +++ b/js/aggregation.js @@ -45,7 +45,8 @@ function byMonth(txs) { // One rule for an account's balance, in currentBalances(), periodEndBalance() and balanceAt(): // - a balance override (manualBalances[id]: a card's amount owed, or a bank balance saved // before v1.16.0) is today's balance, and the starting balance doesn't count; at an earlier -// date it's the override less the transactions after that date; +// date it's taken back past the transactions after that date, the way the override points +// (overrideBalanceAt(): a bank balance less them, a card's amount owed plus them); // - otherwise the starting balance plus the transactions so far. // The starting balance: what the account held before its first imported transaction // (Settings → Accounts, manualBalances[id+'_initial']). 0 when not set. @@ -79,14 +80,12 @@ function periodEndBalance(accountId) { const txsWithBal=State.transactions.filter(t=>t.account===accountId&&t.balance!=null&&t.date<=endDate).sort((a,b)=>b.date-a.date); if (txsWithBal.length) return txsWithBal[0].balance; - // Balance override (today's balance): less the transactions after the period end, for - // every period, as balanceAt() does. A period that reaches the last transaction gets it as - // is. Up to v1.16.19 a period ending within 7 days of today got it as is too, so a range - // ending yesterday showed today's balance and disagreed with the net worth chart. - if (State.manualBalances[accountId]!=null) { - const afterEnd=State.transactions.filter(t=>t.account===accountId&&t.date>endDate).reduce((s,t)=>s+t.amount,0); - return Number(State.manualBalances[accountId])-afterEnd; - } + // Balance override (today's balance): taken back past the transactions after the period + // end, for every period, as balanceAt() does (overrideBalanceAt()). A period that reaches + // the last transaction gets it as is. Up to v1.16.19 a period ending within 7 days of today + // got it as is too, so a range ending yesterday showed today's balance and disagreed with + // the net worth chart. + if (State.manualBalances[accountId]!=null) return overrideBalanceAt(accountId, endDate); // Fallback: initial balance + sum of all transactions up to period end const sum=State.transactions.filter(t=>t.account===accountId&&t.date<=endDate).reduce((s,t)=>s+t.amount,0); @@ -182,17 +181,37 @@ function accountDateRange(accountId) { } /* ---------- BALANCE AT A DATE (v1.14.0) ---------- */ -// An account's balance at the end of `date`. With a manual (current) balance: that balance -// minus everything after `date`. Otherwise: starting balance plus everything up to `date`. -// Used for the Overview net-worth chart and account sparklines. +// An account's balance at the end of `date`. With a balance override: that balance taken back +// past everything after `date` (overrideBalanceAt()). Otherwise: starting balance plus +// everything up to `date`. Used for the Overview net-worth chart, account sparklines and Trends. function balanceAt(accountId, date) { + if (State.manualBalances[accountId]!=null) return overrideBalanceAt(accountId, date); const txs=State.transactions.filter(t=>t.account===accountId); - if (State.manualBalances[accountId]!=null) { - return Number(State.manualBalances[accountId])-txs.filter(t=>t.date>date).reduce((s,t)=>s+t.amount,0); - } return startingBalance(accountId)+txs.filter(t=>t.date<=date).reduce((s,t)=>s+t.amount,0); } +// A balance override (today's balance) at the end of an earlier `date` (v1.16.21). The +// transactions after `date` are taken back the way the override points: +// - A bank balance counts the way its rows do (a deposit is positive), so they come off: +// balance then = override − the rows after `date`. +// - A card's override is the amount owed, entered as a positive number (Settings → Accounts +// "Balance owed today", Settings → Credit cards "Current balance"). Its rows point the other +// way (a charge is negative, a payment positive), so they go back on: +// owed then = override + the rows after `date`. A later charge wasn't owed yet; a later +// payment was still owed. +// - A card override typed as a negative number counts as owed too: every screen takes a +// card balance's size (debtOf()). It points the rows' way, so it's taken back as a bank's. +// With no rows after `date` (All time, a range reaching the last transaction) it's the override +// as it is. Up to v1.16.20 every override was taken back as a bank's, so a card's past balance +// moved the wrong way: with the samples and $617.33 owed today (what their rows add up to), +// Aug 15 showed $900.74 owed, not $333.92. +function overrideBalanceAt(accountId, date) { + const o=Number(State.manualBalances[accountId]); + const after=State.transactions.filter(t=>t.account===accountId&&t.date>date).reduce((s,t)=>s+t.amount,0); + const a=State.accounts[accountId]; + return a&&a.kind==='credit_card'&&o>=0?o+after:o-after; +} + /* ---------- SPANS AND MONTHS (v1.14.0) ---------- */ // First and last transaction dates, the days between them (inclusive) and that in months // (days ÷ 30.44, the same count the AI summary states). null when there are none. diff --git a/js/views-settings.js b/js/views-settings.js index 8f5b201..0262936 100644 --- a/js/views-settings.js +++ b/js/views-settings.js @@ -60,7 +60,7 @@ function _renderGeneralSettings(root) { /* ---- About (the Theme row is gone: light only for now) ---- */ appendHtml(root,`

About

-
VersionFinLens v1.16.20
+
VersionFinLens v1.16.21
`); /* ---- Anthropic API key ---- */