浏览代码

台账分解、台账修订,上报前数据检查调整

MaiXinRong 4 年之前
父节点
当前提交
ee20d4d41b

+ 33 - 24
app/base/base_bills_service.js

@@ -71,9 +71,10 @@ class BaseBillsSerivce extends TreeService {
     async addBillsNode(tenderId, selectId, data, reviseId) {
         if (data) {
             if (reviseId) data.crid = reviseId;
+            data.check_calc = 1;
             return await this.addNode(tenderId, selectId, data);
         } else {
-            return await this.addNode(tenderId, selectId, {crid: reviseId});
+            return await this.addNode(tenderId, selectId, {crid: reviseId, check_calc: 1});
         }
     }
 
@@ -104,6 +105,7 @@ class BaseBillsSerivce extends TreeService {
         data.order = children.length + 1;
         data.full_path = selectData.full_path + '-' + data.ledger_id;
         data.is_leaf = true;
+        data.check_calc = 1;
         if (reviseId) data.crid = reviseId;
 
         this.transaction = await this.db.beginTransaction();
@@ -192,6 +194,7 @@ class BaseBillsSerivce extends TreeService {
         if (data.is_leaf === undefined) {
             data.is_leaf = true;
         }
+        data.check_calc = 1;
         if (reviseId) data.crid = reviseId;
         const result = await this.transaction.insert(this.tableName, data);
 
@@ -365,6 +368,7 @@ class BaseBillsSerivce extends TreeService {
      * @return {Promise<*>}
      */
     async updateCalc(tenderId, data) {
+        const helper = this.ctx.helper;
         // 简单验证数据
         if (tenderId <= 0 || !this.ctx.tender) {
             throw '标段不存在';
@@ -390,27 +394,31 @@ class BaseBillsSerivce extends TreeService {
                     throw '提交数据错误';
                 }
                 let updateData;
-                if (row.unit) {
+
+                // 更新单位或单价,全部数据都应重算
+                if (row.unit !== undefined || row.unit_price !== undefined) {
                     if (row.sgfh_qty === undefined) { row.sgfh_qty = updateNode.sgfh_qty; }
                     if (row.sjcl_qty === undefined) { row.sjcl_qty = updateNode.sjcl_qty; }
                     if (row.qtcl_qty === undefined) { row.qtcl_qty = updateNode.qtcl_qty; }
                     if (row.deal_qty === undefined) { row.deal_qty = updateNode.deal_qty; }
                 }
+
+                // 项目节、工程量清单相关
                 if (row.b_code) {
                     row.dgn_qty1 = null;
                     row.dgn_qty2 = null;
                     row.code = null;
                 }
-                if (row.code) {
-                    row.b_code = null;
-                }
+                if (row.code) row.b_code = null;
+
                 if (this._checkCalcField(row)) {
                     let calcData = JSON.parse(JSON.stringify(row));
-                    const precision = this.ctx.helper.findPrecision(info.precision, row.unit ? row.unit : updateNode.unit);
+                    calcData.check_calc = 1;
+                    const precision = helper.findPrecision(info.precision, row.unit ? row.unit : updateNode.unit);
                     // 数量保留小数位数
-                    this.ctx.helper.checkFieldPrecision(calcData, qtyFields, precision.value);
+                    helper.checkFieldPrecision(calcData, qtyFields, precision.value);
                     // 单位保留小数位数
-                    this.ctx.helper.checkFieldPrecision(calcData, upFields, info.decimal.up);
+                    helper.checkFieldPrecision(calcData, upFields, info.decimal.up);
                     // 未提交单价则读取数据库单价
                     if (row.unit_price === undefined) calcData.unit_price = updateNode.unit_price;
                     // 计算
@@ -420,29 +428,29 @@ class BaseBillsSerivce extends TreeService {
                         if (row.sjcl_qty === undefined) calcData.sjcl_qty = updateNode.sjcl_qty;
                         if (row.qtcl_qty === undefined) calcData.qtcl_qty = updateNode.qtcl_qty;
                         if (row.deal_qty === undefined) calcData.deal_qty = updateNode.deal_qty;
-                        calcData.quantity = this.ctx.helper.sum([calcData.sgfh_qty, calcData.sjcl_qty, calcData.qtcl_qty]);
-                        calcData.sgfh_tp = this.ctx.helper.mul(calcData.sgfh_qty, calcData.unit_price, info.decimal.tp);
-                        calcData.sjcl_tp = this.ctx.helper.mul(calcData.sjcl_qty, calcData.unit_price, info.decimal.tp);
-                        calcData.qtcl_tp = this.ctx.helper.mul(calcData.qtcl_qty, calcData.unit_price, info.decimal.tp);
-                        calcData.total_price = this.ctx.helper.mul(calcData.quantity, calcData.unit_price, info.decimal.tp);
-                        calcData.deal_tp = this.ctx.helper.mul(calcData.deal_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.quantity = helper.sum([calcData.sgfh_qty, calcData.sjcl_qty, calcData.qtcl_qty]);
+                        calcData.sgfh_tp = helper.mul(calcData.sgfh_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.sjcl_tp = helper.mul(calcData.sjcl_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.qtcl_tp = helper.mul(calcData.qtcl_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.total_price = helper.mul(calcData.quantity, calcData.unit_price, info.decimal.tp);
+                        calcData.deal_tp = helper.mul(calcData.deal_qty, calcData.unit_price, info.decimal.tp);
                     } else if (row.sgfh_tp !== undefined || row.sjcl_tp !== undefined || row.qtcl_tp !== undefined || row.deal_tp !== undefined) {
                         calcData.sgfh_qty = null;
                         calcData.sjcl_qty = null;
                         calcData.qtcl_qty = null;
                         calcData.quantity = null;
                         calcData.deal_qty = null;
-                        calcData.sgfh_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.sgfh_tp, info.decimal.tp) : updateNode.sgfh_tp;
-                        calcData.sjcl_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.sjcl_tp, info.decimal.tp) : updateNode.sjcl_tp;
-                        calcData.qtcl_tp = (row.sgfh_tp !== undefined) ? this.ctx.helper.round(calcData.row.qtcl_tp, info.decimal.tp) : updateNode.qtcl_tp;
-                        calcData.total_price = this.ctx.helper.sum([calcData.sgfh_tp, calcData.sjcl_tp, calcData.qtcl_tp]);
-                        calcData.deal_tp = (row.deal_tp !== undefined) ? this.ctx.helper.round(calcData.row.deal_tp, info.decimal.tp) : updateNode.deal_tp;
+                        calcData.sgfh_tp = helper.round(row.sgfh_tp !== undefined ? calcData.row.sgfh_tp : updateNode.sgfh_tp, info.decimal.tp);
+                        calcData.sjcl_tp = helper.round(row.sgfh_tp !== undefined ? calcData.row.sjcl_tp : updateNode.sjcl_tp, info.decimal.tp);
+                        calcData.qtcl_tp = helper.round(row.sgfh_tp !== undefined ? calcData.row.qtcl_tp : updateNode.qtcl_tp, info.decimal.tp);
+                        calcData.total_price = helper.sum([calcData.sgfh_tp, calcData.sjcl_tp, calcData.qtcl_tp]);
+                        calcData.deal_tp = helper.round(row.deal_tp !== undefined ? calcData.row.deal_tp : updateNode.deal_tp, info.decimal.tp);
                     } else if (row.unit_price !== undefined) {
-                        calcData.sgfh_tp = this.ctx.helper.mul(calcData.sgfh_qty, calcData.unit_price, info.decimal.tp);
-                        calcData.sjcl_tp = this.ctx.helper.mul(calcData.sjcl_qty, calcData.unit_price, info.decimal.tp);
-                        calcData.qtcl_tp = this.ctx.helper.mul(calcData.qtcl_qty, calcData.unit_price, info.decimal.tp);
-                        calcData.total_price = this.ctx.helper.mul(calcData.quantity, calcData.unit_price, info.decimal.tp);
-                        calcData.deal_tp = this.ctx.helper.mul(calcData.deal_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.sgfh_tp = helper.mul(calcData.sgfh_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.sjcl_tp = helper.mul(calcData.sjcl_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.qtcl_tp = helper.mul(calcData.qtcl_qty, calcData.unit_price, info.decimal.tp);
+                        calcData.total_price = helper.mul(calcData.quantity, calcData.unit_price, info.decimal.tp);
+                        calcData.deal_tp = helper.mul(calcData.deal_qty, calcData.unit_price, info.decimal.tp);
                     }
                     updateData = this._filterUpdateInvalidField(updateNode.id, calcData);
                 } else {
@@ -592,6 +600,7 @@ class BaseBillsSerivce extends TreeService {
                     sgfh_expr: d.sgfh_expr,
                     sjcl_expr: d.sjcl_expr,
                     qtcl_expr: d.qtcl_expr,
+                    check_calc: 1,
                 };
                 for (const c of d.children) {
                     c.ledger_pid = newBills.ledger_id;

+ 2 - 0
app/extend/helper.js

@@ -1186,6 +1186,8 @@ module.exports = {
             },
         };
         for (const b of bills) {
+            if (!b.check_calc) continue;
+
             const checkData = {}, calcData = {};
             for (const f of field) {
                 checkData[f.tp] = b[f.tp] || 0;

+ 2 - 2
app/service/ledger_revise.js

@@ -99,11 +99,11 @@ module.exports = app => {
                 '  (id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
                 '     quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '     sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
-                '     sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url)' +
+                '     sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url, check_calc)' +
                 '  Select id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
                 '      quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '      sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
-                '      sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url' +
+                '      sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url, 0' +
                 '  From ' + this.ctx.service.ledger.tableName +
                 '  Where `tender_id` = ?';
             const sqlParam = [tid];

+ 2 - 2
app/service/revise_audit.js

@@ -300,11 +300,11 @@ module.exports = app => {
                 '  (id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
                 '     quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '     sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
-                '     sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url)' +
+                '     sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url, check_calc)' +
                 '  Select id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
                 '      quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '      sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp, ' +
-                '      sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url' +
+                '      sgfh_expr, sjcl_expr, qtcl_expr, gxby_status, dagl_status, dagl_url, check_calc' +
                 '  From ' +
                 this.ctx.service.reviseBills.tableName +
                 '  Where `tender_id` = ?';

+ 3 - 1
app/service/revise_bills.js

@@ -46,7 +46,7 @@ module.exports = app => {
          */
         async addReviseNode(tid, rid, lid, count) {
             if (!rid) return null;
-            return await this.addNodeBatch(tid, lid, {crid: rid}, count);
+            return await this.addNodeBatch(tid, lid, {crid: rid, revise_calc: 1}, count);
         }
 
         /**
@@ -86,6 +86,7 @@ module.exports = app => {
                     name: data[i].name,
                     unit: data[i].unit,
                     unit_price: data[i].price,
+                    check_calc: 1,
                 };
 
                 const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
@@ -187,6 +188,7 @@ module.exports = app => {
                     name: data[i].name,
                     unit: data[i].unit,
                     unit_price: data[i].price,
+                    check_calc: 1,
                 };
 
                 const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);

+ 2 - 0
db_script/depart-database-table.js

@@ -72,6 +72,7 @@ const ledgerSql = 'CREATE TABLE `zh_ledger_?` (\n' +
     '  `gxby_status` tinyint(4) DEFAULT \'-1\' COMMENT \'工序报验-状态\',\n' +
     '  `dagl_status` tinyint(4) DEFAULT \'-1\' COMMENT \'档案管理-状态\',\n' +
     '  `dagl_url` varchar(255) DEFAULT \'\' COMMENT \'档案管理-查看链接\',\n' +
+    '  `check_calc` tinyint(1) DEFAULT \'0\' COMMENT \'是否检查计算\',\n' +
     '  PRIMARY KEY (`id`),\n' +
     '  KEY `idx_tender_id` (`tender_id`),\n' +
     '  KEY `idx_template_pid` (`ledger_pid`),\n' +
@@ -146,6 +147,7 @@ const reviseBillsSql = 'CREATE TABLE `zh_revise_bills_?` (\n' +
     '  `gxby_status` tinyint(4) DEFAULT \'-1\' COMMENT \'工序报验状态\',\n' +
     '  `dagl_status` tinyint(4) DEFAULT \'-1\' COMMENT \'档案管理状态\',\n' +
     '  `dagl_url` varchar(255) DEFAULT \'\' COMMENT \'档案管理-查看链接\',\n' +
+    '  `check_calc` tinyint(1) DEFAULT \'0\' COMMENT \'是否检查计算\',\n' +
     '  PRIMARY KEY (`id`),\n' +
     '  KEY `idx_tender_id` (`tender_id`),\n' +
     '  KEY `idx_template_pid` (`ledger_pid`),\n' +

+ 6 - 0
sql/update.sql

@@ -17,3 +17,9 @@ ADD COLUMN `dagl_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NU
 
 ALTER TABLE `zh_advance_file`
 ADD COLUMN `extra_upload` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否为审核通过后再次上传的文件,0为否' AFTER `fileext`;
+
+ALTER TABLE `zh_ledger`
+ADD COLUMN `check_calc`  tinyint(1) NULL DEFAULT 1 COMMENT '是否检查计算' AFTER `dagl_url`;
+
+ALTER TABLE `zh_revise_bills`
+ADD COLUMN `check_calc`  tinyint(1) NULL DEFAULT 1 COMMENT '是否检查计算' AFTER `dagl_url`;