MaiXinRong 2 years ago
parent
commit
7ef8ecd278
2 changed files with 76 additions and 77 deletions
  1. 38 39
      app/service/stage_change.js
  2. 38 38
      app/service/stage_import_change.js

+ 38 - 39
app/service/stage_change.js

@@ -618,45 +618,44 @@ module.exports = app => {
             });
             if (change.length === 0) return [];
 
-            // 因为总包导入后,单价不一定与分包相关,为了避免错误,不计算
-            // const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
-            //     where: { cid: change.map(x => { return x.cid; }) }
-            // });
-            // const changeBillsIndex = {}, changeBillsPart = {};
-            // for (const cb of changeBills) {
-            //     changeBillsIndex[cb.id] = cb;
-            //     if (!changeBillsPart[cb.cid]) changeBillsPart[cb.cid] = [];
-            //     changeBillsPart[cb.cid].push(cb);
-            // }
-            // const stageChangeBills = await this.getChangeBillsWithUsedInfo(stage);
-            // for (const scb of stageChangeBills) {
-            //     if (!scb.qty) continue;
-            //
-            //     const cb = changeBillsIndex[scb.cbid];
-            //     if (cb) cb.used_qty = this.ctx.helper.add(cb.used_qty, scb.qty);
-            // }
-            // for (const cid in changeBillsPart) {
-            //     const c = change.find(x => { return x.cid === cid });
-            //     if (!c) continue;
-            //
-            //     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);
-            //         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);
-            //         }
-            //     }
-            //     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;
-            // }
-            // return change;
+            const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
+                where: { cid: change.map(x => { return x.cid; }) }
+            });
+            const changeBillsIndex = {}, changeBillsPart = {};
+            for (const cb of changeBills) {
+                changeBillsIndex[cb.id] = cb;
+                if (!changeBillsPart[cb.cid]) changeBillsPart[cb.cid] = [];
+                changeBillsPart[cb.cid].push(cb);
+            }
+            const stageChangeBills = await this.getChangeBillsWithUsedInfo(stage);
+            for (const scb of stageChangeBills) {
+                if (!scb.qty) continue;
+
+                const cb = changeBillsIndex[scb.cbid];
+                if (cb) cb.used_qty = this.ctx.helper.add(cb.used_qty, scb.qty);
+            }
+            for (const cid in changeBillsPart) {
+                const c = change.find(x => { return x.cid === cid });
+                if (!c) continue;
+
+                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);
+                    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);
+                    }
+                }
+                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;
+            }
+            return change;
         }
 
         async getStageMinusChange(stage) {

+ 38 - 38
app/service/stage_import_change.js

@@ -105,44 +105,44 @@ module.exports = app => {
                 : await this.getImportChange(stage.id);
             if (change.length === 0) return [];
 
-
-            const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
-                where: { cid: change.map(x => { return x.cid; }) }
-            });
-            const changeBillsIndex = {}, changeBillsPart = {};
-            for (const cb of changeBills) {
-                changeBillsIndex[cb.id] = cb;
-                if (!changeBillsPart[cb.cid]) changeBillsPart[cb.cid] = [];
-                changeBillsPart[cb.cid].push(cb);
-            }
-            const stageChangeBills = await this.getChangeBillsWithUsedInfo(stage);
-            for (const scb of stageChangeBills) {
-                if (!scb.rela_qty) continue;
-
-                const cb = changeBillsIndex[scb.rela_cbid];
-                if (cb) cb.used_qty = this.ctx.helper.add(cb.used_qty, scb.rela_qty);
-            }
-            for (const cid in changeBillsPart) {
-                const c = change.find(x => { return x.cid === cid });
-                if (!c) continue;
-
-                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);
-                    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);
-                    }
-                }
-                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;
-            }
+            // 因为总包导入后,单价不一定与分包相关,为了避免错误,不计算
+            // const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
+            //     where: { cid: change.map(x => { return x.cid; }) }
+            // });
+            // const changeBillsIndex = {}, changeBillsPart = {};
+            // for (const cb of changeBills) {
+            //     changeBillsIndex[cb.id] = cb;
+            //     if (!changeBillsPart[cb.cid]) changeBillsPart[cb.cid] = [];
+            //     changeBillsPart[cb.cid].push(cb);
+            // }
+            // const stageChangeBills = await this.getChangeBillsWithUsedInfo(stage);
+            // for (const scb of stageChangeBills) {
+            //     if (!scb.rela_qty) continue;
+            //
+            //     const cb = changeBillsIndex[scb.rela_cbid];
+            //     if (cb) cb.used_qty = this.ctx.helper.add(cb.used_qty, scb.rela_qty);
+            // }
+            // for (const cid in changeBillsPart) {
+            //     const c = change.find(x => { return x.cid === cid });
+            //     if (!c) continue;
+            //
+            //     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);
+            //         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);
+            //         }
+            //     }
+            //     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;
+            // }
             return change;
         }