支持三人台账、库存更正审批与每日人数增量

This commit is contained in:
summer committed 2026-10-25 14:19:24 +08:00
1 parent 8d9039aacf
commit f6bdfcf10d
57 files changed
+2536 -564

No files matched your search

+6 -6
View File
@@ -69,7 +69,7 @@
// 旧行不补写分项付款人;显式传入时必须完整、有效,不能把无效值当作缺省。
if(raw===undefined)return undefined;
if(!raw||typeof raw!=='object'||Array.isArray(raw)||Object.keys(raw).some(key=>!['material','labor'].includes(key)))throw new Error('料费和进货工费付款人无效');
for(const key of ['material','labor'])if(!Object.hasOwn(raw,key)||!['owner','assistant'].includes(raw[key]))throw new Error(costLabels[key]+'付款人无效');
for(const key of ['material','labor'])if(!Object.hasOwn(raw,key)||!['owner','assistant','assistant2'].includes(raw[key]))throw new Error(costLabels[key]+'付款人无效');
return {material:raw.material,labor:raw.labor};
}
function costs(raw){
@@ -171,11 +171,11 @@
// 订单内部对账用,输入为账本已保存的整数分;预估费用与实际支出分开。
function orderCosts(order){
const empty=()=>({goods:0,goodsMissing:0,paidFees:0,pendingFees:0,pendingMissing:0,total:0,missing:0});
const byPayer={owner:empty(),assistant:empty()},rows=[];
const byPayer={owner:empty(),assistant:empty(),assistant2:empty()},rows=[];
const goodsExcluded=['returned','cancelled'].includes(order.status);
const add=row=>{
rows.push(row);if(row.excluded)return;
const s=byPayer[row.payer];
const s=byPayer[row.payer];if(!s)throw new Error('成本付款人无效');
if(row.kind==='goods'){if(row.amount==null)s.goodsMissing++;else s.goods+=row.amount;}
if(row.kind==='paid')s.paidFees+=row.amount;
if(row.kind==='pending'){if(row.amount==null)s.pendingMissing++;else s.pendingFees+=row.amount;}
@@ -189,12 +189,12 @@
if(part.amount===null||!allocations?.length){
add({kind:'goods',component:'material',name:part.name,source:`商品 ${i+1} · ${line.name} · ${line.costMaterial.poolId}日购料待补`,amount:null,payer:payers?.material??line.payer,excluded:goodsExcluded,materialPoolId:line.costMaterial.poolId,materialPoolRevision:pool?.revision,poolPending:true,calculation:null});
}else{
if(!Array.isArray(allocations)||allocations.some(item=>!['owner','assistant'].includes(item.payer)||!Number.isSafeInteger(item.amount)||item.amount<0)||allocations.reduce((total,item)=>total+item.amount,0)!==part.amount)throw new Error('日购料分项成本记录无效');
if(!Array.isArray(allocations)||allocations.some(item=>!['owner','assistant','assistant2'].includes(item.payer)||!Number.isSafeInteger(item.amount)||item.amount<0)||allocations.reduce((total,item)=>total+item.amount,0)!==part.amount)throw new Error('日购料分项成本记录无效');
for(const item of allocations)add({kind:'goods',component:'material',name:part.name,source:`商品 ${i+1} · ${line.name} · ${line.costMaterial.poolId}日购料`,amount:item.amount,payer:item.payer,excluded:goodsExcluded,materialPoolId:line.costMaterial.poolId,materialPoolRevision:pool?.revision,calculation:{rate:pool.averageRate,quantity:line.quantity,weighted:true}});
}
}else if(part.key==='material'&&line.materialAllocations){
const allocations=line.materialAllocations;
if(!Array.isArray(allocations)||!allocations.length||allocations.some(item=>!['original','extra'].includes(item.source)||!['owner','assistant'].includes(item.payer)||!Number.isSafeInteger(item.amount)||item.amount<0||!Number.isSafeInteger(item.quantity)||item.quantity<=0||!Number.isSafeInteger(item.rate)||item.rate<=0)||allocations.reduce((total,item)=>total+item.amount,0)!==part.amount)throw new Error('锁价分项料费记录无效');
if(!Array.isArray(allocations)||!allocations.length||allocations.some(item=>!['original','extra'].includes(item.source)||!['owner','assistant','assistant2'].includes(item.payer)||!Number.isSafeInteger(item.amount)||item.amount<0||!Number.isSafeInteger(item.quantity)||item.quantity<=0||!Number.isSafeInteger(item.rate)||item.rate<=0)||allocations.reduce((total,item)=>total+item.amount,0)!==part.amount)throw new Error('锁价分项料费记录无效');
for(const item of allocations)add({kind:'goods',component:'material',name:part.name,source:`商品 ${i+1} · ${line.name} · ${item.source==='original'?'原锁价采购':'补重采购'}`,amount:item.amount,payer:item.payer,excluded:goodsExcluded,
priceLockSource:item.source,calculation:{rate:item.rate,quantity:item.quantity}});
}else add({kind:'goods',name:part.name,source:`商品 ${i+1} · ${line.name}`,amount:part.amount,payer:payers?.[part.key]??line.payer,excluded:goodsExcluded,
@@ -218,6 +218,6 @@
}
return {byPayer,total,rows,goodsExcluded,pendingCount:(order.pendingFees||[]).length};
}
const api={calculate,cents,isSilver,costs,costLabels,costPayers,charges,sale,orderTotal,purchaseCosts,poolMaterialAmount,poolMaterialPreview,priceLockCost,orderCosts};
const api={calculate,cents,isSilver,costs,costLabels,costPayers,normalizeCostPayers:costPayers,charges,sale,orderTotal,purchaseCosts,poolMaterialAmount,poolMaterialPreview,priceLockCost,orderCosts};
if(typeof module==='object'&&module.exports)module.exports=api;else root.LedgerCalc=api;
})(typeof globalThis==='object'?globalThis:this);