From 53e4854bc265e28eeded08fababc6a869fe1bd5b Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sun, 1 Nov 2026 19:18:03 +0100 Subject: [PATCH 1/5] Add "Wasser & Heizung" page for the NeoVac water and heating bills MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NeoVac only reports per-mille shares of the property; the own costs in CHF come from the property manager's statement. The new page stores both in water-heating.json (per mandator) and calculates the CHF parts: water base and consumption costs by their per-mille share, consumption split by m³ into warm and cold water, and the warm water part of the heating costs (the rest is room heating). Charts for water (m³), heat (MWh) and the stacked costs; the dialog has a guide image showing where each value is on the bills. The Wasser page stays for bills with the CHF values entered directly. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 6 +- .../Interfaces/IWaterHeatingBillRepository.cs | 17 ++ .../Models/WaterHeatingBill.cs | 128 ++++++++++++++ .../Repositories/RawDataRepository.cs | 9 +- .../WaterHeatingBillRepository.cs | 56 ++++++ .../RawDataRepositoryTestShould.cs | 16 ++ .../WaterHeatingBillRepositoryTestShould.cs | 93 ++++++++++ .../WaterHeatingBillTestShould.cs | 87 ++++++++++ .../Components/Layout/NavMenu.razor | 1 + .../Dialogs/WaterHeatingBillDialog.razor | 89 ++++++++++ .../Dialogs/WaterHeatingBillDialog.razor.cs | 87 ++++++++++ .../Components/Pages/WaterHeating.razor | 61 +++++++ .../Components/Pages/WaterHeating.razor.cs | 164 ++++++++++++++++++ .../Components/Pages/WaterHeating.razor.css | 32 ++++ Schaad.Accounting.UI/Extensions.cs | 1 + .../images/water-heating-bill-guide.svg | 74 ++++++++ 16 files changed, 916 insertions(+), 5 deletions(-) create mode 100644 Schaad.Accounting.Common/Interfaces/IWaterHeatingBillRepository.cs create mode 100644 Schaad.Accounting.Common/Models/WaterHeatingBill.cs create mode 100644 Schaad.Accounting.Db/Repositories/WaterHeatingBillRepository.cs create mode 100644 Schaad.Accounting.Tests/WaterHeatingBillRepositoryTestShould.cs create mode 100644 Schaad.Accounting.Tests/WaterHeatingBillTestShould.cs create mode 100644 Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor create mode 100644 Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs create mode 100644 Schaad.Accounting.UI/Components/Pages/WaterHeating.razor create mode 100644 Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs create mode 100644 Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.css create mode 100644 Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg diff --git a/CLAUDE.md b/CLAUDE.md index dcd4367..c0e70ea 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -48,12 +48,13 @@ Data is multi-mandator and multi-year. The layout below `DataPath` (configured i {DataPath}/{mandator}/{year}/*.json data files {DataPath}/{mandator}/electricity.json electricity bills (not per year, see below) {DataPath}/{mandator}/water.json water bills (not per year, see below) +{DataPath}/{mandator}/water-heating.json NeoVac water and heating bills (not per year, see below) {DataPath}/backup/{mandator}/{year}/ backup zips ``` When a new year is opened, the previous year's data is copied as the starting point. -`electricity.json` and `water.json` are the data files kept per mandator instead of per year (`ISettingsService.GetMandatorPath()`), because the NeoVac billing period runs 1 July–30 June and doesn't align with calendar years. +`electricity.json`, `water.json` and `water-heating.json` are the data files kept per mandator instead of per year (`ISettingsService.GetMandatorPath()`), because the NeoVac billing period runs 1 July–30 June and doesn't align with calendar years. ### Key services @@ -61,11 +62,12 @@ When a new year is opened, the previous year's data is copied as the starting po - **FileService** — imports bank statements (MT940, CAMT053 via external `Schaad.Finance.dll`; uploads go to temp files only), manages backups - **ChartService** — produces data for the Plotly booking-text charts on the transactions page - **SettingsService** — manages the active year, mandator, and file paths -- **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 +- **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`, `water.json` and `water-heating.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, 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` +- **Wasser & Heizung** page (`WaterHeating`, `/water-heating`, under "Charts" in the menu) — same layout for NeoVac bills where only per-mille shares are known, over `IWaterHeatingBillRepository`'s `WaterHeatingBill` records: consumption (warm/cold m³, heat MWh) and ‰ shares from NeoVac, own water/heating costs in CHF from the property manager's statement; `WaterHeatingBillDialog` calls `CalculateCosts`, which stores the CHF parts (water split into base/consumption by ‰, consumption split by m³, warm water part of the heating), so `AddShare` can sum them per period; `RoomHeatingChf` is the rest of the heating. Three charts (stacked m³, MWh, stacked CHF) and a guide image (`water-heating-bill-guide.svg`) ### UI structure diff --git a/Schaad.Accounting.Common/Interfaces/IWaterHeatingBillRepository.cs b/Schaad.Accounting.Common/Interfaces/IWaterHeatingBillRepository.cs new file mode 100644 index 0000000..365543b --- /dev/null +++ b/Schaad.Accounting.Common/Interfaces/IWaterHeatingBillRepository.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Schaad.Accounting.Models; + +namespace Schaad.Accounting.Interfaces +{ + public interface IWaterHeatingBillRepository + { + Task> GetWaterHeatingBillListAsync(); + + Task SaveWaterHeatingBillAsync(WaterHeatingBill bill); + + Task GetWaterHeatingBillAsync(string id); + + Task DeleteWaterHeatingBillAsync(string id); + } +} diff --git a/Schaad.Accounting.Common/Models/WaterHeatingBill.cs b/Schaad.Accounting.Common/Models/WaterHeatingBill.cs new file mode 100644 index 0000000..2c10008 --- /dev/null +++ b/Schaad.Accounting.Common/Models/WaterHeatingBill.cs @@ -0,0 +1,128 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; + +namespace Schaad.Accounting.Models +{ + /// + /// One yearly NeoVac bill for water and heating. NeoVac only reports per-mille shares of the + /// property; the own share in CHF comes from the property manager's statement. The CHF parts + /// (base costs, warm/cold water, warm water heating) are calculated from both by CalculateCosts + /// and stored, so periods can add them up (see BillPeriod). Like the electricity bills, these + /// are stored once per mandator, because the billing period runs 1 July – 30 June + /// (see WaterHeatingBillRepository in Schaad.Accounting.Db). + /// + public class WaterHeatingBill : IPeriodBill + { + public string Id { get; set; } + + [Display(Name = "Von")] + [Required] + public DateOnly PeriodFrom { get; set; } + + [Display(Name = "Bis")] + [Required] + public DateOnly PeriodTo { get; set; } + + // NeoVac "Ablesequittung", consumption billed ("Verbrauch verrechnet"). + + [Display(Name = "Warmwasser")] + public decimal WarmWaterM3 { get; set; } + + [Display(Name = "Kaltwasser")] + public decimal ColdWaterM3 { get; set; } + + [Display(Name = "Wärme")] + public decimal HeatingMwh { get; set; } + + // NeoVac per-mille shares of the property, column "Anteil (‰)". + + [Display(Name = "Wasser Grundkosten-Anteil")] + public decimal WaterBasePermille { get; set; } + + [Display(Name = "Wasser Verbrauchskosten-Anteil")] + public decimal WaterConsumptionPermille { get; set; } + + /// Own share of the heating costs ("Wärmekostenanteil"). + [Display(Name = "Wärmekostenanteil")] + public decimal HeatingPermille { get; set; } + + /// Part of HeatingPermille spent on heating warm water. + [Display(Name = "Warmwasser-Anteil Heizung")] + public decimal WarmWaterHeatingPermille { get; set; } + + // Own share in CHF, from the property manager's statement. + + [Display(Name = "Wasserkosten")] + public decimal WaterCostsChf { get; set; } + + [Display(Name = "Heizkosten")] + public decimal HeatingCostsChf { get; set; } + + // Calculated by CalculateCosts. + + [Display(Name = "Grundkosten Wasser")] + public decimal BaseCostsChf { get; set; } + + [Display(Name = "Warmwasser")] + public decimal WarmWaterChf { get; set; } + + [Display(Name = "Kaltwasser")] + public decimal ColdWaterChf { get; set; } + + [Display(Name = "Heizung Warmwasser")] + public decimal WarmWaterHeatingChf { get; set; } + + /// Warm plus cold water, in m³. + [JsonIgnore] + [Display(Name = "Total")] + public decimal TotalM3 => WarmWaterM3 + ColdWaterM3; + + /// Share of the consumption that was warm water, 0..1. + [JsonIgnore] + [Display(Name = "Warmwasser-Anteil")] + public decimal WarmWaterShare => TotalM3 == 0 ? 0 : WarmWaterM3 / TotalM3; + + /// Heating costs not spent on warm water, i.e. heating the rooms. + [JsonIgnore] + [Display(Name = "Heizung Räume")] + public decimal RoomHeatingChf => HeatingCostsChf - WarmWaterHeatingChf; + + /// Water and heating costs added up. + [JsonIgnore] + [Display(Name = "Total")] + public decimal TotalChf => WaterCostsChf + HeatingCostsChf; + + /// + /// Sets the calculated CHF values: the water costs are split into base and consumption + /// costs by their ‰, and since NeoVac bills warm and cold water consumption together, the + /// consumption costs are split by m³. The warm water part of the heating costs is + /// HeatingCostsChf × WarmWaterHeatingPermille / HeatingPermille. + /// + public void CalculateCosts() + { + var waterPermille = WaterBasePermille + WaterConsumptionPermille; + BaseCostsChf = waterPermille == 0 ? 0 : Round(WaterCostsChf * WaterBasePermille / waterPermille); + var consumptionChf = WaterCostsChf - BaseCostsChf; + WarmWaterChf = Round(consumptionChf * WarmWaterShare); + ColdWaterChf = consumptionChf - WarmWaterChf; + WarmWaterHeatingChf = HeatingPermille == 0 ? 0 : Round(HeatingCostsChf * WarmWaterHeatingPermille / HeatingPermille); + } + + private static decimal Round(decimal value) => Math.Round(value, 2, MidpointRounding.AwayFromZero); + + /// Adds up consumption and CHF values; the per-mille shares don't add up and are left out. + public void AddShare(WaterHeatingBill other, decimal share) + { + WarmWaterM3 += other.WarmWaterM3 * share; + ColdWaterM3 += other.ColdWaterM3 * share; + HeatingMwh += other.HeatingMwh * share; + WaterCostsChf += other.WaterCostsChf * share; + HeatingCostsChf += other.HeatingCostsChf * share; + BaseCostsChf += other.BaseCostsChf * share; + WarmWaterChf += other.WarmWaterChf * share; + ColdWaterChf += other.ColdWaterChf * share; + WarmWaterHeatingChf += other.WarmWaterHeatingChf * share; + } + } +} diff --git a/Schaad.Accounting.Db/Repositories/RawDataRepository.cs b/Schaad.Accounting.Db/Repositories/RawDataRepository.cs index 7e1db03..6fedc33 100644 --- a/Schaad.Accounting.Db/Repositories/RawDataRepository.cs +++ b/Schaad.Accounting.Db/Repositories/RawDataRepository.cs @@ -27,6 +27,7 @@ namespace Schaad.Accounting.Repositories private const string TRANSACTIONS = "Transactions.json"; private const string ELECTRICITY = "electricity.json"; private const string WATER = "water.json"; + private const string WATER_HEATING = "water-heating.json"; private const int MaxErrors = 20; // Like the normal options, but property names that don't exist (typos) are errors instead @@ -50,7 +51,8 @@ namespace Schaad.Accounting.Repositories "BookingTexts.json", "SubClasses.json", ELECTRICITY, - WATER + WATER, + WATER_HEATING ]; public async Task LoadAsync(string fileName) @@ -70,6 +72,7 @@ namespace Schaad.Accounting.Repositories "SubClasses.json" => SaveAsync(fileName, text, loadedHash), ELECTRICITY => SaveAsync(fileName, text, loadedHash), WATER => SaveAsync(fileName, text, loadedHash), + WATER_HEATING => SaveAsync(fileName, text, loadedHash), _ => throw new ArgumentException($"Unknown data file '{fileName}'", nameof(fileName)) }; @@ -240,10 +243,10 @@ namespace Schaad.Accounting.Repositories return Path.Combine(DirectoryOf(fileName), fileName); } - // electricity.json and water.json live at the mandator level, not per year (their period + // electricity.json, water.json and water-heating.json live at the mandator level, not per year (their period // runs 1 July – 30 June, so it doesn't align with calendar years). private string DirectoryOf(string fileName) - => fileName is ELECTRICITY or WATER ? settingsService.GetMandatorPath() : settingsService.GetDbPath(); + => fileName is ELECTRICITY or WATER or WATER_HEATING ? settingsService.GetMandatorPath() : settingsService.GetDbPath(); private static string Hash(byte[] bytes) => Convert.ToHexString(SHA256.HashData(bytes)); diff --git a/Schaad.Accounting.Db/Repositories/WaterHeatingBillRepository.cs b/Schaad.Accounting.Db/Repositories/WaterHeatingBillRepository.cs new file mode 100644 index 0000000..db554d3 --- /dev/null +++ b/Schaad.Accounting.Db/Repositories/WaterHeatingBillRepository.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Schaad.Accounting.Interfaces; +using Schaad.Accounting.Models; + +namespace Schaad.Accounting.Repositories +{ + /// + /// NeoVac water and heating bills of the current mandator, stored once per mandator (not per + /// year like the other data files) because the billing period doesn't align with calendar years. + /// + public class WaterHeatingBillRepository : BaseRepository, IWaterHeatingBillRepository + { + private const string WATER_HEATING = "water-heating.json"; + + public WaterHeatingBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger logger) + : base(settingsService, cache, logger) + { + } + + public Task> GetWaterHeatingBillListAsync() + => LoadListAsync(settingsService.GetMandatorPath(), WATER_HEATING); + + public async Task SaveWaterHeatingBillAsync(WaterHeatingBill bill) + { + var bills = await GetWaterHeatingBillListAsync(); + var idx = bills.FindIndex(b => b.Id == bill.Id); + if (idx >= 0) + { + bills[idx] = bill; + } + else + { + bill.Id = Guid.NewGuid().ToString(); + bills.Add(bill); + } + await SaveAsync(bills, settingsService.GetMandatorPath(), WATER_HEATING); + } + + public async Task GetWaterHeatingBillAsync(string id) + { + var bills = await GetWaterHeatingBillListAsync(); + return bills.FirstOrDefault(b => b.Id == id); + } + + public async Task DeleteWaterHeatingBillAsync(string id) + { + var bills = await GetWaterHeatingBillListAsync(); + bills.RemoveAll(b => b.Id == id); + await SaveAsync(bills, settingsService.GetMandatorPath(), WATER_HEATING); + } + } +} diff --git a/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs b/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs index d74d8ce..3e7524c 100644 --- a/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs +++ b/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs @@ -208,6 +208,22 @@ public class RawDataRepositoryTestShould : IDisposable File.Exists(Path.Combine(dbDir, "water.json")).ShouldBeFalse(); } + [Fact] + public async Task ReadAndWriteWaterHeatingFileInMandatorFolderNotYearFolderWhenEditing() + { + File.WriteAllText(Path.Combine(mandatorDir, "water-heating.json"), """ + [ { "Id": "h1", "PeriodFrom": "2024-07-01", "PeriodTo": "2025-06-30", "HeatingCostsChf": 100 } ] + """); + var loaded = await sut.LoadAsync("water-heating.json"); + + var result = await sut.SaveAsync("water-heating.json", loaded.Text.Replace("100", "150"), loaded.Hash); + + result.Errors.ShouldBeEmpty(); + result.Saved.ShouldBeTrue(); + File.ReadAllText(Path.Combine(mandatorDir, "water-heating.json")).ShouldContain("150"); + File.Exists(Path.Combine(dbDir, "water-heating.json")).ShouldBeFalse(); + } + [Fact] public async Task RejectUnknownFileNameWhenLoading() { diff --git a/Schaad.Accounting.Tests/WaterHeatingBillRepositoryTestShould.cs b/Schaad.Accounting.Tests/WaterHeatingBillRepositoryTestShould.cs new file mode 100644 index 0000000..b8125ec --- /dev/null +++ b/Schaad.Accounting.Tests/WaterHeatingBillRepositoryTestShould.cs @@ -0,0 +1,93 @@ +using Microsoft.Extensions.Logging.Abstractions; +using NSubstitute; +using Schaad.Accounting.Interfaces; +using Schaad.Accounting.Models; +using Schaad.Accounting.Repositories; +using Shouldly; + +namespace Schaad.Accounting.Tests; + +public class WaterHeatingBillRepositoryTestShould : IDisposable +{ + private readonly string mandatorDir; + private readonly ISettingsService settingsService; + private readonly WaterHeatingBillRepository sut; + + public WaterHeatingBillRepositoryTestShould() + { + mandatorDir = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(mandatorDir); + + settingsService = Substitute.For(); + settingsService.GetMandatorPath().Returns(mandatorDir); + + sut = new WaterHeatingBillRepository(settingsService, new RepositoryCache(), NullLogger.Instance); + } + + public void Dispose() + { + if (Directory.Exists(mandatorDir)) + { + Directory.Delete(mandatorDir, recursive: true); + } + } + + [Fact] + public async Task ReturnEmptyListWhenFileDoesNotExistYet() + { + (await sut.GetWaterHeatingBillListAsync()).ShouldBeEmpty(); + } + + [Fact] + public async Task AssignNewIdWhenSavingBillWithoutId() + { + var bill = new WaterHeatingBill + { + PeriodFrom = new DateOnly(2023, 7, 1), + PeriodTo = new DateOnly(2024, 6, 30), + WarmWaterM3 = 12.345m, + ColdWaterM3 = 30.5m, + WaterCostsChf = 304.30m, + HeatingCostsChf = 451.65m + }; + + await sut.SaveWaterHeatingBillAsync(bill); + + var stored = (await sut.GetWaterHeatingBillListAsync()).Single(); + stored.Id.ShouldNotBeNullOrEmpty(); + stored.TotalM3.ShouldBe(42.845m); + stored.TotalChf.ShouldBe(755.95m); + } + + [Fact] + public async Task UpdateInPlaceWhenSavingBillWithExistingId() + { + await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), WarmWaterM3 = 10m }); + var id = (await sut.GetWaterHeatingBillListAsync()).Single().Id; + + await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { Id = id, PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), WarmWaterM3 = 13m }); + + var bills = await sut.GetWaterHeatingBillListAsync(); + bills.Count.ShouldBe(1); + bills[0].WarmWaterM3.ShouldBe(13m); + } + + [Fact] + public async Task RemoveBillWhenDeletingById() + { + await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) }); + var id = (await sut.GetWaterHeatingBillListAsync()).Single().Id; + + await sut.DeleteWaterHeatingBillAsync(id); + + (await sut.GetWaterHeatingBillListAsync()).ShouldBeEmpty(); + } + + [Fact] + public async Task StoreFileDirectlyInMandatorFolderWithoutYearSubfolder() + { + await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) }); + + File.Exists(Path.Combine(mandatorDir, "water-heating.json")).ShouldBeTrue(); + } +} diff --git a/Schaad.Accounting.Tests/WaterHeatingBillTestShould.cs b/Schaad.Accounting.Tests/WaterHeatingBillTestShould.cs new file mode 100644 index 0000000..13ed008 --- /dev/null +++ b/Schaad.Accounting.Tests/WaterHeatingBillTestShould.cs @@ -0,0 +1,87 @@ +using Schaad.Accounting.Models; +using Shouldly; + +namespace Schaad.Accounting.Tests; + +public class WaterHeatingBillTestShould +{ + // Values of the 2024/25 bill: NeoVac per-mille shares and the own share from the property manager. + private static WaterHeatingBill Bill() => new() + { + WarmWaterM3 = 16.399m, + ColdWaterM3 = 51.464m, + WaterBasePermille = 19.52m, + WaterConsumptionPermille = 68.50m, + HeatingPermille = 62.82m, + WarmWaterHeatingPermille = 12.66m, + WaterCostsChf = 304.30m, + HeatingCostsChf = 451.65m + }; + + [Fact] + public void SplitWaterCostsByPermilleAndM3WhenCalculatingCosts() + { + var bill = Bill(); + + bill.CalculateCosts(); + + bill.BaseCostsChf.ShouldBe(67.48m); + bill.WarmWaterChf.ShouldBe(57.23m); + bill.ColdWaterChf.ShouldBe(179.59m); + } + + [Fact] + public void SplitHeatingCostsIntoWarmWaterAndRoomsWhenCalculatingCosts() + { + var bill = Bill(); + + bill.CalculateCosts(); + + bill.WarmWaterHeatingChf.ShouldBe(91.02m); + bill.RoomHeatingChf.ShouldBe(360.63m); + bill.TotalChf.ShouldBe(755.95m); + } + + [Fact] + public void PutAllConsumptionCostsOnColdWaterWhenCalculatingCostsWithoutConsumption() + { + var bill = new WaterHeatingBill { WaterCostsChf = 100m, WaterBasePermille = 20m, WaterConsumptionPermille = 80m }; + + bill.CalculateCosts(); + + bill.BaseCostsChf.ShouldBe(20m); + bill.WarmWaterChf.ShouldBe(0m); + bill.ColdWaterChf.ShouldBe(80m); + } + + [Fact] + public void LeaveHeatingCostsOnRoomsWhenCalculatingCostsWithoutPermilleShares() + { + var bill = new WaterHeatingBill { HeatingCostsChf = 450m }; + + bill.CalculateCosts(); + + bill.BaseCostsChf.ShouldBe(0m); + bill.WarmWaterHeatingChf.ShouldBe(0m); + bill.RoomHeatingChf.ShouldBe(450m); + } + + [Fact] + public void AddShareOfConsumptionAndCostsWhenAddingShareOfOtherBill() + { + var other = Bill(); + other.HeatingMwh = 2.458m; + other.CalculateCosts(); + var sum = new WaterHeatingBill(); + + sum.AddShare(other, 0.5m); + + sum.WarmWaterM3.ShouldBe(8.1995m); + sum.HeatingMwh.ShouldBe(1.229m); + sum.WaterCostsChf.ShouldBe(152.15m); + sum.HeatingCostsChf.ShouldBe(225.825m); + sum.ColdWaterChf.ShouldBe(89.795m); + sum.WarmWaterHeatingChf.ShouldBe(45.51m); + sum.WaterBasePermille.ShouldBe(0m); + } +} diff --git a/Schaad.Accounting.UI/Components/Layout/NavMenu.razor b/Schaad.Accounting.UI/Components/Layout/NavMenu.razor index ebfb65d..8a74e94 100644 --- a/Schaad.Accounting.UI/Components/Layout/NavMenu.razor +++ b/Schaad.Accounting.UI/Components/Layout/NavMenu.razor @@ -21,6 +21,7 @@ Analyse Strom Wasser + Wasser & Heizung Erfolgsrechnung diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor new file mode 100644 index 0000000..a25a43c --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor @@ -0,0 +1,89 @@ +@implements IDialogContentComponent +@rendermode InteractiveServer + + + + + + @Dialog.Instance.Parameters.Title + + + + + + + + + + + + +
NeoVac – Ablesequittung (Verbrauch verrechnet)
+ + + + + + + + +
NeoVac – Anteil (‰)
+ + + + + + + + + +
Verwaltung – Ihr Anteil (CHF)
+ + + + +
+ +
+
+ +
+ Wasser: Grundkosten @Chf(Content.BaseCostsChf) + · Warmwasser @Chf(Content.WarmWaterChf) + · Kaltwasser @Chf(Content.ColdWaterChf) +
+
+ Heizung: Warmwasser @Chf(Content.WarmWaterHeatingChf) + · Räume @Chf(Content.RoomHeatingChf) +
+
+ Total @M3(Content.TotalM3) · @Mwh(Content.HeatingMwh) · @Chf(Content.TotalChf) +
+ + + Woher kommen die Werte? (NeoVac-Abrechnung) + +
+ + + + Abbrechen + + + Speichern + + + +@code { + private const string SectionStyle = "margin-top: 14px; font-size: 11px; font-weight: bold; color: #898781; text-transform: uppercase;"; + + // Shown in its own dialog (see ShowGuideAsync) instead of expanding inline: this dialog has a + // fixed Height, and FluentDialogBody doesn't resize to fit growing content. + private RenderFragment GuideImage => + @Beispiel-Abrechnung mit Markierungen, welcher Wert in welches Feld gehört; +} diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs new file mode 100644 index 0000000..977c101 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs @@ -0,0 +1,87 @@ +using System.Globalization; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.FluentUI.AspNetCore.Components; +using Schaad.Accounting.Interfaces; +using Schaad.Accounting.Models; + +namespace Schaad.Accounting.UI.Components.Pages.Dialogs; + +/// +/// NeoVac water and heating bill: consumption and per-mille shares from NeoVac, own costs from the +/// property manager's statement; the CHF parts are calculated (see ). +/// +public partial class WaterHeatingBillDialog : ComponentBase +{ + private static readonly CultureInfo SwissNumbers = CreateSwissNumbers(); + + private EditContext editContext = null!; + + // FluentDatePicker needs DateTime?; the model stores DateOnly (see WaterHeatingBill). + private DateTime? periodFrom; + private DateTime? periodTo; + + [CascadingParameter] + public FluentDialog Dialog { get; set; } = null!; + + [Parameter] + public WaterHeatingBill Content { get; set; } = null!; + + [Inject] + private IWaterHeatingBillRepository waterHeatingBillRepository { get; set; } = null!; + + [Inject] + private IDialogService dialogService { get; set; } = null!; + + protected override void OnInitialized() + { + periodFrom = Content.PeriodFrom == default ? null : Content.PeriodFrom.ToDateTime(TimeOnly.MinValue); + periodTo = Content.PeriodTo == default ? null : Content.PeriodTo.ToDateTime(TimeOnly.MinValue); + editContext = new EditContext(Content); + } + + private async Task SaveAsync() + { + if (periodFrom is null || periodTo is null) + { + return; + } + Content.PeriodFrom = DateOnly.FromDateTime(periodFrom.Value); + Content.PeriodTo = DateOnly.FromDateTime(periodTo.Value); + Content.CalculateCosts(); + if (editContext.Validate()) + { + await waterHeatingBillRepository.SaveWaterHeatingBillAsync(Content); + await Dialog.CloseAsync(Content); + } + } + + private async Task CancelAsync() + { + await Dialog.CancelAsync(); + } + + private async Task ShowGuideAsync() + { + await dialogService.ShowDialogAsync(GuideImage, new DialogParameters() + { + Width = "680px", + Title = "Woher kommen die Werte?", + PreventDismissOnOverlayClick = true, + PreventScroll = true, + }); + } + + private static string M3(decimal value) => value.ToString("#,0.00", SwissNumbers) + " m³"; + + private static string Mwh(decimal value) => value.ToString("#,0.000", SwissNumbers) + " MWh"; + + private static string Chf(decimal value) => value.ToString("#,0.00", SwissNumbers) + " CHF"; + + private static CultureInfo CreateSwissNumbers() + { + var culture = new CultureInfo("de-CH"); + culture.NumberFormat.NumberGroupSeparator = "'"; + return culture; + } +} diff --git a/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor new file mode 100644 index 0000000..399d877 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor @@ -0,0 +1,61 @@ +@page "/water-heating" +@rendermode InteractiveServer +@using Schaad.Accounting.UI.Components.Pages.Analytics + +Wasser & Heizung + +
+ + Neue Abrechnung hinzufügen + + + @if (source.Count == 0) + { + Noch keine Abrechnungen erfasst. + } + else + { + + +
+ +
Wasserverbrauch @PerPeriod
+ +
+ +
Wärmeverbrauch @PerPeriod
+ +
+
+ + +
Kosten @PerPeriod
+ +
+ } + +
+ + + + + + + + + + + + + + + + + + + +
+
diff --git a/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs new file mode 100644 index 0000000..b3cd5b0 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs @@ -0,0 +1,164 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.FluentUI.AspNetCore.Components; +using Schaad.Accounting.Interfaces; +using Schaad.Accounting.Models; +using Schaad.Accounting.UI.Components.Pages.Charts; +using Schaad.Accounting.UI.Components.Pages.Controls; +using Schaad.Accounting.UI.Components.Pages.Dialogs; + +namespace Schaad.Accounting.UI.Components.Pages; + +/// +/// NeoVac water and heating bills, laid out like the Wasser page (), which holds +/// the bills with the CHF values entered directly: the bills are stored once per mandator, not per +/// calendar year (see ). Grid for entering/editing, plus +/// charts per bill, calendar year or half-year over a year range (see +/// and ): warm/cold water and heat consumption, and the costs split into +/// water base costs, cold/warm water and heating for warm water and the rooms. +/// +public partial class WaterHeating : ComponentBase +{ + [Inject] + private IWaterHeatingBillRepository waterHeatingBillRepository { get; set; } = null!; + + [Inject] + private IDialogService dialogService { get; set; } = null!; + + [Inject] + private IToastService toastService { get; set; } = null!; + + private IReadOnlyList source = []; + + private BillChartFilter filter = new(); + + // Years any bill touches, for the year range of the charts. + private List years = []; + + // True if a bill had to be spread over several periods of the selected kind. + private bool isSplit; + + private object waterData = new(); + private object heatData = new(); + private object costData = new(); + + protected override async Task OnInitializedAsync() + { + await LoadAsync(); + } + + private async Task LoadAsync() + { + source = (await waterHeatingBillRepository.GetWaterHeatingBillListAsync()) + .OrderBy(b => b.PeriodFrom) + .ToList(); + years = BillChartFilter.YearsOf(source); + BuildCharts(); + } + + private void OnFilterChanged(BillChartFilter value) + { + filter = value; + BuildCharts(); + } + + private void BuildCharts() + { + // A bill reaching over several periods is spread evenly over its months. + var periods = filter.Apply(source); + isSplit = periods.Any(p => p.IsSplit); + var labels = periods.Select(p => p.Label).ToList(); + // Cold water blue, warm water orange. + waterData = new + { + labels, + series = new object[] + { + new { name = "Warmwasser", color = ChartTheme.ColorAt(1), values = periods.Select(p => p.Bill?.WarmWaterM3).ToList(), clickable = false }, + new { name = "Kaltwasser", color = ChartTheme.ColorAt(0), values = periods.Select(p => p.Bill?.ColdWaterM3).ToList(), clickable = false } + }, + unit = "m³" + }; + heatData = new + { + labels, + series = new object[] + { + new { name = "Wärme", color = ChartTheme.ColorAt(7), values = periods.Select(p => p.Bill?.HeatingMwh).ToList(), clickable = false } + }, + unit = "MWh", + // A few MWh per year: whole-number ticks would repeat the same value. + axisDecimals = 1 + }; + // Water parts first, then the heating parts (warm water, rooms). + costData = new + { + labels, + series = new object[] + { + new { name = "Grundkosten Wasser", color = ChartTheme.ColorAt(2), values = periods.Select(p => p.Bill?.BaseCostsChf).ToList(), clickable = false }, + new { name = "Kaltwasser", color = ChartTheme.ColorAt(0), values = periods.Select(p => p.Bill?.ColdWaterChf).ToList(), clickable = false }, + new { name = "Warmwasser", color = ChartTheme.ColorAt(1), values = periods.Select(p => p.Bill?.WarmWaterChf).ToList(), clickable = false }, + new { name = "Heizung Warmwasser", color = ChartTheme.ColorAt(3), values = periods.Select(p => p.Bill?.WarmWaterHeatingChf).ToList(), clickable = false }, + new { name = "Heizung Räume", color = ChartTheme.ColorAt(7), values = periods.Select(p => p.Bill?.RoomHeatingChf).ToList(), clickable = false } + }, + unit = "CHF" + }; + } + + private async Task AddAsync() + { + var data = new WaterHeatingBill(); + var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() + { + Width = "560px", + Height = "640px", + Title = "Abrechnung hinzufügen", + PreventDismissOnOverlayClick = true, + PreventScroll = true, + }); + + var result = await dialog.Result; + if (!result.Cancelled && result.Data != null) + { + await LoadAsync(); + toastService.ShowToast(ToastIntent.Success, "Abrechnung gespeichert", 3000); + } + } + + private async Task EditAsync(string id) + { + var data = await waterHeatingBillRepository.GetWaterHeatingBillAsync(id); + var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() + { + Width = "560px", + Height = "640px", + Title = "Abrechnung bearbeiten", + PreventDismissOnOverlayClick = true, + PreventScroll = true, + }); + + var result = await dialog.Result; + if (!result.Cancelled && result.Data != null) + { + await LoadAsync(); + toastService.ShowToast(ToastIntent.Success, "Abrechnung gespeichert", 3000); + } + } + + private async Task DeleteAsync(string id) + { + var bill = source.First(b => b.Id == id); + var dialog = await dialogService.ShowConfirmationAsync($"Abrechnung {FullLabel(bill)} wirklich löschen?", "Ja", "Nein", "Abrechnung löschen"); + var result = await dialog.Result; + if (!result.Cancelled) + { + await waterHeatingBillRepository.DeleteWaterHeatingBillAsync(id); + await LoadAsync(); + toastService.ShowToast(ToastIntent.Success, "Abrechnung gelöscht", 3000); + } + } + + private string PerPeriod => BillChartToolbar.PerPeriod(filter.Kind); + + private static string FullLabel(WaterHeatingBill bill) => $"{bill.PeriodFrom:dd.MM.yyyy} – {bill.PeriodTo:dd.MM.yyyy}"; +} diff --git a/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.css b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.css new file mode 100644 index 0000000..cccd2d3 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.css @@ -0,0 +1,32 @@ +.water-heating { + display: flex; + flex-direction: column; + gap: 16px; +} + +.table-scroll { + overflow-x: auto; +} + +.pair { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); + gap: 12px; +} + +@media (max-width: 1100px) { + .pair { + grid-template-columns: minmax(0, 1fr); + } +} + +::deep .chart-card { + padding: 16px; + min-width: 0; +} + +.card-title { + font-weight: 600; + font-size: 15px; + margin-bottom: 12px; +} diff --git a/Schaad.Accounting.UI/Extensions.cs b/Schaad.Accounting.UI/Extensions.cs index 2ccc383..990d94b 100644 --- a/Schaad.Accounting.UI/Extensions.cs +++ b/Schaad.Accounting.UI/Extensions.cs @@ -23,6 +23,7 @@ namespace Schaad.Accounting.UI services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg b/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg new file mode 100644 index 0000000..a4740aa --- /dev/null +++ b/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg @@ -0,0 +1,74 @@ + + Beispiel-Abrechnung: Wo stehen die Werte? + + + + Beispiel: Wo stehen die Werte auf der Abrechnung? + Platzhalterwerte – der Aufbau entspricht der NeoVac-Abrechnung und der Aufstellung der Verwaltung. + + NEOVAC – ABLESEQUITTUNG, SPALTE „VERBRAUCH VERRECHNET“ + + Abrechnungsperiode + + 01.07.2025 – 30.06.2026 + → Von / Bis + + Wasser – WAZ Pic. (WW) + + 15.000 + → Warmwasser (m³) + + Wasser – WAZ Pic. (KW) + + 45.000 + → Kaltwasser (m³) + + Wärme – Total Wärme (MWh) + + 2.400 + → Wärme (MWh) + Den Verbrauch übernehmen, nicht „Stand neu“ – das ist der Zählerstand. + + NEOVAC – WASSERKOSTEN / WÄRMEKOSTEN, SPALTE „ANTEIL (‰)“ + + Wasser – Grundkosten + + 20.00 + → Wasser Grund (‰) + + Wasser – Verbrauchskosten + + 70.00 + → Wasser Verbrauch (‰) + + Wärmekostenanteil (Gesamt) + + 60.00 + → Heizung total (‰) + + Warmwasser (Gesamt) + + 12.00 + → Heizung WW (‰) + + VERWALTUNG – AUFSTELLUNG, IHR ANTEIL IN CHF + + Wasserkosten + + 300.00 + → Wasserkosten (CHF) + + Heizkosten + + 450.00 + → Heizkosten (CHF) + Die Promille der Verwaltung entsprechen Grund + Verbrauch bzw. dem Wärmekostenanteil. + + + Grundkosten 300.00 × 20 / 90 + 66.67 + Verbrauch 233.33, davon 15 von 60 m³ warm + Warmwasser 58.33 · Kaltwasser 175.00 + Heizung Warmwasser 450.00 × 12 / 60 + Heizung Warmwasser 90.00 · Räume 360.00 + -- 2.39.5 From a58f08e82a7830e3fd1b6a210353a5a9d66a0482 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sun, 1 Nov 2026 19:33:21 +0100 Subject: [PATCH 2/5] Wasser & Heizung: plausibility checks in the bill dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dialog shows a "Kontrolle" section (WaterHeatingBillChecks): the NeoVac per-mille shares against the optional ones of the property manager, optional meter readings continuing from the previous bill, the property totals implied by the own share, and the prices per unit compared with the previous bill (flagged above ±25 %). Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- .../Models/WaterHeatingBill.cs | 26 ++- .../Models/WaterHeatingBillChecks.cs | 141 ++++++++++++++++ .../WaterHeatingBillChecksTestShould.cs | 151 ++++++++++++++++++ .../Dialogs/WaterHeatingBillDialog.razor | 56 +++++-- .../Dialogs/WaterHeatingBillDialog.razor.cs | 26 ++- .../Components/Pages/WaterHeating.razor.cs | 8 +- .../images/water-heating-bill-guide.svg | 29 ++-- 8 files changed, 405 insertions(+), 34 deletions(-) create mode 100644 Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs create mode 100644 Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs diff --git a/CLAUDE.md b/CLAUDE.md index c0e70ea..866c75b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -67,7 +67,7 @@ When a new year is opened, the previous year's data is copied as the starting po - **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, 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` -- **Wasser & Heizung** page (`WaterHeating`, `/water-heating`, under "Charts" in the menu) — same layout for NeoVac bills where only per-mille shares are known, over `IWaterHeatingBillRepository`'s `WaterHeatingBill` records: consumption (warm/cold m³, heat MWh) and ‰ shares from NeoVac, own water/heating costs in CHF from the property manager's statement; `WaterHeatingBillDialog` calls `CalculateCosts`, which stores the CHF parts (water split into base/consumption by ‰, consumption split by m³, warm water part of the heating), so `AddShare` can sum them per period; `RoomHeatingChf` is the rest of the heating. Three charts (stacked m³, MWh, stacked CHF) and a guide image (`water-heating-bill-guide.svg`) +- **Wasser & Heizung** page (`WaterHeating`, `/water-heating`, under "Charts" in the menu) — same layout for NeoVac bills where only per-mille shares are known, over `IWaterHeatingBillRepository`'s `WaterHeatingBill` records: consumption (warm/cold m³, heat MWh) and ‰ shares from NeoVac, own water/heating costs in CHF from the property manager's statement; `WaterHeatingBillDialog` calls `CalculateCosts`, which stores the CHF parts (water split into base/consumption by ‰, consumption split by m³, warm water part of the heating), so `AddShare` can sum them per period; `RoomHeatingChf` is the rest of the heating. The dialog shows plausibility checks from `WaterHeatingBillChecks` (NeoVac ‰ vs. the optional ‰ of the property manager, optional meter readings continuing from the previous bill, implied property totals, prices per unit vs. the previous bill, flagged above ±25 %). Three charts (stacked m³, MWh, stacked CHF) and a guide image (`water-heating-bill-guide.svg`) ### UI structure diff --git a/Schaad.Accounting.Common/Models/WaterHeatingBill.cs b/Schaad.Accounting.Common/Models/WaterHeatingBill.cs index 2c10008..656f0ad 100644 --- a/Schaad.Accounting.Common/Models/WaterHeatingBill.cs +++ b/Schaad.Accounting.Common/Models/WaterHeatingBill.cs @@ -35,6 +35,18 @@ namespace Schaad.Accounting.Models [Display(Name = "Wärme")] public decimal HeatingMwh { get; set; } + // Optional meter readings ("Stand neu"), only for the checks (see WaterHeatingBillChecks): + // the previous bill's reading plus this consumption must give this reading. + + [Display(Name = "Zählerstand Warmwasser")] + public decimal? WarmWaterMeter { get; set; } + + [Display(Name = "Zählerstand Kaltwasser")] + public decimal? ColdWaterMeter { get; set; } + + [Display(Name = "Zählerstand Wärme")] + public decimal? HeatingMeter { get; set; } + // NeoVac per-mille shares of the property, column "Anteil (‰)". [Display(Name = "Wasser Grundkosten-Anteil")] @@ -59,6 +71,15 @@ namespace Schaad.Accounting.Models [Display(Name = "Heizkosten")] public decimal HeatingCostsChf { get; set; } + // Optional per-mille shares as listed by the property manager, only for the checks: they + // must match the NeoVac ones. + + [Display(Name = "Wasser-Anteil Verwaltung")] + public decimal? ManagerWaterPermille { get; set; } + + [Display(Name = "Heizungs-Anteil Verwaltung")] + public decimal? ManagerHeatingPermille { get; set; } + // Calculated by CalculateCosts. [Display(Name = "Grundkosten Wasser")] @@ -111,7 +132,10 @@ namespace Schaad.Accounting.Models private static decimal Round(decimal value) => Math.Round(value, 2, MidpointRounding.AwayFromZero); - /// Adds up consumption and CHF values; the per-mille shares don't add up and are left out. + /// + /// Adds up consumption and CHF values; the per-mille shares and meter readings don't add up + /// and are left out. + /// public void AddShare(WaterHeatingBill other, decimal share) { WarmWaterM3 += other.WarmWaterM3 * share; diff --git a/Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs b/Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs new file mode 100644 index 0000000..e38a557 --- /dev/null +++ b/Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace Schaad.Accounting.Models +{ + public enum BillCheckResult + { + /// A value to compare by hand with the statements. + Info, + Ok, + Warning + } + + public record BillCheck(BillCheckResult Result, string Text); + + /// + /// Plausibility checks for a , shown in its dialog: the NeoVac and + /// property manager's per-mille shares must match, the meter readings must continue from the + /// previous bill, and the prices per unit shouldn't jump. Checks whose optional inputs are + /// missing are left out. + /// + public static class WaterHeatingBillChecks + { + /// Price changes against the previous bill above this share are flagged. + public const decimal MaxPriceChange = 0.25m; + + private const decimal PermilleTolerance = 0.005m; + private const decimal MeterTolerance = 0.0005m; + + private static readonly CultureInfo SwissNumbers = CreateSwissNumbers(); + + /// The bill that ended last before started, if any. + public static WaterHeatingBill PreviousOf(IEnumerable bills, WaterHeatingBill bill) + => bills.Where(b => b.Id != bill.Id && b.PeriodTo < bill.PeriodFrom).MaxBy(b => b.PeriodTo); + + public static IReadOnlyList Check(WaterHeatingBill bill, WaterHeatingBill previous) + { + var checks = new List(); + + var waterPermille = bill.WaterBasePermille + bill.WaterConsumptionPermille; + if (bill.ManagerWaterPermille is decimal managerWater) + { + checks.Add(new BillCheck( + Result(Math.Abs(waterPermille - managerWater) < PermilleTolerance), + $"Wasser: NeoVac {N(bill.WaterBasePermille)} + {N(bill.WaterConsumptionPermille)} = {N(waterPermille)} ‰, Verwaltung {N(managerWater)} ‰")); + } + if (bill.ManagerHeatingPermille is decimal managerHeating) + { + checks.Add(new BillCheck( + Result(Math.Abs(bill.HeatingPermille - managerHeating) < PermilleTolerance), + $"Heizung: NeoVac {N(bill.HeatingPermille)} ‰, Verwaltung {N(managerHeating)} ‰")); + } + if (bill.WarmWaterHeatingPermille > bill.HeatingPermille) + { + checks.Add(new BillCheck(BillCheckResult.Warning, + $"Heizung WW {N(bill.WarmWaterHeatingPermille)} ‰ ist grösser als Heizung total {N(bill.HeatingPermille)} ‰")); + } + + AddMeterCheck(checks, "Warmwasser", bill.WarmWaterMeter, bill.WarmWaterM3, previous?.WarmWaterMeter); + AddMeterCheck(checks, "Kaltwasser", bill.ColdWaterMeter, bill.ColdWaterM3, previous?.ColdWaterMeter); + AddMeterCheck(checks, "Wärme", bill.HeatingMeter, bill.HeatingMwh, previous?.HeatingMeter); + + // The own share divided by the per-mille share gives the costs of the whole property, + // which are on the property manager's statement. + if (waterPermille != 0 && bill.HeatingPermille != 0) + { + checks.Add(new BillCheck(BillCheckResult.Info, + $"Liegenschaft: Wasserkosten {N(bill.WaterCostsChf * 1000 / waterPermille)} CHF, Heizkosten {N(bill.HeatingCostsChf * 1000 / bill.HeatingPermille)} CHF")); + } + + AddPriceCheck(checks, "Wasser", "CHF/m³", WaterPrice(bill), previous is null ? null : WaterPrice(previous)); + AddPriceCheck(checks, "Heizung Warmwasser", "CHF/m³", WarmWaterHeatingPrice(bill), previous is null ? null : WarmWaterHeatingPrice(previous)); + AddPriceCheck(checks, "Heizung Räume", "CHF/MWh", RoomHeatingPrice(bill), previous is null ? null : RoomHeatingPrice(previous)); + + return checks; + } + + private static void AddMeterCheck(List checks, string name, decimal? reading, decimal consumption, decimal? previousReading) + { + if (reading is not decimal now) + { + return; + } + if (previousReading is decimal before) + { + var expected = before + consumption; + var ok = Math.Abs(expected - now) < MeterTolerance; + checks.Add(new BillCheck(Result(ok), + $"Zähler {name}: {M(before)} (Vorperiode) + {M(consumption)} = {M(expected)}" + (ok ? "" : $", Stand neu ist {M(now)}"))); + } + else + { + checks.Add(new BillCheck(BillCheckResult.Info, + $"Zähler {name}: Stand alt = {M(now)} − {M(consumption)} = {M(now - consumption)}")); + } + } + + private static void AddPriceCheck(List checks, string name, string unit, decimal? price, decimal? previousPrice) + { + if (price is not decimal now) + { + return; + } + if (previousPrice is decimal before && before != 0) + { + var change = now / before - 1; + checks.Add(new BillCheck(Result(Math.Abs(change) <= MaxPriceChange), + $"{name}: {N(now)} {unit} (Vorperiode {N(before)}, {change.ToString("+0%;−0%;0%", SwissNumbers)})")); + } + else + { + checks.Add(new BillCheck(BillCheckResult.Info, $"{name}: {N(now)} {unit}")); + } + } + + /// Water consumption costs (without base costs) per m³. + private static decimal? WaterPrice(WaterHeatingBill bill) + => bill.TotalM3 == 0 ? null : (bill.WarmWaterChf + bill.ColdWaterChf) / bill.TotalM3; + + private static decimal? WarmWaterHeatingPrice(WaterHeatingBill bill) + => bill.WarmWaterM3 == 0 ? null : bill.WarmWaterHeatingChf / bill.WarmWaterM3; + + private static decimal? RoomHeatingPrice(WaterHeatingBill bill) + => bill.HeatingMwh == 0 ? null : bill.RoomHeatingChf / bill.HeatingMwh; + + private static BillCheckResult Result(bool ok) => ok ? BillCheckResult.Ok : BillCheckResult.Warning; + + private static string N(decimal value) => value.ToString("#,0.00", SwissNumbers); + + private static string M(decimal value) => value.ToString("#,0.000", SwissNumbers); + + private static CultureInfo CreateSwissNumbers() + { + var culture = new CultureInfo("de-CH"); + culture.NumberFormat.NumberGroupSeparator = "'"; + return culture; + } + } +} diff --git a/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs b/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs new file mode 100644 index 0000000..7f77ecc --- /dev/null +++ b/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs @@ -0,0 +1,151 @@ +using Schaad.Accounting.Models; +using Shouldly; + +namespace Schaad.Accounting.Tests; + +public class WaterHeatingBillChecksTestShould +{ + // Values of the 2024/25 bill: NeoVac per-mille shares and the own share from the property manager. + private static WaterHeatingBill Bill() + { + var bill = new WaterHeatingBill + { + Id = "b2025", + PeriodFrom = new DateOnly(2024, 7, 1), + PeriodTo = new DateOnly(2025, 6, 30), + WarmWaterM3 = 16.399m, + ColdWaterM3 = 51.464m, + HeatingMwh = 2.458m, + WaterBasePermille = 19.52m, + WaterConsumptionPermille = 68.50m, + HeatingPermille = 62.82m, + WarmWaterHeatingPermille = 12.66m, + WaterCostsChf = 304.30m, + HeatingCostsChf = 451.65m + }; + bill.CalculateCosts(); + return bill; + } + + [Fact] + public void PassWhenNeoVacPermilleMatchesPropertyManager() + { + var bill = Bill(); + bill.ManagerWaterPermille = 88.02m; + bill.ManagerHeatingPermille = 62.82m; + + var checks = WaterHeatingBillChecks.Check(bill, null); + + checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text.StartsWith("Wasser: NeoVac 19.52 + 68.50 = 88.02 ‰")); + checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text.StartsWith("Heizung: NeoVac 62.82 ‰")); + } + + [Fact] + public void WarnWhenNeoVacPermilleDiffersFromPropertyManager() + { + var bill = Bill(); + bill.ManagerWaterPermille = 88.20m; + + var checks = WaterHeatingBillChecks.Check(bill, null); + + checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Wasser: NeoVac")); + } + + [Fact] + public void LeaveOutPermilleChecksWhenPropertyManagerValuesAreMissing() + { + var checks = WaterHeatingBillChecks.Check(Bill(), null); + + checks.ShouldNotContain(c => c.Text.StartsWith("Wasser: NeoVac") || c.Text.StartsWith("Heizung: NeoVac")); + } + + [Fact] + public void WarnWhenWarmWaterHeatingPermilleIsAboveHeatingPermille() + { + var bill = Bill(); + bill.WarmWaterHeatingPermille = 70m; + + var checks = WaterHeatingBillChecks.Check(bill, null); + + checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Heizung WW 70.00 ‰")); + } + + [Fact] + public void PassWhenMeterContinuesFromPreviousBill() + { + var previous = Bill(); + previous.WarmWaterMeter = 134.151m; + var bill = Bill(); + bill.WarmWaterMeter = 150.550m; + + var checks = WaterHeatingBillChecks.Check(bill, previous); + + checks.ShouldContain(new BillCheck(BillCheckResult.Ok, "Zähler Warmwasser: 134.151 (Vorperiode) + 16.399 = 150.550")); + } + + [Fact] + public void WarnWhenMeterDoesNotContinueFromPreviousBill() + { + var previous = Bill(); + previous.ColdWaterMeter = 333.273m; + var bill = Bill(); + bill.ColdWaterMeter = 384.740m; + + var checks = WaterHeatingBillChecks.Check(bill, previous); + + checks.ShouldContain(new BillCheck(BillCheckResult.Warning, "Zähler Kaltwasser: 333.273 (Vorperiode) + 51.464 = 384.737, Stand neu ist 384.740")); + } + + [Fact] + public void ShowOldMeterReadingWhenThereIsNoPreviousReading() + { + var bill = Bill(); + bill.HeatingMeter = 21.575m; + + var checks = WaterHeatingBillChecks.Check(bill, null); + + checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Zähler Wärme: Stand alt = 21.575 − 2.458 = 19.117")); + } + + [Fact] + public void ShowPropertyCostsDerivedFromOwnShare() + { + var checks = WaterHeatingBillChecks.Check(Bill(), null); + + checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Liegenschaft: Wasserkosten 3'457.17 CHF, Heizkosten 7'189.59 CHF")); + } + + [Fact] + public void ShowPricesPerUnitWhenThereIsNoPreviousBill() + { + var checks = WaterHeatingBillChecks.Check(Bill(), null); + + checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Wasser: 3.49 CHF/m³")); + checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Heizung Warmwasser: 5.55 CHF/m³")); + checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Heizung Räume: 146.72 CHF/MWh")); + } + + [Fact] + public void WarnWhenPriceChangesMoreThanAllowedAgainstPreviousBill() + { + var previous = Bill(); + previous.HeatingCostsChf = 300m; + previous.CalculateCosts(); + + var checks = WaterHeatingBillChecks.Check(Bill(), previous); + + checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Heizung Räume: 146.72 CHF/MWh (Vorperiode")); + checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text == "Wasser: 3.49 CHF/m³ (Vorperiode 3.49, 0%)"); + } + + [Fact] + public void PickBillThatEndedLastBeforeThisOneAsPrevious() + { + var bill = Bill(); + var older = new WaterHeatingBill { Id = "a", PeriodFrom = new DateOnly(2022, 7, 1), PeriodTo = new DateOnly(2023, 6, 30) }; + var last = new WaterHeatingBill { Id = "b", PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) }; + var later = new WaterHeatingBill { Id = "c", PeriodFrom = new DateOnly(2025, 7, 1), PeriodTo = new DateOnly(2026, 6, 30) }; + + WaterHeatingBillChecks.PreviousOf([later, older, bill, last], bill).ShouldBeSameAs(last); + } +} diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor index a25a43c..2fa7254 100644 --- a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor @@ -1,5 +1,6 @@ @implements IDialogContentComponent @rendermode InteractiveServer +@using Schaad.Accounting.Models @@ -14,33 +15,40 @@ - - + + -
NeoVac – Ablesequittung (Verbrauch verrechnet)
+
NeoVac – Ablesequittung
- - + + + - + + +
NeoVac – Anteil (‰)
- - + + - - + + -
Verwaltung – Ihr Anteil (CHF)
+
Verwaltung – Ihr Anteil
- - + + + + + +
@@ -60,6 +68,12 @@ Total @M3(Content.TotalM3) · @Mwh(Content.HeatingMwh) · @Chf(Content.TotalChf)
+
Kontrolle
+ @foreach (var check in Checks) + { +
@CheckSymbol(check.Result) @check.Text
+ } + Woher kommen die Werte? (NeoVac-Abrechnung) @@ -78,7 +92,7 @@ @code { - private const string SectionStyle = "margin-top: 14px; font-size: 11px; font-weight: bold; color: #898781; text-transform: uppercase;"; + private const string SectionStyle = "margin-top: 14px; margin-bottom: 4px; font-size: 11px; font-weight: bold; color: #898781; text-transform: uppercase;"; // Shown in its own dialog (see ShowGuideAsync) instead of expanding inline: this dialog has a // fixed Height, and FluentDialogBody doesn't resize to fit growing content. @@ -86,4 +100,18 @@ @Beispiel-Abrechnung mit Markierungen, welcher Wert in welches Feld gehört; + + private static string CheckSymbol(BillCheckResult result) => result switch + { + BillCheckResult.Ok => "✓", + BillCheckResult.Warning => "⚠", + _ => "·" + }; + + private static string CheckColor(BillCheckResult result) => result switch + { + BillCheckResult.Ok => "#1a7f37", + BillCheckResult.Warning => "#c4314b", + _ => "#52514e" + }; } diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs index 977c101..9142356 100644 --- a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs @@ -9,7 +9,8 @@ namespace Schaad.Accounting.UI.Components.Pages.Dialogs; /// /// NeoVac water and heating bill: consumption and per-mille shares from NeoVac, own costs from the -/// property manager's statement; the CHF parts are calculated (see ). +/// property manager's statement; the CHF parts are calculated (see ) +/// and checked (see ). /// public partial class WaterHeatingBillDialog : ComponentBase { @@ -21,6 +22,9 @@ public partial class WaterHeatingBillDialog : ComponentBase private DateTime? periodFrom; private DateTime? periodTo; + // The other bills, to find the previous one for the checks (meter readings, prices). + private List bills = []; + [CascadingParameter] public FluentDialog Dialog { get; set; } = null!; @@ -33,13 +37,31 @@ public partial class WaterHeatingBillDialog : ComponentBase [Inject] private IDialogService dialogService { get; set; } = null!; - protected override void OnInitialized() + protected override async Task OnInitializedAsync() { + bills = await waterHeatingBillRepository.GetWaterHeatingBillListAsync(); periodFrom = Content.PeriodFrom == default ? null : Content.PeriodFrom.ToDateTime(TimeOnly.MinValue); periodTo = Content.PeriodTo == default ? null : Content.PeriodTo.ToDateTime(TimeOnly.MinValue); editContext = new EditContext(Content); } + private IReadOnlyList Checks + => WaterHeatingBillChecks.Check(Content, WaterHeatingBillChecks.PreviousOf(bills, Content)); + + // Keeps the period on the bill up to date while editing, so the checks find the right + // previous bill. + private void SyncPeriod() + { + if (periodFrom is not null) + { + Content.PeriodFrom = DateOnly.FromDateTime(periodFrom.Value); + } + if (periodTo is not null) + { + Content.PeriodTo = DateOnly.FromDateTime(periodTo.Value); + } + } + private async Task SaveAsync() { if (periodFrom is null || periodTo is null) diff --git a/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs index b3cd5b0..08f00f4 100644 --- a/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs @@ -110,8 +110,8 @@ public partial class WaterHeating : ComponentBase var data = new WaterHeatingBill(); var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() { - Width = "560px", - Height = "640px", + Width = "760px", + Height = "880px", Title = "Abrechnung hinzufügen", PreventDismissOnOverlayClick = true, PreventScroll = true, @@ -130,8 +130,8 @@ public partial class WaterHeating : ComponentBase var data = await waterHeatingBillRepository.GetWaterHeatingBillAsync(id); var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() { - Width = "560px", - Height = "640px", + Width = "760px", + Height = "880px", Title = "Abrechnung bearbeiten", PreventDismissOnOverlayClick = true, PreventScroll = true, diff --git a/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg b/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg index a4740aa..f1e4259 100644 --- a/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg +++ b/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg @@ -1,7 +1,7 @@ - + Beispiel-Abrechnung: Wo stehen die Werte? - + Beispiel: Wo stehen die Werte auf der Abrechnung? Platzhalterwerte – der Aufbau entspricht der NeoVac-Abrechnung und der Aufstellung der Verwaltung. @@ -27,7 +27,7 @@ 2.400 → Wärme (MWh) - Den Verbrauch übernehmen, nicht „Stand neu“ – das ist der Zählerstand. + „Stand neu“ ist der Zählerstand: optional in „Stand neu …“ für die Kontrolle, nicht als Verbrauch. NEOVAC – WASSERKOSTEN / WÄRMEKOSTEN, SPALTE „ANTEIL (‰)“ @@ -51,7 +51,7 @@ 12.00 → Heizung WW (‰) - VERWALTUNG – AUFSTELLUNG, IHR ANTEIL IN CHF + VERWALTUNG – AUFSTELLUNG, IHR ANTEIL Wasserkosten @@ -62,13 +62,18 @@ 450.00 → Heizkosten (CHF) - Die Promille der Verwaltung entsprechen Grund + Verbrauch bzw. dem Wärmekostenanteil. - + + Promille Wasser / Heizung + + 90.000 / 60.000 + → Wasser / Heizung (‰, optional) + Die Kontrolle vergleicht sie mit Grund + Verbrauch bzw. dem Wärmekostenanteil von NeoVac. + - Grundkosten 300.00 × 20 / 90 - 66.67 - Verbrauch 233.33, davon 15 von 60 m³ warm - Warmwasser 58.33 · Kaltwasser 175.00 - Heizung Warmwasser 450.00 × 12 / 60 - Heizung Warmwasser 90.00 · Räume 360.00 + Grundkosten 300.00 × 20 / 90 + 66.67 + Verbrauch 233.33, davon 15 von 60 m³ warm + Warmwasser 58.33 · Kaltwasser 175.00 + Heizung Warmwasser 450.00 × 12 / 60 + Heizung Warmwasser 90.00 · Räume 360.00 -- 2.39.5 From 9a4f9a9010ea33643f6a9b5505f5cd4a2ef4b313 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sun, 1 Nov 2026 19:36:39 +0100 Subject: [PATCH 3/5] Wasser & Heizung: remove the optional meter readings The "Stand neu" fields for warm water, cold water and heat and their continuity checks are gone; the per-mille, property total and price checks stay. The "Kontrolle" heading is only shown when there is a check. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- .../Models/WaterHeatingBill.cs | 17 +-------- .../Models/WaterHeatingBillChecks.cs | 32 +--------------- .../WaterHeatingBillChecksTestShould.cs | 37 ------------------- .../Dialogs/WaterHeatingBillDialog.razor | 14 +++---- .../Dialogs/WaterHeatingBillDialog.razor.cs | 2 +- .../Components/Pages/WaterHeating.razor.cs | 4 +- .../images/water-heating-bill-guide.svg | 2 +- 8 files changed, 14 insertions(+), 96 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 866c75b..91baef4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -67,7 +67,7 @@ When a new year is opened, the previous year's data is copied as the starting po - **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, 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` -- **Wasser & Heizung** page (`WaterHeating`, `/water-heating`, under "Charts" in the menu) — same layout for NeoVac bills where only per-mille shares are known, over `IWaterHeatingBillRepository`'s `WaterHeatingBill` records: consumption (warm/cold m³, heat MWh) and ‰ shares from NeoVac, own water/heating costs in CHF from the property manager's statement; `WaterHeatingBillDialog` calls `CalculateCosts`, which stores the CHF parts (water split into base/consumption by ‰, consumption split by m³, warm water part of the heating), so `AddShare` can sum them per period; `RoomHeatingChf` is the rest of the heating. The dialog shows plausibility checks from `WaterHeatingBillChecks` (NeoVac ‰ vs. the optional ‰ of the property manager, optional meter readings continuing from the previous bill, implied property totals, prices per unit vs. the previous bill, flagged above ±25 %). Three charts (stacked m³, MWh, stacked CHF) and a guide image (`water-heating-bill-guide.svg`) +- **Wasser & Heizung** page (`WaterHeating`, `/water-heating`, under "Charts" in the menu) — same layout for NeoVac bills where only per-mille shares are known, over `IWaterHeatingBillRepository`'s `WaterHeatingBill` records: consumption (warm/cold m³, heat MWh) and ‰ shares from NeoVac, own water/heating costs in CHF from the property manager's statement; `WaterHeatingBillDialog` calls `CalculateCosts`, which stores the CHF parts (water split into base/consumption by ‰, consumption split by m³, warm water part of the heating), so `AddShare` can sum them per period; `RoomHeatingChf` is the rest of the heating. The dialog shows plausibility checks from `WaterHeatingBillChecks` (NeoVac ‰ vs. the optional ‰ of the property manager, implied property totals, prices per unit vs. the previous bill, flagged above ±25 %). Three charts (stacked m³, MWh, stacked CHF) and a guide image (`water-heating-bill-guide.svg`) ### UI structure diff --git a/Schaad.Accounting.Common/Models/WaterHeatingBill.cs b/Schaad.Accounting.Common/Models/WaterHeatingBill.cs index 656f0ad..f3703fb 100644 --- a/Schaad.Accounting.Common/Models/WaterHeatingBill.cs +++ b/Schaad.Accounting.Common/Models/WaterHeatingBill.cs @@ -35,18 +35,6 @@ namespace Schaad.Accounting.Models [Display(Name = "Wärme")] public decimal HeatingMwh { get; set; } - // Optional meter readings ("Stand neu"), only for the checks (see WaterHeatingBillChecks): - // the previous bill's reading plus this consumption must give this reading. - - [Display(Name = "Zählerstand Warmwasser")] - public decimal? WarmWaterMeter { get; set; } - - [Display(Name = "Zählerstand Kaltwasser")] - public decimal? ColdWaterMeter { get; set; } - - [Display(Name = "Zählerstand Wärme")] - public decimal? HeatingMeter { get; set; } - // NeoVac per-mille shares of the property, column "Anteil (‰)". [Display(Name = "Wasser Grundkosten-Anteil")] @@ -132,10 +120,7 @@ namespace Schaad.Accounting.Models private static decimal Round(decimal value) => Math.Round(value, 2, MidpointRounding.AwayFromZero); - /// - /// Adds up consumption and CHF values; the per-mille shares and meter readings don't add up - /// and are left out. - /// + /// Adds up consumption and CHF values; the per-mille shares don't add up and are left out. public void AddShare(WaterHeatingBill other, decimal share) { WarmWaterM3 += other.WarmWaterM3 * share; diff --git a/Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs b/Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs index e38a557..e5a0bfe 100644 --- a/Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs +++ b/Schaad.Accounting.Common/Models/WaterHeatingBillChecks.cs @@ -17,9 +17,8 @@ namespace Schaad.Accounting.Models /// /// Plausibility checks for a , shown in its dialog: the NeoVac and - /// property manager's per-mille shares must match, the meter readings must continue from the - /// previous bill, and the prices per unit shouldn't jump. Checks whose optional inputs are - /// missing are left out. + /// property manager's per-mille shares must match, and the prices per unit shouldn't jump + /// against the previous bill. Checks whose optional inputs are missing are left out. /// public static class WaterHeatingBillChecks { @@ -27,7 +26,6 @@ namespace Schaad.Accounting.Models public const decimal MaxPriceChange = 0.25m; private const decimal PermilleTolerance = 0.005m; - private const decimal MeterTolerance = 0.0005m; private static readonly CultureInfo SwissNumbers = CreateSwissNumbers(); @@ -58,10 +56,6 @@ namespace Schaad.Accounting.Models $"Heizung WW {N(bill.WarmWaterHeatingPermille)} ‰ ist grösser als Heizung total {N(bill.HeatingPermille)} ‰")); } - AddMeterCheck(checks, "Warmwasser", bill.WarmWaterMeter, bill.WarmWaterM3, previous?.WarmWaterMeter); - AddMeterCheck(checks, "Kaltwasser", bill.ColdWaterMeter, bill.ColdWaterM3, previous?.ColdWaterMeter); - AddMeterCheck(checks, "Wärme", bill.HeatingMeter, bill.HeatingMwh, previous?.HeatingMeter); - // The own share divided by the per-mille share gives the costs of the whole property, // which are on the property manager's statement. if (waterPermille != 0 && bill.HeatingPermille != 0) @@ -77,26 +71,6 @@ namespace Schaad.Accounting.Models return checks; } - private static void AddMeterCheck(List checks, string name, decimal? reading, decimal consumption, decimal? previousReading) - { - if (reading is not decimal now) - { - return; - } - if (previousReading is decimal before) - { - var expected = before + consumption; - var ok = Math.Abs(expected - now) < MeterTolerance; - checks.Add(new BillCheck(Result(ok), - $"Zähler {name}: {M(before)} (Vorperiode) + {M(consumption)} = {M(expected)}" + (ok ? "" : $", Stand neu ist {M(now)}"))); - } - else - { - checks.Add(new BillCheck(BillCheckResult.Info, - $"Zähler {name}: Stand alt = {M(now)} − {M(consumption)} = {M(now - consumption)}")); - } - } - private static void AddPriceCheck(List checks, string name, string unit, decimal? price, decimal? previousPrice) { if (price is not decimal now) @@ -129,8 +103,6 @@ namespace Schaad.Accounting.Models private static string N(decimal value) => value.ToString("#,0.00", SwissNumbers); - private static string M(decimal value) => value.ToString("#,0.000", SwissNumbers); - private static CultureInfo CreateSwissNumbers() { var culture = new CultureInfo("de-CH"); diff --git a/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs b/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs index 7f77ecc..42f6d11 100644 --- a/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs +++ b/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs @@ -70,43 +70,6 @@ public class WaterHeatingBillChecksTestShould checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Heizung WW 70.00 ‰")); } - [Fact] - public void PassWhenMeterContinuesFromPreviousBill() - { - var previous = Bill(); - previous.WarmWaterMeter = 134.151m; - var bill = Bill(); - bill.WarmWaterMeter = 150.550m; - - var checks = WaterHeatingBillChecks.Check(bill, previous); - - checks.ShouldContain(new BillCheck(BillCheckResult.Ok, "Zähler Warmwasser: 134.151 (Vorperiode) + 16.399 = 150.550")); - } - - [Fact] - public void WarnWhenMeterDoesNotContinueFromPreviousBill() - { - var previous = Bill(); - previous.ColdWaterMeter = 333.273m; - var bill = Bill(); - bill.ColdWaterMeter = 384.740m; - - var checks = WaterHeatingBillChecks.Check(bill, previous); - - checks.ShouldContain(new BillCheck(BillCheckResult.Warning, "Zähler Kaltwasser: 333.273 (Vorperiode) + 51.464 = 384.737, Stand neu ist 384.740")); - } - - [Fact] - public void ShowOldMeterReadingWhenThereIsNoPreviousReading() - { - var bill = Bill(); - bill.HeatingMeter = 21.575m; - - var checks = WaterHeatingBillChecks.Check(bill, null); - - checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Zähler Wärme: Stand alt = 21.575 − 2.458 = 19.117")); - } - [Fact] public void ShowPropertyCostsDerivedFromOwnShare() { diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor index 2fa7254..f64fb8b 100644 --- a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor @@ -25,11 +25,6 @@
- - - - -
NeoVac – Anteil (‰)
@@ -68,10 +63,13 @@ Total @M3(Content.TotalM3) · @Mwh(Content.HeatingMwh) · @Chf(Content.TotalChf) -
Kontrolle
- @foreach (var check in Checks) + @if (Checks is { Count: > 0 } checks) { -
@CheckSymbol(check.Result) @check.Text
+
Kontrolle
+ @foreach (var check in checks) + { +
@CheckSymbol(check.Result) @check.Text
+ } } diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs index 9142356..2d05871 100644 --- a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs @@ -22,7 +22,7 @@ public partial class WaterHeatingBillDialog : ComponentBase private DateTime? periodFrom; private DateTime? periodTo; - // The other bills, to find the previous one for the checks (meter readings, prices). + // The other bills, to find the previous one for the price checks. private List bills = []; [CascadingParameter] diff --git a/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs index 08f00f4..25eba78 100644 --- a/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/WaterHeating.razor.cs @@ -111,7 +111,7 @@ public partial class WaterHeating : ComponentBase var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() { Width = "760px", - Height = "880px", + Height = "820px", Title = "Abrechnung hinzufügen", PreventDismissOnOverlayClick = true, PreventScroll = true, @@ -131,7 +131,7 @@ public partial class WaterHeating : ComponentBase var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() { Width = "760px", - Height = "880px", + Height = "820px", Title = "Abrechnung bearbeiten", PreventDismissOnOverlayClick = true, PreventScroll = true, diff --git a/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg b/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg index f1e4259..7892abe 100644 --- a/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg +++ b/Schaad.Accounting.UI/wwwroot/images/water-heating-bill-guide.svg @@ -27,7 +27,7 @@ 2.400 → Wärme (MWh) - „Stand neu“ ist der Zählerstand: optional in „Stand neu …“ für die Kontrolle, nicht als Verbrauch. + Den Verbrauch übernehmen, nicht „Stand neu“ – das ist der Zählerstand. NEOVAC – WASSERKOSTEN / WÄRMEKOSTEN, SPALTE „ANTEIL (‰)“ -- 2.39.5 From 4023db06dd93cfdf2195edcb951e4145aef75a96 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sun, 1 Nov 2026 19:38:37 +0100 Subject: [PATCH 4/5] Wasser & Heizung: put the heat field on its own line in the dialog Co-Authored-By: Claude Opus 5.5 --- .../Components/Pages/Dialogs/WaterHeatingBillDialog.razor | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor index f64fb8b..5ad8318 100644 --- a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor @@ -23,6 +23,8 @@ + + -- 2.39.5 From 24dc89d5fb251c5ee5481daf65ab4cd72e5b2d30 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sun, 1 Nov 2026 19:40:32 +0100 Subject: [PATCH 5/5] Wasser & Heizung: align labels and inputs in the dialog Fields sit in a two-column grid with a fixed label width, so labels and inputs line up across all sections. Co-Authored-By: Claude Opus 5.5 --- .../Dialogs/WaterHeatingBillDialog.razor | 48 ++++++++----------- .../Dialogs/WaterHeatingBillDialog.razor.css | 26 ++++++++++ 2 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.css diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor index 5ad8318..a76c893 100644 --- a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor @@ -14,39 +14,33 @@ - - - - +
+
+
+
NeoVac – Ablesequittung
- - - - - - - +
+
+
+
+
NeoVac – Anteil (‰)
- - - - - - - - +
+
+
+
+
+
Verwaltung – Ihr Anteil
- - - - - - - - +
+
+
+
+
+
diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.css b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.css new file mode 100644 index 0000000..3153dc1 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.css @@ -0,0 +1,26 @@ +/* Two columns of fields; each field is a fixed-width label left of an input that fills the rest, + so labels and inputs line up across rows and sections. */ +.fields { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); + column-gap: 24px; + row-gap: 8px; +} + +.field { + display: flex; + align-items: center; + gap: 8px; +} + +.field ::deep .fluent-input-label { + flex: 0 0 140px; + margin: 0; +} + +.field ::deep fluent-number-field, +.field ::deep fluent-text-field { + flex: 1 1 auto; + min-width: 0; + width: auto; +} -- 2.39.5