New page /analytics shows the current mandator's expenses across all years, with drill-down all -> subclass -> account -> booking-text group, year range and month/quarter/year filters, KPI tiles, a stacked bar chart and a category list. Filters and drill-down position live in the URL. - MultiYearRepository reads any mandator/year (read-only, shared cache) - ExpenseAnalysis flattens all years and answers queries in memory: net amounts (refunds count negative), accounts keyed by number with the latest name, bookings counted in the year of their books, year-over-year comparison over the same months - Chart.js 4.5.1 vendored in wwwroot/lib/chartjs, wrapped by wwwroot/js/charts.js and StackedBarChart.razor Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Schaad.Accounting.Datasets.Analytics
|
|
{
|
|
public enum AnalyticsPeriod
|
|
{
|
|
Month,
|
|
Quarter,
|
|
Year
|
|
}
|
|
|
|
public enum AnalyticsLevel
|
|
{
|
|
All,
|
|
SubClass,
|
|
Account,
|
|
Text
|
|
}
|
|
|
|
/// <summary>
|
|
/// A position in the drill-down: all expenses → subclass → account → booking-text group.
|
|
/// Deeper nodes carry their parents (an account node also has its subclass).
|
|
/// </summary>
|
|
public record AnalyticsNode(int? SubClass = null, int? Account = null, string? Text = null)
|
|
{
|
|
public static readonly AnalyticsNode All = new();
|
|
|
|
public AnalyticsLevel Level =>
|
|
Text != null ? AnalyticsLevel.Text
|
|
: Account != null ? AnalyticsLevel.Account
|
|
: SubClass != null ? AnalyticsLevel.SubClass
|
|
: AnalyticsLevel.All;
|
|
}
|
|
|
|
public record AnalyticsQuery(int FromYear, int ToYear, AnalyticsPeriod Period, AnalyticsNode Node);
|
|
|
|
public record AnalyticsBreadcrumb(AnalyticsNode Node, string Name);
|
|
|
|
/// <summary>
|
|
/// One child of the queried node, with its value per period (aligned with
|
|
/// <see cref="AnalyticsResult.Periods"/>).
|
|
/// </summary>
|
|
public record AnalyticsCategory(
|
|
AnalyticsNode Node,
|
|
string Name,
|
|
IReadOnlyList<decimal> Values,
|
|
decimal Total,
|
|
decimal Share,
|
|
bool CanDrillDown);
|
|
|
|
/// <summary>
|
|
/// The last year of the range against the year before, over the same months
|
|
/// (January to <see cref="Months"/>), so an unfinished year compares fairly.
|
|
/// </summary>
|
|
public record YearComparison(int Year, int Months, decimal Current, decimal Previous)
|
|
{
|
|
public decimal? ChangePercent => Previous == 0 ? null : (Current - Previous) / Math.Abs(Previous) * 100;
|
|
}
|
|
|
|
public record AnalyticsResult(
|
|
IReadOnlyList<AnalyticsBreadcrumb> Breadcrumb,
|
|
IReadOnlyList<DateOnly> Periods,
|
|
IReadOnlyList<AnalyticsCategory> Categories,
|
|
decimal Total,
|
|
int Months,
|
|
decimal AveragePerMonth,
|
|
YearComparison? Comparison);
|
|
}
|