增加客户寄存料登记与置换使用,支持余额恢复
This commit is contained in:
1 parent
d0809d61a7
commit
1f1e6dd402
11 files changed
+170
-23
No files matched your search
@@ -67,9 +67,10 @@ function snapshot(l,row){
|
||||
tables.usages=row.order_id?l.rows('SELECT * FROM material_pool_usages WHERE order_id=? ORDER BY rowid',row.order_id):[];
|
||||
tables.purchase=row.purchase_id?l.one('SELECT * FROM material_purchases WHERE id=?',row.purchase_id):null;
|
||||
tables.purchaseSource=row.purchase_id?l.one('SELECT * FROM recovery_purchase_sources WHERE purchase_id=?',row.purchase_id):null;
|
||||
const customerMaterialEvents=l.rows('SELECT * FROM customer_material_events WHERE recovery_id=? ORDER BY rowid',row.id);if(customerMaterialEvents.length)tables.customerMaterialEvents=customerMaterialEvents;
|
||||
return {record:row,order,...tables};
|
||||
}
|
||||
function dependency(l,row){const counts=Counts.snapshot(l,l.pocketCatalog().map(row=>row.key));return hash({snapshot:snapshot(l,row),pool:Rolling.dependency(l),inventory:l.rows('SELECT id,date,pocket,mg FROM movements ORDER BY rowid'),...(counts?{counts}:{})});}
|
||||
function dependency(l,row){const counts=Counts.snapshot(l,l.pocketCatalog().map(row=>row.key)),customerMaterials=l.rows('SELECT id FROM customer_material_events ORDER BY rowid');return hash({snapshot:snapshot(l,row),pool:Rolling.dependency(l),inventory:l.rows('SELECT id,date,pocket,mg FROM movements ORDER BY rowid'),...(customerMaterials.length?{customerMaterials}:{}),...(counts?{counts}:{})});}
|
||||
function compact(q){return q?Object.fromEntries(['mode','date','oldMg','newMg','purchaseMg','purchaseAmount','receivable','cashReceipt','cashPayment','offsetAmount','goodsCost','directCost','profit'].map(key=>[key,q[key]])):null;}
|
||||
function dto(l,row,actor,env){
|
||||
const current=rowFor(l,row.recovery_id,actor,env),stale=row.status==='pending'&&(current.revision!==row.recovery_revision||dependency(l,current)!==row.dependency);
|
||||
@@ -172,6 +173,7 @@ function execute(l,row,after,actor,reason,env,input={}){return Rolling.withHisto
|
||||
const before=snapshot(l,row),old=JSON.parse(row.data),metadataOnly=!!after&&hash(financialInput(Recoveries.inputFor(old)))===hash(financialInput(Recoveries.inputFor(after)));
|
||||
const inventoryOnly=!!after&&!metadataOnly&&hash(inventoryOnlyInput(Recoveries.inputFor(old)))===hash(inventoryOnlyInput(Recoveries.inputFor(after)));
|
||||
verifyLegacyCount(l,row,after,input,env);
|
||||
require('./customer-materials').apply(l,row.id,after,actor,env);
|
||||
const deltas=metadataOnly?[]:movements(l,row,after);validateInventory(l,deltas,env);
|
||||
const changed=l.run('UPDATE recoveries SET date=?,customer=?,salesperson=?,note=?,old_lines=?,data=?,status=?,cancelled_at=?,updated=?,revision=revision+1 WHERE id=? AND revision=?',after?.date??row.date,after?.customer??row.customer,after?.salesperson??row.salesperson,after?.note??row.note,JSON.stringify(after?.old_lines??old.old_lines),JSON.stringify(metadataOnly?{...old,customer:after.customer,salesperson:after.salesperson,note:after.note}:after??old),after?'active':'cancelled',after?'':env.now(),env.now(),row.id,row.revision);
|
||||
if(changed.changes!==1)env.fail('回收记录已有其他更正,请刷新',409);
|
||||
|
||||
Reference in new issue
Block a user