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 +