From 66c53e69c0f8dd824e024c6e03fe7cc62a4b67f5 Mon Sep 17 00:00:00 2001 From: le king fu Date: Sat, 7 Nov 2026 22:32:46 -0500 Subject: [PATCH] feat(reports): show signed amounts, the net note and money in/out (#392) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - « 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 --- src/components/reports/CategoryDonutChart.tsx | 97 +++++++++++-------- .../reports/CategoryOverTimeChart.tsx | 20 ++-- src/components/reports/MonthlyTrendsTable.tsx | 28 ++++-- src/components/reports/cards/KpiCard.tsx | 4 + src/components/reports/cards/netNote.test.ts | 30 ++++++ src/components/reports/cards/netNote.ts | 33 +++++++ src/components/reports/donutParts.test.tsx | 47 +++++++++ src/components/reports/donutParts.ts | 18 ++++ .../TransactionSummaryBar.render.test.tsx | 30 ++++++ .../transactions/TransactionSummaryBar.tsx | 9 +- src/i18n/locales/en.json | 11 ++- src/i18n/locales/fr.json | 11 ++- src/pages/DashboardPage.tsx | 2 + src/pages/ReportsCartesPage.tsx | 4 +- 14 files changed, 279 insertions(+), 65 deletions(-) create mode 100644 src/components/reports/cards/netNote.test.ts create mode 100644 src/components/reports/cards/netNote.ts create mode 100644 src/components/reports/donutParts.test.tsx create mode 100644 src/components/reports/donutParts.ts create mode 100644 src/components/transactions/TransactionSummaryBar.render.test.tsx diff --git a/src/components/reports/CategoryDonutChart.tsx b/src/components/reports/CategoryDonutChart.tsx index 6b194e3..c75231e 100644 --- a/src/components/reports/CategoryDonutChart.tsx +++ b/src/components/reports/CategoryDonutChart.tsx @@ -2,6 +2,7 @@ import { useTranslation } from "react-i18next"; import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip } from "recharts"; import type { CategoryZoomChild } from "../../shared/types"; import { ChartPatternDefs, getPatternFill } from "../../utils/chartPatterns"; +import { donutParts } from "./donutParts"; export interface CategoryDonutChartProps { byChild: CategoryZoomChild[]; @@ -15,58 +16,70 @@ export default function CategoryDonutChart({ centerValue, }: CategoryDonutChartProps) { const { t } = useTranslation(); + // Only the positive parts can be drawn; the negative ones are named by count (D7, #392). + const { parts, negativeCount } = donutParts(byChild); + const omitted = + negativeCount > 0 ? ( +

+ {t("reports.category.donutOmitted", { count: negativeCount })} +

+ ) : null; - if (byChild.length === 0) { + if (parts.length === 0) { return (
{t("reports.empty.noData")} + {omitted}
); } return ( -
- - - ({ color: c.categoryColor, index }))} - /> - - {byChild.map((entry, index) => ( - - ))} - - - typeof value === "number" - ? new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD" }).format(value) - : String(value) - } - contentStyle={{ - backgroundColor: "var(--card)", - border: "1px solid var(--border)", - borderRadius: "0.5rem", - }} - /> - - -
- {centerLabel} - {centerValue} +
+
+ + + ({ color: c.categoryColor, index }))} + /> + + {parts.map((entry, index) => ( + + ))} + + + typeof value === "number" + ? new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD" }).format(value) + : String(value) + } + contentStyle={{ + backgroundColor: "var(--card)", + border: "1px solid var(--border)", + borderRadius: "0.5rem", + }} + /> + + +
+ {centerLabel} + {centerValue} +
+ {omitted}
); } diff --git a/src/components/reports/CategoryOverTimeChart.tsx b/src/components/reports/CategoryOverTimeChart.tsx index 742706d..6c43513 100644 --- a/src/components/reports/CategoryOverTimeChart.tsx +++ b/src/components/reports/CategoryOverTimeChart.tsx @@ -63,6 +63,9 @@ export default function CategoryOverTimeChart({ // (Issue #264 sidecar) so the stacked series never explode to 80+ layers. The // full, uncapped hierarchy lives in `data.tree` and drives the table instead. const visibleCategories = data.categories.filter((name) => !hiddenCategories.has(name)); + // The series of the rows without a category (its id is null) is keyed by the + // SQL's 'Uncategorized': show the translated label instead (#392). + const labelOf = (name: string) => (data.categoryIds[name] === null ? t("reports.uncategorized") : name); const categoryEntries = visibleCategories.map((name, index) => ({ name, color: data.colors[name], @@ -108,7 +111,7 @@ export default function CategoryOverTimeChart({ /> { - if (hoveredCategory && name !== hoveredCategory) return [null, null]; + if (hoveredCategory && name !== labelOf(hoveredCategory)) return [null, null]; return [cadFormatter(Number(value) || 0), String(name)]; }} labelFormatter={(label) => formatMonth(String(label))} @@ -147,7 +150,7 @@ export default function CategoryOverTimeChart({ className="inline-flex items-center gap-1 px-2 py-0.5 text-xs rounded-full bg-[var(--muted)] text-[var(--muted-foreground)] hover:bg-[var(--border)] transition-colors" > - {name} + {labelOf(name)} ))}