fix(报价单): 明细显示双边的商品名(我方商品 + 配送商品),不再只显示 SKU
- 根因:新「按分类提交」的提议 items 用的是我方 SKU,旧代码按配送 SKU 反查映射 ⇒ 名字/原价全空 - 现在兼容两种约定(我方 SKU 直接用 / 配送 SKU 才反查),并从本系统 skus + 映射镜像取双边名称 - 面板明细改为:我方商品 | 配送商品 | 单位 | 原价 → 新价
This commit is contained in:
@@ -154,6 +154,9 @@ export type QuotePriceProposalDto = {
|
||||
change: 'updated' | 'added' | 'unmapped';
|
||||
/** 反查到的我方 SKU(未映射时为空) */
|
||||
supplier_sku_code?: string | null;
|
||||
/** 对应的配送侧 SKU / 商品名(供审批人对照;配送侧商品名可能与我方不同) */
|
||||
delivery_sku_code?: string | null;
|
||||
delivery_sku_name?: string | null;
|
||||
}>;
|
||||
/** 列表附加:该行最近一次 D2 回执里的 applied 摘要(若本轮拉到了) */
|
||||
applied?: { updated: number; skipped: unknown } | null;
|
||||
@@ -837,39 +840,74 @@ export async function listPriceProposals(input: {
|
||||
if (!bySheet.has(sheet)) bySheet.set(sheet, new Map());
|
||||
bySheet.get(sheet)!.set(String(row.sku_code), row);
|
||||
}
|
||||
// 提议 items 是**配送 SKU** ⇒ 批量反查本地映射(只认 active + delivery_sku_code 非空)
|
||||
const deliverySkus = [
|
||||
...new Set(pendingFromDelivery.flatMap((row) => row.items.map((item) => toText(item.sku_code))).filter(Boolean)),
|
||||
// 提议 items 的 sku_code 有两种约定:
|
||||
// ① 配送侧**手动**发起:给的是「配送 SKU」⇒ 需要反查映射得到我方 SKU;
|
||||
// ② 配送侧「按分类提交成本价」:给的是**我方 SKU**(发送前已按映射换过)⇒ 直接用。
|
||||
const itemCodes = [
|
||||
...new Set(
|
||||
pendingFromDelivery.flatMap((row) => row.items.map((item) => toText(item.sku_code))).filter(Boolean)
|
||||
),
|
||||
];
|
||||
const localSkus = new Map<string, { sku_name: string | null; unit: string | null }>();
|
||||
const deliveryToSupplier = new Map<string, string>();
|
||||
if (deliverySkus.length) {
|
||||
const mappings = await pool.query<{ supplier_sku_code: string; delivery_sku_code: string }>(
|
||||
`SELECT supplier_sku_code, delivery_sku_code
|
||||
FROM main_system_sku_mappings
|
||||
WHERE delivery_sku_code = ANY($1) AND status = 'active'`,
|
||||
[deliverySkus]
|
||||
const supplierToDelivery = new Map<
|
||||
string,
|
||||
{ delivery_sku_code: string; delivery_sku_name: string | null; supplier_sku_name: string | null }
|
||||
>();
|
||||
if (itemCodes.length) {
|
||||
const localRows = await pool.query<{ sku_code: string; sku_name: string | null; unit: string | null }>(
|
||||
`SELECT sku_code, sku_name, unit FROM skus WHERE sku_code = ANY($1)`,
|
||||
[itemCodes]
|
||||
);
|
||||
for (const mapping of mappings.rows) {
|
||||
deliveryToSupplier.set(String(mapping.delivery_sku_code), String(mapping.supplier_sku_code));
|
||||
for (const r of localRows.rows) {
|
||||
localSkus.set(String(r.sku_code), {
|
||||
sku_name: r.sku_name == null ? null : String(r.sku_name),
|
||||
unit: r.unit == null ? null : String(r.unit),
|
||||
});
|
||||
}
|
||||
const mappings = await pool.query<{
|
||||
supplier_sku_code: string;
|
||||
supplier_sku_name: string | null;
|
||||
delivery_sku_code: string;
|
||||
delivery_sku_name: string | null;
|
||||
}>(
|
||||
`SELECT supplier_sku_code, supplier_sku_name, delivery_sku_code, delivery_sku_name
|
||||
FROM main_system_sku_mappings
|
||||
WHERE status = 'active'
|
||||
AND (delivery_sku_code = ANY($1) OR supplier_sku_code = ANY($1))`,
|
||||
[itemCodes]
|
||||
);
|
||||
for (const m of mappings.rows) {
|
||||
deliveryToSupplier.set(String(m.delivery_sku_code), String(m.supplier_sku_code));
|
||||
supplierToDelivery.set(String(m.supplier_sku_code), {
|
||||
delivery_sku_code: String(m.delivery_sku_code),
|
||||
delivery_sku_name: m.delivery_sku_name == null ? null : String(m.delivery_sku_name),
|
||||
supplier_sku_name: m.supplier_sku_name == null ? null : String(m.supplier_sku_name),
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const row of pendingFromDelivery) {
|
||||
const current = bySheet.get(row.quote_sheet_code) || new Map();
|
||||
row.lines = row.items.map((item) => {
|
||||
const supplierSku = deliveryToSupplier.get(toText(item.sku_code)) || null;
|
||||
const code = toText(item.sku_code);
|
||||
const isLocalSupplierSku = localSkus.has(code);
|
||||
const supplierSku = isLocalSupplierSku ? code : deliveryToSupplier.get(code) || null;
|
||||
const before = supplierSku ? current.get(supplierSku) : undefined;
|
||||
const local = supplierSku ? localSkus.get(supplierSku) : undefined;
|
||||
const mirrored = supplierSku ? supplierToDelivery.get(supplierSku) : undefined;
|
||||
const supplierName = before?.sku_name
|
||||
? String(before.sku_name)
|
||||
: local?.sku_name ?? mirrored?.supplier_sku_name ?? null;
|
||||
return {
|
||||
sku_code: item.sku_code,
|
||||
sku_code: code,
|
||||
supplier_sku_code: supplierSku,
|
||||
sku_name: before?.sku_name
|
||||
? String(before.sku_name)
|
||||
: supplierSku
|
||||
? null
|
||||
: null,
|
||||
unit: item.unit || (before?.unit ? String(before.unit) : null),
|
||||
sku_name: supplierName,
|
||||
unit: item.unit || (before?.unit ? String(before.unit) : local?.unit ?? null),
|
||||
before_sale_price: before ? readSheetPrice(before) : null,
|
||||
after_sale_price: roundPrice(item.price),
|
||||
change: !supplierSku ? ('unmapped' as const) : before ? ('updated' as const) : ('added' as const),
|
||||
delivery_sku_code: mirrored?.delivery_sku_code ?? (isLocalSupplierSku ? null : code),
|
||||
delivery_sku_name: mirrored?.delivery_sku_name ?? null,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -192,6 +192,8 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.priceChange': 'Before → After',
|
||||
'priceProposal.col.actions': 'Actions',
|
||||
'priceProposal.col.product': 'Item',
|
||||
'priceProposal.col.supplierProduct': 'Our item',
|
||||
'priceProposal.col.deliveryProduct': 'Delivery item',
|
||||
'priceProposal.col.unit': 'Unit',
|
||||
'priceProposal.col.before': 'Before',
|
||||
'priceProposal.col.after': 'After',
|
||||
|
||||
@@ -197,6 +197,8 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.priceChange': 'Sebelum → Sesudah',
|
||||
'priceProposal.col.actions': 'Aksi',
|
||||
'priceProposal.col.product': 'Item',
|
||||
'priceProposal.col.supplierProduct': 'Item kami',
|
||||
'priceProposal.col.deliveryProduct': 'Item pengiriman',
|
||||
'priceProposal.col.unit': 'Satuan',
|
||||
'priceProposal.col.before': 'Sebelum',
|
||||
'priceProposal.col.after': 'Sesudah',
|
||||
|
||||
@@ -188,6 +188,8 @@ export const quotes: MessageDict = {
|
||||
'priceProposal.col.priceChange': '原价 → 新价',
|
||||
'priceProposal.col.actions': '操作',
|
||||
'priceProposal.col.product': '商品',
|
||||
'priceProposal.col.supplierProduct': '我方商品',
|
||||
'priceProposal.col.deliveryProduct': '配送商品',
|
||||
'priceProposal.col.unit': '单位',
|
||||
'priceProposal.col.before': '原价',
|
||||
'priceProposal.col.after': '新价',
|
||||
|
||||
@@ -245,7 +245,8 @@ export const QuoteDeliveryPriceProposalsPanel: React.FC<QuoteDeliveryPricePropos
|
||||
<table className="min-w-full text-xs">
|
||||
<thead className="text-left text-gray-500">
|
||||
<tr>
|
||||
<th className="px-1 py-0.5">{t('quotes.priceProposal.col.product')}</th>
|
||||
<th className="px-1 py-0.5">{t('quotes.priceProposal.col.supplierProduct')}</th>
|
||||
<th className="px-1 py-0.5">{t('quotes.priceProposal.col.deliveryProduct')}</th>
|
||||
<th className="px-1 py-0.5">{t('quotes.priceProposal.col.unit')}</th>
|
||||
<th className="px-1 py-0.5 text-right">{t('quotes.priceProposal.col.priceChange')}</th>
|
||||
</tr>
|
||||
@@ -254,8 +255,16 @@ export const QuoteDeliveryPriceProposalsPanel: React.FC<QuoteDeliveryPricePropos
|
||||
{(row.lines || []).map((line) => (
|
||||
<tr key={`${line.change}-${line.sku_code}`}>
|
||||
<td className="px-1 py-0.5">
|
||||
{line.sku_name || line.sku_code}
|
||||
<span className="ml-1 font-mono text-gray-400">{line.sku_code}</span>
|
||||
{line.sku_name || line.supplier_sku_code || '—'}
|
||||
<span className="ml-1 font-mono text-gray-400">
|
||||
{line.supplier_sku_code || line.sku_code}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-1 py-0.5">
|
||||
{line.delivery_sku_name || '—'}
|
||||
{line.delivery_sku_code ? (
|
||||
<span className="ml-1 font-mono text-gray-400">{line.delivery_sku_code}</span>
|
||||
) : null}
|
||||
</td>
|
||||
<td className="px-1 py-0.5">{line.unit || '—'}</td>
|
||||
<td className="px-1 py-0.5 text-right tabular-nums">
|
||||
|
||||
@@ -2758,6 +2758,8 @@ export type QuotePriceProposalDto = {
|
||||
/** unmapped = 该配送 SKU 在本地映射里还没有 active 映射(审批会 skip sku_unmapped) */
|
||||
change: 'updated' | 'added' | 'unmapped';
|
||||
supplier_sku_code?: string | null;
|
||||
delivery_sku_code?: string | null;
|
||||
delivery_sku_name?: string | null;
|
||||
}>;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user