第3项:旧界面与 React 共用对账、回收及基础业务规则
This commit is contained in:
1 parent
54c05879d5
commit
389952f31c
65 files changed
+2265
-3800
No files matched your search
@@ -20,72 +20,11 @@ function invalidateRecoveryChangeViews() {
|
||||
recoveryReviewEntry = null;
|
||||
$('#recovery-change-dialog')?.close();
|
||||
}
|
||||
function recoveryInputShape(input) {
|
||||
return (
|
||||
input &&
|
||||
Object.hasOwn(recoveryModeNames, input.mode) &&
|
||||
validOrderDate(input.date) &&
|
||||
typeof input.customer === 'string' &&
|
||||
typeof input.salesperson === 'string' &&
|
||||
teamMemberKeys().includes(input.member) &&
|
||||
Array.isArray(input.old_lines) &&
|
||||
input.old_lines.length > 0 &&
|
||||
input.old_lines.every(
|
||||
row => row && ['name', 'incoming_weight', 'melted_weight', 'purity'].every(key => typeof row[key] === 'string'),
|
||||
) &&
|
||||
(input.mode === 'direct' ||
|
||||
(input.exchange && Array.isArray(input.exchange.charges) && Array.isArray(input.exchange.fee_items)))
|
||||
);
|
||||
}
|
||||
function validateRecoveryEditDetail(data, id) {
|
||||
if (
|
||||
!data ||
|
||||
data.id !== id ||
|
||||
data.record?.id !== id ||
|
||||
!Number.isSafeInteger(data.revision) ||
|
||||
data.revision < 1 ||
|
||||
!['active', 'cancelled'].includes(data.status) ||
|
||||
!recoveryInputShape(data.inputs) ||
|
||||
!data.permissions ||
|
||||
!['canEdit', 'canCancel', 'canDirect', 'requiresApproval'].every(
|
||||
key => typeof data.permissions[key] === 'boolean',
|
||||
) ||
|
||||
!Array.isArray(data.blockedUsages) ||
|
||||
!Array.isArray(data.history) ||
|
||||
(state.user.role !== 'owner' && data.inputs.member !== currentMember())
|
||||
)
|
||||
throw new Error('回收更正资料未完整返回或不属于当前成员,请重新读取。');
|
||||
if (data.record.member !== data.inputs.member || data.record.mode !== data.inputs.mode)
|
||||
throw new Error('回收记录身份与修改资料不一致。');
|
||||
if (data.pending && validateRecoveryChangeRequest(data.pending).recoveryId !== id)
|
||||
throw new Error('回收申请不属于当前记录。');
|
||||
if (data.history.some(row => validateRecoveryChangeRequest(row).recoveryId !== id))
|
||||
throw new Error('回收更正历史不属于当前记录。');
|
||||
return data;
|
||||
return recoveryPageRules.checkEdit(data, id);
|
||||
}
|
||||
function validateRecoveryChangeRequest(request) {
|
||||
if (
|
||||
!request ||
|
||||
typeof request.id !== 'string' ||
|
||||
!request.id ||
|
||||
typeof request.recoveryId !== 'string' ||
|
||||
!Number.isSafeInteger(request.revision) ||
|
||||
request.revision < 1 ||
|
||||
!Number.isSafeInteger(request.recoveryRevision) ||
|
||||
request.recoveryRevision < 1 ||
|
||||
!['update', 'cancel'].includes(request.action) ||
|
||||
!['pending', 'approved', 'rejected'].includes(request.status) ||
|
||||
!recoveryInputShape(request.before) ||
|
||||
(request.action === 'update' && !recoveryInputShape(request.after)) ||
|
||||
(request.action === 'cancel' && request.after !== null) ||
|
||||
typeof request.canApprove !== 'boolean' ||
|
||||
!request.summary ||
|
||||
request.member !== request.before.member ||
|
||||
(request.after && (request.after.member !== request.member || request.after.mode !== request.before.mode)) ||
|
||||
(state.user.role !== 'owner' && request.member !== currentMember())
|
||||
)
|
||||
throw new Error('回收更正申请未完整返回或不属于当前成员,请重新读取。');
|
||||
return request;
|
||||
return recoveryPageRules.checkRequest(request);
|
||||
}
|
||||
function recoveryDetailChangeActionsHTML(value) {
|
||||
const info = recoveryDetailEdit;
|
||||
@@ -114,93 +53,7 @@ function recoveryEditPanelHTML(data) {
|
||||
return `${data.status === 'cancelled' ? '<div class="note">本单已取消,原记录和更正历史保留。</div>' : ''}${data.permissions.reason ? `<p class="small muted">${e(data.permissions.reason)}</p>` : ''}${recoveryMaterialBatchHTML(data.record.materialBatch)}${recoveryBlockedHTML(data.blockedUsages)}${data.permissions.canCancel && data.blockedUsages.length ? recoveryCancellationMaterialHTML() : ''}${data.pending ? `<section class="panel recovery-change-pending"><h3>待店主复核</h3><p class="small muted">原记录仍生效,申请尚未记账。</p>${recoveryChangeComparisonHTML(data.pending)}${button(state.user.role === 'owner' ? '查看并复核' : '查看申请', 'recovery-change-open', '', `data-id="${e(data.pending.id)}"`)}</section>` : ''}${data.history.length ? `<details><summary>更正与取消记录(${data.history.length})</summary><ul class="timeline">${data.history.map(row => `<li>${e(recoveryChangeStatus(row))} · ${e(row.requesterName || '未提供')}${row.reviewerName ? ' · ' + e(row.reviewerName) + '复核' : ''}${row.note ? '<p>' + e(row.note) + '</p>' : ''}${button('查看前后内容', 'recovery-change-open', 'quiet', `data-id="${e(row.id)}"`)}</li>`).join('')}</ul></details>` : ''}`;
|
||||
}
|
||||
function recoveryEditDraft(input) {
|
||||
if (input.exchange?.items) {
|
||||
const rows = input.exchange.items.map(row => recoveryEditDraft({ ...input, ...row, exchange: row.exchange })),
|
||||
first = rows[0],
|
||||
x = input.exchange;
|
||||
return {
|
||||
...first,
|
||||
independent_products: rows.length > 1,
|
||||
extra_products: rows.slice(1),
|
||||
charges: x.charges,
|
||||
charge_name: x.charges[0]?.name || '其他收费',
|
||||
charge_amount: x.charges[0]?.amount || '0',
|
||||
fee_items: x.fee_items,
|
||||
fee_note: x.fee_items[0]?.note || '其他费用',
|
||||
fee_amount: x.fee_items[0]?.amount || '0',
|
||||
fee_payer: x.fee_items[0]?.payer || input.member,
|
||||
discount: x.discount,
|
||||
rounding_mode: x.rounding_mode,
|
||||
};
|
||||
}
|
||||
const first = input.old_lines[0],
|
||||
x = input.exchange || {},
|
||||
charge = x.charges?.[0],
|
||||
fee = x.fee_items?.[0],
|
||||
account = input.payment_account || '',
|
||||
identity = accountIdentity(account),
|
||||
recipient = identity ? memberAccountPrefix(identity.member) : recoveryPrefix(input.member),
|
||||
method = identity?.channel || '微信';
|
||||
return {
|
||||
...recoveryDefaults(input.mode),
|
||||
mode: input.mode,
|
||||
surplus_mode: input.surplus_mode || 'buy',
|
||||
surplus_memo: input.surplus_memo || '',
|
||||
old_source: input.old_source || 'incoming',
|
||||
deposit_id: input.deposit_id || '',
|
||||
deposit_weight: input.deposit_weight || '',
|
||||
date: input.date,
|
||||
customer: input.customer,
|
||||
salesperson: input.salesperson,
|
||||
member: input.member,
|
||||
note: input.note || '',
|
||||
old_pocket: input.old_pocket ?? '回收旧料',
|
||||
old_stock_count: input.old_stock_count ?? '',
|
||||
old_name: first.name,
|
||||
incoming_weight: first.incoming_weight,
|
||||
melted_weight: first.melted_weight,
|
||||
purity: first.purity,
|
||||
old_lines: JSON.parse(JSON.stringify(input.old_lines)),
|
||||
buy_rate: input.buy_rate,
|
||||
buy_total: input.buy_total ?? '',
|
||||
buy_total_manual: Object.hasOwn(input, 'buy_total'),
|
||||
melted_manual: true,
|
||||
depreciation_manual: Object.hasOwn(x, 'depreciation_weight'),
|
||||
payer: input.payer,
|
||||
payment_method: method,
|
||||
payment_recipient: recipient,
|
||||
payout_method: method === '信用卡' ? '微信' : method,
|
||||
new_name: x.name || '足金999',
|
||||
new_quantity: x.quantity || '',
|
||||
pocket: x.pocket ?? state.pockets[0] ?? '',
|
||||
stockCount: x.stockCount ?? '',
|
||||
gold_price: x.gold_price || '0',
|
||||
labor_mode: x.labor_mode || 'gram',
|
||||
labor_rate: x.labor_rate || '0',
|
||||
depreciation_weight: x.depreciation_weight ?? '',
|
||||
depreciation_rate: x.depreciation_rate || '0',
|
||||
charge_name: charge?.name || '其他收费',
|
||||
charge_amount: charge?.amount || '0',
|
||||
charges: JSON.parse(JSON.stringify(x.charges || [])),
|
||||
discount: x.discount || '0',
|
||||
rounding_mode: x.rounding_mode || 'cent',
|
||||
material_source: x.cost_material?.mode === 'pool' ? 'pool' : 'manual',
|
||||
material_pool_id: x.cost_material?.poolId || input.date,
|
||||
material_rate: x.cost_material?.rate || '',
|
||||
material_payer: x.cost_material_payer || input.member,
|
||||
cost_labor_mode: x.cost_labor?.mode || 'total',
|
||||
cost_labor_value: x.cost_labor?.mode === 'gram' ? x.cost_labor.rate : (x.cost_labor?.amount ?? ''),
|
||||
cost_payer: x.cost_payer || input.member,
|
||||
labor_payer: x.cost_labor_payer || x.cost_payer || input.member,
|
||||
fee_note: fee?.note || '其他费用',
|
||||
fee_amount: fee?.amount || '0',
|
||||
fee_payer: fee?.payer || input.member,
|
||||
fee_items: JSON.parse(JSON.stringify(x.fee_items || [])),
|
||||
...(x.products
|
||||
? { ...recoveryProductDraft(x.products[0]), extra_products: x.products.slice(1).map(recoveryProductDraft) }
|
||||
: {}),
|
||||
verified: false,
|
||||
};
|
||||
return recoveryPageRules.forEdit(input);
|
||||
}
|
||||
function recoveryEditFormDraft(form, flat) {
|
||||
const entry = recoveryEditEntry;
|
||||
|
||||
Reference in new issue
Block a user