保存同行基础版:店铺配置与员工管理
This commit is contained in:
1 parent
ecb8d6dec0
commit
b7b987064b
84 files changed
+1884
-573
No files matched your search
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
// 浏览器预览和服务器记账共用整数算法;每行销售额最后统一四舍五入到分。
|
||||
(function(root){
|
||||
const validMember=value=>['owner','assistant','assistant2'].includes(value)||/^staff_[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(value);
|
||||
function fixed(value,places,name){
|
||||
const s=String(value??'').trim();
|
||||
if(!new RegExp('^\\d+(?:\\.\\d{1,'+places+'})?$').test(s))throw new Error(name+'须为非负数字,最多'+places+'位小数');
|
||||
@@ -69,7 +70,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','assistant2'].includes(raw[key]))throw new Error(costLabels[key]+'付款人无效');
|
||||
for(const key of ['material','labor'])if(!Object.hasOwn(raw,key)||!validMember(raw[key]))throw new Error(costLabels[key]+'付款人无效');
|
||||
return {material:raw.material,labor:raw.labor};
|
||||
}
|
||||
function costs(raw){
|
||||
@@ -175,7 +176,8 @@
|
||||
const goodsExcluded=['returned','cancelled'].includes(order.status);
|
||||
const add=row=>{
|
||||
rows.push(row);if(row.excluded)return;
|
||||
const s=byPayer[row.payer];if(!s)throw new Error('成本付款人无效');
|
||||
if(!validMember(row.payer))throw new Error('成本付款人无效');
|
||||
const s=byPayer[row.payer]||(byPayer[row.payer]=empty());
|
||||
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;}
|
||||
@@ -190,12 +192,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','assistant2'].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=>!validMember(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:pool.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','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('锁价分项料费记录无效');
|
||||
if(!Array.isArray(allocations)||!allocations.length||allocations.some(item=>!['original','extra'].includes(item.source)||!validMember(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'?(item.weighted?'原锁日料池':'原锁价采购'):'补重采购'}`,amount:item.amount,payer:item.payer,excluded:goodsExcluded,
|
||||
priceLockSource:item.source,...(item.poolId?{materialPoolId:item.poolId}:{}),calculation:{rate:item.rate,quantity:item.quantity,...(item.weighted?{weighted:true}:{} )}});
|
||||
}else add({kind:'goods',name:part.name,source:`商品 ${i+1} · ${line.name}`+(part.key==='labor'&&line.returnedStock?' · 退回现货继承工费':''),amount:part.amount,payer:payers?.[part.key]??line.payer,excluded:goodsExcluded,...(part.key==='labor'&&line.returnedStock?{inheritedStockCost:true,returnedStockId:line.returnedStockId}:{}),
|
||||
|
||||
Reference in new issue
Block a user