合并跨日余料并支持历史料价复核更正

增加订单货盘筛选,统一当天加权料价,保留历史订单成本;退货按原金料成本回池,历史购料更正经复核后同步结转。708 项测试通过。
This commit is contained in:
summer committed 2026-10-26 17:07:26 +08:00
1 parent 505110ab0e
commit ab9d3009ea
18 files changed
+1163 -77

No files matched your search

+9
View File
@@ -110,6 +110,11 @@ function createApp(options={}){
if(route==='/api/logout'&&isPost){const token=req.headers.cookie?.split(';').map(x=>x.trim()).find(x=>x.startsWith('mm_session='))?.slice(11);if(token)actorLedger.run('DELETE FROM sessions WHERE hash=?',sha(token));res.setHeader('Set-Cookie','mm_session=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0');return send(res,200,{ok:true});}
if(route==='/api/state'&&!isPost){const orders=actorLedger.visibleRows('order',actorLedger.rows('SELECT id FROM orders ORDER BY created DESC')).map(r=>actorLedger.detail(r.id));return send(res,200,{today:today(),mode,user:actor,members:TeamMembers.MEMBERS,pockets:ACTIVE_POCKETS,accounts:ACCOUNTS,inventory:actorLedger.inventory(),orders:orders.map(({audit,payments,expenses,settlements,...o})=>o),priceLockCounts:actorLedger.priceLocks({status:'pending'}).counts,materialPoolSummary:actorLedger.materialPools().summary,materialPoolSettlement:actorLedger.materialPoolSettlement(),materialPoolAllocation:actorLedger.materialPoolAllocationStatus(),sync:actor.role==='owner'?sync.status():{enabled:sync.enabled},printing:settings(actorLedger.meta('printing',defaults)),backup:actor.role==='owner'?{last:lastBackup,error:backupError}:null,movements:actorLedger.inventoryMovements({},actor).movements});}
if(route==='/api/material-pools'&&!isPost)return send(res,200,actorLedger.materialPools(Object.fromEntries(url.searchParams)));
if(route==='/api/material-pools/rolling-preview'&&!isPost){owner(actor);return send(res,200,actorLedger.rollingMaterialPreview(Object.fromEntries(url.searchParams),actor));}
if(route==='/api/material-purchase-changes'&&!isPost)return send(res,200,actorLedger.materialPurchaseChanges(Object.fromEntries(url.searchParams),actor));
const materialChangeMatch=route.match(/^\/api\/material-purchase-changes\/([a-f0-9-]{36})(?:\/(approve|reject))?$/);
if(materialChangeMatch&&!isPost){if(materialChangeMatch[2])fail('地址不存在',404);return send(res,200,actorLedger.materialPurchaseChange(materialChangeMatch[1],actor));}
const materialChangeRequest=route.match(/^\/api\/material-purchases\/([a-f0-9-]{36})\/change$/);
if(route==='/api/recoveries'&&!isPost)return send(res,200,actorLedger.recoveries(Object.fromEntries(url.searchParams),actor));
const recoveryMatch=route.match(/^\/api\/recoveries\/([a-f0-9-]{36})$/);
if(recoveryMatch&&!isPost)return send(res,200,actorLedger.recovery(recoveryMatch[1],actor));
@@ -173,6 +178,10 @@ function createApp(options={}){
if(route==='/api/orders/issue')return actorLedger.issueOrder(b,actor);
if(route==='/api/orders')return actorLedger.saveOrder(b,actor);
if(route==='/api/material-purchases')return actorLedger.createMaterialPurchase(b,actor);
if(route==='/api/material-pools/rolling-enable')return actorLedger.enableRollingMaterial(b,actor);
if(materialChangeRequest)return actorLedger.requestMaterialPurchaseChange(materialChangeRequest[1],b,actor);
if(materialChangeMatch&&materialChangeMatch[2]==='approve')return actorLedger.approveMaterialPurchaseChange(materialChangeMatch[1],b,actor);
if(materialChangeMatch&&materialChangeMatch[2]==='reject')return actorLedger.rejectMaterialPurchaseChange(materialChangeMatch[1],b,actor);
if(materialPurchaseMatch&&materialPurchaseMatch[2]==='edit')return actorLedger.editMaterialPurchase(materialPurchaseMatch[1],b,actor);
if(materialPurchaseMatch&&materialPurchaseMatch[2]==='delete')return actorLedger.deleteMaterialPurchase(materialPurchaseMatch[1],b,actor);
if(materialPoolMatch&&materialPoolMatch[2]==='settlement')return actorLedger.settleMaterialPool(materialPoolMatch[1],b,actor);