From 29aa0ce736af767f3745a552766e4aaf81a4a055 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Fri, 30 Oct 2026 21:26:53 +0000 Subject: [PATCH] Default to yearly periods on Analyse, Strom and Wasser (#15) Co-authored-by: Claudio Schaad Co-committed-by: Claudio Schaad --- CLAUDE.md | 2 +- Schaad.Accounting.Common/Models/BillChartFilter.cs | 6 +++--- Schaad.Accounting.Tests/BillChartFilterTestShould.cs | 6 ++++++ .../Components/Pages/Analytics/Analytics.razor.cs | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 98801b5..210b4d5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -65,7 +65,7 @@ When a new year is opened, the previous year's data is copied as the starting po - **RawDataRepository** — plain-text load/save of the data files for the JSON editor page; validates (strict JSON, unique Ids, account references), refuses if the file changed since loading, and backs up the old version to `backup/{mandator}/{year}/json-{timestamp}/`; for `electricity.json` and `water.json` it reads/writes the mandator folder instead of the year folder - **Texte bereinigen** page (`TextCleanup`) — edits only the `Text` of one account's bookings in the selected year (inline, search/replace via `TextReplacement`, bulk set); saves through `RawDataRepository.SaveTransactionTextsAsync` - **AnalyticsService** — loads all years of the current mandator (via `MultiYearRepository`) into an `AccountingAnalysis` (expenses, income, net, assets) for the Analyse page; queries run in memory -- **Strom** page (`Electricity`, `/electricity`, under "Charts" in the menu) — grid and dialog (FluentDataGrid/`ElectricityBillDialog`) over `IElectricityBillRepository`'s `ElectricityBill` records (one yearly NeoVac bill each: kWh/CHF for grid and PV, side costs; `TotalKwh`, `PvShare`, `TotalChf`, `ChfPerKwh` are computed); three Chart.js charts via `ChartJsChart` (stacked kWh, CHF/kWh lines, total CHF), filtered by the shared `BillChartToolbar` (`BillChartFilter`): grouped per bill (default), calendar year or half-year (`BillPeriod.FromBills` over `IPeriodBill`; a bill reaching over several periods is spread evenly over its months and the page shows a note) and limited to a from/to year range (periods overlapping it are kept whole) +- **Strom** page (`Electricity`, `/electricity`, under "Charts" in the menu) — grid and dialog (FluentDataGrid/`ElectricityBillDialog`) over `IElectricityBillRepository`'s `ElectricityBill` records (one yearly NeoVac bill each: kWh/CHF for grid and PV, side costs; `TotalKwh`, `PvShare`, `TotalChf`, `ChfPerKwh` are computed); three Chart.js charts via `ChartJsChart` (stacked kWh, CHF/kWh lines, total CHF), filtered by the shared `BillChartToolbar` (`BillChartFilter`): grouped per bill, calendar year (default) or half-year (`BillPeriod.FromBills` over `IPeriodBill`; a bill reaching over several periods is spread evenly over its months and the page shows a note) and limited to a from/to year range (periods overlapping it are kept whole) - **Wasser** page (`Water`, `/water`, under "Charts" in the menu) — same layout as Strom over `IWaterBillRepository`'s `WaterBill` records (warm/cold water m³ and CHF, base costs; `TotalM3`, `WarmWaterShare`, `TotalChf` are computed); two charts (stacked m³, total CHF) with the same `BillChartToolbar` ### UI structure diff --git a/Schaad.Accounting.Common/Models/BillChartFilter.cs b/Schaad.Accounting.Common/Models/BillChartFilter.cs index 5464834..6b578b7 100644 --- a/Schaad.Accounting.Common/Models/BillChartFilter.cs +++ b/Schaad.Accounting.Common/Models/BillChartFilter.cs @@ -5,11 +5,11 @@ using System.Linq; namespace Schaad.Accounting.Models { /// - /// What the charts on the Strom and Wasser pages show: how the bills are grouped and which - /// years. A null / means from the first/to the last + /// What the charts on the Strom and Wasser pages show: how the bills are grouped (calendar year + /// by default) and which years. A null / means from the first/to the last /// year with a bill, so a newly added bill shows up without touching the filter. /// - public record BillChartFilter(BillPeriodKind Kind = BillPeriodKind.Bill, int? FromYear = null, int? ToYear = null) + public record BillChartFilter(BillPeriodKind Kind = BillPeriodKind.Year, int? FromYear = null, int? ToYear = null) { /// The years any bill touches, from the first to the last; empty without bills. public static List YearsOf(IEnumerable bills) where T : IPeriodBill diff --git a/Schaad.Accounting.Tests/BillChartFilterTestShould.cs b/Schaad.Accounting.Tests/BillChartFilterTestShould.cs index a22c68a..e865e86 100644 --- a/Schaad.Accounting.Tests/BillChartFilterTestShould.cs +++ b/Schaad.Accounting.Tests/BillChartFilterTestShould.cs @@ -17,6 +17,12 @@ public class BillChartFilterTestShould BillChartFilter.YearsOf([]).ShouldBeEmpty(); } + [Fact] + public void GroupPerCalendarYearWhenNoKindIsGiven() + { + new BillChartFilter().Kind.ShouldBe(BillPeriodKind.Year); + } + [Fact] public void CoverAllYearsWhenNoYearIsSelected() { diff --git a/Schaad.Accounting.UI/Components/Pages/Analytics/Analytics.razor.cs b/Schaad.Accounting.UI/Components/Pages/Analytics/Analytics.razor.cs index be7807c..5abbc11 100644 --- a/Schaad.Accounting.UI/Components/Pages/Analytics/Analytics.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Analytics/Analytics.razor.cs @@ -100,7 +100,7 @@ public partial class Analytics : ComponentBase { (fromYear, toYear) = (toYear, fromYear); } - period = ParsePeriod(Period) ?? (fromYear == toYear ? AnalyticsPeriod.Month : AnalyticsPeriod.Quarter); + period = ParsePeriod(Period) ?? AnalyticsPeriod.Year; view = Enum.TryParse(View, ignoreCase: true, out var parsedView) ? parsedView : AnalyticsView.Expenses; node = Acc is { } account ? new AnalyticsNode(account / 100, account, IsAssets ? null : Text)