Files
weiguang-jewelry-ledger/新账系统/web/src/pages/Recoveries/Comparison.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

236 lines
10 KiB
TypeScript
Raw Normal View History

import type { LedgerState } from '../../shared';
import type { ChangeRequest, Input, Exchange, Labor, Material, MoneySummary } from './types';
type Cell = string | number | null | undefined;
import { Model } from '../../shared';
import { yuan } from '../../lib/format';
import { count as stockCountText } from '../Inventory/data';
import { rowLabel } from './controls';
export function Comparison({ request, state }: { request: ChangeRequest; state: LedgerState }) {
const before = request.before,
after = request.after,
rows: [string, Cell, Cell][] = [],
pair = (title: string, a: Cell, b: Cell): [string, Cell, Cell] => [title, a, b];
const teamMemberName = (k?: string) => Model.memberName(state, k ?? ''),
pocketLabel = (k?: string) => rowLabel(state, k),
accountDisplayName = (v: string) =>
String(v || '')
.replace(/^助理2/, Model.memberName(state, 'assistant2'))
.replace(/^助理1?/, Model.memberName(state, 'assistant'))
.replace(/^麦麦/, Model.memberName(state, 'owner'));
const old = (input: Input) =>
input?.old_lines
.map(row => `${row.name}:来料 ${row.incoming_weight}g,熔后 ${row.melted_weight}g,成色 ${row.purity}%`)
.join('\n'),
fees = (input: Input) =>
input?.exchange?.fee_items
.map(row => `${row.note}:${row.amount}元 · ${teamMemberName(row.payer)}付款`)
.join('\n') || '无',
charges = (input: Input) => input?.exchange?.charges.map(row => `${row.name}:${row.amount}元`).join('\n') || '无';
const x: Partial<Exchange> = before.exchange || {},
y: Partial<Exchange> = after?.exchange || {},
material = (value?: Material) =>
value?.mode === 'pool' ? '料池 ' + value.poolId : value ? '手填 ' + value.rate + '元/克' : '无补金差重',
labor = (value?: Labor) =>
value ? (value.mode === 'gram' ? value.rate + '元/克' : value.amount + '元总工费') : '未提供';
rows.push(
pair('业务日期', before.date, after?.date || '取消原记录'),
pair('客户', before.customer, after?.customer),
pair('开单人', before.salesperson, after?.salesperson),
pair('归属', teamMemberName(before.member), after ? teamMemberName(after.member) : '沿用原身份留档'),
pair('旧料逐项称重', old(before), after ? old(after) : '冲正原库存及关联购料'),
pair(
'旧料入库货盘',
pocketLabel(before.old_pocket ?? '回收旧料'),
after ? pocketLabel(after.old_pocket ?? '回收旧料') : '冲回原入库货盘',
),
pair(
'旧料入库数量(对)',
stockCountText(before.old_stock_count == null ? null : Number(before.old_stock_count)),
after ? stockCountText(after.old_stock_count == null ? null : Number(after.old_stock_count)) : '冲回原入库数量',
),
pair('回收单价(元/克)', before.buy_rate, after?.buy_rate),
pair('回收结算额(元)', before.buy_total, after?.buy_total),
pair(
'实际收付款账户',
accountDisplayName(before.payment_account),
after ? accountDisplayName(after.payment_account) : '冲正原收付记录',
),
pair('付款人', teamMemberName(before.payer), after ? teamMemberName(after.payer) : '原付款流水保留'),
pair('备注', before.note, after?.note),
);
if (before.surplus_mode === 'deposit' || after?.surplus_mode === 'deposit')
rows.push(
pair(
'余料处理',
before.surplus_mode === 'deposit' ? '寄存,暂不结算' : '按回收价结算',
after ? (after.surplus_mode === 'deposit' ? '寄存,暂不结算' : '按回收价结算') : '撤回本单寄存余料',
),
);
if (before.old_source === 'deposit' || after?.old_source === 'deposit')
rows.push(
pair(
'使用客户寄存料',
before.old_source === 'deposit' ? before.deposit_id + ' · ' + before.deposit_weight + 'g' : '本次交来旧料',
after?.old_source === 'deposit'
? after.deposit_id + ' · ' + after.deposit_weight + 'g'
: after
? '本次交来旧料'
: '退回寄存账户',
),
);
if (before.exchange?.items || after?.exchange?.items) {
const items = (v: Input) =>
(v?.exchange?.items || [])
.map(
(p, i) =>
i +
1 +
' · ' +
p.exchange.name +
(p.old_source === 'deposit' ? ' · 寄存记录 ' + p.deposit_id + ' 使用 ' + p.deposit_weight + 'g' : '') +
(p.surplus_mode === 'deposit' ? ' · 余料寄存,暂不结算' : '') +
' · 旧料 ' +
p.old_lines.map(r => r.melted_weight + 'g × ' + r.purity + '%').join('+') +
' 入' +
pocketLabel(p.old_pocket) +
' · 新货 ' +
p.exchange.quantity +
'g ' +
(pocketLabel(p.exchange.pocket) || '外配') +
' · 补金 ' +
p.exchange.gold_price +
'元/g · 折旧 ' +
p.exchange.depreciation_weight +
'g × ' +
p.exchange.depreciation_rate +
'元/g · 回收 ' +
p.buy_rate +
'元/g,' +
p.buy_total +
'元 · 料费 ' +
JSON.stringify(p.exchange.cost_material) +
' · 料费付款 ' +
teamMemberName(p.exchange.cost_material_payer) +
' · 进货工费 ' +
JSON.stringify(p.exchange.cost_labor) +
',' +
teamMemberName(p.exchange.cost_labor_payer),
)
.join(';');
rows.push(pair('逐件置换完整资料', items(before), after ? items(after) : '全部冲回'));
}
if (before.exchange?.products || after?.exchange?.products) {
const items = (x?: Exchange) =>
(x?.products ?? (x ? [x] : []))
.map(
(p, i) =>
i +
1 +
' · ' +
p.name +
' · ' +
p.quantity +
'g · ' +
(pocketLabel(p.pocket) || '外配') +
' · 销售工费 ' +
p.labor_rate +
(p.labor_mode === 'total' ? '元' : '元/克') +
' · 进货工费 ' +
(p.cost_labor?.rate ?? p.cost_labor?.amount ?? '待补') +
' · ' +
teamMemberName(p.cost_labor_payer) +
(p.stockCount == null ? '' : ' · ' + p.stockCount + '对'),
)
.join(';');
rows.push(pair('逐件置换商品', items(before.exchange), after ? items(after.exchange) : '冲回全部新货出库'));
}
if (before.mode === 'exchange')
rows.push(
pair('置换新货', x.name, y.name),
pair('新货克重(g)', x.quantity, y.quantity),
pair('实际货盘', pocketLabel(x.pocket) || '外配', after ? pocketLabel(y.pocket) || '外配' : '冲回原出库货盘'),
pair(
'出库数量(对)',
stockCountText(x.stockCount == null ? null : Number(x.stockCount)),
stockCountText(y.stockCount == null ? null : Number(y.stockCount)),
),
pair('销售金价(元/克)', x.gold_price, y.gold_price),
pair(
'销售工费',
x.labor_rate + '元/' + (x.labor_mode === 'gram' ? '克' : '总额'),
after ? y.labor_rate + '元/' + (y.labor_mode === 'gram' ? '克' : '总额') : '取消',
),
pair(
'折旧计费克重/单价',
x.depreciation_weight + 'g × ' + x.depreciation_rate + '元/克',
after ? y.depreciation_weight + 'g × ' + y.depreciation_rate + '元/克' : '取消',
),
pair('附加收费', charges(before), after ? charges(after) : '取消'),
pair('优惠(元)', x.discount, y.discount),
pair(
'取整方式',
x.rounding_mode === 'yuan' ? '四舍五入到元' : '保留到分',
after ? (y.rounding_mode === 'yuan' ? '四舍五入到元' : '保留到分') : '取消',
),
pair('补金差重进货来源', material(x.cost_material), after ? material(y.cost_material) : '释放原耗用'),
pair(
'料费付款人',
teamMemberName(x.cost_material_payer),
after ? teamMemberName(y.cost_material_payer) : '原来源留档',
),
pair('进货工费', labor(x.cost_labor), after ? labor(y.cost_labor) : '取消'),
pair('工费付款人', teamMemberName(x.cost_labor_payer), after ? teamMemberName(y.cost_labor_payer) : '原来源留档'),
pair('实际费用', fees(before), after ? fees(after) : '冲正原费用'),
);
const a: MoneySummary = request.summary.before || {},
b: MoneySummary = request.summary.after || {};
rows.push(
...(
[
['实际收客户', 'cashReceipt'],
['实际付客户', 'cashPayment'],
['购料成本', 'purchaseAmount'],
['订单货品成本', 'goodsCost'],
['实际费用', 'directCost'],
['原账利润', 'profit'],
] as const
).map(([title, key]) =>
pair(
title,
a[key] == null ? '待核实' : '¥' + yuan(a[key]),
after ? (b[key] == null ? '待核实' : '¥' + yuan(b[key])) : '取消后冲正',
),
),
);
return (
<>
{request.summary.legacyCountNotice && (
<p>
{request.summary.legacyCountNotice}
{request.summary.legacyCountVerified && '(申请人已确认)'}
</p>
)}
<div className="table-wrap">
<table aria-label="回收更正原值与申请值">
<thead>
<tr>
<th>核对项目</th>
<th>原值</th>
<th>{request.action === 'cancel' ? '取消后' : '申请值'}</th>
</tr>
</thead>
<tbody>
{rows.map(([t, a, b]) => (
<tr key={t} className={String(a ?? '') !== String(b ?? '') ? 'modified' : undefined}>
<th scope="row">{t}</th>
<td>{a == null || a === '' ? '未提供' : a}</td>
<td>{b == null || b === '' ? '未提供' : b}</td>
</tr>
))}
</tbody>
</table>
</div>
</>
);
}