fix: one sign convention for every report (#392) #536

Merged
maximus merged 10 commits from issue-392-report-sign-convention into main 2026-11-08 18:24:25 +00:00

10 commits

Author SHA1 Message Date
le king fu
f62dee5cef docs: changelog the sign of a change percentage after a negative period (#392)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m13s
Review 32720 of PR #536: 74b3d0a also fixes a defect users could see
before the PR. « Solde net », the savings rate and the transfer lines of
Compare could already have a negative previous period, and their change
percentage then took the opposite sign of the change: a net balance going
from -500 $ to +200 $ read -140 %. Note it under Fixed in both changelogs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:49:26 -05:00
le king fu
3334fcab55 test: pin the remaining wiring of the report figures (#392)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m16s
The review of the PR left eight mutations green, all on correct code.
Pin each of them:

- Trends' global flow shows the net result in « Net », month and total,
  and KpiCard renders the note it is given (render tests);
- the dashboard and Cartes pages hand « Solde net » the note of the
  snapshot, and no other card a note;
- in year-to-date mode, Cartes reads the note on January to the
  reference month while seasonality stays on the month, and actual vs
  budget keeps the uncategorized line when only the year to date holds
  it;
- the top N of the trend by category ranks by the size of the balance,
  and the zoom lists its children largest first.

The route of "excludes income from top movers" matched no query since
the month is read on t.date: point it at the flows query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 11:17:12 -05:00
le king fu
fc4dfd6117 test: refuse a nested transaction in the SQLite harness (#392)
The real lock of db.ts is not reentrant: a withTransaction called from
inside another one waits forever behind it. The harness refused getDb()
inside a transaction but ran a nested withTransaction, and its finally
then cleared the flag, so a getDb() later in the outer callback passed
too. Refuse the nested call as the lock would block it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 11:17:12 -05:00
le king fu
74b3d0ab08 fix: take a change percentage on the size of the previous amount (#392)
Review 32494 of PR #536: an expense can now be negative (refunds above
purchases, ADR 0026), and six percentages divided the change by the signed
previous amount, so a category going from -50 to 80 read +130 $ and -260 %
while its section total, through pct of compareResults.ts, read +280 %. The
compare lines and group subtotals (month and cumulative each), the
Highlights movers and the KPI cards (extractDelta: expenses, « Solde net »,
savings rate) now divide by Math.abs(previous), as pct does.

The test is the reviewer's probe on the harness: a refund alone in Butcher in
September, 80 spent in October. Red on c404f10 (3 tests); each of the six
expressions mutated back alone turns it red.

Fixes #392

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 11:09:20 -05:00
le king fu
c404f10974 test: pin the signed stacking and the uncategorized label of the trend chart (#392)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m7s
Recharts draws nothing under a static render, so the chart runs under the
shared hook harness and the test reads the props it hands to Recharts:
stackOffset="sign" on the bar and the area charts (D7), and the
uncategorized series named from i18n with its data key unchanged, in the
legend and in a hidden-category chip. Removing either stackOffset, or the
label, now turns the suite red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 22:47:59 -05:00
le king fu
8d3fc2f7f1 docs: the sign convention of the reports, in an ADR and the guides (#392)
- ADR 0026 records the convention (D1 to D8 of #392): signed balance per
  category, the uncategorized line, the two results, « Solde net » and the
  savings rate, where the rule lives, negative amounts in the charts, and the
  Transactions bar; ADR 0024 points its monthly summary to it.
- The user guide gains « Comment les montants sont calculés » and rewrites
  the KPI formulas, movers, seasonality, budget adherence, global flow,
  compare tables and donut lines; the in-app guide follows (docs.dashboard,
  docs.reports, docs.transactions).
- architecture.md: the shared node:sqlite harness, incomeStatement.ts, the
  services rows and ADR 0026; REVIEW.md: the tests that read
  consolidated_schema.sql.
- CHANGELOG EN + FR, Changed and Fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 22:32:58 -05:00
le king fu
66c53e69c0 feat(reports): show signed amounts, the net note and money in/out (#392)
- « Solde net » on the Dashboard and Cartes carries a note giving the
  uncategorized and transfer parts of the net result when they are not zero
  (D5): KpiCard takes an optional note, written by the pure netNote.
- Trends' global-flow table gains « Non classé » and « Transferts » columns,
  and its « Net » is the net result of the month.
- A negative amount stays signed in the charts (D7): the stacked bars and
  areas of CategoryOverTimeChart stack it below zero (stackOffset="sign"),
  and its uncategorized series takes its label from i18n; the zoom's donut
  draws the positive parts only and says how many negative ones it leaves out
  (donutParts), the no-data state included.
- The Transactions summary bar reads « Entrées / Sorties / Solde » (D8): its
  sums by sign are a view of the list, not an income statement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 22:32:46 -05:00
le king fu
d742415e09 fix: count every report by the signed balance of its categories (#392)
Six aggregation rules gave one month six different incomes and expenses, and
the real-vs-real compare counted every split amount twice. Every report now
sums the signed amounts of each category with its section (ADR 0026, D1):
income is the balance of the income categories, expenses the opposite of the
balance of the expense categories (a refund lowers them, refunds above
purchases make them negative), transfers keep their sign, and the rows
without an existing category form one uncategorized line, neither income nor
expense, counted in the result (D4).

- getMonthlyTrends returns the income statement of each month; Cartes and
  the Dashboard read it in place of fetchMonthlyFlows, whose net is the net
  result (D5) and whose savings rate is (income - expenses) / income (D6),
  with the uncategorized and transfer parts in netBreakdown.
- compareDeltaSql, getCategoryOverTime, the Highlights movers, the zoom, the
  seasonality and getExpensesByCategory sum signed amounts; ABS only sorts.
- The budget adherence compares signed spending to the budget, so a refund
  is no overrun; Actual vs budget gets the uncategorized line.
- The three reducers and the three tables carry the uncategorized line, between
  the expenses and the result before transfers.
- getDashboardSummary, without a caller, is removed.

test: reproduces #392 — src/__integration__/report-totals.test.ts reads every
report through its real service, on the reproduction and the edge cases of
the issue, on the shared node:sqlite harness; it failed 17 of its 20 first
tests on the previous code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 22:32:30 -05:00
le king fu
96dfd4f1f8 feat: one sign convention for the reports, in a pure module (#392)
src/utils/incomeStatement.ts holds the rule every report will follow
(ADR 0026): the SQL section of a row (SECTION_SQL on CATEGORY_JOIN_SQL, a row
without an existing category being uncategorized), and the pure functions
that turn signed category balances into what the screens show: orient (an
expense shows its spending, the opposite of its balance), incomeStatement and
statementOf (income, expenses, uncategorized, transfers, result before
transfers, net), addStatements, savingsRate ((income - expenses) / income)
and toCents (no float remainder, no negative zero).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 22:32:11 -05:00
le king fu
79abdecc9d test: share one node:sqlite harness for the integration tests (#392)
src/test/sqliteHarness.ts opens the schema of a new profile with its seed,
foreign keys on, and stands in for ../services/db: $N bound by name,
rowsAffected and lastInsertId, withTransaction on the same handle, getDb()
refused inside a transaction. split-offset-manual-flag.test.ts and
restore.test.ts drop their two copies of that adapter for it, and
sqliteHarness.test.ts proves its rules once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 22:31:54 -05:00