支持三人台账、库存更正审批与每日人数增量

This commit is contained in:
summer committed 2026-10-25 14:19:24 +08:00
1 parent 8d9039aacf
commit f6bdfcf10d
57 files changed
+2536 -564

No files matched your search

+7 -6
View File
@@ -52,7 +52,7 @@ function projection(ledger,id){
return {cancellationPending:request?{...compact(request),stale:ledger.rawOrder(id).revision!==request.order_revision||hash(snapshot(ledger,id))!==request.snapshot_hash}:null,cancellationApproved:compact(accepted)};
}
function detail(ledger,id,actor,env){
activeActor(actor,env);const order=ledger.rawOrder(id),reason=ledger.pendingOrderChange(id)?'本单有待审批修改申请,请先由麦麦同意或驳回':eligibility(ledger,order);
activeActor(actor,env);ledger.assertAccess('order',id,actor);const order=ledger.rawOrder(id),reason=ledger.pendingOrderChange(id)?'本单有待审批修改申请,请先由麦麦同意或驳回':eligibility(ledger,order);
const requests=ledger.rows('SELECT * FROM order_cancellations WHERE order_id=? ORDER BY created DESC,rowid DESC',id).map(row=>rowDetail(ledger,row,actor));
const eligible=!reason&&!requests.some(row=>row.status==='pending'),directActionDate=env.today();
return {eligible,reason:reason||(requests.some(row=>row.status==='pending')?'本单已有取消申请,请先由麦麦审批':''),revision:order.revision,directActionDate,directToday:eligible&&order.date===directActionDate,...(eligible&&order.date===directActionDate?{summary:summary(ledger,ledger.detail(id))}:{}),
@@ -60,16 +60,17 @@ function detail(ledger,id,actor,env){
}
function list(ledger,query,actor,env){
activeActor(actor,env);const status=env.pick(query.status??'pending',['pending','approved','rejected','all'],'取消审批状态');
const rows=ledger.rows('SELECT * FROM order_cancellations'+(status==='all'?'':' WHERE status=?')+' ORDER BY created DESC,rowid DESC',...(status==='all'?[]:[status]));
const counts={pending:0,approved:0,rejected:0};for(const row of ledger.rows('SELECT status,COUNT(*) AS count FROM order_cancellations GROUP BY status'))counts[row.status]=row.count;
const all=ledger.visibleRows('order',ledger.rows('SELECT * FROM order_cancellations ORDER BY created DESC,rowid DESC'),'order_id',actor);
const rows=all.filter(row=>status==='all'||row.status===status);
const counts={pending:0,approved:0,rejected:0};for(const row of all)counts[row.status]++;
return {requests:rows.map(row=>rowDetail(ledger,row,actor)),counts,canApprove:actor.role==='owner'};
}
function read(ledger,id,actor,env){
activeActor(actor,env);const row=ledger.one('SELECT * FROM order_cancellations WHERE id=?',id);if(!row)env.fail('取消申请不存在',404);
activeActor(actor,env);const row=ledger.one('SELECT * FROM order_cancellations WHERE id=?',id);if(!row)env.fail('取消申请不存在',404);ledger.assertAccess('order',row.order_id,actor);
return rowDetail(ledger,row,actor);
}
function request(ledger,id,input,actor,env){return atomic(ledger,()=>{
activeActor(actor,env);inputObject(input,env);const order=ledger.detail(id),reason=eligibility(ledger,order);
activeActor(actor,env);ledger.assertAccess('order',id,actor);inputObject(input,env);if(Object.hasOwn(input,'member'))ledger.selectedMember(input,actor,ledger.entityMember('order',id));const order=ledger.detail(id),reason=eligibility(ledger,order);
if(reason)env.fail(reason,409);
if(pending(ledger,id))env.fail('本单已有待审批取消申请,请先由麦麦处理',409);
if(ledger.pendingOrderChange(id))env.fail('本单有待审批修改申请,请先由麦麦同意或驳回',409);
@@ -130,7 +131,7 @@ function approve(ledger,id,input,actor,env){return atomic(ledger,()=>{
return executeVoid(ledger,order,{requestId:id,reason:row.reason,note,date:env.today(),requestedBy:row.requester_name,requestedAt:row.created,reviewed},actor,env);
});}
function cancelToday(ledger,id,input,actor,env){return atomic(ledger,()=>{
activeActor(actor,env);inputObject(input,env);const order=ledger.detail(id),today=env.today(),date=env.day(input.date??today);
activeActor(actor,env);ledger.assertAccess('order',id,actor);inputObject(input,env);const order=ledger.detail(id),today=env.today(),date=env.day(input.date??today);
ledger.guardOrderChange(id);ledger.guardOrderCancellation(id,{action:'canceltoday'});
if(order.date!==today||date!==today)env.fail('仅原单日期和操作日期都为今天时可直接取消;其他日期请提交取消申请,由麦麦复核',403);
const unavailable=eligibility(ledger,order);if(unavailable)env.fail(unavailable,409);