feat(tahesab): polish asnad invoice PDF and prior balance

Compute حساب قبل from asnad before this doc date/number, add in-app preview layout, and leave a blank mesghal line for handwriting after print.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-24 21:47:46 +03:30
co-authored by Cursor
parent 1ba352f127
commit 2d690b4c04
6 changed files with 1364 additions and 143 deletions
+22
View File
@@ -1,3 +1,5 @@
import { toFaDigits } from '@/lib/jalali';
/** برچسب انواع سند ته‌حساب — کپی runtime برای Vite (بدون named export از shared) */
export const TAHSAB_SANAD_LABELS: Record<string, string> = {
buy_sale_gold: 'خرید/فروش آبشده',
@@ -6,3 +8,23 @@ export const TAHSAB_SANAD_LABELS: Record<string, string> = {
vkh_gold: 'واریز/خروج طلا',
vkh_bank: 'واریز/خروج بانکی',
};
/**
* قالب نمایش ته‌حساب برای مبالغ/مانده‌های علامت‌دار:
* منفی → قدرمطلق + «بد» (بدهکار)، مثبت → قدرمطلق + «بس» (بستانکار).
* صفر بدون پسوند.
*/
export function formatTahesabBedBes(v: unknown): 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: 3 }).format(
Math.abs(n),
),
);
if (n === 0) return abs;
return `${abs} ${n < 0 ? 'بد' : 'بس'}`;
}