42 lines
2.4 KiB
TypeScript
42 lines
2.4 KiB
TypeScript
import { feeMoney } from './overseasFeePresentation'
|
|
import type { StorageRentLot } from './api/storageRent'
|
|
|
|
export function storageRentSourceType(type?: string | null) {
|
|
const labels: Record<string, string> = { LASTLEG_ORDER: '头程尾程订单', WAREHOUSE_TRANSFER: '仓储转运单', RETURN_ORDER: '退货单' }
|
|
return type ? labels[type] || type : '—'
|
|
}
|
|
|
|
export function storageRentGeneratedAmounts(lot: Pick<StorageRentLot, 'generatedAmounts' | 'generatedAmount' | 'generatedCurrency'>) {
|
|
if (lot.generatedAmounts?.length) return lot.generatedAmounts.map(item => feeMoney(item.amount, item.currency))
|
|
return [feeMoney(lot.generatedAmount, lot.generatedCurrency || '')]
|
|
}
|
|
|
|
export function storageRentChargeStatus(charge: { status: string; originalAmount: number | string | null }) {
|
|
if (charge.status === 'SETTLED' && charge.originalAmount != null && Number(charge.originalAmount) === 0) return '免租'
|
|
const labels: Record<string, string> = { PENDING_REVIEW: '待审核', REJECTED: '已驳回', REVIEW_FREEZE_PENDING: '调整锁定中', REVIEW_FREEZE_FAILED: '调整锁定失败', FREEZE_PENDING: '锁定中', READY: '待出库', CONSUMED: '扣费中', SETTLED: '已扣费', SETTLE_FAILED: '扣费失败', FAILED: '锁定失败', EXPIRED: '已过期', CANCELLED: '已取消' }
|
|
return labels[charge.status] || charge.status
|
|
}
|
|
|
|
export function storageRentSummaryStatus(lot: StorageRentLot) {
|
|
if (lot.chargeCount == null) return '待核对'
|
|
if (!Number(lot.chargeCount)) return lot.status === 'CLEARED' ? '仓租记录待核对' : '尚未出库计租'
|
|
if (Number(lot.settledChargeCount) < Number(lot.chargeCount)) return '有待完成扣款'
|
|
return Number(lot.settledAmount) === 0 ? '免租 · 已结算' : '已扣款'
|
|
}
|
|
|
|
export function storageRentBillingShare(quantity: number, lot: StorageRentLot) {
|
|
if (!(Number(lot.originalQuantity) > 0) || lot.billingQuantity == null) return '—'
|
|
const units = Number(quantity) * Number(lot.billingQuantity) / Number(lot.originalQuantity)
|
|
return `${Number(units.toFixed(6))} ${lot.billingUnit === 'PALLET' ? '托' : lot.billingUnit}`
|
|
}
|
|
|
|
export function storageRentTime(value?: string | null, timeZone?: string) {
|
|
if (!value) return '—'
|
|
const date = new Date(value)
|
|
if (Number.isNaN(date.getTime())) return '—'
|
|
return new Intl.DateTimeFormat('sv-SE', {
|
|
year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
hourCycle: 'h23', timeZone,
|
|
}).format(date)
|
|
}
|