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 <noreply@anthropic.com>
72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
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);
|
|
}
|
|
}
|