Add Phase A accounting features: AP Aging, Trial Balance, Cash vs Accrual

- AP Aging report (GetApAgingAsync, controller actions, view, PDF export)
  mirrors AR Aging — groups open bills by vendor, buckets by days past due date
- Trial Balance report (GetTrialBalanceAsync, view, PDF export)
  uses Account.CurrentBalance, groups by AccountType, validates debits == credits
- Cash vs Accrual accounting method setting on Company entity
  switchable at any time — report-time only, no GL re-posting on change
  P&L cash: revenue = payments received; expenses = bills/expenses paid in period
  Balance Sheet cash: omits AR and AP lines (no receivables/payables concept)
  AccountingMethod badge shown on P&L and Balance Sheet views
- Migration A (AddAccountingMethod) applied, default = Accrual for all existing companies
- AP Aging and Trial Balance added to Reports Landing page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 23:34:54 -04:00
parent 379b0de885
commit 7e1676cfd7
18 changed files with 10765 additions and 67 deletions
@@ -0,0 +1,183 @@
@model PowderCoating.Application.DTOs.Accounting.TrialBalanceDto
@using PowderCoating.Core.Enums
@{
ViewData["Title"] = "Trial Balance";
ViewData["PageIcon"] = "bi-list-columns-reverse";
var today = DateTime.Today;
var grouped = Model.Lines.GroupBy(l => l.AccountType).OrderBy(g => g.Key.ToString());
}
<style>
@@media print {
.no-print { display: none !important; }
.card { border: 1px solid #dee2e6 !important; box-shadow: none !important; }
body { font-size: 11px; }
.table { font-size: 11px; }
}
.type-header { background: #f1f5f9; font-weight: 600; }
</style>
<!-- Header -->
<div class="d-flex align-items-center gap-2 mb-3 no-print">
<a asp-action="Index" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i></a>
<p class="text-muted mb-0">
As of @Model.AsOf.ToString("MMMM d, yyyy") ·
@if (Model.IsBalanced)
{
<span class="text-success fw-semibold"><i class="bi bi-check-circle me-1"></i>Balanced</span>
}
else
{
<span class="text-danger fw-semibold"><i class="bi bi-exclamation-triangle me-1"></i>Out of Balance by @((Model.TotalDebits - Model.TotalCredits).ToString("C"))</span>
}
</p>
<div class="ms-auto d-flex gap-2">
<a href="@Url.Action("TrialBalancePdf", new { asOf = Model.AsOf.ToString("yyyy-MM-dd") })"
class="btn btn-sm btn-outline-danger no-print" target="_blank">
<i class="bi bi-file-pdf me-1"></i>Download PDF
</a>
<a href="@Url.Action("TrialBalancePdf", new { asOf = Model.AsOf.ToString("yyyy-MM-dd"), inline = true })"
class="btn btn-sm btn-outline-secondary no-print" target="_blank">
<i class="bi bi-printer me-1"></i>Print
</a>
</div>
</div>
<!-- Date filter -->
<div class="card shadow-sm mb-4 no-print">
<div class="card-body py-3">
<form method="get" class="row g-2 align-items-end">
<div class="col-auto">
<label class="form-label form-label-sm mb-1">As of Date</label>
<input type="date" name="asOf" class="form-control form-control-sm" value="@Model.AsOf.ToString("yyyy-MM-dd")" />
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary btn-sm"><i class="bi bi-funnel me-1"></i>Run Report</button>
</div>
<div class="col-auto ms-2">
<div class="btn-group btn-group-sm">
<a href="@Url.Action("TrialBalance", new { asOf = today.ToString("yyyy-MM-dd") })" class="btn btn-outline-secondary">Today</a>
<a href="@Url.Action("TrialBalance", new { asOf = new DateTime(today.Year, today.Month, 1).AddDays(-1).ToString("yyyy-MM-dd") })" class="btn btn-outline-secondary">End of Last Month</a>
</div>
</div>
</form>
</div>
</div>
<!-- Print header -->
<div class="text-center mb-4 d-none d-print-block">
<h4 class="fw-bold">@Model.CompanyName</h4>
<h5>Trial Balance</h5>
<p class="text-muted">As of @Model.AsOf.ToString("MMMM d, yyyy")</p>
</div>
<!-- Summary cards -->
<div class="row g-3 mb-4">
<div class="col-md-4">
<div class="card shadow-sm text-center h-100">
<div class="card-body py-3">
<div class="h5 text-primary fw-bold mb-1">@Model.TotalDebits.ToString("C0")</div>
<div class="text-muted small">Total Debits</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm text-center h-100">
<div class="card-body py-3">
<div class="h5 text-primary fw-bold mb-1">@Model.TotalCredits.ToString("C0")</div>
<div class="text-muted small">Total Credits</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm text-center h-100 @(Model.IsBalanced ? "border-success border-opacity-50" : "border-danger border-opacity-50")">
<div class="card-body py-3">
@if (Model.IsBalanced)
{
<div class="h5 text-success fw-bold mb-1"><i class="bi bi-check-circle me-1"></i>Balanced</div>
<div class="text-muted small">Debits = Credits</div>
}
else
{
<div class="h5 text-danger fw-bold mb-1"><i class="bi bi-exclamation-triangle me-1"></i>Unbalanced</div>
<div class="text-muted small">Difference: @((Model.TotalDebits - Model.TotalCredits).ToString("C"))</div>
}
</div>
</div>
</div>
</div>
@if (!Model.Lines.Any())
{
<div class="card shadow-sm">
<div class="card-body text-center py-5 text-muted">
<i class="bi bi-journal-x fs-1 d-block mb-2"></i>
<p class="mb-0 fw-semibold">No active accounts with balances found.</p>
</div>
</div>
}
else
{
<div class="card shadow-sm">
<div class="card-header fw-semibold">
<i class="bi bi-list-columns-reverse me-1"></i>Account Balances
</div>
<div class="table-responsive">
<table class="table table-sm align-middle mb-0">
<thead class="table-light">
<tr>
<th style="width:90px">Acct #</th>
<th>Account Name</th>
<th class="text-end" style="width:140px">Debit</th>
<th class="text-end" style="width:140px">Credit</th>
</tr>
</thead>
<tbody>
@foreach (var grp in grouped)
{
<tr class="type-header">
<td colspan="4" class="py-2 text-uppercase small tracking-wide">@grp.Key</td>
</tr>
@foreach (var line in grp.OrderBy(l => l.AccountNumber))
{
<tr>
<td class="ps-4 text-muted small">@line.AccountNumber</td>
<td>@line.AccountName</td>
<td class="text-end @(line.DebitBalance > 0 ? "fw-medium" : "text-muted")">
@(line.DebitBalance > 0 ? line.DebitBalance.ToString("C") : "")
</td>
<td class="text-end @(line.CreditBalance > 0 ? "fw-medium" : "text-muted")">
@(line.CreditBalance > 0 ? line.CreditBalance.ToString("C") : "")
</td>
</tr>
}
<tr class="table-light">
<td colspan="2" class="text-end pe-3 small fw-semibold text-muted">@grp.Key subtotal</td>
<td class="text-end fw-semibold">@grp.Sum(l => l.DebitBalance).ToString("C")</td>
<td class="text-end fw-semibold">@grp.Sum(l => l.CreditBalance).ToString("C")</td>
</tr>
}
</tbody>
<tfoot class="table-dark fw-bold">
<tr>
<td colspan="2" class="text-end pe-3">Total</td>
<td class="text-end">@Model.TotalDebits.ToString("C")</td>
<td class="text-end">@Model.TotalCredits.ToString("C")</td>
</tr>
@if (!Model.IsBalanced)
{
<tr class="table-danger">
<td colspan="2" class="text-end pe-3 text-danger">Difference (out of balance)</td>
<td class="text-end text-danger" colspan="2">@((Model.TotalDebits - Model.TotalCredits).ToString("C"))</td>
</tr>
}
</tfoot>
</table>
</div>
</div>
}
<div class="text-muted small mt-2 no-print">
<i class="bi bi-info-circle me-1"></i>
Generated @DateTime.Now.ToString("MMM d, yyyy h:mm tt") · Uses current account balances (live, not point-in-time). Accounts with zero balance are excluded.
</div>