23 lines
769 B
C#
23 lines
769 B
C#
namespace FinancialApi.Application;
|
|
|
|
public record BalancedJournal
|
|
{
|
|
public JournalEntry Entry { get; }
|
|
|
|
private BalancedJournal(JournalEntry entry) => Entry = entry;
|
|
|
|
public static BalancedJournal Create(Guid id, string description, DateTimeOffset createdAt, List<JournalLine> lines)
|
|
{
|
|
var debits = lines.Where(l => l.Type == EntryType.Debit).Sum(l => l.Amount);
|
|
var credits = lines.Where(l => l.Type == EntryType.Credit).Sum(l => l.Amount);
|
|
|
|
if (debits != credits)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"GAAP Violation: Total Debits ({debits}) must equal Total Credits ({credits})!"
|
|
);
|
|
}
|
|
|
|
return new(new JournalEntry(id, description, createdAt, lines));
|
|
}
|
|
} |