feat: show actual transactions in budget previous year column
Replace planned budget data with actual transaction totals for the previous year column in the budget table. Add getActualTotalsForYear helper to budgetService. Ref #34 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
52faa017f3
commit
4e70eee0a8
5 changed files with 23 additions and 6 deletions
|
|
@ -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é
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue