AccountingNext/Schaad.Accounting.UI/Components/Pages/Dialogs/WaterHeatingBillDialog.razor.cs
Claudio Schaad 9a4f9a9010 Wasser & Heizung: remove the optional meter readings
The "Stand neu" fields for warm water, cold water and heat and their
continuity checks are gone; the per-mille, property total and price
checks stay. The "Kontrolle" heading is only shown when there is a check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:36:39 +01:00

109 lines
3.7 KiB
C#

using System.Globalization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.FluentUI.AspNetCore.Components;
using Schaad.Accounting.Interfaces;
using Schaad.Accounting.Models;
namespace Schaad.Accounting.UI.Components.Pages.Dialogs;
/// <summary>
/// NeoVac water and heating bill: consumption and per-mille shares from NeoVac, own costs from the
/// property manager's statement; the CHF parts are calculated (see <see cref="WaterHeatingBill.CalculateCosts"/>)
/// and checked (see <see cref="WaterHeatingBillChecks"/>).
/// </summary>
public partial class WaterHeatingBillDialog : ComponentBase
{
private static readonly CultureInfo SwissNumbers = CreateSwissNumbers();
private EditContext editContext = null!;
// FluentDatePicker needs DateTime?; the model stores DateOnly (see WaterHeatingBill).
private DateTime? periodFrom;
private DateTime? periodTo;
// The other bills, to find the previous one for the price checks.
private List<WaterHeatingBill> bills = [];
[CascadingParameter]
public FluentDialog Dialog { get; set; } = null!;
[Parameter]
public WaterHeatingBill Content { get; set; } = null!;
[Inject]
private IWaterHeatingBillRepository waterHeatingBillRepository { get; set; } = null!;
[Inject]
private IDialogService dialogService { get; set; } = null!;
protected override async Task OnInitializedAsync()
{
bills = await waterHeatingBillRepository.GetWaterHeatingBillListAsync();
periodFrom = Content.PeriodFrom == default ? null : Content.PeriodFrom.ToDateTime(TimeOnly.MinValue);
periodTo = Content.PeriodTo == default ? null : Content.PeriodTo.ToDateTime(TimeOnly.MinValue);
editContext = new EditContext(Content);
}
private IReadOnlyList<BillCheck> Checks
=> WaterHeatingBillChecks.Check(Content, WaterHeatingBillChecks.PreviousOf(bills, Content));
// Keeps the period on the bill up to date while editing, so the checks find the right
// previous bill.
private void SyncPeriod()
{
if (periodFrom is not null)
{
Content.PeriodFrom = DateOnly.FromDateTime(periodFrom.Value);
}
if (periodTo is not null)
{
Content.PeriodTo = DateOnly.FromDateTime(periodTo.Value);
}
}
private async Task SaveAsync()
{
if (periodFrom is null || periodTo is null)
{
return;
}
Content.PeriodFrom = DateOnly.FromDateTime(periodFrom.Value);
Content.PeriodTo = DateOnly.FromDateTime(periodTo.Value);
Content.CalculateCosts();
if (editContext.Validate())
{
await waterHeatingBillRepository.SaveWaterHeatingBillAsync(Content);
await Dialog.CloseAsync(Content);
}
}
private async Task CancelAsync()
{
await Dialog.CancelAsync();
}
private async Task ShowGuideAsync()
{
await dialogService.ShowDialogAsync(GuideImage, new DialogParameters()
{
Width = "680px",
Title = "Woher kommen die Werte?",
PreventDismissOnOverlayClick = true,
PreventScroll = true,
});
}
private static string M3(decimal value) => value.ToString("#,0.00", SwissNumbers) + " m³";
private static string Mwh(decimal value) => value.ToString("#,0.000", SwissNumbers) + " MWh";
private static string Chf(decimal value) => value.ToString("#,0.00", SwissNumbers) + " CHF";
private static CultureInfo CreateSwissNumbers()
{
var culture = new CultureInfo("de-CH");
culture.NumberFormat.NumberGroupSeparator = "'";
return culture;
}
}