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,124 @@
@using PowderCoating.Core.Entities
@{
ViewData["Title"] = "Year-End Close";
ViewData["PageIcon"] = "bi-calendar-check";
var history = ViewBag.History as List<YearEndClose> ?? new();
var suggested = (int)ViewBag.SuggestedYear;
var closedYears = ViewBag.ClosedYears as HashSet<int> ?? new();
}
<div class="row justify-content-center">
<div class="col-lg-8">
@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>
}
<div class="card border-0 shadow-sm mb-4">
<div class="card-header bg-white border-0 py-3">
<h5 class="mb-0 fw-semibold"><i class="bi bi-calendar-check me-2 text-primary"></i>Close a Fiscal Year</h5>
</div>
<div class="card-body">
<div class="alert alert-warning py-2 mb-4">
<i class="bi bi-exclamation-triangle me-2"></i>
<strong>What this does:</strong> Posts a Journal Entry dated December 31 that zeroes all Revenue
and Expense account balances into Retained Earnings — the standard accounting close.
Run this <strong>after</strong> all entries for the year are posted and the period is locked.
A year can only be closed once.
</div>
<form asp-action="CloseYear" method="post"
onsubmit="return confirm('Close fiscal year ' + document.getElementById('closeYear').value + '? This will post a Journal Entry zeroing all Revenue and Expense balances into Retained Earnings. This cannot be undone.')">
@Html.AntiForgeryToken()
<div class="row g-3 align-items-end">
<div class="col-md-4">
<label class="form-label">Fiscal Year to Close <span class="text-danger">*</span></label>
<input type="number" name="year" id="closeYear" class="form-control"
value="@suggested" min="2000" max="@DateTime.Now.Year" required />
<div class="form-text">All entries for this year should be finalized before closing.</div>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-warning">
<i class="bi bi-calendar-check me-2"></i>Close Year
</button>
</div>
</div>
</form>
<div class="mt-3">
<h6 class="text-muted">Pre-close checklist:</h6>
<ul class="list-unstyled small">
<li><i class="bi bi-check2-square me-2 text-success"></i>All invoices for the year are sent and collected (or written off)</li>
<li><i class="bi bi-check2-square me-2 text-success"></i>All vendor bills are entered and paid</li>
<li><i class="bi bi-check2-square me-2 text-success"></i>Bank reconciliation is complete through December</li>
<li><i class="bi bi-check2-square me-2 text-success"></i>Depreciation is posted for all 12 months</li>
<li><i class="bi bi-check2-square me-2 text-success"></i>Trial Balance is in balance (debits = credits)</li>
<li><i class="bi bi-check2-square me-2 text-success"></i>Period is locked through December 31 in Company Settings</li>
</ul>
</div>
</div>
</div>
<!-- Close History -->
<div class="card border-0 shadow-sm">
<div class="card-header bg-white border-0 py-3">
<h5 class="mb-0 fw-semibold"><i class="bi bi-clock-history me-2 text-primary"></i>Close History</h5>
</div>
<div class="card-body p-0">
@if (!history.Any())
{
<div class="text-center text-muted py-4">
<p>No years have been closed yet.</p>
</div>
}
else
{
<table class="table table-hover align-middle mb-0">
<thead class="table-light">
<tr>
<th>Fiscal Year</th>
<th>Closed On</th>
<th>Closed By</th>
<th>Journal Entry</th>
</tr>
</thead>
<tbody>
@foreach (var c in history)
{
<tr>
<td class="fw-bold">@c.ClosedYear</td>
<td>@c.ClosedAt.ToLocalTime().ToString("MM/dd/yyyy h:mm tt")</td>
<td>@(c.ClosedBy ?? "—")</td>
<td>
@if (c.JournalEntry != null)
{
<a asp-controller="JournalEntries" asp-action="Details" asp-route-id="@c.JournalEntryId">
@c.JournalEntry.EntryNumber
</a>
}
else
{
<span class="text-muted">#@c.JournalEntryId</span>
}
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
</div>
</div>