Compare commits

..

5 commits

Author SHA1 Message Date
24dc89d5fb Wasser & Heizung: align labels and inputs in the dialog
Fields sit in a two-column grid with a fixed label width, so labels and inputs line up across all sections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:40:32 +01:00
4023db06dd Wasser & Heizung: put the heat field on its own line in the dialog
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:38:37 +01:00
9a4f9a9010 Wasser & Heizung: remove the optional meter readings
The "Stand neu" fields for warm water, cold water and heat and their
continuity checks are gone; the per-mille, property total and price
checks stay. The "Kontrolle" heading is only shown when there is a check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:36:39 +01:00
a58f08e82a Wasser & Heizung: plausibility checks in the bill dialog
The dialog shows a "Kontrolle" section (WaterHeatingBillChecks): the NeoVac
per-mille shares against the optional ones of the property manager,
optional meter readings continuing from the previous bill, the property
totals implied by the own share, and the prices per unit compared with
the previous bill (flagged above ±25 %).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:33:21 +01:00
53e4854bc2 Add "Wasser & Heizung" page for the NeoVac water and heating bills
NeoVac only reports per-mille shares of the property; the own costs in CHF
come from the property manager's statement. The new page stores both in
water-heating.json (per mandator) and calculates the CHF parts: water base
and consumption costs by their per-mille share, consumption split by m³
into warm and cold water, and the warm water part of the heating costs
(the rest is room heating). Charts for water (m³), heat (MWh) and the
stacked costs; the dialog has a guide image showing where each value is
on the bills. The Wasser page stays for bills with the CHF values entered
directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:18:03 +01:00
19 changed files with 1227 additions and 5 deletions

View file

