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>
63 lines
No EOL
2 KiB
C#
63 lines
No EOL
2 KiB
C#
using System;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Datasets
|
|
{
|
|
public class TransactionDataset : Transaction
|
|
{
|
|
public Account OriginAccount { get; set; }
|
|
|
|
public Account TargetAccount { get; set; }
|
|
|
|
public TransactionDataset(Transaction transaction, Account originAccount, Account targetAccout)
|
|
{
|
|
this.BankTransactionId = transaction.BankTransactionId;
|
|
this.Id = transaction.Id;
|
|
this.OriginAccountId = transaction.OriginAccountId;
|
|
this.TargetAccountId = transaction.TargetAccountId;
|
|
this.Text = transaction.Text;
|
|
this.Value = transaction.Value;
|
|
this.FxRate = transaction.FxRate;
|
|
this.ValueDate = transaction.ValueDate;
|
|
this.BookingDate = transaction.BookingDate;
|
|
this.OriginAccount = originAccount;
|
|
this.TargetAccount = targetAccout;
|
|
}
|
|
|
|
public decimal GetValue(bool withFxRate)
|
|
{
|
|
if (withFxRate && FxRate != 0)
|
|
{
|
|
return Math.Round(Value / FxRate.Value, 2);
|
|
}
|
|
else
|
|
return Value;
|
|
}
|
|
|
|
public decimal GetValue(bool withFxRate, string accountId)
|
|
{
|
|
if (accountId == OriginAccountId)
|
|
{
|
|
return -1 * GetValue(withFxRate);
|
|
}
|
|
|
|
return GetValue(withFxRate);
|
|
}
|
|
|
|
/// <summary>
|
|
/// First word of <see cref="Text"/>, used to group related bookings (e.g. "Narbonne Car"
|
|
/// and "Narbonne Food" both group under "Narbonne").
|
|
/// </summary>
|
|
public string GetTextGroup() => GetTextGroup(Text);
|
|
|
|
public static string GetTextGroup(string text)
|
|
{
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
return text;
|
|
}
|
|
var spaceIndex = text.IndexOf(' ');
|
|
return spaceIndex < 0 ? text : text[..spaceIndex];
|
|
}
|
|
}
|
|
} |