AccountingNext/Schaad.Accounting.Common/Datasets/TransactionDataset.cs
Claudio Schaad 5d6d49ed8b Group booking-text charts by first word instead of full text
Bookings like "Narbonne Car" and "Narbonne Food" should roll up into
one series/slice instead of staying separate, so grouping now uses
the text up to the first space via TransactionDataset.GetTextGroup().
2026-08-07 18:23:22 +02:00

62 lines
No EOL
1.9 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()
{
if (string.IsNullOrEmpty(Text))
{
return Text;
}
var spaceIndex = Text.IndexOf(' ');
return spaceIndex < 0 ? Text : Text[..spaceIndex];
}
}
}