@ -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}/{year}/*.json data files
{DataPath}/{mandator}/electricity.json electricity bills (not per year, see below) {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.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 {DataPath}/backup/{mandator}/{year}/ backup zips
``` ```
When a new year is opened, the previous year's data is copied as the starting point. 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 ### 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 - **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 - **ChartService** — produces data for the Plotly booking-text charts on the transactions page
- **SettingsService** — manages the active year, mandator, and file paths - **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` - **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 - **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<T>.FromBills` over `IPeriodBill<T>`; a bill reaching over several periods is spread evenly over its months and the page shows a note) and limited to a from/to year range (periods overlapping it are kept whole) - **Strom** page (`Electricity`, `/electricity`, under "Charts" in the menu) — grid and dialog (FluentDataGrid/`ElectricityBillDialog`) over `IElectricityBillRepository`'s `ElectricityBill` records (one yearly NeoVac bill each: kWh/CHF for grid and PV, side costs; `TotalKwh`, `PvShare`, `TotalChf`, `ChfPerKwh` are computed); three Chart.js charts via `ChartJsChart` (stacked kWh, CHF/kWh lines, total CHF), filtered by the shared `BillChartToolbar` (`BillChartFilter`): grouped per bill, calendar year (default) or half-year (`BillPeriod<T>.FromBills` over `IPeriodBill<T>`; 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** page (`Water`, `/water`, under "Charts" in the menu) — same layout as Strom over `IWaterBillRepository`'s `WaterBill` records (warm/cold water m³ and CHF, base costs; `TotalM3`, `WarmWaterShare`, `TotalChf` are computed); two charts (stacked m³, total CHF) with the same `BillChartToolbar`
- **Wasser & Heizung** page (`WaterHeating`, `/water-heating`, under "Charts" in the menu) — same layout for NeoVac bills where only per-mille shares are known, over `IWaterHeatingBillRepository`'s `WaterHeatingBill` records: consumption (warm/cold m³, heat MWh) and ‰ shares from NeoVac, own water/heating costs in CHF from the property manager's statement; `WaterHeatingBillDialog` calls `CalculateCosts`, which stores the CHF parts (water split into base/consumption by ‰, consumption split by m³, warm water part of the heating), so `AddShare` can sum them per period; `RoomHeatingChf` is the rest of the heating. The dialog shows plausibility checks from `WaterHeatingBillChecks` (NeoVac ‰ vs. the optional ‰ of the property manager, implied property totals, prices per unit vs. the previous bill, flagged above ±25 %). Three charts (stacked m³, MWh, stacked CHF) and a guide image (`water-heating-bill-guide.svg`)
### UI structure ### UI structure

View file

@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Schaad.Accounting.Models;
namespace Schaad.Accounting.Interfaces
{
public interface IWaterHeatingBillRepository
{
Task<List<WaterHeatingBill>> GetWaterHeatingBillListAsync();
Task SaveWaterHeatingBillAsync(WaterHeatingBill bill);
Task<WaterHeatingBill> GetWaterHeatingBillAsync(string id);
Task DeleteWaterHeatingBillAsync(string id);
}
}

View file

@ -0,0 +1,137 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace Schaad.Accounting.Models
{
/// <summary>
/// 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).
/// </summary>
public class WaterHeatingBill : IPeriodBill<WaterHeatingBill>
{
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; }
/// <summary>Own share of the heating costs ("Wärmekostenanteil").</summary>
[Display(Name = "Wärmekostenanteil")]
public decimal HeatingPermille { get; set; }
/// <summary>Part of HeatingPermille spent on heating warm water.</summary>
[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; }
// Optional per-mille shares as listed by the property manager, only for the checks: they
// must match the NeoVac ones.
[Display(Name = "Wasser-Anteil Verwaltung")]
public decimal? ManagerWaterPermille { get; set; }
[Display(Name = "Heizungs-Anteil Verwaltung")]
public decimal? ManagerHeatingPermille { get; set; }
// Calculated by CalculateCosts.
[Display(Name = "Grundkosten Wasser")]
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; }
/// <summary>Warm plus cold water, in m³.</summary>
[JsonIgnore]
[Display(Name = "Total")]
public decimal TotalM3 => WarmWaterM3 + ColdWaterM3;
/// <summary>Share of the consumption that was warm water, 0..1.</summary>
[JsonIgnore]
[Display(Name = "Warmwasser-Anteil")]
public decimal WarmWaterShare => TotalM3 == 0 ? 0 : WarmWaterM3 / TotalM3;
/// <summary>Heating costs not spent on warm water, i.e. heating the rooms.</summary>
[JsonIgnore]
[Display(Name = "Heizung Räume")]
public decimal RoomHeatingChf => HeatingCostsChf - WarmWaterHeatingChf;
/// <summary>Water and heating costs added up.</summary>
[JsonIgnore]
[Display(Name = "Total")]
public decimal TotalChf => WaterCostsChf + HeatingCostsChf;
/// <summary>
/// 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.
/// </summary>
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);
/// <summary>Adds up consumption and CHF values; the per-mille shares don't add up and are left out.</summary>
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;
}
}
}

View file

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace Schaad.Accounting.Models
{
public enum BillCheckResult
{
/// <summary>A value to compare by hand with the statements.</summary>
Info,
Ok,
Warning
}
public record BillCheck(BillCheckResult Result, string Text);
/// <summary>
/// Plausibility checks for a <see cref="WaterHeatingBill"/>, shown in its dialog: the NeoVac and
/// property manager's per-mille shares must match, and the prices per unit shouldn't jump
/// against the previous bill. Checks whose optional inputs are missing are left out.
/// </summary>
public static class WaterHeatingBillChecks
{
/// <summary>Price changes against the previous bill above this share are flagged.</summary>
public const decimal MaxPriceChange = 0.25m;
private const decimal PermilleTolerance = 0.005m;
private static readonly CultureInfo SwissNumbers = CreateSwissNumbers();
/// <summary>The bill that ended last before <paramref name="bill"/> started, if any.</summary>
public static WaterHeatingBill PreviousOf(IEnumerable<WaterHeatingBill> bills, WaterHeatingBill bill)
=> bills.Where(b => b.Id != bill.Id && b.PeriodTo < bill.PeriodFrom).MaxBy(b => b.PeriodTo);
public static IReadOnlyList<BillCheck> Check(WaterHeatingBill bill, WaterHeatingBill previous)
{
var checks = new List<BillCheck>();
var waterPermille = bill.WaterBasePermille + bill.WaterConsumptionPermille;
if (bill.ManagerWaterPermille is decimal managerWater)
{
checks.Add(new BillCheck(
Result(Math.Abs(waterPermille - managerWater) < PermilleTolerance),
$"Wasser: NeoVac {N(bill.WaterBasePermille)} + {N(bill.WaterConsumptionPermille)} = {N(waterPermille)} ‰, Verwaltung {N(managerWater)} ‰"));
}
if (bill.ManagerHeatingPermille is decimal managerHeating)
{
checks.Add(new BillCheck(
Result(Math.Abs(bill.HeatingPermille - managerHeating) < PermilleTolerance),
$"Heizung: NeoVac {N(bill.HeatingPermille)} ‰, Verwaltung {N(managerHeating)} ‰"));
}
if (bill.WarmWaterHeatingPermille > bill.HeatingPermille)
{
checks.Add(new BillCheck(BillCheckResult.Warning,
$"Heizung WW {N(bill.WarmWaterHeatingPermille)} ‰ ist grösser als Heizung total {N(bill.HeatingPermille)} ‰"));
}
// The own share divided by the per-mille share gives the costs of the whole property,
// which are on the property manager's statement.
if (waterPermille != 0 && bill.HeatingPermille != 0)
{
checks.Add(new BillCheck(BillCheckResult.Info,
$"Liegenschaft: Wasserkosten {N(bill.WaterCostsChf * 1000 / waterPermille)} CHF, Heizkosten {N(bill.HeatingCostsChf * 1000 / bill.HeatingPermille)} CHF"));
}
AddPriceCheck(checks, "Wasser", "CHF/m³", WaterPrice(bill), previous is null ? null : WaterPrice(previous));
AddPriceCheck(checks, "Heizung Warmwasser", "CHF/m³", WarmWaterHeatingPrice(bill), previous is null ? null : WarmWaterHeatingPrice(previous));
AddPriceCheck(checks, "Heizung Räume", "CHF/MWh", RoomHeatingPrice(bill), previous is null ? null : RoomHeatingPrice(previous));
return checks;
}
private static void AddPriceCheck(List<BillCheck> checks, string name, string unit, decimal? price, decimal? previousPrice)
{
if (price is not decimal now)
{
return;
}
if (previousPrice is decimal before && before != 0)
{
var change = now / before - 1;
checks.Add(new BillCheck(Result(Math.Abs(change) <= MaxPriceChange),
$"{name}: {N(now)} {unit} (Vorperiode {N(before)}, {change.ToString("+0%;−0%;0%", SwissNumbers)})"));
}
else
{
checks.Add(new BillCheck(BillCheckResult.Info, $"{name}: {N(now)} {unit}"));
}
}
/// <summary>Water consumption costs (without base costs) per m³.</summary>
private static decimal? WaterPrice(WaterHeatingBill bill)
=> bill.TotalM3 == 0 ? null : (bill.WarmWaterChf + bill.ColdWaterChf) / bill.TotalM3;
private static decimal? WarmWaterHeatingPrice(WaterHeatingBill bill)
=> bill.WarmWaterM3 == 0 ? null : bill.WarmWaterHeatingChf / bill.WarmWaterM3;
private static decimal? RoomHeatingPrice(WaterHeatingBill bill)
=> bill.HeatingMwh == 0 ? null : bill.RoomHeatingChf / bill.HeatingMwh;
private static BillCheckResult Result(bool ok) => ok ? BillCheckResult.Ok : BillCheckResult.Warning;
private static string N(decimal value) => value.ToString("#,0.00", SwissNumbers);
private static CultureInfo CreateSwissNumbers()
{
var culture = new CultureInfo("de-CH");
culture.NumberFormat.NumberGroupSeparator = "'";
return culture;
}
}
}

View file

@ -27,6 +27,7 @@ namespace Schaad.Accounting.Repositories
private const string TRANSACTIONS = "Transactions.json"; private const string TRANSACTIONS = "Transactions.json";
private const string ELECTRICITY = "electricity.json"; private const string ELECTRICITY = "electricity.json";
private const string WATER = "water.json"; private const string WATER = "water.json";
private const string WATER_HEATING = "water-heating.json";
private const int MaxErrors = 20; private const int MaxErrors = 20;
// Like the normal options, but property names that don't exist (typos) are errors instead // 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", "BookingTexts.json",
"SubClasses.json", "SubClasses.json",
ELECTRICITY, ELECTRICITY,
WATER WATER,
WATER_HEATING
]; ];
public async Task<RawDataFile> LoadAsync(string fileName) public async Task<RawDataFile> LoadAsync(string fileName)
@ -70,6 +72,7 @@ namespace Schaad.Accounting.Repositories
"SubClasses.json" => SaveAsync<SubClass>(fileName, text, loadedHash), "SubClasses.json" => SaveAsync<SubClass>(fileName, text, loadedHash),
ELECTRICITY => SaveAsync<ElectricityBill>(fileName, text, loadedHash), ELECTRICITY => SaveAsync<ElectricityBill>(fileName, text, loadedHash),
WATER => SaveAsync<WaterBill>(fileName, text, loadedHash), WATER => SaveAsync<WaterBill>(fileName, text, loadedHash),
WATER_HEATING => SaveAsync<WaterHeatingBill>(fileName, text, loadedHash),
_ => throw new ArgumentException($"Unknown data file '{fileName}'", nameof(fileName)) _ => throw new ArgumentException($"Unknown data file '{fileName}'", nameof(fileName))
}; };
@ -240,10 +243,10 @@ namespace Schaad.Accounting.Repositories
return Path.Combine(DirectoryOf(fileName), fileName); 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). // runs 1 July – 30 June, so it doesn't align with calendar years).
private string DirectoryOf(string fileName) 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)); private static string Hash(byte[] bytes) => Convert.ToHexString(SHA256.HashData(bytes));

View file

@ -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
{
/// <summary>
/// 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.
/// </summary>
public class WaterHeatingBillRepository : BaseRepository, IWaterHeatingBillRepository
{
private const string WATER_HEATING = "water-heating.json";
public WaterHeatingBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<WaterHeatingBillRepository> logger)
: base(settingsService, cache, logger)
{
}
public Task<List<WaterHeatingBill>> GetWaterHeatingBillListAsync()
=> LoadListAsync<WaterHeatingBill>(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<WaterHeatingBill> 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);
}
}
}

View file

@ -208,6 +208,22 @@ public class RawDataRepositoryTestShould : IDisposable
File.Exists(Path.Combine(dbDir, "water.json")).ShouldBeFalse(); 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] [Fact]
public async Task RejectUnknownFileNameWhenLoading() public async Task RejectUnknownFileNameWhenLoading()
{ {

View file

@ -0,0 +1,114 @@
using Schaad.Accounting.Models;
using Shouldly;
namespace Schaad.Accounting.Tests;
public class WaterHeatingBillChecksTestShould
{
// Values of the 2024/25 bill: NeoVac per-mille shares and the own share from the property manager.
private static WaterHeatingBill Bill()
{
var bill = new WaterHeatingBill
{
Id = "b2025",
PeriodFrom = new DateOnly(2024, 7, 1),
PeriodTo = new DateOnly(2025, 6, 30),
WarmWaterM3 = 16.399m,
ColdWaterM3 = 51.464m,
HeatingMwh = 2.458m,
WaterBasePermille = 19.52m,
WaterConsumptionPermille = 68.50m,
HeatingPermille = 62.82m,
WarmWaterHeatingPermille = 12.66m,
WaterCostsChf = 304.30m,
HeatingCostsChf = 451.65m
};
bill.CalculateCosts();
return bill;
}
[Fact]
public void PassWhenNeoVacPermilleMatchesPropertyManager()
{
var bill = Bill();
bill.ManagerWaterPermille = 88.02m;
bill.ManagerHeatingPermille = 62.82m;
var checks = WaterHeatingBillChecks.Check(bill, null);
checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text.StartsWith("Wasser: NeoVac 19.52 + 68.50 = 88.02 ‰"));
checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text.StartsWith("Heizung: NeoVac 62.82 ‰"));
}
[Fact]
public void WarnWhenNeoVacPermilleDiffersFromPropertyManager()
{
var bill = Bill();
bill.ManagerWaterPermille = 88.20m;
var checks = WaterHeatingBillChecks.Check(bill, null);
checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Wasser: NeoVac"));
}
[Fact]
public void LeaveOutPermilleChecksWhenPropertyManagerValuesAreMissing()
{
var checks = WaterHeatingBillChecks.Check(Bill(), null);
checks.ShouldNotContain(c => c.Text.StartsWith("Wasser: NeoVac") || c.Text.StartsWith("Heizung: NeoVac"));
}
[Fact]
public void WarnWhenWarmWaterHeatingPermilleIsAboveHeatingPermille()
{
var bill = Bill();
bill.WarmWaterHeatingPermille = 70m;
var checks = WaterHeatingBillChecks.Check(bill, null);
checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Heizung WW 70.00 ‰"));
}
[Fact]
public void ShowPropertyCostsDerivedFromOwnShare()
{
var checks = WaterHeatingBillChecks.Check(Bill(), null);
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Liegenschaft: Wasserkosten 3'457.17 CHF, Heizkosten 7'189.59 CHF"));
}
[Fact]
public void ShowPricesPerUnitWhenThereIsNoPreviousBill()
{
var checks = WaterHeatingBillChecks.Check(Bill(), null);
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Wasser: 3.49 CHF/m³"));
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Heizung Warmwasser: 5.55 CHF/m³"));
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Heizung Räume: 146.72 CHF/MWh"));
}
[Fact]
public void WarnWhenPriceChangesMoreThanAllowedAgainstPreviousBill()
{
var previous = Bill();
previous.HeatingCostsChf = 300m;
previous.CalculateCosts();
var checks = WaterHeatingBillChecks.Check(Bill(), previous);
checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Heizung Räume: 146.72 CHF/MWh (Vorperiode"));
checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text == "Wasser: 3.49 CHF/m³ (Vorperiode 3.49, 0%)");
}
[Fact]
public void PickBillThatEndedLastBeforeThisOneAsPrevious()
{
var bill = Bill();
var older = new WaterHeatingBill { Id = "a", PeriodFrom = new DateOnly(2022, 7, 1), PeriodTo = new DateOnly(2023, 6, 30) };
var last = new WaterHeatingBill { Id = "b", PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) };
var later = new WaterHeatingBill { Id = "c", PeriodFrom = new DateOnly(2025, 7, 1), PeriodTo = new DateOnly(2026, 6, 30) };
WaterHeatingBillChecks.PreviousOf([later, older, bill, last], bill).ShouldBeSameAs(last);
}
}

View file

@ -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<ISettingsService>();
settingsService.GetMandatorPath().Returns(mandatorDir);
sut = new WaterHeatingBillRepository(settingsService, new RepositoryCache(), NullLogger<WaterHeatingBillRepository>.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();
}
}

View file

@ -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);
}
}

View file

@ -21,6 +21,7 @@
<FluentNavLink Href="analytics" Icon="@(new Size20.DataHistogram())" IconColor="Color.Accent">Analyse</FluentNavLink> <FluentNavLink Href="analytics" Icon="@(new Size20.DataHistogram())" IconColor="Color.Accent">Analyse</FluentNavLink>
<FluentNavLink Href="electricity" Icon="@(new Size20.Flash())" IconColor="Color.Accent">Strom</FluentNavLink> <FluentNavLink Href="electricity" Icon="@(new Size20.Flash())" IconColor="Color.Accent">Strom</FluentNavLink>
<FluentNavLink Href="water" Icon="@(new Size20.Drop())" IconColor="Color.Accent">Wasser</FluentNavLink> <FluentNavLink Href="water" Icon="@(new Size20.Drop())" IconColor="Color.Accent">Wasser</FluentNavLink>
<FluentNavLink Href="water-heating" Icon="@(new Size20.Temperature())" IconColor="Color.Accent">Wasser &amp; Heizung</FluentNavLink>
</FluentNavGroup> </FluentNavGroup>
<FluentNavGroup Title="Reports" Icon="@(new Size32.DocumentPrint())"> <FluentNavGroup Title="Reports" Icon="@(new Size32.DocumentPrint())">
<FluentNavLink Href="ProfitLossReport" Icon="@(new Size32.DataTrending())" IconColor="Color.Accent">Erfolgsrechnung</FluentNavLink> <FluentNavLink Href="ProfitLossReport" Icon="@(new Size32.DataTrending())" IconColor="Color.Accent">Erfolgsrechnung</FluentNavLink>

View file

@ -0,0 +1,111 @@
@implements IDialogContentComponent<Schaad.Accounting.Models.WaterHeatingBill>
@rendermode InteractiveServer
@using Schaad.Accounting.Models
<FluentDialogHeader ShowDismiss="true">
<FluentStack VerticalAlignment="VerticalAlignment.Center">
<FluentIcon Value="@(new Icons.Regular.Size24.WindowApps())" />
<FluentLabel Typo="Typography.PaneHeader">
@Dialog.Instance.Parameters.Title
</FluentLabel>
</FluentStack>
</FluentDialogHeader>
<FluentDialogBody>
<EditForm EditContext="@editContext">
<DataAnnotationsValidator />
<div class="fields">
<div class="field"><FluentDatePicker @bind-Value="@periodFrom" @bind-Value:after="SyncPeriod" Label="Von" /></div>
<div class="field"><FluentDatePicker @bind-Value="@periodTo" @bind-Value:after="SyncPeriod" Label="Bis" /></div>
</div>
<div style="@SectionStyle">NeoVac – Ablesequittung</div>
<div class="fields">
<div class="field"><FluentNumberField @bind-Value="@Content.WarmWaterM3" @bind-Value:after="Content.CalculateCosts" Label="Warmwasser (m³)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.ColdWaterM3" @bind-Value:after="Content.CalculateCosts" Label="Kaltwasser (m³)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.HeatingMwh" Label="Wärme (MWh)" /></div>
</div>
<div style="@SectionStyle">NeoVac – Anteil (‰)</div>
<div class="fields">
<div class="field"><FluentNumberField @bind-Value="@Content.WaterBasePermille" @bind-Value:after="Content.CalculateCosts" Label="Wasser Grund (‰)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.WaterConsumptionPermille" @bind-Value:after="Content.CalculateCosts" Label="Wasser Verbrauch (‰)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.HeatingPermille" @bind-Value:after="Content.CalculateCosts" Label="Heizung total (‰)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.WarmWaterHeatingPermille" @bind-Value:after="Content.CalculateCosts" Label="Heizung WW (‰)" /></div>
</div>
<div style="@SectionStyle">Verwaltung – Ihr Anteil</div>
<div class="fields">
<div class="field"><FluentNumberField @bind-Value="@Content.WaterCostsChf" @bind-Value:after="Content.CalculateCosts" Label="Wasserkosten (CHF)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.HeatingCostsChf" @bind-Value:after="Content.CalculateCosts" Label="Heizkosten (CHF)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.ManagerWaterPermille" Label="Wasser (‰, optional)" /></div>
<div class="field"><FluentNumberField @bind-Value="@Content.ManagerHeatingPermille" Label="Heizung (‰, optional)" /></div>
</div>
<div>
<FluentValidationSummary />
</div>
</EditForm>
<div style="margin-top: 12px; font-size: 13px; color: #52514e;">
Wasser: Grundkosten <strong>@Chf(Content.BaseCostsChf)</strong>
· Warmwasser <strong>@Chf(Content.WarmWaterChf)</strong>
· Kaltwasser <strong>@Chf(Content.ColdWaterChf)</strong>
</div>
<div style="margin-top: 4px; font-size: 13px; color: #52514e;">
Heizung: Warmwasser <strong>@Chf(Content.WarmWaterHeatingChf)</strong>
· Räume <strong>@Chf(Content.RoomHeatingChf)</strong>
</div>
<div style="margin-top: 4px; font-size: 13px; color: #52514e;">
Total <strong>@M3(Content.TotalM3)</strong> · <strong>@Mwh(Content.HeatingMwh)</strong> · <strong>@Chf(Content.TotalChf)</strong>
</div>
@if (Checks is { Count: > 0 } checks)
{
<div style="@SectionStyle">Kontrolle</div>
@foreach (var check in checks)
{
<div style="font-size: 13px; color: @CheckColor(check.Result);">@CheckSymbol(check.Result) @check.Text</div>
}
}
<FluentButton Appearance="Appearance.Lightweight" Style="margin-top: 12px; padding: 0; font-size: 13px;" OnClick="ShowGuideAsync">
Woher kommen die Werte? (NeoVac-Abrechnung)
</FluentButton>
</FluentDialogBody>
<FluentDialogFooter>
<FluentButton Appearance="Appearance.Neutral"
OnClick="@CancelAsync">
Abbrechen
</FluentButton>
<FluentButton Appearance="Appearance.Accent"
Disabled="@(periodFrom is null || periodTo is null)"
OnClick="@SaveAsync">
Speichern
</FluentButton>
</FluentDialogFooter>
@code {
private const string SectionStyle = "margin-top: 14px; margin-bottom: 4px; font-size: 11px; font-weight: bold; color: #898781; text-transform: uppercase;";
// Shown in its own dialog (see ShowGuideAsync) instead of expanding inline: this dialog has a
// fixed Height, and FluentDialogBody doesn't resize to fit growing content.
private RenderFragment GuideImage =>
@<img src="/images/water-heating-bill-guide.svg"
alt="Beispiel-Abrechnung mit Markierungen, welcher Wert in welches Feld gehört"
style="width: 100%; height: auto; display: block;" />;
private static string CheckSymbol(BillCheckResult result) => result switch
{
BillCheckResult.Ok => "✓",
BillCheckResult.Warning => "⚠",
_ => "·"
};
private static string CheckColor(BillCheckResult result) => result switch
{
BillCheckResult.Ok => "#1a7f37",
BillCheckResult.Warning => "#c4314b",
_ => "#52514e"
};
}

View file

@ -0,0 +1,109 @@
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;
/// <summary>
/// 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 <see cref="WaterHeatingBill.CalculateCosts"/>)
/// and checked (see <see cref="WaterHeatingBillChecks"/>).
/// </summary>
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;
// The other bills, to find the previous one for the price checks.
private List<WaterHeatingBill> bills = [];
[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 async Task OnInitializedAsync()
{
bills = await waterHeatingBillRepository.GetWaterHeatingBillListAsync();
periodFrom = Content.PeriodFrom == default ? null : Content.PeriodFrom.ToDateTime(TimeOnly.MinValue);
periodTo = Content.PeriodTo == default ? null : Content.PeriodTo.ToDateTime(TimeOnly.MinValue);
editContext = new EditContext(Content);
}
private IReadOnlyList<BillCheck> Checks
=> WaterHeatingBillChecks.Check(Content, WaterHeatingBillChecks.PreviousOf(bills, Content));
// Keeps the period on the bill up to date while editing, so the checks find the right
// previous bill.
private void SyncPeriod()
{
if (periodFrom is not null)
{
Content.PeriodFrom = DateOnly.FromDateTime(periodFrom.Value);
}
if (periodTo is not null)
{
Content.PeriodTo = DateOnly.FromDateTime(periodTo.Value);
}
}
private async Task SaveAsync()
{
if (periodFrom is null || periodTo is null)
{
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;
}
}

View file

@ -0,0 +1,26 @@
/* Two columns of fields; each field is a fixed-width label left of an input that fills the rest,
so labels and inputs line up across rows and sections. */
.fields {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
column-gap: 24px;
row-gap: 8px;
}
.field {
display: flex;
align-items: center;
gap: 8px;
}
.field ::deep .fluent-input-label {
flex: 0 0 140px;
margin: 0;
}
.field ::deep fluent-number-field,
.field ::deep fluent-text-field {
flex: 1 1 auto;
min-width: 0;
width: auto;
}

