Files
CRM_Montzar/apps/web/src/lib/tahesab.ts
T
MahdiandCursor 9812e4e5ba fix(crm): honor open data scopes and role assignees
Unset sections on a saved role policy were still filtered as own-only, so full lead access showed nothing. Activities can now be assigned by org role, and the Tahesab sales report reads as a result instead of a tag wall.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-27 18:07:42 +03:30

29 lines
1.2 KiB
TypeScript

import { toFaDigits } from '@/lib/jalali';
/** برچسب انواع سند ته‌حساب — کپی runtime برای Vite (بدون named export از shared) */
export const TAHSAB_SANAD_LABELS: Record<string, string> = {
buy_sale_gold: 'خرید/فروش آبشده',
buy_sale_sekeh: 'خرید/فروش سکه',
talab_bedehi: 'طلب/بدهی',
vkh_gold: 'واریز/خروج طلا',
vkh_bank: 'واریز/خروج بانکی',
};
/**
* قالب نمایش ته‌حساب برای مبالغ/مانده‌های علامت‌دار:
* منفی → قدرمطلق + «بد» (بدهکار)، مثبت → قدرمطلق + «بس» (بستانکار).
* صفر بدون پسوند.
*/
export function formatTahesabBedBes(v: unknown, maximumFractionDigits = 3): string {
if (v == null) return '—';
const s = String(v).trim();
if (!s || s === 'null' || s === 'undefined' || s === 'NaN') return '—';
const n = Number(s.replace(/,/g, ''));
if (!Number.isFinite(n)) return toFaDigits(s);
const abs = toFaDigits(
new Intl.NumberFormat('fa-IR', { maximumFractionDigits }).format(Math.abs(n)),
);
if (n === 0) return abs;
return `${abs} ${n < 0 ? 'بد' : 'بس'}`;
}