浏览代码

添加计算基数

MaiXinRong 3 年之前
父节点
当前提交
1bcaa350e0
共有 5 个文件被更改,包括 41 次插入3 次删除
  1. 1 1
      app/const/change.js
  2. 3 0
      app/const/deal_pay.js
  3. 0 2
      app/lib/pay_calc.js
  4. 10 0
      app/service/stage.js
  5. 27 0
      app/service/stage_change.js

+ 1 - 1
app/const/change.js

@@ -106,4 +106,4 @@ module.exports = {
         souban: { unit: '艘班' },
         mu: { unit: '亩' },
     },
-}
+};

+ 3 - 0
app/const/deal_pay.js

@@ -32,6 +32,9 @@ const calcBase = [
     {name: '本期完成计量', code: 'bqwc', limit: true, sort: 10},
     {name: '本期合同计量', code: 'bqht', limit: true, sort: 10},
     {name: '本期变更计量', code: 'bqbg', limit: true, sort: 10},
+    {name: '本期一般变更计量', code: 'ybbqbg', limit: true, sort: 15},
+    {name: '本期较大变更计量', code: 'jdbqbg', limit: true, sort: 15},
+    {name: '本期重大变更计量', code: 'zdbqbg', limit: true, sort: 15},
     {name: '100章本期完成计量', code: 'ybbqwc', limit: true, sort: 1},
     {name: '本期应付', code: 'bqyf', limit: true, ptNormalLimit: true, sort: 20},
 ];

+ 0 - 2
app/lib/pay_calc.js

@@ -105,7 +105,6 @@ class PayCalculate {
      * @param {Array} pays - (标段)合同支付数据
      */
     async calculateStartRangePrice (pays) {
-        await this.getCalcBase();
         const order = this.stage.curOrder;
         for (const p of pays) {
             // 非本期,本次添加的合同支付项,不允许计算,其中默认添加的合同支付项,归属于第一期原报
@@ -167,7 +166,6 @@ class PayCalculate {
      * @param {Array} pays - (标段&期)合同支付数据
      */
     async calculate(pays) {
-        await this.getCalcBase();
         this.yf = pays.find(function (p) {
             return p.ptype === payType.yf;
         });

+ 10 - 0
app/service/stage.js

@@ -453,6 +453,7 @@ module.exports = app => {
             const param = tenderInfo.deal_param;
             for (const cb of calcBase) {
                 const sum = await this.ctx.service.stageBills.getSumTotalPrice(stage);
+                const bg = await this.ctx.service.stageChange.getQualityTotalPrice(stage.id);
                 switch (cb.code) {
                     case 'htj':
                         cb.value = param.contractPrice;
@@ -482,6 +483,15 @@ module.exports = app => {
                         const sumGcl = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
                         cb.value = this.ctx.helper.add(sumGcl.contract_tp, sumGcl.qc_tp);
                         break;
+                    case 'ybbqbg':
+                        cb.value = bg.common;
+                        break;
+                    case 'jdbqbg':
+                        cb.value = bg.more;
+                        break;
+                    case 'zdbqbg':
+                        cb.value = bg.great;
+                        break;
                     default:
                         cb.value = 0;
                 }

+ 27 - 0
app/service/stage_change.js

@@ -11,6 +11,7 @@
 const defaultPid = -1; // 非pid
 const audit = require('../const/audit');
 const timesLen = audit.stage.timesLen;
+const changeConst = require('../const/change');
 
 module.exports = app => {
 
@@ -393,6 +394,32 @@ module.exports = app => {
             const data = await this.getAllDataByCondition({ where: { tid, sid } });
             return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid']);
         }
+
+        async getQualityTotalPrice(sid) {
+            const helper = this.ctx.helper;
+            const sql = 'SELECT sc.*, c.quality FROM ' + this.tableName + ' sc' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON sc.cid = c.cid' +
+                '  WHERE sid = ?';
+            const data = await this.db.query(sql, [sid]);
+            const bqData = [];
+            for (const d of data) {
+                if (!d.qty) continue;
+                let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
+                if (!bd) {
+                    const bills = await this.ctx.service.ledger.getDataById(d.lid);
+                    if (!bills) continue;
+                    bd = { lid: d.lid, quality: d.quality, unit_price: bills.unit_price };
+                    bqData.push(bd);
+                }
+                const tp = this.ctx.helper.mul(d.qty, bd.unit_price, this.ctx.tender.info.decimal.tp);
+                bd.tp = this.ctx.helper.add(bd.tp, tp);
+            }
+            const result = {};
+            result.common = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.common.value; }), 'tp'));
+            result.more = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.more.value; }), 'tp'));
+            result.great = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.great.value; }), 'tp'));
+            return result;
+        }
     }
 
     return StageChange;