Add cost history to the Costs page: what it cost each month, and what changed

Each cost item's name, amount, currency, period and kind are kept as versions (cost_item_versions), and Hetzner's estimate is written down once a day (cost_snapshots), so a past month's figure and the changes between can be worked out. History card with monthly bars per currency, month-by-month figures and a list of added, changed and removed items.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-04 23:57:59 +01:00
1 parent b29c0b7d04
commit 9f366c37de
15 files changed
+9716 -3

No files matched your search

+12
View File
@@ -1796,6 +1796,17 @@ export interface CostsReport {
categories: string[];
}
/** What the homelab cost, month by month for each currency, and what changed. */
export interface CostHistory {
/** From the first month there is anything to say about, to this one. */
months: string[];
series: { currency: string; points: { month: string; monthly: number; manual: number; automatic: number }[] }[];
/** Newest first: items added, changed and removed, and a read estimate that moved. */
events: { at: string; kind: "added" | "changed" | "removed" | "estimate"; name: string; amount: number; currency: string; period: string; category: string; from: { name: string; amount: number; currency: string; period: string; category: string } | null }[];
/** When the app began keeping the history; null before the first pass. */
startedAt: string | null;
}
/** One Speedtest Tracker (an integration of type speedtest), as its page shows it. Speeds are bits per second. */
export interface SpeedtestInfo {
id: number;
@@ -3610,6 +3621,7 @@ export const api = {
},
costs: {
get: () => request<CostsReport>("/api/costs"),
history: (months = 12) => request<CostHistory>(`/api/costs/history?months=${months}`),
create: (data: CostInput) => request<{ id: number }>("/api/costs", { method: "POST", body: JSON.stringify(data) }),
update: (id: number, data: CostInput) => request<{ id: number }>(`/api/costs/${id}`, { method: "PUT", body: JSON.stringify(data) }),
remove: (id: number) => request<void>(`/api/costs/${id}`, { method: "DELETE" }),