修复四项新版开单和恢复差异,核验三项已确认行为

This commit is contained in:
黄健铭 committed 2026-12-05 03:21:56 -08:00
1 parent fdaa6afad5
commit c29ea45ec4
25 files changed
+617 -171

No files matched your search

@@ -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)
? []