Phase G: Add Budgeting and Year-End Close

Budgeting:
- Budget + BudgetLine entities with Jan–Dec monthly columns per GL account
- BudgetsController: Index, Create, Edit, SetDefault, Copy, Delete
- Copy action rolls a budget forward to a new fiscal year
- Budget vs. Actual report (BudgetVsActual): compares monthly budget amounts to
  real P&L by calling GetProfitAndLossAsync once per month; variance shown as
  favorable/unfavorable; year + budget selectors in header
- Views: Budgets/Index, Create, Edit with inline annual totals via budget-edit.js
- Nav link + report card on Landing

Year-End Close:
- YearEndClose entity records each closed year + JE reference for audit trail
- AccountsController.YearEndClose GET (history + form) + CloseYear POST
- Close zeroes all Revenue and Expense/COGS account balances into Retained Earnings
  via IAccountBalanceService and posts a supporting JE dated Dec 31
- Idempotency: rejects attempt to close an already-closed year
- Pre-close checklist in view to guide the workflow
- Nav link under Finance

Migration AddBudgetsAndYearEndClose applied

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 13:01:56 -04:00
parent fde24b09c9
commit 4fd9c52aaf
19 changed files with 12527 additions and 3 deletions
@@ -0,0 +1,152 @@
@using PowderCoating.Core.Entities
@model List<Budget>
@{
ViewData["Title"] = "Budgets";
ViewData["PageIcon"] = "bi-pie-chart";
var byYear = Model.GroupBy(b => b.FiscalYear).OrderByDescending(g => g.Key).ToList();
}
<div class="d-flex justify-content-between align-items-center mb-4">
<div></div>
<div class="d-flex gap-2">
<a asp-controller="Reports" asp-action="BudgetVsActual" class="btn btn-outline-primary">
<i class="bi bi-bar-chart-line me-2"></i>Budget vs. Actual Report
</a>
<a asp-action="Create" class="btn btn-primary">
<i class="bi bi-plus-circle me-2"></i>New Budget
</a>
</div>
</div>
@if (TempData["Success"] != null)
{
<div class="alert alert-success alert-permanent alert-dismissible fade show" role="alert">
<i class="bi bi-check-circle me-2"></i>@TempData["Success"]
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
}
@if (TempData["Error"] != null)
{
<div class="alert alert-danger alert-permanent alert-dismissible fade show" role="alert">
<i class="bi bi-exclamation-triangle me-2"></i>@TempData["Error"]
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
}
@if (!Model.Any())
{
<div class="card border-0 shadow-sm">
<div class="card-body text-center text-muted py-5">
<i class="bi bi-pie-chart display-4 d-block mb-3 opacity-25"></i>
<p class="mb-0">No budgets yet. <a asp-action="Create">Create your first budget</a> to start tracking variance against actual results.</p>
</div>
</div>
}
else
{
@foreach (var group in byYear)
{
<div class="card border-0 shadow-sm mb-4">
<div class="card-header bg-white border-0 py-3 d-flex justify-content-between align-items-center">
<h5 class="mb-0 fw-semibold"><i class="bi bi-calendar3 me-2 text-primary"></i>Fiscal Year @group.Key</h5>
</div>
<div class="card-body p-0">
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th>Budget Name</th>
<th class="text-center">Lines</th>
<th class="text-end">Total Revenue Budget</th>
<th class="text-end">Total Expense Budget</th>
<th class="text-center">Default</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var b in group.OrderBy(b => b.Name))
{
var revLines = b.Lines.Where(l => l.Account?.AccountType == PowderCoating.Core.Enums.AccountType.Revenue);
var expLines = b.Lines.Where(l => l.Account?.AccountType == PowderCoating.Core.Enums.AccountType.Expense);
<tr>
<td class="fw-semibold">
@b.Name
@if (!string.IsNullOrWhiteSpace(b.Notes))
{
<div class="text-muted small">@b.Notes</div>
}
</td>
<td class="text-center">@b.Lines.Count</td>
<td class="text-end text-success">@b.Lines.Sum(l => l.Annual).ToString("C")</td>
<td class="text-end text-danger">—</td>
<td class="text-center">
@if (b.IsDefault)
{
<span class="badge bg-primary">Default</span>
}
else
{
<form asp-action="SetDefault" asp-route-id="@b.Id" method="post" class="d-inline">
@Html.AntiForgeryToken()
<button type="submit" class="btn btn-sm btn-outline-secondary">Set Default</button>
</form>
}
</td>
<td class="text-end">
<div class="d-flex gap-1 justify-content-end">
<a asp-action="Edit" asp-route-id="@b.Id" class="btn btn-sm btn-outline-primary">
<i class="bi bi-pencil"></i>
</a>
<button type="button" class="btn btn-sm btn-outline-secondary"
data-bs-toggle="modal" data-bs-target="#copyModal"
data-budget-id="@b.Id" data-budget-name="@b.Name">
<i class="bi bi-copy"></i>
</button>
<form asp-action="Delete" asp-route-id="@b.Id" method="post" class="d-inline"
onsubmit="return confirm('Delete budget &quot;@b.Name&quot;? This cannot be undone.')">
@Html.AntiForgeryToken()
<button type="submit" class="btn btn-sm btn-outline-danger">
<i class="bi bi-trash"></i>
</button>
</form>
</div>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
}
<!-- Copy Modal -->
<div class="modal fade" id="copyModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="bi bi-copy me-2"></i>Copy Budget</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form asp-action="Copy" method="post">
@Html.AntiForgeryToken()
<input type="hidden" name="id" id="copyBudgetId" />
<div class="modal-body">
<p>Copy <strong id="copyBudgetName"></strong> to a new fiscal year as a starting point.</p>
<div class="mb-3">
<label class="form-label">New Fiscal Year</label>
<input type="number" name="newYear" class="form-control" value="@(DateTime.Now.Year + 1)" min="2000" max="2099" required />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary"><i class="bi bi-copy me-2"></i>Copy Budget</button>
</div>
</form>
</div>
</div>
</div>
@section Scripts {
<script src="~/js/budget-index.js" asp-append-version="true"></script>
}