新增回收置换记账及打印,完善订单标志和购料单价

This commit is contained in:
summer committed 2026-10-26 14:44:07 +08:00
1 parent 844a1fa860
commit 505110ab0e
26 files changed
+1201 -64

No files matched your search

+3 -1
View File
@@ -114,6 +114,7 @@ function projection(ledger,id){
const request=pending(ledger,id);return {changePending:request?{...compact(request),stale:stale(ledger,request)}:null,changeApproved:compact(approved(ledger,id))};
}
function eligibility(ledger,order,action){
if(order.recovery_id)return order.recovery_immutable_reason;
const blocked=pendingReason(ledger,order.id);if(blocked)return blocked;
if(action==='edit')return '';
if(order.cancellationApproved)return '本单已作废,不能新增费用、收退款、退货或成本';
@@ -125,7 +126,7 @@ function eligibility(ledger,order,action){
return '';
}
function detail(ledger,id,actor,env){
activeActor(actor,env);ledger.assertAccess('order',id,actor);const order=ledger.detail(id),reason=pendingReason(ledger,id),directActionDate=env.today(),actions=Object.fromEntries(Object.keys(ACTION_LABELS).map(action=>{const why=eligibility(ledger,order,action);return [action,{eligible:!why,reason:why,directToday:!why&&['expense','fees','refund','return'].includes(action)&&order.date===directActionDate}];})),requests=ledger.rows('SELECT * FROM order_changes WHERE order_id=? ORDER BY created DESC,rowid DESC',id).map(row=>rowDetail(ledger,row,actor));
activeActor(actor,env);ledger.assertAccess('order',id,actor);const order=ledger.detail(id),reason=order.recovery_id?order.recovery_immutable_reason:pendingReason(ledger,id),directActionDate=env.today(),actions=Object.fromEntries(Object.keys(ACTION_LABELS).map(action=>{const why=eligibility(ledger,order,action);return [action,{eligible:!why,reason:why,directToday:!why&&['expense','fees','refund','return'].includes(action)&&order.date===directActionDate}];})),requests=ledger.rows('SELECT * FROM order_changes WHERE order_id=? ORDER BY created DESC,rowid DESC',id).map(row=>rowDetail(ledger,row,actor));
return {eligible:!reason,reason,actions,directActionDate,revision:order.revision,pending:requests.find(row=>row.status==='pending')||null,requests,canApprove:actor.role==='owner'};
}
function list(ledger,query,actor,env){
@@ -154,6 +155,7 @@ function pendingDecision(ledger,id,actor,env){
}
function approve(ledger,id,input,actor,env){return atomic(ledger,()=>{
inputObject(input,env);const row=pendingDecision(ledger,id,actor,env);
ledger.guardRecoveryOrder(row.order_id);
if(!Number.isSafeInteger(input.revision)||input.revision!==row.order_revision||stale(ledger,row))env.fail('订单、付款、物料或库存已有新变动,这份修改申请已过期,请驳回后重新申请',409);
if(ledger.one("SELECT id FROM order_cancellations WHERE order_id=? AND status='pending'",row.order_id))env.fail('本单有待审批取消申请,请先处理',409);
if(input.verified!==true)env.fail('请核实申请中修改前后的单据、实际收款、费用和库存后再批准');