Phase C: Add Manual Journal Entries (double-entry GL)
- JournalEntry + JournalEntryLine entities with Draft/Posted/Reversed lifecycle - JournalEntryStatus enum (Draft, Posted, Reversed) - Migration AddJournalEntries: two new tables with self-referencing reversal FK - IUnitOfWork/UnitOfWork wired with JournalEntries + JournalEntryLines repos - ApplicationDbContext: DbSets, tenant query filters, reversal FK config - LedgerService: JE lines added as 10th source in GetAccountLedgerAsync and ComputePriorBalanceAsync - JournalEntriesController: Index (All/Draft/Posted tabs), Create, Details, Post, Reverse, Delete - Views: Index, Create (dynamic balanced line grid with running debit/credit totals), Details - journal-entry-create.js: dynamic line management with balance indicator - Nav: Journal Entries added to Finance section in _Layout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -298,6 +298,28 @@ public class LedgerService : ILedgerService
|
||||
});
|
||||
}
|
||||
|
||||
// ── 10. Journal Entry lines touching this account ──────────────────
|
||||
var jeLines = await _context.JournalEntryLines
|
||||
.Include(l => l.JournalEntry)
|
||||
.Where(l => l.AccountId == accountId
|
||||
&& l.JournalEntry.Status == JournalEntryStatus.Posted
|
||||
&& l.JournalEntry.EntryDate >= fromDate
|
||||
&& l.JournalEntry.EntryDate <= toDate)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var line in jeLines)
|
||||
entries.Add(new LedgerEntryDto
|
||||
{
|
||||
Date = line.JournalEntry.EntryDate,
|
||||
Reference = line.JournalEntry.EntryNumber,
|
||||
Source = "Journal Entry",
|
||||
Description = line.Description ?? line.JournalEntry.Description,
|
||||
Debit = line.DebitAmount,
|
||||
Credit = line.CreditAmount,
|
||||
LinkController = "JournalEntries",
|
||||
LinkId = line.JournalEntry.Id
|
||||
});
|
||||
|
||||
// ── Sort and compute running balance ──────────────────────────────────
|
||||
entries = entries
|
||||
.OrderBy(e => e.Date)
|
||||
@@ -429,6 +451,19 @@ public class LedgerService : ILedgerService
|
||||
.SumAsync(bp => (decimal?)bp.Amount) ?? 0;
|
||||
}
|
||||
|
||||
// 10. Posted journal entry lines touching this account (prior to period)
|
||||
debits += await _context.JournalEntryLines
|
||||
.Where(l => l.AccountId == accountId
|
||||
&& l.JournalEntry.Status == JournalEntryStatus.Posted
|
||||
&& l.JournalEntry.EntryDate < beforeDate)
|
||||
.SumAsync(l => (decimal?)l.DebitAmount) ?? 0;
|
||||
|
||||
credits += await _context.JournalEntryLines
|
||||
.Where(l => l.AccountId == accountId
|
||||
&& l.JournalEntry.Status == JournalEntryStatus.Posted
|
||||
&& l.JournalEntry.EntryDate < beforeDate)
|
||||
.SumAsync(l => (decimal?)l.CreditAmount) ?? 0;
|
||||
|
||||
decimal netActivity = normalDebitBalance ? debits - credits : credits - debits;
|
||||
|
||||
// Apply the opening balance if it was established on or before the end of the viewed period.
|
||||
|
||||
Reference in New Issue
Block a user