AccountingNext/Schaad.Accounting.Db/Repositories/WaterHeatingBillRepository.cs
Claudio Schaad 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

56 lines
2 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>
/// 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);
}
}
}