Add Credit Memos standalone management module

CreditMemosController with Index, Details, Create, Apply, and Void actions.
All business logic (atomic apply transaction, RemainingBalance cap,
customer.CreditBalance adjustment, auto-Paid invoice when BalanceDue hits zero)
mirrors the invoice-centric IssueCreditMemo/ApplyCredit/VoidCreditMemo actions in
InvoicesController but redirects back to the credit memo rather than an invoice.

Views: Index (stats bar, status+search filter, table), Details (two-col layout
with application history table and Bootstrap Apply/Void confirm modals),
Create (customer dropdown, amount, reason, notes, optional expiry).

Apply modal populates amount automatically from min(remaining credit,
invoice balance due) via credit-memo.js data-attribute wiring (no inline scripts).

Nav: Credit Memos added to Billing & Payments section in _Layout.

Build: 0 errors. Unit tests: 200/200.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 11:48:35 -04:00
parent d94612cc9c
commit a255893ada
6 changed files with 954 additions and 0 deletions
@@ -0,0 +1,92 @@
@model PowderCoating.Web.Controllers.CreditMemoCreateVm
@{
ViewData["Title"] = "Issue Credit Memo";
var linkedInvoiceNumber = ViewBag.LinkedInvoiceNumber as string;
var customers = ViewBag.Customers as List<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> ?? new();
}
<div class="d-flex justify-content-between align-items-center mb-3">
<h4 class="mb-0"><i class="bi bi-journal-minus me-2 text-primary"></i>Issue Credit Memo</h4>
<a asp-action="Index" class="btn btn-outline-secondary btn-sm">
<i class="bi bi-arrow-left me-1"></i>Back to Credit Memos
</a>
</div>
<div class="row justify-content-center">
<div class="col-lg-7">
<div class="card">
<div class="card-header fw-semibold">Credit Memo Details</div>
<div class="card-body">
<form asp-action="Create" method="post">
@Html.AntiForgeryToken()
<asp-validation-summary asp-validation-summary="All" class="alert alert-danger alert-permanent"></asp-validation-summary>
@if (Model.OriginalInvoiceId.HasValue && !string.IsNullOrEmpty(linkedInvoiceNumber))
{
<input type="hidden" asp-for="OriginalInvoiceId" />
<div class="alert alert-info alert-permanent py-2 mb-3 small">
<i class="bi bi-link-45deg me-1"></i>
Linked to invoice <strong>@linkedInvoiceNumber</strong>
</div>
}
<div class="mb-3">
<label asp-for="CustomerId" class="form-label">Customer <span class="text-danger">*</span></label>
<select asp-for="CustomerId" asp-items="customers" class="form-select">
<option value="0">— select customer —</option>
</select>
<span asp-validation-for="CustomerId" class="text-danger small"></span>
</div>
<div class="mb-3">
<label asp-for="Amount" class="form-label">Credit Amount <span class="text-danger">*</span></label>
<div class="input-group">
<span class="input-group-text">$</span>
<input asp-for="Amount" type="number" step="0.01" min="0.01"
class="form-control" placeholder="0.00" />
</div>
<span asp-validation-for="Amount" class="text-danger small"></span>
</div>
<div class="mb-3">
<label asp-for="Reason" class="form-label">Reason <span class="text-danger">*</span></label>
<input asp-for="Reason" class="form-control"
placeholder="e.g. Price adjustment, billing error, goodwill credit…" />
<span asp-validation-for="Reason" class="text-danger small"></span>
</div>
<div class="mb-3">
<label asp-for="Notes" class="form-label">Internal Notes</label>
<textarea asp-for="Notes" class="form-control" rows="3"
placeholder="Additional context for your records (not shown to customer)"></textarea>
<span asp-validation-for="Notes" class="text-danger small"></span>
</div>
<div class="mb-4">
<label asp-for="ExpiryDate" class="form-label">
Expiry Date
<span class="text-muted small ms-1">(optional — leave blank for no expiry)</span>
</label>
<input asp-for="ExpiryDate" type="date" class="form-control" />
<span asp-validation-for="ExpiryDate" class="text-danger small"></span>
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary">
<i class="bi bi-check-lg me-1"></i>Issue Credit Memo
</button>
<a asp-action="Index" class="btn btn-outline-secondary">Cancel</a>
</div>
</form>
</div>
</div>
<div class="card mt-3 border-0 bg-light">
<div class="card-body py-2 small text-muted">
<i class="bi bi-info-circle me-1"></i>
Issuing a credit memo immediately adds the amount to the customer's credit balance.
You can apply it to one or more open invoices from the Credit Memo Details page.
</div>
</div>
</div>
</div>