@@ -45,6 +47,12 @@ export default function MonthlyTrendsTable({ data }: MonthlyTrendsTableProps) {
{t("dashboard.expenses")}
|
+
+ {t("reports.uncategorized")}
+ |
+
+ {t("reports.compare.sections.transfers")}
+ |
{t("dashboard.net")}
|
@@ -56,18 +64,18 @@ export default function MonthlyTrendsTable({ data }: MonthlyTrendsTableProps) {
{formatMonth(row.month)} |
{cadFormatter(row.income)} |
{cadFormatter(row.expenses)} |
-
= 0 ? "text-[var(--positive)]" : "text-[var(--negative)]"}`}>
- {cadFormatter(row.income - row.expenses)}
- |
+
{cadFormatter(row.uncategorized)} |
+
{cadFormatter(row.transfers)} |
+
{cadFormatter(row.net)} |
))}
| {t("common.total")} |
{cadFormatter(totals.income)} |
{cadFormatter(totals.expenses)} |
- = 0 ? "text-[var(--positive)]" : "text-[var(--negative)]"}`}>
- {cadFormatter(totals.income - totals.expenses)}
- |
+ {cadFormatter(totals.uncategorized)} |
+ {cadFormatter(totals.transfers)} |
+ {cadFormatter(totals.net)} |
diff --git a/src/components/reports/cards/KpiCard.tsx b/src/components/reports/cards/KpiCard.tsx
index 7f4a19f..998a199 100644
--- a/src/components/reports/cards/KpiCard.tsx
+++ b/src/components/reports/cards/KpiCard.tsx
@@ -12,6 +12,8 @@ export interface KpiCardProps {
deltaIsBadWhenUp?: boolean;
/** Optional help text shown on hover of a (?) icon next to the title. */
tooltip?: string;
+ /** Optional line under the value, e.g. what « Solde net » holds beyond income − expenses (#392). */
+ note?: string;
}
function formatCurrency(amount: number, language: string): string {
@@ -106,6 +108,7 @@ export default function KpiCard({
format,
deltaIsBadWhenUp = false,
tooltip,
+ note,
}: KpiCardProps) {
const { t, i18n } = useTranslation();
const language = i18n.language;
@@ -130,6 +133,7 @@ export default function KpiCard({
{kpi.current === null ? "—" : formatValue(kpi.current, format, language)}
+ {note &&
{note}
}
s.replace(/[ ]/g, " ");
+
+describe("netNote", () => {
+ it("names the uncategorized line and the transfers when both are non-zero", () => {
+ expect(nbsp(netNote(markedT, "fr", { uncategorized: 40, transfers: -300 })!)).toBe(
+ "t(reports.cartes.netNote.both[uncategorized=40 $,transfers=-300 $])",
+ );
+ });
+
+ it("names the one part that is non-zero", () => {
+ expect(nbsp(netNote(markedT, "en", { uncategorized: 40, transfers: 0 })!)).toBe(
+ "t(reports.cartes.netNote.uncategorized[amount=$40])",
+ );
+ expect(nbsp(netNote(markedT, "en", { uncategorized: 0, transfers: -300 })!)).toBe(
+ "t(reports.cartes.netNote.transfers[amount=-$300])",
+ );
+ });
+
+ it("is absent when both parts are zero, or round to zero as the card shows them", () => {
+ expect(netNote(markedT, "fr", { uncategorized: 0, transfers: 0 })).toBeUndefined();
+ expect(netNote(markedT, "fr", { uncategorized: 0.4, transfers: -0.2 })).toBeUndefined();
+ });
+});
diff --git a/src/components/reports/cards/netNote.ts b/src/components/reports/cards/netNote.ts
new file mode 100644
index 0000000..e629b6b
--- /dev/null
+++ b/src/components/reports/cards/netNote.ts
@@ -0,0 +1,33 @@
+import type { CartesSnapshot } from "../../../shared/types";
+
+/**
+ * The note under « Solde net » (D5, #392). The card shows the net result,
+ * every amount of the period; beyond income − expenses, it holds the
+ * uncategorized line and the transfers. The note names each part that shows
+ * as a whole amount other than zero, as the card rounds them, and is absent
+ * when neither does.
+ */
+export function netNote(
+ t: (key: string, options?: Record) => string,
+ language: string,
+ breakdown: CartesSnapshot["netBreakdown"],
+): string | undefined {
+ const format = (amount: number) =>
+ new Intl.NumberFormat(language === "fr" ? "fr-CA" : "en-CA", {
+ style: "currency",
+ currency: "CAD",
+ maximumFractionDigits: 0,
+ }).format(amount);
+ const shows = (amount: number) => Math.round(amount) !== 0;
+ const { uncategorized, transfers } = breakdown;
+
+ if (shows(uncategorized) && shows(transfers)) {
+ return t("reports.cartes.netNote.both", {
+ uncategorized: format(uncategorized),
+ transfers: format(transfers),
+ });
+ }
+ if (shows(uncategorized)) return t("reports.cartes.netNote.uncategorized", { amount: format(uncategorized) });
+ if (shows(transfers)) return t("reports.cartes.netNote.transfers", { amount: format(transfers) });
+ return undefined;
+}
diff --git a/src/components/reports/donutParts.test.tsx b/src/components/reports/donutParts.test.tsx
new file mode 100644
index 0000000..592067c
--- /dev/null
+++ b/src/components/reports/donutParts.test.tsx
@@ -0,0 +1,47 @@
+// The zoom's donut and its negative parts (D7, #392). No jsdom: react-dom/server
+// renders the markup; Recharts draws nothing without a size, the mention line
+// is what is read here.
+import { describe, it, expect, vi } from "vitest";
+import { renderToStaticMarkup } from "react-dom/server";
+
+vi.mock("react-i18next", async () => (await import("../../test/i18nMock")).i18nMock());
+
+import CategoryDonutChart from "./CategoryDonutChart";
+import { donutParts } from "./donutParts";
+import type { CategoryZoomChild } from "../../shared/types";
+
+const child = (categoryId: number, total: number): CategoryZoomChild => ({
+ categoryId,
+ categoryName: `C${categoryId}`,
+ categoryColor: "#000",
+ total,
+});
+
+describe("donutParts", () => {
+ it("keeps the positive parts and counts the negative ones; a zero part is neither", () => {
+ const { parts, negativeCount } = donutParts([child(1, 80), child(2, 0), child(3, -50), child(4, 20)]);
+ expect(parts.map((c) => c.categoryId)).toEqual([1, 4]);
+ expect(negativeCount).toBe(1);
+ });
+});
+
+describe("CategoryDonutChart", () => {
+ const render = (byChild: CategoryZoomChild[]) =>
+ renderToStaticMarkup();
+
+ it("says how many negative parts it leaves out", () => {
+ const html = render([child(1, 80), child(3, -50)]);
+ expect(html).toContain("t(reports.category.donutOmitted[count=1])");
+ expect(html).not.toContain("t(reports.empty.noData)");
+ });
+
+ it("shows no ring when every part is negative or zero, and still says why", () => {
+ const html = render([child(2, 0), child(3, -50), child(5, -10)]);
+ expect(html).toContain("t(reports.empty.noData)");
+ expect(html).toContain("t(reports.category.donutOmitted[count=2])");
+ });
+
+ it("adds no line when no part is negative", () => {
+ expect(render([child(1, 80), child(2, 0)])).not.toContain("donutOmitted");
+ });
+});
diff --git a/src/components/reports/donutParts.ts b/src/components/reports/donutParts.ts
new file mode 100644
index 0000000..291419c
--- /dev/null
+++ b/src/components/reports/donutParts.ts
@@ -0,0 +1,18 @@
+import type { CategoryZoomChild } from "../../shared/types";
+
+/**
+ * The parts the zoom's donut can draw (D7, #392): the subcategories that show
+ * a positive amount. A pie cannot draw a negative part — a subcategory whose
+ * refunds exceed its purchases — so the donut leaves the negative ones out and
+ * says how many; a zero part never had a visible slice. The figures stay
+ * signed in the total at the centre and in the table.
+ */
+export function donutParts(byChild: CategoryZoomChild[]): {
+ parts: CategoryZoomChild[];
+ negativeCount: number;
+} {
+ return {
+ parts: byChild.filter((c) => c.total > 0),
+ negativeCount: byChild.filter((c) => c.total < 0).length,
+ };
+}
diff --git a/src/components/transactions/TransactionSummaryBar.render.test.tsx b/src/components/transactions/TransactionSummaryBar.render.test.tsx
new file mode 100644
index 0000000..ec28554
--- /dev/null
+++ b/src/components/transactions/TransactionSummaryBar.render.test.tsx
@@ -0,0 +1,30 @@
+// The summary bar of the Transactions page (#392, D8): a view of the listed
+// transactions, summed by sign, under « Entrées / Sorties / Solde ».
+import { describe, it, expect, vi } from "vitest";
+import { renderToStaticMarkup } from "react-dom/server";
+
+vi.mock("react-i18next", async () => (await import("../../test/i18nMock")).i18nMock());
+
+import TransactionSummaryBar from "./TransactionSummaryBar";
+
+describe("TransactionSummaryBar", () => {
+ const html = renderToStaticMarkup(
+ ,
+ );
+
+ it("labels its sums money in and money out, not income and expenses", () => {
+ expect(html).toContain("t(transactions.summary.moneyIn)");
+ expect(html).toContain("t(transactions.summary.moneyOut)");
+ expect(html).toContain("t(transactions.summary.balance)");
+ expect(html).not.toContain("t(transactions.summary.income)");
+ expect(html).not.toContain("t(transactions.summary.expenses)");
+ });
+
+ it("keeps its sums by sign: what came in, what went out, and the balance", () => {
+ const inIndex = html.indexOf("t(transactions.summary.moneyIn)");
+ const outIndex = html.indexOf("t(transactions.summary.moneyOut)");
+ expect(html.slice(inIndex, outIndex)).toMatch(/1.520[.,]00/);
+ expect(html.slice(outIndex)).toMatch(/600[.,]00/);
+ expect(html.slice(html.indexOf("t(transactions.summary.balance)"))).toMatch(/920[.,]00/);
+ });
+});
diff --git a/src/components/transactions/TransactionSummaryBar.tsx b/src/components/transactions/TransactionSummaryBar.tsx
index cf20dec..33073ed 100644
--- a/src/components/transactions/TransactionSummaryBar.tsx
+++ b/src/components/transactions/TransactionSummaryBar.tsx
@@ -8,6 +8,11 @@ interface TransactionSummaryBarProps {
expenseTotal: number;
}
+/**
+ * The totals of the listed transactions (#392, D8): what came in and what went
+ * out, by sign, split lines left out like the list, and the balance. A view of
+ * the list, not an income statement: the reports count by category.
+ */
export default function TransactionSummaryBar({
totalCount,
totalAmount,
@@ -25,7 +30,7 @@ export default function TransactionSummaryBar({
},
{
icon: TrendingUp,
- label: t("transactions.summary.income"),
+ label: t("transactions.summary.moneyIn"),
value: incomeTotal.toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
@@ -34,7 +39,7 @@ export default function TransactionSummaryBar({
},
{
icon: TrendingDown,
- label: t("transactions.summary.expenses"),
+ label: t("transactions.summary.moneyOut"),
value: Math.abs(expenseTotal).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json
index 1a4d6a0..a33885a 100644
--- a/src/i18n/locales/en.json
+++ b/src/i18n/locales/en.json
@@ -367,8 +367,8 @@
},
"summary": {
"count": "Transactions",
- "income": "Income",
- "expenses": "Expenses",
+ "moneyIn": "Money in",
+ "moneyOut": "Money out",
"balance": "Balance"
},
"table": {
@@ -639,6 +639,11 @@
"income": "Income",
"expenses": "Expenses",
"net": "Net balance",
+ "netNote": {
+ "both": "Includes {{uncategorized}} uncategorized and {{transfers}} of transfers",
+ "uncategorized": "Includes {{amount}} uncategorized",
+ "transfers": "Includes {{amount}} of transfers"
+ },
"savingsRate": "Savings rate",
"savingsRateTooltip": {
"month": "Formula: (income − expenses) ÷ income × 100, computed on the reference month.",
@@ -669,6 +674,8 @@
"includeSubcategories": "Include subcategories",
"directOnly": "Direct only",
"breakdown": "Total",
+ "donutOmitted_one": "{{count}} subcategory with a negative amount is not drawn",
+ "donutOmitted_other": "{{count}} subcategories with a negative amount are not drawn",
"evolution": "Evolution",
"transactions": "Transactions"
},
diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json
index f055788..c1c8f0d 100644
--- a/src/i18n/locales/fr.json
+++ b/src/i18n/locales/fr.json
@@ -367,8 +367,8 @@
},
"summary": {
"count": "Transactions",
- "income": "Revenus",
- "expenses": "Dépenses",
+ "moneyIn": "Entrées",
+ "moneyOut": "Sorties",
"balance": "Solde"
},
"table": {
@@ -639,6 +639,11 @@
"income": "Revenus",
"expenses": "Dépenses",
"net": "Solde net",
+ "netNote": {
+ "both": "Dont {{uncategorized}} non classés et {{transfers}} de transferts",
+ "uncategorized": "Dont {{amount}} non classés",
+ "transfers": "Dont {{amount}} de transferts"
+ },
"savingsRate": "Taux d'épargne",
"savingsRateTooltip": {
"month": "Formule : (revenus − dépenses) ÷ revenus × 100, calculée sur le mois de référence.",
@@ -669,6 +674,8 @@
"includeSubcategories": "Inclure les sous-catégories",
"directOnly": "Directe seulement",
"breakdown": "Total",
+ "donutOmitted_one": "{{count}} sous-catégorie au montant négatif n'apparaît pas dans le graphique",
+ "donutOmitted_other": "{{count}} sous-catégories au montant négatif n'apparaissent pas dans le graphique",
"evolution": "Évolution",
"transactions": "Transactions"
},
diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx
index e3d434f..4bbeab5 100644
--- a/src/pages/DashboardPage.tsx
+++ b/src/pages/DashboardPage.tsx
@@ -32,6 +32,7 @@ import DashboardEmptyState from "../components/dashboard/DashboardEmptyState";
import NetWorthTile from "../components/dashboard/NetWorthTile";
import FilterPanel from "../components/reports/FilterPanel";
import KpiCard from "../components/reports/cards/KpiCard";
+import { netNote } from "../components/reports/cards/netNote";
import IncomeExpenseOverlayChart from "../components/reports/cards/IncomeExpenseOverlayChart";
import TopMoversList from "../components/reports/cards/TopMoversList";
import BudgetAdherenceCard from "../components/reports/cards/BudgetAdherenceCard";
@@ -179,6 +180,7 @@ export default function DashboardPage() {
kpi={cartesSnapshot.kpis.net}
format="currency"
deltaIsBadWhenUp={false}
+ note={netNote(t, i18n.language, cartesSnapshot.netBreakdown)}
/>
diff --git a/src/pages/ReportsCartesPage.tsx b/src/pages/ReportsCartesPage.tsx
index fab9a1f..aeb5502 100644
--- a/src/pages/ReportsCartesPage.tsx
+++ b/src/pages/ReportsCartesPage.tsx
@@ -7,6 +7,7 @@ import { ArrowLeft } from "lucide-react";
import CompareReferenceMonthPicker from "../components/reports/CompareReferenceMonthPicker";
import CartesPeriodModeToggle from "../components/reports/cards/CartesPeriodModeToggle";
import KpiCard from "../components/reports/cards/KpiCard";
+import { netNote } from "../components/reports/cards/netNote";
import IncomeExpenseOverlayChart from "../components/reports/cards/IncomeExpenseOverlayChart";
import TopMoversList from "../components/reports/cards/TopMoversList";
import BudgetAdherenceCard from "../components/reports/cards/BudgetAdherenceCard";
@@ -14,7 +15,7 @@ import SeasonalityCard from "../components/reports/cards/SeasonalityCard";
import { useCartes } from "../hooks/useCartes";
export default function ReportsCartesPage() {
- const { t } = useTranslation();
+ const { t, i18n } = useTranslation();
const { year, month, mode, snapshot, isLoading, error, setReferencePeriod, setMode } =
useCartes();
@@ -84,6 +85,7 @@ export default function ReportsCartesPage() {
kpi={snapshot.kpis.net}
format="currency"
deltaIsBadWhenUp={false}
+ note={netNote(t, i18n.language, snapshot.netBreakdown)}
/>