47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import type { InventoryBalanceDto } from './api/inventory'
|
|
import type { InventoryListItem } from './types'
|
|
import { formatOverseasDateTime } from './lastMilePresentation'
|
|
|
|
function text(value: unknown) {
|
|
const normalized = String(value ?? '').trim()
|
|
return normalized || '—'
|
|
}
|
|
|
|
function count(value: unknown) {
|
|
const normalized = Number(value)
|
|
return Number.isFinite(normalized) ? normalized : 0
|
|
}
|
|
|
|
export function inventoryProductName(dto: InventoryBalanceDto) {
|
|
return text(dto.productNameZh || dto.productNameEn)
|
|
}
|
|
|
|
export function inventoryStatusLabel(dto: InventoryBalanceDto) {
|
|
if (count(dto.holdPackages) > 0) return '存在暂扣'
|
|
if (count(dto.availablePackages) <= 0) return '无可用库存'
|
|
return '正常'
|
|
}
|
|
|
|
export function toInventoryListItem(dto: InventoryBalanceDto): InventoryListItem {
|
|
return {
|
|
id: String(dto.id),
|
|
customerId: String(dto.customerId),
|
|
warehouseId: String(dto.overseasWarehouseId || ''),
|
|
inboundOrderNo: text(dto.inboundOrderNo) === '—' ? '' : String(dto.inboundOrderNo),
|
|
inboundCode: text(dto.inboundCode) === '—' ? '' : String(dto.inboundCode),
|
|
owner: text(dto.customerName),
|
|
warehouse: text(dto.overseasWarehouseName || dto.overseasWarehouseCode),
|
|
sku: text(dto.skuCode),
|
|
productName: inventoryProductName(dto),
|
|
location: '—',
|
|
onHand: count(dto.totalPackages),
|
|
available: count(dto.availablePackages),
|
|
held: count(dto.holdPackages),
|
|
looseboard: '—',
|
|
inTransit: count(dto.inTransitPackages),
|
|
purchase: count(dto.procurementPackages),
|
|
status: inventoryStatusLabel(dto),
|
|
updatedAt: formatOverseasDateTime(dto.updatedAt),
|
|
}
|
|
}
|