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>
51 lines
2 KiB
C#
51 lines
2 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using Schaad.Accounting.Datasets.Analytics;
|
|
using Schaad.Accounting.Interfaces;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Repositories
|
|
{
|
|
public class MultiYearRepository : BaseRepository, IMultiYearRepository
|
|
{
|
|
private const string ACCOUNTS = "Accounts.json";
|
|
private const string SUBCLASSES = "SubClasses.json";
|
|
private const string TRANSACTIONS = "Transactions.json";
|
|
|
|
public MultiYearRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<MultiYearRepository> logger)
|
|
: base(settingsService, cache, logger)
|
|
{
|
|
}
|
|
|
|
public IReadOnlyList<int> GetYears(string mandator)
|
|
{
|
|
var mandatorPath = Path.Combine(settingsService.GetSettings().DataPath, mandator);
|
|
if (Directory.Exists(mandatorPath) == false)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
// Empty year folders exist (GetLastYearDbPath creates them); only years with accounts count.
|
|
return Directory.GetDirectories(mandatorPath)
|
|
.Select(Path.GetFileName)
|
|
.Where(name => int.TryParse(name, out _) && File.Exists(Path.Combine(mandatorPath, name, ACCOUNTS)))
|
|
.Select(int.Parse)
|
|
.Order()
|
|
.ToList();
|
|
}
|
|
|
|
public async Task<YearData> GetYearDataAsync(string mandator, int year)
|
|
{
|
|
// Read-only: never creates folders or copies last year's files, unlike GetDbPath/EnsureFileExists.
|
|
var directory = Path.Combine(settingsService.GetSettings().DataPath, mandator, year.ToString());
|
|
return new YearData(
|
|
year,
|
|
await LoadListAsync<Account>(directory, ACCOUNTS),
|
|
await LoadListAsync<SubClass>(directory, SUBCLASSES),
|
|
await LoadListAsync<Transaction>(directory, TRANSACTIONS));
|
|
}
|
|
}
|
|
}
|