Browse Source

可变更数量计算问题

MaiXinRong 3 years ago
parent
commit
cab7bed62d
3 changed files with 8 additions and 4 deletions
  1. 1 1
      app/controller/stage_controller.js
  2. 2 1
      app/public/js/stage.js
  3. 5 2
      app/service/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 bills = data.bills ? data.bills : await ctx.service.ledger.getDataById(data.pos.lid);
                 const pos = data.pos;
                 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
                 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.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);
                     : await ctx.service.stageChange.getLastestStageData(ctx.tender.id, ctx.stage.id, bills.id, pos ? pos.id : -1);

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

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

+ 5 - 2
app/service/change.js

@@ -1190,7 +1190,7 @@ module.exports = app => {
          * @param pos - 查询的部位
          * @param pos - 查询的部位
          * @return {Promise<*>} - 可用的变更令列表
          * @return {Promise<*>} - 可用的变更令列表
          */
          */
-        async getValidChanges(tid, sorder, bills, pos) {
+        async getValidChanges(tender, stage, bills, pos) {
             const self = this;
             const self = this;
             const getFilterPart = function(field, value) {
             const getFilterPart = function(field, value) {
                 return value
                 return value
@@ -1217,9 +1217,12 @@ module.exports = app => {
                 '  ) As scb ON cb.id = scb.cbid' +
                 '  ) As scb ON cb.id = scb.cbid' +
                 '  WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
                 '  WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
                 '  ORDER BY c.in_time';
                 '  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);
             const changes = await this.db.query(sql, sqlParam);
             for (const c of changes) {
             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 ' +
                 const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
                     '  FROM ?? As ca ' +
                     '  FROM ?? As ca ' +
                     '  Left Join ?? As pa ' +
                     '  Left Join ?? As pa ' +