- Migration M8 adds payments (cash, TDS, mode, reference). Payment status is derived, never stored: unpaid, partially paid, paid, or overdue. Overpayment is rejected, TDS counts toward settling, and only issued invoices accept payments. list_invoices and get_invoice carry the paid, TDS and balance summary. - New invoice detail view: archived-PDF preview, payments list, Record payment modal, Export, Duplicate (as a draft), Re-render and Cancel. An invoice with payments cannot be cancelled until they are deleted. - History gets search, status, financial-year, month and client filters, sortable columns, pagination, footer totals and an FY summary. Cancelled invoices are excluded from totals. The per-row archive-status calls are gone; archiving is on the detail page. - Rust tests for payments and the list summary; vitest for fiscal-year, money, filter and duplicate helpers. PDF output and fingerprint goldens are unchanged. The new UI has not been run in a webview yet.
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { formatAmount } from "./format";
|
|
|
|
/**
|
|
* Parses what a person types into an amount field ("1,25,000", "1250.5", "₹ 99.99") into integer paise
|
|
* without going through floating point. Returns null for anything that is not a plain amount with at
|
|
* most two decimals; an empty string is 0.
|
|
*/
|
|
export function parseRupeesToPaise(text: string): number | null {
|
|
const cleaned = text.replace(/[₹,\s]/g, "");
|
|
if (cleaned === "") return 0;
|
|
const m = /^(\d+)(?:\.(\d{0,2}))?$/.exec(cleaned);
|
|
if (!m) return null;
|
|
const whole = Number(m[1]);
|
|
const paise = whole * 100 + Number((m[2] ?? "").padEnd(2, "0"));
|
|
return Number.isSafeInteger(paise) ? paise : null;
|
|
}
|
|
|
|
/** 123450 -> "1234.50", for filling an amount field. */
|
|
export function paiseToInput(paise: number): string {
|
|
const p = Math.max(0, Math.round(paise));
|
|
return `${Math.floor(p / 100)}.${String(p % 100).padStart(2, "0")}`;
|
|
}
|
|
|
|
/** 123450 -> "₹1,234.50" */
|
|
export function formatPaise(paise: number): string {
|
|
return `₹${formatAmount(paise / 100)}`;
|
|
}
|