浏览代码

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

laiguoran 3 年之前
父节点
当前提交
b805cd921b
共有 6 个文件被更改,包括 24 次插入49 次删除
  1. 1 1
      app/controller/stage_controller.js
  2. 7 23
      app/lib/stage_im.js
  3. 2 1
      app/public/js/stage.js
  4. 7 21
      app/public/js/stage_im.js
  5. 5 2
      app/service/change.js
  6. 2 1
      app/service/stage_change.js

+ 1 - 1
app/controller/stage_controller.js

@@ -504,7 +504,7 @@ module.exports = app => {
                 }
                 const bills = data.bills ? data.bills : await ctx.service.ledger.getDataById(data.pos.lid);
                 const pos = data.pos;
-                const changes = await ctx.service.change.getValidChanges(ctx.tender.id, ctx.stage.order, bills);
+                const changes = await ctx.service.change.getValidChanges(ctx.tender, ctx.stage, bills);
                 const useChanges = ctx.stage.readOnly
                     ? await ctx.service.stageChange.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder, bills.id, pos ? pos.id : -1)
                     : await ctx.service.stageChange.getLastestStageData(ctx.tender.id, ctx.stage.id, bills.id, pos ? pos.id : -1);

+ 7 - 23
app/lib/stage_im.js

@@ -488,9 +488,6 @@ class StageIm {
             if (p.children && p.children.length > 0) {
                 continue;
             }
-            if ((!p.qc_tp || p.qc_tp === 0)) {
-                continue;
-            }
             const posRange = this.pos.getLedgerPos(p.id);
             if (!posRange) {
                 for (const c of this.changes) {
@@ -501,9 +498,6 @@ class StageIm {
                 this.import_changes.forEach(x => { if (x.lid === p.id) im.changes.push(x) });
             } else {
                 for (const pp of posRange) {
-                    if ((!pp.qc_qty || pp.qc_qty === 0)) {
-                        continue;
-                    }
                     for (const c of this.changes) {
                         if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
                             im.changes.push(c);
@@ -803,9 +797,6 @@ class StageIm {
         if (!im.changes) {
             im.changes = [];
         }
-        if ((!node.qc_qty || node.qc_qty === 0)) {
-            return;
-        }
         const posRange = this.pos.getLedgerPos(node.id);
         if (!posRange) {
             for (const c of this.changes) {
@@ -816,9 +807,6 @@ class StageIm {
             this.import_changes.forEach(x => { if (x.lid === node.id) im.changes.push(x) });
         } else {
             for (const p of posRange) {
-                if ((!p.qc_qty || p.qc_qty === 0)) {
-                    continue;
-                }
                 for (const c of this.changes) {
                     if (c.lid === node.id && c.pid === p.id && c.qty && c.qty !== 0) {
                         im.changes.push(c);
@@ -950,11 +938,9 @@ class StageIm {
                     im.end_qc_tp = this.ctx.helper.mul(im.end_qc_jl, im.unit_price, tp_decimal);
                     im.calc_memo = '本期计量:' + (this.ctx.helper.checkZero(im.jl) ? 0 : im.jl) + ' ' + im.unit;
                     this.ImData.push(im);
-                    if (pp.qc_qty && pp.qc_qty !== 0) {
-                        for (const c of this.changes) {
-                            if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
-                                im.changes.push(c);
-                            }
+                    for (const c of this.changes) {
+                        if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
+                            im.changes.push(c);
                         }
                     }
                 }
@@ -982,14 +968,12 @@ class StageIm {
                 };
                 im.calc_memo = '本期计量:' + (this.ctx.helper.checkZero(im.jl) ? 0 : im.jl) + ' ' + im.unit;
                 this.ImData.push(im);
-                if (p.qc_qty && p.qc_qty !== 0) {
-                    for (const c of this.changes) {
-                        if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
-                            im.changes.push(c);
-                        }
+                for (const c of this.changes) {
+                    if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
+                        im.changes.push(c);
                     }
-                    this.import_changes.forEach(x => { if (x.lid === p.id) im.changes.push(x) });
                 }
+                this.import_changes.forEach(x => { if (x.lid === p.id) im.changes.push(x) });
             }
         }
     }

+ 2 - 1
app/public/js/stage.js

@@ -531,11 +531,12 @@ $(document).ready(() => {
         _calculateAmount() {
             for (const c of this.changes) {
                 c.bamount = _.toNumber(c.b_amount);
-                c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
+                c.vamount = ZhCalc.sub(ZhCalc.sub(c.bamount, c.used_amount), c.stage_used_amount);
                 const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
                 if (uc) {
                     c.org_uamount = uc.qty;
                     c.uamount = uc.qty;
+                    c.vamount = ZhCalc.add(c.vamount, uc.qty);
                 }
                 c.pre_amount = ZhCalc.sub(c.used_amount, c.uamount);
             }

+ 7 - 21
app/public/js/stage_im.js

@@ -507,9 +507,6 @@ const stageIm = (function () {
             if (p.children && p.children.length > 0) {
                 continue;
             }
-            if ((!p.qc_tp || p.qc_tp === 0)) {
-                continue;
-            }
             const posRange = gsPos.getLedgerPos(p.id);
             if (!posRange) {
                 for (const c of changes) {
@@ -520,9 +517,6 @@ const stageIm = (function () {
                 importChanges.forEach(x => { if (x.lid === p.id) im.changes.push(x); });
             } else {
                 for (const pp of posRange) {
-                    if ((!pp.qc_qty || pp.qc_qty === 0)) {
-                        continue;
-                    }
                     for (const c of changes) {
                         if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
                             im.changes.push(c);
@@ -778,9 +772,6 @@ const stageIm = (function () {
         if (!im.changes) {
             im.changes = [];
         }
-        if ((!node.qc_qty || node.qc_qty === 0)) {
-            return;
-        }
         const posRange = gsPos.getLedgerPos(node.id);
         if (!posRange) {
             for (const c of changes) {
@@ -791,7 +782,6 @@ const stageIm = (function () {
             importChanges.forEach(x => { if (x.lid === node.id) im.changes.push(x); });
         } else {
             for (const p of posRange) {
-                if ((!p.qc_qty || p.qc_qty === 0)) continue;
                 for (const c of changes) {
                     if (c.lid === node.id && c.pid === p.id && c.qty && c.qty !== 0) {
                         im.changes.push(c);
@@ -879,11 +869,9 @@ const stageIm = (function () {
                     };
                     im.calc_memo = '本期计量:' + (checkZero(im.jl) ? 0 : im.jl) + ' ' + im.unit;
                     ImData.push(im);
-                    if (pp.qc_qty && pp.qc_qty !== 0) {
-                        for (const c of changes) {
-                            if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
-                                im.changes.push(c);
-                            }
+                    for (const c of changes) {
+                        if (c.lid === p.id && c.pid === pp.id && c.qty && c.qty !== 0) {
+                            im.changes.push(c);
                         }
                     }
                 }
@@ -907,14 +895,12 @@ const stageIm = (function () {
                 };
                 im.calc_memo = '本期计量:' + (checkZero(im.jl) ? 0 : im.jl) + ' ' + im.unit;
                 ImData.push(im);
-                if (p.qc_qty && p.qc_qty !== 0) {
-                    for (const c of changes) {
-                        if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
-                            im.changes.push(c);
-                        }
+                for (const c of changes) {
+                    if (c.lid === p.id && c.pid == -1 && c.qty && c.qty !== 0) {
+                        im.changes.push(c);
                     }
-                    importChanges.forEach(x => { if (x.lid === p.id) im.changes.push(x); });
                 }
+                importChanges.forEach(x => { if (x.lid === p.id) im.changes.push(x); });
             }
         }
     }

+ 5 - 2
app/service/change.js

@@ -1190,7 +1190,7 @@ module.exports = app => {
          * @param pos - 查询的部位
          * @return {Promise<*>} - 可用的变更令列表
          */
-        async getValidChanges(tid, sorder, bills, pos) {
+        async getValidChanges(tender, stage, bills, pos) {
             const self = this;
             const getFilterPart = function(field, value) {
                 return value
@@ -1217,9 +1217,12 @@ module.exports = app => {
                 '  ) As scb ON cb.id = scb.cbid' +
                 '  WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
                 '  ORDER BY c.in_time';
-            const sqlParam = [tid, sorder, tid, audit.flow.status.checked];
+            const sqlParam = [tender.id, stage.order, tender.id, audit.flow.status.checked];
             const changes = await this.db.query(sql, sqlParam);
             for (const c of changes) {
+                const stageUsedData = await this.ctx.service.stageChange.getAllDataByCondition({ where: { sid: stage.id, cbid: c.cbid } });
+                const filter = this.ctx.helper.filterLastestData(stageUsedData, ['pid', 'lid'], 'stimes', 'sorder');
+                c.stage_used_amount = this.ctx.helper.sum(filter.map(x => { return x.qty }));
                 const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
                     '  FROM ?? As ca ' +
                     '  Left Join ?? As pa ' +

+ 2 - 1
app/service/stage_change.js

@@ -444,7 +444,8 @@ module.exports = app => {
 
         async getChangeWithUsedInfo(stage) {
             const change = await this.ctx.service.change.getAllDataByCondition({
-                where: { tid: stage.tid, status: audit.flow.status.checked }
+                where: { tid: stage.tid, status: audit.flow.status.checked },
+                orders: [['code', 'asc']],
             });
             if (change.length === 0) return [];