AccountingNext/Schaad.Accounting.Common/Models/WaterBill.cs
Claudio Schaad eefbfff3eb Add "Wasser" page for the water bills (#11)
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
2026-10-30 20:19:07 +00:00

63 lines
2.1 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.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace Schaad.Accounting.Models
{
/// <summary>
/// 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).
/// </summary>
public class WaterBill : IPeriodBill<WaterBill>
{
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; }
/// <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>Warm water, cold water and base costs added up.</summary>
[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;
}
}
}