Adjust location of classes further.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using FinancialApi.Domain.Entities;
|
||||
|
||||
namespace FinancialApi.Domain.Aggregates;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public static BalancedJournal CreateReversal(JournalEntry original, string reason, DateTimeOffset now)
|
||||
{
|
||||
var reversedLines = original.Lines.Select(l =>
|
||||
l with { Type = l.Type == EntryType.Debit ? EntryType.Credit : EntryType.Debit })
|
||||
.ToList();
|
||||
|
||||
return Create(Guid.NewGuid(), reason, now, reversedLines);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user