保存同行基础版:店铺配置与员工管理
This commit is contained in:
1 parent
ecb8d6dec0
commit
b7b987064b
84 files changed
+1884
-573
No files matched your search
+13
-11
@@ -2,6 +2,7 @@
|
||||
// 回收与置换的金额、实物和现金分别保存;关联记录始终在同一保存点内生成。
|
||||
const {randomUUID}=require('node:crypto');
|
||||
const Calc=require('./public/calculations');
|
||||
const CreditCardRates=require('./credit-card-rates'),CreditCardFees=require('./public/credit-card-fees');
|
||||
const MaterialPools=require('./material-pools');
|
||||
const TeamFunds=require('./team-funds');
|
||||
const RecoveryMaterial=require('./recovery-material');
|
||||
@@ -47,13 +48,14 @@ function orderTotal(subtotal,discount,mode,env){
|
||||
function quote(ledger,input,actor,env,{creating=false,orderId=null,existingRecovery=null}={}){
|
||||
active(actor,env);if(!input||typeof input!=='object'||Array.isArray(input))env.fail('回收/置换记录格式无效');
|
||||
if(!existingRecovery&&!ledger.pocket('回收旧料')?.active)env.fail('回收旧料货盘已停用,请先启用后再登记新的回收或置换');
|
||||
const mode=env.pick(input.mode,['direct','exchange'],'回收方式'),date=env.day(input.date||env.today()),member=ledger.selectedMember(input,actor);
|
||||
const mode=env.pick(input.mode,['direct','exchange'],'回收方式'),date=env.day(input.date||env.today()),member=ledger.selectedMember(input,actor,existingRecovery?.member??null);
|
||||
const old_lines=normalizeOld(input.old_lines,env),oldMg=safe(sum(old_lines,'foldedMg'),env,'旧料折后总重量');
|
||||
const customer=creating?product(input.customer,'客户称呼/代号',60,env):env.text(input.customer,'客户称呼/代号',60,true);
|
||||
const salesperson=creating?product(input.salesperson,'开单人',30,env):env.text(input.salesperson,'开单人',30,true);
|
||||
const note=env.text(input.note,'备注',240,true),payer=env.pick(input.payer??member,TeamFunds.MEMBERS,'回收付款人');
|
||||
const payment_account=env.paymentAccount(input.payment_account||'麦麦微信');
|
||||
const result={mode,date,customer,salesperson,member,note,old_lines,oldMg,newMg:0,matchedMg:0,differenceMg:0,surplusMg:mode==='direct'?oldMg:0,
|
||||
const note=env.text(input.note,'备注',240,true),payer=ledger.validateMember(input.payer??member,'回收付款人',{original:existingRecovery?.payer});
|
||||
const payment_account=env.paymentAccount(input.payment_account||'麦麦微信',{original:existingRecovery?.payment_account});
|
||||
const credit_card_rate_permille=existingRecovery?(existingRecovery.credit_card_rate_permille??(orderId?CreditCardRates.read(ledger,'order',orderId):CreditCardFees.ratePermille)):CreditCardRates.current(ledger);
|
||||
const result={mode,date,customer,salesperson,member,note,old_lines,oldMg,credit_card_rate_permille,newMg:0,matchedMg:0,differenceMg:0,surplusMg:mode==='direct'?oldMg:0,
|
||||
goldRate:0,laborRate:0,laborMode:'gram',depreciationRate:0,depreciationMg:0,goldAmount:0,laborAmount:0,depreciationAmount:0,
|
||||
charges:[],chargesAmount:0,discount:0,rounding_mode:'cent',rounding_adjustment:0,receivable:0,payer,payment_account,
|
||||
materialCost:0,laborCost:0,goodsCost:0,directCost:0,profit:0};
|
||||
@@ -95,9 +97,9 @@ function quote(ledger,input,actor,env,{creating=false,orderId=null,existingRecov
|
||||
const rate=env.money(laborMode==='gram'?e.cost_labor.rate:e.cost_labor.amount,'进货工费');
|
||||
laborCost=laborMode==='gram'?multiply(newMg,rate,env):rate;costLabor={mode:laborMode,...(laborMode==='gram'?{rate}:{amount:rate})};
|
||||
}else if(creating)env.fail('请填写进货工费;没有发生的填0');
|
||||
const costPayer=env.pick(e.cost_payer??member,TeamFunds.MEMBERS,'货品成本付款人');
|
||||
const costPayers={material:env.pick(e.cost_material_payer??costPayer,TeamFunds.MEMBERS,'料费付款人'),labor:env.pick(e.cost_labor_payer??costPayer,TeamFunds.MEMBERS,'进货工费付款人')};
|
||||
const fee_items=ledger.validateFees((e.fee_items??[]).map(fee=>({...fee,status:'estimated'})));
|
||||
const costPayer=ledger.validateMember(e.cost_payer??member,'货品成本付款人',{original:existingRecovery?.exchange?.costPayer});
|
||||
const costPayers={material:ledger.validateMember(e.cost_material_payer??costPayer,'料费付款人',{original:existingRecovery?.exchange?.costPayers?.material}),labor:ledger.validateMember(e.cost_labor_payer??costPayer,'进货工费付款人',{original:existingRecovery?.exchange?.costPayers?.labor})};
|
||||
const fee_items=ledger.validateFees((e.fee_items??[]).map(fee=>({...fee,status:'estimated'})),{historicalFees:existingRecovery?.exchange?.fee_items??[]});
|
||||
if(fee_items.some(fee=>fee.amount===null))env.fail('请补齐实际费用,没有发生的填0');
|
||||
const directCost=safe(sum(fee_items,'amount'),env),goodsCost=materialCost===null||laborCost===null?null:safe(materialCost+laborCost,env);
|
||||
Object.assign(result,{newMg,newProduct,matchedMg,differenceMg,surplusMg,goldRate,laborRate,laborMode,depreciationRate,depreciationMg,goldAmount,laborAmount,depreciationAmount,
|
||||
@@ -112,12 +114,12 @@ function quote(ledger,input,actor,env,{creating=false,orderId=null,existingRecov
|
||||
if(!purchaseMg&&input.buy_total!==undefined&&input.buy_total!==''&&env.money(input.buy_total,'最终回收总金额')!==0)env.fail('没有余料,不能另计回收购料金额');
|
||||
const netSettlement=result.receivable-purchaseAmount,cashReceipt=Math.max(netSettlement,0),cashPayment=Math.max(-netSettlement,0),offsetAmount=Math.min(result.receivable,purchaseAmount);
|
||||
if(cashPayment&&payment_account.endsWith('信用卡'))env.fail('回收付款不支持信用卡,请选择实际付款方式');
|
||||
if(creating&&cashPayment&&TeamFunds.accountMember(payment_account)!==payer)env.fail('实际付款账户须与回收付款人一致');
|
||||
const cardFee=cashReceipt&&payment_account.endsWith('信用卡')?env.cardFee(cashReceipt):0;
|
||||
if(creating&&cashPayment&&TeamFunds.accountMember(payment_account,ledger)!==payer)env.fail('实际付款账户须与回收付款人一致');
|
||||
const cardFee=cashReceipt&&payment_account.endsWith('信用卡')?env.cardFee(cashReceipt,credit_card_rate_permille):0;
|
||||
Object.assign(result,{purchaseMg,buyRate,calculatedPurchaseAmount,purchaseAmount,actualBuyRate:purchaseMg?Number((BigInt(purchaseAmount)*1000n+BigInt(purchaseMg)/2n)/BigInt(purchaseMg)):null,
|
||||
offsetAmount,netSettlement,cashReceipt,cashPayment,cardFee,directCost:result.directCost+cardFee,
|
||||
profit:mode==='exchange'?(result.goodsCost===null?null:result.receivable-result.goodsCost-result.directCost-cardFee):0,
|
||||
paymentMethods:cashReceipt||cashPayment?[payment_account.replace(/^(助理2|助理1|助理|麦麦)/,'')]:[]});
|
||||
paymentMethods:cashReceipt||cashPayment?[TeamFunds.accountChannel(payment_account)]:[]});
|
||||
return result;
|
||||
}
|
||||
function nextNumber(ledger,date,env){
|
||||
@@ -182,7 +184,7 @@ function detail(ledger,id,actor,env){
|
||||
active(actor,env);const row=raw(ledger,id,actor,env),saved=JSON.parse(row.data);
|
||||
const order=row.order_id?ledger.detail(row.order_id):null;
|
||||
const materialBatch=row.purchase_id?RecoveryMaterial.purchaseStatus(ledger,row.purchase_id):null;
|
||||
return {...saved,id:row.id,number:row.number,order_id:row.order_id,purchase_id:row.purchase_id,created:row.created,actor:row.actor,revision:row.revision,
|
||||
return {...saved,credit_card_rate_permille:saved.credit_card_rate_permille??order?.credit_card_rate_permille??CreditCardFees.ratePermille,id:row.id,number:row.number,order_id:row.order_id,purchase_id:row.purchase_id,created:row.created,actor:row.actor,revision:row.revision,
|
||||
...(materialBatch?{materialBatch}:{}),
|
||||
...(order?{paper_number:order.paper_number,materialCost:order.lines[0].costParts.material,goodsCost:order.goodsCost,directCost:order.directCost,profit:order.profit,materialCostPending:order.materialCostPending}:{}),
|
||||
...require('./recovery-changes').projection(ledger,row,actor,env),immutableReason:IMMUTABLE_REASON};
|
||||
|
||||
Reference in new issue
Block a user