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>
128 lines
5.3 KiB
C#
128 lines
5.3 KiB
C#
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; }
|
||
|
||
// 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;
|
||
}
|
||
}
|
||
}
|