/** * Net amount of a single document line after its per-item percentage discount * ("Sleva"). `net = qty × unit_price × (1 − discount/100)`. * * The discount is tolerant of null/undefined/NaN (a missing discount = none) * and clamped to 0–100 so a stray value can never make the net negative. * Single source of truth for offers + invoices (totals, VAT base, PDFs). */ export function lineNet( qty: number, unitPrice: number, discountPct: number | null | undefined, ): number { const pct = Number(discountPct); const safePct = Number.isFinite(pct) ? Math.min(100, Math.max(0, pct)) : 0; return qty * unitPrice * (1 - safePct / 100); }