@model PowderCoating.Core.Entities.CreditMemo @using PowderCoating.Core.Entities @using PowderCoating.Core.Enums @{ ViewData["Title"] = $"Credit Memo {Model.MemoNumber}"; var applications = ViewBag.Applications as List ?? new(); var openInvoices = ViewBag.OpenInvoices as List ?? new(); bool canApply = ViewBag.CanApply; var (badgeClass, badgeLabel) = Model.Status switch { CreditMemoStatus.Active => ("bg-success-subtle text-success border border-success-subtle", "Active"), CreditMemoStatus.PartiallyApplied => ("bg-warning-subtle text-warning border border-warning-subtle", "Partially Applied"), CreditMemoStatus.FullyApplied => ("bg-secondary-subtle text-secondary border border-secondary-subtle", "Fully Applied"), CreditMemoStatus.Voided => ("bg-danger-subtle text-danger border border-danger-subtle", "Voided"), _ => ("bg-secondary-subtle text-secondary", Model.Status.ToString()) }; } @if (TempData["Success"] != null) {
@TempData["Success"]
} @if (TempData["Error"] != null) {
@TempData["Error"]
} @* ── Header ────────────────────────────────────────────────────── *@

@Model.MemoNumber @badgeLabel

@if (canApply && openInvoices.Any()) { } @if (Model.Status != CreditMemoStatus.Voided) { } Back
@* ── Left: memo details ──────────────────────────────────────── *@
Credit Memo Details
@* Balance summary *@
Total Credit
@Model.Amount.ToString("C")
Applied
@Model.AmountApplied.ToString("C")
Remaining
@Model.RemainingBalance.ToString("C")
Issue Date
@Model.IssueDate.ToLocalTime().ToString("MMMM d, yyyy")
Expiry Date
@if (Model.ExpiryDate.HasValue) { var expired = Model.ExpiryDate.Value < DateTime.UtcNow; @Model.ExpiryDate.Value.ToLocalTime().ToString("MMMM d, yyyy") @if (expired) { (Expired) } } else { No expiry }
@if (Model.OriginalInvoice != null) {
Original Invoice
@Model.OriginalInvoice.InvoiceNumber
}
Issued By
@(Model.IssuedBy?.FullName ?? "System")
Reason
@Model.Reason
@if (!string.IsNullOrWhiteSpace(Model.Notes)) {
Notes
@Model.Notes
}
@* ── Right: application history ──────────────────────────────── *@
Application History @applications.Count applied
@if (!applications.Any()) {
This credit memo has not been applied to any invoice yet. @if (canApply && openInvoices.Any()) { Use Apply to Invoice above to apply it. } else if (canApply && !openInvoices.Any()) { No open invoices with a balance due for this customer. }
} else {
@foreach (var a in applications) { }
Invoice Date Applied Amount Applied By
@(a.Invoice?.InvoiceNumber ?? $"#{a.InvoiceId}") @a.AppliedDate.ToLocalTime().ToString("MM/dd/yyyy") @a.AmountApplied.ToString("C") @(a.AppliedBy?.FullName ?? "—")
}
@* ── Apply Modal ─────────────────────────────────────────────── *@ @if (canApply) { } @* ── Void Confirm Modal ──────────────────────────────────────── *@ @if (Model.Status != CreditMemoStatus.Voided) { } @section Scripts { }