AccountingNext/Schaad.Accounting.Common/Datasets/Analytics/AnalyticsModels.cs
Claudio Schaad 64494e2de8 Analyse page: income, net and assets views; narrow-screen layout
- View switch Ausgaben | Einnahmen | Netto | Vermögen (URL: view=).
  ExpenseAnalysis becomes AccountingAnalysis:
  - Income: bookings from income accounts positive, to them negative
  - Net: income positive, expenses negative, ordered by size; bar chart with
    a net line, savings-rate tile, no treemap (areas can't be negative)
  - Assets: month-end balances of asset accounts in CHF (foreign balances
    converted once per currency, like the balance sheet); periods take their
    last balance, drill-down ends at the account
- Change colours follow the view: more expenses red, more income/assets green
- Old Vermögen chart page and its menu entry removed
- Narrow screens: side menu starts collapsed below 700px, slimmer header,
  wrapping button groups, two KPI tiles per row, pinned name column in the
  year table

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:38:46 +02:00

121 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#nullable enable
using System;
using System.Collections.Generic;
namespace Schaad.Accounting.Datasets.Analytics
{
public enum AnalyticsPeriod
{
Month,
Quarter,
Year
}
public enum AnalyticsView
{
/// <summary>Net expenses (class 4): bookings to an expense account minus refunds.</summary>
Expenses,
/// <summary>Net income (class 3): bookings from an income account minus corrections.</summary>
Income,
/// <summary>Income minus expenses: income subclasses positive, expense subclasses negative.</summary>
Net,
/// <summary>Month-end balances of the asset accounts (class 1), in CHF. A stock, not a flow.</summary>
Assets
}
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, AnalyticsView View = AnalyticsView.Expenses);
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.
/// For <see cref="AnalyticsView.Assets"/> it compares the balances at the end of those months.
/// </summary>
public record YearComparison(int Year, int Months, decimal Current, decimal Previous)
{
public decimal? ChangePercent => Previous == 0 ? null : (Current - Previous) / Math.Abs(Previous) * 100;
}
/// <summary>
/// Monthly values of the queried node in one year (index 0 = January): sums, or month-end
/// balances for <see cref="AnalyticsView.Assets"/>. Months after the last month with data are
/// null. <see cref="Total"/> is the year's sum, or its last balance.
/// </summary>
public record YearProfile(int Year, IReadOnlyList<decimal?> Months, decimal Total);
/// <summary>
/// A category's value in one year (for <see cref="AnalyticsView.Assets"/>: its balance at the end
/// of the year). For the running year only the months with data count, and the change compares
/// the same months of the previous year.
/// </summary>
public record YearCell(int Year, decimal Value, decimal? ChangePercent);
/// <summary>
/// One row of the category × year table, in the same order as <see cref="AnalyticsResult.Categories"/>.
/// </summary>
public record CategoryYears(AnalyticsNode Node, string Name, bool CanDrillDown, IReadOnlyList<YearCell> Cells, decimal Total);
/// <summary>
/// A treemap tile: a child of the queried node and, one level deeper, one of its children.
/// <see cref="Child"/> is null when the child has no deeper level (booking-text groups).
/// Only positive amounts are included; an area can't show a refund.
/// </summary>
public record CompositionItem(AnalyticsNode Parent, string ParentName, AnalyticsNode? Child, string? ChildName, decimal Value);
/// <summary>
/// <see cref="Total"/> is the sum over the range, or for <see cref="AnalyticsView.Assets"/> the
/// balance at its end; <see cref="Opening"/> is then the balance at its start (null otherwise).
/// </summary>
public record AnalyticsResult(
IReadOnlyList<AnalyticsBreadcrumb> Breadcrumb,
IReadOnlyList<DateOnly> Periods,
IReadOnlyList<AnalyticsCategory> Categories,
decimal Total,
int Months,
decimal AveragePerMonth,
YearComparison? Comparison,
IReadOnlyList<YearProfile> YearProfiles,
IReadOnlyList<CategoryYears> CategoryYears,
IReadOnlyList<CompositionItem> Composition,
decimal? Opening = null);
}