将账本业务页面、表单与审批迁移到 React,并加入旧版对照验收
This commit is contained in:
1 parent
f1a4e69f0d
commit
00dd683116
107 files changed
+31755
-191
No files matched your search
@@ -0,0 +1,845 @@
|
||||
import { Children } from 'react';
|
||||
import { Calc as LedgerCalc } from '../../../shared';
|
||||
export function afterSales(
|
||||
{ afterSaleChangesStatus, state, ui, orderAfterSaleFormEntry, currentOrder },
|
||||
{
|
||||
button,
|
||||
validOrderDate,
|
||||
teamMemberKeys,
|
||||
field,
|
||||
moneyField,
|
||||
opts,
|
||||
teamMemberOptions,
|
||||
currentMember,
|
||||
teamMode,
|
||||
choice,
|
||||
teamMemberName,
|
||||
yuan,
|
||||
activePaymentAccounts,
|
||||
normalizePaymentAccount,
|
||||
accountIdentity,
|
||||
orderAfterSaleSummaryHTML,
|
||||
orderActionCanDirect,
|
||||
grams,
|
||||
stockCountText,
|
||||
pocketCountsEnabled,
|
||||
pocketLabel,
|
||||
stockCountField,
|
||||
activePocketKeys,
|
||||
orderChangeUser,
|
||||
stockCountValue,
|
||||
},
|
||||
) {
|
||||
function validateAfterSaleDetail(detail, id) {
|
||||
const record = detail?.record,
|
||||
permissions = detail?.permissions;
|
||||
if (
|
||||
!record ||
|
||||
detail.id !== id ||
|
||||
record.id !== id ||
|
||||
!Number.isSafeInteger(detail.revision) ||
|
||||
detail.revision < 1 ||
|
||||
record.revision !== detail.revision ||
|
||||
!afterSaleValuesValid(record) ||
|
||||
!teamMemberKeys().includes(record.member) ||
|
||||
typeof permissions?.canEdit !== 'boolean' ||
|
||||
typeof permissions.canDirectEdit !== 'boolean' ||
|
||||
typeof permissions.requiresApproval !== 'boolean' ||
|
||||
!Array.isArray(detail.history)
|
||||
)
|
||||
throw new Error('售后记录资料未完整返回,请重新读取后再修改。');
|
||||
if (detail.pending && (validateAfterSaleRequest(detail.pending).afterSaleId !== id || permissions.canEdit))
|
||||
throw new Error('售后修改状态不一致,请重新读取。');
|
||||
for (const request of detail.history)
|
||||
if (validateAfterSaleRequest(request).afterSaleId !== id) throw new Error('售后修改历史不一致,请重新读取。');
|
||||
return detail;
|
||||
}
|
||||
function independentReviewForm(kind, request) {
|
||||
return (
|
||||
<form id="after-sale-review-form" data-id={request.id} data-kind={kind}>
|
||||
<h3>{kind === 'approve' ? '同意售后修改' : '驳回售后修改'}</h3>
|
||||
<label>
|
||||
{kind === 'approve' ? '复核备注(选填)' : '驳回意见'}
|
||||
<textarea disabled={ui.blocked} name="note" rows="2" maxLength="200" required={kind === 'reject'}></textarea>
|
||||
</label>
|
||||
{kind === 'approve' ? (
|
||||
<label className="check">
|
||||
<input disabled={ui.blocked} type="checkbox" name="verified" required />
|
||||
已核对原值、申请值、日期、金额和付款人。
|
||||
</label>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
<div className="form-actions">
|
||||
{button('取消', 'after-sale-review-cancel', 'quiet', { disabled: ui.busy })}
|
||||
<button type="submit" disabled={ui.blocked} className={kind === 'approve' ? 'primary' : ''}>
|
||||
{kind === 'approve' ? '确认同意修改' : '确认驳回申请'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
function independentReview(request, kind) {
|
||||
const canReview = state.user.role === 'owner' && request.status === 'pending';
|
||||
return (
|
||||
<>
|
||||
<button className="dialog-close" data-action="after-sale-changes-close" aria-label="关闭售后修改复核">
|
||||
×
|
||||
</button>
|
||||
<h2 id="after-sale-changes-title">售后修改{request.status === 'pending' ? '复核' : '记录'}</h2>
|
||||
<div className="actions">{button('返回申请列表', 'after-sale-changes-reload', 'quiet')}</div>
|
||||
<p>
|
||||
{afterSaleStatus(request)} · {request.requesterName || '申请人未提供'} · {afterSaleTime(request.created)}
|
||||
</p>
|
||||
<p className="small muted">
|
||||
订单归属:{teamMemberName(request.member)}。
|
||||
{request.status === 'pending' ? '本次申请尚未生效;店主同意后才更新原售后。' : ''}
|
||||
</p>
|
||||
{request.reason ? <p className="change-reason">修改说明:{request.reason}</p> : ''}
|
||||
{afterSaleComparisonHTML(request)}
|
||||
{request.stale ? (
|
||||
<div className="error">
|
||||
{request.staleReason || '原记录已有变动,不能同意这份旧申请。请驳回后按最新记录重新申请。'}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
{request.status !== 'pending' ? (
|
||||
<>
|
||||
<p className="small muted">
|
||||
复核人:{request.reviewerName || '未提供'} · {afterSaleTime(request.reviewed)}
|
||||
</p>
|
||||
{request.note ? (
|
||||
<p className="change-reason">
|
||||
{request.status === 'rejected' ? '驳回意见' : '复核备注'}:{request.note}
|
||||
</p>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
<div id="after-sale-review-actions">
|
||||
{kind ? (
|
||||
independentReviewForm(kind, request)
|
||||
) : canReview ? (
|
||||
<div className="actions">
|
||||
{request.canApprove && !request.stale
|
||||
? button('同意修改', 'after-sale-review-decision', 'primary', {
|
||||
'data-kind': 'approve',
|
||||
})
|
||||
: ''}
|
||||
{button('驳回申请', 'after-sale-review-decision', '', {
|
||||
'data-kind': 'reject',
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</div>
|
||||
<div id="after-sale-review-error" aria-live="polite">
|
||||
{ui.feedback}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
function afterSaleHistoryHTML(request) {
|
||||
return (
|
||||
<li>
|
||||
<strong>{afterSaleStatus(request)}</strong>
|
||||
<small>
|
||||
{request.requesterName || '申请人未提供'} · {afterSaleTime(request.created)}
|
||||
</small>
|
||||
{request.reason ? <p className="change-reason">修改说明:{request.reason}</p> : ''}
|
||||
{request.status !== 'pending' ? (
|
||||
<>
|
||||
<small>
|
||||
复核人:{request.reviewerName || '未提供'} · {afterSaleTime(request.reviewed)}
|
||||
</small>
|
||||
{request.note ? (
|
||||
<p className="change-reason">
|
||||
{request.status === 'rejected' ? '驳回意见' : '复核备注'}:{request.note}
|
||||
</p>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
<details>
|
||||
<summary>查看原值与申请值</summary>
|
||||
{afterSaleComparisonHTML(request)}
|
||||
</details>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
function afterSaleRecordHTML(record) {
|
||||
return (
|
||||
<dl className="after-sale-facts">
|
||||
{Children.toArray(
|
||||
[
|
||||
['售后日期', record.date],
|
||||
['售后项目', record.project],
|
||||
['客户', record.customer],
|
||||
['金额', '¥' + yuan(record.amount)],
|
||||
['谁支付', teamMemberName(record.payer)],
|
||||
['订单归属', teamMemberName(record.member)],
|
||||
].map(([title, value]) => (
|
||||
<div>
|
||||
<dt>{title}</dt>
|
||||
<dd>{value}</dd>
|
||||
</div>
|
||||
)),
|
||||
)}
|
||||
</dl>
|
||||
);
|
||||
}
|
||||
function afterSaleComparisonHTML(raw) {
|
||||
const request = validateAfterSaleRequest(raw),
|
||||
pair = (title, key, format = value => value) => {
|
||||
const changed = request.before[key] !== request.after[key];
|
||||
return (
|
||||
<tr
|
||||
{...(changed
|
||||
? {
|
||||
className: 'order-change-modified',
|
||||
}
|
||||
: {})}
|
||||
>
|
||||
<th scope="row">
|
||||
{title}
|
||||
{changed ? <span className="change-mark">已修改</span> : ''}
|
||||
</th>
|
||||
<td>{format(request.before[key])}</td>
|
||||
<td>{format(request.after[key])}</td>
|
||||
</tr>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<div className="table-wrap after-sale-comparison">
|
||||
<table className="order-change-table" aria-label="售后修改原值与申请值对照">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>核对项目</th>
|
||||
<th>原值(申请时)</th>
|
||||
<th>申请值(同意后)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pair('售后日期', 'date')}
|
||||
{pair('售后项目', 'project')}
|
||||
{pair('客户', 'customer')}
|
||||
{pair('金额', 'amount', value => '¥' + yuan(value))}
|
||||
{pair('谁支付', 'payer', teamMemberName)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
function editIndependentSale(detail) {
|
||||
const record = detail.record,
|
||||
request = detail.pending;
|
||||
const pendingHTML = request ? (
|
||||
<section className="after-sale-pending">
|
||||
<h3>待店主审批</h3>
|
||||
<p className="small muted">申请尚未生效,当前仍按原记录计账。</p>
|
||||
{afterSaleComparisonHTML(request)}
|
||||
{request.reason ? <p className="change-reason">修改说明:{request.reason}</p> : ''}
|
||||
{state.user.role === 'owner' ? (
|
||||
button('查看并复核', 'after-sale-change-open', 'primary', {
|
||||
'data-id': request.id,
|
||||
})
|
||||
) : (
|
||||
<p className="small muted">店主同意后才更新这笔记录。</p>
|
||||
)}
|
||||
</section>
|
||||
) : (
|
||||
''
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<button className="dialog-close" data-action="close-after-sale" aria-label="关闭售后记录">
|
||||
×
|
||||
</button>
|
||||
<h2 id="after-sale-title">修改售后</h2>
|
||||
{detail.permissions.canEdit ? (
|
||||
<form id="after-sale-edit-form" data-id={record.id} data-approval={String(ui.approval)}>
|
||||
<fieldset disabled={ui.blocked} style={{ display: 'contents' }}>
|
||||
<div className="grid two">
|
||||
{field('售后日期', 'date', record.date, 'date', {
|
||||
required: true,
|
||||
max: state.today,
|
||||
})}
|
||||
{field('售后项目', 'project', record.project, 'text', {
|
||||
required: true,
|
||||
maxLength: '100',
|
||||
})}
|
||||
{field('客户', 'customer', record.customer, 'text', {
|
||||
required: true,
|
||||
maxLength: '60',
|
||||
})}
|
||||
{moneyField('金额(元)', 'amount', (record.amount / 100).toFixed(2))}
|
||||
{orderMemberField(record.member, true)}
|
||||
{choice('谁支付', 'payer', teamMemberOptions(), record.payer)}
|
||||
</div>
|
||||
<div className="note" id="after-sale-edit-mode" aria-live="polite">
|
||||
{ui.approval
|
||||
? '本次修改需店主审批。同意后才更新售后费用和利润;待审批期间仍按原记录计账。'
|
||||
: state.user.role === 'owner'
|
||||
? '保存后直接更新这笔售后,费用与利润按修改后的日期重算。'
|
||||
: '原日期与修改后日期均为今天,直接保存;改为其他日期须提交店主审批。'}
|
||||
</div>
|
||||
<label>
|
||||
修改说明(选填)
|
||||
<textarea name="reason" rows="2" maxLength="200" placeholder="例如:售后金额或付款人录错。"></textarea>
|
||||
</label>
|
||||
</fieldset>
|
||||
<div id="after-sale-edit-error" aria-live="polite">
|
||||
{ui.feedback}
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<span className="small muted">金额可填 0。归属沿用原记录。</span>
|
||||
<div className="actions">
|
||||
{button('取消', 'close-after-sale', 'quiet', { disabled: ui.busy })}
|
||||
<button type="submit" disabled={ui.blocked} className="primary">
|
||||
{ui.approval ? '提交修改申请' : '直接保存修改'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
) : (
|
||||
<>
|
||||
{afterSaleRecordHTML(record)}
|
||||
{!request ? <p className="note">{detail.permissions.reason || '这笔售后当前不可修改。'}</p> : ''}
|
||||
{pendingHTML}
|
||||
</>
|
||||
)}
|
||||
<div id="after-sale-read-error" aria-live="polite"></div>
|
||||
{detail.history.length ? (
|
||||
<details>
|
||||
<summary>售后修改记录({detail.history.length})</summary>
|
||||
<ul className="timeline">{Children.toArray(detail.history.map(afterSaleHistoryHTML))}</ul>
|
||||
</details>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
function orderMemberField(member = currentMember(), locked = false) {
|
||||
if (!teamMode()) return '';
|
||||
const selected = teamMemberKeys().includes(member) ? member : currentMember();
|
||||
return state.user.role === 'owner' && !locked ? (
|
||||
choice('订单归属(经营款与业绩)', 'member', teamMemberOptions(), selected)
|
||||
) : (
|
||||
<label>
|
||||
订单归属(经营款与业绩)
|
||||
<input defaultValue={teamMemberName(selected)} readOnly />
|
||||
<input type="hidden" name="member" defaultValue={selected} />
|
||||
</label>
|
||||
);
|
||||
}
|
||||
function newIndependentSale() {
|
||||
return (
|
||||
<>
|
||||
<button className="dialog-close" data-action="close-after-sale" aria-label="关闭新增售后">
|
||||
×
|
||||
</button>
|
||||
<h2 id="after-sale-title">新增售后</h2>
|
||||
<p className="small muted">售后费用计入所选日期,并扣减当天利润。</p>
|
||||
<form id="after-sale-form">
|
||||
<div className="grid two">
|
||||
{field('售后日期', 'date', state.today, 'date', {
|
||||
required: true,
|
||||
max: state.today,
|
||||
})}
|
||||
{field('售后项目', 'project', '', 'text', {
|
||||
required: true,
|
||||
maxLength: '100',
|
||||
placeholder: '例如:维修、补寄快递',
|
||||
})}
|
||||
{field('客户', 'customer', '', 'text', {
|
||||
required: true,
|
||||
maxLength: '60',
|
||||
placeholder: '客户称呼或代号',
|
||||
})}
|
||||
{moneyField('金额(元)', 'amount', '')}
|
||||
{orderMemberField()}
|
||||
<label>
|
||||
谁支付
|
||||
<select name="payer" required defaultValue="">
|
||||
<option value="" disabled>
|
||||
请选择
|
||||
</option>
|
||||
{opts(teamMemberOptions(), '')}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div id="after-sale-error" aria-live="polite">
|
||||
{ui.feedback}
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<span className="small muted">金额可填 0,请按实际支出填写。</span>
|
||||
<div className="actions">
|
||||
{button('取消', 'close-after-sale', 'quiet')}
|
||||
<button className="primary" type="submit">
|
||||
保存售后
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
function orderAfterSaleAccountPayer(account) {
|
||||
return accountIdentity(account)?.member || currentMember();
|
||||
}
|
||||
function materialPoolMg(value) {
|
||||
const text = String(value ?? '').trim();
|
||||
if (!/^\d+(?:\.\d{1,3})?$/.test(text)) return null;
|
||||
const [whole, fraction = ''] = text.split('.'),
|
||||
mg = BigInt(whole) * 1000n + BigInt(fraction.padEnd(3, '0'));
|
||||
return mg > 0n && mg <= 100000000000n ? Number(mg) : null;
|
||||
}
|
||||
function orderAfterSaleInput(form) {
|
||||
const order = currentOrder,
|
||||
entry = orderAfterSaleFormEntry,
|
||||
get = name => String(form.querySelector(`[name="${name}"]`)?.value ?? '').trim();
|
||||
if (
|
||||
!entry ||
|
||||
entry.id !== order?.id ||
|
||||
entry.user !== orderChangeUser() ||
|
||||
entry.revision !== order.revision ||
|
||||
form.dataset.orderId !== entry.id
|
||||
)
|
||||
throw new Error('请重新读取订单后核对售后。');
|
||||
const date = get('date'),
|
||||
reason = get('reason');
|
||||
if (!validOrderDate(date) || date > state.today || date < (order.delivered_date || order.date))
|
||||
throw new Error('售后日期应为交付当天至今天之间的有效日期。');
|
||||
if (!reason || reason.length > 200) throw new Error('售后原因请填写1~200字。');
|
||||
const rows = [...form.querySelectorAll('[data-after-sale-line]')];
|
||||
if (rows.length !== order.lines.length) throw new Error('请核对全部退回商品后再提交。');
|
||||
const lines = rows.map((row, lineIndex) => {
|
||||
const read = name => String(row.querySelector(`[name="${name}"]`)?.value ?? '').trim(),
|
||||
original = order.lines[lineIndex],
|
||||
quantity = read('return_quantity'),
|
||||
mg = materialPoolMg(quantity),
|
||||
pocket = read('return_pocket'),
|
||||
disposition = read('return_disposition');
|
||||
if (!mg || mg > original.quantity)
|
||||
throw new Error('商品 ' + (lineIndex + 1) + '实际退回克重须大于0且不超过原出库克重。');
|
||||
if (!orderAfterSalePocketKeys().includes(pocket))
|
||||
throw new Error('商品 ' + (lineIndex + 1) + '请选择已启用的自有退入货盘。');
|
||||
if (!['stock', 'scrap'].includes(disposition)) throw new Error('请选择退回后的实物状态。');
|
||||
if (disposition === 'scrap' && pocketCountsEnabled(pocket))
|
||||
throw new Error('旧料不恢复成品对数,请选择不按对计数的旧料货盘。');
|
||||
const stockCount =
|
||||
disposition === 'stock' && pocketCountsEnabled(pocket)
|
||||
? stockCountValue(read('return_count'), {
|
||||
title: '商品 ' + (lineIndex + 1) + '实际退回数量(对)',
|
||||
})
|
||||
: null;
|
||||
if (Number.isSafeInteger(original.stockCount) && stockCount > original.stockCount)
|
||||
throw new Error('商品 ' + (lineIndex + 1) + '实际退回对数不能超过原出库对数。');
|
||||
return {
|
||||
lineIndex,
|
||||
quantity,
|
||||
pocket,
|
||||
disposition,
|
||||
stockCount,
|
||||
};
|
||||
});
|
||||
const refundAmount = get('refund_amount'),
|
||||
refundCents = LedgerCalc.cents(refundAmount, '实际退款金额');
|
||||
if (refundCents > order.netReceived) throw new Error('实际退款不能超过本单尚未退回的净实收金额。');
|
||||
const deductionReason = get('deduction_reason');
|
||||
if (deductionReason.length > 200 || (order.netReceived - refundCents > 0 && !deductionReason))
|
||||
throw new Error('有扣留客户款时,请填写1~200字扣留原因。');
|
||||
const account = normalizePaymentAccount(get('refund_account')),
|
||||
payer = get('refund_payer');
|
||||
if (!account || !teamMemberKeys().includes(payer)) throw new Error('请选择退款账户与实际退款付款人。');
|
||||
if (payer !== orderAfterSaleAccountPayer(account)) throw new Error('实际退款付款人须与退款账户一致。');
|
||||
const reference = get('refund_reference');
|
||||
if (reference.length > 100) throw new Error('退款凭据备注最多100字。');
|
||||
const expenses = [...form.querySelectorAll('.order-after-sale-expense')].map(row => {
|
||||
const read = name => String(row.querySelector(`[name="${name}"]`)?.value ?? '').trim(),
|
||||
amount = read('expense_amount'),
|
||||
note = read('expense_note'),
|
||||
payer = read('expense_payer');
|
||||
if (LedgerCalc.cents(amount, '新增售后成本') <= 0) throw new Error('新增售后成本须大于0,没有发生请移除此项。');
|
||||
if (!note || note.length > 150 || !teamMemberKeys().includes(payer))
|
||||
throw new Error('请填写新增售后成本项目并选择实际付款人。');
|
||||
return {
|
||||
amount,
|
||||
payer,
|
||||
note,
|
||||
};
|
||||
});
|
||||
if (expenses.length > 30) throw new Error('一次售后最多填写30项新增成本。');
|
||||
return {
|
||||
date,
|
||||
revision: entry.revision,
|
||||
reason,
|
||||
verified: true,
|
||||
afterSale: {
|
||||
lines,
|
||||
refund: {
|
||||
amount: refundAmount,
|
||||
account,
|
||||
payer,
|
||||
reference,
|
||||
},
|
||||
deductionReason,
|
||||
expenses,
|
||||
},
|
||||
};
|
||||
}
|
||||
function orderAfterSaleExpenseHTML(value = {}) {
|
||||
return (
|
||||
<div className="order-after-sale-expense grid four">
|
||||
{field('售后成本项目', 'expense_note', value.note || '', 'text', {
|
||||
required: true,
|
||||
maxLength: '150',
|
||||
placeholder: '如寄件费、重新编绳',
|
||||
})}
|
||||
{moneyField('实际成本(元)', 'expense_amount', value.amount ?? '')}
|
||||
{choice('实际付款人', 'expense_payer', teamMemberOptions(), value.payer || currentMember())}
|
||||
{button('移除', 'order-after-sale-remove-expense', 'quiet')}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
function orderAfterSalePocketKeys() {
|
||||
return activePocketKeys().filter(key => state.pocketCatalog?.some(row => row.key === key && row.self === true));
|
||||
}
|
||||
function orderAfterSaleLineHTML(line, index) {
|
||||
const pockets = orderAfterSalePocketKeys();
|
||||
const pocket = ui.lines?.[index]?.pocket ?? (pockets.includes(line.pocket) ? line.pocket : pockets[0] || '');
|
||||
const disposition = ui.lines?.[index]?.disposition || 'stock';
|
||||
return (
|
||||
<article className="order-after-sale-line" data-after-sale-line={index}>
|
||||
<div className="panel-title">
|
||||
<h3>
|
||||
{index + 1} · {line.name}
|
||||
</h3>
|
||||
<span className="small muted">
|
||||
原出库 {grams(line.quantity)}g
|
||||
{Number.isSafeInteger(line.stockCount)
|
||||
? ' · ' + stockCountText(line.stockCount)
|
||||
: pocketCountsEnabled(line.pocket)
|
||||
? ' · 未记录对数'
|
||||
: ''}
|
||||
</span>
|
||||
</div>
|
||||
<div className="grid two">
|
||||
{field('实际退回克重(g)', 'return_quantity', grams(line.quantity), 'number', {
|
||||
required: true,
|
||||
min: '0.001',
|
||||
max: grams(line.quantity),
|
||||
step: '0.001',
|
||||
inputMode: 'decimal',
|
||||
})}
|
||||
{choice(
|
||||
'退回后的状态',
|
||||
'return_disposition',
|
||||
[
|
||||
['stock', '完好退回现货(保留工费)'],
|
||||
['scrap', '退回旧料(工费损失)'],
|
||||
],
|
||||
'stock',
|
||||
)}
|
||||
{choice(
|
||||
'实际退入自有货盘',
|
||||
'return_pocket',
|
||||
pockets.map(key => [key, pocketLabel(key)]),
|
||||
pocket,
|
||||
)}
|
||||
{stockCountField(pocket, line.stockCount, {
|
||||
name: 'return_count',
|
||||
visible: disposition === 'stock' && pocketCountsEnabled(pocket),
|
||||
title: '实际退回数量(对)',
|
||||
help: '按实际清点填写,不使用计工费件数。',
|
||||
})}
|
||||
</div>
|
||||
<p className="small muted" data-after-sale-line-note="">
|
||||
{disposition === 'stock'
|
||||
? '实退材料按原料费回售后日料池;原进货工费保留为这件现货的库存成本,再销售时选择对应退回现货继承,不重复付款。'
|
||||
: '实退材料按原料费回售后日料池;原进货工费计入本单售后损失,不恢复成品对数。'}
|
||||
</p>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
function orderAfterSaleApproval(date = state.today) {
|
||||
return (
|
||||
orderAfterSaleFormEntry?.forceApproval ||
|
||||
(state.user.role === 'assistant' && !orderActionCanDirect('return', date))
|
||||
);
|
||||
}
|
||||
function orderAfterSaleModeText(date = state.today) {
|
||||
return orderAfterSaleApproval(date)
|
||||
? '本次提交原订单售后申请,店主同意后一次登记退货、退款、费用与利润调整。复核前原账保持原值。'
|
||||
: '核实后一次登记退货、实际退款与售后成本。系统只记账,退款须已在实际账户完成。';
|
||||
}
|
||||
function orderAfterSaleFormHTML(order) {
|
||||
const receipts = order.payments?.filter(row => row.kind === 'receipt') || [],
|
||||
account =
|
||||
receipts.find(
|
||||
row =>
|
||||
order.payments
|
||||
.filter(item => item.account === row.account)
|
||||
.reduce((sum, item) => sum + (item.kind === 'receipt' ? item.amount : -item.amount), 0) > 0,
|
||||
)?.account || order.payment_account;
|
||||
const accounts = activePaymentAccounts(normalizePaymentAccount(account));
|
||||
if (account && !accounts.includes(normalizePaymentAccount(account)))
|
||||
accounts.push(normalizePaymentAccount(account));
|
||||
const payer = accountIdentity(account)?.member || currentMember();
|
||||
return (
|
||||
<form id="order-after-sale-form" className="panel order-after-sale-form" data-order-id={order.id}>
|
||||
<h2>处理售后</h2>
|
||||
<p id="order-after-sale-mode" className="note" aria-live="polite">
|
||||
{orderAfterSaleModeText(ui.date)}
|
||||
</p>
|
||||
<div className="grid two">
|
||||
{field('售后日期', 'date', state.today, 'date', {
|
||||
required: true,
|
||||
max: state.today,
|
||||
})}
|
||||
<label>
|
||||
售后原因
|
||||
<textarea
|
||||
name="reason"
|
||||
rows="2"
|
||||
maxLength="200"
|
||||
required
|
||||
placeholder="填写客户实际退货退款原因。"
|
||||
></textarea>
|
||||
</label>
|
||||
</div>
|
||||
<section className="order-after-sale-products">
|
||||
<h3>实物回库</h3>
|
||||
{Children.toArray(order.lines.map(orderAfterSaleLineHTML))}
|
||||
</section>
|
||||
<section className="order-after-sale-refund internal">
|
||||
<h3>实际退款</h3>
|
||||
<div className="grid three">
|
||||
{moneyField('实际退款金额(元,可修改)', 'refund_amount', (order.netReceived / 100).toFixed(2))}
|
||||
{choice('退款账户', 'refund_account', accounts, normalizePaymentAccount(account))}
|
||||
{choice('实际退款付款人', 'refund_payer', teamMemberOptions(), payer)}
|
||||
</div>
|
||||
{field('退款凭据备注(选填)', 'refund_reference', '', 'text', {
|
||||
maxLength: '100',
|
||||
})}
|
||||
<div className="order-after-sale-retained">
|
||||
<span>本次扣留客户款(系统计算)</span>
|
||||
<strong id="order-after-sale-retained">{ui.retained ?? '¥0.00'}</strong>
|
||||
<small className="muted">原净实收 ¥{yuan(order.netReceived)} − 本次实际退款</small>
|
||||
</div>
|
||||
<label>
|
||||
扣留款原因
|
||||
<textarea
|
||||
name="deduction_reason"
|
||||
required={ui.reasonRequired}
|
||||
rows="2"
|
||||
maxLength="200"
|
||||
placeholder="有扣留款时填写,如约定扣除不可退工费或实际损耗。"
|
||||
></textarea>
|
||||
</label>
|
||||
<p className="small muted">扣留款与支付渠道手续费分开核对。原单已经发生的支付手续费、邮费等成本继续保留。</p>
|
||||
</section>
|
||||
<section className="order-after-sale-expenses internal">
|
||||
<div className="panel-title">
|
||||
<h3>新增售后成本(选填)</h3>
|
||||
{button('+ 添加售后成本', 'order-after-sale-add-expense')}
|
||||
</div>
|
||||
<p className="small muted">只填这次新发生且实际已付的成本;原单已记费用不要重复填写。</p>
|
||||
<div id="order-after-sale-expenses">{ui.expenses}</div>
|
||||
</section>
|
||||
<div className="form-actions">
|
||||
<button type="button" className="primary" data-action="order-after-sale-preview" disabled={ui.previewLoading}>
|
||||
核对售后预览
|
||||
</button>
|
||||
<span className="small muted" id="order-after-sale-preview-status" aria-live="polite">
|
||||
{ui.previewStatus || '填好后先预览,核对回库、回料、退款和利润。'}
|
||||
</span>
|
||||
</div>
|
||||
<div id="order-after-sale-preview" aria-live="polite">
|
||||
{ui.preview &&
|
||||
orderAfterSaleSummaryHTML(ui.preview.record, {
|
||||
preview: true,
|
||||
})}
|
||||
</div>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required disabled={!ui.preview} />
|
||||
已按实际退回商品、退款凭据和新增成本,核对以下预览。
|
||||
</label>
|
||||
<div id="order-after-sale-error" aria-live="polite">
|
||||
{ui.afterError && (
|
||||
<div className="error">
|
||||
{ui.afterError}{' '}
|
||||
<button type="button" data-action="reload-order-change">
|
||||
重新读取订单
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="primary" data-order-after-sale-submit="" disabled={!ui.preview}>
|
||||
{orderAfterSaleApproval(ui.date) ? '提交售后申请' : '确认并保存售后'}
|
||||
</button>
|
||||
{button('收起', 'order-after-sale-close', 'quiet')}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
function afterSaleStatus(request) {
|
||||
return (
|
||||
{
|
||||
pending: '待店主审批',
|
||||
approved: '已同意',
|
||||
rejected: '已驳回',
|
||||
}[request.status] || '状态待确认'
|
||||
);
|
||||
}
|
||||
function afterSaleTime(value) {
|
||||
return String(value || '未提供')
|
||||
.replace('T', ' ')
|
||||
.replace(/\.\d{3}Z$/, ' UTC')
|
||||
.replace(/Z$/, ' UTC');
|
||||
}
|
||||
function afterSaleValuesValid(record) {
|
||||
return (
|
||||
record &&
|
||||
validOrderDate(record.date) &&
|
||||
typeof record.project === 'string' &&
|
||||
record.project.trim() &&
|
||||
record.project.length <= 100 &&
|
||||
typeof record.customer === 'string' &&
|
||||
record.customer.trim() &&
|
||||
record.customer.length <= 60 &&
|
||||
Number.isSafeInteger(record.amount) &&
|
||||
record.amount >= 0 &&
|
||||
teamMemberKeys().includes(record.payer)
|
||||
);
|
||||
}
|
||||
function validateAfterSaleRequest(request) {
|
||||
if (
|
||||
!request ||
|
||||
typeof request.id !== 'string' ||
|
||||
!request.id ||
|
||||
typeof request.afterSaleId !== 'string' ||
|
||||
!request.afterSaleId ||
|
||||
!Number.isSafeInteger(request.revision) ||
|
||||
request.revision < 1 ||
|
||||
!Number.isSafeInteger(request.recordRevision) ||
|
||||
request.recordRevision < 1 ||
|
||||
!['pending', 'approved', 'rejected'].includes(request.status) ||
|
||||
!afterSaleValuesValid(request.before) ||
|
||||
!afterSaleValuesValid(request.after) ||
|
||||
typeof request.canApprove !== 'boolean'
|
||||
)
|
||||
throw new Error('售后修改申请资料未完整返回,请重新读取。');
|
||||
return request;
|
||||
}
|
||||
function afterSaleChangeListHTML(data) {
|
||||
if (
|
||||
!Array.isArray(data.requests) ||
|
||||
!data.counts ||
|
||||
!['pending', 'approved', 'rejected'].every(key => Number.isSafeInteger(data.counts[key]) && data.counts[key] >= 0)
|
||||
)
|
||||
throw new Error('售后修改列表未完整返回,请重新读取。');
|
||||
const tabs = Children.toArray(
|
||||
[
|
||||
['pending', '待审批'],
|
||||
['approved', '已同意'],
|
||||
['rejected', '已驳回'],
|
||||
['all', '全部'],
|
||||
].map(([status, name]) =>
|
||||
button(
|
||||
name + (status === 'all' ? '' : '(' + data.counts[status] + ')'),
|
||||
'after-sale-changes-filter',
|
||||
status === afterSaleChangesStatus ? 'active' : '',
|
||||
{
|
||||
'data-status': status,
|
||||
'aria-pressed': status === afterSaleChangesStatus,
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
const rows = data.requests.map(validateAfterSaleRequest);
|
||||
return (
|
||||
<>
|
||||
<div className="change-list-tabs" role="group" aria-label="售后修改申请状态">
|
||||
{tabs}
|
||||
</div>
|
||||
{rows.length ? (
|
||||
<div className="table-wrap">
|
||||
<table className="change-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>售后记录</th>
|
||||
<th>修改后日期</th>
|
||||
<th>申请人</th>
|
||||
<th>申请时间</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Children.toArray(
|
||||
rows.map(request => (
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{request.before.customer}</strong>
|
||||
<div className="small muted">
|
||||
{request.before.date} · {request.before.project}
|
||||
</div>
|
||||
</td>
|
||||
<td>{request.after.date}</td>
|
||||
<td>{request.requesterName || '未提供'}</td>
|
||||
<td>{afterSaleTime(request.created)}</td>
|
||||
<td>
|
||||
{afterSaleStatus(request)}
|
||||
{request.stale ? <div className="small danger-text">原记录已有变动</div> : ''}
|
||||
</td>
|
||||
<td>
|
||||
{button(
|
||||
state.user.role === 'owner' && request.status === 'pending' ? '查看并复核' : '查看修改',
|
||||
'after-sale-change-open',
|
||||
'',
|
||||
{
|
||||
'data-id': request.id,
|
||||
},
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="empty">没有符合状态的售后修改申请。</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
return {
|
||||
afterSaleChangeListHTML,
|
||||
newIndependentSale,
|
||||
editIndependentSale,
|
||||
independentReview,
|
||||
independentReviewForm,
|
||||
orderAfterSaleFormHTML,
|
||||
orderAfterSaleExpenseHTML,
|
||||
orderAfterSaleInput,
|
||||
orderAfterSaleApproval,
|
||||
orderAfterSalePocketKeys,
|
||||
orderAfterSaleAccountPayer,
|
||||
orderAfterSaleModeText,
|
||||
validateAfterSaleDetail,
|
||||
validateAfterSaleRequest,
|
||||
orderAfterSaleSummaryHTML,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,834 @@
|
||||
import { Children, useState } from 'react';
|
||||
import { Cards as CreditCardFees, Calc as LedgerCalc } from '../../../shared';
|
||||
const asMoney = value => (value == null ? '' : (value / 100).toFixed(2));
|
||||
const costKeys = ['material', 'labor', 'accessories', 'other'];
|
||||
function costBreakdown(line, quantity, parts, modes, rates) {
|
||||
const input = { unit: line.unit, quantity, costParts: parts };
|
||||
for (const [key, property] of [
|
||||
['material', 'costMaterial'],
|
||||
['labor', 'costLabor'],
|
||||
]) {
|
||||
input[property] = modes[key] === 'gram' ? { mode: 'gram', rate: rates[key] } : { mode: 'total' };
|
||||
}
|
||||
return LedgerCalc.purchaseCosts(input);
|
||||
}
|
||||
function LegacyCostRow({ line, index, members, fallback, choice, opts, grams, yuan }) {
|
||||
const prefix = 'cost-' + index + '-';
|
||||
const quantity = line.unit === 'g' ? (line.quantity / 1000).toFixed(3) : line.quantity;
|
||||
const initialParts = Object.fromEntries(
|
||||
costKeys.map(key => [
|
||||
key,
|
||||
line.costParts ? asMoney(line.costParts[key]) : ['accessories', 'other'].includes(key) ? '0' : '',
|
||||
]),
|
||||
);
|
||||
const originalMode = ['gram', 'total'].includes(line.costMaterial?.mode)
|
||||
? line.costMaterial.mode
|
||||
: initialParts.material === ''
|
||||
? 'gram'
|
||||
: 'total';
|
||||
const [parts, setParts] = useState(initialParts);
|
||||
const [modes, setModes] = useState({
|
||||
material: line.unit === 'g' ? originalMode : 'total',
|
||||
labor: line.unit === 'g' ? line.costLabor?.mode || 'total' : 'total',
|
||||
});
|
||||
const [rates, setRates] = useState({
|
||||
material: asMoney(line.costMaterial?.rate),
|
||||
labor: asMoney(line.costLabor?.rate),
|
||||
});
|
||||
const originalTotal = line.unit !== 'g' || originalMode === 'total' ? initialParts.material : '';
|
||||
const changePart = (key, value) => setParts(old => ({ ...old, [key]: value }));
|
||||
const updateMode = (key, value, computed) => {
|
||||
if (value === 'total' && (key === 'labor' || parts.material === '')) changePart(key, computed);
|
||||
setModes(old => ({ ...old, [key]: value }));
|
||||
};
|
||||
const amount = (key, title, value, gram = false) => (
|
||||
<label>
|
||||
{title}
|
||||
<input
|
||||
type="number"
|
||||
name={prefix + key}
|
||||
min="0"
|
||||
step="0.01"
|
||||
placeholder="开单前必填,没有填0"
|
||||
required={!gram}
|
||||
readOnly={gram}
|
||||
value={value}
|
||||
onChange={event => changePart(key, event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
function group(key) {
|
||||
const material = key === 'material',
|
||||
gram = modes[key] === 'gram';
|
||||
const payer = line.costPayers?.[key] ?? line.payer ?? fallback;
|
||||
let value = parts[key],
|
||||
formula;
|
||||
if (gram) {
|
||||
try {
|
||||
const result = costBreakdown(
|
||||
line,
|
||||
quantity,
|
||||
{ material: '0', labor: '0', accessories: '0', other: '0' },
|
||||
{ material: 'total', labor: 'total', [key]: 'gram' },
|
||||
rates,
|
||||
).parts[key];
|
||||
value = asMoney(result);
|
||||
formula =
|
||||
result == null
|
||||
? material
|
||||
? '填写每克进货料价后,系统自动乘以本行克重。'
|
||||
: '填写每克工费后自动乘以克重。'
|
||||
: quantity + 'g × ' + rates[key] + '元/克 = ' + yuan(result) + '元';
|
||||
} catch (err) {
|
||||
value = '';
|
||||
formula = err.message;
|
||||
}
|
||||
} else {
|
||||
formula = material
|
||||
? line.unit === 'g'
|
||||
? '直接填写本行料费合计,不再乘以克重。'
|
||||
: '按件商品请填写本行料费合计' + (rates.material ? ';每克料价已保留,切回g可恢复' : '') + '。'
|
||||
: '直接填写本行总工费。';
|
||||
}
|
||||
const options = members(false, { selected: payer });
|
||||
return (
|
||||
<div className={'purchase-' + key} data-prefix={prefix} data-mode={modes[key]}>
|
||||
<div className="grid purchase-cost-grid">
|
||||
<label>
|
||||
{material ? '进货料费方式' : '进货工费方式'}
|
||||
<select
|
||||
name={prefix + key + 'Mode'}
|
||||
value={modes[key]}
|
||||
onChange={event => updateMode(key, event.target.value, value)}
|
||||
>
|
||||
<option value="gram" disabled={line.unit !== 'g'}>
|
||||
{material ? '按克料价' : '克工费'}
|
||||
</option>
|
||||
<option value="total">{material ? '直接填总料费' : '总工费'}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label hidden={!gram}>
|
||||
{material ? '进货料价(元/克)' : '进货克工费(元/克)'}
|
||||
<input
|
||||
type="number"
|
||||
name={prefix + key + 'Rate'}
|
||||
min="0"
|
||||
step="0.01"
|
||||
value={rates[key]}
|
||||
placeholder={material ? '填写每克进货料价' : '填写每克工费'}
|
||||
disabled={!gram}
|
||||
required={gram}
|
||||
onChange={event => setRates(old => ({ ...old, [key]: event.target.value }))}
|
||||
/>
|
||||
</label>
|
||||
{amount(key, material ? '料费成本合计(元)' : '进货总工费(元)', value, gram)}
|
||||
<label className="purchase-payer">
|
||||
{material ? '料费付款人' : '进货工费付款人'}
|
||||
<select
|
||||
required
|
||||
name={prefix + key + 'Payer'}
|
||||
defaultValue={options.some(([id]) => id === payer) ? payer : ''}
|
||||
>
|
||||
{options.some(([id]) => id === payer) ? null : (
|
||||
<option value="" disabled>
|
||||
请选择
|
||||
</option>
|
||||
)}
|
||||
{opts(options)}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<p className="purchase-formula small muted" aria-live="polite">
|
||||
{formula}
|
||||
</p>
|
||||
{material && (
|
||||
<p className="purchase-original small muted" hidden={!originalTotal}>
|
||||
{originalTotal &&
|
||||
'已保留原料费合计 ' + originalTotal + '元。原金额不会当成每克料价;切换按克后请填写实际进货料价。'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
let summary;
|
||||
try {
|
||||
summary = costBreakdown(line, quantity, parts, modes, rates).total;
|
||||
} catch {
|
||||
summary = null;
|
||||
}
|
||||
return (
|
||||
<div className="internal cost-editor">
|
||||
<h3>
|
||||
{line.name} · {line.unit === 'g' ? grams(line.quantity) + 'g' : line.quantity + '件'}
|
||||
</h3>
|
||||
<div className="cost-fallback-payer">
|
||||
{choice('配件及其他成本付款人', 'goodsPayer', members(), line.payer || 'owner')}
|
||||
</div>
|
||||
{!line.costParts && line.cost !== null && (
|
||||
<p className="small">原记录未分项,总额 ¥{yuan(line.cost)};请按凭据拆分,不要把总额再填入每个项目。</p>
|
||||
)}
|
||||
<div className="cost-fields grid">
|
||||
{group('material')}
|
||||
{group('labor')}
|
||||
{amount('accessories', '配件成本(元,本行合计)', parts.accessories)}
|
||||
{amount('other', '其他货品成本(元,本行合计)', parts.other)}
|
||||
</div>
|
||||
<div className="cost-summary small">
|
||||
本行货品成本合计:{summary == null ? '请补齐(没有的项目填0)' : '¥' + yuan(summary)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function orderActions(
|
||||
{ currentOrder, ui, state },
|
||||
{
|
||||
orderActionUsesChangeForm,
|
||||
orderActionRequiresApproval,
|
||||
orderAfterSaleRecord,
|
||||
orderOwnershipPending,
|
||||
orderCancellationPending,
|
||||
orderChangePending,
|
||||
moneyField,
|
||||
choice,
|
||||
teamMemberOptions,
|
||||
field,
|
||||
grams,
|
||||
yuan,
|
||||
pocketCountsEnabled,
|
||||
stockCountField,
|
||||
teamMode,
|
||||
teamMemberName,
|
||||
accountDisplayName,
|
||||
activePaymentAccounts,
|
||||
orderChangeActionLabels,
|
||||
actionName,
|
||||
button,
|
||||
normalizePaymentAccount,
|
||||
accountIdentity,
|
||||
memberAccountPrefix,
|
||||
teamMemberEnabled,
|
||||
opts,
|
||||
currentMember,
|
||||
activePocketKeys,
|
||||
pocketLabel,
|
||||
stockCountValue,
|
||||
},
|
||||
) {
|
||||
function readReturnCounts(form, pockets) {
|
||||
return pockets.map((pocket, index) => {
|
||||
if (!pocketCountsEnabled(pocket)) return null;
|
||||
const count = stockCountValue(form.querySelector('[name="returnCount-' + index + '"]')?.value, {
|
||||
title: '商品 ' + (index + 1) + '实际退回数量(对)',
|
||||
}),
|
||||
original = currentOrder?.lines?.[index]?.stockCount;
|
||||
if (Number.isSafeInteger(original) && count !== original)
|
||||
throw new Error('商品 ' + (index + 1) + '整单退回数量须与原出库的' + original + '对一致。');
|
||||
return count;
|
||||
});
|
||||
}
|
||||
function readPaymentAccount(form) {
|
||||
return normalizePaymentAccount(
|
||||
(form?.querySelector?.('[name="payment_recipient"]')?.value || '') +
|
||||
(form?.querySelector?.('[name="payment_method"]')?.value || ''),
|
||||
);
|
||||
}
|
||||
function actionInput(form) {
|
||||
const data = Object.fromEntries(new FormData(form));
|
||||
const kind = form.dataset.kind;
|
||||
const input = {
|
||||
...data,
|
||||
date: data.date || state.today,
|
||||
verified: data.verified === 'on',
|
||||
feesVerified: data.feesVerified === 'on',
|
||||
};
|
||||
if (kind === 'fees') {
|
||||
input.revision = currentOrder.revision;
|
||||
input.fee_items = [...form.querySelectorAll('.fee-verify-row')].map(row => ({
|
||||
...currentOrder.pendingFees.find(f => f.key === row.dataset.key),
|
||||
status: 'estimated',
|
||||
amount: row.querySelector('[name="verifiedAmount"]').value,
|
||||
payer: row.querySelector('[name="verifiedPayer"]').value,
|
||||
}));
|
||||
}
|
||||
if (kind === 'correct') {
|
||||
const [type, target] = data.entry.split(':');
|
||||
input.type = type;
|
||||
input.target = target;
|
||||
}
|
||||
if (kind === 'cost')
|
||||
input.costs = Array.from(form.querySelectorAll('.cost-editor'), (row, index) => {
|
||||
const get = key => row.querySelector('[name="cost-' + index + '-' + key + '"]').value;
|
||||
const mode = key =>
|
||||
get(key + 'Mode') === 'gram' ? { mode: 'gram', rate: get(key + 'Rate') } : { mode: 'total' };
|
||||
return {
|
||||
parts: Object.fromEntries(costKeys.map(key => [key, get(key)])),
|
||||
costMaterial: mode('material'),
|
||||
costLabor: mode('labor'),
|
||||
costPayers: { material: get('materialPayer'), labor: get('laborPayer') },
|
||||
payer: row.querySelector('[name="goodsPayer"]').value,
|
||||
};
|
||||
});
|
||||
if (kind === 'receipt' || kind === 'refund') input.account = readPaymentAccount(form);
|
||||
if (kind === 'correct' && input.account) input.account = normalizePaymentAccount(input.account);
|
||||
if (kind === 'return') {
|
||||
input.returnPockets = currentOrder.lines.map(
|
||||
(_, i) => form.querySelector('[name="return-' + i + '"]')?.value ?? data['return-' + i],
|
||||
);
|
||||
input.returnCounts = readReturnCounts(form, input.returnPockets);
|
||||
}
|
||||
if (kind === 'complete') {
|
||||
input.stockCounts = {};
|
||||
currentOrder.lines.forEach((line, index) => {
|
||||
if (line.unit === 'g' && pocketCountsEnabled(line.pocket) && line.stockCount == null)
|
||||
input.stockCounts[index] = stockCountValue(
|
||||
form.querySelector('[name="completeCount-' + index + '"]')?.value,
|
||||
{
|
||||
title: '商品 ' + (index + 1) + '实际出库数量(对)',
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
if (['review', 'complete'].includes(kind)) input.revision = currentOrder.revision;
|
||||
return input;
|
||||
}
|
||||
function orderActionModeText(kind, approval) {
|
||||
return approval
|
||||
? `本次提交${orderChangeActionLabels[kind]}申请。店主同意后才记账;待批期间原订单、收退款、费用、库存和利润均不变。系统不会发起真实付款。`
|
||||
: '原单与本次业务日期均为今天,核实后直接记账,无需店主审批。改为其他业务日期须提交申请。系统不会发起真实付款。';
|
||||
}
|
||||
function orderActionChangeReviewHTML(kind) {
|
||||
const approval = orderActionRequiresApproval(kind, ui.date);
|
||||
return (
|
||||
<>
|
||||
<div className="note" id="order-action-mode" aria-live="polite">
|
||||
{orderActionModeText(kind, approval)}
|
||||
</div>
|
||||
{kind === 'return' ? (
|
||||
''
|
||||
) : (
|
||||
<label>
|
||||
<span id="order-action-reason-label">{approval ? '申请原因' : '登记原因'}</span>
|
||||
<textarea
|
||||
name="change_reason"
|
||||
maxLength="200"
|
||||
rows="2"
|
||||
required
|
||||
placeholder="写清本次需要登记或更正的原因。"
|
||||
></textarea>
|
||||
</label>
|
||||
)}
|
||||
{['cost', 'expense'].includes(kind) ? (
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实本次金额、实际付款人与凭据一致。
|
||||
</label>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
function creditCardPreviewHTML(id, payer = 'owner', basis = '客户付款金额') {
|
||||
const values = ui.values || {};
|
||||
const original = currentOrder.payment_account;
|
||||
const method = ui.paymentMethod ?? accountIdentity(original)?.channel;
|
||||
const corrected = currentOrder.payments.find(p => p.id === (values.entry || '').split(':')[1]);
|
||||
const correction = ui.action === 'correct';
|
||||
const visible = correction
|
||||
? corrected?.kind === 'receipt' && isCreditCardAccount(values.account)
|
||||
: method === '信用卡' && ui.action === 'receipt';
|
||||
const rate = currentOrder.credit_card_rate_permille ?? state.shopSettings?.creditCardRatePermille ?? 6;
|
||||
let amount, formula;
|
||||
if (visible || ui.lastCardBasis !== undefined) {
|
||||
try {
|
||||
const basisAmount = visible ? (values.amount ?? (currentOrder.balance / 100).toFixed(2)) : ui.lastCardBasis;
|
||||
const cents = LedgerCalc.cents(basisAmount);
|
||||
amount = (CreditCardFees.amount(cents, rate) / 100).toFixed(2);
|
||||
formula =
|
||||
basis +
|
||||
' ¥' +
|
||||
yuan(cents) +
|
||||
' × ' +
|
||||
rate +
|
||||
'‰ = ¥' +
|
||||
yuan(CreditCardFees.amount(cents, rate)) +
|
||||
'。计入内部成本,客户付款金额不变;退款不退回已发生的手续费。';
|
||||
} catch {
|
||||
formula =
|
||||
'填写客户付款金额后自动计算' + rate + '‰手续费;付款人默认' + teamMemberName('owner') + ',可按实际修改。';
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className="credit-card-preview" id={id} data-basis={basis} hidden={!visible}>
|
||||
<div className="credit-card-heading">
|
||||
<strong>信用卡手续费(内部)</strong>
|
||||
<span className="small muted">自动计算 · 客户单据不显示</span>
|
||||
</div>
|
||||
<div className="credit-card-fields">
|
||||
<label>
|
||||
手续费(元,自动)
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
data-credit-card-amount=""
|
||||
readOnly
|
||||
value={amount || ''}
|
||||
aria-label="信用卡手续费自动金额"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
手续费付款人
|
||||
<select name="credit_card_fee_payer" defaultValue={payer} required={!!visible} disabled={!visible}>
|
||||
{opts(teamMemberOptions())}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<p className="small muted" data-credit-card-formula="" aria-live="polite">
|
||||
{formula}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
function isAutomaticCardFee(item) {
|
||||
return item?.system === 'credit_card' || String(item?.key || '').startsWith('card_fee:');
|
||||
}
|
||||
function pocketOptions(selected = '', historical = false) {
|
||||
const keys = activePocketKeys(),
|
||||
options = keys.map(key => [key, pocketLabel(key)]);
|
||||
if (selected && !keys.includes(selected))
|
||||
options.push([
|
||||
selected,
|
||||
pocketLabel(selected) + (historical ? '(已停用 · 原货盘)' : '(已停用,请重新选择)'),
|
||||
true,
|
||||
]);
|
||||
return options;
|
||||
}
|
||||
function isCreditCardAccount(account) {
|
||||
return typeof CreditCardFees === 'object' && typeof CreditCardFees.isAccount === 'function'
|
||||
? CreditCardFees.isAccount(account)
|
||||
: ['助理信用卡', '助理1信用卡', '麦麦信用卡', '助理2信用卡'].includes(account);
|
||||
}
|
||||
const orderFormMember = () => currentOrder?.member || currentMember();
|
||||
function defaultPaymentRecipient() {
|
||||
const member = teamMode() ? orderFormMember() : 'assistant';
|
||||
return memberAccountPrefix(teamMemberEnabled(member) ? member : 'owner');
|
||||
}
|
||||
function creditCardAvailable() {
|
||||
return typeof CreditCardFees === 'object' && state?.accounts?.includes('麦麦信用卡');
|
||||
}
|
||||
function accountFields(account) {
|
||||
const methods = ['微信', '支付宝', '现金', ...(creditCardAvailable() ? ['信用卡'] : [])];
|
||||
account = normalizePaymentAccount(account || defaultPaymentRecipient() + '微信');
|
||||
const card = ui.paymentMethod ? ui.paymentMethod === '信用卡' : isCreditCardAccount(account),
|
||||
identity = accountIdentity(account),
|
||||
prefix = identity ? memberAccountPrefix(identity.member) : defaultPaymentRecipient();
|
||||
const recipients = teamMemberOptions(!teamMode()).map(([member, name]) => [memberAccountPrefix(member), name]);
|
||||
if (identity && !teamMemberEnabled(identity.member))
|
||||
recipients.push([prefix, teamMemberName(identity.member) + '(已停用 · 原记录)']);
|
||||
return (
|
||||
<>
|
||||
{choice('收款方式', 'payment_method', methods, identity?.channel || '微信')}
|
||||
<label>
|
||||
收款人
|
||||
<select
|
||||
name="payment_recipient"
|
||||
key={card ? 'card' : 'standard'}
|
||||
defaultValue={card ? '麦麦' : ui.recipient || prefix}
|
||||
data-non-card-recipient={card ? defaultPaymentRecipient() : prefix}
|
||||
data-card-locked={card}
|
||||
disabled={card}
|
||||
>
|
||||
{opts(recipients, card ? '麦麦' : prefix)}
|
||||
</select>
|
||||
{creditCardAvailable() ? (
|
||||
<small className="small muted payment-account-note" hidden={!card}>
|
||||
信用卡统一由{teamMemberName('owner')}收款。
|
||||
</small>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
}
|
||||
const dateField = (name = 'date', value) =>
|
||||
field('业务日期', name, value || state.today, 'date', {
|
||||
max: state.today,
|
||||
required: true,
|
||||
});
|
||||
function showAction(action) {
|
||||
const o = currentOrder;
|
||||
let html = '';
|
||||
const dt = dateField(),
|
||||
changeForm = orderActionUsesChangeForm(action),
|
||||
requiresApproval = orderActionRequiresApproval(action, ui.date);
|
||||
if (['return', 'refund'].includes(action) && orderAfterSaleRecord(o))
|
||||
throw new Error('本单已办理售后,请查看售后处理记录,不能重复退货退款。');
|
||||
if (action === 'cancel') throw new Error('请重新读取订单后,从“取消订单”或“申请取消”核对办理。');
|
||||
if (o.ownershipPending || orderOwnershipPending(o))
|
||||
throw new Error('归属申请待店主复核,当前暂停本单其他修改和记账。');
|
||||
if (o.cancellationPending || orderCancellationPending(o))
|
||||
throw new Error('取消申请待店主复核,当前暂停本单修改和退货。');
|
||||
if (o.changePending || orderChangePending(o))
|
||||
throw new Error('修改申请待店主复核,当前暂停本单其他记账和取消申请。');
|
||||
if (o.cancellationApproved && !['settlement', 'correct', 'review'].includes(action))
|
||||
throw new Error('本单已按录错作废,不能继续登记销售、费用或退款。');
|
||||
if (action === 'complete' && state.user.role === 'assistant' && o.pendingFees.length)
|
||||
throw new Error('这张旧单还有费用尚未入账,请先申请补记旧单费用,店主同意后再补齐旧单账务。');
|
||||
if (action === 'fees')
|
||||
html = (
|
||||
<>
|
||||
<p>补齐旧单实际已付费用,没有发生的填0。保存后只记一次实际费用;完成旧单账务后计算完整利润。</p>
|
||||
{dt}
|
||||
<div className="fee-grid" id="verify-fees">
|
||||
{Children.toArray(
|
||||
o.pendingFees.map(f => (
|
||||
<div className="fee-verify-row" data-key={f.key}>
|
||||
<h3>{f.note}</h3>
|
||||
{moneyField('实际成本(元)', 'verifiedAmount', f.amount === null ? '' : (f.amount / 100).toFixed(2))}
|
||||
{choice('实际付款人', 'verifiedPayer', teamMemberOptions(true), f.payer)}
|
||||
</div>
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实实际支付,没有发生的费用已填0。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
if (['receipt', 'refund'].includes(action))
|
||||
html = (
|
||||
<>
|
||||
<div className="grid three">
|
||||
{dt}
|
||||
{moneyField(
|
||||
action === 'receipt' ? '本次实收金额' : '本次实退金额',
|
||||
'amount',
|
||||
((action === 'receipt' ? o.balance : o.netReceived) / 100).toFixed(2),
|
||||
)}
|
||||
{accountFields(
|
||||
action === 'refund'
|
||||
? o.payments.find(
|
||||
p =>
|
||||
p.kind === 'receipt' &&
|
||||
o.payments
|
||||
.filter(r => r.account === p.account)
|
||||
.reduce((n, r) => n + (r.kind === 'receipt' ? r.amount : -r.amount), 0) > 0,
|
||||
)?.account || o.payment_account
|
||||
: o.payment_account,
|
||||
)}
|
||||
</div>
|
||||
{field('凭据备注(选填)', 'reference', '', 'text', {
|
||||
maxLength: '100',
|
||||
placeholder: '交易凭据末几位或说明',
|
||||
})}
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已在实际账户核实{action === 'receipt' ? '到账' : '退款成功'},不是仅收到客户截图。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
if (action === 'expense')
|
||||
html = (
|
||||
<>
|
||||
{o.pendingFees.length ? (
|
||||
<div className="note">
|
||||
本旧单还有费用尚未入账,请从“补记旧单费用”补齐,或完成旧单账务时一并入账。这里仅记额外发生的费用。
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
<p className="small muted">记录额外已支付的费用;已包含在货品成本或已记账费用中的不要重复登记。</p>
|
||||
<div className="grid three">
|
||||
{dt}
|
||||
{moneyField('本次费用', 'amount')}
|
||||
{choice('实际付款人', 'payer', teamMemberOptions(true), 'assistant')}
|
||||
</div>
|
||||
{field('费用项目与说明', 'note', '', 'text', {
|
||||
required: true,
|
||||
maxLength: '150',
|
||||
})}
|
||||
</>
|
||||
);
|
||||
if (action === 'cost')
|
||||
html = (
|
||||
<>
|
||||
<div className="note">
|
||||
进货料价和克工费按该行克重自动计算;原单合计金额保留,改按克录入时需填写实际单价。没有的成本填0,完成销售记账后锁定。快递和附加费用可从“补记旧单费用”填写。
|
||||
</div>
|
||||
{o.lines.map((line, index) => (
|
||||
<LegacyCostRow
|
||||
key={index}
|
||||
line={line}
|
||||
index={index}
|
||||
members={teamMemberOptions}
|
||||
fallback={teamMode() ? orderFormMember() : 'owner'}
|
||||
choice={choice}
|
||||
opts={opts}
|
||||
grams={grams}
|
||||
yuan={yuan}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
if (action === 'complete')
|
||||
html = (
|
||||
<>
|
||||
{dt}
|
||||
{Children.toArray(
|
||||
o.lines.map((line, index) =>
|
||||
line.unit === 'g' && pocketCountsEnabled(line.pocket) && line.stockCount == null
|
||||
? stockCountField(line.pocket, '', {
|
||||
name: 'completeCount-' + index,
|
||||
title: line.name + ' · 实际出库数量(对)',
|
||||
help: '',
|
||||
})
|
||||
: '',
|
||||
),
|
||||
)}
|
||||
<p>
|
||||
补齐这张旧单的销售记账:按填写金额记录实际费用、从原货盘扣减黄金并计入销售与利润。款项未收齐或成本金额有空白时,请先补齐。
|
||||
</p>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实全额收款、商品已交付,所填费用为实际已付金额,没有发生的已填0。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
if (action === 'return')
|
||||
html = (
|
||||
<>
|
||||
{dt}
|
||||
{field('退货原因', 'reason', '', 'text', {
|
||||
required: true,
|
||||
maxLength: '200',
|
||||
})}
|
||||
<div className="grid two">
|
||||
{Children.toArray(
|
||||
o.lines.map((l, i) => (
|
||||
<div className="return-stock-item">
|
||||
{choice(
|
||||
l.name + ' · 实物去向',
|
||||
'return-' + i,
|
||||
l.unit === 'g'
|
||||
? [
|
||||
...(l.pocket || l.costMaterial?.mode === 'pool' ? [] : [['', '已退供应商,不留店内']]),
|
||||
...pocketOptions(l.pocket, true),
|
||||
]
|
||||
: [['', '按件商品,不记黄金货盘']],
|
||||
l.pocket || (l.costMaterial?.mode === 'pool' ? state.pockets[0] : ''),
|
||||
)}
|
||||
{stockCountField(
|
||||
ui.values?.['return-' + i] ??
|
||||
(l.pocket || (l.costMaterial?.mode === 'pool' ? state.pockets[0] : '')),
|
||||
l.stockCount,
|
||||
{
|
||||
readOnly: Number.isSafeInteger(l.stockCount),
|
||||
name: 'returnCount-' + i,
|
||||
title: '实际退回数量(对)',
|
||||
help: '',
|
||||
},
|
||||
)}
|
||||
</div>
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
<div className="note">
|
||||
本入口办理整单退货,原销售额与货品成本在退货日冲回。已花费的运费等仍保留。换货先退原单,再开新单;部分退货暂未开放。
|
||||
</div>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实本单全部商品退回,所选去向与实际一致。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
if (action === 'settlement' && teamMode()) throw new Error('团队成员往来请在每日对账核对。');
|
||||
if (action === 'settlement' && (o.materialCostPending || o.settlementDue == null))
|
||||
throw new Error('本批料费尚未补齐,补足采购后再核对实际交款。');
|
||||
if (action === 'settlement')
|
||||
html = (
|
||||
<>
|
||||
<div className="grid three">
|
||||
{dt}
|
||||
{choice(
|
||||
'转款方向',
|
||||
'direction',
|
||||
[
|
||||
['toOwner', teamMemberName('assistant') + ' → ' + teamMemberName('owner')],
|
||||
['toAssistant', teamMemberName('owner') + ' → ' + teamMemberName('assistant')],
|
||||
],
|
||||
o.settlementDue < 0 ? 'toAssistant' : 'toOwner',
|
||||
)}
|
||||
{choice(
|
||||
'本笔归属',
|
||||
'bucket',
|
||||
[
|
||||
['cost', '货款'],
|
||||
['profit', '利润'],
|
||||
],
|
||||
'cost',
|
||||
)}
|
||||
</div>
|
||||
<div className="grid two">
|
||||
{moneyField('实际转账金额', 'amount')}
|
||||
{field('转账凭据/说明', 'note', '', 'text', {
|
||||
required: true,
|
||||
maxLength: '150',
|
||||
})}
|
||||
</div>
|
||||
<p className="small muted">
|
||||
{o.ownerCredit
|
||||
? teamMemberName('owner') + '已直接收到部分客户款,先按实际情况核清归属。'
|
||||
: `货款待结 ¥${yuan(o.costDue)};利润待结 ¥${yuan(o.profitDue)}(负数为${teamMemberName('owner')}需转回)。`}
|
||||
</p>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实各人实际转账,不是仅记录计划交款。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
if (action === 'correct') {
|
||||
const valid = r =>
|
||||
!r.price_lock_event_id &&
|
||||
!o.corrections.some(c => c.target === r.id) &&
|
||||
!String(r.note || r.reference || '').startsWith('更正冲回:');
|
||||
const cardExpenseIds = new Set((o.fee_items || []).filter(isAutomaticCardFee).map(item => item.expense_id));
|
||||
const entries = [
|
||||
...(o.cancellationApproved || orderAfterSaleRecord(o) ? [] : o.payments.filter(valid)).map(r => [
|
||||
'payment:' + r.id,
|
||||
r.date +
|
||||
' ' +
|
||||
(r.kind === 'receipt' ? '客户收款' : '客户退款') +
|
||||
' ' +
|
||||
yuan(r.amount) +
|
||||
'元 ' +
|
||||
accountDisplayName(r.account),
|
||||
]),
|
||||
...(o.cancellationApproved || orderAfterSaleRecord(o)
|
||||
? []
|
||||
: o.expenses.filter(r => valid(r) && !isAutomaticCardFee(r) && !cardExpenseIds.has(r.id))
|
||||
).map(r => ['expense:' + r.id, r.date + ' 直接费用 ' + yuan(r.amount) + '元 ' + r.note]),
|
||||
...o.settlements
|
||||
.filter(valid)
|
||||
.map(r => [
|
||||
'settlement:' + r.id,
|
||||
r.date +
|
||||
' ' +
|
||||
(r.amount < 0 ? teamMemberName('owner') + '返款' : teamMemberName('assistant') + '交款') +
|
||||
' ' +
|
||||
yuan(Math.abs(r.amount)) +
|
||||
'元',
|
||||
]),
|
||||
];
|
||||
html = (
|
||||
<>
|
||||
<div className="note">
|
||||
更正录错的流水,保留原记录。填0表示撤回误记。真实客户退货请用退货入口,不要用更正代替。更正发生在所选日期,不覆盖原日记录。
|
||||
</div>
|
||||
{choice('选择原流水', 'entry', entries, entries[0]?.[0])}
|
||||
<div className="grid three">
|
||||
{dt}
|
||||
{moneyField('更正后金额(元)', 'amount')}
|
||||
<label>
|
||||
更正后收退款账户(仅收退款)
|
||||
<select name="account" defaultValue="助理微信">
|
||||
{opts(activePaymentAccounts())}
|
||||
</select>
|
||||
<small className="small muted correction-card-note" hidden={!isCreditCardAccount(ui.values?.account)}>
|
||||
信用卡统一由{teamMemberName('owner')}收款。
|
||||
</small>
|
||||
</label>
|
||||
{choice('更正后付款人(仅费用)', 'payer', teamMemberOptions(true), 'assistant')}
|
||||
{choice(
|
||||
'更正后转款方向(仅交款)',
|
||||
'direction',
|
||||
[
|
||||
['toOwner', teamMemberName('assistant') + ' → ' + teamMemberName('owner')],
|
||||
['toAssistant', teamMemberName('owner') + ' → ' + teamMemberName('assistant')],
|
||||
],
|
||||
'toOwner',
|
||||
)}
|
||||
{choice(
|
||||
'更正后款项归属(仅交款)',
|
||||
'bucket',
|
||||
[
|
||||
['cost', '货款'],
|
||||
['profit', '利润'],
|
||||
],
|
||||
'cost',
|
||||
)}
|
||||
</div>
|
||||
{field('更正原因', 'reason', '', 'text', {
|
||||
required: true,
|
||||
maxLength: '200',
|
||||
})}
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实原凭据,这次是修正登记错误。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
}
|
||||
if (['receipt', 'correct'].includes(action))
|
||||
html = (
|
||||
<>
|
||||
{html}
|
||||
{creditCardPreviewHTML('action-credit-card-fee')}
|
||||
</>
|
||||
);
|
||||
if (action === 'review')
|
||||
html = <p>确认已查看商品、克重、成本、收退款与交款凭据。复核后再有变动,会重新提示待复核。</p>;
|
||||
return (
|
||||
<form
|
||||
key={ui.formKey}
|
||||
className="panel"
|
||||
id="action-form"
|
||||
data-kind={action}
|
||||
{...(changeForm
|
||||
? {
|
||||
'data-order-change': 'true',
|
||||
'data-order-direct': !requiresApproval,
|
||||
}
|
||||
: {})}
|
||||
>
|
||||
<h2>{requiresApproval ? '申请' + orderChangeActionLabels[action] : actionName[action]}</h2>
|
||||
{changeForm ? (
|
||||
<>
|
||||
<fieldset style={{ display: 'contents' }} disabled={!!ui.stale}>
|
||||
{html}
|
||||
{orderActionChangeReviewHTML(action)}
|
||||
</fieldset>
|
||||
<div id="order-action-change-error" aria-live="polite">
|
||||
{ui.actionError && (
|
||||
<div className="error">
|
||||
{ui.actionError}
|
||||
{ui.stale && <> {button('重新读取订单后申请', 'reload-order-change')}</>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
html
|
||||
)}
|
||||
<div className="form-actions">
|
||||
<button
|
||||
className="primary"
|
||||
disabled={!!ui.stale}
|
||||
{...(changeForm
|
||||
? {
|
||||
'data-order-action-submit': '',
|
||||
}
|
||||
: {})}
|
||||
>
|
||||
{requiresApproval ? '提交变更申请' : changeForm ? '核实并保存' : '确认保存'}
|
||||
</button>
|
||||
{button('收起', 'hide-action', 'quiet')}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
return { showAction, actionInput, orderActionUsesChangeForm, orderActionRequiresApproval };
|
||||
}
|
||||
@@ -0,0 +1,825 @@
|
||||
import { Children, Fragment } from 'react';
|
||||
export function orderBook(
|
||||
{ orderBookFilters, state },
|
||||
{
|
||||
yuan,
|
||||
teamMode,
|
||||
teamMemberKeys,
|
||||
teamMemberName,
|
||||
badge,
|
||||
orderEntryTimeHTML,
|
||||
showOrderCopyEntry,
|
||||
button,
|
||||
e,
|
||||
printStatusBadge,
|
||||
orderIsReviewed,
|
||||
grams,
|
||||
validOrderDate,
|
||||
activePocketKeys,
|
||||
pocketLabel,
|
||||
accountDisplayName,
|
||||
},
|
||||
) {
|
||||
const priceLockPayerName = payer => (payer ? teamMemberName(payer) : '待补');
|
||||
function priceLockActivityRows(activity) {
|
||||
if (!activity) return [];
|
||||
return [...(activity.customerCash || []), ...(activity.orderPayments || [])]
|
||||
.map(item => ({
|
||||
...item,
|
||||
activityType: item.kind === 'receipt' ? '客户收款' : '客户退款',
|
||||
who: accountDisplayName(item.account),
|
||||
activityName: item.product || '客户收退款',
|
||||
}))
|
||||
.concat(
|
||||
(activity.materialOutlays || []).map(item => ({
|
||||
...item,
|
||||
activityType: item.source === 'extra' ? '补重料费付款' : '原锁料费付款',
|
||||
who: priceLockPayerName(item.payer),
|
||||
activityName: (item.product || '黄金') + ' · ' + grams(item.quantity) + 'g × ' + yuan(item.rate) + '元/克',
|
||||
})),
|
||||
(activity.deliveryGoodsOutlays || []).map(item => ({
|
||||
...item,
|
||||
activityType: '交付货品支出',
|
||||
who: priceLockPayerName(item.payer),
|
||||
activityName: item.name,
|
||||
})),
|
||||
(activity.directOutlays || []).map(item => ({
|
||||
...item,
|
||||
activityType: '实际费用',
|
||||
who: priceLockPayerName(item.payer),
|
||||
activityName: item.note,
|
||||
})),
|
||||
)
|
||||
.sort((a, b) => a.date.localeCompare(b.date));
|
||||
}
|
||||
function priceLockActivityHTML(activity) {
|
||||
if (!activity?.summary?.eventCount) return '';
|
||||
const s = activity.summary,
|
||||
rows = priceLockActivityRows(activity);
|
||||
return (
|
||||
<section className="panel lock-activity">
|
||||
<h2>锁价实际收付</h2>
|
||||
<p className="small muted">
|
||||
{activity.from === activity.date ? activity.date : activity.from + ' 至 ' + activity.date}
|
||||
实际发生的锁价收退款与支出。此区不随订单搜索或状态筛选变化;每日对账归集这些收付。待交付不计销售和利润;交付日计入完整订单利润,原锁料款不重复记支出。
|
||||
</p>
|
||||
<div className="lock-activity-summary">
|
||||
<span>
|
||||
客户实收<strong>¥{yuan(s.receipt)}</strong>
|
||||
</span>
|
||||
<span>
|
||||
客户实退<strong>¥{yuan(s.refund)}</strong>
|
||||
</span>
|
||||
<span>
|
||||
{teamMemberName('owner')}实际支出<strong>¥{yuan(s.ownerOutlay)}</strong>
|
||||
</span>
|
||||
<span>
|
||||
{teamMemberName('assistant')}实际支出<strong>¥{yuan(s.assistantOutlay)}</strong>
|
||||
</span>
|
||||
</div>
|
||||
<details>
|
||||
<summary>查看 {rows.length} 项收付记录</summary>
|
||||
<div className="table-wrap">
|
||||
<table className="lock-activity-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>日期/锁价单</th>
|
||||
<th>项目/客户</th>
|
||||
<th>账户/付款人</th>
|
||||
<th className="number">金额</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Children.toArray(
|
||||
rows.map(item => (
|
||||
<tr>
|
||||
<td>
|
||||
{item.date}
|
||||
<br />
|
||||
<button className="link-button" data-action="open-price-lock" data-id={item.price_lock_id}>
|
||||
{item.number || '锁价记录'}
|
||||
</button>
|
||||
</td>
|
||||
<td>
|
||||
{item.activityType} · {item.activityName}
|
||||
<div className="small muted">{item.customer}</div>
|
||||
</td>
|
||||
<td>{item.who}</td>
|
||||
<td className="number">{item.amount == null ? '待补齐' : '¥' + yuan(item.amount)}</td>
|
||||
</tr>
|
||||
)),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</details>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
const orderBookStatusOptions = [
|
||||
['', '全部状态'],
|
||||
['reviewed', '已复核'],
|
||||
['unreviewed', '未复核'],
|
||||
['after_sale', '售后'],
|
||||
['recovery', '回收'],
|
||||
['price_lock', '锁价'],
|
||||
];
|
||||
const orderBookPeriodOptions = [
|
||||
['today', '今天'],
|
||||
['yesterday', '昨天'],
|
||||
['month', '本月'],
|
||||
['date', '某天'],
|
||||
['range', '自定义区间'],
|
||||
];
|
||||
function orderBookScope() {
|
||||
return '销售与利润按开单/交付日期,售后与回收按记录日期筛选。普通订单收款显示当前累计;锁价收退款按实际发生日期计入,待交付不计销售和利润。已取消订单不计本页销售汇总;直接回收付款计入每日购料,不计销售和利润。';
|
||||
}
|
||||
function previousOrderDate(today) {
|
||||
const date = new Date(today + 'T12:00:00Z');
|
||||
date.setUTCDate(date.getUTCDate() - 1);
|
||||
return date.toISOString().slice(0, 10);
|
||||
}
|
||||
const getOrderBookFilters = () => orderBookFilters;
|
||||
function orderBookRange() {
|
||||
const f = getOrderBookFilters(),
|
||||
today = state.today;
|
||||
if (f.mode === 'range') {
|
||||
if (!f.from || !f.to) throw new Error('请选择开始日期和结束日期。');
|
||||
if (!validOrderDate(f.from) || !validOrderDate(f.to) || f.from < '2000-01-01' || f.to < '2000-01-01')
|
||||
throw new Error('日期区间无效,请选择2000-01-01起的有效日期。');
|
||||
if (f.from > today || f.to > today) throw new Error('请选择今天或之前的日期。');
|
||||
if (f.from > f.to) throw new Error('开始日期不能晚于结束日期。');
|
||||
return {
|
||||
from: f.from,
|
||||
date: f.to,
|
||||
name: '自定义区间',
|
||||
};
|
||||
}
|
||||
if (f.mode === 'date') {
|
||||
if (!f.date) throw new Error('请选择要查看的日期。');
|
||||
if (!validOrderDate(f.date)) throw new Error('日期无效,请重新选择。');
|
||||
if (f.date > today) throw new Error('请选择今天或之前的日期。');
|
||||
return {
|
||||
from: f.date,
|
||||
date: f.date,
|
||||
name: f.date,
|
||||
};
|
||||
}
|
||||
if (f.mode === 'yesterday') {
|
||||
const date = previousOrderDate(today);
|
||||
return {
|
||||
from: date,
|
||||
date,
|
||||
name: '昨日',
|
||||
};
|
||||
}
|
||||
return {
|
||||
from: f.mode === 'month' ? today.slice(0, 7) + '-01' : today,
|
||||
date: today,
|
||||
name: f.mode === 'month' ? '本月' : '今日',
|
||||
};
|
||||
}
|
||||
function orderBookPocketOptions() {
|
||||
const active = activePocketKeys(),
|
||||
historical = [
|
||||
...new Set(
|
||||
[
|
||||
...(state?.pocketCatalog || []).filter(row => !row.active).map(row => row.key),
|
||||
...(state?.orders || []).flatMap(order => (order.lines || []).map(line => line.pocket)),
|
||||
].filter(pocket => pocket && !active.includes(pocket)),
|
||||
),
|
||||
];
|
||||
return [
|
||||
['', '全部货盘'],
|
||||
['external', '配货'],
|
||||
...active.map(pocket => [pocket, pocketLabel(pocket)]),
|
||||
...historical.map(pocket => [pocket, pocketLabel(pocket) + '(已停用 · 历史)']),
|
||||
];
|
||||
}
|
||||
function orderBookMobileCards(rows, version, showCopy) {
|
||||
return (
|
||||
<div className="order-mobile-list">
|
||||
{Children.toArray(
|
||||
rows.map(row => (
|
||||
<article
|
||||
className={
|
||||
'order-mobile-card ' + (row.status === 'cancelled' || row.status === 'returned' ? 'order-reversed' : '')
|
||||
}
|
||||
>
|
||||
<div className="order-mobile-heading">{orderBookIdentity(row, version)}</div>
|
||||
<div className="order-mobile-meta">
|
||||
{row.date} · {row.kind === 'recovery' ? '已记录' : badge(row)} {orderReviewBadge(row)}
|
||||
</div>
|
||||
<div className="order-mobile-amounts">
|
||||
<div>
|
||||
<span>克重/件数{row.kind === 'recovery' ? '(折后)' : ''}</span>
|
||||
<strong>{orderBookQuantity(row)}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>售价</span>
|
||||
<strong>{orderBookMoney(row, 'sale')}</strong>
|
||||
</div>
|
||||
</div>
|
||||
{row.status === 'cancelled' ? <p className="small muted">已取消,未计入汇总</p> : ''}
|
||||
{row.balance < 0 ? <p className="small danger-text">退款待处理</p> : ''}
|
||||
<details className="order-mobile-breakdown">
|
||||
<summary>成本、利润与备注</summary>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>货盘/类型</dt>
|
||||
<dd>{row.types.map(e).join('、') || '—'}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>料成本</dt>
|
||||
<dd>{orderBookMoney(row, 'material')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>工费及附加成本</dt>
|
||||
<dd>
|
||||
{orderBookMoney(row, 'laborAndFees')}
|
||||
{orderBookFeeParts(row)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>成本合计</dt>
|
||||
<dd>
|
||||
{orderBookMoney(row, 'totalCost')}
|
||||
{row.unallocated ? <div className="small muted">含未分项 ¥{yuan(row.unallocated)}</div> : ''}
|
||||
{row.pendingCosts ? (
|
||||
<div className="small danger-text">另有 {row.pendingCosts} 项费用未入账</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>利润</dt>
|
||||
<dd>{orderBookMoney(row, 'profit')}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<div className="order-mobile-note">
|
||||
{row.kind === 'afterSale' ? afterSalePayerName(row) + '支付' : row.note || '暂无备注'}
|
||||
</div>
|
||||
<div className="order-mobile-print-status">{printStatusBadge(row)}</div>
|
||||
{row.costHint ? (
|
||||
<p className={'small ' + (row.incomplete ? 'danger-text' : 'muted')}>{row.costHint}</p>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
{!['afterSale', 'orderAfterSale', 'recovery'].includes(row.kind) ? orderEntryTimeHTML(row) : ''}
|
||||
{showCopy && !['afterSale', 'orderAfterSale', 'recovery'].includes(row.kind)
|
||||
? button('复制新增', 'copy-order', 'order-copy-button', {
|
||||
'data-id': row.id,
|
||||
})
|
||||
: ''}
|
||||
</details>
|
||||
</article>
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
function orderBookSummaryQuantity(summary) {
|
||||
return (
|
||||
<>
|
||||
{grams(summary.mg) + 'g' + (summary.pieces ? ' / ' + summary.pieces + '件' : '')}
|
||||
<div className="small muted">克重不含银饰</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
function afterSalePayerName(row) {
|
||||
return row.costItems?.[0]?.payer ? teamMemberName(row.costItems[0].payer) : '付款人待补';
|
||||
}
|
||||
function orderBookFeeParts(row) {
|
||||
if (row.kind === 'recovery') return '';
|
||||
if (row.status === 'draft') return '';
|
||||
if (row.kind === 'afterSale')
|
||||
return (
|
||||
<div className="order-fee-parts">
|
||||
<span>售后费用</span>
|
||||
</div>
|
||||
);
|
||||
if (row.kind === 'orderAfterSale')
|
||||
return (
|
||||
<div className="order-fee-parts">
|
||||
<span>原单售后成本调整</span>
|
||||
</div>
|
||||
);
|
||||
const grouped = new Map();
|
||||
for (const item of row.laborAndFeeItems || []) {
|
||||
const key = item.component + ':' + item.name,
|
||||
previous = grouped.get(key);
|
||||
grouped.set(key, {
|
||||
name: item.name,
|
||||
amount: (previous?.amount || 0) + (item.amount || 0),
|
||||
missing: previous?.missing || item.amount == null,
|
||||
});
|
||||
}
|
||||
const items = [...grouped.values()].filter(item => item.amount || item.missing);
|
||||
return items.length ? (
|
||||
<div className="order-fee-parts">
|
||||
{Children.toArray(
|
||||
items.map(item => (
|
||||
<span>
|
||||
{item.name}{' '}
|
||||
{item.missing
|
||||
? item.amount
|
||||
? '已知 ¥' + yuan(item.amount) + ',待补'
|
||||
: '待补'
|
||||
: '¥' + yuan(item.amount)}
|
||||
</span>
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
);
|
||||
}
|
||||
function orderBookMoney(row, key) {
|
||||
if (row.kind === 'recovery') return <span className="muted">—</span>;
|
||||
if (row.status === 'draft')
|
||||
return (
|
||||
<>
|
||||
<span className="muted">未开单</span>
|
||||
{key === 'sale' && row.originalSale != null ? (
|
||||
<div className="small muted">报价 ¥{yuan(row.originalSale)}</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</>
|
||||
);
|
||||
if (row[key] != null) return '¥' + yuan(row[key]);
|
||||
const known = row.known?.[key],
|
||||
unallocated = ['material', 'laborAndFees'].includes(key) && row.legacyUnallocated;
|
||||
const hint = unallocated
|
||||
? '未分项'
|
||||
: row.materialCostPending && ['material', 'totalCost', 'profit'].includes(key)
|
||||
? '料费待补'
|
||||
: key === 'profit' && row.status === 'confirmed'
|
||||
? '旧单待补齐'
|
||||
: '待补齐';
|
||||
return (
|
||||
<>
|
||||
{known ? '已知 ¥' + yuan(known) : ''}
|
||||
<div className={'small ' + (unallocated ? 'muted' : 'danger-text')}>{hint}</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
function orderBookQuantity(value) {
|
||||
return (
|
||||
[value.mg ? grams(value.mg) + 'g' : '', value.pieces ? value.pieces + '件' : ''].filter(Boolean).join(' / ') ||
|
||||
'—'
|
||||
);
|
||||
}
|
||||
function orderReviewBadge(row) {
|
||||
return orderIsReviewed(row) ? <span className="order-review-status">已复核</span> : '';
|
||||
}
|
||||
function afterSaleEditButton(row) {
|
||||
return button('修改', 'after-sale-edit', 'after-sale-edit-button', {
|
||||
'data-id': row.after_sale_id || row.id,
|
||||
'aria-label': '修改 ' + row.customer + ' 的售后记录',
|
||||
});
|
||||
}
|
||||
function orderBookIdentity(row, version) {
|
||||
if (row.kind === 'orderAfterSale')
|
||||
return (
|
||||
<button
|
||||
className="link-button order-book-link order-book-customer-first"
|
||||
data-action="open-order"
|
||||
data-id={row.order_id || row.id}
|
||||
>
|
||||
<strong className="order-book-customer-name">{row.customer || '未填称呼'}</strong>
|
||||
<span className="order-book-secondary muted">订单售后 · {row.paper_number || row.number}</span>
|
||||
<span className="small muted">查看原单售后结果</span>
|
||||
</button>
|
||||
);
|
||||
if (row.kind === 'recovery')
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
className="link-button order-book-link order-book-customer-first"
|
||||
data-action="recovery-open"
|
||||
data-id={row.recovery_id || row.id}
|
||||
>
|
||||
<span className="order-book-identity-line">
|
||||
<strong className="order-book-customer-name">{row.customer || '未填称呼'}</strong>
|
||||
<span className="order-book-recovery-badge">回收</span>
|
||||
</span>
|
||||
<span className="order-book-secondary muted">{row.number}</span>
|
||||
<span className="order-book-recovery-payment">回收付款 ¥{yuan(row.cashPayment)}</span>
|
||||
</button>
|
||||
{button('打印', 'recovery-print', 'quiet order-book-recovery-print', {
|
||||
'data-id': row.recovery_id || row.id,
|
||||
'aria-label': '打印 ' + (row.customer || '客户') + ' 的回收单',
|
||||
})}
|
||||
</>
|
||||
);
|
||||
if (version !== undefined) {
|
||||
const name = <strong className="order-book-customer-name">{row.customer || '未填称呼'}</strong>;
|
||||
const customer =
|
||||
row.recovery_mode === 'exchange' ? (
|
||||
<span className="order-book-identity-line">
|
||||
{name}
|
||||
<span className="order-book-recovery-badge is-exchange">置换</span>
|
||||
</span>
|
||||
) : (
|
||||
name
|
||||
);
|
||||
if (row.kind === 'afterSale')
|
||||
return (
|
||||
<div className="after-sale-identity order-book-customer-first">
|
||||
{customer}
|
||||
<span className="order-book-secondary muted">售后 · {row.project || row.note}</span>
|
||||
{afterSaleEditButton(row)}
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<button
|
||||
className="link-button order-book-link order-book-customer-first"
|
||||
data-action="open-order"
|
||||
data-id={row.id}
|
||||
data-order-book-version={version}
|
||||
>
|
||||
{customer}
|
||||
<span className="order-book-secondary muted">{row.paper_number || row.number}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
if (row.kind === 'afterSale')
|
||||
return (
|
||||
<div className="after-sale-identity">
|
||||
<strong>售后 · {row.project || row.note}</strong>
|
||||
<span>{row.customer}</span>
|
||||
{afterSaleEditButton(row)}
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<button
|
||||
className="link-button order-book-link"
|
||||
data-action="open-order"
|
||||
data-id={row.id}
|
||||
data-order-book-version={version}
|
||||
>
|
||||
<strong>{row.paper_number || row.number}</strong>
|
||||
<span>{row.customer || '未填称呼'}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
const card = (title, value, hint = '', emphasis = false) => (
|
||||
<div className={'stat ' + (emphasis ? 'emphasis' : '')}>
|
||||
<small>{title}</small>
|
||||
<strong>{value}</strong>
|
||||
<div className="hint">{hint}</div>
|
||||
</div>
|
||||
);
|
||||
function orderBookSummaryAmount(summary, key) {
|
||||
const missing = summary.unknownCounts?.[key] || 0,
|
||||
known = summary.knownCounts?.[key];
|
||||
if (missing && known === 0 && !summary[key] && !summary.afterSaleCount)
|
||||
return (
|
||||
<span className="muted">
|
||||
{['material', 'laborAndFees'].includes(key) && summary.unallocated ? '未分项' : '未补齐'}
|
||||
</span>
|
||||
);
|
||||
return (missing ? '已知 ' : '') + '¥' + yuan(summary[key]);
|
||||
}
|
||||
function validateOrderBook(book) {
|
||||
const s = book?.summaryWithoutCancelled,
|
||||
r = book?.receiptsWithoutCancelled;
|
||||
const amounts = [
|
||||
'sale',
|
||||
'material',
|
||||
'laborAndFees',
|
||||
'unallocated',
|
||||
'totalCost',
|
||||
'profit',
|
||||
'ownerCost',
|
||||
'assistantCost',
|
||||
];
|
||||
const counts = [
|
||||
'orderCount',
|
||||
'completedCount',
|
||||
'draftCount',
|
||||
'incompleteCount',
|
||||
'afterSaleCount',
|
||||
'recordCount',
|
||||
'mg',
|
||||
'pieces',
|
||||
'unknownCosts',
|
||||
'unknownCostCount',
|
||||
'unknownProfitCount',
|
||||
];
|
||||
if (
|
||||
!Array.isArray(book?.rows) ||
|
||||
(book.displayRows !== undefined && !Array.isArray(book.displayRows)) ||
|
||||
(book.recoveryCount !== undefined && (!Number.isSafeInteger(book.recoveryCount) || book.recoveryCount < 0)) ||
|
||||
!s ||
|
||||
!r ||
|
||||
r.basis !== 'orderDate' ||
|
||||
r.filterScope !== 'matchingOrdersWithoutCancelled' ||
|
||||
r.from !== book.from ||
|
||||
r.date !== book.date ||
|
||||
!amounts.every(
|
||||
key =>
|
||||
Number.isSafeInteger(s[key]) &&
|
||||
Number.isSafeInteger(s.knownCounts?.[key]) &&
|
||||
s.knownCounts[key] >= 0 &&
|
||||
Number.isSafeInteger(s.unknownCounts?.[key]) &&
|
||||
s.unknownCounts[key] >= 0,
|
||||
) ||
|
||||
!counts.every(key => Number.isSafeInteger(s[key]) && s[key] >= 0) ||
|
||||
!['receipt', 'refund', 'net'].every(key => Number.isSafeInteger(r[key])) ||
|
||||
!Array.isArray(r.channels) ||
|
||||
!r.channels.every(
|
||||
channel =>
|
||||
channel &&
|
||||
typeof channel.name === 'string' &&
|
||||
['receipt', 'refund', 'net'].every(key => Number.isSafeInteger(channel[key])),
|
||||
) ||
|
||||
!['wechat', 'alipay', 'cash'].every(channel => r.channels.some(item => item.channel === channel))
|
||||
)
|
||||
throw new Error('订单汇总数据尚未完整返回,请刷新后重新读取。');
|
||||
return book;
|
||||
}
|
||||
function renderOrderBook(book, range) {
|
||||
validateOrderBook(book);
|
||||
const s = book.summaryWithoutCancelled,
|
||||
receipts = book.receiptsWithoutCancelled,
|
||||
recoveryCount = book.recoveryCount || 0;
|
||||
const detailList = {
|
||||
version: 1,
|
||||
};
|
||||
const cancelledCount = book.rows.filter(row => row.status === 'cancelled').length;
|
||||
const profitMissing = s.unknownProfitCount || 0,
|
||||
costMissing = s.unknownCosts || 0,
|
||||
costPartial = (s.unknownCostCount || 0) > 0 || costMissing > 0;
|
||||
const countHints = [
|
||||
`已完成 ${s.completedCount} 单`,
|
||||
recoveryCount ? `另有回收 ${recoveryCount} 笔` : null,
|
||||
s.afterSaleCount ? `另有售后 ${s.afterSaleCount} 笔` : null,
|
||||
s.draftCount ? `旧草稿 ${s.draftCount} 单` : null,
|
||||
s.incompleteCount ? `${s.incompleteCount} 单账务待补齐` : null,
|
||||
cancelledCount ? `${cancelledCount} 单取消未计汇总` : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
const channels = ['wechat', 'alipay', 'cash', 'credit_card']
|
||||
.map(
|
||||
channel =>
|
||||
receipts.channels.find(r => r.channel === channel) || {
|
||||
channel,
|
||||
name: {
|
||||
wechat: '微信',
|
||||
alipay: '支付宝',
|
||||
cash: '现金',
|
||||
credit_card: '信用卡',
|
||||
}[channel],
|
||||
receipt: 0,
|
||||
refund: 0,
|
||||
},
|
||||
)
|
||||
.filter(r => !['cash', 'credit_card'].includes(r.channel) || r.receipt !== 0 || r.refund !== 0);
|
||||
const receiptDetails = (
|
||||
<>
|
||||
<div className="order-stat-lines">
|
||||
{Children.toArray(
|
||||
channels.map(r => (
|
||||
<span>
|
||||
<b>{r.name}</b>
|
||||
<span>¥{yuan(r.receipt)}</span>
|
||||
</span>
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
<div className="order-stat-refund">退款 ¥{yuan(receipts.refund)}</div>
|
||||
</>
|
||||
);
|
||||
const costDetails = (
|
||||
<>
|
||||
<div className="order-stat-lines">
|
||||
{Children.toArray(
|
||||
(teamMode() ? teamMemberKeys() : ['owner', 'assistant']).map(member => (
|
||||
<span>
|
||||
<b>{teamMemberName(member)}</b>
|
||||
<span>{orderBookSummaryAmount(s, member + 'Cost')}</span>
|
||||
</span>
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
{costPartial ? (
|
||||
<div className="order-stat-refund danger-text">
|
||||
{s.unknownCostCount ? `${s.unknownCostCount} 单成本未补齐` : ''}
|
||||
{s.unknownCostCount && costMissing ? ' · ' : ''}
|
||||
{costMissing ? `${costMissing} 项成本未补齐/未入账` : ''}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</>
|
||||
);
|
||||
const costValue =
|
||||
s.unknownCostCount && s.knownCounts?.totalCost === 0 && !s.totalCost && !s.afterSaleCount
|
||||
? '未补齐'
|
||||
: '¥' + yuan(s.totalCost);
|
||||
const cards = (
|
||||
<>
|
||||
{card(
|
||||
range.name + '销售订单',
|
||||
<>
|
||||
{s.orderCount}
|
||||
<span className="stat-unit">单</span>
|
||||
</>,
|
||||
countHints,
|
||||
)}
|
||||
{card(
|
||||
range.name + '利润' + (profitMissing ? '(已核算部分)' : ''),
|
||||
profitMissing && s.knownCounts?.profit === 0 && !s.profit && !s.afterSaleCount
|
||||
? '待补齐'
|
||||
: '¥' + yuan(s.profit),
|
||||
profitMissing ? profitMissing + ' 单利润待补齐' : '已扣货品成本、实际费用和售后费用',
|
||||
true,
|
||||
)}
|
||||
{card(range.name + '收款', '¥' + yuan(receipts.receipt), receiptDetails)}
|
||||
{card(range.name + '成本' + (costPartial ? '(已知部分)' : ''), costValue, costDetails)}
|
||||
</>
|
||||
);
|
||||
const count = `${range.name} · 汇总 ${s.orderCount} 单${recoveryCount ? ' · 回收 ' + recoveryCount + ' 笔' : ''}${s.afterSaleCount ? ' · 售后 ' + s.afterSaleCount + ' 笔' : ''}${cancelledCount ? ',另有 ' + cancelledCount + ' 单取消未计' : ''}${orderBookFilters.q || orderBookFilters.status || orderBookFilters.pocket || orderBookFilters.member ? '(已筛选)' : ''}`;
|
||||
const rows = book.displayRows ?? book.rows;
|
||||
if (!rows.length) {
|
||||
const list = (
|
||||
<div className="empty">
|
||||
<strong>这个日期没有符合条件的订单、回收或售后</strong>可以切换日期,或调整搜索和状态筛选。
|
||||
</div>
|
||||
);
|
||||
return {
|
||||
cards,
|
||||
count,
|
||||
list,
|
||||
};
|
||||
}
|
||||
const table = (
|
||||
<div className="table-wrap order-book-table-wrap">
|
||||
<table className="order-book-table" aria-label={range.name + '订单账本'}>
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="order-index">序号</th>
|
||||
<th>客户/销售、回收或售后</th>
|
||||
<th>类型</th>
|
||||
<th className="number">克重/件数</th>
|
||||
<th className="number">售价</th>
|
||||
<th className="number">料成本</th>
|
||||
<th className="number">工费及附加成本</th>
|
||||
<th className="number">成本合计</th>
|
||||
<th className="number">利润</th>
|
||||
<th>备注</th>
|
||||
<th className="order-print-status">打印状态</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Children.toArray(
|
||||
rows.map((row, i) => (
|
||||
<tr
|
||||
className={
|
||||
['afterSale', 'orderAfterSale'].includes(row.kind)
|
||||
? 'order-after-sale'
|
||||
: row.kind === 'recovery'
|
||||
? 'order-recovery'
|
||||
: row.status === 'draft'
|
||||
? 'order-draft'
|
||||
: row.status === 'returned' || row.status === 'cancelled'
|
||||
? 'order-reversed'
|
||||
: ''
|
||||
}
|
||||
>
|
||||
<td className="order-index">{i + 1}</td>
|
||||
<td className="order-customer">
|
||||
{orderBookIdentity(row, detailList.version)}
|
||||
<div className="small muted">
|
||||
业务日期 {row.date} ·{' '}
|
||||
{row.kind === 'recovery' ? <span className="order-status muted">已记录</span> : badge(row)}
|
||||
{orderReviewBadge(row)}
|
||||
</div>
|
||||
{!['afterSale', 'orderAfterSale', 'recovery'].includes(row.kind) ? orderEntryTimeHTML(row) : ''}
|
||||
{showOrderCopyEntry && !['afterSale', 'orderAfterSale', 'recovery'].includes(row.kind)
|
||||
? button(
|
||||
<>
|
||||
<span aria-hidden="true">+</span>复制新增
|
||||
</>,
|
||||
'copy-order',
|
||||
'order-copy-button',
|
||||
{
|
||||
'data-id': row.id,
|
||||
'aria-label': '复制 ' + (row.paper_number || row.number) + ' 为新订单',
|
||||
},
|
||||
)
|
||||
: ''}
|
||||
{row.status === 'cancelled' ? <div className="small muted">未计入汇总</div> : ''}
|
||||
{row.balance < 0 ? <div className="small danger-text">退款待处理</div> : ''}
|
||||
</td>
|
||||
<td className="order-type">
|
||||
{row.types.map(e).map((part, i) => (
|
||||
<Fragment key={i}>
|
||||
{i > 0 && <br />}
|
||||
{part}
|
||||
</Fragment>
|
||||
)) || '—'}
|
||||
</td>
|
||||
<td className="number">
|
||||
{orderBookQuantity(row)}
|
||||
{row.kind === 'recovery' ? <div className="small muted">折后克重</div> : ''}
|
||||
</td>
|
||||
<td className="number">{orderBookMoney(row, 'sale')}</td>
|
||||
<td className="number">{orderBookMoney(row, 'material')}</td>
|
||||
<td className="number order-fees">
|
||||
{orderBookMoney(row, 'laborAndFees')}
|
||||
{orderBookFeeParts(row)}
|
||||
</td>
|
||||
<td className="number">
|
||||
{orderBookMoney(row, 'totalCost')}
|
||||
{row.unallocated ? <div className="small muted">含未分项 ¥{yuan(row.unallocated)}</div> : ''}
|
||||
{row.pendingCosts ? (
|
||||
<div className="small danger-text">另有 {row.pendingCosts} 项费用未入账</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</td>
|
||||
<td className="number order-profit">{orderBookMoney(row, 'profit')}</td>
|
||||
<td className="order-notes">
|
||||
{row.kind === 'afterSale'
|
||||
? afterSalePayerName(row) + '支付'
|
||||
: row.note || <span className="muted">—</span>}
|
||||
{row.costHint ? (
|
||||
<div className={'small ' + (row.incomplete ? 'danger-text' : 'muted')}>{row.costHint}</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</td>
|
||||
<td className="order-print-status">{printStatusBadge(row) || '—'}</td>
|
||||
</tr>
|
||||
)),
|
||||
)}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colSpan="2">
|
||||
汇总 {s.orderCount} 单
|
||||
{recoveryCount ? (
|
||||
<>
|
||||
<br />
|
||||
回收 {recoveryCount} 笔
|
||||
</>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
{s.afterSaleCount ? (
|
||||
<>
|
||||
<br />
|
||||
售后 {s.afterSaleCount} 笔
|
||||
</>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</td>
|
||||
<td></td>
|
||||
<td className="number">{orderBookSummaryQuantity(s)}</td>
|
||||
<td className="number">{orderBookSummaryAmount(s, 'sale')}</td>
|
||||
<td className="number">{orderBookSummaryAmount(s, 'material')}</td>
|
||||
<td className="number">{orderBookSummaryAmount(s, 'laborAndFees')}</td>
|
||||
<td className="number">
|
||||
{costPartial ? '已知 ' : ''}¥{yuan(s.totalCost)}
|
||||
{s.unallocated ? <div className="small muted">含未分项 ¥{yuan(s.unallocated)}</div> : ''}
|
||||
</td>
|
||||
<td className="number">{orderBookSummaryAmount(s, 'profit')}</td>
|
||||
<td className="small order-notes">
|
||||
{[
|
||||
cancelledCount ? cancelledCount + ' 单取消未计汇总' : '',
|
||||
s.draftCount ? s.draftCount + ' 单草稿未计金额' : '',
|
||||
s.unknownCostCount ? s.unknownCostCount + ' 单成本未补齐' : '',
|
||||
profitMissing ? profitMissing + ' 单利润待补齐' : '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(';') || '账本金额'}
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
return {
|
||||
cards,
|
||||
count,
|
||||
list: [table, orderBookMobileCards(rows, 1, showOrderCopyEntry)],
|
||||
};
|
||||
}
|
||||
return {
|
||||
renderOrderBook,
|
||||
orderBookRange,
|
||||
orderBookPocketOptions,
|
||||
orderBookScope,
|
||||
orderBookPeriodOptions,
|
||||
orderBookStatusOptions,
|
||||
priceLockActivityHTML,
|
||||
teamMemberName,
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,767 @@
|
||||
import { Children } from 'react';
|
||||
export function orderReviews(
|
||||
{
|
||||
state,
|
||||
currentOrder,
|
||||
orderChangeDetail,
|
||||
orderOwnershipDetail,
|
||||
orderCancellationDetail,
|
||||
orderChangeListStatus,
|
||||
orderOwnershipListStatus,
|
||||
orderCancellationListStatus,
|
||||
},
|
||||
{
|
||||
orderChangeActionLabel,
|
||||
orderChangeTime,
|
||||
orderChangeActionSummaryHTML,
|
||||
orderChangeComparisonHTML,
|
||||
button,
|
||||
teamMemberEnabled,
|
||||
opts,
|
||||
orderOwnershipEffectHTML,
|
||||
orderOwnershipPairHTML,
|
||||
orderOwnershipTime,
|
||||
orderCancellationCanDirect,
|
||||
orderCancellationTime,
|
||||
validateOrderCancellationSummary,
|
||||
yuan,
|
||||
pocketLabel,
|
||||
grams,
|
||||
inventoryCountHTML,
|
||||
orderCancellationStatus,
|
||||
orderChangeMoney,
|
||||
orderChangeStatus,
|
||||
orderOwnershipStatus,
|
||||
validateOrderChangeRequest,
|
||||
validateOrderOwnershipRequest,
|
||||
},
|
||||
) {
|
||||
function orderCancellationRecordStatus(request) {
|
||||
return request.direct === true ? '当天直接取消' : orderCancellationStatus[request.status];
|
||||
}
|
||||
function orderCancellationListHTML(result) {
|
||||
const owner = state.user.role === 'owner' && result.canApprove;
|
||||
return (
|
||||
<>
|
||||
<div className="cancellation-list-tabs" role="group" aria-label="取消申请状态">
|
||||
{Children.toArray(
|
||||
[
|
||||
['pending', '待复核'],
|
||||
['approved', '已取消'],
|
||||
['rejected', '已驳回'],
|
||||
['all', '全部'],
|
||||
].map(([value, name]) =>
|
||||
button(
|
||||
name + (value === 'all' ? '' : '(' + result.counts[value] + ')'),
|
||||
'filter-order-cancellations',
|
||||
orderCancellationListStatus === value ? 'primary' : '',
|
||||
{
|
||||
'data-status': value,
|
||||
'aria-pressed': orderCancellationListStatus === value,
|
||||
},
|
||||
),
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
{result.requests.length ? (
|
||||
<div className="table-wrap">
|
||||
<table className="cancellation-list-table" aria-label="全部日期的取消申请">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>原订单/日期</th>
|
||||
<th>经办/申请人及时间</th>
|
||||
<th>取消原因</th>
|
||||
<th>状态/处理记录</th>
|
||||
<th>查看</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Children.toArray(
|
||||
result.requests.map(request => (
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{request.order_number}</strong>
|
||||
<div className="small muted">{request.order_date}</div>
|
||||
<div className="small">原成交 ¥{yuan(request.summary.total)}</div>
|
||||
</td>
|
||||
<td>
|
||||
{request.direct === true ? '经办人:' : ''}
|
||||
{request.operator_name || request.requester_name}
|
||||
<div className="small muted">
|
||||
{orderCancellationTime(request.executedAt || request.created)}
|
||||
</div>
|
||||
</td>
|
||||
<td className="cancellation-reason">{request.reason}</td>
|
||||
<td>
|
||||
{orderCancellationRecordStatus(request)}
|
||||
{request.stale && request.status === 'pending' ? (
|
||||
<div className="small danger-text">原单已有变动,需驳回后重新申请</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
{request.note ? <div className="small cancellation-reason">{request.note}</div> : ''}
|
||||
{request.reviewer_name ? (
|
||||
<div className="small muted">
|
||||
{request.reviewer_name} · {orderCancellationTime(request.reviewed)}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
{button(
|
||||
owner && request.status === 'pending' ? '查看并复核' : '查看订单',
|
||||
'open-cancellation-order',
|
||||
'',
|
||||
{
|
||||
'data-id': request.order_id,
|
||||
},
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="empty">全部日期均无此状态的取消申请。</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
function orderOwnershipListHTML(result) {
|
||||
const owner = state.user.role === 'owner' && result.canApprove;
|
||||
return (
|
||||
<>
|
||||
<div className="change-list-tabs" role="group" aria-label="归属申请状态">
|
||||
{Children.toArray(
|
||||
[
|
||||
['pending', '待复核'],
|
||||
['approved', '已修改'],
|
||||
['rejected', '已驳回'],
|
||||
['all', '全部'],
|
||||
].map(([status, name]) =>
|
||||
button(
|
||||
name + (status === 'all' ? '' : '(' + result.counts[status] + ')'),
|
||||
'order-ownership-filter',
|
||||
orderOwnershipListStatus === status ? 'primary' : '',
|
||||
{
|
||||
'data-status': status,
|
||||
'aria-pressed': orderOwnershipListStatus === status,
|
||||
},
|
||||
),
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
{result.requests.length ? (
|
||||
<div className="table-wrap">
|
||||
<table className="change-list-table" aria-label="全部日期的归属申请">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>订单/日期</th>
|
||||
<th>归属修改</th>
|
||||
<th>申请人/原因</th>
|
||||
<th>复核结果</th>
|
||||
<th>查看</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Children.toArray(
|
||||
result.requests.map(request => (
|
||||
<tr>
|
||||
<td>
|
||||
<strong className="order-ownership-list-customer">
|
||||
{request.order_customer || '未填客户称呼'}
|
||||
</strong>
|
||||
<div className="small muted">
|
||||
{request.order_number} · {request.order_date}
|
||||
</div>
|
||||
</td>
|
||||
<td>{orderOwnershipPairHTML(request)}</td>
|
||||
<td>
|
||||
{request.requester_name}
|
||||
<div className="small muted">{orderOwnershipTime(request.created)}</div>
|
||||
<p className="change-reason">{request.reason}</p>
|
||||
</td>
|
||||
<td>
|
||||
{orderOwnershipStatus[request.status]}
|
||||
{request.stale && request.status === 'pending' ? (
|
||||
<div className="small danger-text">订单已有变动,需驳回后重申</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
{request.note ? <p className="small change-reason">{request.note}</p> : ''}
|
||||
{request.reviewer_name ? (
|
||||
<div className="small muted">
|
||||
{request.reviewer_name} · {orderOwnershipTime(request.reviewed)}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
{button(
|
||||
owner && request.status === 'pending' ? '查看并复核' : '查看订单',
|
||||
'order-ownership-open-order',
|
||||
'',
|
||||
{
|
||||
'data-id': request.order_id,
|
||||
},
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="empty">全部日期均无此状态的归属申请。</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
function orderChangeListHTML(result) {
|
||||
const owner = state.user.role === 'owner' && result.canApprove;
|
||||
return (
|
||||
<>
|
||||
<div className="change-list-tabs" role="group" aria-label="变更申请状态">
|
||||
{Children.toArray(
|
||||
[
|
||||
['pending', '待复核'],
|
||||
['approved', '已同意'],
|
||||
['rejected', '已驳回'],
|
||||
['all', '全部'],
|
||||
].map(([value, name]) =>
|
||||
button(
|
||||
name + (value === 'all' ? '' : '(' + result.counts[value] + ')'),
|
||||
'filter-order-changes',
|
||||
orderChangeListStatus === value ? 'primary' : '',
|
||||
{
|
||||
'data-status': value,
|
||||
'aria-pressed': orderChangeListStatus === value,
|
||||
},
|
||||
),
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
{result.requests.length ? (
|
||||
<div className="table-wrap">
|
||||
<table className="change-list-table" aria-label="全部日期的变更申请">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>原订单/日期</th>
|
||||
<th>申请人/申请时间</th>
|
||||
<th>动作/申请原因</th>
|
||||
<th>状态/复核意见</th>
|
||||
<th>查看</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Children.toArray(
|
||||
result.requests.map(request => (
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{request.order_number}</strong>
|
||||
<div className="small muted">{request.order_date}</div>
|
||||
<div className="small">
|
||||
原成交 {orderChangeMoney(request.summary.before.total)}
|
||||
<br />
|
||||
申请成交 {orderChangeMoney(request.summary.after.total)}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{request.requester_name}
|
||||
<div className="small muted">{orderChangeTime(request.created)}</div>
|
||||
</td>
|
||||
<td className="change-reason">
|
||||
<strong>{orderChangeActionLabel(request)}</strong>
|
||||
<br />
|
||||
{request.reason}
|
||||
</td>
|
||||
<td>
|
||||
{orderChangeStatus[request.status]}
|
||||
{request.stale && request.status === 'pending' ? (
|
||||
<div className="small danger-text">原单已有变动,需驳回后重新申请</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
{request.note ? <div className="small change-reason">{request.note}</div> : ''}
|
||||
{request.reviewer_name ? (
|
||||
<div className="small muted">
|
||||
{request.reviewer_name} · {orderChangeTime(request.reviewed)}
|
||||
</div>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
{button(
|
||||
owner && request.status === 'pending' ? '查看并复核' : '查看订单',
|
||||
'open-change-order',
|
||||
'',
|
||||
{
|
||||
'data-id': request.order_id,
|
||||
},
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
)),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="empty">全部日期均无此状态的变更申请。</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
function legacyCountConfirmationHTML(value) {
|
||||
return value?.requiresLegacyCountVerified ? (
|
||||
<>
|
||||
<div className="note">
|
||||
{value.legacyCountNotice ||
|
||||
'这笔历史记录未记录对数,当前对数按实际盘点基准保留。本次旧重量冲回不自动更改当前对数,如实物有变化请另做当天对数调整。'}
|
||||
</div>
|
||||
<label className="check">
|
||||
<input name="legacyCountVerified" type="checkbox" required />
|
||||
已核对当前对数基准,理解本次更正对历史对数的处理
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
''
|
||||
);
|
||||
}
|
||||
function validateOrderCancellationRequest(request, orderId) {
|
||||
const summary = request?.summary,
|
||||
nullable = value => value === null || Number.isSafeInteger(value);
|
||||
if (
|
||||
!request ||
|
||||
typeof request.id !== 'string' ||
|
||||
!request.id ||
|
||||
typeof request.order_id !== 'string' ||
|
||||
(orderId && request.order_id !== orderId) ||
|
||||
!Object.hasOwn(orderCancellationStatus, request.status) ||
|
||||
!Number.isSafeInteger(request.order_revision) ||
|
||||
typeof request.reason !== 'string' ||
|
||||
typeof request.requester_name !== 'string' ||
|
||||
typeof request.created !== 'string' ||
|
||||
typeof request.stale !== 'boolean' ||
|
||||
typeof request.canApprove !== 'boolean' ||
|
||||
!summary ||
|
||||
!['total', 'netReceived', 'directCost'].every(key => Number.isSafeInteger(summary[key])) ||
|
||||
!['goodsCost', 'profit', 'settlementDue'].every(key => nullable(summary[key])) ||
|
||||
!Array.isArray(summary.inventory) ||
|
||||
!summary.inventory.every(
|
||||
item => typeof item.date === 'string' && typeof item.pocket === 'string' && Number.isSafeInteger(item.mg),
|
||||
)
|
||||
)
|
||||
throw new Error('取消申请资料未完整返回,请重新读取订单后复核。');
|
||||
return request;
|
||||
}
|
||||
function orderCancellationSummaryHTML(request) {
|
||||
return orderCancellationSummaryDataHTML(validateOrderCancellationRequest(request).summary);
|
||||
}
|
||||
function orderCancellationSummaryDataHTML(value) {
|
||||
const summary = validateOrderCancellationSummary(value),
|
||||
amount = value => (value === null ? '待补齐' : '¥' + yuan(value));
|
||||
return (
|
||||
<>
|
||||
<div className="note">本次按“录错作废”撤销本单记账,不是实际退货退款。原单和冲回明细保留,不会向客户付款。</div>
|
||||
<dl className="cancellation-summary">
|
||||
<div>
|
||||
<dt>撤销原成交金额</dt>
|
||||
<dd>{amount(summary.total)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>撤销收款净额</dt>
|
||||
<dd>{amount(summary.netReceived)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>撤销货品成本</dt>
|
||||
<dd>{amount(summary.goodsCost)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>撤销已记费用</dt>
|
||||
<dd>{amount(summary.directCost)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>撤销原记账利润</dt>
|
||||
<dd>{amount(summary.profit)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>当前双方待结净额</dt>
|
||||
<dd>{amount(summary.settlementDue)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<h3>库存冲回摘要</h3>
|
||||
{summary.legacyCountNotice ? <p className="note">{summary.legacyCountNotice}</p> : ''}
|
||||
{summary.inventory.length ? (
|
||||
<div className="table-wrap">
|
||||
<table aria-label="取消后库存冲回摘要">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>原日期</th>
|
||||
<th>货盘</th>
|
||||
<th className="number">恢复/冲回克重</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{Children.toArray(
|
||||
summary.inventory.map(item => (
|
||||
<tr>
|
||||
<td>{item.date}</td>
|
||||
<td>{pocketLabel(item.pocket)}</td>
|
||||
<td className="number">
|
||||
{item.mg > 0 ? '+' : ''}
|
||||
{grams(item.mg)}g
|
||||
{inventoryCountHTML(item, {
|
||||
signed: true,
|
||||
})}
|
||||
</td>
|
||||
</tr>
|
||||
)),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<p className="small muted">本单没有需要冲回的库存出入。</p>
|
||||
)}
|
||||
<p className="small muted cancellation-summary-note">
|
||||
按原日期、原货盘冲回库存。收款与费用撤回后仍能查看原记录和冲回行;双方实际交款保留,不会自动抹掉或转账。日购料真实采购付款保留,本单耗用将释放并重算相关成本与待结金额。
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
const requireOrderCancellationDetail = () => ({
|
||||
order: currentOrder,
|
||||
data: orderCancellationDetail.data,
|
||||
});
|
||||
function showOrderCancellationForm(kind) {
|
||||
const { order, data } = requireOrderCancellationDetail(),
|
||||
request = data.pending;
|
||||
if (kind === 'request' && orderCancellationCanDirect(order)) kind = 'direct';
|
||||
if (
|
||||
['request', 'direct'].includes(kind) &&
|
||||
(!data.eligible || request || !['draft', 'confirmed', 'delivered'].includes(order.status))
|
||||
)
|
||||
throw new Error(data.reason || '这张订单当前不能申请取消。');
|
||||
if (kind === 'direct' && !orderCancellationCanDirect(order)) throw new Error('当前不能直接取消,请重新读取订单。');
|
||||
if (
|
||||
!['request', 'direct'].includes(kind) &&
|
||||
(state.user.role !== 'owner' || !data.canApprove || request?.status !== 'pending')
|
||||
)
|
||||
throw new Error('取消申请由店主账号复核。');
|
||||
if (kind === 'approve' && (!request.canApprove || request.stale || request.order_revision !== order.revision))
|
||||
throw new Error('订单已有变动,请重新读取后复核;过期申请需驳回后重新申请。');
|
||||
let html, title, submit;
|
||||
if (kind === 'direct') {
|
||||
title = '取消今天的订单';
|
||||
submit = '核实并取消订单';
|
||||
html = (
|
||||
<>
|
||||
<div className="note" id="order-cancellation-mode">
|
||||
这张订单是今天开的,核实后直接按录错作废,无需另行审批。业务日期:{data.directActionDate}
|
||||
。本入口不办理真实退货或退款。
|
||||
</div>
|
||||
<input type="hidden" name="date" defaultValue={data.directActionDate} />
|
||||
{orderCancellationSummaryDataHTML(data.summary)}
|
||||
<label>
|
||||
取消原因
|
||||
<textarea
|
||||
name="reason"
|
||||
rows="3"
|
||||
required
|
||||
maxLength="200"
|
||||
placeholder="写清这张单录错的原因,例如:同一笔销售重复录入。"
|
||||
></textarea>
|
||||
</label>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实这是录错作废,并确认撤销上述记账和冲回库存;本次不登记真实退货退款。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
} else if (kind === 'request') {
|
||||
title = '申请取消这张订单';
|
||||
submit = '提交取消申请';
|
||||
html = (
|
||||
<>
|
||||
<p>
|
||||
仅用于开错、重复录入等需要整单作废的登记错误。提交后仍按原单计账,店主同意后才取消、恢复库存并撤销本单销售、成本、收款和费用记账。
|
||||
</p>
|
||||
<p className="small muted">真实退货请从“整单退货”办理;这里不会发起真实退款。</p>
|
||||
<label>
|
||||
取消原因
|
||||
<textarea
|
||||
name="reason"
|
||||
rows="3"
|
||||
required
|
||||
maxLength="200"
|
||||
placeholder="写清这张单录错的原因,例如:同一笔销售重复录入。"
|
||||
></textarea>
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
} else if (kind === 'approve') {
|
||||
title = '复核并同意取消';
|
||||
submit = '同意取消并作废';
|
||||
html = (
|
||||
<>
|
||||
<p>
|
||||
申请人:{request.requester_name} · {orderCancellationTime(request.created)}
|
||||
</p>
|
||||
<p className="cancellation-reason">取消原因:{request.reason}</p>
|
||||
{orderCancellationSummaryHTML(request)}
|
||||
<label>
|
||||
复核备注(选填)<textarea name="note" maxLength="200" rows="2"></textarea>
|
||||
</label>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核实这是录错作废,并确认撤销上述记账和冲回库存;本次不登记真实退货退款。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
} else if (kind === 'reject') {
|
||||
title = '驳回取消申请';
|
||||
submit = '确认驳回';
|
||||
html = (
|
||||
<>
|
||||
<p className="cancellation-reason">取消原因:{request.reason}</p>
|
||||
<p className="small muted">驳回后原订单继续计账,申请人可核对后重新申请。</p>
|
||||
<label>
|
||||
驳回意见
|
||||
<textarea
|
||||
name="note"
|
||||
rows="3"
|
||||
required
|
||||
maxLength="200"
|
||||
placeholder="写清需要补充或重新核对的地方。"
|
||||
></textarea>
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
} else throw new Error('取消操作无效,请重新读取订单。');
|
||||
if (kind !== 'reject')
|
||||
html = (
|
||||
<>
|
||||
{html}
|
||||
{legacyCountConfirmationHTML(
|
||||
kind === 'approve' ? request.summary : data.requiresLegacyCountVerified ? data : data.summary,
|
||||
)}
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<form className="panel order-cancellation-form" id="order-cancellation-form" data-kind={kind}>
|
||||
<h2>{title}</h2>
|
||||
{html}
|
||||
<div id="order-cancellation-error" aria-live="polite"></div>
|
||||
<div className="form-actions">
|
||||
<button
|
||||
type="submit"
|
||||
data-order-cancellation-submit=""
|
||||
className={['approve', 'direct'].includes(kind) ? 'danger' : 'primary'}
|
||||
>
|
||||
{submit}
|
||||
</button>
|
||||
{button('收起', 'close-order-cancellation-form', 'quiet')}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
const requireOrderOwnershipDetail = () => ({
|
||||
order: currentOrder,
|
||||
data: orderOwnershipDetail.data,
|
||||
});
|
||||
function showOrderOwnershipForm(kind = 'request') {
|
||||
const { order, data } = requireOrderOwnershipDetail(),
|
||||
request = data.pending;
|
||||
if (!['request', 'approve', 'reject'].includes(kind)) throw new Error('归属修改操作无效,请重新读取。');
|
||||
if (kind === 'request' && (!data.eligible || request)) throw new Error(data.reason || '本单当前不能重复修改归属。');
|
||||
if (kind !== 'request' && (state.user.role !== 'owner' || !data.canApprove || request?.status !== 'pending'))
|
||||
throw new Error('归属申请由店主账号复核。');
|
||||
if (kind === 'approve' && (!request.canApprove || request.stale || request.order_revision !== order.revision))
|
||||
throw new Error('订单已有变动,请驳回旧申请后按最新订单重新核对。');
|
||||
const direct = kind === 'request' && state.user.role === 'owner' && data.canDirect;
|
||||
if (kind === 'request' && state.user.role === 'owner' && !direct)
|
||||
throw new Error(data.reason || '当前不能直接修改归属,请重新读取订单。');
|
||||
let title, html, submit;
|
||||
if (kind === 'request') {
|
||||
title = direct ? '修改订单归属' : '申请修改订单归属';
|
||||
submit = direct ? '确认修改归属' : '提交归属申请';
|
||||
const before = data.members.find(member => member.member === data.member),
|
||||
members = data.members.filter(
|
||||
member => member.member !== data.member && member.enabled !== false && teamMemberEnabled(member.member),
|
||||
);
|
||||
html = (
|
||||
<>
|
||||
<div className="note">
|
||||
{direct ? '店主核对后直接生效。' : '提交后等待店主复核,今天的订单也须审批;批准前继续按原归属计账。'}
|
||||
</div>
|
||||
<div className="grid two">
|
||||
<label>
|
||||
当前归属
|
||||
<input defaultValue={before.label} readOnly />
|
||||
</label>
|
||||
<label>
|
||||
修改为
|
||||
<select name="member" required defaultValue="">
|
||||
{opts([['', '请选择新归属'], ...members.map(member => [member.member, member.label])])}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<p className="order-ownership-selection" id="order-ownership-selection" aria-live="polite">
|
||||
{before.label} → 请选择新归属
|
||||
</p>
|
||||
{orderOwnershipEffectHTML(data.member)}
|
||||
<label>
|
||||
修改原因
|
||||
<textarea
|
||||
name="reason"
|
||||
required
|
||||
maxLength="200"
|
||||
rows="3"
|
||||
placeholder="写清原归属录错的原因及正确归属。"
|
||||
></textarea>
|
||||
</label>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核对原归属、新归属和修改原因,确认本次归属{direct ? '更正' : '申请'}。
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
} else {
|
||||
title = kind === 'approve' ? '复核并同意修改归属' : '驳回归属申请';
|
||||
submit = kind === 'approve' ? '同意并修改归属' : '确认驳回';
|
||||
html = (
|
||||
<>
|
||||
{orderOwnershipPairHTML(request)}
|
||||
<p>
|
||||
申请人:{request.requester_name} · {orderOwnershipTime(request.created)}
|
||||
</p>
|
||||
<p className="change-reason">修改原因:{request.reason}</p>
|
||||
{kind === 'approve' ? (
|
||||
<>
|
||||
{orderOwnershipEffectHTML(request.before.member)}
|
||||
<label>
|
||||
复核备注(选填)<textarea name="note" maxLength="200" rows="2"></textarea>
|
||||
</label>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核对原归属、新归属和原因,同意后按新归属统计,并更新原助理的查看权限。
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<p className="small muted">驳回后保留原归属,申请人可核对后重新申请。</p>
|
||||
<label>
|
||||
驳回意见
|
||||
<textarea
|
||||
name="note"
|
||||
required
|
||||
maxLength="200"
|
||||
rows="3"
|
||||
placeholder="写清需要重新核对的地方。"
|
||||
></textarea>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<form id="order-ownership-form" className="panel order-ownership-form" data-kind={kind}>
|
||||
<h2>{title}</h2>
|
||||
{html}
|
||||
<div id="order-ownership-error" aria-live="polite"></div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="primary">
|
||||
{submit}
|
||||
</button>
|
||||
{button('收起', 'order-ownership-close-form', 'quiet')}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
const requireOrderChangeDetail = () => ({
|
||||
order: currentOrder,
|
||||
data: orderChangeDetail.data,
|
||||
});
|
||||
function showOrderChangeForm(kind) {
|
||||
const { order, data } = requireOrderChangeDetail(),
|
||||
request = data.pending;
|
||||
if (!['approve', 'reject'].includes(kind)) throw new Error('修改复核操作无效,请重新读取订单。');
|
||||
if (state.user.role !== 'owner' || !data.canApprove || request?.status !== 'pending')
|
||||
throw new Error('修改申请由店主账号复核。');
|
||||
if (kind === 'approve' && (!request.canApprove || request.stale || request.order_revision !== order.revision))
|
||||
throw new Error('订单已有变动,请重新读取后复核;过期申请需驳回后重新申请。');
|
||||
const reason = (
|
||||
<>
|
||||
<p>
|
||||
<strong>本次申请:{orderChangeActionLabel(request)}</strong>
|
||||
</p>
|
||||
<p>
|
||||
申请人:{request.requester_name} · {orderChangeTime(request.created)}
|
||||
</p>
|
||||
<p className="change-reason">申请原因:{request.reason}</p>
|
||||
</>
|
||||
);
|
||||
const html =
|
||||
kind === 'approve' ? (
|
||||
<>
|
||||
{reason}
|
||||
{orderChangeActionSummaryHTML(request)}
|
||||
{orderChangeComparisonHTML(request)}
|
||||
<label>
|
||||
复核备注(选填)<textarea name="note" maxLength="200" rows="2"></textarea>
|
||||
</label>
|
||||
<label className="check">
|
||||
<input type="checkbox" name="verified" required />
|
||||
已核对本次申请动作、金额、日期、账户或付款人、退货去向及库存,确认原值与申请值,以及以上关联订单的本次修改。
|
||||
</label>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{reason}
|
||||
<p>驳回后原单继续计账,申请人可按最新原单重新申请。</p>
|
||||
<label>
|
||||
驳回意见
|
||||
<textarea
|
||||
name="note"
|
||||
required
|
||||
maxLength="200"
|
||||
rows="3"
|
||||
placeholder="写清需要重新核对或补充的地方。"
|
||||
></textarea>
|
||||
</label>
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<form className="panel order-change-form" id="order-change-form" data-kind={kind}>
|
||||
<h2>{kind === 'approve' ? '复核并同意变更' : '驳回变更申请'}</h2>
|
||||
{html}
|
||||
<div id="order-change-error" aria-live="polite"></div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="primary">
|
||||
{kind === 'approve' ? '同意变更并更新原单' : '确认驳回'}
|
||||
</button>
|
||||
{button('收起', 'close-order-change-form', 'quiet')}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
return {
|
||||
showOrderChangeForm,
|
||||
showOrderOwnershipForm,
|
||||
showOrderCancellationForm,
|
||||
orderChangeListHTML,
|
||||
orderOwnershipListHTML,
|
||||
orderCancellationListHTML,
|
||||
validateOrderCancellationRequest,
|
||||
validateOrderChangeRequest,
|
||||
validateOrderOwnershipRequest,
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user