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
@@ -180,6 +180,7 @@
</a>
</div>
<select asp-for="Terms" asp-items="ViewBag.PaymentTermsOptions" class="form-select"></select>
<div id="earlyPaymentDiscountNotice" class="form-text text-success d-none"></div>
</div>
</div>
</div>
@@ -456,11 +457,52 @@
function onCustomerChanged(select) {
document.getElementById('hiddenCustomerId').value = select.value;
const customerId = parseInt(select.value) || 0;
const taxField = document.getElementById('TaxPercent');
if (taxField) {
taxField.value = taxExemptCustomerIds.has(customerId) ? 0 : companyTaxPercent;
recalcTotals();
}
if (!customerId) return;
// Fetch payment terms + tax rate for the selected customer
fetch(`/Invoices/GetCustomerPaymentTerms?customerId=${customerId}`)
.then(r => r.ok ? r.json() : null)
.then(data => {
if (!data) return;
// Auto-fill Terms dropdown
const termsSelect = document.getElementById('Terms');
if (termsSelect && data.paymentTerms) {
// Set the matching option, or fall back to the raw value
const opt = Array.from(termsSelect.options).find(o => o.value === data.paymentTerms);
if (opt) termsSelect.value = data.paymentTerms;
// Trigger due date recalculation (invoice-due-date.js listens to 'change')
termsSelect.dispatchEvent(new Event('change'));
}
// Show/hide early payment discount notice
const discountEl = document.getElementById('earlyPaymentDiscountNotice');
if (discountEl) {
if (data.earlyPaymentDiscountPercent > 0) {
discountEl.textContent = `${data.earlyPaymentDiscountPercent}% discount if paid within ${data.earlyPaymentDiscountDays} days`;
discountEl.classList.remove('d-none');
} else {
discountEl.classList.add('d-none');
}
}
}).catch(() => {});
// Fetch tax rate for the selected customer
fetch(`/Invoices/GetTaxRateForCustomer?customerId=${customerId}`)
.then(r => r.ok ? r.json() : null)
.then(data => {
if (!data) return;
const taxField = document.getElementById('TaxPercent');
if (taxField) {
taxField.value = data.taxPercent ?? 0;
recalcTotals();
}
}).catch(() => {
// Fall back to client-side tax exempt check
const taxField = document.getElementById('TaxPercent');
if (taxField) {
taxField.value = taxExemptCustomerIds.has(customerId) ? 0 : companyTaxPercent;
recalcTotals();
}
});
}
// ── Merchandise combobox ────────────────────────────────────────────────