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>
This commit is contained in:
parent
d742415e09
commit
66c53e69c0
14 changed files with 279 additions and 65 deletions
|
|
@ -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 ? (
|
||||
<p className="text-xs text-[var(--muted-foreground)] text-center mt-2 not-italic">
|
||||
{t("reports.category.donutOmitted", { count: negativeCount })}
|
||||
</p>
|
||||
) : null;
|
||||
|
||||
if (byChild.length === 0) {
|
||||
if (parts.length === 0) {
|
||||
return (
|
||||
<div className="bg-[var(--card)] border border-[var(--border)] rounded-xl p-6 text-center text-[var(--muted-foreground)] italic">
|
||||
{t("reports.empty.noData")}
|
||||
{omitted}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-[var(--card)] border border-[var(--border)] rounded-xl p-4 relative">
|
||||
<ResponsiveContainer width="100%" height={240}>
|
||||
<PieChart>
|
||||
<ChartPatternDefs
|
||||
prefix="cat-donut"
|
||||
categories={byChild.map((c, index) => ({ color: c.categoryColor, index }))}
|
||||
/>
|
||||
<Pie
|
||||
data={byChild}
|
||||
dataKey="total"
|
||||
nameKey="categoryName"
|
||||
cx="50%"
|
||||
cy="50%"
|
||||
innerRadius={55}
|
||||
outerRadius={95}
|
||||
paddingAngle={2}
|
||||
>
|
||||
{byChild.map((entry, index) => (
|
||||
<Cell
|
||||
key={entry.categoryId}
|
||||
fill={getPatternFill("cat-donut", index, entry.categoryColor)}
|
||||
/>
|
||||
))}
|
||||
</Pie>
|
||||
<Tooltip
|
||||
formatter={(value) =>
|
||||
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",
|
||||
}}
|
||||
/>
|
||||
</PieChart>
|
||||
</ResponsiveContainer>
|
||||
<div className="absolute inset-0 flex flex-col items-center justify-center pointer-events-none">
|
||||
<span className="text-xs text-[var(--muted-foreground)]">{centerLabel}</span>
|
||||
<span className="text-lg font-bold">{centerValue}</span>
|
||||
<div className="bg-[var(--card)] border border-[var(--border)] rounded-xl p-4">
|
||||
<div className="relative">
|
||||
<ResponsiveContainer width="100%" height={240}>
|
||||
<PieChart>
|
||||
<ChartPatternDefs
|
||||
prefix="cat-donut"
|
||||
categories={parts.map((c, index) => ({ color: c.categoryColor, index }))}
|
||||
/>
|
||||
<Pie
|
||||
data={parts}
|
||||
dataKey="total"
|
||||
nameKey="categoryName"
|
||||
cx="50%"
|
||||
cy="50%"
|
||||
innerRadius={55}
|
||||
outerRadius={95}
|
||||
paddingAngle={2}
|
||||
>
|
||||
{parts.map((entry, index) => (
|
||||
<Cell
|
||||
key={entry.categoryId}
|
||||
fill={getPatternFill("cat-donut", index, entry.categoryColor)}
|
||||
/>
|
||||
))}
|
||||
</Pie>
|
||||
<Tooltip
|
||||
formatter={(value) =>
|
||||
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",
|
||||
}}
|
||||
/>
|
||||
</PieChart>
|
||||
</ResponsiveContainer>
|
||||
<div className="absolute inset-0 flex flex-col items-center justify-center pointer-events-none">
|
||||
<span className="text-xs text-[var(--muted-foreground)]">{centerLabel}</span>
|
||||
<span className="text-lg font-bold">{centerValue}</span>
|
||||
</div>
|
||||
</div>
|
||||
{omitted}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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({
|
|||
/>
|
||||
<Tooltip
|
||||
formatter={(value: unknown, name: unknown) => {
|
||||
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"
|
||||
>
|
||||
<Eye size={12} />
|
||||
{name}
|
||||
{labelOf(name)}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
|
|
@ -160,9 +163,12 @@ export default function CategoryOverTimeChart({
|
|||
)}
|
||||
|
||||
<div onContextMenu={handleContextMenu}>
|
||||
{/* `stackOffset="sign"`: a negative value (an expense whose refunds
|
||||
exceed its purchases, a one-leg transfer) stacks below zero, in
|
||||
bars as in areas (D7, #392). */}
|
||||
<ResponsiveContainer width="100%" height={400}>
|
||||
{chartType === "area" ? (
|
||||
<AreaChart data={data.data} margin={{ top: 10, right: 10, left: 10, bottom: 0 }}>
|
||||
<AreaChart data={data.data} stackOffset="sign" margin={{ top: 10, right: 10, left: 10, bottom: 0 }}>
|
||||
{patternDefs}
|
||||
{commonAxes}
|
||||
{categoryEntries.map((c) => (
|
||||
|
|
@ -170,6 +176,7 @@ export default function CategoryOverTimeChart({
|
|||
key={c.name}
|
||||
type="monotone"
|
||||
dataKey={c.name}
|
||||
name={labelOf(c.name)}
|
||||
stackId="1"
|
||||
stroke={c.color}
|
||||
fill={getPatternFill(patternPrefix, c.index, c.color)}
|
||||
|
|
@ -181,13 +188,14 @@ export default function CategoryOverTimeChart({
|
|||
))}
|
||||
</AreaChart>
|
||||
) : (
|
||||
<BarChart data={data.data} margin={{ top: 10, right: 10, left: 10, bottom: 0 }}>
|
||||
<BarChart data={data.data} stackOffset="sign" margin={{ top: 10, right: 10, left: 10, bottom: 0 }}>
|
||||
{patternDefs}
|
||||
{commonAxes}
|
||||
{categoryEntries.map((c) => (
|
||||
<Bar
|
||||
key={c.name}
|
||||
dataKey={c.name}
|
||||
name={labelOf(c.name)}
|
||||
stackId="stack"
|
||||
fill={getPatternFill(patternPrefix, c.index, c.color)}
|
||||
fillOpacity={hoveredCategory === null || hoveredCategory === c.name ? 1 : 0.2}
|
||||
|
|
@ -215,14 +223,14 @@ export default function CategoryOverTimeChart({
|
|||
<ChartContextMenu
|
||||
x={contextMenu.x}
|
||||
y={contextMenu.y}
|
||||
categoryName={contextMenu.name}
|
||||
categoryName={labelOf(contextMenu.name)}
|
||||
onHide={() => onToggleHidden(contextMenu.name)}
|
||||
onViewDetails={() => {
|
||||
const color = data.colors[contextMenu.name] || "#9ca3af";
|
||||
const categoryId = data.categoryIds[contextMenu.name] ?? null;
|
||||
onViewDetails({
|
||||
category_id: categoryId,
|
||||
category_name: contextMenu.name,
|
||||
category_name: labelOf(contextMenu.name),
|
||||
category_color: color,
|
||||
total: 0,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useTranslation } from "react-i18next";
|
||||
import type { MonthlyTrendItem } from "../../shared/types";
|
||||
import { EMPTY_STATEMENT, addStatements } from "../../utils/incomeStatement";
|
||||
|
||||
const cadFormatter = (value: number) =>
|
||||
new Intl.NumberFormat("en-CA", { style: "currency", currency: "CAD", maximumFractionDigits: 0 }).format(value);
|
||||
|
|
@ -25,10 +26,11 @@ export default function MonthlyTrendsTable({ data }: MonthlyTrendsTableProps) {
|
|||
);
|
||||
}
|
||||
|
||||
const totals = data.reduce(
|
||||
(acc, row) => ({ income: acc.income + row.income, expenses: acc.expenses + row.expenses }),
|
||||
{ income: 0, expenses: 0 },
|
||||
);
|
||||
// Each month is an income statement (#392, ADR 0026): « Net » is the net
|
||||
// result, every amount of the month, so the uncategorized line and the
|
||||
// transfers it holds beyond income − expenses have their own columns (D5).
|
||||
const totals = data.reduce(addStatements, EMPTY_STATEMENT);
|
||||
const signColor = (value: number) => (value >= 0 ? "text-[var(--positive)]" : "text-[var(--negative)]");
|
||||
|
||||
return (
|
||||
<div className="bg-[var(--card)] border border-[var(--border)] rounded-xl overflow-hidden">
|
||||
|
|
@ -45,6 +47,12 @@ export default function MonthlyTrendsTable({ data }: MonthlyTrendsTableProps) {
|
|||
<th className="text-right px-3 py-2 font-medium text-[var(--muted-foreground)] bg-[var(--card)]">
|
||||
{t("dashboard.expenses")}
|
||||
</th>
|
||||
<th className="text-right px-3 py-2 font-medium text-[var(--muted-foreground)] bg-[var(--card)]">
|
||||
{t("reports.uncategorized")}
|
||||
</th>
|
||||
<th className="text-right px-3 py-2 font-medium text-[var(--muted-foreground)] bg-[var(--card)]">
|
||||
{t("reports.compare.sections.transfers")}
|
||||
</th>
|
||||
<th className="text-right px-3 py-2 font-medium text-[var(--muted-foreground)] bg-[var(--card)]">
|
||||
{t("dashboard.net")}
|
||||
</th>
|
||||
|
|
@ -56,18 +64,18 @@ export default function MonthlyTrendsTable({ data }: MonthlyTrendsTableProps) {
|
|||
<td className="px-3 py-1.5">{formatMonth(row.month)}</td>
|
||||
<td className="text-right px-3 py-1.5 text-[var(--positive)]">{cadFormatter(row.income)}</td>
|
||||
<td className="text-right px-3 py-1.5 text-[var(--negative)]">{cadFormatter(row.expenses)}</td>
|
||||
<td className={`text-right px-3 py-1.5 ${row.income - row.expenses >= 0 ? "text-[var(--positive)]" : "text-[var(--negative)]"}`}>
|
||||
{cadFormatter(row.income - row.expenses)}
|
||||
</td>
|
||||
<td className="text-right px-3 py-1.5">{cadFormatter(row.uncategorized)}</td>
|
||||
<td className="text-right px-3 py-1.5">{cadFormatter(row.transfers)}</td>
|
||||
<td className={`text-right px-3 py-1.5 ${signColor(row.net)}`}>{cadFormatter(row.net)}</td>
|
||||
</tr>
|
||||
))}
|
||||
<tr className="border-t-2 border-[var(--border)] font-bold text-sm bg-[var(--muted)]/20">
|
||||
<td className="px-3 py-3">{t("common.total")}</td>
|
||||
<td className="text-right px-3 py-3 text-[var(--positive)]">{cadFormatter(totals.income)}</td>
|
||||
<td className="text-right px-3 py-3 text-[var(--negative)]">{cadFormatter(totals.expenses)}</td>
|
||||
<td className={`text-right px-3 py-3 ${totals.income - totals.expenses >= 0 ? "text-[var(--positive)]" : "text-[var(--negative)]"}`}>
|
||||
{cadFormatter(totals.income - totals.expenses)}
|
||||
</td>
|
||||
<td className="text-right px-3 py-3">{cadFormatter(totals.uncategorized)}</td>
|
||||
<td className="text-right px-3 py-3">{cadFormatter(totals.transfers)}</td>
|
||||
<td className={`text-right px-3 py-3 ${signColor(totals.net)}`}>{cadFormatter(totals.net)}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -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({
|
|||
<div className="text-2xl font-bold tabular-nums text-[var(--foreground)]">
|
||||
{kpi.current === null ? "—" : formatValue(kpi.current, format, language)}
|
||||
</div>
|
||||
{note && <div className="-mt-2 text-xs text-[var(--muted-foreground)]">{note}</div>}
|
||||
<KpiSparkline data={kpi.sparkline} />
|
||||
<div className="flex items-start justify-between gap-2 pt-1 border-t border-[var(--border)]">
|
||||
<DeltaBadge
|
||||
|
|
|
|||
30
src/components/reports/cards/netNote.test.ts
Normal file
30
src/components/reports/cards/netNote.test.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { markedT } from "../../../test/i18nMock";
|
||||
import { netNote } from "./netNote";
|
||||
|
||||
// The note under « Solde net » (D5, #392): what the net result holds beyond
|
||||
// income − expenses.
|
||||
|
||||
const nbsp = (s: string) => 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();
|
||||
});
|
||||
});
|
||||
33
src/components/reports/cards/netNote.ts
Normal file
33
src/components/reports/cards/netNote.ts
Normal file
|
|
@ -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, unknown>) => 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;
|
||||
}
|
||||
47
src/components/reports/donutParts.test.tsx
Normal file
47
src/components/reports/donutParts.test.tsx
Normal file
|
|
@ -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(<CategoryDonutChart byChild={byChild} centerLabel="Total" centerValue="30 $" />);
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
18
src/components/reports/donutParts.ts
Normal file
18
src/components/reports/donutParts.ts
Normal file
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
@ -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(
|
||||
<TransactionSummaryBar totalCount={5} totalAmount={920} incomeTotal={1520} expenseTotal={-600} />,
|
||||
);
|
||||
|
||||
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/);
|
||||
});
|
||||
});
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-[180px]">
|
||||
|
|
|
|||
|
|
@ -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)}
|
||||
/>
|
||||
<KpiCard
|
||||
id="savingsRate"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue