using System; using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; namespace Schaad.Accounting.Models { /// /// One water bill for the apartment. Like the electricity bills, these are stored once per /// mandator instead of per calendar year, because the billing period (e.g. 1 July – 30 June) /// doesn't align with calendar years (see WaterBillRepository in Schaad.Accounting.Db). /// public class WaterBill : IPeriodBill { public string Id { get; set; } [Display(Name = "Von")] [Required] public DateOnly PeriodFrom { get; set; } [Display(Name = "Bis")] [Required] public DateOnly PeriodTo { get; set; } [Display(Name = "Warmwasser")] public decimal WarmWaterM3 { get; set; } [Display(Name = "Kaltwasser")] public decimal ColdWaterM3 { get; set; } [Display(Name = "Warmwasser")] public decimal WarmWaterChf { get; set; } [Display(Name = "Kaltwasser")] public decimal ColdWaterChf { get; set; } [Display(Name = "Grundkosten")] public decimal BaseCostsChf { get; set; } /// Warm plus cold water, in m³. [JsonIgnore] [Display(Name = "Total")] public decimal TotalM3 => WarmWaterM3 + ColdWaterM3; /// Share of the consumption that was warm water, 0..1. [JsonIgnore] [Display(Name = "Warmwasser-Anteil")] public decimal WarmWaterShare => TotalM3 == 0 ? 0 : WarmWaterM3 / TotalM3; /// Warm water, cold water and base costs added up. [JsonIgnore] [Display(Name = "Total")] public decimal TotalChf => WarmWaterChf + ColdWaterChf + BaseCostsChf; public void AddShare(WaterBill other, decimal share) { WarmWaterM3 += other.WarmWaterM3 * share; ColdWaterM3 += other.ColdWaterM3 * share; WarmWaterChf += other.WarmWaterChf * share; ColdWaterChf += other.ColdWaterChf * share; BaseCostsChf += other.BaseCostsChf * share; } } }