فهرست منبع

变更概况,计算调整

MaiXinRong 3 ماه پیش
والد
کامیت
6fb3eae39d
1فایلهای تغییر یافته به همراه29 افزوده شده و 11 حذف شده
  1. 29 11
      app/service/stage_change.js

+ 29 - 11
app/service/stage_change.js

@@ -749,22 +749,40 @@ module.exports = app => {
                 const c = change.find(x => { return x.cid === cid });
                 if (!c) continue;
 
+                const sumBills = [];
                 for (const cb of changeBillsPart[cid]) {
-                    cb.tp = this.ctx.helper.mul(cb.spamount, cb.unit_price, c.tp_decimal || this.ctx.tender.info.decimal.tp);
-                    cb.used_tp = this.ctx.helper.mul(cb.used_qty, cb.unit_price, this.ctx.tender.info.decimal.tp);
-
-                    c.used_tp = this.ctx.helper.add(c.used_tp, cb.used_tp);
+                    let sb;
+                    if (cb.gcl_id) {
+                        sb = sumBills.find(x => { return x.gcl_id === cb.gcl_id; });
+                    }
+                    if (!cb.gcl_id || !sb) {
+                        sb = { gcl_id: cb.gcl_id, unit_price: cb.unit_price, used_qty: 0, p_used_qty: 0, n_used_qty: 0 };
+                        sumBills.push(sb);
+                    }
+                    sb.used_qty = this.ctx.helper.add(sb.used_qty, cb.used_qty);
                     if (cb.spamount > 0) {
-                        c.p_tp = this.ctx.helper.add(c.p_tp, cb.tp);
-                        c.p_used_tp = this.ctx.helper.add(c.p_used_tp, cb.used_tp);
-                    } else if (cb.spamount < 0){
-                        c.n_tp = this.ctx.helper.add(c.n_tp, cb.tp);
-                        c.n_used_tp = this.ctx.helper.add(c.n_used_tp, cb.used_tp);
+                        sb.p_used_qty = this.ctx.helper.add(sb.p_used_qty, cb.used_qty);
+                    } else {
+                        sb.n_used_qty = this.ctx.helper.add(sb.n_used_qty, cb.used_qty);
                     }
+
+                    cb.tp = this.ctx.helper.mul(cb.spamount, cb.unit_price, c.tp_decimal || this.ctx.tender.info.decimal.tp);
+                    cb.used_tp = this.ctx.helper.mul(cb.used_qty, cb.unit_price, this.ctx.tender.info.decimal.tp);
+                }
+                for (const sb of sumBills) {
+                    sb.used_tp = this.ctx.helper.mul(sb.used_qty, sb.unit_price, this.ctx.tender.info.decimal.tp);
+                    sb.p_used_tp = this.ctx.helper.mul(sb.p_used_qty, sb.unit_price, this.ctx.tender.info.decimal.tp);
+                    sb.n_used_tp = this.ctx.helper.mul(sb.n_used_qty, sb.unit_price, this.ctx.tender.info.decimal.tp);
+
+                    c.used_tp = this.ctx.helper.add(c.used_tp, sb.used_tp);
+                    c.p_used_tp = this.ctx.helper.add(c.p_used_tp, sb.p_used_tp);
+                    c.n_used_tp = this.ctx.helper.add(c.n_used_tp, sb.n_used_tp);
                 }
+                c.p_tp = c.positive_tp;
+                c.n_tp = c.negative_tp;
                 c.used_pt = c.total_price ? this.ctx.helper.mul(this.ctx.helper.div(c.used_tp, c.total_price, 4), 100) : 0;
-                c.p_used_pt = c.p_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.p_used_tp, c.p_tp, 4), 100) : 0;
-                c.n_used_pt = c.n_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.n_used_tp, c.n_tp, 4), 100) : 0;
+                c.p_used_pt = c.positive_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.p_used_tp, c.positive_tp, 4), 100) : 0;
+                c.n_used_pt = c.negative_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.n_used_tp, c.negative_tp, 4), 100) : 0;
             }
             return change;
         }