Просмотр исходного кода

重构变更金额方法,增加正负值显示

laiguoran 2 лет назад
Родитель
Сommit
77aff2d6df

+ 1 - 1
app/controller/change_controller.js

@@ -854,7 +854,7 @@ module.exports = app => {
                         responseData.data = changeList;
                         break;
                     case 'update_tp':
-                        await ctx.service.change.saveInfo({ total_price: data.updateData });
+                        await ctx.service.change.saveInfo(data.updateData);
                         break;
                     case 'order_by':
                         const result = await ctx.service.change.saveOrderBy(data.updateData, data.newLedgerList);

+ 1 - 1
app/controller/datacollect_controller.js

@@ -126,7 +126,7 @@ module.exports = app => {
                         t.total_price = sum.total_price;
                         t.deal_tp = sum.deal_tp;
                     }
-                    t.change_tp = await ctx.service.change.getChangeTp(t.id);
+                    [t.change_tp, t.change_p_tp, t.change_n_tp] = await ctx.service.change.getChangeTp(t.id);
                     // t.material_tp = await ctx.service.material.getSumMaterial(t.id);
                     // 获取本标段 本月计量期审批通过数目,变更令审批通过数目,台账修订通过数目,材料调差通过数目
                     t.month_stage_num = await ctx.service.stageAudit.getNumByMonth(t.id, startMonth, endMonth);

+ 5 - 1
app/controller/tender_controller.js

@@ -414,11 +414,15 @@ module.exports = app => {
                     tender.gather_tp = ctx.helper.sum([lastStage.contract_tp, lastStage.qc_tp, lastStage.pc_tp]);
                     tender.end_contract_tp = ctx.helper.sum([lastStage.contract_tp, lastStage.pre_contract_tp, lastStage.contract_pc_tp]);
                     tender.end_qc_tp = ctx.helper.sum([lastStage.qc_tp, lastStage.pre_qc_tp, lastStage.qc_pc_tp]);
+                    tender.end_positive_qc_tp = ctx.helper.sum([lastStage.positive_qc_tp, lastStage.pre_positive_qc_tp, lastStage.positive_qc_pc_tp]);
+                    tender.end_negative_qc_tp = ctx.helper.sum([lastStage.negative_qc_tp, lastStage.pre_negative_qc_tp, lastStage.negative_qc_pc_tp]);
                     tender.end_gather_tp = ctx.helper.add(tender.end_contract_tp, tender.end_qc_tp);
                     tender.pre_gather_tp = ctx.helper.add(lastStage.pre_contract_tp, lastStage.pre_qc_tp);
                     tender.yf_tp = lastStage.yf_tp;
-                    const change_tp = await ctx.service.change.getChangeTp(tender.id);
+                    const [change_tp, change_p_tp, change_n_tp] = await ctx.service.change.getChangeTp(tender.id);
                     tender.change_tp = change_tp;
+                    tender.change_p_tp = change_p_tp;
+                    tender.change_n_tp = change_n_tp;
                     tender.qc_ratio = ctx.helper.mul(ctx.helper.div(tender.end_qc_tp, ctx.tender.info.deal_param.contractPrice, 2), 100);
                     tender.sum = ctx.helper.add(tender.total_price, tender.change_tp);
                     tender.pre_ratio = ctx.helper.mul(ctx.helper.div(tender.pre_gather_tp, tender.sum, 2), 100);

+ 50 - 9
app/public/js/change_information.js

@@ -87,15 +87,16 @@ $(document).ready(() => {
 
     // 计算最新的变更总额和change的total_price是否一致,不一致则更新
     if (changeStatus !== auditConst.status.checked) {
-        let new_tp = 0;
-        for (const c of changeList) {
-            new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
-        }
-        console.log(changeTp, new_tp);
-        if (changeTp !== new_tp) {
-            postData(window.location.pathname + '/save', { type:'update_tp', updateData: new_tp }, function (result) {
-            });
-        }
+        calcChangePrice();
+        // let new_tp = 0;
+        // for (const c of changeList) {
+        //     new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
+        // }
+        // console.log(changeTp, new_tp);
+        // if (changeTp !== new_tp) {
+        //     postData(window.location.pathname + '/save', { type:'update_tp', updateData: new_tp }, function (result) {
+        //     });
+        // }
     }
 
     //tab change
@@ -496,6 +497,46 @@ $(document).ready(() => {
         xmjSpread.refresh();
     }
 });
+
+function calcChangePrice() {
+    let positive_tp = 0;
+    let negative_tp = 0;
+    let new_tp = 0;
+    for (const c of changeList) {
+        if (c.spamount) {
+            const price = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
+            new_tp = ZhCalc.add(new_tp, price);
+            if (price >= 0) {
+                positive_tp = ZhCalc.add(positive_tp, price);
+            } else {
+                negative_tp = ZhCalc.add(negative_tp, price);
+            }
+        }
+    }
+    const updateTpList = {};
+    let updateFlag = false;
+    if (changeTp !== new_tp) {
+        updateTpList.total_price = new_tp;
+        updateFlag = true;
+    }
+    if (positive_tp !== changePp) {
+        updateTpList.positive_tp = positive_tp;
+        updateFlag = true;
+    }
+    if (negative_tp !== changeNp) {
+        updateTpList.negative_tp = negative_tp;
+        updateFlag = true;
+    }
+    if (updateFlag) {
+        console.log(updateTpList);
+        postData(window.location.pathname + '/save', { type:'update_tp', updateData: updateTpList }, function () {
+            changePp = positive_tp;
+            changeNp = negative_tp;
+            changeTp = new_tp;
+        });
+    }
+}
+
 function findDecimal(unit) {
     let value = precision.other.value;
     const changeUnits = precision;

+ 2 - 2
app/service/change.js

@@ -500,10 +500,10 @@ module.exports = app => {
          * @return {void}
          */
         async getChangeTp(tenderId) {
-            const sql = 'SELECT SUM(`total_price`) AS tp FROM ?? WHERE tid = ? AND status = ?';
+            const sql = 'SELECT SUM(`total_price`) AS tp, SUM(`positive_tp`) AS p_tp, SUM(`negative_tp`) AS n_tp FROM ?? WHERE tid = ? AND status = ?';
             const sqlParam = [this.tableName, tenderId, audit.flow.status.checked];
             const result = await this.db.queryOne(sql, sqlParam);
-            return result ? result.tp : 0;
+            return result ? [result.tp, result.p_tp, result.n_tp] : [0, 0, 0];
         }
 
         /**

+ 11 - 1
app/service/change_audit_list.js

@@ -396,12 +396,22 @@ module.exports = app => {
             const sqlParam = [this.tableName, this.ctx.change.cid];
             const changeList = await transaction.query(sql, sqlParam);
             let total_price = 0;
+            let positive_tp = 0;
+            let negative_tp = 0;
             const tp_decimal = this.ctx.change.tp_decimal ? this.ctx.change.tp_decimal : this.ctx.tender.info.decimal.tp;
             for (const cl of changeList) {
-                total_price = this.ctx.helper.accAdd(total_price, this.ctx.helper.mul(cl.unit_price, cl.spamount, tp_decimal));
+                const price = this.ctx.helper.mul(cl.unit_price, cl.spamount, tp_decimal);
+                total_price = this.ctx.helper.accAdd(total_price, price);
+                if (price >= 0) {
+                    positive_tp = this.ctx.helper.accAdd(positive_tp, price);
+                } else {
+                    negative_tp = this.ctx.helper.accAdd(negative_tp, price);
+                }
             }
             const updateData = {
                 total_price,
+                positive_tp,
+                negative_tp,
             };
             if (updateTpDecimal) {
                 updateData.tp_decimal = tp_decimal;

+ 3 - 1
app/view/change/information.ejs

@@ -421,7 +421,9 @@
     const ledgerConsts = JSON.parse('<%- JSON.stringify(ledgerConsts) %>');
     const auditStatus = parseInt('<%- auditStatus %>');
     const changeName = JSON.parse(unescape('<%- escape(JSON.stringify(change.name)) %>'));
-    const changeTp = parseFloat('<%- change.total_price ? change.total_price : 0 %>');
+    let changeTp = parseFloat('<%- change.total_price ? change.total_price : 0 %>');
+    let changePp = parseFloat('<%- change.positive_tp ? change.positive_tp : 0 %>');
+    let changeNp = parseFloat('<%- change.negative_tp ? change.negative_tp : 0 %>');
     const changeStatus = parseFloat('<%- change.status %>');
     const touristPermission = parseInt('<%- ctx.tender.touristPermission.file %>');
     const auditList = JSON.parse(unescape('<%- escape(JSON.stringify(auditList)) %>'));

+ 7 - 2
app/view/datacollect/index.ejs

@@ -92,7 +92,7 @@
                                 </div>
                                 <div class="height-20 mb-2">
                                     <div class="card text-center bg-dark text-white ml-2 mr-2 py-2 height-100">
-                                        <div class="card-body card-per-body">
+                                        <div class="card-body card-per-body" data-toggle="tooltip" data-placement="bottom" data-html="true" data-original-title="">
                                             <h5 class="card-title card-case-title data_total_checked_change_price">0.00</h5>
                                             <p class="card-text text-muted">已批复变更金额</p>
                                         </div>
@@ -365,7 +365,7 @@
                                         </div>
                                         <div class="col-4 pl-0">
                                             <div class="card text-center bg-dark text-white height-100">
-                                                <div class="card-body card-per-body">
+                                                <div class="card-body card-per-body" data-toggle="tooltip" data-placement="bottom" data-html="true" data-original-title="">
                                                     <h5 class="card-title card-case-title data_total_checked_change_price">0.00</h5>
                                                     <p class="card-text text-muted">已批复变更金额</p>
                                                 </div>
@@ -1349,6 +1349,8 @@
             let total_price = 0;
             // let total_change_price = 0;
             let total_checked_change_price = 0;
+            // let total_checked_change_positive_price = 0;
+            // let total_checked_change_negative_price = 0;
             let total_after_change_price = 0;
             let total_stage_price = 0;
             let total_advance_price = 0;
@@ -1388,6 +1390,8 @@
                 total_price = ZhCalc.add(total_price, t.total_price);
                 // total_change_price = ZhCalc.add(total_change_price, t.end_qc_tp);
                 total_checked_change_price = ZhCalc.add(total_checked_change_price, t.change_tp);
+                // total_checked_change_positive_price = ZhCalc.add(total_checked_change_positive_price, t.change_p_tp);
+                // total_checked_change_negative_price = ZhCalc.add(total_checked_change_negative_price, t.change_n_tp);
                 total_after_change_price = ZhCalc.add(total_after_change_price, ZhCalc.add(t.total_price, t.change_tp));
                 total_stage_price = ZhCalc.add(total_stage_price, t.end_gather_tp);
                 // total_material_price = ZhCalc.add(total_material_price, t.material_tp);
@@ -1447,6 +1451,7 @@
             $('.data_total_price').text(formatMoney(total_price));
             // $('.data_total_change_price').text(formatMoney(total_change_price));
             $('.data_total_checked_change_price').text(formatMoney(total_checked_change_price));
+            // $('.data_total_checked_change_price').parents('div').attr('data-original-title', "<p style='text-align:left;'>批复正变更:" + formatMoney(total_checked_change_positive_price) + "</p>批复负变更:" + formatMoney(total_checked_change_negative_price));
             $('.data_total_after_change_price').text(formatMoney(total_after_change_price));
             $('.data_total_stage_price').text(formatMoney(total_stage_price));
             $('.data_total_advance_price').text(formatMoney(total_advance_price));

+ 2 - 2
app/view/tender/detail.ejs

@@ -85,7 +85,7 @@
                                     </div>
                                     <div class="col-auto pl-0">
                                         <div class="card text-center <% if (!ctx.tender.info.display.dayMode) { %>bg-dark text-white<% } %>">
-                                            <div class="card-body">
+                                            <div class="card-body" data-toggle="tooltip" data-placement="bottom" data-html="true" data-original-title="<p style='text-align:left;'>批复正变更:<%- ctx.helper.formatMoney(tender.change_p_tp) %></p>批复负变更:<%- ctx.helper.formatMoney(tender.change_n_tp) %>">
                                                 <h5 class="card-title card-big-title"><%- ctx.helper.formatMoney(tender.change_tp) %></h5>
                                                 <p class="card-text text-muted">已批复变更金额</p>
                                             </div>
@@ -101,7 +101,7 @@
                                     </div>
                                     <div class="col-auto pl-0">
                                         <div class="card text-center <% if (!ctx.tender.info.display.dayMode) { %>bg-dark text-white<% } %>">
-                                            <div class="card-body">
+                                            <div class="card-body" data-toggle="tooltip" data-placement="bottom" data-html="true" data-original-title="<p style='text-align:left;'>截止本期正变更:<%- ctx.helper.formatMoney(tender.end_positive_qc_tp) %></p>截止本期负变更:<%- ctx.helper.formatMoney(tender.end_negative_qc_tp) %>">
                                                 <h5 class="card-title card-big-title"><%- ctx.helper.formatMoney(tender.end_qc_tp) %> <small class="text-danger"  data-toggle="tooltip" data-placement="bottom" title="" data-original-title="占合同比例"><%- tender.qc_ratio %>%</small></h5>
                                                 <p class="card-text text-muted">截止本期变更</p>
                                             </div>