调整当天订单审批规则并完善订单复核状态展示
This commit is contained in:
1 parent
a506fb1228
commit
8a4d1df248
19 files changed
+545
-105
No files matched your search
+14
-5
@@ -16,6 +16,7 @@ const OrderCancellations=require('./order-cancellations');
|
||||
const OrderChanges=require('./order-changes');
|
||||
// 仅服务器的新单生成流程能传入,客户端字段不能取得这个权限。
|
||||
const NEW_ORDER_ACTION=Symbol('newOrderAction');
|
||||
const SAME_DAY_ORDER_ACTION=Symbol('sameDayOrderAction');
|
||||
const PRICE_LOCK_DELIVERY=Symbol('priceLockDelivery');
|
||||
const FEE_LABELS={shipping:'快递费',box:'包装盒',certificate:'证书',braiding:'编绳',sticker:'手机贴',other:'其他直接费用'};
|
||||
const POCKETS = ['现货','金料','找金','回收旧料','君宝汇','臻金汇','金金','定制工厂'];
|
||||
@@ -139,6 +140,7 @@ class Ledger {
|
||||
orderCancellationRequest(id,actor){return OrderCancellations.read(this,id,actor,priceLockEnv);}
|
||||
requestOrderCancellation(id,input,actor){return OrderCancellations.request(this,id,input,actor,priceLockEnv);}
|
||||
approveOrderCancellation(id,input,actor){return OrderCancellations.approve(this,id,input,actor,priceLockEnv);}
|
||||
cancelOrderToday(id,input,actor){return OrderCancellations.cancelToday(this,id,input,actor,priceLockEnv);}
|
||||
rejectOrderCancellation(id,input,actor){return OrderCancellations.reject(this,id,input,actor,priceLockEnv);}
|
||||
guardOrderCancellation(id,options){return OrderCancellations.guard(this,id,options,priceLockEnv);}
|
||||
detail(id){
|
||||
@@ -237,7 +239,7 @@ class Ledger {
|
||||
}).filter(item=>item.status==='estimated'||item.amount>0);
|
||||
}
|
||||
recordFees(o,items,date,actor,context=null){
|
||||
if(actor.role!=='owner'&&context!==NEW_ORDER_ACTION)fail('已开订单的费用须先提交复核申请,由麦麦批准后入账',403);
|
||||
if(actor.role!=='owner'&&context!==NEW_ORDER_ACTION&&context!==SAME_DAY_ORDER_ACTION)fail('已开订单的费用须先提交复核申请,由麦麦批准后入账',403);
|
||||
if(items.some(f=>f.amount===null))fail('请补齐附加成本;没有发生的费用填0');
|
||||
for(const f of items){if(f.amount>0)this.run('INSERT INTO expenses VALUES (?,?,?,?,?,?,?,?)',randomUUID(),o.id,date,f.amount,f.payer,f.note,actor.name,now());}
|
||||
const keys=new Set(items.map(f=>f.key));this.run('UPDATE orders SET fee_items=?,fees_date=? WHERE id=?',JSON.stringify(o.fee_items.map(f=>keys.has(f.key)?{...items.find(item=>item.key===f.key),status:'recorded'}:f)),date,o.id);
|
||||
@@ -414,13 +416,19 @@ class Ledger {
|
||||
}
|
||||
journal(id,date,kind,sales,goods,expense){this.run('INSERT INTO journal VALUES (?,?,?,?,?,?,?,?,?)',randomUUID(),id,date,kind,sales,goods,expense,sales-goods-expense,now());this.dirty(date);}
|
||||
action(id,action,input,actor,context=null){
|
||||
const o=this.detail(id);const date=day(input.date||today(),o.date);
|
||||
const o=this.detail(id);const date=day(input.date||today(),actor.role==='assistant'&&['expense','fees','refund','return'].includes(action)?'2000-01-01':o.date);
|
||||
if(action==='cancel')fail('取消订单须先提交取消申请,并由麦麦账号审批;旧取消接口不能直接作废订单',409);
|
||||
this.guardOrderCancellation(id,{action,type:input.type});
|
||||
this.guardOrderChange(id,{action});
|
||||
if(action==='material')owner(actor);
|
||||
let sameDayDirect=false;
|
||||
if(actor.role!=='owner'&&context!==NEW_ORDER_ACTION){
|
||||
if(['expense','fees','refund','return','cost'].includes(action))fail('这项订单变更须先提交复核申请,由麦麦批准后入账',403);
|
||||
if(['expense','fees','refund','return','cost'].includes(action)){
|
||||
if(actor.role!=='assistant'||action==='cost'||o.date!==today()||date!==today())fail('这项订单变更须先提交复核申请;助理仅可直接保存原单日期和操作日期都为今天的费用、退款或退货',403);
|
||||
if(!Number.isSafeInteger(input.revision)||input.revision!==o.revision)fail('订单有新变动,请保留输入并重新读取后核对',409);
|
||||
if(input.verified!==true)fail('请核实实际凭据与本次操作后勾选确认');
|
||||
text(input.reason,'本次操作原因',200);sameDayDirect=true;
|
||||
}
|
||||
if(o.pendingFees.length&&(action==='complete'||action==='confirm'&&input.feesVerified===true))fail('本单还有待记费用,请先提交旧费用核实申请,由麦麦批准后继续交付',403);
|
||||
}
|
||||
// 整单更正后旧错日期可能已全额冲零;审计行仍保留,但不能阻挡后续真实业务。
|
||||
@@ -460,7 +468,7 @@ class Ledger {
|
||||
const fees=this.validateFees(input.fee_items);
|
||||
const keys=new Set(o.pendingFees.map(f=>f.key));
|
||||
if(fees.length!==keys.size||fees.some(f=>!keys.has(f.key)))fail('请逐项核实本单预估成本,不要遗漏');
|
||||
this.recordFees(o,fees,date,actor,context);
|
||||
this.recordFees(o,fees,date,actor,sameDayDirect?SAME_DAY_ORDER_ACTION:context);
|
||||
} else if(action==='cost'){
|
||||
if(o.status!=='confirmed')fail('只能在交付前补齐成本;交付后成本已锁定');
|
||||
if(!Array.isArray(input.costs)||input.costs.length!==o.lines.length)fail('请逐行填写成本');
|
||||
@@ -560,7 +568,8 @@ class Ledger {
|
||||
} else if(action==='print'){
|
||||
this.audit(id,'打开打印页',actor,{mode:input.mode==='overlay'?'预印纸套打':'完整单据',notice:'不代表纸张已输出'});return {id};
|
||||
} else fail('不支持的订单操作');
|
||||
this.touch(id);this.dirty(date);this.audit(id,action,actor,{...input,revision:this.rawOrder(id).revision});return {id};
|
||||
if(sameDayDirect)this.run('UPDATE orders SET reviewed_revision=0 WHERE id=?',id);
|
||||
this.touch(id);this.dirty(date);this.audit(id,action,actor,{...input,...(sameDayDirect?{direct:true,directDate:date}:{}),revision:this.rawOrder(id).revision});return {id};
|
||||
}
|
||||
publicOrder(id){
|
||||
const o=this.detail(id);
|
||||
|
||||
Reference in new issue
Block a user