修复四项新版开单和恢复差异,核验三项已确认行为
This commit is contained in:
1 parent
fdaa6afad5
commit
c29ea45ec4
25 files changed
+617
-171
No files matched your search
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Alert, App as AntApp, Button, Popconfirm, Spin, Typography } from 'antd';
|
||||
import { ClearOutlined } from '@ant-design/icons';
|
||||
import type { ApiError, LedgerClient, PendingJob } from '../../lib/api';
|
||||
import { clearDraft, loadDraft } from '../../lib/drafts';
|
||||
import { clearDraft, clearIssuedDraft, loadDraft, saveDraft } from '../../lib/drafts';
|
||||
import { navigate, pathFor, searchParam } from '../../lib/router';
|
||||
import { useClientSnapshot } from '../../lib/useClient';
|
||||
import { Model } from '../../shared';
|
||||
@@ -84,6 +84,11 @@ function CreateOrderForm({
|
||||
const [error, setError] = useState('');
|
||||
const [accountChanged, setAccountChanged] = useState(false);
|
||||
const [issued, setIssued] = useState<{ order: IssuedOrder; error: string } | null>(null);
|
||||
const completed = issued !== null;
|
||||
const awaitingIssue = useRef(false);
|
||||
useEffect(() => {
|
||||
if (!completed && !awaitingIssue.current) saveDraft(window.localStorage, state.user.id, store.draft);
|
||||
}, [completed, state.user.id, store.draft]);
|
||||
const [tags, setTags] = useState<string[]>([]);
|
||||
const [tagsStatus, setTagsStatus] = useState('正在读取快捷标签…');
|
||||
const busy = client.busy;
|
||||
@@ -140,8 +145,7 @@ function CreateOrderForm({
|
||||
[message],
|
||||
);
|
||||
const finishIssued = useCallback(
|
||||
async (input: OrderDraft, result: { id: string }) => {
|
||||
clearDraft(window.localStorage, state.user.id);
|
||||
async (customer: string | undefined, result: { id: string }) => {
|
||||
setIssued({ order: { id: result.id }, error: '' });
|
||||
try {
|
||||
const order = await client.api<IssuedOrder>('/api/orders/' + encodeURIComponent(result.id));
|
||||
@@ -154,12 +158,12 @@ function CreateOrderForm({
|
||||
void refreshState().catch(() => {});
|
||||
} catch {
|
||||
setIssued({
|
||||
order: { id: result.id, customer: input.customer },
|
||||
order: { id: result.id, customer },
|
||||
error: '销售单据已经生成,最新订单暂未读到。请重新读取或查看已生成销售单;不要重复开单。',
|
||||
});
|
||||
}
|
||||
},
|
||||
[client, message, refreshState, state.user.id],
|
||||
[client, message, refreshState],
|
||||
);
|
||||
|
||||
async function submit() {
|
||||
@@ -169,9 +173,12 @@ function CreateOrderForm({
|
||||
const draft = Model.validateIssueDraft(Model.collectDraft(form, state), state);
|
||||
if (draft.id && state.user.role !== 'owner')
|
||||
throw new Error('已有草稿由店主继续填写并开单;无单号的新开单流程照常使用。');
|
||||
awaitingIssue.current = true;
|
||||
const result = await client.mutate<{ id: string }>('/api/orders/issue', draft);
|
||||
await finishIssued(draft, result);
|
||||
clearIssuedDraft(window.localStorage, state.user.id, draft);
|
||||
await finishIssued(draft.customer, result);
|
||||
} catch (err) {
|
||||
awaitingIssue.current = false;
|
||||
showError(err);
|
||||
}
|
||||
}
|
||||
@@ -179,18 +186,23 @@ function CreateOrderForm({
|
||||
if (job.url !== '/api/orders/issue' && onRecoverOther) return onRecoverOther();
|
||||
setError('');
|
||||
try {
|
||||
awaitingIssue.current = true;
|
||||
const recovered = await client.retryPending<{ id?: string }>();
|
||||
if (!recovered) return;
|
||||
if (job.url === '/api/orders/issue' && recovered.result.id)
|
||||
return await finishIssued(job.data as OrderDraft, recovered.result as { id: string });
|
||||
message.success('原操作已确认,不会重复记账');
|
||||
if (recovered?.result.id && job.url === '/api/orders/issue') {
|
||||
clearIssuedDraft(window.localStorage, state.user.id, recovered.job.data);
|
||||
return await finishIssued((recovered.job.data as OrderDraft).customer, { id: recovered.result.id });
|
||||
}
|
||||
awaitingIssue.current = false;
|
||||
if (recovered) message.success('原操作已确认,不会重复记账');
|
||||
} catch (err) {
|
||||
awaitingIssue.current = false;
|
||||
showError(err);
|
||||
}
|
||||
}
|
||||
function startNew() {
|
||||
clearDraft(window.localStorage, state.user.id);
|
||||
if (window.location.search) window.history.replaceState(null, '', window.location.pathname);
|
||||
awaitingIssue.current = false;
|
||||
setIssued(null);
|
||||
setError('');
|
||||
reset(null);
|
||||
@@ -234,7 +246,7 @@ function CreateOrderForm({
|
||||
client.mutate('/api/orders/' + encodeURIComponent(issued.order.id) + '/print', { mode: 'full' })
|
||||
}
|
||||
error={issued.error}
|
||||
onRetry={() => void finishIssued({ customer: issued.order.customer } as OrderDraft, { id: issued.order.id })}
|
||||
onRetry={() => void finishIssued(issued.order.customer, { id: issued.order.id })}
|
||||
onNew={startNew}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// 开单表单状态:每次修改都经共用模型 syncForm 重新同步(等同旧页面每次输入后的 updateTotal)。
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { LedgerClient } from '../../lib/api';
|
||||
import { saveDraft } from '../../lib/drafts';
|
||||
import { Model } from '../../shared';
|
||||
import type {
|
||||
FormSummary,
|
||||
@@ -69,10 +68,6 @@ export function useOrderForm({
|
||||
ctxRef.current = ctx;
|
||||
commit(Model.syncForm(storeRef.current.form, ctx));
|
||||
}, [ctx, commit]);
|
||||
// 填写内容自动暂存。
|
||||
useEffect(() => {
|
||||
if (!editing) saveDraft(window.localStorage, state.user.id, store.draft);
|
||||
}, [store.draft, state.user.id, editing]);
|
||||
|
||||
const [poolsRequest, setPoolsRequest] = useState(0);
|
||||
const loadPools = useCallback(() => setPoolsRequest(value => value + 1), []);
|
||||
|
||||
@@ -99,6 +99,7 @@ export function OrderActionDialog({
|
||||
const printStatus = printStatuses[original?.printStatus?.id || id];
|
||||
const order = original && printStatus ? { ...original, printStatus } : original;
|
||||
const [change, ownership, cancellation] = details.value?.entries || [];
|
||||
const pending = client.pending();
|
||||
const ctx = {
|
||||
state,
|
||||
session,
|
||||
@@ -112,7 +113,12 @@ export function OrderActionDialog({
|
||||
user: state.user.id,
|
||||
forceApproval: ui.forceApproval,
|
||||
},
|
||||
ui,
|
||||
ui: {
|
||||
...ui,
|
||||
actionBlocked: client.busy || !!pending,
|
||||
retryBusy: client.busy,
|
||||
retryKey: pending?.key === ui.pendingKey ? ui.pendingKey : null,
|
||||
},
|
||||
navigation: (
|
||||
<DetailNavigation ids={listIds} id={id} open={openOrder} blocked={!!form || client.busy || !!client.pending()} />
|
||||
),
|
||||
@@ -340,7 +346,21 @@ export function OrderActionDialog({
|
||||
data = readForm(node),
|
||||
kind = node.dataset.kind;
|
||||
let submittedDirect = false;
|
||||
let submittedKey;
|
||||
const retryKey = e.nativeEvent.submitter?.dataset.retryKey;
|
||||
try {
|
||||
if (client.busy) return;
|
||||
if (retryKey) {
|
||||
const job = client.pending();
|
||||
if (!job || job.key !== retryKey || job.key !== ui.pendingKey) return;
|
||||
submittedKey = job.key;
|
||||
submittedDirect = job.url === base + '/' + kind;
|
||||
await client.retryPending();
|
||||
refreshDetail();
|
||||
await refreshState();
|
||||
return;
|
||||
}
|
||||
if (client.pending()) return;
|
||||
let url, payload;
|
||||
if (form.type === 'after') {
|
||||
payload = views.orderAfterSaleInput(node);
|
||||
@@ -400,7 +420,9 @@ export function OrderActionDialog({
|
||||
}
|
||||
if (data.legacyCountVerified) payload.legacyCountVerified = true;
|
||||
}
|
||||
await client.mutate(url, payload);
|
||||
const saving = client.mutate(url, payload);
|
||||
submittedKey = client.pending()?.key;
|
||||
await saving;
|
||||
refreshDetail();
|
||||
await refreshState();
|
||||
} catch (err) {
|
||||
@@ -421,14 +443,16 @@ export function OrderActionDialog({
|
||||
} else if (
|
||||
form.type === 'action' &&
|
||||
views.orderActionUsesChangeForm(kind) &&
|
||||
[403, 404, 409].includes(err.status)
|
||||
([403, 404, 409].includes(err.status) || (submittedKey && submittedKey === client.pending()?.key))
|
||||
) {
|
||||
const forceApproval = err.status === 403 && submittedDirect && !client.pending();
|
||||
if (node.elements.verified) node.elements.verified.checked = false;
|
||||
const rejected = [403, 404, 409].includes(err.status);
|
||||
if (rejected && node.elements.verified) node.elements.verified.checked = false;
|
||||
setUi(old => ({
|
||||
...old,
|
||||
forceApproval,
|
||||
stale: !forceApproval,
|
||||
pendingKey: submittedKey,
|
||||
stale: !forceApproval && rejected,
|
||||
actionError: messageOf(err) + (forceApproval ? ' 输入已保留,请重新核实后提交店主审批。' : ''),
|
||||
}));
|
||||
} else setError(messageOf(err));
|
||||
|
||||
@@ -797,7 +797,7 @@ export function orderActions(
|
||||
<h2>{requiresApproval ? '申请' + orderChangeActionLabels[action] : actionName[action]}</h2>
|
||||
{changeForm ? (
|
||||
<>
|
||||
<fieldset style={{ display: 'contents' }} disabled={!!ui.stale}>
|
||||
<fieldset style={{ display: 'contents' }} disabled={!!ui.stale || !!ui.actionBlocked}>
|
||||
{html}
|
||||
{orderActionChangeReviewHTML(action)}
|
||||
</fieldset>
|
||||
@@ -805,6 +805,11 @@ export function orderActions(
|
||||
{ui.actionError && (
|
||||
<div className="error">
|
||||
{ui.actionError}
|
||||
{ui.retryKey && (
|
||||
<button type="submit" formNoValidate data-retry-key={ui.retryKey} disabled={!!ui.retryBusy}>
|
||||
恢复原操作
|
||||
</button>
|
||||
)}
|
||||
{ui.stale && <> {button('重新读取订单后申请', 'reload-order-change')}</>}
|
||||
</div>
|
||||
)}
|
||||
@@ -816,7 +821,7 @@ export function orderActions(
|
||||
<div className="form-actions">
|
||||
<button
|
||||
className="primary"
|
||||
disabled={!!ui.stale}
|
||||
disabled={!!ui.stale || !!ui.actionBlocked}
|
||||
{...(changeForm
|
||||
? {
|
||||
'data-order-action-submit': '',
|
||||
|
||||
@@ -1,62 +1,8 @@
|
||||
import { Children, Fragment } from 'react';
|
||||
import { describeMaterialSources, validateMaterialQuote as checkMaterialQuote } from '../../lib/materialQuote';
|
||||
import { Model, Calc as LedgerCalc } from '../../shared';
|
||||
export function lockViews(state, session) {
|
||||
function validateMaterialQuote(result, input) {
|
||||
const integer = value => Number.isSafeInteger(value) && value >= 0,
|
||||
amount = value => value === null || integer(value);
|
||||
if (
|
||||
!result ||
|
||||
result.date !== input.date ||
|
||||
result.member !== input.member ||
|
||||
!Array.isArray(result.entries) ||
|
||||
result.entries.length !== input.entries.length ||
|
||||
!Array.isArray(result.pools)
|
||||
)
|
||||
throw new Error('分来源料费未完整返回,请刷新料价。');
|
||||
for (const original of input.entries) {
|
||||
const row = result.entries.find(row => row.lineIndex === original.lineIndex);
|
||||
if (
|
||||
!row ||
|
||||
row.poolId !== original.poolId ||
|
||||
row.mg !== original.mg ||
|
||||
!amount(row.amount) ||
|
||||
!Array.isArray(row.allocations) ||
|
||||
!Array.isArray(row.materialSources) ||
|
||||
row.materialSources.reduce((sum, source) => sum + source.quantity, 0) !== row.mg
|
||||
)
|
||||
throw new Error('分来源料费与当前商品不一致,请重新核对。');
|
||||
for (const source of row.materialSources)
|
||||
if (
|
||||
!['personal_recovery', 'public'].includes(source.kind) ||
|
||||
(source.kind === 'personal_recovery' && source.member !== input.member) ||
|
||||
!integer(source.quantity) ||
|
||||
!amount(source.amount) ||
|
||||
!Array.isArray(source.allocations) ||
|
||||
source.allocations.some(part => !teamMemberKeys().includes(part.payer) || !integer(part.amount)) ||
|
||||
(source.amount !== null && source.allocations.reduce((sum, part) => sum + part.amount, 0) !== source.amount)
|
||||
)
|
||||
throw new Error('个人回收料或付款来源不完整,请重新读取。');
|
||||
if (
|
||||
row.amount !== null &&
|
||||
(row.materialSources.some(source => source.amount === null) ||
|
||||
row.materialSources.reduce((sum, source) => sum + source.amount, 0) !== row.amount ||
|
||||
row.allocations.reduce((sum, part) => sum + part.amount, 0) !== row.amount)
|
||||
)
|
||||
throw new Error('分来源料费合计不一致,请重新读取。');
|
||||
}
|
||||
if (
|
||||
result.pools.length !== new Set(input.entries.map(row => row.poolId)).size ||
|
||||
result.pools.some(
|
||||
pool =>
|
||||
!input.entries.some(row => row.poolId === pool.poolId) ||
|
||||
!['personalRemainingMg', 'publicRemainingMg', 'eligibleRemainingMg'].every(key => integer(pool[key])) ||
|
||||
!amount(pool.personalRemainingAmount) ||
|
||||
!amount(pool.publicRemainingAmount),
|
||||
)
|
||||
)
|
||||
throw new Error('个人与公共可用克重未完整返回,请重新读取。');
|
||||
return result;
|
||||
}
|
||||
const validateMaterialQuote = (result, input) => checkMaterialQuote(result, input, Model.memberKeys(state));
|
||||
function priceLockSplitMaterialSources(pool, mg) {
|
||||
let left = mg;
|
||||
const taken = [],
|
||||
@@ -1056,21 +1002,7 @@ export function lockViews(state, session) {
|
||||
{text}
|
||||
</button>
|
||||
);
|
||||
function materialPoolRate(value) {
|
||||
return value == null ? '待补采购' : yuan(value);
|
||||
}
|
||||
const materialPayerName = payer => (payer ? teamMemberName(payer) : '待补');
|
||||
function materialSourceName(source) {
|
||||
return source.kind === 'personal_recovery' ? materialPayerName(source.member) + '个人回收料' : '公共料';
|
||||
}
|
||||
function materialSourceSegmentsText(sources = []) {
|
||||
return sources
|
||||
.map(
|
||||
source =>
|
||||
`${materialSourceName(source)} ${grams(source.quantity)}g · ${source.amount == null ? '料费待补' : '¥' + yuan(source.amount)}${source.averageRate == null ? '' : '(加权约 ¥' + materialPoolRate(source.averageRate) + '/克)'}`,
|
||||
)
|
||||
.join(';');
|
||||
}
|
||||
const materialSourceSegmentsText = sources => describeMaterialSources(sources, teamMemberName);
|
||||
function priceLockMaterialAllocations(lock) {
|
||||
return priceLockMaterialPending(lock)
|
||||
? []
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Model } from '../../shared';
|
||||
import { grams } from '../../lib/format';
|
||||
import { pocketOptions, Settlement } from './controls';
|
||||
import { pocketOptions, Settlement, money } from './controls';
|
||||
import { describeMaterialSources } from '../../lib/materialQuote';
|
||||
|
||||
// 早期的置换单按每件新货分别核算来料、差重和余料。修改时沿用原单结构。
|
||||
export function IndependentItems({
|
||||
parts,
|
||||
quotedItems,
|
||||
draft,
|
||||
edit,
|
||||
state,
|
||||
@@ -27,6 +29,7 @@ export function IndependentItems({
|
||||
const index = i - 1,
|
||||
f = fields(row, index),
|
||||
original = edit.inputs.exchange.items[i],
|
||||
item = quotedItems?.[i],
|
||||
deposit = row.old_source === 'deposit',
|
||||
saveSurplus = row.surplus_mode === 'deposit',
|
||||
today = draft.date;
|
||||
@@ -222,6 +225,19 @@ export function IndependentItems({
|
||||
})}
|
||||
{f.select('工费付款人', 'labor_payer', members)}
|
||||
</div>
|
||||
<p data-item-cost>
|
||||
{item &&
|
||||
'本件差重料费 ' +
|
||||
money(item.materialCost) +
|
||||
';进货工费 ' +
|
||||
money(item.laborCost) +
|
||||
(item.exchange.costMaterial.materialSources
|
||||
? ';' +
|
||||
describeMaterialSources(item.exchange.costMaterial.materialSources, key =>
|
||||
Model.memberName(state, key),
|
||||
)
|
||||
: '')}
|
||||
</p>
|
||||
<div data-item-formula>{q ? <Settlement q={q} input={input} draft={row} /> : error}</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { grams } from '../../lib/format';
|
||||
import { memberAccountPrefix, recoveryModel } from './model';
|
||||
import { LegacyCount, Settlement, loadDraft, money, options, pocketOptions, rowLabel } from './controls';
|
||||
import { IndependentItems } from './IndependentItems';
|
||||
import { localMaterialNote, quotedMaterialNote } from './materialPreview';
|
||||
import { useRead } from '../Inventory/data';
|
||||
|
||||
function normalize(draft) {
|
||||
@@ -194,7 +195,8 @@ export function RecoveryForm({ client, state, edit, materials = [], deposit, sav
|
||||
};
|
||||
}, [edit, editKey, key, raw, revision]);
|
||||
const quoteUrl = edit ? '/api/recoveries/' + encodeURIComponent(edit.id) + '/quote' : '/api/recoveries/quote',
|
||||
expected = q?.netSettlement;
|
||||
expected = q?.netSettlement,
|
||||
differenceMg = q?.differenceMg;
|
||||
useEffect(() => {
|
||||
if (!signature || conflict) return;
|
||||
let valid = true;
|
||||
@@ -204,28 +206,8 @@ export function RecoveryForm({ client, state, edit, materials = [], deposit, sav
|
||||
value = await client.api(quoteUrl, payload);
|
||||
if (!Number.isSafeInteger(value.netSettlement) || value.netSettlement !== expected)
|
||||
throw new Error('结算规则已更新,请重新读取页面再核对。');
|
||||
let materialText = '';
|
||||
if (value.exchange?.costMaterial?.materialSources?.length && payload.exchange?.cost_material?.mode === 'pool') {
|
||||
const sources = value.exchange.costMaterial.materialSources;
|
||||
if (
|
||||
value.member !== payload.member ||
|
||||
sources.some(s => s.kind === 'personal_recovery' && s.member !== payload.member) ||
|
||||
sources.reduce((n, s) => n + s.quantity, 0) !== value.differenceMg
|
||||
)
|
||||
throw new Error('置换用料来源与当前归属不一致,请重新核对。');
|
||||
const pool = await client.api('/api/material-pools/quote', {
|
||||
date: payload.date,
|
||||
member: payload.member,
|
||||
...(edit?.record?.order_id ? { orderId: edit.record.order_id } : {}),
|
||||
entries: [{ lineIndex: 0, poolId: payload.exchange.cost_material.poolId, mg: value.differenceMg }],
|
||||
});
|
||||
materialText =
|
||||
'差重 ' +
|
||||
grams(value.differenceMg) +
|
||||
'g · 料费 ' +
|
||||
money(value.materialCost) +
|
||||
(pool.pools?.length ? ' · 已核对料池余额' : '');
|
||||
}
|
||||
if (!valid) return;
|
||||
const materialText = await quotedMaterialNote(client, state, payload, value, differenceMg, edit);
|
||||
if (valid) setQuote({ signature, text: '结算已核对;保存时按最新账务记录确认。', materialText, value });
|
||||
} catch (e) {
|
||||
if (valid)
|
||||
@@ -239,7 +221,7 @@ export function RecoveryForm({ client, state, edit, materials = [], deposit, sav
|
||||
valid = false;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [client, signature, expected, quoteUrl, edit, conflict]);
|
||||
}, [client, state, signature, expected, differenceMg, quoteUrl, edit, conflict]);
|
||||
const pools = useRead(client, exchange ? '/api/material-pools' : null, 0)?.value?.rows || [],
|
||||
members = Model.memberOptions(state),
|
||||
recipients = members.map(([k, t]) => [memberAccountPrefix(k), t]);
|
||||
@@ -641,6 +623,7 @@ export function RecoveryForm({ client, state, edit, materials = [], deposit, sav
|
||||
{parts ? (
|
||||
<IndependentItems
|
||||
parts={parts}
|
||||
quotedItems={quote.signature === signature ? quote.value?.exchangeItems : undefined}
|
||||
draft={d}
|
||||
edit={edit}
|
||||
state={state}
|
||||
@@ -924,7 +907,10 @@ export function RecoveryForm({ client, state, edit, materials = [], deposit, sav
|
||||
{select('料费付款人', 'material_payer', members, { disabled: !diff || d.material_source === 'pool' })}
|
||||
</div>
|
||||
</div>
|
||||
<p id="recovery-material-note">{quote.signature === signature && quote.materialText}</p>
|
||||
<p id="recovery-material-note">
|
||||
{(quote.signature === signature && quote.materialText) ||
|
||||
localMaterialNote(d, q, pools, state, model, edit)}
|
||||
</p>
|
||||
<details>
|
||||
<summary>其他实际成本(选填)</summary>
|
||||
<div className="recovery-row">
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { Calc, Model } from '../../shared';
|
||||
import { grams } from '../../lib/format';
|
||||
import { describeMaterialBalance, describeMaterialSources, validateMaterialQuote } from '../../lib/materialQuote';
|
||||
import { money } from './controls';
|
||||
|
||||
// 与结算报价分开读取料池余额。余额暂不可用时仍可核对已算出的来源、成本和结算。
|
||||
export async function quotedMaterialNote(client, state, input, result, differenceMg, edit) {
|
||||
const material = input.exchange?.cost_material;
|
||||
if (material?.mode !== 'pool') return '';
|
||||
const sources = result.exchange?.costMaterial?.materialSources;
|
||||
if (!sources?.length) {
|
||||
if (!edit) return '';
|
||||
return (
|
||||
'更正后从 ' +
|
||||
material.poolId +
|
||||
' 料池扣差重 ' +
|
||||
grams(differenceMg) +
|
||||
'g,原单耗用已排除。' +
|
||||
(result.materialCost == null
|
||||
? '料费待补齐购料后核算。'
|
||||
: '本次预估料费 ' + money(result.materialCost) + ',按原购料来源核算付款人。')
|
||||
);
|
||||
}
|
||||
if (
|
||||
result.member !== input.member ||
|
||||
sources.some(s => s.kind === 'personal_recovery' && s.member !== input.member) ||
|
||||
sources.reduce((sum, s) => sum + s.quantity, 0) !== differenceMg ||
|
||||
(result.materialCost !== null && sources.reduce((sum, s) => sum + s.amount, 0) !== result.materialCost)
|
||||
)
|
||||
throw new Error('置换用料来源与当前归属不一致,请重新核对。');
|
||||
const request = {
|
||||
date: input.date,
|
||||
member: input.member,
|
||||
...(edit?.record.order_id ? { orderId: edit.record.order_id } : {}),
|
||||
entries: [{ lineIndex: 0, poolId: material.poolId, mg: differenceMg }],
|
||||
};
|
||||
let balance;
|
||||
try {
|
||||
const response = await client.api('/api/material-pools/quote', request);
|
||||
const pool = validateMaterialQuote(response, request, Model.memberKeys(state)).pools[0];
|
||||
balance = describeMaterialBalance(pool);
|
||||
} catch {
|
||||
balance = '个人与公共余量暂未读到,请刷新核对。';
|
||||
}
|
||||
return (
|
||||
describeMaterialSources(sources, key => Model.memberName(state, key)) +
|
||||
';' +
|
||||
balance +
|
||||
(edit ? '原单耗用已排除。' : '')
|
||||
);
|
||||
}
|
||||
|
||||
export function localMaterialNote(draft, calculation, pools, state, model, edit) {
|
||||
if (!calculation || draft.mode !== 'exchange') return '填写新旧克重后显示差重料费。';
|
||||
const { differenceMg, matchedMg } = calculation;
|
||||
if (!differenceMg) return '等重交换 ' + grams(matchedMg) + 'g,只记实物;无补金差重,不耗用每日料池。';
|
||||
if (draft.material_source !== 'pool') {
|
||||
let detail = '待填进货料价';
|
||||
try {
|
||||
const rate = model.units(draft.material_rate, 2, '差重进货料价');
|
||||
detail =
|
||||
grams(differenceMg) + 'g × ' + draft.material_rate + '元/g = ' + money(model.multiply(differenceMg, rate));
|
||||
} catch {
|
||||
// 填写过程中的空值或无效价格保留待填提示。
|
||||
}
|
||||
return '只计算补金差重 ' + grams(differenceMg) + 'g 的料费:' + detail + '。等重部分不进出料池。';
|
||||
}
|
||||
const pool = pools.find(p => p.id === (draft.material_pool_id || draft.date));
|
||||
let note = '当前料费待核算;购料不足时保留待补状态。';
|
||||
if (pool && Object.hasOwn(pool, 'personalPools'))
|
||||
note = '先用' + Model.memberName(state, draft.member) + '个人回收料,公共补足;正在核对分来源料费。';
|
||||
else if (edit) note = '更正料费通过原单核对,排除原有耗用。';
|
||||
else if (pool) {
|
||||
try {
|
||||
const cost = Calc.poolMaterialPreview(pool, [{ lineIndex: 0, mg: differenceMg }]).amounts[0];
|
||||
if (cost != null) note = '当前预估料费 ' + money(cost) + ',按原购料记录归属付款人。';
|
||||
} catch {
|
||||
// 历史料池资料不足以在本地计算时,等待服务端报价。
|
||||
}
|
||||
}
|
||||
return '只核算补金差重 ' + grams(differenceMg) + 'g,等重交换 ' + grams(matchedMg) + 'g不扣料池。' + note;
|
||||
}
|
||||
@@ -787,6 +787,7 @@ export function recoveryModel(state, editData = null) {
|
||||
validate: validateRecoveryInput,
|
||||
newWeight: recoveryNewWeight,
|
||||
units: recoveryUnits,
|
||||
multiply: recoveryMul,
|
||||
checkEdit: validateRecoveryEditDetail,
|
||||
checkRequest: validateRecoveryChangeRequest,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user