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:
@@ -1134,6 +1134,10 @@
|
||||
<i class="bi bi-journal-text"></i>
|
||||
<span>Journal Entries</span>
|
||||
</a>
|
||||
<a asp-controller="VendorCredits" asp-action="Index" class="nav-link">
|
||||
<i class="bi bi-arrow-return-left"></i>
|
||||
<span>Vendor Credits</span>
|
||||
</a>
|
||||
if (hasReports)
|
||||
{
|
||||
<a asp-controller="AccountingExport" asp-action="Index" class="nav-link">
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
@model PowderCoating.Core.Entities.VendorCredit
|
||||
@{
|
||||
ViewData["Title"] = "New Vendor Credit";
|
||||
var apAccounts = ViewBag.APAccountList as List<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> ?? new();
|
||||
var expAccounts = ViewBag.ExpenseAccountList as List<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> ?? new();
|
||||
var vendors = ViewBag.VendorList as List<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> ?? new();
|
||||
}
|
||||
|
||||
<div class="d-flex align-items-center mb-3 gap-2">
|
||||
<a asp-action="Index" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left me-1"></i>Back
|
||||
</a>
|
||||
<h4 class="mb-0 fw-semibold ms-2">New Vendor Credit</h4>
|
||||
</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>
|
||||
}
|
||||
|
||||
<form asp-action="Create" method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-header fw-semibold">Credit Details</div>
|
||||
<div class="card-body">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label fw-semibold">Vendor <span class="text-danger">*</span></label>
|
||||
<select asp-for="VendorId" asp-items="vendors" class="form-select" required>
|
||||
<option value="">— select vendor —</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-semibold">Credit Date <span class="text-danger">*</span></label>
|
||||
<input asp-for="CreditDate" type="date" class="form-control"
|
||||
value="@Model.CreditDate.ToString("yyyy-MM-dd")" required />
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<label class="form-label fw-semibold">AP Account <span class="text-danger">*</span></label>
|
||||
<select asp-for="APAccountId" asp-items="apAccounts" class="form-select" required>
|
||||
<option value="">— select account —</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">Memo</label>
|
||||
<input asp-for="Memo" class="form-control" placeholder="Reason for the credit" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-header fw-semibold">Line Items</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0" id="linesTable">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width:40%">Expense / COGS Account</th>
|
||||
<th>Description</th>
|
||||
<th class="text-end" style="width:130px">Amount</th>
|
||||
<th style="width:40px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="linesBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer d-flex justify-content-between align-items-center">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="addLineBtn">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Line
|
||||
</button>
|
||||
<span class="fw-semibold">
|
||||
Total: <span id="lineTotal">$0.00</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">Create Vendor Credit</button>
|
||||
<a asp-action="Index" class="btn btn-outline-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
(function() {
|
||||
const expenseAccounts = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(
|
||||
expAccounts.Select(a => new { value = a.Value, text = a.Text })));
|
||||
let idx = 0;
|
||||
|
||||
function addLine() {
|
||||
const tbody = document.getElementById('linesBody');
|
||||
const i = idx++;
|
||||
const tr = document.createElement('tr');
|
||||
tr.innerHTML = `
|
||||
<td>
|
||||
<select name="lineAccountIds" class="form-select form-select-sm">
|
||||
<option value="">— optional —</option>
|
||||
${expenseAccounts.map(a => `<option value="${a.value}">${escHtml(a.text)}</option>`).join('')}
|
||||
</select>
|
||||
</td>
|
||||
<td><input name="lineDescriptions" type="text" class="form-control form-control-sm" placeholder="what was credited" /></td>
|
||||
<td>
|
||||
<input name="lineAmounts" type="number" step="0.01" min="0.01" class="form-control form-control-sm text-end line-amount" placeholder="0.00" required />
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-link text-danger p-0" onclick="this.closest('tr').remove(); updateTotal();">
|
||||
<i class="bi bi-x-lg"></i>
|
||||
</button>
|
||||
</td>`;
|
||||
tr.querySelector('.line-amount').addEventListener('input', updateTotal);
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
|
||||
function updateTotal() {
|
||||
let total = 0;
|
||||
document.querySelectorAll('.line-amount').forEach(el => total += parseFloat(el.value) || 0);
|
||||
document.getElementById('lineTotal').textContent = total.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
||||
}
|
||||
|
||||
function escHtml(s) {
|
||||
return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
|
||||
}
|
||||
|
||||
document.getElementById('addLineBtn').addEventListener('click', addLine);
|
||||
addLine();
|
||||
})();
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
@model PowderCoating.Core.Entities.VendorCredit
|
||||
@using PowderCoating.Core.Enums
|
||||
@{
|
||||
ViewData["Title"] = $"Vendor Credit {Model.CreditNumber}";
|
||||
var accountMap = ViewBag.AccountMap as Dictionary<int, string> ?? new();
|
||||
var billMap = ViewBag.BillMap as Dictionary<int, string> ?? new();
|
||||
var openBills = ViewBag.OpenBills as List<PowderCoating.Core.Entities.Bill> ?? new();
|
||||
bool canApply = Model.Status is VendorCreditStatus.Open or VendorCreditStatus.PartiallyApplied;
|
||||
}
|
||||
|
||||
<div class="d-flex align-items-center mb-3 gap-2 flex-wrap">
|
||||
<a asp-action="Index" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left me-1"></i>Back
|
||||
</a>
|
||||
<h4 class="mb-0 fw-semibold ms-2">@Model.CreditNumber</h4>
|
||||
@{
|
||||
var (badgeClass, label) = Model.Status switch
|
||||
{
|
||||
VendorCreditStatus.Open => ("bg-success", "Open"),
|
||||
VendorCreditStatus.PartiallyApplied => ("bg-warning text-dark", "Partially Applied"),
|
||||
VendorCreditStatus.Applied => ("bg-secondary", "Applied"),
|
||||
VendorCreditStatus.Voided => ("bg-danger", "Voided"),
|
||||
_ => ("bg-secondary", Model.Status.ToString())
|
||||
};
|
||||
}
|
||||
<span class="badge @badgeClass ms-1 fs-6">@label</span>
|
||||
|
||||
<div class="ms-auto d-flex gap-2">
|
||||
@if (Model.Status == VendorCreditStatus.Open)
|
||||
{
|
||||
<form asp-action="Post" asp-route-id="@Model.Id" method="post" class="d-inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<button type="submit" class="btn btn-sm btn-success"
|
||||
onclick="return confirm('Post this credit to the GL? Accounts Payable will be debited and expense accounts credited.')">
|
||||
<i class="bi bi-check-circle me-1"></i>Post to GL
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
@if (Model.Status != VendorCreditStatus.Voided && Model.Status != VendorCreditStatus.Applied)
|
||||
{
|
||||
<form asp-action="Void" asp-route-id="@Model.Id" method="post" class="d-inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger"
|
||||
onclick="return confirm('Void this vendor credit?')">
|
||||
<i class="bi bi-x-circle me-1"></i>Void
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
</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-8">
|
||||
<div class="card shadow-sm h-100">
|
||||
<div class="card-body">
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-4 text-muted">Credit Number</dt>
|
||||
<dd class="col-8 fw-semibold">@Model.CreditNumber</dd>
|
||||
|
||||
<dt class="col-4 text-muted">Vendor</dt>
|
||||
<dd class="col-8">@Model.Vendor?.CompanyName</dd>
|
||||
|
||||
<dt class="col-4 text-muted">Date</dt>
|
||||
<dd class="col-8">@Model.CreditDate.ToString("MMMM d, yyyy")</dd>
|
||||
|
||||
<dt class="col-4 text-muted">AP Account</dt>
|
||||
<dd class="col-8">@Model.APAccount?.AccountNumber – @Model.APAccount?.Name</dd>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(Model.Memo))
|
||||
{
|
||||
<dt class="col-4 text-muted">Memo</dt>
|
||||
<dd class="col-8">@Model.Memo</dd>
|
||||
}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card shadow-sm h-100">
|
||||
<div class="card-body text-center py-4">
|
||||
<div class="fs-5 fw-bold">@Model.Total.ToString("C")</div>
|
||||
<div class="text-muted small mb-3">Total Credit</div>
|
||||
@if (Model.RemainingAmount > 0)
|
||||
{
|
||||
<div class="fs-4 fw-bold text-success">@Model.RemainingAmount.ToString("C")</div>
|
||||
<div class="text-muted small">Remaining</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="text-muted">Fully Applied</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-header fw-semibold">Line Items</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Account</th>
|
||||
<th>Description</th>
|
||||
<th class="text-end">Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var line in Model.LineItems)
|
||||
{
|
||||
<tr>
|
||||
<td class="small">
|
||||
@if (line.AccountId.HasValue && accountMap.TryGetValue(line.AccountId.Value, out var acct))
|
||||
{ @acct }
|
||||
else
|
||||
{ <span class="text-muted">—</span> }
|
||||
</td>
|
||||
<td class="text-muted small">@line.Description</td>
|
||||
<td class="text-end">@line.Amount.ToString("C")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<tfoot class="table-light fw-semibold">
|
||||
<tr>
|
||||
<td colspan="2" class="text-end">Total</td>
|
||||
<td class="text-end">@Model.Total.ToString("C")</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.Applications.Any())
|
||||
{
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-header fw-semibold">Applied To</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Bill</th>
|
||||
<th>Applied Date</th>
|
||||
<th class="text-end">Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var app in Model.Applications.OrderByDescending(a => a.AppliedDate))
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@if (billMap.TryGetValue(app.BillId, out var billNum))
|
||||
{
|
||||
<a asp-controller="Bills" asp-action="Details" asp-route-id="@app.BillId">@billNum</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-muted">#@app.BillId</span>
|
||||
}
|
||||
</td>
|
||||
<td>@app.AppliedDate.ToLocalTime().ToString("MMM d, yyyy")</td>
|
||||
<td class="text-end">@app.Amount.ToString("C")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (canApply && openBills.Any())
|
||||
{
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-semibold">Apply to a Bill</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Bill</th>
|
||||
<th>Due Date</th>
|
||||
<th class="text-end">Balance Due</th>
|
||||
<th class="text-end">Apply Amount</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var bill in openBills)
|
||||
{
|
||||
var maxApply = Math.Min(Model.RemainingAmount, bill.BalanceDue);
|
||||
<tr>
|
||||
<td>
|
||||
<a asp-controller="Bills" asp-action="Details" asp-route-id="@bill.Id">@bill.BillNumber</a>
|
||||
</td>
|
||||
<td class="text-muted small">@(bill.DueDate?.ToString("MMM d, yyyy") ?? "—")</td>
|
||||
<td class="text-end">@bill.BalanceDue.ToString("C")</td>
|
||||
<td class="text-end" style="width:150px">
|
||||
<form asp-action="Apply" method="post" class="d-inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@Model.Id" />
|
||||
<input type="hidden" name="billId" value="@bill.Id" />
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-text">$</span>
|
||||
<input name="amount" type="number" step="0.01" min="0.01"
|
||||
max="@maxApply"
|
||||
value="@maxApply.ToString("F2")"
|
||||
class="form-control text-end" />
|
||||
<button type="submit" class="btn btn-sm btn-success">Apply</button>
|
||||
</div>
|
||||
</form>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else if (canApply)
|
||||
{
|
||||
<div class="alert alert-info alert-permanent">
|
||||
No open bills found for this vendor to apply the credit against.
|
||||
</div>
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user