Compare commits
No commits in common. "04bf48feb61494aeacef4e968054e08831f00502" and "c9a25481f2d87b49da236af5af01843bde002593" have entirely different histories.
04bf48feb6
...
c9a25481f2
44 changed files with 48 additions and 2128 deletions
10
CLAUDE.md
10
CLAUDE.md
|
|
@ -46,27 +46,21 @@ Data is multi-mandator and multi-year. The layout below `DataPath` (configured i
|
|||
|
||||
```
|
||||
{DataPath}/{mandator}/{year}/*.json data files
|
||||
{DataPath}/{mandator}/electricity.json electricity bills (not per year, see below)
|
||||
{DataPath}/{mandator}/water.json water bills (not per year, see below)
|
||||
{DataPath}/uploads/{mandator}/{year}/ imported bank statements (+ creditCard/)
|
||||
{DataPath}/backup/{mandator}/{year}/ backup zips
|
||||
```
|
||||
|
||||
When a new year is opened, the previous year's data is copied as the starting point.
|
||||
|
||||
`electricity.json` and `water.json` are the data files kept per mandator instead of per year (`ISettingsService.GetMandatorPath()`), because the NeoVac billing period runs 1 July–30 June and doesn't align with calendar years.
|
||||
|
||||
### Key services
|
||||
|
||||
- **ViewService** — aggregates account balances, applies FX rates, builds datasets for the UI
|
||||
- **FileService** — imports bank statements (MT940, CAMT053 via external `Schaad.Finance.dll`), parses PDFs, manages backups
|
||||
- **ChartService** — produces data for the Plotly booking-text charts on the transactions page
|
||||
- **SettingsService** — manages the active year, mandator, and file paths
|
||||
- **RawDataRepository** — plain-text load/save of the data files for the JSON editor page; validates (strict JSON, unique Ids, account references), refuses if the file changed since loading, and backs up the old version to `backup/{mandator}/{year}/json-{timestamp}/`; for `electricity.json` and `water.json` it reads/writes the mandator folder instead of the year folder
|
||||
- **RawDataRepository** — plain-text load/save of the data files for the JSON editor page; validates (strict JSON, unique Ids, account references), refuses if the file changed since loading, and backs up the old version to `backup/{mandator}/{year}/json-{timestamp}/`
|
||||
- **Texte bereinigen** page (`TextCleanup`) — edits only the `Text` of one account's bookings in the selected year (inline, search/replace via `TextReplacement`, bulk set); saves through `RawDataRepository.SaveTransactionTextsAsync`
|
||||
- **AnalyticsService** — loads all years of the current mandator (via `MultiYearRepository`) into an `AccountingAnalysis` (expenses, income, net, assets) for the Analyse page; queries run in memory
|
||||
- **Strom** page (`Electricity`, `/electricity`, under "Charts" in the menu) — grid and dialog (FluentDataGrid/`ElectricityBillDialog`) over `IElectricityBillRepository`'s `ElectricityBill` records (one yearly NeoVac bill each: kWh/CHF for grid and PV, side costs; `TotalKwh`, `PvShare`, `TotalChf`, `ChfPerKwh` are computed); three Chart.js charts via `ChartJsChart` (stacked kWh, CHF/kWh lines, total CHF), filtered by the shared `BillChartToolbar` (`BillChartFilter`): grouped per bill (default), calendar year or half-year (`BillPeriod<T>.FromBills` over `IPeriodBill<T>`; a bill reaching over several periods is spread evenly over its months and the page shows a note) and limited to a from/to year range (periods overlapping it are kept whole)
|
||||
- **Wasser** page (`Water`, `/water`, under "Charts" in the menu) — same layout as Strom over `IWaterBillRepository`'s `WaterBill` records (warm/cold water m³ and CHF, base costs; `TotalM3`, `WarmWaterShare`, `TotalChf` are computed); two charts (stacked m³, total CHF) with the same `BillChartToolbar`
|
||||
|
||||
### UI structure
|
||||
|
||||
|
|
@ -76,7 +70,7 @@ Pages live in `Schaad.Accounting.UI/Components/Pages/`. Each page typically has
|
|||
|
||||
- `Microsoft.FluentUI.AspNetCore.Components` — UI components (FluentDataGrid, FluentDialog, etc.)
|
||||
- `Plotly.Blazor` — charts on the older chart pages
|
||||
- `BlazorMonaco` — Monaco editor for the JSON editor page; loaded on demand by `wwwroot/js/monaco.js` instead of script tags in `App.razor`. Pages are interactive one by one, so `NavigationManager.NavigateTo` and menu links run enhanced navigation, which syncs `<head>` (removing Monaco's styles; `monaco.js` puts them back) and re-renders the page on the server. The editor therefore switches files in place and only rewrites the URL (`wwwroot/js/url.js`)
|
||||
- `BlazorMonaco` — Monaco editor for the JSON editor page; loaded on demand by `wwwroot/js/monaco.js` instead of script tags in `App.razor`
|
||||
- Chart.js 4 + `chartjs-chart-treemap` — charts on the Analyse page; vendored in `wwwroot/lib/` (no CDN), wrapped by `wwwroot/js/charts.js` and `ChartJsChart.razor`
|
||||
- `FreeSpire.PDF` — PDF parsing for bank statement imports
|
||||
- `Schaad.Finance.dll` / `Schaad.Finance.Api.dll` — proprietary DLLs for MT940/CAMT053 parsing and FX rate lookups (FixerIo API key in `appsettings.Development.json`)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Schaad.Accounting.Models;
|
||||
|
||||
namespace Schaad.Accounting.Interfaces
|
||||
{
|
||||
public interface IElectricityBillRepository
|
||||
{
|
||||
Task<List<ElectricityBill>> GetElectricityBillListAsync();
|
||||
|
||||
Task SaveElectricityBillAsync(ElectricityBill bill);
|
||||
|
||||
Task<ElectricityBill> GetElectricityBillAsync(string id);
|
||||
|
||||
Task DeleteElectricityBillAsync(string id);
|
||||
}
|
||||
}
|
||||
|
|
@ -26,12 +26,6 @@ namespace Schaad.Accounting.Interfaces
|
|||
|
||||
string GetLastYearDbPath();
|
||||
|
||||
/// <summary>
|
||||
/// The mandator's folder, above the per-year folders. For data that is not kept per
|
||||
/// year (e.g. the electricity and water bills, whose period doesn't align with calendar years).
|
||||
/// </summary>
|
||||
string GetMandatorPath();
|
||||
|
||||
SettingsDataset GetSettings();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Schaad.Accounting.Models;
|
||||
|
||||
namespace Schaad.Accounting.Interfaces
|
||||
{
|
||||
public interface IWaterBillRepository
|
||||
{
|
||||
Task<List<WaterBill>> GetWaterBillListAsync();
|
||||
|
||||
Task SaveWaterBillAsync(WaterBill bill);
|
||||
|
||||
Task<WaterBill> GetWaterBillAsync(string id);
|
||||
|
||||
Task DeleteWaterBillAsync(string id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Schaad.Accounting.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// What the charts on the Strom and Wasser pages show: how the bills are grouped and which
|
||||
/// years. A null <see cref="FromYear"/>/<see cref="ToYear"/> means from the first/to the last
|
||||
/// year with a bill, so a newly added bill shows up without touching the filter.
|
||||
/// </summary>
|
||||
public record BillChartFilter(BillPeriodKind Kind = BillPeriodKind.Bill, int? FromYear = null, int? ToYear = null)
|
||||
{
|
||||
/// <summary>The years any bill touches, from the first to the last; empty without bills.</summary>
|
||||
public static List<int> YearsOf<T>(IEnumerable<T> bills) where T : IPeriodBill<T>
|
||||
{
|
||||
var list = bills.ToList();
|
||||
if (list.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
var first = list.Min(b => b.PeriodFrom.Year);
|
||||
var last = list.Max(b => b.PeriodTo.Year);
|
||||
return Enumerable.Range(first, Math.Max(last - first, 0) + 1).ToList();
|
||||
}
|
||||
|
||||
/// <summary>The selected years, clamped to <paramref name="years"/> (which must not be empty).</summary>
|
||||
public (int From, int To) RangeIn(IReadOnlyList<int> years)
|
||||
{
|
||||
var from = Math.Clamp(FromYear ?? years[0], years[0], years[^1]);
|
||||
var to = Math.Clamp(ToYear ?? years[^1], years[0], years[^1]);
|
||||
return from <= to ? (from, to) : (to, from);
|
||||
}
|
||||
|
||||
/// <summary>True if the filter covers all of <paramref name="years"/>.</summary>
|
||||
public bool CoversAll(IReadOnlyList<int> years) => RangeIn(years) == (years[0], years[^1]);
|
||||
|
||||
/// <summary>
|
||||
/// Groups the bills by <see cref="Kind"/> and keeps the periods that overlap the selected
|
||||
/// years. A bill (or calendar period) reaching into the range is kept whole, e.g. the bill
|
||||
/// 1.7.2023–30.6.2024 for the range 2024–2024.
|
||||
/// </summary>
|
||||
public List<BillPeriod<T>> Apply<T>(IEnumerable<T> bills) where T : class, IPeriodBill<T>, new()
|
||||
{
|
||||
var list = bills.ToList();
|
||||
var years = YearsOf(list);
|
||||
if (years.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
var (from, to) = RangeIn(years);
|
||||
return BillPeriod<T>.FromBills(list, Kind)
|
||||
.Where(p => p.From.Year <= to && p.To.Year >= from)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Schaad.Accounting.Models
|
||||
{
|
||||
/// <summary>How bills are grouped for the charts on the Strom and Wasser pages.</summary>
|
||||
public enum BillPeriodKind
|
||||
{
|
||||
/// <summary>One entry per bill, exactly as entered.</summary>
|
||||
Bill,
|
||||
|
||||
/// <summary>One entry per calendar year.</summary>
|
||||
Year,
|
||||
|
||||
/// <summary>One entry per calendar half-year (January–June or July–December).</summary>
|
||||
HalfYear
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One period of bills, for the charts on the Strom and Wasser pages. <see cref="Bill"/> holds
|
||||
/// the bill values that fall into this period, or is null if no bill covers it.
|
||||
/// </summary>
|
||||
public class BillPeriod<T> where T : class, IPeriodBill<T>, new()
|
||||
{
|
||||
public BillPeriodKind Kind { get; init; }
|
||||
|
||||
public DateOnly From { get; init; }
|
||||
|
||||
public DateOnly To { get; init; }
|
||||
|
||||
public T Bill { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the values were (partly) spread from a bill whose period reaches beyond this one,
|
||||
/// i.e. they are estimated rather than billed.
|
||||
/// </summary>
|
||||
public bool IsSplit { get; init; }
|
||||
|
||||
/// <summary>Short label for a chart axis, e.g. "23/24", "2024" or "H2 23".</summary>
|
||||
public string Label => Kind switch
|
||||
{
|
||||
BillPeriodKind.Year => From.Year.ToString(),
|
||||
BillPeriodKind.HalfYear => $"H{(From.Month <= 6 ? 1 : 2)} {From:yy}",
|
||||
_ => IsWholeBillingYear ? $"{From:yy}/{To:yy}" : $"{From:dd.MM.yy}–{To:dd.MM.yy}"
|
||||
};
|
||||
|
||||
private bool IsWholeBillingYear => From.Day == 1 && To == From.AddYears(1).AddDays(-1);
|
||||
|
||||
/// <summary>
|
||||
/// Groups the bills by <paramref name="kind"/>. With <see cref="BillPeriodKind.Bill"/>
|
||||
/// each bill is its own period. Otherwise the result runs from the first to the last covered
|
||||
/// calendar period (periods in between that no bill covers are included with a null Bill),
|
||||
/// and a bill's values are spread evenly over the months of its period, so a yearly bill
|
||||
/// (1 July – 30 June) contributes exactly half to each of its two half-years or calendar years.
|
||||
/// </summary>
|
||||
public static List<BillPeriod<T>> FromBills(IEnumerable<T> bills, BillPeriodKind kind)
|
||||
{
|
||||
if (kind == BillPeriodKind.Bill)
|
||||
{
|
||||
return bills
|
||||
.OrderBy(b => b.PeriodFrom)
|
||||
.Select(b => new BillPeriod<T> { Kind = kind, From = b.PeriodFrom, To = b.PeriodTo, Bill = b })
|
||||
.ToList();
|
||||
}
|
||||
|
||||
var length = kind == BillPeriodKind.Year ? 12 : 6;
|
||||
var sums = new SortedDictionary<DateOnly, T>();
|
||||
var split = new HashSet<DateOnly>();
|
||||
foreach (var bill in bills)
|
||||
{
|
||||
var months = MonthIndex(bill.PeriodTo) - MonthIndex(bill.PeriodFrom) + 1;
|
||||
if (months <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var monthsPerPeriod = Enumerable.Range(0, months)
|
||||
.Select(m => PeriodStart(bill.PeriodFrom.AddMonths(m), length))
|
||||
.GroupBy(start => start)
|
||||
.ToList();
|
||||
foreach (var period in monthsPerPeriod)
|
||||
{
|
||||
var share = (decimal)period.Count() / months;
|
||||
if (!sums.TryGetValue(period.Key, out var sum))
|
||||
{
|
||||
sum = new T { PeriodFrom = period.Key, PeriodTo = period.Key.AddMonths(length).AddDays(-1) };
|
||||
sums[period.Key] = sum;
|
||||
}
|
||||
if (monthsPerPeriod.Count > 1)
|
||||
{
|
||||
split.Add(period.Key);
|
||||
}
|
||||
sum.AddShare(bill, share);
|
||||
}
|
||||
}
|
||||
|
||||
var result = new List<BillPeriod<T>>();
|
||||
if (sums.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
for (var start = sums.Keys.First(); start <= sums.Keys.Last(); start = start.AddMonths(length))
|
||||
{
|
||||
result.Add(new BillPeriod<T>
|
||||
{
|
||||
Kind = kind,
|
||||
From = start,
|
||||
To = start.AddMonths(length).AddDays(-1),
|
||||
Bill = sums.GetValueOrDefault(start),
|
||||
IsSplit = split.Contains(start)
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int MonthIndex(DateOnly date) => date.Year * 12 + date.Month - 1;
|
||||
|
||||
private static DateOnly PeriodStart(DateOnly date, int length) => new(date.Year, (date.Month - 1) / length * length + 1, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Schaad.Accounting.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// One yearly NeoVac electricity bill for the apartment. The billing period runs
|
||||
/// 1 July – 30 June, so these are not stored per calendar year like the other data files
|
||||
/// (see ElectricityBillRepository in Schaad.Accounting.Db).
|
||||
/// </summary>
|
||||
public class ElectricityBill : IPeriodBill<ElectricityBill>
|
||||
{
|
||||
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 = "Netzbezug")]
|
||||
public decimal GridKwh { get; set; }
|
||||
|
||||
[Display(Name = "PV-Produktion")]
|
||||
public decimal PvKwh { get; set; }
|
||||
|
||||
[Display(Name = "Netzbezug")]
|
||||
public decimal GridChf { get; set; }
|
||||
|
||||
[Display(Name = "PV")]
|
||||
public decimal PvChf { get; set; }
|
||||
|
||||
[Display(Name = "Nebenkosten")]
|
||||
public decimal SideCostsChf { get; set; }
|
||||
|
||||
/// <summary>Grid draw plus own PV consumption, in kWh.</summary>
|
||||
[JsonIgnore]
|
||||
[Display(Name = "Total")]
|
||||
public decimal TotalKwh => GridKwh + PvKwh;
|
||||
|
||||
/// <summary>Share of the consumption covered by PV, 0..1.</summary>
|
||||
[JsonIgnore]
|
||||
[Display(Name = "PV-Anteil")]
|
||||
public decimal PvShare => TotalKwh == 0 ? 0 : PvKwh / TotalKwh;
|
||||
|
||||
/// <summary>Grid, PV and side costs added up.</summary>
|
||||
[JsonIgnore]
|
||||
[Display(Name = "Total")]
|
||||
public decimal TotalChf => GridChf + PvChf + SideCostsChf;
|
||||
|
||||
/// <summary>Average price per kWh over the whole period.</summary>
|
||||
[JsonIgnore]
|
||||
[Display(Name = "CHF/kWh")]
|
||||
public decimal ChfPerKwh => TotalKwh == 0 ? 0 : TotalChf / TotalKwh;
|
||||
|
||||
/// <summary>Price per kWh of grid electricity; null if there was no grid draw.</summary>
|
||||
[JsonIgnore]
|
||||
[Display(Name = "CHF/kWh Netz")]
|
||||
public decimal? GridChfPerKwh => GridKwh == 0 ? null : GridChf / GridKwh;
|
||||
|
||||
/// <summary>Price per kWh of PV electricity; null if there was no PV consumption.</summary>
|
||||
[JsonIgnore]
|
||||
[Display(Name = "CHF/kWh PV")]
|
||||
public decimal? PvChfPerKwh => PvKwh == 0 ? null : PvChf / PvKwh;
|
||||
|
||||
public void AddShare(ElectricityBill other, decimal share)
|
||||
{
|
||||
GridKwh += other.GridKwh * share;
|
||||
PvKwh += other.PvKwh * share;
|
||||
GridChf += other.GridChf * share;
|
||||
PvChf += other.PvChf * share;
|
||||
SideCostsChf += other.SideCostsChf * share;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace Schaad.Accounting.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A bill over a period (e.g. the yearly NeoVac electricity or water bill), so it can be
|
||||
/// grouped into calendar periods by <see cref="BillPeriod{T}"/>.
|
||||
/// </summary>
|
||||
public interface IPeriodBill<in T>
|
||||
{
|
||||
DateOnly PeriodFrom { get; set; }
|
||||
|
||||
DateOnly PeriodTo { get; set; }
|
||||
|
||||
/// <summary>Adds <paramref name="share"/> (0..1) of the other bill's values to this one.</summary>
|
||||
void AddShare(T other, decimal share);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,16 +78,9 @@ namespace Schaad.Accounting.Repositories
|
|||
/// renames it, so a crash mid-write leaves the previous file intact. Invalidates
|
||||
/// the corresponding cache entry.
|
||||
/// </summary>
|
||||
protected Task SaveAsync<T>(T obj, string fileName)
|
||||
=> SaveAsync(obj, settingsService.GetDbPath(), fileName);
|
||||
|
||||
/// <summary>
|
||||
/// Same as <see cref="SaveAsync{T}(T,string)"/> for a file in any data directory (e.g.
|
||||
/// the mandator's folder instead of a year below it).
|
||||
/// </summary>
|
||||
protected async Task SaveAsync<T>(T obj, string directory, string fileName)
|
||||
protected async Task SaveAsync<T>(T obj, string fileName)
|
||||
{
|
||||
var filePath = Path.Combine(directory, fileName);
|
||||
var filePath = Path.Combine(settingsService.GetDbPath(), fileName);
|
||||
var tmpPath = filePath + ".tmp";
|
||||
|
||||
var semaphore = GetLock(filePath);
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Schaad.Accounting.Interfaces;
|
||||
using Schaad.Accounting.Models;
|
||||
|
||||
namespace Schaad.Accounting.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// Electricity bills of the current mandator, stored once per mandator (not per year like
|
||||
/// the other data files) because the billing period runs 1 July – 30 June.
|
||||
/// </summary>
|
||||
public class ElectricityBillRepository : BaseRepository, IElectricityBillRepository
|
||||
{
|
||||
private const string ELECTRICITY = "electricity.json";
|
||||
|
||||
public ElectricityBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<ElectricityBillRepository> logger)
|
||||
: base(settingsService, cache, logger)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<List<ElectricityBill>> GetElectricityBillListAsync()
|
||||
=> LoadListAsync<ElectricityBill>(settingsService.GetMandatorPath(), ELECTRICITY);
|
||||
|
||||
public async Task SaveElectricityBillAsync(ElectricityBill bill)
|
||||
{
|
||||
var bills = await GetElectricityBillListAsync();
|
||||
var idx = bills.FindIndex(b => b.Id == bill.Id);
|
||||
if (idx >= 0)
|
||||
{
|
||||
bills[idx] = bill;
|
||||
}
|
||||
else
|
||||
{
|
||||
bill.Id = Guid.NewGuid().ToString();
|
||||
bills.Add(bill);
|
||||
}
|
||||
await SaveAsync(bills, settingsService.GetMandatorPath(), ELECTRICITY);
|
||||
}
|
||||
|
||||
public async Task<ElectricityBill> GetElectricityBillAsync(string id)
|
||||
{
|
||||
var bills = await GetElectricityBillListAsync();
|
||||
return bills.FirstOrDefault(b => b.Id == id);
|
||||
}
|
||||
|
||||
public async Task DeleteElectricityBillAsync(string id)
|
||||
{
|
||||
var bills = await GetElectricityBillListAsync();
|
||||
bills.RemoveAll(b => b.Id == id);
|
||||
await SaveAsync(bills, settingsService.GetMandatorPath(), ELECTRICITY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -25,8 +25,6 @@ namespace Schaad.Accounting.Repositories
|
|||
{
|
||||
private const string ACCOUNTS = "Accounts.json";
|
||||
private const string TRANSACTIONS = "Transactions.json";
|
||||
private const string ELECTRICITY = "electricity.json";
|
||||
private const string WATER = "water.json";
|
||||
private const int MaxErrors = 20;
|
||||
|
||||
// Like the normal options, but property names that don't exist (typos) are errors instead
|
||||
|
|
@ -49,9 +47,7 @@ namespace Schaad.Accounting.Repositories
|
|||
"BookingRules.json",
|
||||
"BookingTexts.json",
|
||||
"SplitPredefinitions.json",
|
||||
"SubClasses.json",
|
||||
ELECTRICITY,
|
||||
WATER
|
||||
"SubClasses.json"
|
||||
];
|
||||
|
||||
public async Task<RawDataFile> LoadAsync(string fileName)
|
||||
|
|
@ -70,8 +66,6 @@ namespace Schaad.Accounting.Repositories
|
|||
"BookingTexts.json" => SaveAsync<BookingText>(fileName, text, loadedHash),
|
||||
"SplitPredefinitions.json" => SaveAsync<SplitPredefinition>(fileName, text, loadedHash),
|
||||
"SubClasses.json" => SaveAsync<SubClass>(fileName, text, loadedHash),
|
||||
ELECTRICITY => SaveAsync<ElectricityBill>(fileName, text, loadedHash),
|
||||
WATER => SaveAsync<WaterBill>(fileName, text, loadedHash),
|
||||
_ => throw new ArgumentException($"Unknown data file '{fileName}'", nameof(fileName))
|
||||
};
|
||||
|
||||
|
|
@ -112,7 +106,7 @@ namespace Schaad.Accounting.Repositories
|
|||
}
|
||||
|
||||
var backupPath = await BackupAsync(current);
|
||||
await SaveAsync(items, DirectoryOf(fileName), fileName);
|
||||
await SaveAsync(items, fileName);
|
||||
logger.LogInformation("Saved {FilePath} from the JSON editor; previous version in {BackupPath}", current.Path, backupPath);
|
||||
|
||||
return new RawDataSaveResult([], await LoadAsync(fileName), backupPath);
|
||||
|
|
@ -239,14 +233,9 @@ namespace Schaad.Accounting.Repositories
|
|||
{
|
||||
throw new ArgumentException($"Unknown data file '{fileName}'", nameof(fileName));
|
||||
}
|
||||
return Path.Combine(DirectoryOf(fileName), fileName);
|
||||
return Path.Combine(settingsService.GetDbPath(), fileName);
|
||||
}
|
||||
|
||||
// electricity.json and water.json live at the mandator level, not per year (their period
|
||||
// runs 1 July – 30 June, so it doesn't align with calendar years).
|
||||
private string DirectoryOf(string fileName)
|
||||
=> fileName is ELECTRICITY or WATER ? settingsService.GetMandatorPath() : settingsService.GetDbPath();
|
||||
|
||||
private static string Hash(byte[] bytes) => Convert.ToHexString(SHA256.HashData(bytes));
|
||||
|
||||
private static string Describe(JsonException ex)
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Schaad.Accounting.Interfaces;
|
||||
using Schaad.Accounting.Models;
|
||||
|
||||
namespace Schaad.Accounting.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// Water bills of the current mandator, stored once per mandator (not per year like the
|
||||
/// other data files) because the billing period doesn't align with calendar years.
|
||||
/// </summary>
|
||||
public class WaterBillRepository : BaseRepository, IWaterBillRepository
|
||||
{
|
||||
private const string WATER = "water.json";
|
||||
|
||||
public WaterBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<WaterBillRepository> logger)
|
||||
: base(settingsService, cache, logger)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<List<WaterBill>> GetWaterBillListAsync()
|
||||
=> LoadListAsync<WaterBill>(settingsService.GetMandatorPath(), WATER);
|
||||
|
||||
public async Task SaveWaterBillAsync(WaterBill bill)
|
||||
{
|
||||
var bills = await GetWaterBillListAsync();
|
||||
var idx = bills.FindIndex(b => b.Id == bill.Id);
|
||||
if (idx >= 0)
|
||||
{
|
||||
bills[idx] = bill;
|
||||
}
|
||||
else
|
||||
{
|
||||
bill.Id = Guid.NewGuid().ToString();
|
||||
bills.Add(bill);
|
||||
}
|
||||
await SaveAsync(bills, settingsService.GetMandatorPath(), WATER);
|
||||
}
|
||||
|
||||
public async Task<WaterBill> GetWaterBillAsync(string id)
|
||||
{
|
||||
var bills = await GetWaterBillListAsync();
|
||||
return bills.FirstOrDefault(b => b.Id == id);
|
||||
}
|
||||
|
||||
public async Task DeleteWaterBillAsync(string id)
|
||||
{
|
||||
var bills = await GetWaterBillListAsync();
|
||||
bills.RemoveAll(b => b.Id == id);
|
||||
await SaveAsync(bills, settingsService.GetMandatorPath(), WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,11 +94,6 @@ namespace Schaad.Accounting.Services
|
|||
return EnsureDirectory(Path.Combine(GetSettings().DataPath, mandator, (year - 1).ToString()));
|
||||
}
|
||||
|
||||
public string GetMandatorPath()
|
||||
{
|
||||
return EnsureDirectory(Path.Combine(GetSettings().DataPath, mandator));
|
||||
}
|
||||
|
||||
public SettingsDataset GetSettings()
|
||||
{
|
||||
return settingsDataset;
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
using Schaad.Accounting.Models;
|
||||
using Shouldly;
|
||||
|
||||
namespace Schaad.Accounting.Tests;
|
||||
|
||||
public class BillChartFilterTestShould
|
||||
{
|
||||
[Fact]
|
||||
public void ListEveryYearFromFirstToLastBillWhenGettingYears()
|
||||
{
|
||||
BillChartFilter.YearsOf([YearlyBill(2025), YearlyBill(2022)]).ShouldBe([2022, 2023, 2024, 2025, 2026]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnNoYearsWhenThereAreNoBills()
|
||||
{
|
||||
BillChartFilter.YearsOf<ElectricityBill>([]).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CoverAllYearsWhenNoYearIsSelected()
|
||||
{
|
||||
var filter = new BillChartFilter();
|
||||
|
||||
filter.RangeIn([2022, 2023, 2024]).ShouldBe((2022, 2024));
|
||||
filter.CoversAll([2022, 2023, 2024]).ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClampSelectedYearsWhenTheyAreOutsideTheAvailableYears()
|
||||
{
|
||||
var filter = new BillChartFilter(FromYear: 2019, ToYear: 2030);
|
||||
|
||||
filter.RangeIn([2022, 2023, 2024]).ShouldBe((2022, 2024));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SwapYearsWhenFromIsAfterTo()
|
||||
{
|
||||
var filter = new BillChartFilter(FromYear: 2024, ToYear: 2022);
|
||||
|
||||
filter.RangeIn([2021, 2022, 2023, 2024]).ShouldBe((2022, 2024));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeepBillsOverlappingTheRangeWhenGroupingPerBill()
|
||||
{
|
||||
var filter = new BillChartFilter(BillPeriodKind.Bill, 2024, 2024);
|
||||
|
||||
var periods = filter.Apply([YearlyBill(2022), YearlyBill(2023), YearlyBill(2024), YearlyBill(2025)]);
|
||||
|
||||
periods.Select(p => p.Label).ShouldBe(["23/24", "24/25"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeepOnlyPeriodsInsideTheRangeWhenGroupingPerHalfYear()
|
||||
{
|
||||
var filter = new BillChartFilter(BillPeriodKind.HalfYear, 2024, 2024);
|
||||
|
||||
var periods = filter.Apply([YearlyBill(2023), YearlyBill(2024)]);
|
||||
|
||||
periods.Select(p => p.Label).ShouldBe(["H1 24", "H2 24"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeepEmptyPeriodsInsideTheRangeWhenNoBillCoversThem()
|
||||
{
|
||||
var filter = new BillChartFilter(BillPeriodKind.Year, 2023, 2025);
|
||||
|
||||
var periods = filter.Apply([Bill(new DateOnly(2022, 1, 1), new DateOnly(2022, 12, 31)), Bill(new DateOnly(2026, 1, 1), new DateOnly(2026, 12, 31))]);
|
||||
|
||||
periods.Select(p => p.Label).ShouldBe(["2023", "2024", "2025"]);
|
||||
periods.ShouldAllBe(p => p.Bill == null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnNoPeriodsWhenThereAreNoBills()
|
||||
{
|
||||
new BillChartFilter().Apply<WaterBill>([]).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
private static ElectricityBill YearlyBill(int startYear) => Bill(new DateOnly(startYear, 7, 1), new DateOnly(startYear + 1, 6, 30));
|
||||
|
||||
private static ElectricityBill Bill(DateOnly from, DateOnly to) => new() { PeriodFrom = from, PeriodTo = to };
|
||||
}
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
using Schaad.Accounting.Models;
|
||||
using Shouldly;
|
||||
|
||||
namespace Schaad.Accounting.Tests;
|
||||
|
||||
public class BillPeriodTestShould
|
||||
{
|
||||
[Fact]
|
||||
public void KeepEachBillUnchangedWhenGroupingPerBill()
|
||||
{
|
||||
var later = YearlyBill(2024);
|
||||
var first = YearlyBill(2023);
|
||||
|
||||
var periods = BillPeriod<ElectricityBill>.FromBills([later, first], BillPeriodKind.Bill);
|
||||
|
||||
periods.Select(p => p.Bill).ShouldBe([first, later]);
|
||||
periods.ShouldAllBe(p => !p.IsSplit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LabelBillAsBillingYearWhenItCoversAWholeYear()
|
||||
{
|
||||
var periods = BillPeriod<ElectricityBill>.FromBills([YearlyBill(2023)], BillPeriodKind.Bill);
|
||||
|
||||
periods[0].Label.ShouldBe("23/24");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LabelBillWithDatesWhenItIsNotAWholeYear()
|
||||
{
|
||||
var bill = Bill(new DateOnly(2024, 1, 1), new DateOnly(2024, 6, 30));
|
||||
|
||||
var periods = BillPeriod<ElectricityBill>.FromBills([bill], BillPeriodKind.Bill);
|
||||
|
||||
periods[0].Label.ShouldBe("01.01.24–30.06.24");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplitYearlyBillIntoTwoHalvesWhenPeriodRunsJulyToJune()
|
||||
{
|
||||
var bill = YearlyBill(2023);
|
||||
bill.GridKwh = 3000m;
|
||||
bill.PvKwh = 2000m;
|
||||
bill.GridChf = 900m;
|
||||
bill.PvChf = 400m;
|
||||
bill.SideCostsChf = 100m;
|
||||
|
||||
var halves = BillPeriod<ElectricityBill>.FromBills([bill], BillPeriodKind.HalfYear);
|
||||
|
||||
halves.Count.ShouldBe(2);
|
||||
halves[0].From.ShouldBe(new DateOnly(2023, 7, 1));
|
||||
halves[1].From.ShouldBe(new DateOnly(2024, 1, 1));
|
||||
foreach (var half in halves)
|
||||
{
|
||||
half.IsSplit.ShouldBeTrue();
|
||||
half.Bill.GridKwh.ShouldBe(1500m);
|
||||
half.Bill.PvKwh.ShouldBe(1000m);
|
||||
half.Bill.GridChf.ShouldBe(450m);
|
||||
half.Bill.PvChf.ShouldBe(200m);
|
||||
half.Bill.SideCostsChf.ShouldBe(50m);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplitYearlyBillIntoTwoCalendarYearsWhenPeriodRunsJulyToJune()
|
||||
{
|
||||
var first = YearlyBill(2023);
|
||||
first.GridKwh = 3000m;
|
||||
var second = YearlyBill(2024);
|
||||
second.GridKwh = 5000m;
|
||||
|
||||
var years = BillPeriod<ElectricityBill>.FromBills([first, second], BillPeriodKind.Year);
|
||||
|
||||
years.Select(y => y.Label).ShouldBe(["2023", "2024", "2025"]);
|
||||
years.Select(y => y.Bill.GridKwh).ShouldBe([1500m, 4000m, 2500m]);
|
||||
years.ShouldAllBe(y => y.IsSplit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SplitWaterBillIntoTwoHalvesWhenPeriodRunsJulyToJune()
|
||||
{
|
||||
var bill = new WaterBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), WarmWaterM3 = 10m, ColdWaterM3 = 30m, BaseCostsChf = 200m };
|
||||
|
||||
var halves = BillPeriod<WaterBill>.FromBills([bill], BillPeriodKind.HalfYear);
|
||||
|
||||
halves.Select(h => h.Label).ShouldBe(["H2 23", "H1 24"]);
|
||||
halves.ShouldAllBe(h => h.Bill.WarmWaterM3 == 5m && h.Bill.ColdWaterM3 == 15m && h.Bill.BaseCostsChf == 100m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeepPricePerKwhOfTheBillWhenSplittingIt()
|
||||
{
|
||||
var bill = YearlyBill(2023);
|
||||
bill.GridKwh = 3000m;
|
||||
bill.GridChf = 900m;
|
||||
|
||||
var halves = BillPeriod<ElectricityBill>.FromBills([bill], BillPeriodKind.HalfYear);
|
||||
|
||||
halves.ShouldAllBe(h => h.Bill.GridChfPerKwh == 0.3m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddUpBillsWithoutSplittingWhenTheyShareAPeriod()
|
||||
{
|
||||
var first = Bill(new DateOnly(2024, 1, 1), new DateOnly(2024, 3, 31));
|
||||
first.GridKwh = 100m;
|
||||
var second = Bill(new DateOnly(2024, 4, 1), new DateOnly(2024, 6, 30));
|
||||
second.GridKwh = 200m;
|
||||
|
||||
var halves = BillPeriod<ElectricityBill>.FromBills([first, second], BillPeriodKind.HalfYear);
|
||||
|
||||
halves.Count.ShouldBe(1);
|
||||
halves[0].Bill.GridKwh.ShouldBe(300m);
|
||||
halves[0].IsSplit.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IncludeEmptyHalfYearWhenNoBillCoversIt()
|
||||
{
|
||||
var first = YearlyBill(2022);
|
||||
var later = YearlyBill(2024);
|
||||
|
||||
var halves = BillPeriod<ElectricityBill>.FromBills([later, first], BillPeriodKind.HalfYear);
|
||||
|
||||
halves.Select(h => h.Label).ShouldBe(["H2 22", "H1 23", "H2 23", "H1 24", "H2 24", "H1 25"]);
|
||||
halves[2].Bill.ShouldBeNull();
|
||||
halves[3].Bill.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(BillPeriodKind.Bill)]
|
||||
[InlineData(BillPeriodKind.Year)]
|
||||
[InlineData(BillPeriodKind.HalfYear)]
|
||||
public void ReturnEmptyListWhenThereAreNoBills(BillPeriodKind kind)
|
||||
{
|
||||
BillPeriod<ElectricityBill>.FromBills([], kind).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
private static ElectricityBill YearlyBill(int startYear) => Bill(new DateOnly(startYear, 7, 1), new DateOnly(startYear + 1, 6, 30));
|
||||
|
||||
private static ElectricityBill Bill(DateOnly from, DateOnly to) => new() { PeriodFrom = from, PeriodTo = to };
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
using Schaad.Accounting.Interfaces;
|
||||
using Schaad.Accounting.Models;
|
||||
using Schaad.Accounting.Repositories;
|
||||
using Shouldly;
|
||||
|
||||
namespace Schaad.Accounting.Tests;
|
||||
|
||||
public class ElectricityBillRepositoryTestShould : IDisposable
|
||||
{
|
||||
private readonly string mandatorDir;
|
||||
private readonly ISettingsService settingsService;
|
||||
private readonly ElectricityBillRepository sut;
|
||||
|
||||
public ElectricityBillRepositoryTestShould()
|
||||
{
|
||||
mandatorDir = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(mandatorDir);
|
||||
|
||||
settingsService = Substitute.For<ISettingsService>();
|
||||
settingsService.GetMandatorPath().Returns(mandatorDir);
|
||||
|
||||
sut = new ElectricityBillRepository(settingsService, new RepositoryCache(), NullLogger<ElectricityBillRepository>.Instance);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(mandatorDir))
|
||||
{
|
||||
Directory.Delete(mandatorDir, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReturnEmptyListWhenFileDoesNotExistYet()
|
||||
{
|
||||
(await sut.GetElectricityBillListAsync()).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AssignNewIdWhenSavingBillWithoutId()
|
||||
{
|
||||
var bill = new ElectricityBill
|
||||
{
|
||||
PeriodFrom = new DateOnly(2023, 7, 1),
|
||||
PeriodTo = new DateOnly(2024, 6, 30),
|
||||
GridKwh = 3419.432m,
|
||||
PvKwh = 1936.328m,
|
||||
GridChf = 1009.55m,
|
||||
PvChf = 544.10m,
|
||||
SideCostsChf = 134.30m
|
||||
};
|
||||
|
||||
await sut.SaveElectricityBillAsync(bill);
|
||||
|
||||
var stored = (await sut.GetElectricityBillListAsync()).Single();
|
||||
stored.Id.ShouldNotBeNullOrEmpty();
|
||||
stored.TotalChf.ShouldBe(1687.95m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateInPlaceWhenSavingBillWithExistingId()
|
||||
{
|
||||
await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), GridKwh = 1000m });
|
||||
var id = (await sut.GetElectricityBillListAsync()).Single().Id;
|
||||
|
||||
await sut.SaveElectricityBillAsync(new ElectricityBill { Id = id, PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), GridKwh = 1300m });
|
||||
|
||||
var bills = await sut.GetElectricityBillListAsync();
|
||||
bills.Count.ShouldBe(1);
|
||||
bills[0].GridKwh.ShouldBe(1300m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveBillWhenDeletingById()
|
||||
{
|
||||
await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) });
|
||||
var id = (await sut.GetElectricityBillListAsync()).Single().Id;
|
||||
|
||||
await sut.DeleteElectricityBillAsync(id);
|
||||
|
||||
(await sut.GetElectricityBillListAsync()).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StoreFileDirectlyInMandatorFolderWithoutYearSubfolder()
|
||||
{
|
||||
await sut.SaveElectricityBillAsync(new ElectricityBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) });
|
||||
|
||||
File.Exists(Path.Combine(mandatorDir, "electricity.json")).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
using Schaad.Accounting.Models;
|
||||
using Shouldly;
|
||||
|
||||
namespace Schaad.Accounting.Tests;
|
||||
|
||||
public class ElectricityBillTestShould
|
||||
{
|
||||
[Fact]
|
||||
public void AddGridAndPvWhenCalculatingTotalKwh()
|
||||
{
|
||||
var bill = new ElectricityBill { GridKwh = 3419.432m, PvKwh = 1936.328m };
|
||||
|
||||
bill.TotalKwh.ShouldBe(5355.76m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DividePvByTotalWhenCalculatingPvShare()
|
||||
{
|
||||
var bill = new ElectricityBill { GridKwh = 600m, PvKwh = 400m };
|
||||
|
||||
bill.PvShare.ShouldBe(0.4m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnZeroPvShareWhenThereIsNoConsumption()
|
||||
{
|
||||
var bill = new ElectricityBill { GridKwh = 0m, PvKwh = 0m };
|
||||
|
||||
bill.PvShare.ShouldBe(0m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddGridPvAndSideCostsWhenCalculatingTotalChf()
|
||||
{
|
||||
var bill = new ElectricityBill { GridChf = 1009.55m, PvChf = 544.10m, SideCostsChf = 134.30m };
|
||||
|
||||
bill.TotalChf.ShouldBe(1687.95m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DivideTotalChfByTotalKwhWhenCalculatingChfPerKwh()
|
||||
{
|
||||
var bill = new ElectricityBill { GridKwh = 600m, PvKwh = 400m, GridChf = 60m, PvChf = 40m };
|
||||
|
||||
bill.ChfPerKwh.ShouldBe(0.1m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnZeroChfPerKwhWhenThereIsNoConsumption()
|
||||
{
|
||||
var bill = new ElectricityBill { GridKwh = 0m, PvKwh = 0m, GridChf = 0m, PvChf = 0m, SideCostsChf = 50m };
|
||||
|
||||
bill.ChfPerKwh.ShouldBe(0m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DivideGridChfByGridKwhWhenCalculatingGridChfPerKwh()
|
||||
{
|
||||
var bill = new ElectricityBill { GridKwh = 600m, GridChf = 180m };
|
||||
|
||||
bill.GridChfPerKwh.ShouldBe(0.3m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnNullGridChfPerKwhWhenThereWasNoGridDraw()
|
||||
{
|
||||
var bill = new ElectricityBill { GridKwh = 0m, GridChf = 0m };
|
||||
|
||||
bill.GridChfPerKwh.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DividePvChfByPvKwhWhenCalculatingPvChfPerKwh()
|
||||
{
|
||||
var bill = new ElectricityBill { PvKwh = 400m, PvChf = 100m };
|
||||
|
||||
bill.PvChfPerKwh.ShouldBe(0.25m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnNullPvChfPerKwhWhenThereWasNoPvConsumption()
|
||||
{
|
||||
var bill = new ElectricityBill { PvKwh = 0m, PvChf = 0m };
|
||||
|
||||
bill.PvChfPerKwh.ShouldBeNull();
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,6 @@ public class RawDataRepositoryTestShould : IDisposable
|
|||
|
||||
private readonly string dataPath;
|
||||
private readonly string dbDir;
|
||||
private readonly string mandatorDir;
|
||||
private readonly RepositoryCache cache = new();
|
||||
private readonly ISettingsService settingsService;
|
||||
private readonly RawDataRepository sut;
|
||||
|
|
@ -32,8 +31,7 @@ public class RawDataRepositoryTestShould : IDisposable
|
|||
public RawDataRepositoryTestShould()
|
||||
{
|
||||
dataPath = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N"));
|
||||
mandatorDir = Path.Combine(dataPath, "Mandator");
|
||||
dbDir = Path.Combine(mandatorDir, "2026");
|
||||
dbDir = Path.Combine(dataPath, "Mandator", "2026");
|
||||
Directory.CreateDirectory(dbDir);
|
||||
File.WriteAllText(Path.Combine(dbDir, "Accounts.json"), Accounts);
|
||||
File.WriteAllText(Path.Combine(dbDir, "Transactions.json"), Transactions);
|
||||
|
|
@ -41,7 +39,6 @@ public class RawDataRepositoryTestShould : IDisposable
|
|||
settingsService = Substitute.For<ISettingsService>();
|
||||
settingsService.GetDbPath().Returns(dbDir);
|
||||
settingsService.GetLastYearDbPath().Returns(Path.Combine(dataPath, "no-such-dir"));
|
||||
settingsService.GetMandatorPath().Returns(mandatorDir);
|
||||
settingsService.GetSettings().Returns(new SettingsDataset { DataPath = dataPath });
|
||||
settingsService.GetMandator().Returns("Mandator");
|
||||
settingsService.GetYear().Returns(2026);
|
||||
|
|
@ -172,42 +169,6 @@ public class RawDataRepositoryTestShould : IDisposable
|
|||
File.ReadAllText(Path.Combine(dbDir, "Transactions.json")).ShouldContain("13");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAndWriteElectricityFileInMandatorFolderNotYearFolderWhenEditing()
|
||||
{
|
||||
File.WriteAllText(Path.Combine(mandatorDir, "electricity.json"), """
|
||||
[ { "Id": "e1", "PeriodFrom": "2023-07-01", "PeriodTo": "2024-06-30", "GridKwh": 100 } ]
|
||||
""");
|
||||
var loaded = await sut.LoadAsync("electricity.json");
|
||||
loaded.Text.ShouldContain("\"GridKwh\": 100");
|
||||
|
||||
var result = await sut.SaveAsync("electricity.json", loaded.Text.Replace("100", "150"), loaded.Hash);
|
||||
|
||||
result.Errors.ShouldBeEmpty();
|
||||
result.Saved.ShouldBeTrue();
|
||||
File.Exists(Path.Combine(mandatorDir, "electricity.json")).ShouldBeTrue();
|
||||
File.ReadAllText(Path.Combine(mandatorDir, "electricity.json")).ShouldContain("150");
|
||||
File.Exists(Path.Combine(dbDir, "electricity.json")).ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAndWriteWaterFileInMandatorFolderNotYearFolderWhenEditing()
|
||||
{
|
||||
File.WriteAllText(Path.Combine(mandatorDir, "water.json"), """
|
||||
[ { "Id": "w1", "PeriodFrom": "2023-07-01", "PeriodTo": "2024-06-30", "WarmWaterM3": 100 } ]
|
||||
""");
|
||||
var loaded = await sut.LoadAsync("water.json");
|
||||
loaded.Text.ShouldContain("\"WarmWaterM3\": 100");
|
||||
|
||||
var result = await sut.SaveAsync("water.json", loaded.Text.Replace("100", "150"), loaded.Hash);
|
||||
|
||||
result.Errors.ShouldBeEmpty();
|
||||
result.Saved.ShouldBeTrue();
|
||||
File.Exists(Path.Combine(mandatorDir, "water.json")).ShouldBeTrue();
|
||||
File.ReadAllText(Path.Combine(mandatorDir, "water.json")).ShouldContain("150");
|
||||
File.Exists(Path.Combine(dbDir, "water.json")).ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RejectUnknownFileNameWhenLoading()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,12 +33,6 @@ public class SettingsServiceTestShould : IDisposable
|
|||
sut.GetLastYearDbPath().ShouldBe(Path.Combine(dataPath, "Mandator", "2024"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnMandatorFolderWithoutYearWhenGettingMandatorPath()
|
||||
{
|
||||
sut.GetMandatorPath().ShouldBe(Path.Combine(dataPath, "Mandator"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnFoldersBelowRootUploadsWhenGettingUploadPaths()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,94 +0,0 @@
|
|||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
using Schaad.Accounting.Interfaces;
|
||||
using Schaad.Accounting.Models;
|
||||
using Schaad.Accounting.Repositories;
|
||||
using Shouldly;
|
||||
|
||||
namespace Schaad.Accounting.Tests;
|
||||
|
||||
public class WaterBillRepositoryTestShould : IDisposable
|
||||
{
|
||||
private readonly string mandatorDir;
|
||||
private readonly ISettingsService settingsService;
|
||||
private readonly WaterBillRepository sut;
|
||||
|
||||
public WaterBillRepositoryTestShould()
|
||||
{
|
||||
mandatorDir = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(mandatorDir);
|
||||
|
||||
settingsService = Substitute.For<ISettingsService>();
|
||||
settingsService.GetMandatorPath().Returns(mandatorDir);
|
||||
|
||||
sut = new WaterBillRepository(settingsService, new RepositoryCache(), NullLogger<WaterBillRepository>.Instance);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(mandatorDir))
|
||||
{
|
||||
Directory.Delete(mandatorDir, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReturnEmptyListWhenFileDoesNotExistYet()
|
||||
{
|
||||
(await sut.GetWaterBillListAsync()).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AssignNewIdWhenSavingBillWithoutId()
|
||||
{
|
||||
var bill = new WaterBill
|
||||
{
|
||||
PeriodFrom = new DateOnly(2023, 7, 1),
|
||||
PeriodTo = new DateOnly(2024, 6, 30),
|
||||
WarmWaterM3 = 12.345m,
|
||||
ColdWaterM3 = 30.5m,
|
||||
WarmWaterChf = 250.40m,
|
||||
ColdWaterChf = 98.15m,
|
||||
BaseCostsChf = 120m
|
||||
};
|
||||
|
||||
await sut.SaveWaterBillAsync(bill);
|
||||
|
||||
var stored = (await sut.GetWaterBillListAsync()).Single();
|
||||
stored.Id.ShouldNotBeNullOrEmpty();
|
||||
stored.TotalM3.ShouldBe(42.845m);
|
||||
stored.TotalChf.ShouldBe(468.55m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateInPlaceWhenSavingBillWithExistingId()
|
||||
{
|
||||
await sut.SaveWaterBillAsync(new WaterBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), WarmWaterM3 = 10m });
|
||||
var id = (await sut.GetWaterBillListAsync()).Single().Id;
|
||||
|
||||
await sut.SaveWaterBillAsync(new WaterBill { Id = id, PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), WarmWaterM3 = 13m });
|
||||
|
||||
var bills = await sut.GetWaterBillListAsync();
|
||||
bills.Count.ShouldBe(1);
|
||||
bills[0].WarmWaterM3.ShouldBe(13m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RemoveBillWhenDeletingById()
|
||||
{
|
||||
await sut.SaveWaterBillAsync(new WaterBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) });
|
||||
var id = (await sut.GetWaterBillListAsync()).Single().Id;
|
||||
|
||||
await sut.DeleteWaterBillAsync(id);
|
||||
|
||||
(await sut.GetWaterBillListAsync()).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StoreFileDirectlyInMandatorFolderWithoutYearSubfolder()
|
||||
{
|
||||
await sut.SaveWaterBillAsync(new WaterBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) });
|
||||
|
||||
File.Exists(Path.Combine(mandatorDir, "water.json")).ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
using Schaad.Accounting.Models;
|
||||
using Shouldly;
|
||||
|
||||
namespace Schaad.Accounting.Tests;
|
||||
|
||||
public class WaterBillTestShould
|
||||
{
|
||||
[Fact]
|
||||
public void AddWarmAndColdWaterWhenCalculatingTotalM3()
|
||||
{
|
||||
var bill = new WaterBill { WarmWaterM3 = 12.345m, ColdWaterM3 = 30.5m };
|
||||
|
||||
bill.TotalM3.ShouldBe(42.845m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DivideWarmWaterByTotalWhenCalculatingWarmWaterShare()
|
||||
{
|
||||
var bill = new WaterBill { WarmWaterM3 = 10m, ColdWaterM3 = 30m };
|
||||
|
||||
bill.WarmWaterShare.ShouldBe(0.25m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnZeroWarmWaterShareWhenThereIsNoConsumption()
|
||||
{
|
||||
var bill = new WaterBill { WarmWaterM3 = 0m, ColdWaterM3 = 0m };
|
||||
|
||||
bill.WarmWaterShare.ShouldBe(0m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddWarmColdAndBaseCostsWhenCalculatingTotalChf()
|
||||
{
|
||||
var bill = new WaterBill { WarmWaterChf = 250.40m, ColdWaterChf = 98.15m, BaseCostsChf = 120m };
|
||||
|
||||
bill.TotalChf.ShouldBe(468.55m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddShareOfAllValuesWhenAddingShareOfOtherBill()
|
||||
{
|
||||
var sum = new WaterBill { WarmWaterM3 = 1m, ColdWaterM3 = 2m, WarmWaterChf = 4m, ColdWaterChf = 5m, BaseCostsChf = 3m };
|
||||
|
||||
sum.AddShare(new WaterBill { WarmWaterM3 = 10m, ColdWaterM3 = 20m, WarmWaterChf = 40m, ColdWaterChf = 50m, BaseCostsChf = 300m }, 0.5m);
|
||||
|
||||
sum.WarmWaterM3.ShouldBe(6m);
|
||||
sum.ColdWaterM3.ShouldBe(12m);
|
||||
sum.WarmWaterChf.ShouldBe(24m);
|
||||
sum.ColdWaterChf.ShouldBe(30m);
|
||||
sum.BaseCostsChf.ShouldBe(153m);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,8 +19,6 @@
|
|||
</FluentNavGroup>
|
||||
<FluentNavGroup Title="Charts" Icon="@(new Size32.ChartMultiple())">
|
||||
<FluentNavLink Href="analytics" Icon="@(new Size20.DataHistogram())" IconColor="Color.Accent">Analyse</FluentNavLink>
|
||||
<FluentNavLink Href="electricity" Icon="@(new Size20.Flash())" IconColor="Color.Accent">Strom</FluentNavLink>
|
||||
<FluentNavLink Href="water" Icon="@(new Size20.Drop())" IconColor="Color.Accent">Wasser</FluentNavLink>
|
||||
</FluentNavGroup>
|
||||
<FluentNavGroup Title="Reports" Icon="@(new Size32.DocumentPrint())">
|
||||
<FluentNavLink Href="ProfitLossReport" Icon="@(new Size32.DataTrending())" IconColor="Color.Accent">Erfolgsrechnung</FluentNavLink>
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
<div class="bill-chart-toolbar">
|
||||
<div class="segmented" role="group" aria-label="Zeitraum">
|
||||
@foreach (var kind in PeriodKinds)
|
||||
{
|
||||
<FluentButton Appearance="@(kind == Filter.Kind ? Appearance.Accent : Appearance.Neutral)"
|
||||
aria-pressed="@(kind == Filter.Kind ? "true" : "false")"
|
||||
OnClick="@(() => ChangeAsync(Filter with { Kind = kind }))">@PeriodKindName(kind)</FluentButton>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (Years.Count > 0)
|
||||
{
|
||||
<div class="years">
|
||||
<FluentSelect TOption="int" Label="Von" Width="110px"
|
||||
Items="@Years"
|
||||
OptionText="@(y => y.ToString())"
|
||||
OptionValue="@(y => y.ToString())"
|
||||
SelectedOption="@Range.From"
|
||||
SelectedOptionChanged="@OnFromChanged" />
|
||||
<FluentSelect TOption="int" Label="Bis" Width="110px"
|
||||
Items="@Years"
|
||||
OptionText="@(y => y.ToString())"
|
||||
OptionValue="@(y => y.ToString())"
|
||||
SelectedOption="@Range.To"
|
||||
SelectedOptionChanged="@OnToChanged" />
|
||||
<FluentButton Appearance="Appearance.Lightweight" OnClick="@(() => ChangeAsync(Filter with { FromYear = null, ToYear = null }))"
|
||||
Disabled="@Filter.CoversAll(Years)">Alle Jahre</FluentButton>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (IsSplit)
|
||||
{
|
||||
<span class="split-note">Werte anteilig auf die Monate der Abrechnungsperiode verteilt</span>
|
||||
}
|
||||
</div>
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Schaad.Accounting.Models;
|
||||
|
||||
namespace Schaad.Accounting.UI.Components.Pages.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Filter above the charts on the Strom and Wasser pages: period toggle (bill, calendar year,
|
||||
/// half-year), year range and the note shown when bills had to be split over several periods.
|
||||
/// </summary>
|
||||
public partial class BillChartToolbar : ComponentBase
|
||||
{
|
||||
private static readonly BillPeriodKind[] PeriodKinds =
|
||||
[BillPeriodKind.Bill, BillPeriodKind.Year, BillPeriodKind.HalfYear];
|
||||
|
||||
[Parameter]
|
||||
public BillChartFilter Filter { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<BillChartFilter> FilterChanged { get; set; }
|
||||
|
||||
/// <summary>The years any bill touches (see <see cref="BillChartFilter.YearsOf{T}"/>).</summary>
|
||||
[Parameter]
|
||||
public IReadOnlyList<int> Years { get; set; } = [];
|
||||
|
||||
[Parameter]
|
||||
public bool IsSplit { get; set; }
|
||||
|
||||
private (int From, int To) Range => Filter.RangeIn(Years);
|
||||
|
||||
/// <summary>Suffix for chart titles, e.g. "pro Halbjahr".</summary>
|
||||
public static string PerPeriod(BillPeriodKind kind) => kind switch
|
||||
{
|
||||
BillPeriodKind.Year => "pro Jahr",
|
||||
BillPeriodKind.HalfYear => "pro Halbjahr",
|
||||
_ => "pro Abrechnung"
|
||||
};
|
||||
|
||||
private static string PeriodKindName(BillPeriodKind kind) => kind switch
|
||||
{
|
||||
BillPeriodKind.Year => "Kalenderjahr",
|
||||
BillPeriodKind.HalfYear => "Halbjahr",
|
||||
_ => "Abrechnung"
|
||||
};
|
||||
|
||||
// Picking a "from" after the current "to" (or the other way round) moves the other end along.
|
||||
private Task OnFromChanged(int year)
|
||||
=> year == Range.From ? Task.CompletedTask : ChangeAsync(Filter with { FromYear = year, ToYear = Math.Max(Range.To, year) });
|
||||
|
||||
private Task OnToChanged(int year)
|
||||
=> year == Range.To ? Task.CompletedTask : ChangeAsync(Filter with { FromYear = Math.Min(Range.From, year), ToYear = year });
|
||||
|
||||
private Task ChangeAsync(BillChartFilter filter) => FilterChanged.InvokeAsync(filter);
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
.bill-chart-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.segmented {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.years {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.split-note {
|
||||
font-size: 12px;
|
||||
color: var(--neutral-foreground-hint);
|
||||
align-self: center;
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
@implements IDialogContentComponent<Schaad.Accounting.Models.ElectricityBill>
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<FluentDialogHeader ShowDismiss="true">
|
||||
<FluentStack VerticalAlignment="VerticalAlignment.Center">
|
||||
<FluentIcon Value="@(new Icons.Regular.Size24.WindowApps())" />
|
||||
<FluentLabel Typo="Typography.PaneHeader">
|
||||
@Dialog.Instance.Parameters.Title
|
||||
</FluentLabel>
|
||||
</FluentStack>
|
||||
</FluentDialogHeader>
|
||||
|
||||
<FluentDialogBody>
|
||||
<EditForm EditContext="@editContext">
|
||||
<DataAnnotationsValidator />
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentDatePicker @bind-Value="@periodFrom" Label="Von" Style="width: 170px;" />
|
||||
<FluentDatePicker @bind-Value="@periodTo" Label="Bis" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentNumberField @bind-Value="@Content.GridKwh" Label="Netzbezug (kWh)" Style="width: 170px;" />
|
||||
<FluentNumberField @bind-Value="@Content.PvKwh" Label="PV-Produktion (kWh)" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentNumberField @bind-Value="@Content.GridChf" Label="Netzbezug (CHF)" Style="width: 170px;" />
|
||||
<FluentNumberField @bind-Value="@Content.PvChf" Label="PV (CHF)" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentNumberField @bind-Value="@Content.SideCostsChf" Label="Nebenkosten (CHF)" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<div>
|
||||
<FluentValidationSummary />
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<div style="margin-top: 12px; font-size: 13px; color: #52514e;">
|
||||
Total <strong>@Chf(Content.TotalChf)</strong>
|
||||
</div>
|
||||
|
||||
<FluentButton Appearance="Appearance.Lightweight" Style="margin-top: 12px; padding: 0; font-size: 13px;" OnClick="ShowGuideAsync">
|
||||
Woher kommen die Werte? (NeoVac-Abrechnung)
|
||||
</FluentButton>
|
||||
</FluentDialogBody>
|
||||
|
||||
<FluentDialogFooter>
|
||||
<FluentButton Appearance="Appearance.Neutral"
|
||||
OnClick="@CancelAsync">
|
||||
Abbrechen
|
||||
</FluentButton>
|
||||
<FluentButton Appearance="Appearance.Accent"
|
||||
Disabled="@(periodFrom is null || periodTo is null)"
|
||||
OnClick="@SaveAsync">
|
||||
Speichern
|
||||
</FluentButton>
|
||||
</FluentDialogFooter>
|
||||
|
||||
@code {
|
||||
// Shown in its own dialog (see ShowGuideAsync) instead of expanding inline: this dialog has a
|
||||
// fixed Height, and FluentDialogBody doesn't resize to fit growing content.
|
||||
private RenderFragment GuideImage =>
|
||||
@<img src="/images/electricity-bill-guide.svg"
|
||||
alt="Beispiel-Abrechnung mit Markierungen, welcher Wert in welches Feld gehört"
|
||||
style="width: 100%; height: auto; display: block;" />;
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
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;
|
||||
|
||||
public partial class ElectricityBillDialog : ComponentBase
|
||||
{
|
||||
private static readonly CultureInfo SwissNumbers = CreateSwissNumbers();
|
||||
|
||||
private EditContext editContext = null!;
|
||||
|
||||
// FluentDatePicker needs DateTime?; the model stores DateOnly (see ElectricityBill).
|
||||
private DateTime? periodFrom;
|
||||
private DateTime? periodTo;
|
||||
|
||||
[CascadingParameter]
|
||||
public FluentDialog Dialog { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public ElectricityBill Content { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IElectricityBillRepository electricityBillRepository { 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);
|
||||
if (editContext.Validate())
|
||||
{
|
||||
await electricityBillRepository.SaveElectricityBillAsync(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 Chf(decimal value) => value.ToString("#,0.00", SwissNumbers) + " CHF";
|
||||
|
||||
private static CultureInfo CreateSwissNumbers()
|
||||
{
|
||||
var culture = new CultureInfo("de-CH");
|
||||
culture.NumberFormat.NumberGroupSeparator = "'";
|
||||
return culture;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
@implements IDialogContentComponent<Schaad.Accounting.Models.WaterBill>
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<FluentDialogHeader ShowDismiss="true">
|
||||
<FluentStack VerticalAlignment="VerticalAlignment.Center">
|
||||
<FluentIcon Value="@(new Icons.Regular.Size24.WindowApps())" />
|
||||
<FluentLabel Typo="Typography.PaneHeader">
|
||||
@Dialog.Instance.Parameters.Title
|
||||
</FluentLabel>
|
||||
</FluentStack>
|
||||
</FluentDialogHeader>
|
||||
|
||||
<FluentDialogBody>
|
||||
<EditForm EditContext="@editContext">
|
||||
<DataAnnotationsValidator />
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentDatePicker @bind-Value="@periodFrom" Label="Von" Style="width: 170px;" />
|
||||
<FluentDatePicker @bind-Value="@periodTo" Label="Bis" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentNumberField @bind-Value="@Content.WarmWaterM3" Label="Warmwasser (m³)" Style="width: 170px;" />
|
||||
<FluentNumberField @bind-Value="@Content.ColdWaterM3" Label="Kaltwasser (m³)" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentNumberField @bind-Value="@Content.WarmWaterChf" Label="Warmwasser (CHF)" Style="width: 170px;" />
|
||||
<FluentNumberField @bind-Value="@Content.ColdWaterChf" Label="Kaltwasser (CHF)" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<FluentStack Orientation="Orientation.Horizontal">
|
||||
<FluentNumberField @bind-Value="@Content.BaseCostsChf" Label="Grundkosten (CHF)" Style="width: 170px;" />
|
||||
</FluentStack>
|
||||
<div>
|
||||
<FluentValidationSummary />
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<div style="margin-top: 12px; font-size: 13px; color: #52514e;">
|
||||
Total <strong>@M3(Content.TotalM3)</strong> · <strong>@Chf(Content.TotalChf)</strong>
|
||||
</div>
|
||||
</FluentDialogBody>
|
||||
|
||||
<FluentDialogFooter>
|
||||
<FluentButton Appearance="Appearance.Neutral"
|
||||
OnClick="@CancelAsync">
|
||||
Abbrechen
|
||||
</FluentButton>
|
||||
<FluentButton Appearance="Appearance.Accent"
|
||||
Disabled="@(periodFrom is null || periodTo is null)"
|
||||
OnClick="@SaveAsync">
|
||||
Speichern
|
||||
</FluentButton>
|
||||
</FluentDialogFooter>
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
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;
|
||||
|
||||
public partial class WaterBillDialog : ComponentBase
|
||||
{
|
||||
private static readonly CultureInfo SwissNumbers = CreateSwissNumbers();
|
||||
|
||||
private EditContext editContext = null!;
|
||||
|
||||
// FluentDatePicker needs DateTime?; the model stores DateOnly (see WaterBill).
|
||||
private DateTime? periodFrom;
|
||||
private DateTime? periodTo;
|
||||
|
||||
[CascadingParameter]
|
||||
public FluentDialog Dialog { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public WaterBill Content { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IWaterBillRepository waterBillRepository { 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);
|
||||
if (editContext.Validate())
|
||||
{
|
||||
await waterBillRepository.SaveWaterBillAsync(Content);
|
||||
await Dialog.CloseAsync(Content);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CancelAsync()
|
||||
{
|
||||
await Dialog.CancelAsync();
|
||||
}
|
||||
|
||||
private static string M3(decimal value) => value.ToString("#,0.00", SwissNumbers) + " m³";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
@page "/electricity"
|
||||
@rendermode InteractiveServer
|
||||
@using Schaad.Accounting.UI.Components.Pages.Analytics
|
||||
|
||||
<PageTitle>Strom</PageTitle>
|
||||
|
||||
<div class="electricity">
|
||||
<FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center">
|
||||
<FluentButton IconStart="@(new Icons.Regular.Size16.Add())" Appearance="Appearance.Neutral" OnClick="AddAsync">Neue Abrechnung hinzufügen</FluentButton>
|
||||
</FluentStack>
|
||||
|
||||
@if (source.Count == 0)
|
||||
{
|
||||
<FluentMessageBar Intent="MessageIntent.Info" AllowDismiss="false">Noch keine Abrechnungen erfasst.</FluentMessageBar>
|
||||
}
|
||||
else
|
||||
{
|
||||
<BillChartToolbar Filter="@filter" FilterChanged="@OnFilterChanged" Years="@years" IsSplit="@isSplit" />
|
||||
|
||||
<div class="pair">
|
||||
<FluentCard class="chart-card">
|
||||
<div class="card-title">Verbrauch @PerPeriod</div>
|
||||
<ChartJsChart Kind="stackedBar" Data="@barData" Height="360px"
|
||||
AriaLabel="@($"Netzbezug und PV-Produktion {PerPeriod}, gestapelte Balken in kWh")" />
|
||||
</FluentCard>
|
||||
<FluentCard class="chart-card">
|
||||
<div class="card-title">Preis pro kWh</div>
|
||||
<ChartJsChart Kind="line" Data="@lineData" Height="360px"
|
||||
AriaLabel="@($"Preis pro kWh für Netz, PV und Total {PerPeriod}")" />
|
||||
</FluentCard>
|
||||
</div>
|
||||
|
||||
<FluentCard class="chart-card">
|
||||
<div class="card-title">Gesamtkosten @PerPeriod</div>
|
||||
<ChartJsChart Kind="line" Data="@costData" Height="320px"
|
||||
AriaLabel="@($"Gesamtkosten {PerPeriod}")" />
|
||||
</FluentCard>
|
||||
}
|
||||
|
||||
<div class="table-scroll">
|
||||
<FluentDataGrid Items="@source.AsQueryable()" RowSize="DataGridRowSize.Medium">
|
||||
<PropertyColumn Title="Von" Property="@(p => p.PeriodFrom)" Format="dd.MM.yyyy" Sortable="true" IsDefaultSortColumn="true" InitialSortDirection="SortDirection.Descending" />
|
||||
<PropertyColumn Title="Bis" Property="@(p => p.PeriodTo)" Format="dd.MM.yyyy" Sortable="true" />
|
||||
<PropertyColumn Title="Netz kWh" Property="@(p => p.GridKwh)" Format="#,0.0" Align="Align.End" />
|
||||
<PropertyColumn Title="PV kWh" Property="@(p => p.PvKwh)" Format="#,0.0" Align="Align.End" />
|
||||
<PropertyColumn Title="Total kWh" Property="@(p => p.TotalKwh)" Format="#,0.0" Align="Align.End" />
|
||||
<PropertyColumn Title="PV-Anteil" Property="@(p => p.PvShare)" Format="P1" Align="Align.End" />
|
||||
<PropertyColumn Title="Netz CHF" Property="@(p => p.GridChf)" Format="C2" Align="Align.End" />
|
||||
<PropertyColumn Title="PV CHF" Property="@(p => p.PvChf)" Format="C2" Align="Align.End" />
|
||||
<PropertyColumn Title="Nebenkosten" Property="@(p => p.SideCostsChf)" Format="C2" Align="Align.End" />
|
||||
<PropertyColumn Title="Total CHF" Property="@(p => p.TotalChf)" Format="C2" Align="Align.End" />
|
||||
<TemplateColumn Align="Align.Center" Width="50px">
|
||||
<FluentButton IconEnd="@(new Icons.Regular.Size16.Delete())" Appearance="Appearance.Neutral" title="Löschen" aria-label="Löschen" OnClick="@(() => DeleteAsync(context.Id))" />
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Align="Align.Center" Width="50px">
|
||||
<FluentButton IconEnd="@(new Icons.Regular.Size16.Edit())" Appearance="Appearance.Neutral" title="Bearbeiten" aria-label="Bearbeiten" OnClick="@(() => EditAsync(context.Id))" />
|
||||
</TemplateColumn>
|
||||
</FluentDataGrid>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
using Schaad.Accounting.Interfaces;
|
||||
using Schaad.Accounting.Models;
|
||||
using Schaad.Accounting.UI.Components.Pages.Charts;
|
||||
using Schaad.Accounting.UI.Components.Pages.Controls;
|
||||
using Schaad.Accounting.UI.Components.Pages.Dialogs;
|
||||
|
||||
namespace Schaad.Accounting.UI.Components.Pages;
|
||||
|
||||
/// <summary>
|
||||
/// Yearly NeoVac electricity bills for the apartment (billing period 1 July – 30 June, so the
|
||||
/// bills are stored once per mandator, not per calendar year; see
|
||||
/// <see cref="IElectricityBillRepository"/>). Grid for entering/editing, plus charts per bill,
|
||||
/// calendar year or half-year over a year range (see <see cref="BillChartToolbar"/> and
|
||||
/// <see cref="BillPeriod{T}"/>): consumption grid/PV, price per kWh and total costs.
|
||||
/// </summary>
|
||||
public partial class Electricity : ComponentBase
|
||||
{
|
||||
[Inject]
|
||||
private IElectricityBillRepository electricityBillRepository { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IDialogService dialogService { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IToastService toastService { get; set; } = null!;
|
||||
|
||||
private IReadOnlyList<ElectricityBill> source = [];
|
||||
|
||||
private BillChartFilter filter = new();
|
||||
|
||||
// Years any bill touches, for the year range of the charts.
|
||||
private List<int> years = [];
|
||||
|
||||
// True if a bill had to be spread over several periods of the selected kind.
|
||||
private bool isSplit;
|
||||
|
||||
private object barData = new();
|
||||
private object lineData = new();
|
||||
private object costData = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
source = (await electricityBillRepository.GetElectricityBillListAsync())
|
||||
.OrderBy(b => b.PeriodFrom)
|
||||
.ToList();
|
||||
years = BillChartFilter.YearsOf(source);
|
||||
BuildCharts();
|
||||
}
|
||||
|
||||
private void OnFilterChanged(BillChartFilter value)
|
||||
{
|
||||
filter = value;
|
||||
BuildCharts();
|
||||
}
|
||||
|
||||
private void BuildCharts()
|
||||
{
|
||||
// A bill reaching over several periods is spread evenly over its months.
|
||||
var periods = filter.Apply(source);
|
||||
isSplit = periods.Any(p => p.IsSplit);
|
||||
var labels = periods.Select(p => p.Label).ToList();
|
||||
barData = new
|
||||
{
|
||||
labels,
|
||||
series = new object[]
|
||||
{
|
||||
new { name = "Netz", color = ChartTheme.ColorAt(0), values = periods.Select(p => p.Bill?.GridKwh).ToList(), clickable = false },
|
||||
new { name = "PV", color = ChartTheme.ColorAt(1), values = periods.Select(p => p.Bill?.PvKwh).ToList(), clickable = false }
|
||||
},
|
||||
unit = "kWh"
|
||||
};
|
||||
lineData = new
|
||||
{
|
||||
labels,
|
||||
series = new object[]
|
||||
{
|
||||
new { name = "Netz", color = ChartTheme.ColorAt(0), values = periods.Select(p => p.Bill?.GridChfPerKwh).ToList(), width = 2 },
|
||||
new { name = "PV", color = ChartTheme.ColorAt(1), values = periods.Select(p => p.Bill?.PvChfPerKwh).ToList(), width = 2 },
|
||||
new { name = "Total", color = ChartTheme.OtherColor, values = periods.Select(p => p.Bill?.ChfPerKwh).ToList(), width = 2 }
|
||||
},
|
||||
unit = "CHF/kWh",
|
||||
axisDecimals = 2
|
||||
};
|
||||
costData = new
|
||||
{
|
||||
labels,
|
||||
series = new object[]
|
||||
{
|
||||
new { name = "Total", color = ChartTheme.ColorAt(2), values = periods.Select(p => p.Bill?.TotalChf).ToList(), width = 2 }
|
||||
},
|
||||
unit = "CHF"
|
||||
};
|
||||
}
|
||||
|
||||
private async Task AddAsync()
|
||||
{
|
||||
var data = new ElectricityBill();
|
||||
var dialog = await dialogService.ShowDialogAsync<ElectricityBillDialog>(data, new DialogParameters()
|
||||
{
|
||||
Width = "560px",
|
||||
Height = "460px",
|
||||
Title = "Abrechnung hinzufügen",
|
||||
PreventDismissOnOverlayClick = true,
|
||||
PreventScroll = true,
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
if (!result.Cancelled && result.Data != null)
|
||||
{
|
||||
await LoadAsync();
|
||||
toastService.ShowToast(ToastIntent.Success, "Abrechnung gespeichert", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EditAsync(string id)
|
||||
{
|
||||
var data = await electricityBillRepository.GetElectricityBillAsync(id);
|
||||
var dialog = await dialogService.ShowDialogAsync<ElectricityBillDialog>(data, new DialogParameters()
|
||||
{
|
||||
Width = "560px",
|
||||
Height = "460px",
|
||||
Title = "Abrechnung bearbeiten",
|
||||
PreventDismissOnOverlayClick = true,
|
||||
PreventScroll = true,
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
if (!result.Cancelled && result.Data != null)
|
||||
{
|
||||
await LoadAsync();
|
||||
toastService.ShowToast(ToastIntent.Success, "Abrechnung gespeichert", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(string id)
|
||||
{
|
||||
var bill = source.First(b => b.Id == id);
|
||||
var dialog = await dialogService.ShowConfirmationAsync($"Abrechnung {FullLabel(bill)} wirklich löschen?", "Ja", "Nein", "Abrechnung löschen");
|
||||
var result = await dialog.Result;
|
||||
if (!result.Cancelled)
|
||||
{
|
||||
await electricityBillRepository.DeleteElectricityBillAsync(id);
|
||||
await LoadAsync();
|
||||
toastService.ShowToast(ToastIntent.Success, "Abrechnung gelöscht", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
private string PerPeriod => BillChartToolbar.PerPeriod(filter.Kind);
|
||||
|
||||
private static string FullLabel(ElectricityBill bill) => $"{bill.PeriodFrom:dd.MM.yyyy} – {bill.PeriodTo:dd.MM.yyyy}";
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
.electricity {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.table-scroll {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.pair {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.pair {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
::deep .chart-card {
|
||||
padding: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
|
@ -39,7 +39,6 @@ public partial class JsonEditor : ComponentBase, IAsyncDisposable
|
|||
|
||||
private StandaloneCodeEditor? editor;
|
||||
private IJSObjectReference? unsavedGuard;
|
||||
private IJSObjectReference? url;
|
||||
private bool monacoLoaded;
|
||||
private string? monacoError;
|
||||
private RawDataFile? file;
|
||||
|
|
@ -49,12 +48,20 @@ public partial class JsonEditor : ComponentBase, IAsyncDisposable
|
|||
private bool saving;
|
||||
private IReadOnlyList<string> errors = [];
|
||||
|
||||
// The file parameter is only read here: switching files doesn't navigate (see OnFileChanged),
|
||||
// and while leaving the page the query changes again for a component that is about to go.
|
||||
protected override async Task OnInitializedAsync()
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
fileName = repository.FileNames.Contains(FileParameter ?? "") ? FileParameter! : repository.FileNames[0];
|
||||
var requested = repository.FileNames.Contains(FileParameter ?? "") ? FileParameter! : repository.FileNames[0];
|
||||
if (requested == fileName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
fileName = requested;
|
||||
file = await repository.LoadAsync(fileName);
|
||||
errors = [];
|
||||
if (editor is not null)
|
||||
{
|
||||
await ShowFileAsync();
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
|
|
@ -64,7 +71,6 @@ public partial class JsonEditor : ComponentBase, IAsyncDisposable
|
|||
return;
|
||||
}
|
||||
unsavedGuard = await js.InvokeAsync<IJSObjectReference>("import", "./js/unsaved-guard.js");
|
||||
url = await js.InvokeAsync<IJSObjectReference>("import", "./js/url.js");
|
||||
try
|
||||
{
|
||||
await using var module = await js.InvokeAsync<IJSObjectReference>("import", "./js/monaco.js");
|
||||
|
|
@ -160,33 +166,24 @@ public partial class JsonEditor : ComponentBase, IAsyncDisposable
|
|||
await ShowFileAsync();
|
||||
}
|
||||
|
||||
// Loads the file in place and only puts it into the address bar (for bookmarks and reloads).
|
||||
// Navigating instead would run an enhanced navigation, which re-renders the page on the server
|
||||
// and merges it into the DOM; the editor doesn't survive that.
|
||||
// Switching goes through the URL, so the file is part of bookmarks and back/forward.
|
||||
private async Task OnFileChanged(string name)
|
||||
{
|
||||
if (name == fileName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (dirty && await ConfirmDiscardAsync() == false)
|
||||
if (dirty)
|
||||
{
|
||||
// Re-render puts the select back on the current file.
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
fileName = name;
|
||||
file = await repository.LoadAsync(fileName);
|
||||
errors = [];
|
||||
// Before Monaco is up, the editor picks up the file when it is created (EditorOptions).
|
||||
if (editor is not null)
|
||||
{
|
||||
await ShowFileAsync();
|
||||
}
|
||||
if (url is not null)
|
||||
{
|
||||
await url.InvokeVoidAsync("replace", navigation.GetUriWithQueryParameter("file", name));
|
||||
if (await ConfirmDiscardAsync() == false)
|
||||
{
|
||||
// Re-render puts the select back on the current file.
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
await SetDirtyAsync(false);
|
||||
}
|
||||
navigation.NavigateTo(navigation.GetUriWithQueryParameter("file", name));
|
||||
}
|
||||
|
||||
private async Task<bool> ConfirmDiscardAsync()
|
||||
|
|
@ -229,10 +226,6 @@ public partial class JsonEditor : ComponentBase, IAsyncDisposable
|
|||
await unsavedGuard.InvokeVoidAsync("set", (object?)null);
|
||||
await unsavedGuard.DisposeAsync();
|
||||
}
|
||||
if (url is not null)
|
||||
{
|
||||
await url.DisposeAsync();
|
||||
}
|
||||
}
|
||||
catch (JSDisconnectedException)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
@page "/water"
|
||||
@rendermode InteractiveServer
|
||||
@using Schaad.Accounting.UI.Components.Pages.Analytics
|
||||
|
||||
<PageTitle>Wasser</PageTitle>
|
||||
|
||||
<div class="water">
|
||||
<FluentStack Orientation="Orientation.Horizontal" VerticalAlignment="VerticalAlignment.Center">
|
||||
<FluentButton IconStart="@(new Icons.Regular.Size16.Add())" Appearance="Appearance.Neutral" OnClick="AddAsync">Neue Abrechnung hinzufügen</FluentButton>
|
||||
</FluentStack>
|
||||
|
||||
@if (source.Count == 0)
|
||||
{
|
||||
<FluentMessageBar Intent="MessageIntent.Info" AllowDismiss="false">Noch keine Abrechnungen erfasst.</FluentMessageBar>
|
||||
}
|
||||
else
|
||||
{
|
||||
<BillChartToolbar Filter="@filter" FilterChanged="@OnFilterChanged" Years="@years" IsSplit="@isSplit" />
|
||||
|
||||
<div class="pair">
|
||||
<FluentCard class="chart-card">
|
||||
<div class="card-title">Verbrauch @PerPeriod</div>
|
||||
<ChartJsChart Kind="stackedBar" Data="@barData" Height="360px"
|
||||
AriaLabel="@($"Warm- und Kaltwasserverbrauch {PerPeriod}, gestapelte Balken in m³")" />
|
||||
</FluentCard>
|
||||
<FluentCard class="chart-card">
|
||||
<div class="card-title">Gesamtkosten @PerPeriod</div>
|
||||
<ChartJsChart Kind="line" Data="@costData" Height="360px"
|
||||
AriaLabel="@($"Gesamtkosten {PerPeriod}")" />
|
||||
</FluentCard>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="table-scroll">
|
||||
<FluentDataGrid Items="@source.AsQueryable()" RowSize="DataGridRowSize.Medium">
|
||||
<PropertyColumn Title="Von" Property="@(p => p.PeriodFrom)" Format="dd.MM.yyyy" Sortable="true" IsDefaultSortColumn="true" InitialSortDirection="SortDirection.Descending" />
|
||||
<PropertyColumn Title="Bis" Property="@(p => p.PeriodTo)" Format="dd.MM.yyyy" Sortable="true" />
|
||||
<PropertyColumn Title="Warmwasser m³" Property="@(p => p.WarmWaterM3)" Format="#,0.00" Align="Align.End" />
|
||||
<PropertyColumn Title="Kaltwasser m³" Property="@(p => p.ColdWaterM3)" Format="#,0.00" Align="Align.End" />
|
||||
<PropertyColumn Title="Total m³" Property="@(p => p.TotalM3)" Format="#,0.00" Align="Align.End" />
|
||||
<PropertyColumn Title="Warmwasser-Anteil" Property="@(p => p.WarmWaterShare)" Format="P1" Align="Align.End" />
|
||||
<PropertyColumn Title="Warmwasser CHF" Property="@(p => p.WarmWaterChf)" Format="C2" Align="Align.End" />
|
||||
<PropertyColumn Title="Kaltwasser CHF" Property="@(p => p.ColdWaterChf)" Format="C2" Align="Align.End" />
|
||||
<PropertyColumn Title="Grundkosten" Property="@(p => p.BaseCostsChf)" Format="C2" Align="Align.End" />
|
||||
<PropertyColumn Title="Total CHF" Property="@(p => p.TotalChf)" Format="C2" Align="Align.End" />
|
||||
<TemplateColumn Align="Align.Center" Width="50px">
|
||||
<FluentButton IconEnd="@(new Icons.Regular.Size16.Delete())" Appearance="Appearance.Neutral" title="Löschen" aria-label="Löschen" OnClick="@(() => DeleteAsync(context.Id))" />
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Align="Align.Center" Width="50px">
|
||||
<FluentButton IconEnd="@(new Icons.Regular.Size16.Edit())" Appearance="Appearance.Neutral" title="Bearbeiten" aria-label="Bearbeiten" OnClick="@(() => EditAsync(context.Id))" />
|
||||
</TemplateColumn>
|
||||
</FluentDataGrid>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
using Schaad.Accounting.Interfaces;
|
||||
using Schaad.Accounting.Models;
|
||||
using Schaad.Accounting.UI.Components.Pages.Charts;
|
||||
using Schaad.Accounting.UI.Components.Pages.Controls;
|
||||
using Schaad.Accounting.UI.Components.Pages.Dialogs;
|
||||
|
||||
namespace Schaad.Accounting.UI.Components.Pages;
|
||||
|
||||
/// <summary>
|
||||
/// Water bills for the apartment, laid out like the Strom page (<see cref="Electricity"/>): the
|
||||
/// bills are stored once per mandator, not per calendar year (see <see cref="IWaterBillRepository"/>).
|
||||
/// Grid for entering/editing, plus charts per bill, calendar year or half-year over a year range
|
||||
/// (see <see cref="BillChartToolbar"/> and <see cref="BillPeriod{T}"/>): warm/cold water
|
||||
/// consumption and total costs.
|
||||
/// </summary>
|
||||
public partial class Water : ComponentBase
|
||||
{
|
||||
[Inject]
|
||||
private IWaterBillRepository waterBillRepository { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IDialogService dialogService { get; set; } = null!;
|
||||
|
||||
[Inject]
|
||||
private IToastService toastService { get; set; } = null!;
|
||||
|
||||
private IReadOnlyList<WaterBill> source = [];
|
||||
|
||||
private BillChartFilter filter = new();
|
||||
|
||||
// Years any bill touches, for the year range of the charts.
|
||||
private List<int> years = [];
|
||||
|
||||
// True if a bill had to be spread over several periods of the selected kind.
|
||||
private bool isSplit;
|
||||
|
||||
private object barData = new();
|
||||
private object costData = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
source = (await waterBillRepository.GetWaterBillListAsync())
|
||||
.OrderBy(b => b.PeriodFrom)
|
||||
.ToList();
|
||||
years = BillChartFilter.YearsOf(source);
|
||||
BuildCharts();
|
||||
}
|
||||
|
||||
private void OnFilterChanged(BillChartFilter value)
|
||||
{
|
||||
filter = value;
|
||||
BuildCharts();
|
||||
}
|
||||
|
||||
private void BuildCharts()
|
||||
{
|
||||
// A bill reaching over several periods is spread evenly over its months.
|
||||
var periods = filter.Apply(source);
|
||||
isSplit = periods.Any(p => p.IsSplit);
|
||||
var labels = periods.Select(p => p.Label).ToList();
|
||||
barData = new
|
||||
{
|
||||
labels,
|
||||
series = new object[]
|
||||
{
|
||||
new { name = "Warmwasser", color = ChartTheme.ColorAt(0), values = periods.Select(p => p.Bill?.WarmWaterM3).ToList(), clickable = false },
|
||||
new { name = "Kaltwasser", color = ChartTheme.ColorAt(1), values = periods.Select(p => p.Bill?.ColdWaterM3).ToList(), clickable = false }
|
||||
},
|
||||
unit = "m³"
|
||||
};
|
||||
costData = new
|
||||
{
|
||||
labels,
|
||||
series = new object[]
|
||||
{
|
||||
new { name = "Total", color = ChartTheme.ColorAt(2), values = periods.Select(p => p.Bill?.TotalChf).ToList(), width = 2 }
|
||||
},
|
||||
unit = "CHF"
|
||||
};
|
||||
}
|
||||
|
||||
private async Task AddAsync()
|
||||
{
|
||||
var data = new WaterBill();
|
||||
var dialog = await dialogService.ShowDialogAsync<WaterBillDialog>(data, new DialogParameters()
|
||||
{
|
||||
Width = "560px",
|
||||
Height = "460px",
|
||||
Title = "Abrechnung hinzufügen",
|
||||
PreventDismissOnOverlayClick = true,
|
||||
PreventScroll = true,
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
if (!result.Cancelled && result.Data != null)
|
||||
{
|
||||
await LoadAsync();
|
||||
toastService.ShowToast(ToastIntent.Success, "Abrechnung gespeichert", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EditAsync(string id)
|
||||
{
|
||||
var data = await waterBillRepository.GetWaterBillAsync(id);
|
||||
var dialog = await dialogService.ShowDialogAsync<WaterBillDialog>(data, new DialogParameters()
|
||||
{
|
||||
Width = "560px",
|
||||
Height = "460px",
|
||||
Title = "Abrechnung bearbeiten",
|
||||
PreventDismissOnOverlayClick = true,
|
||||
PreventScroll = true,
|
||||
});
|
||||
|
||||
var result = await dialog.Result;
|
||||
if (!result.Cancelled && result.Data != null)
|
||||
{
|
||||
await LoadAsync();
|
||||
toastService.ShowToast(ToastIntent.Success, "Abrechnung gespeichert", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(string id)
|
||||
{
|
||||
var bill = source.First(b => b.Id == id);
|
||||
var dialog = await dialogService.ShowConfirmationAsync($"Abrechnung {FullLabel(bill)} wirklich löschen?", "Ja", "Nein", "Abrechnung löschen");
|
||||
var result = await dialog.Result;
|
||||
if (!result.Cancelled)
|
||||
{
|
||||
await waterBillRepository.DeleteWaterBillAsync(id);
|
||||
await LoadAsync();
|
||||
toastService.ShowToast(ToastIntent.Success, "Abrechnung gelöscht", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
private string PerPeriod => BillChartToolbar.PerPeriod(filter.Kind);
|
||||
|
||||
private static string FullLabel(WaterBill bill) => $"{bill.PeriodFrom:dd.MM.yyyy} – {bill.PeriodTo:dd.MM.yyyy}";
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
.water {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.table-scroll {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.pair {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.pair {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
::deep .chart-card {
|
||||
padding: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
|
@ -21,8 +21,6 @@ namespace Schaad.Accounting.UI
|
|||
services.AddScoped<IBankTransactionRepository, BankTransactionRepository>();
|
||||
services.AddScoped<IBookingRuleRepository, BookingRuleRepository>();
|
||||
services.AddScoped<IBookingTextRepository, BookingTextRepository>();
|
||||
services.AddScoped<IElectricityBillRepository, ElectricityBillRepository>();
|
||||
services.AddScoped<IWaterBillRepository, WaterBillRepository>();
|
||||
services.AddScoped<ISplitPredefinitionRepository, SplitPredefinitionRepository>();
|
||||
services.AddScoped<ISubclassRepository, SubclassRepository>();
|
||||
services.AddScoped<ITransactionRepository, TransactionRepository>();
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
}
|
||||
},
|
||||
"Settings": {
|
||||
"DataPath_": "/home/schaad/Documents/Developer/Data/Accounting/",
|
||||
"DataPath": "D:\\Developer\\AccountingData",
|
||||
"DataPath": "D:\\Developer\\AccountingData\\",
|
||||
"FixerIoApiKey": "ee23142f1120bb1223b0e76f98abfa97",
|
||||
"DefaultMandator": "Claudio Schaad"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 532" role="img" aria-labelledby="guide-title">
|
||||
<title id="guide-title">Beispiel-Abrechnung: Wo stehen die Werte?</title>
|
||||
|
||||
<rect x="8" y="8" width="624" height="516" rx="10" fill="#fcfcfb" stroke="#e1e0d9" />
|
||||
|
||||
<text x="24" y="38" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="16" font-weight="bold" fill="#0b0b0b">Beispiel: Wo stehen die Werte auf der Abrechnung?</text>
|
||||
<text x="24" y="58" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#52514e">Platzhalterwerte – der Aufbau entspricht dem Abschnitt „Ihre Abrechnung vom …“ der NeoVac-Abrechnung.</text>
|
||||
|
||||
<line x1="24" y1="72" x2="616" y2="72" stroke="#e1e0d9" stroke-width="1" />
|
||||
|
||||
<!-- Von / Bis -->
|
||||
<text x="24" y="114" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Abrechnungsperiode</text>
|
||||
<rect x="380" y="94" width="232" height="22" rx="4" fill="none" stroke="#e87ba4" stroke-width="2" />
|
||||
<text x="604" y="110" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">01.07.2025 – 30.06.2026</text>
|
||||
<text x="604" y="128" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#e87ba4">→ Von / Bis</text>
|
||||
|
||||
<!-- Netzbezug kWh -->
|
||||
<text x="24" y="180" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Netzstrom – Ihr Anteil</text>
|
||||
<rect x="380" y="160" width="232" height="22" rx="4" fill="none" stroke="#2a78d6" stroke-width="2" />
|
||||
<text x="604" y="176" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">1'200.000 kWh</text>
|
||||
<text x="604" y="194" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#2a78d6">→ Netzbezug (kWh)</text>
|
||||
|
||||
<!-- Netzbezug CHF -->
|
||||
<text x="24" y="246" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">Netzstrom – Betrag (CHF)</text>
|
||||
<rect x="380" y="226" width="232" height="22" rx="4" fill="none" stroke="#2a78d6" stroke-width="2" />
|
||||
<text x="604" y="242" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">350.00</text>
|
||||
<text x="604" y="260" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#2a78d6">→ Netzbezug (CHF)</text>
|
||||
|
||||
<!-- PV kWh -->
|
||||
<text x="24" y="312" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">ZEV Photovoltaikstrom – Ihr Anteil</text>
|
||||
<rect x="380" y="292" width="232" height="22" rx="4" fill="none" stroke="#eb6834" stroke-width="2" />
|
||||
<text x="604" y="308" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">900.000 kWh</text>
|
||||
<text x="604" y="326" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#eb6834">→ PV-Produktion (kWh)</text>
|
||||
|
||||
<!-- PV CHF -->
|
||||
<text x="24" y="378" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">ZEV Photovoltaikstrom – Betrag (CHF)</text>
|
||||
<rect x="380" y="358" width="232" height="22" rx="4" fill="none" stroke="#eb6834" stroke-width="2" />
|
||||
<text x="604" y="374" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">250.00</text>
|
||||
<text x="604" y="392" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#eb6834">→ PV (CHF)</text>
|
||||
|
||||
<!-- Nebenkosten CHF -->
|
||||
<text x="24" y="444" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" fill="#0b0b0b">ZEV Stromnebenkosten – Betrag (CHF)</text>
|
||||
<rect x="380" y="424" width="232" height="22" rx="4" fill="none" stroke="#1baf7a" stroke-width="2" />
|
||||
<text x="604" y="440" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="13" font-weight="bold" fill="#0b0b0b">80.00</text>
|
||||
<text x="604" y="458" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="11" font-weight="bold" fill="#1baf7a">→ Nebenkosten (CHF)</text>
|
||||
|
||||
<line x1="24" y1="480" x2="616" y2="480" stroke="#e1e0d9" stroke-width="1" />
|
||||
|
||||
<!-- Computed, informational only -->
|
||||
<text x="24" y="506" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">Stromkosten (wird berechnet)</text>
|
||||
<text x="604" y="506" text-anchor="end" font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="12" fill="#898781">680.00</text>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.8 KiB |
|
|
@ -36,18 +36,9 @@ const theme = {
|
|||
|
||||
// de-CH uses a typographic apostrophe; the rest of the app (Formatting.cs) uses a plain one.
|
||||
const amount = new Intl.NumberFormat('de-CH', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||
const axisAmount = new Intl.NumberFormat('de-CH', { maximumFractionDigits: 0 });
|
||||
const formatChf = value => amount.format(value).replace(/’/g, "'");
|
||||
|
||||
// Axis ticks default to whole numbers (CHF amounts in the hundreds/thousands); series with small
|
||||
// values (e.g. CHF/kWh, well under 1) pass data.axisDecimals to avoid every tick rounding to "0".
|
||||
const axisAmountFormatters = new Map();
|
||||
function axisAmount(decimals) {
|
||||
if (!axisAmountFormatters.has(decimals)) {
|
||||
axisAmountFormatters.set(decimals, new Intl.NumberFormat('de-CH', { minimumFractionDigits: decimals, maximumFractionDigits: decimals }));
|
||||
}
|
||||
return axisAmountFormatters.get(decimals);
|
||||
}
|
||||
const formatAxis = (value, decimals = 0) => axisAmount(decimals).format(value).replace(/’/g, "'");
|
||||
const formatAxis = value => axisAmount.format(value).replace(/’/g, "'");
|
||||
|
||||
// Treemap tile helpers: level 0 tiles are parents (their group value is the parent id); level 1
|
||||
// tiles keep the original tree items, which carry the parent id.
|
||||
|
|
@ -77,14 +68,12 @@ const legend = {
|
|||
labels: { usePointStyle: true, pointStyle: 'rectRounded', boxWidth: 10, color: theme.muted, font: { size: 12 } }
|
||||
};
|
||||
|
||||
// unit/decimals default to CHF/0, so existing callers that don't pass data.unit/axisDecimals
|
||||
// keep their current axis.
|
||||
const amountAxis = (unit = 'CHF', decimals = 0) => ({
|
||||
const amountAxis = {
|
||||
grid: { color: theme.grid },
|
||||
border: { display: false },
|
||||
title: { display: true, text: unit, color: theme.muted },
|
||||
ticks: { color: theme.muted, callback: value => formatAxis(value, decimals) }
|
||||
});
|
||||
title: { display: true, text: 'CHF', color: theme.muted },
|
||||
ticks: { color: theme.muted, callback: value => formatAxis(value) }
|
||||
};
|
||||
|
||||
const categoryAxis = { grid: { display: false }, ticks: { color: theme.muted } };
|
||||
|
||||
|
|
@ -121,7 +110,7 @@ const kinds = {
|
|||
order: -1
|
||||
}] : [])]
|
||||
}),
|
||||
options: state => ({
|
||||
options: () => ({
|
||||
interaction: { mode: 'index', intersect: false },
|
||||
plugins: {
|
||||
legend,
|
||||
|
|
@ -130,17 +119,17 @@ const kinds = {
|
|||
filter: item => item.parsed.y !== 0,
|
||||
itemSort: (a, b) => b.parsed.y - a.parsed.y,
|
||||
callbacks: {
|
||||
label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} ${state().unit ?? 'CHF'}`,
|
||||
label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} CHF`,
|
||||
footer: items => {
|
||||
const bars = items.filter(i => i.dataset.type !== 'line');
|
||||
return bars.length === items.length
|
||||
? `Total: ${formatChf(bars.reduce((sum, i) => sum + i.parsed.y, 0))} ${state().unit ?? 'CHF'}`
|
||||
? `Total: ${formatChf(bars.reduce((sum, i) => sum + i.parsed.y, 0))} CHF`
|
||||
: '';
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: { x: { ...categoryAxis, stacked: true }, y: { ...amountAxis(state().unit ?? 'CHF', state().axisDecimals ?? 0), stacked: true } }
|
||||
scales: { x: { ...categoryAxis, stacked: true }, y: { ...amountAxis, stacked: true } }
|
||||
}),
|
||||
hit: (chart, event) => {
|
||||
const hit = chart.getElementsAtEventForMode(event, 'nearest', { intersect: true }, false)[0];
|
||||
|
|
@ -165,7 +154,7 @@ const kinds = {
|
|||
spanGaps: false
|
||||
}))
|
||||
}),
|
||||
options: state => ({
|
||||
options: () => ({
|
||||
interaction: { mode: 'index', intersect: false },
|
||||
plugins: {
|
||||
legend: { ...legend, labels: { ...legend.labels, pointStyle: 'line' } },
|
||||
|
|
@ -173,10 +162,10 @@ const kinds = {
|
|||
...tooltip,
|
||||
filter: item => item.parsed.y !== null,
|
||||
itemSort: (a, b) => b.parsed.y - a.parsed.y,
|
||||
callbacks: { label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} ${state().unit ?? 'CHF'}` }
|
||||
callbacks: { label: item => ` ${item.dataset.label}: ${formatChf(item.parsed.y)} CHF` }
|
||||
}
|
||||
},
|
||||
scales: { x: categoryAxis, y: amountAxis(state().unit ?? 'CHF', state().axisDecimals ?? 0) }
|
||||
scales: { x: categoryAxis, y: amountAxis }
|
||||
}),
|
||||
hit: () => null
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,25 +4,6 @@
|
|||
|
||||
let loading;
|
||||
|
||||
// Enhanced navigation (moving between pages without a full reload) syncs <head> with the
|
||||
// server-rendered page and so removes the stylesheets Monaco added at runtime. Monaco itself stays
|
||||
// loaded in the window, so remember those elements and put them back before the next editor is
|
||||
// created. Monaco keeps references to its <style> elements (e.g. the theme colors) and updates
|
||||
// them in place, so they have to be the same elements, not copies.
|
||||
const monacoStyles = new Set();
|
||||
|
||||
function isMonacoStyle(node) {
|
||||
return node.tagName === 'STYLE' || (node.tagName === 'LINK' && node.href?.includes('/BlazorMonaco/'));
|
||||
}
|
||||
|
||||
function restoreStyles() {
|
||||
for (const node of monacoStyles) {
|
||||
if (node.isConnected === false) {
|
||||
document.head.appendChild(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadScript(src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
|
|
@ -33,14 +14,7 @@ function loadScript(src) {
|
|||
});
|
||||
}
|
||||
|
||||
export async function ensureLoaded() {
|
||||
if (loading === undefined) {
|
||||
new MutationObserver(records => {
|
||||
for (const record of records) {
|
||||
record.addedNodes.forEach(node => isMonacoStyle(node) && monacoStyles.add(node));
|
||||
}
|
||||
}).observe(document.head, { childList: true });
|
||||
}
|
||||
export function ensureLoaded() {
|
||||
loading ??= (async () => {
|
||||
// Sets the AMD path config (var require = ...) and window.blazorMonaco.
|
||||
await loadScript('_content/BlazorMonaco/jsInterop.js');
|
||||
|
|
@ -49,6 +23,5 @@ export async function ensureLoaded() {
|
|||
// editor.main registers itself as an AMD module; wait until it (and window.monaco) is ready.
|
||||
await new Promise(resolve => window.require(['vs/editor/editor.main'], resolve));
|
||||
})();
|
||||
await loading;
|
||||
restoreStyles();
|
||||
return loading;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
// Changes the address bar without navigating. Pages are interactive one by one, so
|
||||
// NavigationManager.NavigateTo runs an enhanced navigation (the page is rendered again on the
|
||||
// server and merged into the DOM), which the JSON editor can't survive.
|
||||
|
||||
/** Replaces the current history entry's URL, keeping Blazor's history state. */
|
||||
export function replace(url) {
|
||||
history.replaceState(history.state, '', url);
|
||||
}
|
||||
Loading…
Reference in a new issue