Files
SupplierSystem/src/utils/exportColumnPresets.ts
T
Ubuntu 3ccb07acf6
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat(订单导出): 实收数量列读取持久字段
2026-11-03 13:08:26 +08:00

671 lines
25 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.
import type { ExportColumnDef } from './documentExport';
import { formatOrderAmount } from './currency';
import { formatCycleCode } from './cycleDisplay';
import { getStatementStatus } from './statements';
import { formatOrderStatusLabel } from './orderStatusLabels';
const fmtMoney = (v: unknown) => {
const n = Number(v);
return Number.isFinite(n) ? formatOrderAmount(n) : '';
};
const fmtQty = (v: unknown) => {
if (v == null || v === '') return '';
const n = Number(v);
if (!Number.isFinite(n)) return String(v);
return Number.isInteger(n) ? String(n) : n.toFixed(2).replace(/\.?0+$/, '');
};
const fmtQtyWithUnit = (qty: unknown, unit?: string | null) => {
const q = fmtQty(qty);
if (!q) return '';
const u = String(unit || '').trim();
return u ? `${q} ${u}` : q;
};
const fmtDate = (v: unknown) => {
if (!v) return '';
const d = new Date(String(v));
return Number.isNaN(d.getTime()) ? String(v) : d.toLocaleString('zh-CN');
};
const DELIVERY_SLOT: Record<string, string> = {
morning: '上午',
afternoon: '下午',
evening: '晚上',
};
const DELIVERY_STATUS: Record<string, string> = {
pending: '待配送',
delivering: '配送中',
completed: '已完成',
exception: '异常',
};
const QUOTE_APPROVAL: Record<number, string> = {
30: '执行中',
40: '已驳回',
};
export type OrderExportRow = {
order_code: string;
cycle_code?: string;
customer_code?: string;
company_name?: string;
order_status?: number;
total_amount?: number;
total_weight?: number;
delivery_date?: string;
delivery_time_slot?: string;
delivery_address?: string;
remark?: string;
created_at?: string;
sku_code?: string;
sku_name?: string;
item_name?: string;
quantity?: number;
unit?: string;
/** 销售单价(订单明细 price / locked_price) */
price?: number;
/** 成本单价(报价→备货→自采) */
cost_price?: number;
amount?: number;
processing_method?: string;
category_name?: string;
supplier_name?: string;
};
export const ORDER_HEADER_COLUMNS: ExportColumnDef<OrderExportRow>[] = [
{ id: 'order_code', label: '订单号', group: 'header', getValue: (r) => r.order_code || '' },
{ id: 'cycle_code', label: '周期', group: 'header', getValue: (r) => formatCycleCode(r.cycle_code || '') },
{ id: 'customer_code', label: '客户编码', group: 'header', getValue: (r) => r.customer_code || '' },
{ id: 'company_name', label: '客户名称', group: 'header', getValue: (r) => r.company_name || '' },
{
id: 'order_status',
label: '订单状态',
group: 'header',
getValue: (r) => formatOrderStatusLabel(r.order_status) || String(r.order_status ?? ''),
},
{ id: 'total_amount', label: '订单金额', group: 'header', getValue: (r) => fmtMoney(r.total_amount) },
{ id: 'total_weight', label: '总重量(kg)', group: 'header', defaultSelected: false, getValue: (r) => r.total_weight ?? '' },
{ id: 'delivery_date', label: '配送日期', group: 'header', getValue: (r) => r.delivery_date || '' },
{
id: 'delivery_time_slot',
label: '配送时段',
group: 'header',
defaultSelected: false,
getValue: (r) => DELIVERY_SLOT[r.delivery_time_slot || ''] || r.delivery_time_slot || '',
},
{ id: 'delivery_address', label: '配送地址', group: 'header', defaultSelected: false, getValue: (r) => r.delivery_address || '' },
{ id: 'remark', label: '备注', group: 'header', defaultSelected: false, getValue: (r) => r.remark || '' },
{ id: 'created_at', label: '创建时间', group: 'header', defaultSelected: false, getValue: (r) => fmtDate(r.created_at) },
];
export const ORDER_ITEM_COLUMNS: ExportColumnDef<OrderExportRow>[] = [
{ id: 'sku_code', label: '商品编码', group: 'item', getValue: (r) => r.sku_code || '' },
{ id: 'sku_name', label: '商品名称', group: 'item', getValue: (r) => r.sku_name || r.item_name || '' },
{ id: 'category_name', label: '分类', group: 'item', defaultSelected: false, getValue: (r) => r.category_name || '' },
{ id: 'quantity', label: '数量', group: 'item', getValue: (r) => r.quantity ?? '' },
{ id: 'unit', label: '单位', group: 'item', getValue: (r) => r.unit || '' },
{ id: 'processing_method', label: '加工方式', group: 'item', getValue: (r) => r.processing_method || '' },
{ id: 'price', label: '销售价', group: 'item', defaultSelected: true, getValue: (r) => fmtMoney(r.price) },
{ id: 'cost_price', label: '成本价', group: 'item', defaultSelected: true, getValue: (r) => fmtMoney(r.cost_price) },
{ id: 'amount', label: '行金额', group: 'item', defaultSelected: true, getValue: (r) => fmtMoney(r.amount) },
{ id: 'supplier_name', label: '供应商', group: 'item', defaultSelected: false, getValue: (r) => r.supplier_name || '' },
];
export type { PreparationExportRow } from './preparationSupplierExport';
export { PREPARATION_EXPORT_COLUMNS } from './preparationSupplierExport';
export type QuoteExportRow = {
quote_sheet_code: string;
title?: string;
version_no?: number;
quote_cycle?: string;
customer_names?: string;
customer_code?: string;
company_name?: string;
approval_status?: number;
status?: number;
effective_at?: string;
expires_at?: string;
sku_code?: string;
sku_name?: string;
unit?: string;
price?: number;
cost_price?: number;
sale_price?: number;
};
export const QUOTE_HEADER_COLUMNS: ExportColumnDef<QuoteExportRow>[] = [
{ id: 'quote_sheet_code', label: '报价单号', group: 'header', getValue: (r) => r.quote_sheet_code },
{ id: 'title', label: '标题', group: 'header', getValue: (r) => r.title || '' },
{ id: 'version_no', label: '版本', group: 'header', defaultSelected: false, getValue: (r) => r.version_no ?? '' },
{ id: 'quote_cycle', label: '报价周期', group: 'header', getValue: (r) => r.quote_cycle || '' },
{ id: 'customer_names', label: '适用客户', group: 'header', getValue: (r) => r.customer_names || r.company_name || '' },
{
id: 'approval_status',
label: '状态',
group: 'header',
getValue: (r) => {
if (r.status === 1 && Number(r.approval_status) === 30) return '执行中';
if (r.status === 3) return '已替换';
return QUOTE_APPROVAL[Number(r.approval_status)] || '已结束';
},
},
{ id: 'effective_at', label: '生效日期', group: 'header', getValue: (r) => r.effective_at || '' },
{ id: 'expires_at', label: '到期日期', group: 'header', getValue: (r) => r.expires_at || '' },
];
export const QUOTE_ITEM_COLUMNS: ExportColumnDef<QuoteExportRow>[] = [
{ id: 'sku_code', label: '商品编码', group: 'item', getValue: (r) => r.sku_code || '' },
{ id: 'sku_name', label: '商品名称', group: 'item', getValue: (r) => r.sku_name || '' },
{ id: 'unit', label: '单位', group: 'item', getValue: (r) => r.unit || '' },
{ id: 'cost_price', label: '成本价', group: 'item', getValue: (r) => fmtMoney(r.cost_price) },
{ id: 'sale_price', label: '销售价', group: 'item', getValue: (r) => fmtMoney(r.sale_price ?? r.price) },
];
export type StatementExportRow = {
statement_no: string;
party_name?: string;
party_code?: string;
cycle_code?: string;
total_amount?: number;
paid_amount?: number;
unpaid_amount?: number;
payable_amount?: number;
deduction_amount?: number;
due_date?: string;
statement_status?: number;
order_code?: string;
sku_code?: string;
sku_name?: string;
quantity?: number;
unit_price?: number;
line_amount?: number;
price_source?: string;
category_name?: string;
is_summary_row?: boolean;
settlement_bank_name?: string;
settlement_bank_account?: string;
settlement_contact_phone?: string;
};
export const STATEMENT_HEADER_COLUMNS: ExportColumnDef<StatementExportRow>[] = [
{ id: 'statement_no', label: '结算单号', group: 'header', getValue: (r) => r.statement_no },
{ id: 'party_code', label: '编码', group: 'header', getValue: (r) => r.party_code || '' },
{ id: 'party_name', label: '名称', group: 'header', getValue: (r) => r.party_name || '' },
{ id: 'cycle_code', label: '入账时间', group: 'header', getValue: (r) => formatCycleCode(r.cycle_code || '') },
{ id: 'total_amount', label: '结算总额', group: 'header', getValue: (r) => fmtMoney(r.total_amount) },
{ id: 'unpaid_amount', label: '未收/未付', group: 'header', getValue: (r) => fmtMoney(r.unpaid_amount ?? r.payable_amount) },
{ id: 'deduction_amount', label: '扣款', group: 'header', defaultSelected: false, getValue: (r) => fmtMoney(r.deduction_amount) },
{ id: 'due_date', label: '到期日', group: 'header', getValue: (r) => r.due_date || '' },
{ id: 'settlement_bank_name', label: '开户银行', group: 'header', defaultSelected: false, getValue: (r) => r.settlement_bank_name || '' },
{ id: 'settlement_bank_account', label: '银行账号', group: 'header', defaultSelected: false, getValue: (r) => r.settlement_bank_account || '' },
{ id: 'settlement_contact_phone', label: '联系电话', group: 'header', defaultSelected: false, getValue: (r) => r.settlement_contact_phone || '' },
{
id: 'statement_status',
label: '状态',
group: 'header',
getValue: (r) => getStatementStatus(r.statement_status ?? null).text,
},
];
export const STATEMENT_ITEM_COLUMNS: ExportColumnDef<StatementExportRow>[] = [
{ id: 'order_code', label: '订单号', group: 'item', getValue: (r) => r.order_code || '' },
{ id: 'sku_code', label: '商品编码', group: 'item', getValue: (r) => r.sku_code || '' },
{ id: 'sku_name', label: '商品名称', group: 'item', getValue: (r) => r.sku_name || '' },
{ id: 'quantity', label: '数量', group: 'item', getValue: (r) => r.quantity ?? '' },
{ id: 'unit_price', label: '单价', group: 'item', getValue: (r) => fmtMoney(r.unit_price) },
{ id: 'line_amount', label: '行金额', group: 'item', getValue: (r) => fmtMoney(r.line_amount) },
{ id: 'price_source', label: '价格来源', group: 'item', defaultSelected: false, getValue: (r) => r.price_source || '' },
];
/** 客户结算导出明细列:明细行用 line_amount,合计行用结算单 total_amount */
export const CUSTOMER_STATEMENT_ITEM_COLUMNS: ExportColumnDef<StatementExportRow>[] = [
{ id: 'order_code', label: '订单号', group: 'item', defaultSelected: false, getValue: (r) => r.order_code || '' },
{ id: 'sku_code', label: '商品编码', group: 'item', getValue: (r) => r.sku_code || '' },
{ id: 'sku_name', label: '商品名称', group: 'item', getValue: (r) => r.sku_name || '' },
{ id: 'category_name', label: '分类', group: 'item', getValue: (r) => r.category_name || '' },
{ id: 'quantity', label: '数量', group: 'item', getValue: (r) => r.quantity ?? '' },
{ id: 'unit_price', label: '单价', group: 'item', getValue: (r) => fmtMoney(r.unit_price) },
{
id: 'statement_total_amount',
label: '金额',
group: 'item',
getValue: (r) =>
fmtMoney(
r.is_summary_row || (r.line_amount == null && r.sku_code == null)
? r.total_amount
: (r.line_amount ?? r.total_amount)
),
},
{ id: 'price_source', label: '价格来源', group: 'item', defaultSelected: false, getValue: (r) => r.price_source || '' },
];
const fmtProductDesc = (spec?: string | null, origin?: string | null) => {
const parts = [String(spec || '').trim(), String(origin || '').trim()].filter(Boolean);
return parts.join(' / ');
};
export type DeliveryExportRow = {
task_code?: string;
order_code: string;
customer_code?: string;
customer_name?: string;
customer_phone?: string;
address?: string;
delivery_person?: string;
delivery_person_phone?: string;
status?: string;
estimated_time?: string;
actual_time?: string;
seq_no?: number;
sku_code?: string;
sku_name?: string;
customer_alias?: string;
category_name?: string;
spec?: string;
origin?: string;
quantity?: number;
unit?: string;
price?: number;
amount?: number;
actual_amount?: number;
picked_qty?: number | null;
loaded_qty?: number | null;
inspection_actual_qty?: number | null;
weigh_qty?: number | null;
weigh_unit?: string | null;
base_unit?: string | null;
weigh_qty_base?: number | null;
delivery_qty?: number | null;
received_qty?: number | null;
received_unit?: string | null;
box_no?: string;
box_count?: number | null;
processing_method?: string;
/** 明细备注 */
remark?: string;
item_remark?: string;
supplier_name?: string;
merchant_name?: string;
is_extra_dish?: boolean;
};
function withExtraDishLabel(name: string, isExtraDish?: boolean): string {
const label = String(name || '').trim();
if (!isExtraDish) return label;
return label ? `【加菜】${label}` : '【加菜】';
}
export const DELIVERY_HEADER_COLUMNS: ExportColumnDef<DeliveryExportRow>[] = [
{ id: 'task_code', label: '任务编号', group: 'header', getValue: (r) => r.task_code || '' },
{ id: 'order_code', label: '订单号', group: 'header', getValue: (r) => r.order_code },
{ id: 'customer_code', label: '客户编码', group: 'header', defaultSelected: false, getValue: (r) => r.customer_code || '' },
{ id: 'customer_name', label: '客户名称', group: 'header', getValue: (r) => r.customer_name || '' },
{ id: 'customer_phone', label: '联系电话', group: 'header', getValue: (r) => r.customer_phone || '' },
{ id: 'address', label: '送货地址', group: 'header', getValue: (r) => r.address || '' },
{ id: 'delivery_person', label: '配送员', group: 'header', getValue: (r) => r.delivery_person || '' },
{ id: 'delivery_person_phone', label: '配送员电话', group: 'header', defaultSelected: false, getValue: (r) => r.delivery_person_phone || '' },
{
id: 'status',
label: '配送状态',
group: 'header',
getValue: (r) => DELIVERY_STATUS[r.status || ''] || r.status || '',
},
{ id: 'estimated_time', label: '须送达时刻', group: 'header', defaultSelected: false, getValue: (r) => r.estimated_time || '' },
{ id: 'actual_time', label: '实际抵达', group: 'header', defaultSelected: false, getValue: (r) => r.actual_time || '' },
];
export const DELIVERY_ITEM_COLUMNS: ExportColumnDef<DeliveryExportRow>[] = [
{ id: 'seq_no', label: '序号', group: 'item', defaultSelected: true, getValue: (r) => r.seq_no ?? '' },
{ id: 'merchant_name', label: '商户', group: 'item', defaultSelected: false, getValue: (r) => r.merchant_name || '' },
{ id: 'sku_code', label: '商品编码', group: 'item', defaultSelected: false, getValue: (r) => r.sku_code || '' },
{
id: 'sku_name',
label: '商品名称',
group: 'item',
getValue: (r) => withExtraDishLabel(r.sku_name || '', r.is_extra_dish),
},
{
id: 'display_name',
label: '商品名称',
group: 'item',
defaultSelected: true,
getValue: (r) => withExtraDishLabel(r.customer_alias || r.sku_name || '', r.is_extra_dish),
},
{
id: 'product_desc',
label: '商品描述',
group: 'item',
defaultSelected: true,
getValue: (r) => fmtProductDesc(r.spec, r.origin),
},
{
id: 'customer_alias',
label: '商品别名',
group: 'item',
defaultSelected: true,
getValue: (r) => {
const alias = r.customer_alias || '';
return alias ? withExtraDishLabel(alias, r.is_extra_dish) : '';
},
},
{ id: 'category_name', label: '分类', group: 'item', defaultSelected: false, getValue: (r) => r.category_name || '' },
{ id: 'spec', label: '规格', group: 'item', defaultSelected: false, getValue: (r) => r.spec || '' },
{ id: 'origin', label: '产地', group: 'item', defaultSelected: false, getValue: (r) => r.origin || '' },
{ id: 'quantity', label: '下单数量', group: 'item', getValue: (r) => r.quantity ?? '' },
{
id: 'planned_qty',
label: '计划数量',
group: 'item',
defaultSelected: true,
getValue: (r) => fmtQty(r.quantity),
},
{ id: 'unit', label: '单位', group: 'item', getValue: (r) => r.unit || '' },
{
id: 'order_qty_display',
label: '下单数',
group: 'item',
defaultSelected: false,
getValue: (r) => fmtQtyWithUnit(r.quantity, r.unit),
},
{
id: 'picked_qty',
label: '分拣实重',
group: 'item',
defaultSelected: true,
getValue: (r) => fmtQtyWithUnit(r.picked_qty, r.weigh_unit || r.base_unit || r.unit),
},
{
id: 'weigh_qty',
label: '称重数',
group: 'item',
defaultSelected: true,
getValue: (r) => fmtQtyWithUnit(r.weigh_qty, r.weigh_unit),
},
{
id: 'weigh_qty_base',
label: '称重数(基本单位)',
group: 'item',
defaultSelected: true,
getValue: (r) => fmtQtyWithUnit(r.weigh_qty_base, r.base_unit),
},
{
id: 'inspection_actual_qty',
label: '验收实收',
group: 'item',
defaultSelected: false,
getValue: (r) => fmtQtyWithUnit(r.inspection_actual_qty, r.weigh_unit || r.base_unit),
},
{
id: 'delivery_qty',
label: '配送数量',
group: 'item',
defaultSelected: true,
getValue: (r) => fmtQtyWithUnit(r.delivery_qty, r.weigh_unit || r.base_unit || r.unit),
},
{
id: 'loaded_qty',
label: '装车数量',
group: 'item',
defaultSelected: false,
getValue: (r) => fmtQtyWithUnit(r.loaded_qty, r.weigh_unit || r.base_unit),
},
{ id: 'box_no', label: '箱号', group: 'item', defaultSelected: false, getValue: (r) => r.box_no || '' },
{ id: 'box_count', label: '箱数', group: 'item', defaultSelected: false, getValue: (r) => r.box_count ?? '' },
{ id: 'processing_method', label: '加工方式', group: 'item', defaultSelected: false, getValue: (r) => r.processing_method || '' },
{ id: 'price', label: '单价', group: 'item', getValue: (r) => fmtMoney(r.price) },
{ id: 'amount', label: '金额', group: 'item', getValue: (r) => fmtMoney(r.amount) },
{
id: 'received_qty',
label: '实收数量',
group: 'item',
defaultSelected: true,
getValue: (r) => fmtQty(r.received_qty ?? r.delivery_qty),
},
{
id: 'item_remark',
label: '备注',
group: 'item',
defaultSelected: true,
getValue: (r) => r.remark || r.item_remark || '',
},
{ id: 'actual_amount', label: '实配金额', group: 'item', defaultSelected: false, getValue: (r) => fmtMoney(r.actual_amount ?? r.amount) },
{ id: 'supplier_name', label: '供应商', group: 'item', defaultSelected: false, getValue: (r) => r.supplier_name || '' },
];
export type SkuExportRow = {
sku_code: string;
sku_name?: string;
category_name?: string;
unit?: string;
spec?: string;
origin?: string;
status?: number;
};
export const SKU_COLUMNS: ExportColumnDef<SkuExportRow>[] = [
{ id: 'sku_code', label: '商品编码', getValue: (r) => r.sku_code },
{ id: 'sku_name', label: '商品名称', getValue: (r) => r.sku_name || '' },
{ id: 'category_name', label: '分类', getValue: (r) => r.category_name || '' },
{ id: 'unit', label: '单位', getValue: (r) => r.unit || '' },
// 规格默认勾选(2026-10-16):存量商品大量缺规格,导出时通常就要看/改这一列
{ id: 'spec', label: '规格', defaultSelected: true, getValue: (r) => r.spec || '' },
{ id: 'origin', label: '产地', defaultSelected: false, getValue: (r) => r.origin || '' },
{
id: 'status',
label: '状态',
getValue: (r) => (Number(r.status) === 1 ? '启用' : '停用'),
},
];
export type InventoryExportRow = {
sku_code: string;
sku_name?: string;
category_name?: string;
batch_no?: string;
available_qty?: number;
production_date?: string;
expiry_date?: string;
cost_price?: number;
status?: number;
};
export const INVENTORY_COLUMNS: ExportColumnDef<InventoryExportRow>[] = [
{ id: 'sku_code', label: '商品编码', getValue: (r) => r.sku_code },
{ id: 'sku_name', label: '商品名称', getValue: (r) => r.sku_name || '' },
{ id: 'category_name', label: '分类', getValue: (r) => r.category_name || '' },
{ id: 'batch_no', label: '批次号', getValue: (r) => r.batch_no || '' },
{ id: 'available_qty', label: '可用量', getValue: (r) => r.available_qty ?? '' },
{ id: 'production_date', label: '生产日期', defaultSelected: false, getValue: (r) => r.production_date || '' },
{ id: 'expiry_date', label: '到期日', getValue: (r) => r.expiry_date || '' },
{ id: 'cost_price', label: '成本价', defaultSelected: false, getValue: (r) => fmtMoney(r.cost_price) },
{
id: 'status',
label: '状态',
getValue: (r) => (Number(r.status) === 1 ? '正常' : '停用'),
},
];
export function mergeExportColumns<T>(
header: ExportColumnDef<T>[],
item: ExportColumnDef<T>[]
): ExportColumnDef<T>[] {
return [...header, ...item];
}
/** 成本管理 · 商品成本明细导出(订单×SKU) */
export type CostSkuExportRow = {
cost_source: 'supplier' | 'self' | 'stock_cover';
cost_source_label: string;
order_code: string;
delivery_date: string;
customer_code: string;
customer_name: string;
supplier_code: string;
supplier_name: string;
sku_code: string;
sku_name: string;
category_name: string;
quantity: number;
unit: string;
unit_cost: number;
purchase_cost: number;
/** 库存成本(账本 inventory_cover 结转额);与 purchase_cost 相加 = 行真实成本 */
stock_cover_cost: number;
sales_amount: number;
};
type CostSkuExportTFn = (key: string, vars?: Record<string, string | number>) => string;
export function getCostSkuExportColumns(t: CostSkuExportTFn): ExportColumnDef<CostSkuExportRow>[] {
return [
{
id: 'cost_source',
label: t('finance.cost.sku.exportCol.source'),
getValue: (r) => r.cost_source_label || '',
},
{
id: 'order_code',
label: t('finance.cost.sku.exportCol.orderCode'),
getValue: (r) => r.order_code || '',
},
{
id: 'delivery_date',
label: t('finance.cost.sku.exportCol.deliveryDate'),
getValue: (r) => r.delivery_date || '',
},
{
id: 'customer_code',
label: t('finance.cost.sku.exportCol.customerCode'),
getValue: (r) => r.customer_code || '',
},
{
id: 'customer_name',
label: t('finance.cost.sku.exportCol.customerName'),
getValue: (r) => r.customer_name || '',
},
{
id: 'supplier_code',
label: t('finance.cost.sku.exportCol.supplierCode'),
defaultSelected: false,
getValue: (r) => r.supplier_code || '',
},
{
id: 'supplier_name',
label: t('finance.cost.sku.exportCol.supplierName'),
getValue: (r) => r.supplier_name || '',
},
{
id: 'sku_code',
label: t('finance.cost.sku.exportCol.skuCode'),
getValue: (r) => r.sku_code || '',
},
{
id: 'sku_name',
label: t('finance.cost.sku.exportCol.skuName'),
getValue: (r) => r.sku_name || '',
},
{
id: 'category_name',
label: t('finance.cost.sku.exportCol.category'),
getValue: (r) => r.category_name || '',
},
{
id: 'quantity',
label: t('finance.cost.sku.exportCol.quantity'),
getValue: (r) => fmtQty(r.quantity),
},
{
id: 'unit',
label: t('finance.cost.sku.exportCol.unit'),
getValue: (r) => r.unit || '',
},
{
id: 'unit_cost',
label: t('finance.cost.sku.exportCol.unitCost'),
getValue: (r) => fmtMoney(r.unit_cost),
},
{
id: 'purchase_cost',
label: t('finance.cost.sku.exportCol.purchaseCost'),
getValue: (r) => fmtMoney(r.purchase_cost),
},
{
// 2026-10-14 口径:行真实成本 = 采购成本(缺口量×unit_cost)+ 库存成本(账本结转额)
// 见 docs/design/20261014-订单成本排除独立进货与库存成本分类.md §5.1
id: 'stock_cover_cost',
label: t('finance.cost.sku.exportCol.stockCoverCost'),
getValue: (r) => fmtMoney(r.stock_cover_cost),
},
{
id: 'sales_amount',
label: t('finance.cost.sku.exportCol.salesAmount'),
getValue: (r) => fmtMoney(r.sales_amount),
},
];
}
type DeliveryExportTFn = (key: string, vars?: Record<string, string | number>) => string;
function withExtraDishLabelLocalized(
name: string,
isExtraDish: boolean | undefined,
tag: string
): string {
const label = String(name || '').trim();
if (!isExtraDish) return label;
return label ? `${tag}${label}` : tag;
}
/** Localize delivery export column titles (+ status / extra-dish shell) for current UI locale. */
export function localizeDeliveryExportColumns(
t: DeliveryExportTFn
): ExportColumnDef<DeliveryExportRow>[] {
const statusMap: Record<string, string> = {
pending: t('delivery.status.pending'),
delivering: t('delivery.status.delivering'),
completed: t('delivery.status.completed'),
exception: t('delivery.status.exception'),
};
const extraTag = t('delivery.export.extraDish');
return mergeExportColumns(DELIVERY_HEADER_COLUMNS, DELIVERY_ITEM_COLUMNS).map((col) => {
const label = t(`delivery.export.col.${col.id}`);
if (col.id === 'status') {
return {
...col,
label,
getValue: (r) => statusMap[r.status || ''] || r.status || '',
};
}
if (col.id === 'sku_name') {
return {
...col,
label,
getValue: (r) => withExtraDishLabelLocalized(r.sku_name || '', r.is_extra_dish, extraTag),
};
}
if (col.id === 'display_name') {
return {
...col,
label,
getValue: (r) =>
withExtraDishLabelLocalized(r.customer_alias || r.sku_name || '', r.is_extra_dish, extraTag),
};
}
if (col.id === 'customer_alias') {
return {
...col,
label,
getValue: (r) => {
const alias = r.customer_alias || '';
return alias ? withExtraDishLabelLocalized(alias, r.is_extra_dish, extraTag) : '';
},
};
}
return { ...col, label };
});
}