Files
CRM_Montzar/apps/web/src/views/treasury/treasury-format.ts
T
MahdiandCursor 1b08ab1230 Show selected account balance beside the treasury account field.
Color the balance green, red, or gray on income and expense forms so users see cash position before posting.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-15 13:48:30 +03:30

24 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export function toman(value: string | number | null | undefined) {
const n = Number(value ?? 0);
if (!Number.isFinite(n)) return '۰';
return `${new Intl.NumberFormat('fa-IR').format(Math.round(n))} تومان`;
}
/** ماندهٔ دریافتنی منهای ماندهٔ پرداختنی: بد قرمز، بس سبز، صفر خاکستری. */
export function partyNetPosition(receivable: number, payable: number) {
const net = receivable - payable;
if (net > 0) return { text: `بد ${toman(net)}`, type: 'danger' as const };
if (net < 0) return { text: `بس ${toman(-net)}`, type: 'success' as const };
return { text: `مانده ${toman(0)}`, type: 'secondary' as const };
}
/** موجودی حساب: مثبت سبز، منفی قرمز، صفر خاکستری. */
export function accountBalanceTone(balance: string | number | null | undefined) {
const n = Number(balance ?? 0);
if (!Number.isFinite(n) || n === 0) {
return { text: `موجودی ${toman(0)}`, type: 'secondary' as const };
}
if (n > 0) return { text: `موجودی ${toman(n)}`, type: 'success' as const };
return { text: `موجودی ${toman(n)}`, type: 'danger' as const };
}