From 7d7bd6073c87227baa1468e4ebc2f6194f105fd3 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Sun, 25 Oct 2026 20:30:40 +0100 Subject: [PATCH 1/6] Add "Strom" page for the yearly NeoVac electricity bill A new page (/electricity) to record one electricity bill per billing period (1 July-30 June) with a grid, add/edit dialog, and two Chart.js charts (kWh split grid/PV per period, CHF/kWh as a line). - ElectricityBill (Common): Grid/PV kWh and CHF, side costs, advance payment; computed TotalKwh, PvShare, TotalChf, Balance, ChfPerKwh. - Stored once per mandator at {DataPath}/{mandator}/electricity.json instead of per year, since the billing period doesn't align with calendar years (new ISettingsService.GetMandatorPath(), BaseRepository gets a directory-aware SaveAsync overload). - electricity.json is also editable through the JSON editor (RawDataRepository). - charts.js: stackedBar/line charts can now show a unit other than CHF (defaults to CHF, so the Analyse page is unaffected). - The add/edit dialog links to an annotated example (SVG, placeholder data) showing which value on the real NeoVac bill goes into which field; opens in its own dialog since the main dialog has a fixed height. - Tests for the computed properties and the new repositories. Also bumps the TargetFramework to net10.0 and updates the local DataPath in appsettings.Development.json. Co-Authored-By: Claude Sonnet 5 --- CLAUDE.md | 6 +- Directory.Build.props | 2 +- .../Interfaces/IElectricityBillRepository.cs | 17 +++ .../Interfaces/ISettingsService.cs | 6 + .../Models/ElectricityBill.cs | 67 +++++++++ .../Repositories/BaseRepository.cs | 11 +- .../Repositories/ElectricityBillRepository.cs | 56 +++++++ .../Repositories/RawDataRepository.cs | 14 +- Schaad.Accounting.Services/SettingsService.cs | 5 + .../ElectricityBillRepositoryTestShould.cs | 94 ++++++++++++ .../ElectricityBillTestShould.cs | 72 +++++++++ .../RawDataRepositoryTestShould.cs | 23 ++- .../SettingsServiceTestShould.cs | 6 + .../Components/Layout/NavMenu.razor | 1 + .../Pages/Dialogs/ElectricityBillDialog.razor | 66 +++++++++ .../Dialogs/ElectricityBillDialog.razor.cs | 78 ++++++++++ .../Components/Pages/Electricity.razor | 57 ++++++++ .../Components/Pages/Electricity.razor.cs | 138 ++++++++++++++++++ .../Components/Pages/Electricity.razor.css | 40 +++++ Schaad.Accounting.UI/Extensions.cs | 1 + .../appsettings.Development.json | 4 +- .../wwwroot/images/electricity-bill-guide.svg | 61 ++++++++ Schaad.Accounting.UI/wwwroot/js/charts.js | 21 +-- 23 files changed, 826 insertions(+), 20 deletions(-) create mode 100644 Schaad.Accounting.Common/Interfaces/IElectricityBillRepository.cs create mode 100644 Schaad.Accounting.Common/Models/ElectricityBill.cs create mode 100644 Schaad.Accounting.Db/Repositories/ElectricityBillRepository.cs create mode 100644 Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs create mode 100644 Schaad.Accounting.Tests/ElectricityBillTestShould.cs create mode 100644 Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor create mode 100644 Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor.cs create mode 100644 Schaad.Accounting.UI/Components/Pages/Electricity.razor create mode 100644 Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs create mode 100644 Schaad.Accounting.UI/Components/Pages/Electricity.razor.css create mode 100644 Schaad.Accounting.UI/wwwroot/images/electricity-bill-guide.svg diff --git a/CLAUDE.md b/CLAUDE.md index 5349be2..c25b8da 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -46,21 +46,25 @@ 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}/uploads/{mandator}/{year}/ imported bank statements (+ creditCard/) {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` is the one data file 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 - **ViewService** — aggregates account balances, applies FX rates, builds datasets for the UI - **FileService** — imports bank statements (MT940, CAMT053 via external `Schaad.Finance.dll`), parses PDFs, 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}/` +- **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` 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`) — grid and dialog (FluentDataGrid/`ElectricityBillDialog`) over `IElectricityBillRepository`'s `ElectricityBill` records (one yearly NeoVac bill each: kWh/CHF for grid and PV, side costs, advance payment; `TotalKwh`, `PvShare`, `TotalChf`, `Balance`, `ChfPerKwh` are computed); two Chart.js charts via `ChartJsChart` (stacked kWh per period, CHF/kWh line) ### UI structure diff --git a/Directory.Build.props b/Directory.Build.props index 67b2324..020f2b0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - net9.0 + net10.0 diff --git a/Schaad.Accounting.Common/Interfaces/IElectricityBillRepository.cs b/Schaad.Accounting.Common/Interfaces/IElectricityBillRepository.cs new file mode 100644 index 0000000..1b54b39 --- /dev/null +++ b/Schaad.Accounting.Common/Interfaces/IElectricityBillRepository.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Schaad.Accounting.Models; + +namespace Schaad.Accounting.Interfaces +{ + public interface IElectricityBillRepository + { + Task> GetElectricityBillListAsync(); + + Task SaveElectricityBillAsync(ElectricityBill bill); + + Task GetElectricityBillAsync(string id); + + Task DeleteElectricityBillAsync(string id); + } +} diff --git a/Schaad.Accounting.Common/Interfaces/ISettingsService.cs b/Schaad.Accounting.Common/Interfaces/ISettingsService.cs index 4e6c279..ec1f6d8 100644 --- a/Schaad.Accounting.Common/Interfaces/ISettingsService.cs +++ b/Schaad.Accounting.Common/Interfaces/ISettingsService.cs @@ -26,6 +26,12 @@ namespace Schaad.Accounting.Interfaces string GetLastYearDbPath(); + /// + /// The mandator's folder, above the per-year folders. For data that is not kept per + /// year (e.g. the electricity bills, whose period doesn't align with calendar years). + /// + string GetMandatorPath(); + SettingsDataset GetSettings(); } } \ No newline at end of file diff --git a/Schaad.Accounting.Common/Models/ElectricityBill.cs b/Schaad.Accounting.Common/Models/ElectricityBill.cs new file mode 100644 index 0000000..6311756 --- /dev/null +++ b/Schaad.Accounting.Common/Models/ElectricityBill.cs @@ -0,0 +1,67 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; + +namespace Schaad.Accounting.Models +{ + /// + /// One yearly NeoVac electricity bill for the apartment. The billing period runs + /// 1 July – 30 June, so these are not stored per calendar year like the other data files + /// (see ElectricityBillRepository in Schaad.Accounting.Db). + /// + public class ElectricityBill + { + public string Id { get; set; } + + [Display(Name = "Von")] + [Required] + public DateOnly PeriodFrom { get; set; } + + [Display(Name = "Bis")] + [Required] + public DateOnly PeriodTo { get; set; } + + [Display(Name = "Netzbezug")] + public decimal GridKwh { get; set; } + + [Display(Name = "PV-Produktion")] + public decimal PvKwh { get; set; } + + [Display(Name = "Netzbezug")] + public decimal GridChf { get; set; } + + [Display(Name = "PV")] + public decimal PvChf { get; set; } + + [Display(Name = "Nebenkosten")] + public decimal SideCostsChf { get; set; } + + [Display(Name = "Akonto")] + public decimal AdvanceChf { get; set; } + + /// Grid draw plus own PV consumption, in kWh. + [JsonIgnore] + [Display(Name = "Total")] + public decimal TotalKwh => GridKwh + PvKwh; + + /// Share of the consumption covered by PV, 0..1. + [JsonIgnore] + [Display(Name = "PV-Anteil")] + public decimal PvShare => TotalKwh == 0 ? 0 : PvKwh / TotalKwh; + + /// Grid, PV and side costs added up, before the advance payment. + [JsonIgnore] + [Display(Name = "Total")] + public decimal TotalChf => GridChf + PvChf + SideCostsChf; + + /// What is still owed (positive) or was overpaid (negative) after the advance. + [JsonIgnore] + [Display(Name = "Saldo")] + public decimal Balance => TotalChf - AdvanceChf; + + /// Average price per kWh over the whole period. + [JsonIgnore] + [Display(Name = "CHF/kWh")] + public decimal ChfPerKwh => TotalKwh == 0 ? 0 : TotalChf / TotalKwh; + } +} diff --git a/Schaad.Accounting.Db/Repositories/BaseRepository.cs b/Schaad.Accounting.Db/Repositories/BaseRepository.cs index 019424a..843788b 100644 --- a/Schaad.Accounting.Db/Repositories/BaseRepository.cs +++ b/Schaad.Accounting.Db/Repositories/BaseRepository.cs @@ -78,9 +78,16 @@ namespace Schaad.Accounting.Repositories /// renames it, so a crash mid-write leaves the previous file intact. Invalidates /// the corresponding cache entry. /// - protected async Task SaveAsync(T obj, string fileName) + protected Task SaveAsync(T obj, string fileName) + => SaveAsync(obj, settingsService.GetDbPath(), fileName); + + /// + /// Same as for a file in any data directory (e.g. + /// the mandator's folder instead of a year below it). + /// + protected async Task SaveAsync(T obj, string directory, string fileName) { - var filePath = Path.Combine(settingsService.GetDbPath(), fileName); + var filePath = Path.Combine(directory, fileName); var tmpPath = filePath + ".tmp"; var semaphore = GetLock(filePath); diff --git a/Schaad.Accounting.Db/Repositories/ElectricityBillRepository.cs b/Schaad.Accounting.Db/Repositories/ElectricityBillRepository.cs new file mode 100644 index 0000000..620d43a --- /dev/null +++ b/Schaad.Accounting.Db/Repositories/ElectricityBillRepository.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 +{ + /// + /// Electricity bills of the current mandator, stored once per mandator (not per year like + /// the other data files) because the billing period runs 1 July – 30 June. + /// + public class ElectricityBillRepository : BaseRepository, IElectricityBillRepository + { + private const string ELECTRICITY = "electricity.json"; + + public ElectricityBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger logger) + : base(settingsService, cache, logger) + { + } + + public Task> GetElectricityBillListAsync() + => LoadListAsync(settingsService.GetMandatorPath(), ELECTRICITY); + + public async Task SaveElectricityBillAsync(ElectricityBill bill) + { + var bills = await GetElectricityBillListAsync(); + 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(), ELECTRICITY); + } + + public async Task GetElectricityBillAsync(string id) + { + var bills = await GetElectricityBillListAsync(); + return bills.FirstOrDefault(b => b.Id == id); + } + + public async Task DeleteElectricityBillAsync(string id) + { + var bills = await GetElectricityBillListAsync(); + bills.RemoveAll(b => b.Id == id); + await SaveAsync(bills, settingsService.GetMandatorPath(), ELECTRICITY); + } + } +} diff --git a/Schaad.Accounting.Db/Repositories/RawDataRepository.cs b/Schaad.Accounting.Db/Repositories/RawDataRepository.cs index 1cf4713..fa85658 100644 --- a/Schaad.Accounting.Db/Repositories/RawDataRepository.cs +++ b/Schaad.Accounting.Db/Repositories/RawDataRepository.cs @@ -25,6 +25,7 @@ namespace Schaad.Accounting.Repositories { private const string ACCOUNTS = "Accounts.json"; private const string TRANSACTIONS = "Transactions.json"; + private const string ELECTRICITY = "electricity.json"; private const int MaxErrors = 20; // Like the normal options, but property names that don't exist (typos) are errors instead @@ -47,7 +48,8 @@ namespace Schaad.Accounting.Repositories "BookingRules.json", "BookingTexts.json", "SplitPredefinitions.json", - "SubClasses.json" + "SubClasses.json", + ELECTRICITY ]; public async Task LoadAsync(string fileName) @@ -66,6 +68,7 @@ namespace Schaad.Accounting.Repositories "BookingTexts.json" => SaveAsync(fileName, text, loadedHash), "SplitPredefinitions.json" => SaveAsync(fileName, text, loadedHash), "SubClasses.json" => SaveAsync(fileName, text, loadedHash), + ELECTRICITY => SaveAsync(fileName, text, loadedHash), _ => throw new ArgumentException($"Unknown data file '{fileName}'", nameof(fileName)) }; @@ -106,7 +109,7 @@ namespace Schaad.Accounting.Repositories } var backupPath = await BackupAsync(current); - await SaveAsync(items, fileName); + await SaveAsync(items, DirectoryOf(fileName), fileName); logger.LogInformation("Saved {FilePath} from the JSON editor; previous version in {BackupPath}", current.Path, backupPath); return new RawDataSaveResult([], await LoadAsync(fileName), backupPath); @@ -233,9 +236,14 @@ namespace Schaad.Accounting.Repositories { throw new ArgumentException($"Unknown data file '{fileName}'", nameof(fileName)); } - return Path.Combine(settingsService.GetDbPath(), fileName); + return Path.Combine(DirectoryOf(fileName), fileName); } + // electricity.json lives at the mandator level, not per year (its period runs 1 July – + // 30 June, so it doesn't align with calendar years). + private string DirectoryOf(string fileName) + => fileName == ELECTRICITY ? settingsService.GetMandatorPath() : settingsService.GetDbPath(); + private static string Hash(byte[] bytes) => Convert.ToHexString(SHA256.HashData(bytes)); private static string Describe(JsonException ex) diff --git a/Schaad.Accounting.Services/SettingsService.cs b/Schaad.Accounting.Services/SettingsService.cs index 82f3a3e..2157691 100644 --- a/Schaad.Accounting.Services/SettingsService.cs +++ b/Schaad.Accounting.Services/SettingsService.cs @@ -94,6 +94,11 @@ namespace Schaad.Accounting.Services return EnsureDirectory(Path.Combine(GetSettings().DataPath, mandator, (year - 1).ToString())); } + public string GetMandatorPath() + { + return EnsureDirectory(Path.Combine(GetSettings().DataPath, mandator)); + } + public SettingsDataset GetSettings() { return settingsDataset; diff --git a/Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs b/Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs new file mode 100644 index 0000000..3b2e687 --- /dev/null +++ b/Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs @@ -0,0 +1,94 @@ +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 ElectricityBillRepositoryTestShould : IDisposable +{ + private readonly string mandatorDir; + private readonly ISettingsService settingsService; + private readonly ElectricityBillRepository sut; + + public ElectricityBillRepositoryTestShould() + { + mandatorDir = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(mandatorDir); + + settingsService = Substitute.For(); + settingsService.GetMandatorPath().Returns(mandatorDir); + + sut = new ElectricityBillRepository(settingsService, new RepositoryCache(), NullLogger.Instance); + } + + public void Dispose() + { + if (Directory.Exists(mandatorDir)) + { + Directory.Delete(mandatorDir, recursive: true); + } + } + + [Fact] + public async Task ReturnEmptyListWhenFileDoesNotExistYet() + { + (await sut.GetElectricityBillListAsync()).ShouldBeEmpty(); + } + + [Fact] + public async Task AssignNewIdWhenSavingBillWithoutId() + { + var bill = new ElectricityBill + { + PeriodFrom = new DateOnly(2023, 7, 1), + PeriodTo = new DateOnly(2024, 6, 30), + GridKwh = 3419.432m, + PvKwh = 1936.328m, + GridChf = 1009.55m, + PvChf = 544.10m, + SideCostsChf = 134.30m, + AdvanceChf = 1212.00m + }; + + await sut.SaveElectricityBillAsync(bill); + + var stored = (await sut.GetElectricityBillListAsync()).Single(); + stored.Id.ShouldNotBeNullOrEmpty(); + stored.Balance.ShouldBe(475.95m); + } + + [Fact] + public async Task UpdateInPlaceWhenSavingBillWithExistingId() + { + await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), AdvanceChf = 1000m }); + var id = (await sut.GetElectricityBillListAsync()).Single().Id; + + await sut.SaveElectricityBillAsync(new ElectricityBill { Id = id, PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), AdvanceChf = 1300m }); + + var bills = await sut.GetElectricityBillListAsync(); + bills.Count.ShouldBe(1); + bills[0].AdvanceChf.ShouldBe(1300m); + } + + [Fact] + public async Task RemoveBillWhenDeletingById() + { + await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) }); + var id = (await sut.GetElectricityBillListAsync()).Single().Id; + + await sut.DeleteElectricityBillAsync(id); + + (await sut.GetElectricityBillListAsync()).ShouldBeEmpty(); + } + + [Fact] + public async Task StoreFileDirectlyInMandatorFolderWithoutYearSubfolder() + { + await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) }); + + File.Exists(Path.Combine(mandatorDir, "electricity.json")).ShouldBeTrue(); + } +} diff --git a/Schaad.Accounting.Tests/ElectricityBillTestShould.cs b/Schaad.Accounting.Tests/ElectricityBillTestShould.cs new file mode 100644 index 0000000..b335ea9 --- /dev/null +++ b/Schaad.Accounting.Tests/ElectricityBillTestShould.cs @@ -0,0 +1,72 @@ +using Schaad.Accounting.Models; +using Shouldly; + +namespace Schaad.Accounting.Tests; + +public class ElectricityBillTestShould +{ + [Fact] + public void AddGridAndPvWhenCalculatingTotalKwh() + { + var bill = new ElectricityBill { GridKwh = 3419.432m, PvKwh = 1936.328m }; + + bill.TotalKwh.ShouldBe(5355.76m); + } + + [Fact] + public void DividePvByTotalWhenCalculatingPvShare() + { + var bill = new ElectricityBill { GridKwh = 600m, PvKwh = 400m }; + + bill.PvShare.ShouldBe(0.4m); + } + + [Fact] + public void ReturnZeroPvShareWhenThereIsNoConsumption() + { + var bill = new ElectricityBill { GridKwh = 0m, PvKwh = 0m }; + + bill.PvShare.ShouldBe(0m); + } + + [Fact] + public void AddGridPvAndSideCostsWhenCalculatingTotalChf() + { + var bill = new ElectricityBill { GridChf = 1009.55m, PvChf = 544.10m, SideCostsChf = 134.30m }; + + bill.TotalChf.ShouldBe(1687.95m); + } + + [Fact] + public void CalculateBalanceWhenAdvanceIsSubtractedFromTotal() + { + var bill = new ElectricityBill + { + GridKwh = 3419.432m, + PvKwh = 1936.328m, + GridChf = 1009.55m, + PvChf = 544.10m, + SideCostsChf = 134.30m, + AdvanceChf = 1212.00m + }; + + bill.TotalChf.ShouldBe(1687.95m); + bill.Balance.ShouldBe(475.95m); + } + + [Fact] + public void DivideTotalChfByTotalKwhWhenCalculatingChfPerKwh() + { + var bill = new ElectricityBill { GridKwh = 600m, PvKwh = 400m, GridChf = 60m, PvChf = 40m }; + + bill.ChfPerKwh.ShouldBe(0.1m); + } + + [Fact] + public void ReturnZeroChfPerKwhWhenThereIsNoConsumption() + { + var bill = new ElectricityBill { GridKwh = 0m, PvKwh = 0m, GridChf = 0m, PvChf = 0m, SideCostsChf = 50m }; + + bill.ChfPerKwh.ShouldBe(0m); + } +} diff --git a/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs b/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs index 2e917ac..6df8a7f 100644 --- a/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs +++ b/Schaad.Accounting.Tests/RawDataRepositoryTestShould.cs @@ -24,6 +24,7 @@ public class RawDataRepositoryTestShould : IDisposable private readonly string dataPath; private readonly string dbDir; + private readonly string mandatorDir; private readonly RepositoryCache cache = new(); private readonly ISettingsService settingsService; private readonly RawDataRepository sut; @@ -31,7 +32,8 @@ public class RawDataRepositoryTestShould : IDisposable public RawDataRepositoryTestShould() { dataPath = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N")); - dbDir = Path.Combine(dataPath, "Mandator", "2026"); + mandatorDir = Path.Combine(dataPath, "Mandator"); + dbDir = Path.Combine(mandatorDir, "2026"); Directory.CreateDirectory(dbDir); File.WriteAllText(Path.Combine(dbDir, "Accounts.json"), Accounts); File.WriteAllText(Path.Combine(dbDir, "Transactions.json"), Transactions); @@ -39,6 +41,7 @@ public class RawDataRepositoryTestShould : IDisposable settingsService = Substitute.For(); settingsService.GetDbPath().Returns(dbDir); settingsService.GetLastYearDbPath().Returns(Path.Combine(dataPath, "no-such-dir")); + settingsService.GetMandatorPath().Returns(mandatorDir); settingsService.GetSettings().Returns(new SettingsDataset { DataPath = dataPath }); settingsService.GetMandator().Returns("Mandator"); settingsService.GetYear().Returns(2026); @@ -169,6 +172,24 @@ public class RawDataRepositoryTestShould : IDisposable File.ReadAllText(Path.Combine(dbDir, "Transactions.json")).ShouldContain("13"); } + [Fact] + public async Task ReadAndWriteElectricityFileInMandatorFolderNotYearFolderWhenEditing() + { + File.WriteAllText(Path.Combine(mandatorDir, "electricity.json"), """ + [ { "Id": "e1", "PeriodFrom": "2023-07-01", "PeriodTo": "2024-06-30", "GridKwh": 100 } ] + """); + var loaded = await sut.LoadAsync("electricity.json"); + loaded.Text.ShouldContain("\"GridKwh\": 100"); + + var result = await sut.SaveAsync("electricity.json", loaded.Text.Replace("100", "150"), loaded.Hash); + + result.Errors.ShouldBeEmpty(); + result.Saved.ShouldBeTrue(); + File.Exists(Path.Combine(mandatorDir, "electricity.json")).ShouldBeTrue(); + File.ReadAllText(Path.Combine(mandatorDir, "electricity.json")).ShouldContain("150"); + File.Exists(Path.Combine(dbDir, "electricity.json")).ShouldBeFalse(); + } + [Fact] public async Task RejectUnknownFileNameWhenLoading() { diff --git a/Schaad.Accounting.Tests/SettingsServiceTestShould.cs b/Schaad.Accounting.Tests/SettingsServiceTestShould.cs index 568e348..f4fc335 100644 --- a/Schaad.Accounting.Tests/SettingsServiceTestShould.cs +++ b/Schaad.Accounting.Tests/SettingsServiceTestShould.cs @@ -33,6 +33,12 @@ public class SettingsServiceTestShould : IDisposable sut.GetLastYearDbPath().ShouldBe(Path.Combine(dataPath, "Mandator", "2024")); } + [Fact] + public void ReturnMandatorFolderWithoutYearWhenGettingMandatorPath() + { + sut.GetMandatorPath().ShouldBe(Path.Combine(dataPath, "Mandator")); + } + [Fact] public void ReturnFoldersBelowRootUploadsWhenGettingUploadPaths() { diff --git a/Schaad.Accounting.UI/Components/Layout/NavMenu.razor b/Schaad.Accounting.UI/Components/Layout/NavMenu.razor index 7bda4bb..6696f58 100644 --- a/Schaad.Accounting.UI/Components/Layout/NavMenu.razor +++ b/Schaad.Accounting.UI/Components/Layout/NavMenu.razor @@ -9,6 +9,7 @@ Home Transaktionen Bank Transaktionen + Strom Buchungsregeln Buchungstexte diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor b/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor new file mode 100644 index 0000000..20dbb4d --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor @@ -0,0 +1,66 @@ +@implements IDialogContentComponent +@rendermode InteractiveServer + + + + + + @Dialog.Instance.Parameters.Title + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ Total @Chf(Content.TotalChf), Akonto @Chf(Content.AdvanceChf) → Saldo @Chf(Content.Balance) + (@(Content.Balance >= 0 ? "Nachzahlung" : "Gutschrift")) +
+ + + Woher kommen die Werte? (NeoVac-Abrechnung) + +
+ + + + Abbrechen + + + Speichern + + + +@code { + // 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/ElectricityBillDialog.razor.cs b/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor.cs new file mode 100644 index 0000000..6ec5410 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor.cs @@ -0,0 +1,78 @@ +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; + +public partial class ElectricityBillDialog : ComponentBase +{ + private static readonly CultureInfo SwissNumbers = CreateSwissNumbers(); + + private EditContext editContext = null!; + + // FluentDatePicker needs DateTime?; the model stores DateOnly (see ElectricityBill). + private DateTime? periodFrom; + private DateTime? periodTo; + + [CascadingParameter] + public FluentDialog Dialog { get; set; } = null!; + + [Parameter] + public ElectricityBill Content { get; set; } = null!; + + [Inject] + private IElectricityBillRepository electricityBillRepository { 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); + if (editContext.Validate()) + { + await electricityBillRepository.SaveElectricityBillAsync(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 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/Electricity.razor b/Schaad.Accounting.UI/Components/Pages/Electricity.razor new file mode 100644 index 0000000..3f49484 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor @@ -0,0 +1,57 @@ +@page "/electricity" +@rendermode InteractiveServer +@using Schaad.Accounting.UI.Components.Pages.Analytics + +Strom + +
+ + Neue Abrechnung hinzufügen + + +
+ + + + + + + + + + + + + + @Chf(context.Balance) + + + + + + + + + +
+ + @if (source.Count == 0) + { + Noch keine Abrechnungen erfasst. + } + else + { +
+ +
Verbrauch pro Periode
+ +
+ +
Preis pro kWh
+ +
+
+ } +
diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs new file mode 100644 index 0000000..479ff26 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs @@ -0,0 +1,138 @@ +using System.Globalization; +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.Dialogs; + +namespace Schaad.Accounting.UI.Components.Pages; + +/// +/// Yearly NeoVac electricity bills for the apartment (billing period 1 July – 30 June, so the +/// bills are stored once per mandator, not per calendar year; see +/// ). Grid for entering/editing, plus two charts: +/// consumption split grid/PV per period, and the resulting price per kWh. +/// +public partial class Electricity : ComponentBase +{ + private static readonly CultureInfo SwissNumbers = CreateSwissNumbers(); + + [Inject] + private IElectricityBillRepository electricityBillRepository { get; set; } = null!; + + [Inject] + private IDialogService dialogService { get; set; } = null!; + + [Inject] + private IToastService toastService { get; set; } = null!; + + private IReadOnlyList source = []; + + private object barData = new(); + private object lineData = new(); + + protected override async Task OnInitializedAsync() + { + await LoadAsync(); + } + + private async Task LoadAsync() + { + source = (await electricityBillRepository.GetElectricityBillListAsync()) + .OrderBy(b => b.PeriodFrom) + .ToList(); + BuildCharts(); + } + + private void BuildCharts() + { + var labels = source.Select(ChartLabel).ToList(); + barData = new + { + labels, + series = new object[] + { + new { name = "Netz", color = ChartTheme.ColorAt(0), values = source.Select(b => b.GridKwh).ToList(), clickable = false }, + new { name = "PV", color = ChartTheme.ColorAt(1), values = source.Select(b => b.PvKwh).ToList(), clickable = false } + }, + unit = "kWh" + }; + lineData = new + { + labels, + series = new object[] + { + new { name = "CHF/kWh", color = ChartTheme.ColorAt(0), values = source.Select(b => b.ChfPerKwh).ToList(), width = 2 } + }, + unit = "CHF/kWh" + }; + } + + private async Task AddAsync() + { + var data = new ElectricityBill(); + var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() + { + Width = "560px", + Height = "460px", + 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 electricityBillRepository.GetElectricityBillAsync(id); + var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() + { + Width = "560px", + Height = "460px", + 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 electricityBillRepository.DeleteElectricityBillAsync(id); + await LoadAsync(); + toastService.ShowToast(ToastIntent.Success, "Abrechnung gelöscht", 3000); + } + } + + // Short label for the chart axis, e.g. "23/24". + private static string ChartLabel(ElectricityBill bill) => $"{bill.PeriodFrom:yy}/{bill.PeriodTo:yy}"; + + private static string FullLabel(ElectricityBill bill) => $"{bill.PeriodFrom:dd.MM.yyyy} – {bill.PeriodTo:dd.MM.yyyy}"; + + 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/Electricity.razor.css b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.css new file mode 100644 index 0000000..3b2b4a5 --- /dev/null +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.css @@ -0,0 +1,40 @@ +.electricity { + display: flex; + flex-direction: column; + gap: 16px; +} + +.table-scroll { + overflow-x: auto; +} + +.due { + color: #c50f1f; +} + +.credit { + color: #107c10; +} + +.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 16cc13d..697e699 100644 --- a/Schaad.Accounting.UI/Extensions.cs +++ b/Schaad.Accounting.UI/Extensions.cs @@ -21,6 +21,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/appsettings.Development.json b/Schaad.Accounting.UI/appsettings.Development.json index c513c03..5237f59 100644 --- a/Schaad.Accounting.UI/appsettings.Development.json +++ b/Schaad.Accounting.UI/appsettings.Development.json @@ -6,8 +6,8 @@ } }, "Settings": { - "DataPath": "D:\\Developer\\AccountingData\\", + "DataPath": "/home/schaad/Documents/Developer/Data/Accounting/", "FixerIoApiKey": "ee23142f1120bb1223b0e76f98abfa97", "DefaultMandator": "Claudio Schaad" } -} +} \ No newline at end of file diff --git a/Schaad.Accounting.UI/wwwroot/images/electricity-bill-guide.svg b/Schaad.Accounting.UI/wwwroot/images/electricity-bill-guide.svg new file mode 100644 index 0000000..1e3c619 --- /dev/null +++ b/Schaad.Accounting.UI/wwwroot/images/electricity-bill-guide.svg @@ -0,0 +1,61 @@ + + Beispiel-Abrechnung: Wo stehen die Werte? + + + + Beispiel: Wo stehen die Werte auf der Abrechnung? + Platzhalterwerte – der Aufbau entspricht dem Abschnitt „Ihre Abrechnung vom …“ der NeoVac-Abrechnung. + + + + + Abrechnungsperiode + + 01.07.2025 – 30.06.2026 + → Von / Bis + + + Netzstrom – Ihr Anteil + + 1'200.000 kWh + → Netzbezug (kWh) + + + Netzstrom – Betrag (CHF) + + 350.00 + → Netzbezug (CHF) + + + ZEV Photovoltaikstrom – Ihr Anteil + + 900.000 kWh + → PV-Produktion (kWh) + + + ZEV Photovoltaikstrom – Betrag (CHF) + + 250.00 + → PV (CHF) + + + ZEV Stromnebenkosten – Betrag (CHF) + + 80.00 + → Nebenkosten (CHF) + + + Akontozahlungen Strom + + -600.00 + → Akonto (CHF), ohne Minus eingeben + + + + + Stromkosten (wird berechnet) + 680.00 + + Saldo (wird berechnet) + 80.00 + diff --git a/Schaad.Accounting.UI/wwwroot/js/charts.js b/Schaad.Accounting.UI/wwwroot/js/charts.js index 6800571..0fa4ce8 100644 --- a/Schaad.Accounting.UI/wwwroot/js/charts.js +++ b/Schaad.Accounting.UI/wwwroot/js/charts.js @@ -68,12 +68,13 @@ const legend = { labels: { usePointStyle: true, pointStyle: 'rectRounded', boxWidth: 10, color: theme.muted, font: { size: 12 } } }; -const amountAxis = { +// unit defaults to CHF, so existing callers that don't pass data.unit keep their current axis. +const amountAxis = (unit = 'CHF') => ({ grid: { color: theme.grid }, border: { display: false }, - title: { display: true, text: 'CHF', color: theme.muted }, + title: { display: true, text: unit, color: theme.muted }, ticks: { color: theme.muted, callback: value => formatAxis(value) } -}; +}); const categoryAxis = { grid: { display: false }, ticks: { color: theme.muted } }; @@ -110,7 +111,7 @@ const kinds = { order: -1 }] : [])] }), - options: () => ({ + options: state => ({ interaction: { mode: 'index', intersect: false }, plugins: { legend, @@ -119,17 +120,17 @@ const kinds = { filter: item => item.parsed.y !== 0, itemSort: (a, b) => b.parsed.y - a.parsed.y, callbacks: { - label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} CHF`, + label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} ${state().unit ?? 'CHF'}`, footer: items => { const bars = items.filter(i => i.dataset.type !== 'line'); return bars.length === items.length - ? `Total: ${formatChf(bars.reduce((sum, i) => sum + i.parsed.y, 0))} CHF` + ? `Total: ${formatChf(bars.reduce((sum, i) => sum + i.parsed.y, 0))} ${state().unit ?? 'CHF'}` : ''; } } } }, - scales: { x: { ...categoryAxis, stacked: true }, y: { ...amountAxis, stacked: true } } + scales: { x: { ...categoryAxis, stacked: true }, y: { ...amountAxis(state().unit ?? 'CHF'), stacked: true } } }), hit: (chart, event) => { const hit = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false)[0]; @@ -154,7 +155,7 @@ const kinds = { spanGaps: false })) }), - options: () => ({ + options: state => ({ interaction: { mode: 'index', intersect: false }, plugins: { legend: { ...legend, labels: { ...legend.labels, pointStyle: 'line' } }, @@ -162,10 +163,10 @@ const kinds = { ...tooltip, filter: item => item.parsed.y !== null, itemSort: (a, b) => b.parsed.y - a.parsed.y, - callbacks: { label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} CHF` } + callbacks: { label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} ${state().unit ?? 'CHF'}` } } }, - scales: { x: categoryAxis, y: amountAxis } + scales: { x: categoryAxis, y: amountAxis(state().unit ?? 'CHF') } }), hit: () => null }, -- 2.39.5 From ec0bf7d6022b3c9e0a4d12c965179429a7318764 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Mon, 26 Oct 2026 16:27:17 +0100 Subject: [PATCH 2/6] Split the CHF/kWh chart by Netz/PV and fix its axis scale The price-per-kWh line only showed the blended total; add GridChfPerKwh and PvChfPerKwh (null when there was no draw/consumption of that kind, so the chart shows a gap instead of a misleading 0) and plot Netz, PV and Total as separate lines. Also fixes the y-axis: ticks used a fixed 0-decimal formatter, so CHF/kWh values (well under 1) all rounded to "0". charts.js now takes an optional data.axisDecimals (defaults to 0, so the Analyse page is unaffected); the Strom page passes 2 for its CHF/kWh chart. Co-Authored-By: Claude Sonnet 5 --- .../Models/ElectricityBill.cs | 10 ++++++ .../ElectricityBillTestShould.cs | 32 +++++++++++++++++++ .../Components/Pages/Electricity.razor | 2 +- .../Components/Pages/Electricity.razor.cs | 7 ++-- Schaad.Accounting.UI/wwwroot/js/charts.js | 24 ++++++++++---- 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Schaad.Accounting.Common/Models/ElectricityBill.cs b/Schaad.Accounting.Common/Models/ElectricityBill.cs index 6311756..fd1d8de 100644 --- a/Schaad.Accounting.Common/Models/ElectricityBill.cs +++ b/Schaad.Accounting.Common/Models/ElectricityBill.cs @@ -63,5 +63,15 @@ namespace Schaad.Accounting.Models [JsonIgnore] [Display(Name = "CHF/kWh")] public decimal ChfPerKwh => TotalKwh == 0 ? 0 : TotalChf / TotalKwh; + + /// Price per kWh of grid electricity; null if there was no grid draw. + [JsonIgnore] + [Display(Name = "CHF/kWh Netz")] + public decimal? GridChfPerKwh => GridKwh == 0 ? null : GridChf / GridKwh; + + /// Price per kWh of PV electricity; null if there was no PV consumption. + [JsonIgnore] + [Display(Name = "CHF/kWh PV")] + public decimal? PvChfPerKwh => PvKwh == 0 ? null : PvChf / PvKwh; } } diff --git a/Schaad.Accounting.Tests/ElectricityBillTestShould.cs b/Schaad.Accounting.Tests/ElectricityBillTestShould.cs index b335ea9..2119756 100644 --- a/Schaad.Accounting.Tests/ElectricityBillTestShould.cs +++ b/Schaad.Accounting.Tests/ElectricityBillTestShould.cs @@ -69,4 +69,36 @@ public class ElectricityBillTestShould bill.ChfPerKwh.ShouldBe(0m); } + + [Fact] + public void DivideGridChfByGridKwhWhenCalculatingGridChfPerKwh() + { + var bill = new ElectricityBill { GridKwh = 600m, GridChf = 180m }; + + bill.GridChfPerKwh.ShouldBe(0.3m); + } + + [Fact] + public void ReturnNullGridChfPerKwhWhenThereWasNoGridDraw() + { + var bill = new ElectricityBill { GridKwh = 0m, GridChf = 0m }; + + bill.GridChfPerKwh.ShouldBeNull(); + } + + [Fact] + public void DividePvChfByPvKwhWhenCalculatingPvChfPerKwh() + { + var bill = new ElectricityBill { PvKwh = 400m, PvChf = 100m }; + + bill.PvChfPerKwh.ShouldBe(0.25m); + } + + [Fact] + public void ReturnNullPvChfPerKwhWhenThereWasNoPvConsumption() + { + var bill = new ElectricityBill { PvKwh = 0m, PvChf = 0m }; + + bill.PvChfPerKwh.ShouldBeNull(); + } } diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor b/Schaad.Accounting.UI/Components/Pages/Electricity.razor index 3f49484..d8cfcf7 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor @@ -50,7 +50,7 @@
Preis pro kWh
+ AriaLabel="Preis pro kWh für Netz, PV und Total über die Abrechnungsperioden" />
} diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs index 479ff26..f5d799c 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs @@ -63,9 +63,12 @@ public partial class Electricity : ComponentBase labels, series = new object[] { - new { name = "CHF/kWh", color = ChartTheme.ColorAt(0), values = source.Select(b => b.ChfPerKwh).ToList(), width = 2 } + new { name = "Netz", color = ChartTheme.ColorAt(0), values = source.Select(b => b.GridChfPerKwh).ToList(), width = 2 }, + new { name = "PV", color = ChartTheme.ColorAt(1), values = source.Select(b => b.PvChfPerKwh).ToList(), width = 2 }, + new { name = "Total", color = ChartTheme.OtherColor, values = source.Select(b => (decimal?)b.ChfPerKwh).ToList(), width = 2 } }, - unit = "CHF/kWh" + unit = "CHF/kWh", + axisDecimals = 2 }; } diff --git a/Schaad.Accounting.UI/wwwroot/js/charts.js b/Schaad.Accounting.UI/wwwroot/js/charts.js index 0fa4ce8..463d12a 100644 --- a/Schaad.Accounting.UI/wwwroot/js/charts.js +++ b/Schaad.Accounting.UI/wwwroot/js/charts.js @@ -36,9 +36,18 @@ const theme = { // de-CH uses a typographic apostrophe; the rest of the app (Formatting.cs) uses a plain one. const amount = new Intl.NumberFormat('de-CH', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); -const axisAmount = new Intl.NumberFormat('de-CH', { maximumFractionDigits: 0 }); const formatChf = value => amount.format(value).replace(/’/g, "'"); -const formatAxis = value => axisAmount.format(value).replace(/’/g, "'"); + +// Axis ticks default to whole numbers (CHF amounts in the hundreds/thousands); series with small +// values (e.g. CHF/kWh, well under 1) pass data.axisDecimals to avoid every tick rounding to "0". +const axisAmountFormatters = new Map(); +function axisAmount(decimals) { + if (!axisAmountFormatters.has(decimals)) { + axisAmountFormatters.set(decimals, new Intl.NumberFormat('de-CH', { minimumFractionDigits: decimals, maximumFractionDigits: decimals })); + } + return axisAmountFormatters.get(decimals); +} +const formatAxis = (value, decimals = 0) => axisAmount(decimals).format(value).replace(/’/g, "'"); // Treemap tile helpers: level 0 tiles are parents (their group value is the parent id); level 1 // tiles keep the original tree items, which carry the parent id. @@ -68,12 +77,13 @@ const legend = { labels: { usePointStyle: true, pointStyle: 'rectRounded', boxWidth: 10, color: theme.muted, font: { size: 12 } } }; -// unit defaults to CHF, so existing callers that don't pass data.unit keep their current axis. -const amountAxis = (unit = 'CHF') => ({ +// unit/decimals default to CHF/0, so existing callers that don't pass data.unit/axisDecimals +// keep their current axis. +const amountAxis = (unit = 'CHF', decimals = 0) => ({ grid: { color: theme.grid }, border: { display: false }, title: { display: true, text: unit, color: theme.muted }, - ticks: { color: theme.muted, callback: value => formatAxis(value) } + ticks: { color: theme.muted, callback: value => formatAxis(value, decimals) } }); const categoryAxis = { grid: { display: false }, ticks: { color: theme.muted } }; @@ -130,7 +140,7 @@ const kinds = { } } }, - scales: { x: { ...categoryAxis, stacked: true }, y: { ...amountAxis(state().unit ?? 'CHF'), stacked: true } } + scales: { x: { ...categoryAxis, stacked: true }, y: { ...amountAxis(state().unit ?? 'CHF', state().axisDecimals ?? 0), stacked: true } } }), hit: (chart, event) => { const hit = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false)[0]; @@ -166,7 +176,7 @@ const kinds = { callbacks: { label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} ${state().unit ?? 'CHF'}` } } }, - scales: { x: categoryAxis, y: amountAxis(state().unit ?? 'CHF') } + scales: { x: categoryAxis, y: amountAxis(state().unit ?? 'CHF', state().axisDecimals ?? 0) } }), hit: () => null }, -- 2.39.5 From 034bc4e0f02d524729e012dd07fbd2e68c50d018 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Mon, 26 Oct 2026 16:29:32 +0100 Subject: [PATCH 3/6] Add a total-costs-per-period line chart to the Strom page A third chart below the existing pair, plotting ElectricityBill.TotalChf per period. Co-Authored-By: Claude Sonnet 5 --- .../Components/Pages/Electricity.razor | 6 ++++++ .../Components/Pages/Electricity.razor.cs | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor b/Schaad.Accounting.UI/Components/Pages/Electricity.razor index d8cfcf7..47fa361 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor @@ -53,5 +53,11 @@ AriaLabel="Preis pro kWh für Netz, PV und Total über die Abrechnungsperioden" /> + + +
Gesamtkosten pro Periode
+ +
} diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs index f5d799c..0fe2531 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs @@ -31,6 +31,7 @@ public partial class Electricity : ComponentBase private object barData = new(); private object lineData = new(); + private object costData = new(); protected override async Task OnInitializedAsync() { @@ -70,6 +71,15 @@ public partial class Electricity : ComponentBase unit = "CHF/kWh", axisDecimals = 2 }; + costData = new + { + labels, + series = new object[] + { + new { name = "Total", color = ChartTheme.ColorAt(2), values = source.Select(b => (decimal?)b.TotalChf).ToList(), width = 2 } + }, + unit = "CHF" + }; } private async Task AddAsync() -- 2.39.5 From 52870bb0896218958b28d379305b896d6f784903 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Tue, 27 Oct 2026 19:25:34 +0100 Subject: [PATCH 4/6] Show charts above the bill list on the Strom page Co-Authored-By: Claude Opus 5.5 --- .../Components/Pages/Electricity.razor | 52 +++++++++---------- .../appsettings.Development.json | 3 +- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor b/Schaad.Accounting.UI/Components/Pages/Electricity.razor index 47fa361..27abfa6 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor @@ -9,32 +9,6 @@ Neue Abrechnung hinzufügen -
- - - - - - - - - - - - - - @Chf(context.Balance) - - - - - - - - - -
- @if (source.Count == 0) { Noch keine Abrechnungen erfasst. @@ -60,4 +34,30 @@ AriaLabel="Gesamtkosten pro Abrechnungsperiode" /> } + +
+ + + + + + + + + + + + + + @Chf(context.Balance) + + + + + + + + + +
diff --git a/Schaad.Accounting.UI/appsettings.Development.json b/Schaad.Accounting.UI/appsettings.Development.json index 5237f59..1a84ea5 100644 --- a/Schaad.Accounting.UI/appsettings.Development.json +++ b/Schaad.Accounting.UI/appsettings.Development.json @@ -6,7 +6,8 @@ } }, "Settings": { - "DataPath": "/home/schaad/Documents/Developer/Data/Accounting/", + "DataPath_": "/home/schaad/Documents/Developer/Data/Accounting/", + "DataPath": "D:\\Developer\\AccountingData", "FixerIoApiKey": "ee23142f1120bb1223b0e76f98abfa97", "DefaultMandator": "Claudio Schaad" } -- 2.39.5 From df522374205ab772482fe0c1bb1566b54395c465 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Tue, 27 Oct 2026 19:28:29 +0100 Subject: [PATCH 5/6] Show the Strom charts per half-year Each bill's values are spread evenly over the months of its period and summed per calendar half-year, so a yearly July-June bill contributes half to each of its two halves. Half-years without a bill appear as gaps. Co-Authored-By: Claude Opus 5.5 --- .../Models/ElectricityHalfYear.cs | 74 +++++++++++++++++ .../ElectricityHalfYearTestShould.cs | 81 +++++++++++++++++++ .../Components/Pages/Electricity.razor | 10 +-- .../Components/Pages/Electricity.razor.cs | 23 +++--- 4 files changed, 171 insertions(+), 17 deletions(-) create mode 100644 Schaad.Accounting.Common/Models/ElectricityHalfYear.cs create mode 100644 Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs diff --git a/Schaad.Accounting.Common/Models/ElectricityHalfYear.cs b/Schaad.Accounting.Common/Models/ElectricityHalfYear.cs new file mode 100644 index 0000000..c03758c --- /dev/null +++ b/Schaad.Accounting.Common/Models/ElectricityHalfYear.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Schaad.Accounting.Models +{ + /// + /// One calendar half-year (January–June or July–December) of electricity bills, for the + /// charts on the Strom page. holds the bill values that fall into this + /// half-year, or is null if no bill covers it. + /// + public class ElectricityHalfYear + { + public DateOnly From { get; init; } + + public ElectricityBill Bill { get; init; } + + /// Short label for a chart axis, e.g. "H2 23". + public string Label => $"H{(From.Month <= 6 ? 1 : 2)} {From:yy}"; + + /// + /// Splits the bills into calendar half-years, from the first to the last covered one + /// (half-years in between that no bill covers are included with a null Bill). A bill's + /// values are spread evenly over the months of its period, so a yearly bill (1 July – + /// 30 June) contributes exactly half to each of its two half-years. + /// + public static List FromBills(IEnumerable bills) + { + var sums = new SortedDictionary(); + foreach (var bill in bills) + { + var months = MonthIndex(bill.PeriodTo) - MonthIndex(bill.PeriodFrom) + 1; + if (months <= 0) + { + continue; + } + + var monthsPerHalf = Enumerable.Range(0, months) + .Select(m => HalfYearStart(bill.PeriodFrom.AddMonths(m))) + .GroupBy(start => start); + foreach (var half in monthsPerHalf) + { + var share = (decimal)half.Count() / months; + if (!sums.TryGetValue(half.Key, out var sum)) + { + sum = new ElectricityBill { PeriodFrom = half.Key, PeriodTo = half.Key.AddMonths(6).AddDays(-1) }; + sums[half.Key] = sum; + } + sum.GridKwh += bill.GridKwh * share; + sum.PvKwh += bill.PvKwh * share; + sum.GridChf += bill.GridChf * share; + sum.PvChf += bill.PvChf * share; + sum.SideCostsChf += bill.SideCostsChf * share; + sum.AdvanceChf += bill.AdvanceChf * share; + } + } + + var result = new List(); + if (sums.Count == 0) + { + return result; + } + for (var start = sums.Keys.First(); start <= sums.Keys.Last(); start = start.AddMonths(6)) + { + result.Add(new ElectricityHalfYear { From = start, Bill = sums.GetValueOrDefault(start) }); + } + return result; + } + + private static int MonthIndex(DateOnly date) => date.Year * 12 + date.Month - 1; + + private static DateOnly HalfYearStart(DateOnly date) => new(date.Year, date.Month <= 6 ? 1 : 7, 1); + } +} diff --git a/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs b/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs new file mode 100644 index 0000000..8a8b525 --- /dev/null +++ b/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs @@ -0,0 +1,81 @@ +using Schaad.Accounting.Models; +using Shouldly; + +namespace Schaad.Accounting.Tests; + +public class ElectricityHalfYearTestShould +{ + [Fact] + public void SplitYearlyBillIntoTwoHalvesWhenPeriodRunsJulyToJune() + { + var bill = Bill(new DateOnly(2023, 7, 1), new DateOnly(2024, 6, 30)); + bill.GridKwh = 3000m; + bill.PvKwh = 2000m; + bill.GridChf = 900m; + bill.PvChf = 400m; + bill.SideCostsChf = 100m; + bill.AdvanceChf = 1200m; + + var halves = ElectricityHalfYear.FromBills([bill]); + + halves.Count.ShouldBe(2); + halves[0].From.ShouldBe(new DateOnly(2023, 7, 1)); + halves[1].From.ShouldBe(new DateOnly(2024, 1, 1)); + foreach (var half in halves) + { + half.Bill.GridKwh.ShouldBe(1500m); + half.Bill.PvKwh.ShouldBe(1000m); + half.Bill.GridChf.ShouldBe(450m); + half.Bill.PvChf.ShouldBe(200m); + half.Bill.SideCostsChf.ShouldBe(50m); + half.Bill.AdvanceChf.ShouldBe(600m); + } + } + + [Fact] + public void KeepPricePerKwhOfTheBillWhenSplittingIt() + { + var bill = Bill(new DateOnly(2023, 7, 1), new DateOnly(2024, 6, 30)); + bill.GridKwh = 3000m; + bill.GridChf = 900m; + + var halves = ElectricityHalfYear.FromBills([bill]); + + halves.ShouldAllBe(h => h.Bill.GridChfPerKwh == 0.3m); + } + + [Fact] + public void AddUpBillsWhenTheyShareAHalfYear() + { + var first = Bill(new DateOnly(2024, 1, 1), new DateOnly(2024, 3, 31)); + first.GridKwh = 100m; + var second = Bill(new DateOnly(2024, 4, 1), new DateOnly(2024, 6, 30)); + second.GridKwh = 200m; + + var halves = ElectricityHalfYear.FromBills([first, second]); + + halves.Count.ShouldBe(1); + halves[0].Bill.GridKwh.ShouldBe(300m); + } + + [Fact] + public void IncludeEmptyHalfYearWhenNoBillCoversIt() + { + var first = Bill(new DateOnly(2022, 7, 1), new DateOnly(2023, 6, 30)); + var later = Bill(new DateOnly(2024, 7, 1), new DateOnly(2025, 6, 30)); + + var halves = ElectricityHalfYear.FromBills([later, first]); + + halves.Select(h => h.Label).ShouldBe(["H2 22", "H1 23", "H2 23", "H1 24", "H2 24", "H1 25"]); + halves[2].Bill.ShouldBeNull(); + halves[3].Bill.ShouldBeNull(); + } + + [Fact] + public void ReturnEmptyListWhenThereAreNoBills() + { + ElectricityHalfYear.FromBills([]).ShouldBeEmpty(); + } + + private static ElectricityBill Bill(DateOnly from, DateOnly to) => new() { PeriodFrom = from, PeriodTo = to }; +} diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor b/Schaad.Accounting.UI/Components/Pages/Electricity.razor index 27abfa6..f598099 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor @@ -17,21 +17,21 @@ {
-
Verbrauch pro Periode
+
Verbrauch pro Halbjahr
+ AriaLabel="Netzbezug und PV-Produktion pro Halbjahr, gestapelte Balken in kWh" />
Preis pro kWh
+ AriaLabel="Preis pro kWh für Netz, PV und Total pro Halbjahr" />
-
Gesamtkosten pro Periode
+
Gesamtkosten pro Halbjahr
+ AriaLabel="Gesamtkosten pro Halbjahr" />
} diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs index 0fe2531..695a92e 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs @@ -11,8 +11,8 @@ namespace Schaad.Accounting.UI.Components.Pages; /// /// Yearly NeoVac electricity bills for the apartment (billing period 1 July – 30 June, so the /// bills are stored once per mandator, not per calendar year; see -/// ). Grid for entering/editing, plus two charts: -/// consumption split grid/PV per period, and the resulting price per kWh. +/// ). Grid for entering/editing, plus charts per half-year +/// (see ): consumption grid/PV, price per kWh and total costs. /// public partial class Electricity : ComponentBase { @@ -48,14 +48,16 @@ public partial class Electricity : ComponentBase private void BuildCharts() { - var labels = source.Select(ChartLabel).ToList(); + // One entry per half-year; a yearly bill is split evenly into its two halves. + var halves = ElectricityHalfYear.FromBills(source); + var labels = halves.Select(h => h.Label).ToList(); barData = new { labels, series = new object[] { - new { name = "Netz", color = ChartTheme.ColorAt(0), values = source.Select(b => b.GridKwh).ToList(), clickable = false }, - new { name = "PV", color = ChartTheme.ColorAt(1), values = source.Select(b => b.PvKwh).ToList(), clickable = false } + new { name = "Netz", color = ChartTheme.ColorAt(0), values = halves.Select(h => h.Bill?.GridKwh).ToList(), clickable = false }, + new { name = "PV", color = ChartTheme.ColorAt(1), values = halves.Select(h => h.Bill?.PvKwh).ToList(), clickable = false } }, unit = "kWh" }; @@ -64,9 +66,9 @@ public partial class Electricity : ComponentBase labels, series = new object[] { - new { name = "Netz", color = ChartTheme.ColorAt(0), values = source.Select(b => b.GridChfPerKwh).ToList(), width = 2 }, - new { name = "PV", color = ChartTheme.ColorAt(1), values = source.Select(b => b.PvChfPerKwh).ToList(), width = 2 }, - new { name = "Total", color = ChartTheme.OtherColor, values = source.Select(b => (decimal?)b.ChfPerKwh).ToList(), width = 2 } + new { name = "Netz", color = ChartTheme.ColorAt(0), values = halves.Select(h => h.Bill?.GridChfPerKwh).ToList(), width = 2 }, + new { name = "PV", color = ChartTheme.ColorAt(1), values = halves.Select(h => h.Bill?.PvChfPerKwh).ToList(), width = 2 }, + new { name = "Total", color = ChartTheme.OtherColor, values = halves.Select(h => h.Bill?.ChfPerKwh).ToList(), width = 2 } }, unit = "CHF/kWh", axisDecimals = 2 @@ -76,7 +78,7 @@ public partial class Electricity : ComponentBase labels, series = new object[] { - new { name = "Total", color = ChartTheme.ColorAt(2), values = source.Select(b => (decimal?)b.TotalChf).ToList(), width = 2 } + new { name = "Total", color = ChartTheme.ColorAt(2), values = halves.Select(h => h.Bill?.TotalChf).ToList(), width = 2 } }, unit = "CHF" }; @@ -135,9 +137,6 @@ public partial class Electricity : ComponentBase } } - // Short label for the chart axis, e.g. "23/24". - private static string ChartLabel(ElectricityBill bill) => $"{bill.PeriodFrom:yy}/{bill.PeriodTo:yy}"; - private static string FullLabel(ElectricityBill bill) => $"{bill.PeriodFrom:dd.MM.yyyy} – {bill.PeriodTo:dd.MM.yyyy}"; private static string Chf(decimal value) => value.ToString("#,0.00", SwissNumbers) + " CHF"; -- 2.39.5 From ca4a67f20aa1f20302c3f8da1aba69299c1457a8 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Tue, 27 Oct 2026 19:33:52 +0100 Subject: [PATCH 6/6] Remove Akonto and Saldo from the electricity bills Drop the advance payment (AdvanceChf) and the computed Balance from ElectricityBill, the Strom list, the edit dialog and the help image. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- .../Models/ElectricityBill.cs | 10 +--------- .../Models/ElectricityHalfYear.cs | 1 - .../ElectricityBillRepositoryTestShould.cs | 11 +++++------ .../ElectricityBillTestShould.cs | 17 ----------------- .../ElectricityHalfYearTestShould.cs | 2 -- .../Pages/Dialogs/ElectricityBillDialog.razor | 4 +--- .../Components/Pages/Electricity.razor | 5 ----- .../Components/Pages/Electricity.razor.cs | 12 ------------ .../Components/Pages/Electricity.razor.css | 8 -------- .../wwwroot/images/electricity-bill-guide.svg | 19 +++++-------------- 11 files changed, 13 insertions(+), 78 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index c25b8da..735af40 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -64,7 +64,7 @@ When a new year is opened, the previous year's data is copied as the starting po - **RawDataRepository** — plain-text load/save of the data files for the JSON editor page; validates (strict JSON, unique Ids, account references), refuses if the file changed since loading, and backs up the old version to `backup/{mandator}/{year}/json-{timestamp}/`; for `electricity.json` 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`) — grid and dialog (FluentDataGrid/`ElectricityBillDialog`) over `IElectricityBillRepository`'s `ElectricityBill` records (one yearly NeoVac bill each: kWh/CHF for grid and PV, side costs, advance payment; `TotalKwh`, `PvShare`, `TotalChf`, `Balance`, `ChfPerKwh` are computed); two Chart.js charts via `ChartJsChart` (stacked kWh per period, CHF/kWh line) +- **Strom** page (`Electricity`, `/electricity`) — 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`, one value per calendar half-year (`ElectricityHalfYear` spreads each bill evenly over its months): stacked kWh, CHF/kWh lines, total CHF ### UI structure diff --git a/Schaad.Accounting.Common/Models/ElectricityBill.cs b/Schaad.Accounting.Common/Models/ElectricityBill.cs index fd1d8de..04edc59 100644 --- a/Schaad.Accounting.Common/Models/ElectricityBill.cs +++ b/Schaad.Accounting.Common/Models/ElectricityBill.cs @@ -36,9 +36,6 @@ namespace Schaad.Accounting.Models [Display(Name = "Nebenkosten")] public decimal SideCostsChf { get; set; } - [Display(Name = "Akonto")] - public decimal AdvanceChf { get; set; } - /// Grid draw plus own PV consumption, in kWh. [JsonIgnore] [Display(Name = "Total")] @@ -49,16 +46,11 @@ namespace Schaad.Accounting.Models [Display(Name = "PV-Anteil")] public decimal PvShare => TotalKwh == 0 ? 0 : PvKwh / TotalKwh; - /// Grid, PV and side costs added up, before the advance payment. + /// Grid, PV and side costs added up. [JsonIgnore] [Display(Name = "Total")] public decimal TotalChf => GridChf + PvChf + SideCostsChf; - /// What is still owed (positive) or was overpaid (negative) after the advance. - [JsonIgnore] - [Display(Name = "Saldo")] - public decimal Balance => TotalChf - AdvanceChf; - /// Average price per kWh over the whole period. [JsonIgnore] [Display(Name = "CHF/kWh")] diff --git a/Schaad.Accounting.Common/Models/ElectricityHalfYear.cs b/Schaad.Accounting.Common/Models/ElectricityHalfYear.cs index c03758c..3742efc 100644 --- a/Schaad.Accounting.Common/Models/ElectricityHalfYear.cs +++ b/Schaad.Accounting.Common/Models/ElectricityHalfYear.cs @@ -51,7 +51,6 @@ namespace Schaad.Accounting.Models sum.GridChf += bill.GridChf * share; sum.PvChf += bill.PvChf * share; sum.SideCostsChf += bill.SideCostsChf * share; - sum.AdvanceChf += bill.AdvanceChf * share; } } diff --git a/Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs b/Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs index 3b2e687..016eaba 100644 --- a/Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs +++ b/Schaad.Accounting.Tests/ElectricityBillRepositoryTestShould.cs @@ -49,28 +49,27 @@ public class ElectricityBillRepositoryTestShould : IDisposable PvKwh = 1936.328m, GridChf = 1009.55m, PvChf = 544.10m, - SideCostsChf = 134.30m, - AdvanceChf = 1212.00m + SideCostsChf = 134.30m }; await sut.SaveElectricityBillAsync(bill); var stored = (await sut.GetElectricityBillListAsync()).Single(); stored.Id.ShouldNotBeNullOrEmpty(); - stored.Balance.ShouldBe(475.95m); + stored.TotalChf.ShouldBe(1687.95m); } [Fact] public async Task UpdateInPlaceWhenSavingBillWithExistingId() { - await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), AdvanceChf = 1000m }); + await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), GridKwh = 1000m }); var id = (await sut.GetElectricityBillListAsync()).Single().Id; - await sut.SaveElectricityBillAsync(new ElectricityBill { Id = id, PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), AdvanceChf = 1300m }); + await sut.SaveElectricityBillAsync(new ElectricityBill { Id = id, PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), GridKwh = 1300m }); var bills = await sut.GetElectricityBillListAsync(); bills.Count.ShouldBe(1); - bills[0].AdvanceChf.ShouldBe(1300m); + bills[0].GridKwh.ShouldBe(1300m); } [Fact] diff --git a/Schaad.Accounting.Tests/ElectricityBillTestShould.cs b/Schaad.Accounting.Tests/ElectricityBillTestShould.cs index 2119756..22ea132 100644 --- a/Schaad.Accounting.Tests/ElectricityBillTestShould.cs +++ b/Schaad.Accounting.Tests/ElectricityBillTestShould.cs @@ -37,23 +37,6 @@ public class ElectricityBillTestShould bill.TotalChf.ShouldBe(1687.95m); } - [Fact] - public void CalculateBalanceWhenAdvanceIsSubtractedFromTotal() - { - var bill = new ElectricityBill - { - GridKwh = 3419.432m, - PvKwh = 1936.328m, - GridChf = 1009.55m, - PvChf = 544.10m, - SideCostsChf = 134.30m, - AdvanceChf = 1212.00m - }; - - bill.TotalChf.ShouldBe(1687.95m); - bill.Balance.ShouldBe(475.95m); - } - [Fact] public void DivideTotalChfByTotalKwhWhenCalculatingChfPerKwh() { diff --git a/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs b/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs index 8a8b525..febdd09 100644 --- a/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs +++ b/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs @@ -14,7 +14,6 @@ public class ElectricityHalfYearTestShould bill.GridChf = 900m; bill.PvChf = 400m; bill.SideCostsChf = 100m; - bill.AdvanceChf = 1200m; var halves = ElectricityHalfYear.FromBills([bill]); @@ -28,7 +27,6 @@ public class ElectricityHalfYearTestShould half.Bill.GridChf.ShouldBe(450m); half.Bill.PvChf.ShouldBe(200m); half.Bill.SideCostsChf.ShouldBe(50m); - half.Bill.AdvanceChf.ShouldBe(600m); } } diff --git a/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor b/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor index 20dbb4d..76e588f 100644 --- a/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor +++ b/Schaad.Accounting.UI/Components/Pages/Dialogs/ElectricityBillDialog.razor @@ -27,7 +27,6 @@ -
@@ -35,8 +34,7 @@
- Total @Chf(Content.TotalChf), Akonto @Chf(Content.AdvanceChf) → Saldo @Chf(Content.Balance) - (@(Content.Balance >= 0 ? "Nachzahlung" : "Gutschrift")) + Total @Chf(Content.TotalChf)
diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor b/Schaad.Accounting.UI/Components/Pages/Electricity.razor index f598099..71f582a 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor @@ -47,11 +47,6 @@ - - - @Chf(context.Balance) - - diff --git a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs index 695a92e..6482c3e 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.cs @@ -1,4 +1,3 @@ -using System.Globalization; using Microsoft.AspNetCore.Components; using Microsoft.FluentUI.AspNetCore.Components; using Schaad.Accounting.Interfaces; @@ -16,8 +15,6 @@ namespace Schaad.Accounting.UI.Components.Pages; /// public partial class Electricity : ComponentBase { - private static readonly CultureInfo SwissNumbers = CreateSwissNumbers(); - [Inject] private IElectricityBillRepository electricityBillRepository { get; set; } = null!; @@ -138,13 +135,4 @@ public partial class Electricity : ComponentBase } private static string FullLabel(ElectricityBill bill) => $"{bill.PeriodFrom:dd.MM.yyyy} – {bill.PeriodTo:dd.MM.yyyy}"; - - 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/Electricity.razor.css b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.css index 3b2b4a5..658a09f 100644 --- a/Schaad.Accounting.UI/Components/Pages/Electricity.razor.css +++ b/Schaad.Accounting.UI/Components/Pages/Electricity.razor.css @@ -8,14 +8,6 @@ overflow-x: auto; } -.due { - color: #c50f1f; -} - -.credit { - color: #107c10; -} - .pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); diff --git a/Schaad.Accounting.UI/wwwroot/images/electricity-bill-guide.svg b/Schaad.Accounting.UI/wwwroot/images/electricity-bill-guide.svg index 1e3c619..de41d40 100644 --- a/Schaad.Accounting.UI/wwwroot/images/electricity-bill-guide.svg +++ b/Schaad.Accounting.UI/wwwroot/images/electricity-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 dem Abschnitt „Ihre Abrechnung vom …“ der NeoVac-Abrechnung. @@ -44,18 +44,9 @@ 80.00 → Nebenkosten (CHF) - - Akontozahlungen Strom - - -600.00 - → Akonto (CHF), ohne Minus eingeben - - + - Stromkosten (wird berechnet) - 680.00 - - Saldo (wird berechnet) - 80.00 + Stromkosten (wird berechnet) + 680.00 -- 2.39.5