Same layout as the Strom page: grid and dialog for the bills (warm and cold water in m3 and CHF, base costs; total m3 and CHF are computed), stored per mandator in water.json, and charts for consumption and total costs with the period toggle (bill, calendar year, half-year). The period grouping is now generic: ElectricityPeriod becomes BillPeriod<T> over IPeriodBill<T>, implemented by ElectricityBill and WaterBill. water.json can be edited in the JSON editor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
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>
|
|
/// Water 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 WaterBillRepository : BaseRepository, IWaterBillRepository
|
|
{
|
|
private const string WATER = "water.json";
|
|
|
|
public WaterBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<WaterBillRepository> logger)
|
|
: base(settingsService, cache, logger)
|
|
{
|
|
}
|
|
|
|
public Task<List<WaterBill>> GetWaterBillListAsync()
|
|
=> LoadListAsync<WaterBill>(settingsService.GetMandatorPath(), WATER);
|
|
|
|
public async Task SaveWaterBillAsync(WaterBill bill)
|
|
{
|
|
var bills = await GetWaterBillListAsync();
|
|
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);
|
|
}
|
|
|
|
public async Task<WaterBill> GetWaterBillAsync(string id)
|
|
{
|
|
var bills = await GetWaterBillListAsync();
|
|
return bills.FirstOrDefault(b => b.Id == id);
|
|
}
|
|
|
|
public async Task DeleteWaterBillAsync(string id)
|
|
{
|
|
var bills = await GetWaterBillListAsync();
|
|
bills.RemoveAll(b => b.Id == id);
|
|
await SaveAsync(bills, settingsService.GetMandatorPath(), WATER);
|
|
}
|
|
}
|
|
}
|