feat: add invoice builder with line detail, address, and person picker.
Enrich invoice line items and previews, migrate several CRM surfaces to Ant, and wire shared money/picker helpers.
This commit is contained in:
@@ -62,6 +62,75 @@ export function formatGroupedInput(value: number, maxFractionDigits = 2): string
|
||||
}).format(value);
|
||||
}
|
||||
|
||||
/** formatter برای a-input-number با جداکنندهٔ هزارگان فارسی */
|
||||
export function groupedNumberFormatter(maxFractionDigits = 2) {
|
||||
return (value: string | number) => {
|
||||
if (value === '' || value == null) return '';
|
||||
const n = typeof value === 'number' ? value : Number(value);
|
||||
if (!Number.isFinite(n)) return String(value);
|
||||
return formatGroupedInput(n, maxFractionDigits);
|
||||
};
|
||||
}
|
||||
|
||||
/** parser برای a-input-number؛ ارقام فارسی و جداکنندهها را میپذیرد */
|
||||
export function groupedNumberParser(maxFractionDigits = 2) {
|
||||
return (display?: string) => {
|
||||
if (display == null || display === '') return '';
|
||||
const n = parseMoneyNumber(display, maxFractionDigits);
|
||||
return n == null ? '' : n;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* فقط رقم (و در صورت نیاز اعشار/منفی) را هنگام تایپ میپذیرد.
|
||||
* میانبرها (Ctrl/Meta) و کلیدهای کنترلی (Backspace، Enter، …) آزاد میمانند.
|
||||
*/
|
||||
export function blockNonNumericKeydown(
|
||||
event: KeyboardEvent,
|
||||
opts: { allowDecimal?: boolean; allowMinus?: boolean } = {},
|
||||
) {
|
||||
const { allowDecimal = true, allowMinus = false } = opts;
|
||||
if (event.ctrlKey || event.metaKey || event.altKey) return;
|
||||
if (event.isComposing) return;
|
||||
if (event.key.length !== 1) return;
|
||||
|
||||
if (/[0-9۰-۹٠-٩]/.test(event.key)) return;
|
||||
if (
|
||||
allowDecimal &&
|
||||
(event.key === '.' ||
|
||||
event.key === ',' ||
|
||||
event.key === '٫' ||
|
||||
event.key === '،')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (allowMinus && event.key === '-') return;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
/** متن پیستشده را به کاراکترهای مجاز عددی محدود میکند */
|
||||
export function sanitizeNumericClipboard(
|
||||
raw: string,
|
||||
opts: { allowDecimal?: boolean; allowMinus?: boolean } = {},
|
||||
): string {
|
||||
const { allowDecimal = true, allowMinus = false } = opts;
|
||||
let out = '';
|
||||
for (const ch of raw) {
|
||||
if (/[0-9۰-۹٠-٩]/.test(ch)) {
|
||||
out += ch;
|
||||
continue;
|
||||
}
|
||||
if (allowDecimal && (ch === '.' || ch === ',' || ch === '٫' || ch === '،')) {
|
||||
out += ch;
|
||||
continue;
|
||||
}
|
||||
if (allowMinus && ch === '-' && !out.includes('-')) {
|
||||
out += ch;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* پارس متن ورودی مبلغ/قیمت.
|
||||
* جداکنندهها و ارقام فارسی را میپذیرد و مقدار عددی برمیگرداند.
|
||||
|
||||
Reference in New Issue
Block a user