Files
client-web/src/modules/first-leg/utils/inboundBilling.ts
T
2026-09-21 19:36:37 +08:00

86 lines
3.1 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 formatInboundNumber(value: number | null | undefined, maximumFractionDigits = 3) {
if (value === null || value === undefined || !Number.isFinite(value)) return '-'
return new Intl.NumberFormat('zh-CN', { maximumFractionDigits }).format(value)
}
export function formatInboundMeasure(value: number | null | undefined, unit: string, maximumFractionDigits = 3) {
const formatted = formatInboundNumber(value, maximumFractionDigits)
return formatted === '-' ? formatted : `${formatted} ${unit}`
}
export function formatInboundMoney(value: number | null | undefined, currency: string) {
if (value === null || value === undefined || !Number.isFinite(value)) return '-'
try {
return new Intl.NumberFormat('zh-CN', {
style: 'currency',
currency,
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(value)
} catch {
return `${currency} ${value.toFixed(2)}`
}
}
export function formatInboundDateTime(value: string | null | undefined) {
if (!value) return '-'
const date = new Date(value)
if (Number.isNaN(date.getTime())) return value
return new Intl.DateTimeFormat('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: false,
}).format(date)
}
export function getChargeModeLabel(value: 'KG' | 'CBM') {
return value === 'KG' ? '按重量计费' : '按体积计费'
}
export function getTaxModeLabel(value: string) {
if (value === 'TAX_INCLUDED') return '包税'
if (value === 'TAX_EXCLUDED') return '不包税'
return value || '-'
}
export function getCalculationRuleLabel(value: string | null | undefined) {
if (!value) return '-'
if (value === 'ACTUAL_DIMENSION_V1' || value === 'DIMENSION_ACTUAL_V1') return '按实际箱规计算'
const customerRule = /^CUSTOMER_DIMENSION_(SMALL|MEDIUM|LARGE|EXTRA_LARGE)_V(\d+)$/.exec(value)
if (customerRule) {
const sizeLabel: Record<string, string> = {
SMALL: '小号', MEDIUM: '中号', LARGE: '大号', EXTRA_LARGE: '超大号',
}
return `客户箱规规则(${sizeLabel[customerRule[1]]},V${customerRule[2]})`
}
const warehouseRule = /^WAREHOUSE_OUTER_OVERRIDE_(.+)$/.exec(value)
return warehouseRule ? `仓库外箱规覆盖(${warehouseRule[1]})` : value
}
export function getRoundingModeLabel(value: string | null | undefined) {
const labels: Record<string, string> = {
UP: '向上舍入',
DOWN: '向下舍入',
CEILING: '向上取整',
FLOOR: '向下取整',
HALF_UP: '四舍五入',
HALF_DOWN: '五舍六入',
HALF_EVEN: '银行家舍入',
}
return value ? labels[value] || value : '-'
}
export function formatConversionPrecision(
conversionFactor: number | null | undefined,
roundingScale: number | null | undefined,
roundingMode: string | null | undefined,
) {
if (conversionFactor === null || conversionFactor === undefined
|| roundingScale === null || roundingScale === undefined
|| !roundingMode) return '-'
return `系数 ${formatInboundNumber(conversionFactor)} · 保留 ${roundingScale} 位 ${getRoundingModeLabel(roundingMode)}`
}