瀏覽代碼

合同支付,未达起扣金额时,直接输入本期金额,不计算

MaiXinRong 6 年之前
父節點
當前提交
1c16e48545
共有 3 個文件被更改,包括 45 次插入40 次删除
  1. 7 8
      app/lib/pay_calc.js
  2. 9 2
      app/public/js/stage_pay.js
  3. 29 30
      app/service/stage_pay.js

+ 7 - 8
app/lib/pay_calc.js

@@ -35,7 +35,6 @@ class PayCalculate {
             //     return 0;
             // }
         });
-        console.log(this.bases);
         for (const b of this.bases) {
             b.reg = new RegExp(b.code, 'igm');
         }
@@ -160,12 +159,12 @@ class PayCalculate {
         yfPay.tp = 0;
         for (const p of pays) {
             if (p.ptype === payType.normal || p.ptype === payType.wc) {
-                if (p.expr && p.expr !== '') {
-                    if (!p.pause && (!p.sprice || addRela.gather_tp > p.sprice)) {
+                if (!p.pause && (!p.sprice || addRela.gather_tp > p.sprice)) {
+                    if (p.expr && p.expr !== '') {
                         const first = !(p.pre_tp && !this.ctx.helper.checkZero(p.pre_tp));
                         const value = this.ctx.helper.round(this.calculateTpExpr(p, first, addRela), this.decimal);
                         if (p.rprice) {
-                            if (this.checkDeadline(p)) {
+                            if (this.checkDeadline(p, addRela)) {
                                 p.tp = this.ctx.helper.sub(p.rprice, p.pre_total_price);
                             } else {
                                 p.tp = Math.min(this.ctx.helper.sub(p.rprice, p.pre_total_price), value);
@@ -173,11 +172,11 @@ class PayCalculate {
                         } else {
                             p.tp = value;
                         }
-                    } else {
-                        p.tp = null;
+                    } else if (p.tp && !this.ctx.helper.checkZero(p.tp)) {
+                        p.tp = this.ctx.helper.round(p.tp, this.decimal);
                     }
-                } else if (p.tp && !this.ctx.helper.checkZero(p.tp)) {
-                    p.tp = this.ctx.helper.round(p.tp, this.decimal);
+                } else {
+                    p.tp = 0;
                 }
                 // 累加 至 应付
                 if (p.is_yf) {

+ 9 - 2
app/public/js/stage_pay.js

@@ -149,6 +149,13 @@ $(document).ready(() => {
             rprice: function (data) {
                 return payCol.readOnly.sprice(data); // 同起扣金额
             },
+            pause: function (data) {
+                if (payCol.readOnly.isOld(data)) { // 上报或审批后,仅原报,可修改
+                    return payCol.readOnly.isSpecial(data) || !payCol.readOnly.isYB(data);
+                } else { // 新增时,新增人可修改
+                    return payCol.readOnly.isSpecial(data);
+                }
+            }
         }
     };
     SpreadJsObj.initSpreadSettingEvents(paySpreadSetting, payCol);
@@ -628,7 +635,7 @@ $(document).ready(() => {
                 },
                 disabled: function (key, opt) {
                     const select = SpreadJsObj.getSelectObject(paySpread.getActiveSheet());
-                    return readOnly || payCol.readOnly.minus(select);
+                    return readOnly || payCol.readOnly.pause(select);
                 }
             },
             'stop': {
@@ -655,7 +662,7 @@ $(document).ready(() => {
                 },
                 disabled: function (key, opt) {
                     const select = SpreadJsObj.getSelectObject(paySpread.getActiveSheet());
-                    return readOnly || payCol.readOnly.minus(select);
+                    return readOnly || payCol.readOnly.pause(select);
                 }
             },
             'setDeadline': {

+ 29 - 30
app/service/stage_pay.js

@@ -178,35 +178,22 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async save(saveData) {
-            const datas = saveData instanceof Array ? saveData : [saveData];
-            const transaction = await this.db.beginTransaction();
-            try {
-                // 更新数据
-                for (const data of datas) {
-                    const stagePay = await this.getStagePay(this.ctx.stage, data.pid);
-                    const updateData = { id: stagePay.id };
-                    if (data.name !== undefined) { updateData.name = data.name }
-                    if (data.expr !== undefined) { updateData.expr = data.expr }
-                    if (data.tp !== undefined) { updateData.tp = data.tp }
-                    if (data.pause !== undefined) { updateData.pause = data.pause }
-                    const result = await transaction.update(this.tableName, updateData);
-                    if (result.affectedRows !== 1) {
-                        throw '保存数据失败';
-                    }
-                    // 缓存至pay
-                    // if (data.expr !== undefined) {
-                    //     const pr = await transaction.update(this.ctx.service.pay.tableName, {
-                    //         id: data.pid, expr: data.expr
-                    //     });
-                    //     if (pr.affectedRows !== 1) {
-                    //         throw '保存数据失败';
-                    //     }
-                    // }
-                }
-                await transaction.commit();
-            } catch(err) {
-                await transaction.rollback();
-                throw err;
+            const datas = saveData instanceof Array ? saveData : [saveData], updateDatas = [];
+            const stagePays = await this.getStagePay(this.ctx.stage, this._.map(datas, 'pid'));
+            for (const data of datas) {
+                const stagePay = stagePays.find(function (x) {
+                    return x.pid === data.pid;
+                });
+                const updateData = {id: stagePay.id};
+                if (data.name !== undefined) { updateData.name = data.name }
+                if (data.expr !== undefined) { updateData.expr = data.expr }
+                if (data.tp !== undefined) { updateData.tp = data.tp }
+                if (data.pause !== undefined) { updateData.pause = data.pause }
+                updateDatas.push(updateData);
+            }
+            const result = await this.db.updateRows(this.tableName, updateDatas);
+            if (result.affectedRows !== updateDatas.length) {
+                throw '保存数据失败';
             }
         }
 
@@ -224,12 +211,24 @@ module.exports = app => {
             const PayCalculator = require('../lib/pay_calc');
             const payCalculator = new PayCalculator(this.ctx, this.ctx.tender.info.decimal);
             await payCalculator.calculateAll(stagePays);
+            const srUpdate = [], update = [];
             for (const sp of stagePays) {
-                await transaction.update(this.tableName, {
+                update.push({
                     id: sp.id,
                     tp: sp.tp,
                     end_tp: sp.end_tp
                 });
+                if (stage.order === 1 || sp.csorder >= stage.order) {
+                    srUpdate.push({
+                        id: sp.pid,
+                        sprice: sp.sprice,
+                        rprice: sp.rprice,
+                    });
+                }
+            }
+            await transaction.updateRows(this.tableName, update);
+            if (srUpdate.length > 0) {
+                await transaction.updateRows(this.ctx.service.pay.tableName, srUpdate);
             }
         }