支持多商品锁价及待交付修改作废审批

This commit is contained in:
summer committed 2026-11-08 02:22:58 +08:00
1 parent 1cbcdc728c
commit 337b2a709f
28 files changed
+1187 -344

No files matched your search

+7 -7
View File
@@ -36,9 +36,9 @@ function batches(value){
}
return totals;
}
function lockBatches(l,lockId,snapshot){
function lockBatches(l,lockId,snapshot,lineIndex=0){
const result=batches(snapshot.materialSources);
if(exists(l,'material_return_sources'))for(const returned of l.rows("SELECT s.sources FROM material_return_sources s JOIN price_lock_pool_returns r ON s.return_kind='lock' AND s.return_id=r.id WHERE r.price_lock_id=? ORDER BY r.rowid",lockId))
if(exists(l,'material_return_sources'))for(const returned of l.rows("SELECT s.sources FROM material_return_sources s JOIN price_lock_pool_returns r ON s.return_kind='lock' AND s.return_id=r.id WHERE r.price_lock_id=? AND r.line_index=? ORDER BY r.rowid",lockId,lineIndex))
for(const [purchaseId,mg] of batches(returned.sources))result.set(purchaseId,(result.get(purchaseId)||0)-mg);
for(const mg of result.values())if(mg<0)fail('锁价回收料耗用与回料克重不一致,请先核对料池');
return result;
@@ -49,8 +49,8 @@ function blockedUsages(l,purchaseId){
const add=(key,row)=>{if(!row.mg)return;const previous=result.get(key);result.set(key,previous?{...previous,mg:previous.mg+row.mg}:row);};
if(exists(l,'material_usage_sources'))for(const row of l.rows('SELECT u.order_id,o.number,s.sources FROM material_usage_sources s JOIN material_pool_usages u ON u.id=s.usage_id JOIN orders o ON o.id=u.order_id WHERE u.active=1 AND instr(s.sources,?)>0 ORDER BY u.created,u.rowid',purchaseId))
add('order:'+row.order_id,{orderId:row.order_id,number:row.number,mg:batches(row.sources).get(purchaseId)||0});
if(exists(l,'price_lock_pool_reservations'))for(const row of l.rows('SELECT r.snapshot,p.id,p.final_order_id,p.number FROM price_lock_pool_reservations r JOIN price_locks p ON p.id=r.price_lock_id WHERE instr(r.snapshot,?)>0 ORDER BY r.created,r.rowid',purchaseId))
add('lock:'+row.id,{orderId:row.final_order_id??null,number:row.number,mg:lockBatches(l,row.id,JSON.parse(row.snapshot)).get(purchaseId)||0,priceLockId:row.id});
if(exists(l,'price_lock_pool_reservations'))for(const row of l.rows('SELECT r.id AS reservation_id,r.line_index,r.snapshot,p.id,p.final_order_id,p.number FROM price_lock_pool_reservations r JOIN price_locks p ON p.id=r.price_lock_id WHERE instr(r.snapshot,?)>0 ORDER BY r.created,r.rowid',purchaseId))
add('lock:'+row.id,{orderId:row.final_order_id??null,number:row.number,mg:lockBatches(l,row.id,JSON.parse(row.snapshot),row.line_index).get(purchaseId)||0,priceLockId:row.id});
return [...result.values()];
}
function purchaseStatus(l,purchaseId){
@@ -80,10 +80,10 @@ function ownershipReason(l,order,target=null,env){
const usages=exists(l,'material_usage_sources')?l.rows('SELECT u.pool_id,s.sources FROM material_pool_usages u JOIN material_usage_sources s ON s.usage_id=u.id WHERE u.order_id=? AND u.active=1',order.id):[];
const dates=new Set(usages.map(row=>row.pool_id));
let personal=usages.some(row=>sources(row.sources).some(source=>source.kind==='personal_recovery'&&source.quantity>0));
const reservation=l.one('SELECT r.*,p.id AS lock_id FROM price_lock_pool_reservations r JOIN price_locks p ON p.id=r.price_lock_id WHERE p.final_order_id=?',order.id);
if(reservation){
const reservations=l.rows('SELECT r.*,p.id AS lock_id FROM price_lock_pool_reservations r JOIN price_locks p ON p.id=r.price_lock_id WHERE p.final_order_id=?',order.id);
for(const reservation of reservations){
dates.add(reservation.pool_id);
const net=lockBatches(l,reservation.lock_id,JSON.parse(reservation.snapshot));
const net=lockBatches(l,reservation.lock_id,JSON.parse(reservation.snapshot),reservation.line_index);
personal||=[...net].some(([id,mg])=>mg>0&&purchaseSource(l,id));
}
if(!personal&&target)for(const date of dates){