fix: show actual transactions in budget previous year column (#34) #35

Merged
maximus merged 4 commits from fix/simpl-resultat-34-budget-previous-year-actual into main 2026-03-11 16:16:19 +00:00
5 changed files with 23 additions and 6 deletions
Showing only changes of commit 4e70eee0a8 - Show all commits

View file

@ -2,6 +2,9 @@
## [Non publié] ## [Non publié]
### Modifié
- Tableau de budget : la colonne année précédente affiche maintenant le réel (transactions) au lieu du budget planifié (#34)
## [0.6.5] ## [0.6.5]
### Ajouté ### Ajouté

View file

@ -2,6 +2,9 @@
## [Unreleased] ## [Unreleased]
### Changed
- Budget table: previous year column now shows actual transactions instead of planned budget (#34)
## [0.6.5] ## [0.6.5]
### Added ### Added

View file

@ -3,6 +3,7 @@ import type { BudgetYearRow, BudgetTemplate } from "../shared/types";
import { import {
getAllActiveCategories, getAllActiveCategories,
getBudgetEntriesForYear, getBudgetEntriesForYear,
getActualTotalsForYear,
upsertBudgetEntry, upsertBudgetEntry,
upsertBudgetEntriesForYear, upsertBudgetEntriesForYear,
getAllTemplates, getAllTemplates,
@ -72,10 +73,10 @@ export function useBudget() {
dispatch({ type: "SET_ERROR", payload: null }); dispatch({ type: "SET_ERROR", payload: null });
try { try {
const [allCategories, entries, prevYearEntries, templates] = await Promise.all([ const [allCategories, entries, prevYearActuals, templates] = await Promise.all([
getAllActiveCategories(), getAllActiveCategories(),
getBudgetEntriesForYear(year), getBudgetEntriesForYear(year),
getBudgetEntriesForYear(year - 1), getActualTotalsForYear(year - 1),
getAllTemplates(), getAllTemplates(),
]); ]);
@ -88,10 +89,10 @@ export function useBudget() {
entryMap.get(e.category_id)!.set(e.month, e.amount); entryMap.get(e.category_id)!.set(e.month, e.amount);
} }
// Build a map for previous year totals: categoryId -> annual total // Build a map for previous year actuals: categoryId -> annual actual total
const prevYearTotalMap = new Map<number, number>(); const prevYearTotalMap = new Map<number, number>();
for (const e of prevYearEntries) { for (const a of prevYearActuals) {
prevYearTotalMap.set(e.category_id, (prevYearTotalMap.get(e.category_id) ?? 0) + e.amount); if (a.category_id != null) prevYearTotalMap.set(a.category_id, a.actual);
} }
// Helper: build months array from entryMap // Helper: build months array from entryMap

View file

@ -178,6 +178,16 @@ export async function deleteTemplate(templateId: number): Promise<void> {
await db.execute("DELETE FROM budget_templates WHERE id = $1", [templateId]); await db.execute("DELETE FROM budget_templates WHERE id = $1", [templateId]);
} }
// --- Actuals helpers ---
export async function getActualTotalsForYear(
year: number
): Promise<Array<{ category_id: number | null; actual: number }>> {
const dateFrom = `${year}-01-01`;
const dateTo = `${year}-12-31`;
return getActualsByCategoryRange(dateFrom, dateTo);
}
// --- Budget vs Actual --- // --- Budget vs Actual ---
async function getActualsByCategoryRange( async function getActualsByCategoryRange(

View file

@ -142,7 +142,7 @@ export interface BudgetYearRow {
depth?: number; depth?: number;
months: number[]; // index 0-11 = Jan-Dec planned amounts months: number[]; // index 0-11 = Jan-Dec planned amounts
annual: number; // computed sum annual: number; // computed sum
previousYearTotal: number; // total budget from the previous year previousYearTotal: number; // actual (transactions) total from the previous year
} }
export interface ImportConfigTemplate { export interface ImportConfigTemplate {