style(成本排行): 展开区对齐报价单目标列表
有价格目标时只显示目标行:报价单/商品库标记、报价单名+客户名、当前销售价、右侧输入;隐藏通用成本明细;补客户名与当前价文案。
This commit is contained in:
@@ -1253,6 +1253,7 @@ export interface SkuDirectCostRow {
|
||||
code: string;
|
||||
title: string | null;
|
||||
customer_code: string;
|
||||
customer_name?: string | null;
|
||||
sale_price: number;
|
||||
}>;
|
||||
/** 只读:按客户去重的价格目标(报价单优先,其次客户商品库) */
|
||||
@@ -1303,10 +1304,12 @@ export async function getSkuDirectCosts(
|
||||
const customer = customerCode ? String(customerCode).trim() : null;
|
||||
const branch = ctx?.branchCode ? String(ctx.branchCode).trim() : null;
|
||||
const quoteRows = await pool.query(
|
||||
`SELECT qs.quote_sheet_code AS code, qs.title, qsc.customer_code, qsi.sku_code,
|
||||
`SELECT qs.quote_sheet_code AS code, qs.title, qsc.customer_code,
|
||||
c.company_name AS customer_name, qsi.sku_code,
|
||||
COALESCE(NULLIF(qsi.sale_price, 0), qsi.price)::float AS sale_price
|
||||
FROM customer_quote_sheets qs
|
||||
JOIN customer_quote_sheet_customers qsc ON qsc.quote_sheet_code = qs.quote_sheet_code
|
||||
LEFT JOIN customers c ON c.customer_code = qsc.customer_code
|
||||
JOIN customer_quote_sheet_items qsi ON qsi.quote_sheet_code = qs.quote_sheet_code
|
||||
WHERE qs.status = 1 AND qs.approval_status = 30
|
||||
AND (qs.expires_at IS NULL OR qs.expires_at > NOW())
|
||||
@@ -1341,6 +1344,7 @@ export async function getSkuDirectCosts(
|
||||
code: String(q.code || ''),
|
||||
title: q.title ? String(q.title) : null,
|
||||
customer_code: customerCodeValue,
|
||||
customer_name: q.customer_name ? String(q.customer_name) : null,
|
||||
sale_price: price,
|
||||
};
|
||||
const options = optionsBySku.get(sku) || [];
|
||||
@@ -1353,6 +1357,7 @@ export async function getSkuDirectCosts(
|
||||
customer_code: customerCodeValue,
|
||||
quote_sheet_code: String(q.code || ''),
|
||||
title: q.title ? String(q.title) : null,
|
||||
customer_name: q.customer_name ? String(q.customer_name) : null,
|
||||
sale_price: price,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('成本排行只读报价单展示', () => {
|
||||
expect(types).toContain('sale_price_targets');
|
||||
expect(page).toContain('quoteMin');
|
||||
expect(page).toContain('quoteMax');
|
||||
expect(page).toContain("t('finance.cost.rank.sourceQuoteLabel'");
|
||||
expect(page).toContain("'finance.cost.rank.sourceQuoteLabel'");
|
||||
expect(page).toContain("target.closest('input, button, a, label')");
|
||||
expect(page).toContain("setExpandedSkuCode((cur) => (cur === sku.sku_code ? null : sku.sku_code))");
|
||||
expect(page).not.toContain("t('finance.cost.rank.grossAmt')\n }`}");
|
||||
|
||||
@@ -152,6 +152,7 @@ export const finance: MessageDict = {
|
||||
'cost.rank.sourceQuote': 'Quote sale price {price}',
|
||||
'cost.rank.quoteSheets': 'Quote sheets',
|
||||
'cost.rank.sourceCustomerSkuLabel': 'Product library',
|
||||
'cost.rank.currentSalePrice': 'Current price: ¥{amount}',
|
||||
'cost.rank.priceTargets': 'Price targets',
|
||||
'cost.rank.editSalePrice': 'Edit sale price',
|
||||
'cost.rank.invalidSalePrice': 'Invalid sale price',
|
||||
|
||||
@@ -152,6 +152,7 @@ export const finance: MessageDict = {
|
||||
'cost.rank.sourceQuote': 'Harga jual penawaran {price}',
|
||||
'cost.rank.quoteSheets': 'Lembar penawaran',
|
||||
'cost.rank.sourceCustomerSkuLabel': 'Katalog produk',
|
||||
'cost.rank.currentSalePrice': 'Harga saat ini: ¥{amount}',
|
||||
'cost.rank.priceTargets': 'Target harga',
|
||||
'cost.rank.editSalePrice': 'Ubah harga jual',
|
||||
'cost.rank.invalidSalePrice': 'Harga jual tidak valid',
|
||||
|
||||
@@ -152,6 +152,7 @@ export const finance: MessageDict = {
|
||||
'cost.rank.sourceQuote': '报价单 销售价 {price}',
|
||||
'cost.rank.quoteSheets': '报价单',
|
||||
'cost.rank.sourceCustomerSkuLabel': '商品库',
|
||||
'cost.rank.currentSalePrice': '当前销售价:¥{amount}',
|
||||
'cost.rank.priceTargets': '价格目标',
|
||||
'cost.rank.editSalePrice': '修改销售价',
|
||||
'cost.rank.invalidSalePrice': '销售价无效',
|
||||
|
||||
@@ -2936,94 +2936,104 @@ export const CostAccountingPanel: React.FC<CostAccountingPanelProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
{rowExpanded ? (
|
||||
<div className="mt-3 ml-9 grid grid-cols-2 sm:grid-cols-3 gap-2 text-xs border-t pt-3">
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.skuCode')}</p>
|
||||
<p className="app-foreground font-medium break-all">{sku.sku_code}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.category')}</p>
|
||||
<p className="app-foreground font-medium">{sku.category_name || '-'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.quantity')}</p>
|
||||
<p className="app-foreground font-medium">{sku.quantity.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.revenue')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.sales_amount.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.purchaseCost')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.purchase_cost.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.loss')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.loss_cost.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.directTotal')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.total_cost.toLocaleString()}</p>
|
||||
</div>
|
||||
<div className="mt-2 ml-9 border-t border-dashed pt-2 text-xs">
|
||||
{(sku.sale_price_targets?.length ?? 0) > 0 ? (
|
||||
<div className="col-span-2 sm:col-span-3">
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.priceTargets')}</p>
|
||||
<div className="mt-1 space-y-1">
|
||||
{sku.sale_price_targets!.map((target) => {
|
||||
const key = `${sku.sku_code}:${target.customer_code}`;
|
||||
return (
|
||||
<div key={`${key}:${target.target_type}`} className="flex items-center gap-2">
|
||||
<span className="app-foreground min-w-0 flex-1 truncate">
|
||||
{target.customer_name || target.customer_code}
|
||||
{target.target_type === 'quote_sheet'
|
||||
? ` · ${target.title || target.quote_sheet_code || t('finance.cost.rank.sourceQuoteLabel')}`
|
||||
: ` · ${t('finance.cost.rank.sourceCustomerSkuLabel')}`}
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
defaultValue={Number(target.sale_price).toFixed(2)}
|
||||
disabled={skuPriceSavingKey === key}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') e.currentTarget.blur();
|
||||
}}
|
||||
onBlur={(e) => {
|
||||
const input = e.currentTarget;
|
||||
const old = Number(target.sale_price);
|
||||
const next = Number(input.value);
|
||||
if (input.value.trim() === '' || next === old) {
|
||||
input.value = old.toFixed(2);
|
||||
return;
|
||||
}
|
||||
void saveSkuPrice(
|
||||
target.customer_code,
|
||||
sku.sku_code,
|
||||
input.value,
|
||||
target.target_type,
|
||||
target.quote_sheet_code
|
||||
).then((ok) => {
|
||||
if (!ok) input.value = old.toFixed(2);
|
||||
});
|
||||
}}
|
||||
className="w-24 px-1 py-0.5 text-xs border rounded"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<div className="space-y-1.5">
|
||||
{sku.sale_price_targets!.map((target) => {
|
||||
const key = `${sku.sku_code}:${target.customer_code}`;
|
||||
return (
|
||||
<div
|
||||
key={`${key}:${target.target_type}`}
|
||||
className="flex items-center gap-2 rounded border border-gray-200 px-2 py-1.5"
|
||||
>
|
||||
<span className="app-foreground-muted text-[10px] leading-none shrink-0">
|
||||
{t(
|
||||
target.target_type === 'quote_sheet'
|
||||
? 'finance.cost.rank.sourceQuoteLabel'
|
||||
: 'finance.cost.rank.sourceCustomerSkuLabel'
|
||||
)}
|
||||
</span>
|
||||
<span className="app-foreground min-w-0 flex-1 truncate">
|
||||
{target.target_type === 'quote_sheet'
|
||||
? `${target.title || target.quote_sheet_code || ''}${
|
||||
target.customer_name ? `(${target.customer_name})` : ''
|
||||
}`
|
||||
: target.customer_name || target.customer_code}
|
||||
</span>
|
||||
<span className="app-foreground-muted shrink-0">
|
||||
{t('finance.cost.rank.currentSalePrice', {
|
||||
amount: Number(target.sale_price).toFixed(2),
|
||||
})}
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
defaultValue={Number(target.sale_price).toFixed(2)}
|
||||
disabled={skuPriceSavingKey === key}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') e.currentTarget.blur();
|
||||
}}
|
||||
onBlur={(e) => {
|
||||
const input = e.currentTarget;
|
||||
const old = Number(target.sale_price);
|
||||
const next = Number(input.value);
|
||||
if (input.value.trim() === '' || next === old) {
|
||||
input.value = old.toFixed(2);
|
||||
return;
|
||||
}
|
||||
void saveSkuPrice(
|
||||
target.customer_code,
|
||||
sku.sku_code,
|
||||
input.value,
|
||||
target.target_type,
|
||||
target.quote_sheet_code
|
||||
).then((ok) => {
|
||||
if (!ok) input.value = old.toFixed(2);
|
||||
});
|
||||
}}
|
||||
className="w-20 shrink-0 px-1 py-0.5 text-xs border rounded"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 gap-2">
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.skuCode')}</p>
|
||||
<p className="app-foreground font-medium break-all">{sku.sku_code}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.category')}</p>
|
||||
<p className="app-foreground font-medium">{sku.category_name || '-'}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.quantity')}</p>
|
||||
<p className="app-foreground font-medium">{sku.quantity.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.revenue')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.sales_amount.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.col.purchaseCost')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.purchase_cost.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.loss')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.loss_cost.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.directTotal')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.total_cost.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.grossAmt')}</p>
|
||||
<p className="app-foreground font-medium">¥{sku.gross_profit.toLocaleString()}</p>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<div>
|
||||
<p className="app-foreground-muted">{t('finance.cost.rank.grossAmt')}</p>
|
||||
<p
|
||||
className={`font-medium ${
|
||||
sku.gross_profit < 0 ? 'text-red-600' : 'text-emerald-700'
|
||||
}`}
|
||||
>
|
||||
¥{sku.gross_profit.toLocaleString()}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -134,6 +134,7 @@ export interface SkuCostDetail {
|
||||
code: string;
|
||||
title: string | null;
|
||||
customer_code: string;
|
||||
customer_name?: string | null;
|
||||
sale_price: number;
|
||||
}>;
|
||||
sale_price_targets?: Array<{
|
||||
|
||||
Reference in New Issue
Block a user