Phase D: Add Vendor Credits (AP cycle completion)

- VendorCredit, VendorCreditLineItem, VendorCreditApplication entities
- VendorCreditStatus enum (Open, PartiallyApplied, Applied, Voided)
- Migration AddVendorCredits: three new tables
- IUnitOfWork/UnitOfWork wired with all three repositories
- VendorCreditsController: Index (status tabs), Create, Details, Post, Apply, Void
- Post action: DR AP, CR each expense line (reverses original expense)
- Apply action: links credit to bill, updates Bill.AmountPaid and bill status
- Views: Index (summary cards + table), Create (dynamic line grid), Details (apply panel)
- Nav: Vendor Credits added to Finance section in _Layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 00:03:14 -04:00
parent a33687f7bd
commit cf9dcfb4c1
13 changed files with 11387 additions and 3 deletions
@@ -0,0 +1,138 @@
@model IEnumerable<PowderCoating.Core.Entities.VendorCredit>
@using PowderCoating.Core.Enums
@{
ViewData["Title"] = "Vendor Credits";
var statusFilter = ViewBag.StatusFilter as string ?? "All";
}
<div class="d-flex align-items-center mb-3 gap-2">
<h4 class="mb-0 fw-semibold">Vendor Credits</h4>
<a asp-action="Create" class="btn btn-sm btn-primary ms-auto">
<i class="bi bi-plus-lg me-1"></i>New Credit
</a>
</div>
@if (TempData["Success"] != null)
{
<div class="alert alert-success alert-permanent alert-dismissible fade show">
@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">
@TempData["Error"]
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
}
<div class="row g-3 mb-3">
<div class="col-md-4">
<div class="card shadow-sm text-center py-3">
<div class="fs-4 fw-bold text-success">@((ViewBag.TotalUnapplied as decimal? ?? 0).ToString("C"))</div>
<div class="small text-muted">Total Unapplied Credit</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm text-center py-3">
<div class="fs-4 fw-bold">@ViewBag.OpenCount</div>
<div class="small text-muted">Open Credits</div>
</div>
</div>
<div class="col-md-4">
<div class="card shadow-sm text-center py-3">
<div class="fs-4 fw-bold">@ViewBag.PartialCount</div>
<div class="small text-muted">Partially Applied</div>
</div>
</div>
</div>
<ul class="nav nav-tabs mb-3">
<li class="nav-item">
<a class="nav-link @(statusFilter == "All" ? "active" : "")" asp-action="Index">
All <span class="badge bg-secondary ms-1">@ViewBag.TotalCount</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link @(statusFilter == "Open" ? "active" : "")" asp-action="Index" asp-route-status="Open">
Open <span class="badge bg-success ms-1">@ViewBag.OpenCount</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link @(statusFilter == "Partial" ? "active" : "")" asp-action="Index" asp-route-status="Partial">
Partially Applied <span class="badge bg-warning text-dark ms-1">@ViewBag.PartialCount</span>
</a>
</li>
</ul>
<div class="card shadow-sm">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th>Credit #</th>
<th>Date</th>
<th>Vendor</th>
<th>Memo</th>
<th class="text-end">Total</th>
<th class="text-end">Remaining</th>
<th>Status</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
@if (!Model.Any())
{
<tr>
<td colspan="8" class="text-center text-muted py-4">No vendor credits found.</td>
</tr>
}
@foreach (var vc in Model)
{
<tr>
<td>
<a asp-action="Details" asp-route-id="@vc.Id" class="fw-semibold text-decoration-none">
@vc.CreditNumber
</a>
</td>
<td>@vc.CreditDate.ToString("MMM d, yyyy")</td>
<td>@vc.Vendor?.CompanyName</td>
<td class="text-muted small text-truncate" style="max-width:180px">@vc.Memo</td>
<td class="text-end">@vc.Total.ToString("C")</td>
<td class="text-end">
@if (vc.RemainingAmount > 0)
{
<span class="text-success fw-semibold">@vc.RemainingAmount.ToString("C")</span>
}
else
{
<span class="text-muted">—</span>
}
</td>
<td>
@{
var (badgeClass, label) = vc.Status switch
{
VendorCreditStatus.Open => ("bg-success", "Open"),
VendorCreditStatus.PartiallyApplied => ("bg-warning text-dark", "Partial"),
VendorCreditStatus.Applied => ("bg-secondary", "Applied"),
VendorCreditStatus.Voided => ("bg-danger", "Voided"),
_ => ("bg-secondary", vc.Status.ToString())
};
}
<span class="badge @badgeClass">@label</span>
</td>
<td class="text-end">
<a asp-action="Details" asp-route-id="@vc.Id" class="btn btn-sm btn-outline-secondary">
View
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>