Phase F: Customer/Vendor Statements, Payment Terms Parser, Tax Rates

F1: GetCustomerStatementAsync/GetVendorStatementAsync on IFinancialReportService;
    StatementLineDto; CustomerStatementDto/VendorStatementDto; Statement action on
    CustomersController + VendorsController; Statement views + PDF download via
    StatementPdfHelper (QuestPDF); Statement button on Customer/Vendor Details pages.

F2: PaymentTermsParser static helper (CalculateDueDate, ParseEarlyPaymentDiscount);
    EarlyPaymentDiscountPercent/Days on Invoice entity; GetCustomerPaymentTerms AJAX
    endpoint on InvoicesController auto-populates Terms + due date on customer select;
    early payment discount notice on Invoice Create.

F3: TaxRate entity (Name/Rate/State/IsDefault/IsActive, tenant-filtered);
    IUnitOfWork.TaxRates + UnitOfWork + ApplicationDbContext; TaxRatesController
    (Index/Create/Edit/Delete/ToggleActive, CompanyAdminOnly); GetTaxRateForCustomer
    AJAX endpoint; Tax Rates in Settings gear menu.

Also fixes AddVendorCredits migration: VendorCreditApplications FKs changed from
CASCADE to NoAction to resolve SQL Server error 1785 (multiple cascade paths).
Migration: AddPaymentTermsAndTaxRates applied locally; 200/200 unit tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-10 10:55:22 -04:00
parent 1229081436
commit d3a5d827f9
27 changed files with 11492 additions and 12 deletions
@@ -0,0 +1,49 @@
using System.Text.RegularExpressions;
namespace PowderCoating.Web.Helpers;
/// <summary>
/// Parses payment terms strings (e.g., "Net 30", "2/10 Net 30", "Due on Receipt")
/// to compute due dates and extract early-payment discount terms.
/// </summary>
public static class PaymentTermsParser
{
private static readonly Regex NetDaysRegex = new(@"\bnet\s+(\d+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex EarlyDiscountRegex = new(@"(\d+(?:\.\d+)?)/(\d+)\s+net", RegexOptions.IgnoreCase | RegexOptions.Compiled);
/// <summary>
/// Returns the due date calculated from <paramref name="invoiceDate"/> and the supplied terms.
/// Returns null when the terms string cannot be parsed.
/// </summary>
public static DateTime? CalculateDueDate(string? terms, DateTime invoiceDate)
{
if (string.IsNullOrWhiteSpace(terms)) return null;
var normalized = terms.Trim().ToLowerInvariant();
if (Regex.IsMatch(normalized, @"\b(receipt|due\s*now|cod|immediate)\b"))
return invoiceDate;
var match = NetDaysRegex.Match(terms);
if (match.Success && int.TryParse(match.Groups[1].Value, out var days))
return invoiceDate.AddDays(days);
return null;
}
/// <summary>
/// Extracts early-payment discount terms from a string like "2/10 Net 30".
/// Returns (percent: 2, days: 10) for that example, or (0, 0) if not present.
/// </summary>
public static (decimal Percent, int Days) ParseEarlyPaymentDiscount(string? terms)
{
if (string.IsNullOrWhiteSpace(terms)) return (0, 0);
var match = EarlyDiscountRegex.Match(terms);
if (match.Success
&& decimal.TryParse(match.Groups[1].Value, out var percent)
&& int.TryParse(match.Groups[2].Value, out var days))
return (percent, days);
return (0, 0);
}
}