Files
nademitex_admin/src/utils/settlement.ts
T

53 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-10-01 20:50:23 +03:30
import type { SettlementMethod } from '@/types'
const CASH_PHASE_RAW_STATUSES = new Set([
'awaiting_cash_payment',
'cash_invoice_issued',
'cash_in_progress',
'cash_payment_submitted',
'awaiting_cash_confirmation',
])
export function settlementMethodLabel(method?: string | null): string {
if (!method) return 'انتخاب‌نشده'
if (method === 'check') return 'چکی'
if (method === 'cash_check') return 'نصف نقد، نصف چکی'
2026-10-01 20:50:23 +03:30
return 'نقدی'
}
export function settlementPlanLabel(
method?: string | null,
checkTermMonths?: number | null,
): string {
const base = settlementMethodLabel(method)
if ((method === 'check' || method === 'cash_check') && checkTermMonths) {
return `${base} · چک ${checkTermMonths} ماهه`
}
return base
}
2026-10-01 20:50:23 +03:30
export function orderShowsCashActions(
order: { settlementMethod?: SettlementMethod | null; rawStatus?: string },
): boolean {
const method = order.settlementMethod
if (!method) return false
if (method === 'cash') {
return order.rawStatus !== 'cash_confirmed'
}
if (method === 'cash_check') {
return !!order.rawStatus && CASH_PHASE_RAW_STATUSES.has(order.rawStatus)
}
return false
}
export function orderShowsCheckActions(
order: { settlementMethod?: SettlementMethod | null; rawStatus?: string },
): boolean {
const method = order.settlementMethod
if (method === 'check') return true
if (method === 'cash_check') {
return !!order.rawStatus && !CASH_PHASE_RAW_STATUSES.has(order.rawStatus)
}
return false
}