AccountingNext/Schaad.Accounting.Db/Repositories/ElectricityBillRepository.cs
Claudio Schaad 7d7bd6073c 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 <noreply@anthropic.com>
2026-10-25 20:30:40 +01:00

56 lines
2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>
/// 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.
/// </summary>
public class ElectricityBillRepository : BaseRepository, IElectricityBillRepository
{
private const string ELECTRICITY = "electricity.json";
public ElectricityBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<ElectricityBillRepository> logger)
: base(settingsService, cache, logger)
{
}
public Task<List<ElectricityBill>> GetElectricityBillListAsync()
=> LoadListAsync<ElectricityBill>(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<ElectricityBill> 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);
}
}
}