View file

@ -0,0 +1,61 @@
@page "/water-heating"
@rendermode InteractiveServer
@using Schaad.Accounting.UI.Components.Pages.Analytics
<PageTitle>Wasser &amp; Heizung</PageTitle>
<div class="water-heating">
<FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center">
<FluentButton IconStart="@(new Icons.Regular.Size16.Add())" Appearance="Appearance.Neutral" OnClick="AddAsync">Neue Abrechnung hinzufügen</FluentButton>
</FluentStack>
@if (source.Count == 0)
{
<FluentMessageBar Intent="MessageIntent.Info" AllowDismiss="false">Noch keine Abrechnungen erfasst.</FluentMessageBar>
}
else
{
<BillChartToolbar Filter="@filter" FilterChanged="@OnFilterChanged" Years="@years" IsSplit="@isSplit" />
<div class="pair">
<FluentCard class="chart-card">
<div class="card-title">Wasserverbrauch @PerPeriod</div>
<ChartJsChart Kind="stackedBar" Data="@waterData" Height="360px"
AriaLabel="@($"Warm- und Kaltwasserverbrauch {PerPeriod}, gestapelte Balken in m³")" />
</FluentCard>
<FluentCard class="chart-card">
<div class="card-title">Wärmeverbrauch @PerPeriod</div>
<ChartJsChart Kind="stackedBar" Data="@heatData" Height="360px"
AriaLabel="@($"Wärmeverbrauch {PerPeriod}, Balken in MWh")" />
</FluentCard>
</div>
<FluentCard class="chart-card">
<div class="card-title">Kosten @PerPeriod</div>
<ChartJsChart Kind="stackedBar" Data="@costData" Height="320px"
AriaLabel="@($"Kosten {PerPeriod}, gestapelte Balken in CHF: Grundkosten Wasser, Kalt- und Warmwasser, Heizung Warmwasser und Räume")" />
</FluentCard>
}
<div class="table-scroll">
<FluentDataGrid Items="@source.AsQueryable()" RowSize="DataGridRowSize.Medium">
<PropertyColumn Title="Von" Property="@(p => p.PeriodFrom)" Format="dd.MM.yyyy" Sortable="true" IsDefaultSortColumn="true" InitialSortDirection="SortDirection.Descending" />
<PropertyColumn Title="Bis" Property="@(p => p.PeriodTo)" Format="dd.MM.yyyy" Sortable="true" />
<PropertyColumn Title="Warmwasser m³" Property="@(p => p.WarmWaterM3)" Format="#,0.00" Align="Align.End" />
<PropertyColumn Title="Kaltwasser m³" Property="@(p => p.ColdWaterM3)" Format="#,0.00" Align="Align.End" />
<PropertyColumn Title="Wärme MWh" Property="@(p => p.HeatingMwh)" Format="#,0.000" Align="Align.End" />
<PropertyColumn Title="Grundkosten" Property="@(p => p.BaseCostsChf)" Format="C2" Align="Align.End" />
<PropertyColumn Title="Warmwasser CHF" Property="@(p => p.WarmWaterChf)" Format="C2" Align="Align.End" />
<PropertyColumn Title="Kaltwasser CHF" Property="@(p => p.ColdWaterChf)" Format="C2" Align="Align.End" />
<PropertyColumn Title="Heizung Warmwasser" Property="@(p => p.WarmWaterHeatingChf)" Format="C2" Align="Align.End" />
<PropertyColumn Title="Heizung Räume" Property="@(p => p.RoomHeatingChf)" Format="C2" Align="Align.End" />
<PropertyColumn Title="Total CHF" Property="@(p => p.TotalChf)" Format="C2" Align="Align.End" />
<TemplateColumn Align="Align.Center" Width="50px">
<FluentButton IconEnd="@(new Icons.Regular.Size16.Delete())" Appearance="Appearance.Neutral" title="Löschen" aria-label="Löschen" OnClick="@(() => DeleteAsync(context.Id))" />
</TemplateColumn>
<TemplateColumn Align="Align.Center" Width="50px">
<FluentButton IconEnd="@(new Icons.Regular.Size16.Edit())" Appearance="Appearance.Neutral" title="Bearbeiten" aria-label="Bearbeiten" OnClick="@(() => EditAsync(context.Id))" />
</TemplateColumn>
</FluentDataGrid>
</div>
</div>

