fix: show actual transactions in budget previous year column (#34) #35
5 changed files with 23 additions and 6 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
## [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]
|
||||
|
||||
### Ajouté
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
- Budget table: previous year column now shows actual transactions instead of planned budget (#34)
|
||||
|
||||
## [0.6.5]
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import type { BudgetYearRow, BudgetTemplate } from "../shared/types";
|
|||
import {
|
||||
getAllActiveCategories,
|
||||
getBudgetEntriesForYear,
|
||||
getActualTotalsForYear,
|
||||
upsertBudgetEntry,
|
||||
upsertBudgetEntriesForYear,
|
||||
getAllTemplates,
|
||||
|
|
@ -72,10 +73,10 @@ export function useBudget() {
|
|||
dispatch({ type: "SET_ERROR", payload: null });
|
||||
|
||||
try {
|
||||
const [allCategories, entries, prevYearEntries, templates] = await Promise.all([
|
||||
const [allCategories, entries, prevYearActuals, templates] = await Promise.all([
|
||||
getAllActiveCategories(),
|
||||
getBudgetEntriesForYear(year),
|
||||
getBudgetEntriesForYear(year - 1),
|
||||
getActualTotalsForYear(year - 1),
|
||||
getAllTemplates(),
|
||||
]);
|
||||
|
||||
|
|
@ -88,10 +89,10 @@ export function useBudget() {
|
|||
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>();
|
||||
for (const e of prevYearEntries) {
|
||||
prevYearTotalMap.set(e.category_id, (prevYearTotalMap.get(e.category_id) ?? 0) + e.amount);
|
||||
for (const a of prevYearActuals) {
|
||||
if (a.category_id != null) prevYearTotalMap.set(a.category_id, a.actual);
|
||||
}
|
||||
|
||||
// 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]);
|
||||
}
|
||||
|
||||
// --- 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 ---
|
||||
|
||||
async function getActualsByCategoryRange(
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ export interface BudgetYearRow {
|
|||
depth?: number;
|
||||
months: number[]; // index 0-11 = Jan-Dec planned amounts
|
||||
annual: number; // computed sum
|
||||
previousYearTotal: number; // total budget from the previous year
|
||||
previousYearTotal: number; // actual (transactions) total from the previous year
|
||||
}
|
||||
|
||||
export interface ImportConfigTemplate {
|
||||
|
|
|
|||
Loading…
Reference in a new issue