Files
portal/app/resources/js/composables/billingFormatters.ts
T

52 lines
2.1 KiB
TypeScript
Raw Normal View History

/**
* Форматтеры для биллинга. Экспортируются для использования в нескольких
* sub-components BillingView (BalanceCard, TransactionsTable, InvoicesTable).
* Sprint 4 Phase B/2 — split BillingView.
*/
import type { BillingTransaction, InvoiceFormat, TxStatus } from './mockBilling';
/** «5000» → «5 000 ₽» (без знака). */
export function formatPlain(cost: number): string {
return new Intl.NumberFormat('ru-RU').format(cost) + ' ₽';
}
/** Знаковый формат: «+ 5 000 ₽» / «− 6 600 ₽» / «0 ₽». */
export function formatCost(cost: number): string {
const sign = cost > 0 ? '+ ' : cost < 0 ? ' ' : '';
return sign + new Intl.NumberFormat('ru-RU').format(Math.abs(cost)) + ' ₽';
}
/** CSS-класс для суммы транзакции по статусу/знаку. */
export function txAmountClass(tx: BillingTransaction): string {
if (tx.status === 'rejected') return 'tx-amount-neutral';
if (tx.amount > 0) return 'tx-amount-up';
if (tx.amount < 0) return 'tx-amount-down';
return 'tx-amount-neutral';
}
/** Vuetify-цвет чипа статуса транзакции. */
export function statusChipColor(status: TxStatus): string {
if (status === 'pending') return 'warning';
if (status === 'completed') return 'success';
return 'error';
}
/** Локализованный лейбл статуса транзакции. */
export function statusLabel(status: TxStatus): string {
if (status === 'pending') return 'В обработке';
if (status === 'completed') return 'Проведён';
return 'Отклонено';
}
/** Лейбл формата файла счёта/УПД (PDF / 1С 8.3 XML). */
export function formatLabel(format: InvoiceFormat): string {
if (format === 'pdf') return 'PDF';
return '1С 8.3 XML';
}
/** Иконка формата файла счёта/УПД. */
export function formatIcon(format: InvoiceFormat): string {
if (format === 'pdf') return 'mdi-file-pdf-box';
return 'mdi-xml';
}