Explorar o código

计价和不计价清单金额汇总及展示

ellisran hai 1 ano
pai
achega
7d38ec2661
Modificáronse 3 ficheiros con 77 adicións e 1 borrados
  1. 12 1
      app/service/change.js
  2. 57 0
      db_script/change_valuation.js
  3. 8 0
      sql/update.sql

+ 12 - 1
app/service/change.js

@@ -948,6 +948,8 @@ module.exports = app => {
                     // 清单数据更新
                     const bills_list = await this.ctx.service.changeAuditList.getList(changeData.cid, changeData.order_by);
                     let total_price = 0;
+                    let valuation_tp = 0;
+                    let unvaluation_tp = 0;
                     const tp_decimal = changeData.tp_decimal ? changeData.tp_decimal : this.ctx.tender.info.decimal.tp;
                     const updateList = [];
                     for (const bl of bills_list) {
@@ -962,6 +964,9 @@ module.exports = app => {
                             list_update.samount = bl.spamount;
                             list_update.checked_amount = bl.spamount;
                             list_update.checked_price = this.ctx.helper.mul(bl.unit_price, list_update.checked_amount, tp_decimal);
+                            // 统计计价和不计价金额
+                            valuation_tp = bl.is_valuation ? this.ctx.helper.add(valuation_tp, list_update.checked_price) : valuation_tp;
+                            unvaluation_tp = !bl.is_valuation ? this.ctx.helper.add(unvaluation_tp, list_update.checked_price) : unvaluation_tp;
                         }
                         updateList.push(list_update);
                     }
@@ -1040,9 +1045,11 @@ module.exports = app => {
                         }
                     }
                     change_update.total_price = total_price;
+                    change_update.valuation_tp = valuation_tp;
+                    change_update.unvaluation_tp = unvaluation_tp;
                     const options = {
                         where: {
-                            cid: postData.change_id,
+                            cid: changeData.cid,
                         },
                     };
                     await this.transaction.update(this.tableName, change_update, options);
@@ -1631,6 +1638,8 @@ module.exports = app => {
                     up_decimal: null,
                     is_revise: 1,
                     final_auditor_str: '',
+                    valuation_tp: 0,
+                    unvaluation_tp: 0,
                 };
                 const options = {
                     where: {
@@ -1799,6 +1808,8 @@ module.exports = app => {
                     sin_time: null,
                     total_price,
                     final_auditor_str: '',
+                    valuation_tp: 0,
+                    unvaluation_tp: 0,
                 };
                 const options = {
                     where: {

+ 57 - 0
db_script/change_valuation.js

@@ -0,0 +1,57 @@
+// 计算变更令,计价不计价金额数
+
+const defaultInfo = require('../app/const/tender_info');
+const BaseUtil = require('./baseUtils');
+const status = require('../app/const/audit').change.status;
+const querySql = BaseUtil.querySql;
+const ZhCalc = BaseUtil.ZhCalc;
+
+const checkChange = async function(change) {
+    const changeBills = await querySql('Select * From zh_change_audit_list where cid = ?', [change.cid]);
+    let valuation_tp = 0;
+    let unvaluation_tp = 0;
+    for (const cb of changeBills) {
+        valuation_tp = cb.is_valuation ? ZhCalc.add(valuation_tp, cb.checked_price) : valuation_tp;
+        unvaluation_tp = !cb.is_valuation ? ZhCalc.add(unvaluation_tp, cb.checked_price) : unvaluation_tp;
+    }
+    await querySql('Update zh_change Set valuation_tp = ?, unvaluation_tp = ? Where cid = ?', [valuation_tp, unvaluation_tp, change.cid]);
+    console.log(`Update Change ${change.cid}`);
+};
+
+const doComplete = async function() {
+    try {
+        const tender = await querySql('Select * From zh_tender');
+        for (const t of tender) {
+            console.log(`Update Tender ${t.id}:`);
+            const changes = await querySql('Select * From zh_change where tid = ? AND status = ?', [t.id, status.checked]);
+            for (const c of changes) {
+                await checkChange(c);
+            }
+        }
+    } catch (err) {
+        console.log(err);
+    }
+    BaseUtil.closePool();
+};
+const doCompleteTest = async function(tid) {
+    try {
+        const tender = await querySql('Select * From zh_tender where id = ?', [tid]);
+        for (const t of tender) {
+            console.log(`Update Tender ${t.id}:`);
+            const changes = await querySql('Select * From zh_change where tid = ? AND status = ?', [t.id, status.checked]);
+            for (const c of changes) {
+                await checkChange(c);
+            }
+        }
+    } catch (err) {
+        console.log(err);
+    }
+    BaseUtil.closePool();
+};
+
+const tenderId = process.argv[3];
+if (tenderId) {
+    doCompleteTest(tenderId);
+} else {
+    doComplete();
+}

+ 8 - 0
sql/update.sql

@@ -2,3 +2,11 @@ ALTER TABLE `zh_project`
 ADD COLUMN `common_json` json NULL COMMENT '通用json,没有sql查询值必要的可放这' AFTER `notice_setting`;
 ALTER TABLE `zh_ledger_tag`
 ADD COLUMN `pos_id` varchar(36) NOT NULL DEFAULT '' COMMENT '关联计量单元id(zh_pos表中的id)' AFTER `id`;
+
+ALTER TABLE `zh_change`
+ADD COLUMN `valuation_tp` decimal(30, 8) NULL DEFAULT 0 COMMENT '计价金额(审批完成后统计)' AFTER `negative_tp`,
+ADD COLUMN `unvaluation_tp` decimal(30, 8) NULL DEFAULT 0 COMMENT '不计价金额(审批完成后统计)' AFTER `valuation_tp`;
+
+ALTER TABLE `zh_change`
+MODIFY COLUMN `positive_tp` decimal(30, 8) NOT NULL DEFAULT 0.00000000 COMMENT '正变更金额' AFTER `order_by`,
+MODIFY COLUMN `negative_tp` decimal(30, 8) NOT NULL DEFAULT 0.00000000 COMMENT '负变更金额' AFTER `positive_tp`,