View file

@ -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;
/// <summary>
/// NeoVac water and heating bills, laid out like the Wasser page (<see cref="Water"/>), which holds
/// the bills with the CHF values entered directly: the bills are stored once per mandator, not per
/// calendar year (see <see cref="IWaterHeatingBillRepository"/>). Grid for entering/editing, plus
/// charts per bill, calendar year or half-year over a year range (see <see cref="BillChartToolbar"/>
/// and <see cref="BillPeriod{T}"/>): 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.
/// </summary>
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<WaterHeatingBill> source = [];
private BillChartFilter filter = new();
// Years any bill touches, for the year range of the charts.
private List<int> 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<WaterHeatingBillDialog>(data, new DialogParameters()
{
Width = "760px",
Height = "820px",
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<WaterHeatingBillDialog>(data, new DialogParameters()
{
Width = "760px",
Height = "820px",
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}";
}

View file

@ -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;
}

View file

@ -23,6 +23,7 @@ namespace Schaad.Accounting.UI
services.AddScoped<IBookingTextRepository, BookingTextRepository>(); services.AddScoped<IBookingTextRepository, BookingTextRepository>();
services.AddScoped<IElectricityBillRepository, ElectricityBillRepository>(); services.AddScoped<IElectricityBillRepository, ElectricityBillRepository>();
services.AddScoped<IWaterBillRepository, WaterBillRepository>(); services.AddScoped<IWaterBillRepository, WaterBillRepository>();
services.AddScoped<IWaterHeatingBillRepository, WaterHeatingBillRepository>();
services.AddScoped<ISubclassRepository, SubclassRepository>(); services.AddScoped<ISubclassRepository, SubclassRepository>();
services.AddScoped<ITransactionRepository, TransactionRepository>(); services.AddScoped<ITransactionRepository, TransactionRepository>();
services.AddScoped<IMultiYearRepository, MultiYearRepository>(); services.AddScoped<IMultiYearRepository, MultiYearRepository>();

View file

@ -0,0 +1,79 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 824" role="img" aria-labelledby="guide-title">
<title id="guide-title">Beispiel-Abrechnung: Wo stehen die Werte?</title>
<rect x="8" y="8" width="624" height="808" rx="10" fill="#fcfcfb" stroke="#e1e0d9" />
<text x="24" y="38" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="16" font-weight="bold" fill="#0b0b0b">Beispiel: Wo stehen die Werte auf der Abrechnung?</text>
<text x="24" y="58" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#52514e">Platzhalterwerte – der Aufbau entspricht der NeoVac-Abrechnung und der Aufstellung der Verwaltung.</text>
<line x1="24" y1="72" x2="616" y2="72" stroke="#e1e0d9" stroke-width="1" />
<text x="24" y="98" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#898781">NEOVAC – ABLESEQUITTUNG, SPALTE „VERBRAUCH VERRECHNET“</text>
<!-- Von / Bis -->
<text x="24" y="133" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Abrechnungsperiode</text>
<rect x="380" y="113" width="232" height="22" rx="4" fill="none" stroke="#e87ba4" stroke-width="2" />
<text x="604" y="129" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">01.07.2025 – 30.06.2026</text>
<text x="604" y="147" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#e87ba4">→ Von / Bis</text>
<!-- Warmwasser (m³) -->
<text x="24" y="175" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Wasser – WAZ Pic. (WW)</text>
<rect x="380" y="155" width="232" height="22" rx="4" fill="none" stroke="#eb6834" stroke-width="2" />
<text x="604" y="171" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">15.000</text>
<text x="604" y="189" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#eb6834">→ Warmwasser (m³)</text>
<!-- Kaltwasser (m³) -->
<text x="24" y="217" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Wasser – WAZ Pic. (KW)</text>
<rect x="380" y="197" width="232" height="22" rx="4" fill="none" stroke="#2a78d6" stroke-width="2" />
<text x="604" y="213" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">45.000</text>
<text x="604" y="231" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#2a78d6">→ Kaltwasser (m³)</text>
<!-- Wärme (MWh) -->
<text x="24" y="259" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Wärme – Total Wärme (MWh)</text>
<rect x="380" y="239" width="232" height="22" rx="4" fill="none" stroke="#e34948" stroke-width="2" />
<text x="604" y="255" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">2.400</text>
<text x="604" y="273" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#e34948">→ Wärme (MWh)</text>
<text x="24" y="298" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#52514e">Den Verbrauch übernehmen, nicht „Stand neu“ – das ist der Zählerstand.</text>
<line x1="24" y1="312" x2="616" y2="312" stroke="#e1e0d9" stroke-width="1" />
<text x="24" y="338" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#898781">NEOVAC – WASSERKOSTEN / WÄRMEKOSTEN, SPALTE „ANTEIL (‰)“</text>
<!-- Wasser Grund (‰) -->
<text x="24" y="373" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Wasser – Grundkosten</text>
<rect x="380" y="353" width="232" height="22" rx="4" fill="none" stroke="#1baf7a" stroke-width="2" />
<text x="604" y="369" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">20.00</text>
<text x="604" y="387" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#1baf7a">→ Wasser Grund (‰)</text>
<!-- Wasser Verbrauch (‰) -->
<text x="24" y="415" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Wasser – Verbrauchskosten</text>
<rect x="380" y="395" width="232" height="22" rx="4" fill="none" stroke="#8a5cd1" stroke-width="2" />
<text x="604" y="411" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">70.00</text>
<text x="604" y="429" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#8a5cd1">→ Wasser Verbrauch (‰)</text>
<!-- Heizung total (‰) -->
<text x="24" y="457" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Wärmekostenanteil (Gesamt)</text>
<rect x="380" y="437" width="232" height="22" rx="4" fill="none" stroke="#c98500" stroke-width="2" />
<text x="604" y="453" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">60.00</text>
<text x="604" y="471" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#c98500">→ Heizung total (‰)</text>
<!-- Heizung WW (‰) -->
<text x="24" y="499" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Warmwasser (Gesamt)</text>
<rect x="380" y="479" width="232" height="22" rx="4" fill="none" stroke="#c98500" stroke-width="2" />
<text x="604" y="495" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">12.00</text>
<text x="604" y="513" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#c98500">→ Heizung WW (‰)</text>
<line x1="24" y1="528" x2="616" y2="528" stroke="#e1e0d9" stroke-width="1" />
<text x="24" y="554" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#898781">VERWALTUNG – AUFSTELLUNG, IHR ANTEIL</text>
<!-- Wasserkosten (CHF) -->
<text x="24" y="589" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Wasserkosten</text>
<rect x="380" y="569" width="232" height="22" rx="4" fill="none" stroke="#1a9bb0" stroke-width="2" />
<text x="604" y="585" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">300.00</text>
<text x="604" y="603" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#1a9bb0">→ Wasserkosten (CHF)</text>
<!-- Heizkosten (CHF) -->
<text x="24" y="631" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Heizkosten</text>
<rect x="380" y="611" width="232" height="22" rx="4" fill="none" stroke="#c98500" stroke-width="2" />
<text x="604" y="627" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">450.00</text>
<text x="604" y="645" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#c98500">→ Heizkosten (CHF)</text>
<!-- Wasser / Heizung (‰, optional) -->
<text x="24" y="673" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Promille Wasser / Heizung</text>
<rect x="380" y="653" width="232" height="22" rx="4" fill="none" stroke="#898781" stroke-width="2" />
<text x="604" y="669" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">90.000 / 60.000</text>
<text x="604" y="687" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#898781">→ Wasser / Heizung (‰, optional)</text>
<text x="24" y="712" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#52514e">Die Kontrolle vergleicht sie mit Grund + Verbrauch bzw. dem Wärmekostenanteil von NeoVac.</text>
<line x1="24" y1="726" x2="616" y2="726" stroke="#e1e0d9" stroke-width="1" />
<!-- Worked example, informational only -->
<text x="24" y="752" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">Grundkosten 300.00 × 20 / 90</text>
<text x="604" y="752" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">66.67</text>
<text x="24" y="774" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">Verbrauch 233.33, davon 15 von 60 m³ warm</text>
<text x="604" y="774" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">Warmwasser 58.33 · Kaltwasser 175.00</text>
<text x="24" y="796" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">Heizung Warmwasser 450.00 × 12 / 60</text>
<text x="604" y="796" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">Heizung Warmwasser 90.00 · Räume 360.00</text>
</svg>

After

Width:  |  Height:  |  Size: 9.7 KiB