Bladeren bron

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

Tony Kang 1 jaar geleden
bovenliggende
commit
286b3c12d4

+ 1 - 2
app/controller/measure_controller.js

@@ -47,8 +47,7 @@ module.exports = app => {
                     auditConst2: JSON.stringify(auditConst),
                     auditType,
                 };
-                renderData.stages = await ctx.service.stage.getValidStages(ctx.tender.id);
-                if (renderData.stages.length > 0) await this.ctx.service.stage.checkStageGatherData(renderData.stages[0], this.ctx.session.sessionUser.is_admin);
+                renderData.stages = await ctx.service.stage.getValidStages(ctx.tender.id, this.ctx.session.sessionUser.is_admin);
                 for (const s of renderData.stages) {
                     // 根据期状态返回展示用户
                     s.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(s.id, s.status, s.times);

+ 3 - 2
app/lib/revise_price.js

@@ -391,6 +391,7 @@ class revisePriceCalc {
         if (result.ibData.length > 0) await transaction.insert(this.ctx.service.stageBills.tableName, result.ibData);
         if (result.ubData.length > 0) await transaction.updateRows(this.ctx.service.stageBills.tableName, result.ubData);
         if (result.scData.length > 0) await transaction.updateRows(this.ctx.service.stageChange.tableName, result.scData);
+        if (result.ibData.length > 0 || result.ubData.length > 0) await transaction.update(this.ctx.service.stage.tableName, { id: stage.id, check_calc: true});
     }
     /**
      * 计算修订台账
@@ -435,9 +436,9 @@ class revisePriceCalc {
             for (const s of stages) {
                 if (s.status === audit.stage.status.checked) continue;
                 if (!pcTp) {
-                    pcTp = await this._calcStage(latestStage, xmj, transaction);
+                    pcTp = await this._calcStage(s, xmj, transaction);
                 } else {
-                    await this._calcStageWithoutPc(latestStage, xmj, transaction);
+                    await this._calcStageWithoutPc(s, xmj, transaction);
                 }
             }
         }

+ 1 - 1
app/public/js/shares/sjs_setting.js

@@ -122,7 +122,7 @@ const sjsSettingObj = (function () {
     const setIsTpCol = function(cols, rela) {
         setRelaCols(cols, rela, function(col, r) {
             col.headerCellType = 'tip';
-            col.getHeaderTip = function() { return '可用单位:元、总额、台、个、处、月 、棵、套、组、辆'; };
+            col.getHeaderTip = function() { return '可用单位:总额、元、台、个、处、月 、棵、套、组、辆、项、座、根、块、系统'; };
         });
     };
     return {

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

@@ -1320,7 +1320,7 @@ $(document).ready(() => {
                 const node = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
                 const posRange = stagePos.getLedgerPos(node.id);
-                const tpUnit = ['总额', '元', '台', '个', '处', '月', '棵', '套', '组', '辆'];
+                const tpUnit = ['总额', '元', '台', '个', '处', '月', '棵', '套', '组', '辆', '项', '座', '根', '块', '系统'];
                 if (node.pre_used === 1 ||
                     (node.children && node.children.length > 0) ||
                     (tpUnit.indexOf(node.unit) < 0) ||

+ 3 - 3
app/public/js/stage_audit.js

@@ -304,14 +304,14 @@ $(document).ready(function () {
                     html.push(`<td class="text-left d-flex"></td>`);
                 }
                 html.push(`<td></span> ${auditor.name} <small class="text-muted">${auditor.role}</small></td>`);
-                html.push(`<td style="text-align: center"><span class="${auditConst.auditStringClass[auditor.status]}">${ auditor.status !== auditConst.status.uncheck ? auditConst.auditString[auditor.status] : '待审批' }</span></td>`);
+                html.push(`<td style="text-align: center"><span class="${sam_auditConst.auditStringClass[auditor.status]}">${ auditor.status !== sam_auditConst.status.uncheck ? sam_auditConst.auditString[auditor.status] : '待审批' }</span></td>`);
                 html.push('<td style="text-align: center">');
-                if (auditor.status === auditConst.status.checking && j === group.length - 1) {
+                if (auditor.status === sam_auditConst.status.checking && j === group.length - 1) {
                     html.push('<span class="dropdown mr-2">',
                         `<a href="javascript: void(0)" class="add-audit" id="${auditor.aid}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,
                         makeSelectAudit(auditor.aid+'_add', auditor.aid, 'add'),'</div>', '</span>');
                 }
-                if (auditor.status === auditConst.status.uncheck) {
+                if (auditor.status === sam_auditConst.status.uncheck) {
                     if (j === group.length - 1) {
                         html.push('<span class="dropdown mr-2">',
                             `<a href="javascript: void(0)" class="add-audit" id="${auditor.aid}_add_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">增加</a>`,

+ 2 - 2
app/service/stage.js

@@ -407,7 +407,7 @@ module.exports = app => {
          * @param tenderId
          * @return {Promise<void>}
          */
-        async getValidStages(tenderId) {
+        async getValidStages(tenderId, force = false) {
             let stages = await this.db.select(this.tableName, {
                 where: { tid: tenderId },
                 orders: [['order', 'desc']],
@@ -423,7 +423,7 @@ module.exports = app => {
             if (stages.length === 0) return stages;
 
             for (const s of stages) {
-                if (s.status !== auditConst.stage.status.checked) await this.checkStageGatherData(s, true);
+                if (s.status !== auditConst.stage.status.checked) await this.checkStageGatherData(s, force);
                 s.tp = this.ctx.helper.sum([s.contract_tp, s.qc_tp, s.pc_tp]);
                 s.pre_tp = this.ctx.helper.add(s.pre_contract_tp, s.pre_qc_tp);
                 s.end_tp = this.ctx.helper.add(s.pre_tp, s.tp);

+ 7 - 7
app/service/stage_audit.js

@@ -424,8 +424,10 @@ module.exports = app => {
             const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
             const stageInfo = await this.ctx.service.stage.getDataById(stageId);
 
-            const transaction = await this.db.beginTransaction();
+            // 计算并合同支付最终数据
+            const [yfPay, sfPay, stagePays] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage);
 
+            const transaction = await this.db.beginTransaction();
             try {
                 const ledgerTp = await this._updateTender(transaction);
                 // 添加通知
@@ -460,8 +462,6 @@ module.exports = app => {
                     end_time: time,
                 });
                 await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, selfAudit.id);
-                // 计算并合同支付最终数据
-                const [yfPay, sfPay, stagePays] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
                 const stageTp = {
                     contract_tp: tpData.contract_tp,
                     qc_tp: tpData.qc_tp,
@@ -574,10 +574,10 @@ module.exports = app => {
                                 await this.ctx.service.stageTempLand.addInitialStageData(ns, this.ctx.stage, transaction);
                             }
                             const preStageTp = {
-                                pre_contract_tp: this.ctx.helper.sum([this.ctx.stage.pre_contract_tp, stageTp.contract_tp, stageTp.contract_pc_tp]),
-                                pre_qc_tp: this.ctx.helper.sum([this.ctx.stage.pre_qc_tp, stageTp.qc_tp, stageTp.qc_pc_tp]),
-                                pre_positive_qc_tp: this.ctx.helper.sum([this.ctx.stage.pre_positive_qc_tp, stageTp.positive_qc_tp, stageTp.positive_qc_pc_tp]),
-                                pre_negative_qc_tp: this.ctx.helper.sum([this.ctx.stage.pre_negative_qc_tp, stageTp.negative_qc_tp, stageTp.negative_qc_pc_tp]),
+                                pre_contract_tp: this.ctx.helper.sum([this.ctx.stage.pre_contract_tp, stageTp.contract_tp, this.ctx.stage.contract_pc_tp]),
+                                pre_qc_tp: this.ctx.helper.sum([this.ctx.stage.pre_qc_tp, stageTp.qc_tp, this.ctx.stage.qc_pc_tp]),
+                                pre_positive_qc_tp: this.ctx.helper.sum([this.ctx.stage.pre_positive_qc_tp, stageTp.positive_qc_tp, this.ctx.stage.positive_qc_pc_tp]),
+                                pre_negative_qc_tp: this.ctx.helper.sum([this.ctx.stage.pre_negative_qc_tp, stageTp.negative_qc_tp, this.ctx.stage.negative_qc_pc_tp]),
                                 pre_yf_tp: this.ctx.helper.add(this.ctx.stage.pre_yf_tp, stageTp.yf_tp),
                                 pre_sf_tp: this.ctx.helper.add(this.ctx.stage.pre_sf_tp, stageTp.sf_tp),
                             };

+ 13 - 6
app/service/stage_pay.js

@@ -144,6 +144,7 @@ module.exports = app => {
             const stagePays = [];
             const prePays = await this.getStageLastestPays(preStage);
             for (const pp of prePays) {
+                console.log(pp);
                 const p = this._.find(pays, {id: pp.pid});
                 if (!p.valid) continue;
                 stagePays.push({
@@ -263,9 +264,8 @@ module.exports = app => {
          * @return {Promise<Array>} 计算结果(应付和实付数据)
          */
         async calcAllStagePays(stage, transaction) {
-            if (!stage || !transaction) {
-                throw '计算数据错误';
-            }
+            if (!stage) throw '计算数据错误';
+
             const stagePays = await this.getStagePays(stage);
             const PayCalculator = require('../lib/pay_calc');
             const payCalculator = new PayCalculator(this.ctx, stage, this.ctx.tender.info);
@@ -286,9 +286,16 @@ module.exports = app => {
                     rprice: sp.rprice,
                 });
             }
-            await transaction.updateRows(this.tableName, update);
-            if (srUpdate.length > 0) {
-                await transaction.updateRows(this.ctx.service.pay.tableName, srUpdate);
+            const conn = transaction || await this.db.beginTransaction();
+            try {
+                await conn.updateRows(this.tableName, update);
+                if (srUpdate.length > 0) {
+                    await conn.updateRows(this.ctx.service.pay.tableName, srUpdate);
+                }
+                if (!transaction) await conn.commit();
+            } catch (err) {
+                if (!transaction) await conn.rollback();
+                throw '计算合同支付数据错误';
             }
             const yf = this._.find(stagePays, {ptype: payConst.payType.yf});
             const sf = this._.find(stagePays, {ptype: payConst.payType.sf});