## Summary
Step 4 of the analytics plan, items 2, 4 and 5: **income, net and assets views** on the Analyse page (replacing the old Vermögen chart page) and a **narrow-screen layout** pass.
### Views
A switch at the top selects **Ausgaben | Einnahmen | Netto | Vermögen**, stored in the URL as `view=`. Switching starts the drill-down from the top, because the subclasses differ per view.
- **Einnahmen:** works like Ausgaben. Bookings *from* an income account count positive, bookings *to* one (corrections) negative.
- **Netto:** income minus expenses. Income subclasses are positive and expense subclasses negative.
- The bar chart stacks income up and expenses down, with a black line for the net result per period; the tooltip total is left out there.
- Categories are ordered by size, so the big expense groups aren't folded into "Andere".
- The fourth tile shows the **savings rate** (net / income).
- No treemap, since areas can't show negative amounts.
- **Vermögen:** month-end balances of the asset accounts (class 1) in CHF. It is a stock, not a flow:
- A month, quarter or year shows the balance at its end, and the total is the balance at the end of the range.
- Tiles show that balance, the change since the start of the range (with the opening balance), and the comparison with the same month a year earlier.
- The year table shows year-end balances; the drill-down ends at the account.
- The year comparison shows month-end balances, without the cumulative switch.
- Foreign-currency balances are computed like the balance sheet (`ViewService`): kept in the account currency and converted with `IFxConverter`, which is asked once per currency.
- **Colours follow the view:** more expenses are red; more income, surplus or assets green. The CSS classes are now `worse` / `better` instead of `up` / `down`.
### Code
- `ExpenseAnalysis` → **`AccountingAnalysis`** with `AnalyticsView` (Expenses, Income, Net, Assets), and `GetExpenseAnalysisAsync` → `GetAnalysisAsync`. The running year's last month now comes from all bookings, not just expenses.
- `AnalyticsResult.Opening` gives the balance at the start of the range for Vermögen.
- `charts.js`: the stacked bar chart takes an optional `totalLine`.
### Removed
- The **Vermögen** chart page (`/Assets`) and its menu entry. Plotly is now only used by the booking-text charts on the Transactions page.
### Narrow screens
At 400 px the page was wider than the screen.
- **App-wide:** the side menu took half the screen. It now starts collapsed to icons below 700 px (`wwwroot/js/viewport.js`); the ☰ toggle still opens it. The header dropdowns are narrower, and the app name hides below 520 px.
- **Analyse page:** button groups wrap, the tiles sit two per row, and in the year table the name column is narrower and pinned while the years scroll, with the full name as a tooltip.
## Test plan
- [x] `dotnet build`: no warnings
- [x] `dotnet test`: 88/88 pass, including 7 new `AccountingAnalysisTestShould` tests (income signs, net ordering, month-end balances with opening, balance at period end, FX conversion asked once, comparison at the same month, assets drill-down ends at the account)
- [x] Against a copy of the real data, all matching the app's own reports:
- Einnahmen 2026 = 109'865.13 ("Total Einkünfte" in the profit-and-loss report)
- Netto 2026 = 32'859.06 (= 109'865.13 − 77'006.07)
- Vermögen end of Oct 2026 = 263'994.98 ("Total Aktiven" in the Bilanz)
- [x] Headless Chrome at 400, 820 and 1500 px: no horizontal overflow; menu collapsed at 400 px and expanded at 820 / 1500 px; pinned table column scrolls correctly; all charts render without console errors
## Note on the data (not a code issue)
The Vermögen view shows each year as its books say. In the real data, some closing balances don't match the next year's opening balances. These are probably bookings added to a year after the next one was opened:
- End of 2024 → 2025: Bargeld CHF (+40.75)
- End of 2025 → 2026: Bargeld CHF (+98.50), TKB Privatkonto (+200.00), account 1042 (2'030.40 at the end of 2025, missing in 2026), Durchlaufskonto (−7.29)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed-on: #6
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
442 lines
20 KiB
C#
442 lines
20 KiB
C#
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Schaad.Accounting.Datasets;
|
|
using Schaad.Accounting.Datasets.Analytics;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Services
|
|
{
|
|
/// <summary>
|
|
/// The bookings of one mandator over all years, flattened into one row per
|
|
/// (month, account, booking-text group) and view, so every query is an in-memory group-by.
|
|
///
|
|
/// <list type="bullet">
|
|
/// <item>Expenses: a booking to an expense account counts positive, a booking from one
|
|
/// (refund, correction) negative.</item>
|
|
/// <item>Income: a booking from an income account counts positive, a booking to one negative.</item>
|
|
/// <item>Net: income positive, expenses negative.</item>
|
|
/// <item>Assets: one row per asset account and month with its balance at the end of that month
|
|
/// (opening balance of the year plus the bookings so far), in CHF. Rows are balances, not
|
|
/// amounts: a period takes its last month instead of the sum.</item>
|
|
/// </list>
|
|
///
|
|
/// Bookings count in the year of the books they are in. Accounts are identified by number across
|
|
/// years and shown with the name from the latest year they appear in.
|
|
/// </summary>
|
|
public class AccountingAnalysis
|
|
{
|
|
private const string NoTextName = "(ohne Text)";
|
|
|
|
private static readonly Dictionary<AnalyticsView, string> RootNames = new()
|
|
{
|
|
[AnalyticsView.Expenses] = "Ausgaben",
|
|
[AnalyticsView.Income] = "Einnahmen",
|
|
[AnalyticsView.Net] = "Netto",
|
|
[AnalyticsView.Assets] = "Vermögen"
|
|
};
|
|
|
|
private record Fact(DateOnly Month, int Account, string Text, decimal Amount);
|
|
|
|
private readonly Dictionary<AnalyticsView, List<Fact>> factsByView = new()
|
|
{
|
|
[AnalyticsView.Expenses] = new(),
|
|
[AnalyticsView.Income] = new(),
|
|
[AnalyticsView.Net] = new(),
|
|
[AnalyticsView.Assets] = new()
|
|
};
|
|
// Opening balance (CHF) per year and asset account.
|
|
private readonly Dictionary<(int Year, int Account), decimal> openings = new();
|
|
private readonly Dictionary<int, string> accountNames = new();
|
|
private readonly Dictionary<int, string> subClassNames = new();
|
|
private readonly DateOnly? lastMonth;
|
|
|
|
public IReadOnlyList<int> Years { get; }
|
|
|
|
/// <param name="chfRate">CHF value of one unit of a currency; asked once per currency.</param>
|
|
public AccountingAnalysis(IEnumerable<YearData> years, Func<string, decimal>? chfRate = null)
|
|
{
|
|
var ordered = years.OrderBy(y => y.Year).ToList();
|
|
Years = ordered.Select(y => y.Year).ToList();
|
|
|
|
var bookMonths = ordered
|
|
.SelectMany(y => y.Transactions.Select(t => BookMonth(t.ValueDate, y.Year)))
|
|
.ToList();
|
|
lastMonth = bookMonths.Count > 0 ? bookMonths.Max() : null;
|
|
|
|
var rates = new Dictionary<string, decimal>();
|
|
decimal RateOf(Account account)
|
|
{
|
|
if (account.IsFxAccount == false || chfRate is null)
|
|
{
|
|
return 1;
|
|
}
|
|
if (rates.TryGetValue(account.Currency, out var rate) == false)
|
|
{
|
|
rate = rates[account.Currency] = chfRate(account.Currency);
|
|
}
|
|
return rate;
|
|
}
|
|
|
|
foreach (var year in ordered)
|
|
{
|
|
// Later years overwrite earlier names, so the latest name wins.
|
|
foreach (var account in year.Accounts)
|
|
{
|
|
accountNames[account.Number] = account.Name;
|
|
}
|
|
foreach (var subClass in year.SubClasses)
|
|
{
|
|
subClassNames[subClass.Number] = subClass.Name;
|
|
}
|
|
|
|
var accountsById = year.Accounts.Where(a => a.Id != null).ToDictionary(a => a.Id);
|
|
// Asset flows per account and month, in the account's currency.
|
|
var assetFlows = new Dictionary<(int Account, int Month), decimal>();
|
|
|
|
foreach (var transaction in year.Transactions)
|
|
{
|
|
var month = BookMonth(transaction.ValueDate, year.Year);
|
|
var text = TransactionDataset.GetTextGroup(transaction.Text) ?? "";
|
|
accountsById.TryGetValue(transaction.TargetAccountId ?? "", out var target);
|
|
accountsById.TryGetValue(transaction.OriginAccountId ?? "", out var origin);
|
|
|
|
if (target?.Class == ClassIds.Expenses)
|
|
{
|
|
AddFlow(AnalyticsView.Expenses, new Fact(month, target.Number, text, transaction.Value));
|
|
}
|
|
if (origin?.Class == ClassIds.Expenses)
|
|
{
|
|
AddFlow(AnalyticsView.Expenses, new Fact(month, origin.Number, text, -transaction.Value));
|
|
}
|
|
if (origin?.Class == ClassIds.Income)
|
|
{
|
|
AddFlow(AnalyticsView.Income, new Fact(month, origin.Number, text, transaction.Value));
|
|
}
|
|
if (target?.Class == ClassIds.Income)
|
|
{
|
|
AddFlow(AnalyticsView.Income, new Fact(month, target.Number, text, -transaction.Value));
|
|
}
|
|
|
|
if (target?.Class == ClassIds.Activa)
|
|
{
|
|
AddAssetFlow(assetFlows, target, month.Month, InAccountCurrency(transaction, target));
|
|
}
|
|
if (origin?.Class == ClassIds.Activa)
|
|
{
|
|
AddAssetFlow(assetFlows, origin, month.Month, -InAccountCurrency(transaction, origin));
|
|
}
|
|
}
|
|
|
|
AddBalances(year, assetFlows, RateOf);
|
|
}
|
|
}
|
|
|
|
private void AddFlow(AnalyticsView view, Fact fact)
|
|
{
|
|
factsByView[view].Add(fact);
|
|
factsByView[AnalyticsView.Net].Add(view == AnalyticsView.Expenses ? fact with { Amount = -fact.Amount } : fact);
|
|
}
|
|
|
|
private static void AddAssetFlow(Dictionary<(int, int), decimal> flows, Account account, int month, decimal amount)
|
|
{
|
|
flows[(account.Number, month)] = flows.GetValueOrDefault((account.Number, month)) + amount;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Same as the balance sheet (ViewService): amounts of a foreign-currency account are kept
|
|
/// in its currency and only the balance is converted.
|
|
/// </summary>
|
|
private static decimal InAccountCurrency(Transaction transaction, Account account)
|
|
=> account.IsFxAccount && transaction.FxRate is { } rate && rate != 0
|
|
? Math.Round(transaction.Value / rate, 2)
|
|
: transaction.Value;
|
|
|
|
private void AddBalances(YearData year, Dictionary<(int Account, int Month), decimal> flows, Func<Account, decimal> rateOf)
|
|
{
|
|
var lastMonthOfYear = lastMonth is { } last && last.Year == year.Year ? last.Month : 12;
|
|
foreach (var account in year.Accounts.Where(a => a.Class == ClassIds.Activa))
|
|
{
|
|
var rate = rateOf(account);
|
|
openings[(year.Year, account.Number)] = account.StartBalance * rate;
|
|
|
|
var balance = account.StartBalance;
|
|
for (var month = 1; month <= lastMonthOfYear; month++)
|
|
{
|
|
balance += flows.GetValueOrDefault((account.Number, month));
|
|
factsByView[AnalyticsView.Assets].Add(new Fact(new DateOnly(year.Year, month, 1), account.Number, "", balance * rate));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A booking belongs to the year of the books it is in, like in the annual reports. The
|
|
/// few bookings dated outside that year (late-December payments booked in the next year)
|
|
/// go to its first or last month.
|
|
/// </summary>
|
|
private static DateOnly BookMonth(DateTime valueDate, int bookYear)
|
|
{
|
|
var month = new DateOnly(valueDate.Year, valueDate.Month, 1);
|
|
var first = new DateOnly(bookYear, 1, 1);
|
|
var last = new DateOnly(bookYear, 12, 1);
|
|
return month < first ? first : month > last ? last : month;
|
|
}
|
|
|
|
public AnalyticsResult Query(AnalyticsQuery query)
|
|
{
|
|
var view = query.View;
|
|
var isStock = view == AnalyticsView.Assets;
|
|
var node = Normalize(query.Node, view);
|
|
|
|
var start = new DateOnly(query.FromYear, 1, 1);
|
|
var end = new DateOnly(query.ToYear, 12, 1);
|
|
if (lastMonth is { } last && last < end && last >= start)
|
|
{
|
|
// Don't count months that have no data yet (the running year).
|
|
end = last;
|
|
}
|
|
var months = (end.Year - start.Year) * 12 + end.Month - start.Month + 1;
|
|
|
|
var nodeFacts = factsByView[view].Where(f => IsInNode(f, node)).ToList();
|
|
var inRange = nodeFacts.Where(f => f.Month >= start && f.Month <= end).ToList();
|
|
|
|
var periods = GetPeriods(start, end, query.Period);
|
|
var periodIndex = periods.Select((p, i) => (p, i)).ToDictionary(x => x.p, x => x.i);
|
|
|
|
// A balance counts at the end of its period (or of the range), an amount in its period.
|
|
bool CountsIn(Fact fact) => isStock == false || fact.Month == PeriodEnd(fact.Month, query.Period, end);
|
|
var total = inRange.Where(f => isStock == false || f.Month == end).Sum(f => f.Amount);
|
|
|
|
var categories = inRange
|
|
.GroupBy(f => ChildOf(f, node, view))
|
|
.Select(g =>
|
|
{
|
|
var values = new decimal[periods.Count];
|
|
foreach (var fact in g.Where(CountsIn))
|
|
{
|
|
values[periodIndex[PeriodStart(fact.Month, query.Period)]] += fact.Amount;
|
|
}
|
|
var categoryTotal = isStock ? g.Where(f => f.Month == end).Sum(f => f.Amount) : values.Sum();
|
|
return new AnalyticsCategory(
|
|
g.Key,
|
|
NameOf(g.Key, view),
|
|
values,
|
|
categoryTotal,
|
|
total == 0 ? 0 : categoryTotal / total,
|
|
CanDrillDown: g.Key.Level < LeafLevel(view));
|
|
})
|
|
// Accounts whose bookings cancel out completely are noise, not a category.
|
|
.Where(c => c.Values.Any(v => v != 0))
|
|
// Net mixes income (positive) and expenses (negative); by size, the big expenses
|
|
// stay among the first categories instead of being folded away last.
|
|
.OrderByDescending(c => view == AnalyticsView.Net ? Math.Abs(c.Total) : c.Total)
|
|
.ToList();
|
|
|
|
decimal? opening = isStock
|
|
? openings.Where(o => o.Key.Year == start.Year && IsInNode(new Fact(start, o.Key.Account, "", 0), node)).Sum(o => o.Value)
|
|
: null;
|
|
|
|
return new AnalyticsResult(
|
|
GetBreadcrumb(node, view),
|
|
periods,
|
|
categories,
|
|
total,
|
|
months,
|
|
isStock || months == 0 ? 0 : total / months,
|
|
GetComparison(nodeFacts, end, isStock),
|
|
GetYearProfiles(nodeFacts, start, end, isStock),
|
|
GetCategoryYears(nodeFacts, node, view, categories, start, end, isStock),
|
|
GetComposition(inRange, node, view, categories, end, isStock),
|
|
opening);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Booking texts mean nothing for balances, so the assets drill-down ends at the account.
|
|
/// </summary>
|
|
private static AnalyticsLevel LeafLevel(AnalyticsView view)
|
|
=> view == AnalyticsView.Assets ? AnalyticsLevel.Account : AnalyticsLevel.Text;
|
|
|
|
private static AnalyticsNode Normalize(AnalyticsNode node, AnalyticsView view)
|
|
=> view == AnalyticsView.Assets && node.Text != null ? node with { Text = null } : node;
|
|
|
|
private YearComparison? GetComparison(List<Fact> nodeFacts, DateOnly end, bool isStock)
|
|
{
|
|
var year = end.Year;
|
|
if (Years.Contains(year - 1) == false)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var current = SumYear(nodeFacts, year, end.Month, isStock);
|
|
var previous = SumYear(nodeFacts, year - 1, end.Month, isStock);
|
|
return new YearComparison(year, end.Month, current, previous);
|
|
}
|
|
|
|
private static List<YearProfile> GetYearProfiles(List<Fact> nodeFacts, DateOnly start, DateOnly end, bool isStock)
|
|
{
|
|
var profiles = new List<YearProfile>();
|
|
for (var year = start.Year; year <= end.Year; year++)
|
|
{
|
|
var lastMonthOfYear = year == end.Year ? end.Month : 12;
|
|
var months = new decimal?[12];
|
|
for (var month = 1; month <= lastMonthOfYear; month++)
|
|
{
|
|
months[month - 1] = 0;
|
|
}
|
|
foreach (var fact in nodeFacts.Where(f => f.Month.Year == year && f.Month.Month <= lastMonthOfYear))
|
|
{
|
|
months[fact.Month.Month - 1] += fact.Amount;
|
|
}
|
|
var yearTotal = isStock ? months[lastMonthOfYear - 1] ?? 0 : months.Sum() ?? 0;
|
|
profiles.Add(new YearProfile(year, months, yearTotal));
|
|
}
|
|
return profiles;
|
|
}
|
|
|
|
private List<CategoryYears> GetCategoryYears(
|
|
List<Fact> nodeFacts, AnalyticsNode node, AnalyticsView view, List<AnalyticsCategory> categories,
|
|
DateOnly start, DateOnly end, bool isStock)
|
|
{
|
|
// Not limited to the range: the first year's change needs the year before.
|
|
var factsByChild = nodeFacts.GroupBy(f => ChildOf(f, node, view)).ToDictionary(g => g.Key, g => g.ToList());
|
|
|
|
return categories.Select(category =>
|
|
{
|
|
var childFacts = factsByChild.GetValueOrDefault(category.Node) ?? new List<Fact>();
|
|
var cells = new List<YearCell>();
|
|
for (var year = start.Year; year <= end.Year; year++)
|
|
{
|
|
var lastMonthOfYear = year == end.Year ? end.Month : 12;
|
|
var value = SumYear(childFacts, year, lastMonthOfYear, isStock);
|
|
decimal? change = null;
|
|
if (Years.Contains(year - 1))
|
|
{
|
|
var previous = SumYear(childFacts, year - 1, lastMonthOfYear, isStock);
|
|
change = previous == 0 ? null : (value - previous) / Math.Abs(previous) * 100;
|
|
}
|
|
cells.Add(new YearCell(year, value, change));
|
|
}
|
|
return new CategoryYears(category.Node, category.Name, category.CanDrillDown, cells, category.Total);
|
|
}).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Amounts from January to <paramref name="lastMonthOfYear"/>, or the balance at its end.
|
|
/// </summary>
|
|
private static decimal SumYear(List<Fact> facts, int year, int lastMonthOfYear, bool isStock)
|
|
=> isStock
|
|
? facts.Where(f => f.Month.Year == year && f.Month.Month == lastMonthOfYear).Sum(f => f.Amount)
|
|
: facts.Where(f => f.Month.Year == year && f.Month.Month <= lastMonthOfYear).Sum(f => f.Amount);
|
|
|
|
private List<CompositionItem> GetComposition(
|
|
List<Fact> inRange, AnalyticsNode node, AnalyticsView view, List<AnalyticsCategory> categories,
|
|
DateOnly end, bool isStock)
|
|
{
|
|
var facts = isStock ? inRange.Where(f => f.Month == end).ToList() : inRange;
|
|
var items = new List<CompositionItem>();
|
|
foreach (var category in categories.Where(c => c.Total > 0))
|
|
{
|
|
if (category.Node.Level == LeafLevel(view))
|
|
{
|
|
items.Add(new CompositionItem(category.Node, category.Name, null, null, category.Total));
|
|
continue;
|
|
}
|
|
|
|
var children = facts
|
|
.Where(f => ChildOf(f, node, view) == category.Node)
|
|
.GroupBy(f => ChildOf(f, category.Node, view))
|
|
.Select(g => (Node: g.Key, Value: g.Sum(f => f.Amount)))
|
|
.Where(c => c.Value > 0)
|
|
.OrderByDescending(c => c.Value);
|
|
foreach (var child in children)
|
|
{
|
|
items.Add(new CompositionItem(category.Node, category.Name, child.Node, NameOf(child.Node, view), child.Value));
|
|
}
|
|
}
|
|
return items;
|
|
}
|
|
|
|
private static bool IsInNode(Fact fact, AnalyticsNode node) => node.Level switch
|
|
{
|
|
AnalyticsLevel.All => true,
|
|
AnalyticsLevel.SubClass => fact.Account / 100 == node.SubClass,
|
|
AnalyticsLevel.Account => fact.Account == node.Account,
|
|
_ => fact.Account == node.Account && fact.Text == node.Text
|
|
};
|
|
|
|
private static AnalyticsNode ChildOf(Fact fact, AnalyticsNode node, AnalyticsView view)
|
|
{
|
|
// The lowest level is its own only child.
|
|
if (node.Level >= LeafLevel(view))
|
|
{
|
|
return node;
|
|
}
|
|
return node.Level switch
|
|
{
|
|
AnalyticsLevel.All => new AnalyticsNode(SubClass: fact.Account / 100),
|
|
AnalyticsLevel.SubClass => new AnalyticsNode(SubClass: fact.Account / 100, Account: fact.Account),
|
|
_ => new AnalyticsNode(SubClass: fact.Account / 100, Account: fact.Account, Text: fact.Text)
|
|
};
|
|
}
|
|
|
|
private string NameOf(AnalyticsNode node, AnalyticsView view) => node.Level switch
|
|
{
|
|
AnalyticsLevel.All => RootNames[view],
|
|
AnalyticsLevel.SubClass => subClassNames.GetValueOrDefault(node.SubClass!.Value, $"Subklasse {node.SubClass}"),
|
|
AnalyticsLevel.Account => accountNames.GetValueOrDefault(node.Account!.Value, $"Konto {node.Account}"),
|
|
_ => string.IsNullOrEmpty(node.Text) ? NoTextName : node.Text
|
|
};
|
|
|
|
private List<AnalyticsBreadcrumb> GetBreadcrumb(AnalyticsNode node, AnalyticsView view)
|
|
{
|
|
var path = new List<AnalyticsBreadcrumb> { new(AnalyticsNode.All, RootNames[view]) };
|
|
if (node.SubClass is { } subClass)
|
|
{
|
|
path.Add(new(new AnalyticsNode(subClass), NameOf(new AnalyticsNode(subClass), view)));
|
|
}
|
|
if (node.Account is { } account)
|
|
{
|
|
path.Add(new(new AnalyticsNode(account / 100, account), NameOf(new AnalyticsNode(account / 100, account), view)));
|
|
}
|
|
if (node.Text is not null)
|
|
{
|
|
path.Add(new(node, NameOf(node, view)));
|
|
}
|
|
return path;
|
|
}
|
|
|
|
private static List<DateOnly> GetPeriods(DateOnly start, DateOnly end, AnalyticsPeriod period)
|
|
{
|
|
var step = period switch { AnalyticsPeriod.Month => 1, AnalyticsPeriod.Quarter => 3, _ => 12 };
|
|
var periods = new List<DateOnly>();
|
|
for (var p = PeriodStart(start, period); p <= end; p = p.AddMonths(step))
|
|
{
|
|
periods.Add(p);
|
|
}
|
|
return periods;
|
|
}
|
|
|
|
private static DateOnly PeriodStart(DateOnly month, AnalyticsPeriod period) => period switch
|
|
{
|
|
AnalyticsPeriod.Month => month,
|
|
AnalyticsPeriod.Quarter => new DateOnly(month.Year, (month.Month - 1) / 3 * 3 + 1, 1),
|
|
_ => new DateOnly(month.Year, 1, 1)
|
|
};
|
|
|
|
/// <summary>
|
|
/// Last month of the period containing <paramref name="month"/>, but not after the range end.
|
|
/// </summary>
|
|
private static DateOnly PeriodEnd(DateOnly month, AnalyticsPeriod period, DateOnly rangeEnd)
|
|
{
|
|
var periodEnd = period switch
|
|
{
|
|
AnalyticsPeriod.Month => month,
|
|
AnalyticsPeriod.Quarter => PeriodStart(month, period).AddMonths(2),
|
|
_ => new DateOnly(month.Year, 12, 1)
|
|
};
|
|
return periodEnd > rangeEnd ? rangeEnd : periodEnd;
|
|
}
|
|
}
|
|
}
|