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>
87 lines
2.8 KiB
C#
87 lines
2.8 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"/>).
|
|
/// </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;
|
|
|
|
[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 void OnInitialized()
|
|
{
|
|
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 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;
|
|
}
|
|
}
|