Bladeren bron

合同结算金额bug修复

ellisran 9 uur geleden
bovenliggende
commit
bf50df66a0
3 gewijzigde bestanden met toevoegingen van 22 en 9 verwijderingen
  1. 7 2
      app/service/contract.js
  2. 8 5
      app/service/contract_pay.js
  3. 7 2
      app/service/contract_tree.js

+ 7 - 2
app/service/contract.js

@@ -146,8 +146,13 @@ module.exports = app => {
                         if (!Number.isFinite(settlePrice) || settlePrice < 0) {
                             throw '结算金额只能输入大于等于0的数字';
                         }
-                        if (settlePrice !== 0 && settlePrice < Number(updateNode.yf_price || 0)) {
-                            throw '结算金额不能小于累计应' + (options.contract_type === 1 ? '付' : '回') + '金额';
+                        const actionName = options.contract_type === 1 ? '付' : '回';
+                        const yfPrice = Number(updateNode.yf_price || 0);
+                        if (settlePrice === 0 && Number(updateNode.total_price || 0) < yfPrice) {
+                            throw '合同金额不能小于累计应' + actionName + '金额';
+                        }
+                        if (settlePrice !== 0 && settlePrice < yfPrice) {
+                            throw '结算金额不能小于累计应' + actionName + '金额';
                         }
                         row.settle_price = settlePrice;
                     }

+ 8 - 5
app/service/contract_pay.js

@@ -85,7 +85,10 @@ module.exports = app => {
             if (!node) {
                 throw '合同不存在';
             }
-            await this._checkPayLimit(options, node, this.ctx.helper.add(node.yf_price || 0, data.yf_price || 0));
+            await this._checkPayLimit(options, node, this.ctx.helper.add(
+                Number(node.yf_price || 0),
+                Number(data.yf_price || 0)
+            ));
             const transaction = await this.db.beginTransaction();
             try {
                 const insertData = {
@@ -141,8 +144,8 @@ module.exports = app => {
             if (selectedStages.some(stage => !stage)) {
                 throw '付款阶段不存在或未通过审批';
             }
-            const addYfPrice = selectedStages.reduce((total, stage) => this.ctx.helper.add(total, stage.yf_price || 0), 0);
-            await this._checkPayLimit(options, node, this.ctx.helper.add(node.yf_price || 0, addYfPrice));
+            const addYfPrice = selectedStages.reduce((total, stage) => this.ctx.helper.add(total, Number(stage.yf_price || 0)), 0);
+            await this._checkPayLimit(options, node, this.ctx.helper.add(Number(node.yf_price || 0), addYfPrice));
 
             const existedPays = await this.getAllDataByCondition({ where: { cid, rela_stage: ids } });
             if (existedPays.length > 0) {
@@ -282,8 +285,8 @@ module.exports = app => {
                 throw '关联标段期的合同支付不能编辑';
             }
             const newYfPrice = this.ctx.helper.add(
-                this.ctx.helper.sub(node.yf_price || 0, cpInfo.yf_price || 0),
-                data.yf_price || 0
+                this.ctx.helper.sub(Number(node.yf_price || 0), Number(cpInfo.yf_price || 0)),
+                Number(data.yf_price || 0)
             );
             await this._checkPayLimit(options, node, newYfPrice);
             const transaction = await this.db.beginTransaction();

+ 7 - 2
app/service/contract_tree.js

@@ -195,8 +195,13 @@ module.exports = app => {
                               if (!Number.isFinite(settlePrice) || settlePrice < 0) {
                                   throw '结算金额只能输入大于等于0的数字';
                               }
-                              if (settlePrice !== 0 && settlePrice < Number(contractNode.yf_price || 0)) {
-                                  throw '结算金额不能小于累计应' + (options.contract_type === contractConst.type.expenses ? '付' : '回') + '金额';
+                              const actionName = options.contract_type === contractConst.type.expenses ? '付' : '回';
+                              const yfPrice = Number(contractNode.yf_price || 0);
+                              if (settlePrice === 0 && Number(contractNode.total_price || 0) < yfPrice) {
+                                  throw '合同金额不能小于累计应' + actionName + '金额';
+                              }
+                              if (settlePrice !== 0 && settlePrice < yfPrice) {
+                                  throw '结算金额不能小于累计应' + actionName + '金额';
                               }
                               row.settle_price = settlePrice;
                           }