MaiXinRong 2 недель назад
Родитель
Сommit
0a4a877c2a
4 измененных файлов с 39 добавлено и 21 удалено
  1. 6 1
      app/lib/budget_final.js
  2. 11 10
      app/lib/ledger.js
  3. 15 10
      app/service/change.js
  4. 7 0
      sql/update.sql

+ 6 - 1
app/lib/budget_final.js

@@ -95,7 +95,7 @@ class BudgetFinal {
     constructor (ctx) {
         this.ctx = ctx;
         this.budgetSetting = { id: 'tree_id', pid: 'tree_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price'] };
-        this.tenderSetting = { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price', 'end_gather_tp', 'end_contract_tp', 'end_qc_tp', 'tz_qc_tp'] };
+        this.tenderSetting = { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: ['total_price', 'end_gather_tp', 'end_contract_tp', 'end_qc_tp', 'tz_qc_tp', 'un_tz_qc_tp'] };
         this.finalTree = new FinalTree(this.ctx, { id: 'id', pid: 'pid', order: 'order', level: 'level', fullPath: 'full_path', rootId: -1 });
     }
 
@@ -295,6 +295,8 @@ class BudgetFinal {
         const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(id);
         const reCalcChange = await this.ctx.service.change.getReCalcChangeData(id, tenderInfo);
         TreeUtils.loadChangeData(tree, null, reCalcChange, tenderInfo, helper);
+        const reCalcUnChange = await this.ctx.service.change.getReCalcChangeData(id, tenderInfo, false);
+        TreeUtils.loadChangeData(tree, null, reCalcUnChange, tenderInfo, helper, 'un_');
 
         tree.calculateAll();
         this.finalTree.loadTree(tree, function (cur, source) {
@@ -313,6 +315,8 @@ class BudgetFinal {
 
             cur.tz_qc_qty = helper.add(cur.tz_qc_qty, source.tz_qc_qty);
             cur.tz_qc_tp = helper.add(cur.tz_qc_tp, source.tz_qc_tp);
+            cur.un_tz_qc_qty = helper.add(cur.un_tz_qc_qty, source.un_tz_qc_qty);
+            cur.un_tz_qc_tp = helper.add(cur.un_tz_qc_tp, source.un_tz_qc_tp);
         });
     }
 
@@ -444,6 +448,7 @@ class BudgetFinal {
                 final_contract_tp: x.final_contract_tp || 0, final_qc_tp: x.final_qc_tp || 0,
                 final_dgn_price: x.final_dgn_price || 0, final_dgn_qty: x.final_dgn_qty || '',
                 tz_qc_qty: x.tz_qc_qty || 0, tz_qc_tp: x.tz_qc_tp || 0,
+                un_tz_qc_qty: x.un_tz_qc_qty || 0, un_tz_qc_tp: x.un_tz_qc_tp || 0,
                 grow_dgn_qty1: x.grow_dgn_qty1 || 0, grow_dgn_qty2: x.grow_dgn_qty2 || 0, grow_dgn_qty: x.grow_dgn_qty || '', grow_tp: x.grow_tp || 0,
             })
         });

+ 11 - 10
app/lib/ledger.js

@@ -1447,7 +1447,7 @@ class reviseTree extends billsTree {
 }
 
 const treeUtils = {
-    loadChangeData: function(tree, pos, changes, tenderInfo, helper) {
+    loadChangeData: function(tree, pos, changes, tenderInfo, helper, prefix = '') {
         const findEmptyBills = function(tree, change, changeBills) {
             const cb = {
                 b_code: changeBills.code || '',
@@ -1475,26 +1475,27 @@ const treeUtils = {
                     : findEmptyBills(tree, change, changeBills);
 
                 if (!node) continue;
-                if (!node.changeBills) node.changeBills = [];
-                node.tz_qc_qty = helper.add(node.tz_qc_qty, changeBills.checked_amount);
+                if (!node[prefix + 'changeBills']) node[prefix + 'changeBills'] = [];
+                node[prefix + 'tz_qc_qty'] = helper.add(node[prefix + 'tz_qc_qty'], changeBills.checked_amount);
                 if (tenderInfo.calc_type === 'up') {
-                    node.tz_qc_tp = helper.add(node.tz_qc_tp, changeBills.checked_price);
+                    node[prefix + 'tz_qc_tp'] = helper.add(node[prefix + 'tz_qc_tp'], changeBills.checked_price);
                 } else {
-                    node.tz_qc_tp = helper.add(node.tz_qc_tp, changeBills.tp);
+                    node[prefix + 'tz_qc_tp'] = helper.add(node[prefix + 'tz_qc_tp'], changeBills.tp);
                 }
+                console.log(prefix, changeBills, node);
 
                 const posData = pos ? pos.getLedgerPos(node.id) : undefined;
                 if (posData && posData.length > 0) {
                     for (const p of changeBills.pos) {
                         const changePos = p.bwmx ? posData.find(x => { return x.name === p.bwmx; }) : posData[0];
                         if (changePos) {
-                            changePos.tz_qc_qty = helper.add(changePos.tz_qc_qty, p.checked_amount);
-                            if (!changePos.changeBills) changePos.changeBills = [];
-                            changePos.changeBills.push({
+                            changePos[prefix + 'tz_qc_qty'] = helper.add(changePos[prefix + 'tz_qc_qty'], p.checked_amount);
+                            if (!changePos[prefix + 'changeBills']) changePos[prefix + 'changeBills'] = [];
+                            changePos[prefix + 'changeBills'].push({
                                 code: change.code || '', name: change.name || '', is_valuation:  p.is_valuation,
                                 qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: changePos.name,
                             });
-                            node.changeBills.push({
+                            node[prefix + 'changeBills'].push({
                                 code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
                                 qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: changePos.name,
                             });
@@ -1502,7 +1503,7 @@ const treeUtils = {
                     }
                 } else {
                     for (const p of changeBills.pos) {
-                        node.changeBills.push({
+                        node[prefix + 'changeBills'].push({
                             code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
                             qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: '',
                         });

+ 15 - 10
app/service/change.js

@@ -2230,18 +2230,24 @@ module.exports = app => {
             return returnList;
         }
 
-        async getReCalcChangeData(tenderId, tenderInfo) {
-            const change = await this.ctx.service.change.getAllDataByCondition({
-                columns: [ 'cid', 'code', 'name', 'w_code', 'tp_decimal', 'up_decimal' ],
-                where: { tid: tenderId, valid: 1, status: audit.flow.status.checked },
+        async getReCalcChangeData(tenderId, tenderInfo, checked = true) {
+            let change = await this.ctx.service.change.getAllDataByCondition({
+                columns: [ 'cid', 'code', 'name', 'w_code', 'tp_decimal', 'up_decimal', 'status' ],
+                where: { tid: tenderId, valid: 1 },
                 orders: [['code', 'asc']],
             });
+            if (checked) {
+                change = change.filter(x => { return x.status === audit.flow.status.checked; });
+            } else {
+                change = change.filter(x => { return x.status !== audit.flow.status.checked; });
+            }
             const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
-                columns: [ 'id', 'cid', 'code', 'name', 'unit', 'unit_price', 'oamount2', 'checked_amount', 'checked_price', 'is_valuation', 'gcl_id', 'bwmx', 'mx_id'],
+                columns: [ 'id', 'cid', 'code', 'name', 'unit', 'unit_price', 'oamount2', 'checked_amount', 'checked_price', 'is_valuation', 'gcl_id', 'bwmx', 'mx_id', 'camount'],
                 where: { tid: tenderId }
             });
             const changeIndex = {};
             change.forEach(x => { changeIndex[x.cid] = x; x.bills = [] });
+            const field = checked ? 'checked_amount' : 'camount';
             changeBills.forEach(cb => {
                 const c = changeIndex[cb.cid];
                 if (!c) return;
@@ -2251,19 +2257,18 @@ module.exports = app => {
                         b = { code: cb.code, name: cb.name, unit: cb.unit, unit_price: cb.unit_price, pos: [], gcl_id: cb.gcl_id };
                         c.bills.push(b);
                     }
-                    b.checked_amount = this.ctx.helper.add(b.checked_amount, cb.checked_amount);
+                    b.checked_amount = this.ctx.helper.add(b.checked_amount, cb[field]);
                     if (cb.is_valuation) {
-                        b.qty = this.ctx.helper.add(b.qty, cb.checked_amount);
+                        b.qty = this.ctx.helper.add(b.qty, cb[field]);
                     } else {
-                        b.minus_qty = this.ctx.helper.add(b.minus_qty, cb.checked_amount);
+                        b.minus_qty = this.ctx.helper.add(b.minus_qty, cb[field]);
                     }
                     b.pos.push(cb);
                 } else {
                     c.bills.push({
                         code: cb.code, name: cb.name, unit: cb.unit, unit_price: cb.unit_price,
                         gcl_id: '', checked_amount: cb.checked_amount, checked_price: cb.checked_price,
-                        qty: cb.is_valuation ? cb.checked_amount : 0, tp: cb.is_valuation ? cb.checked_price : 0,
-                        minus_qty: !cb.is_valuation ? cb.checked_amount : 0, minus_tp: !cb.is_valuation ? cb.checked_price : 0,
+                        qty: cb.is_valuation ? cb[field] : 0, minus_qty: !cb.is_valuation ? cb[field] : 0,
                         pos: [cb],
                     });
                 }

+ 7 - 0
sql/update.sql

@@ -122,6 +122,13 @@ ALTER TABLE `zh_ledger_attachment`
 ALTER TABLE `zh_advance_audit`
 ADD COLUMN `audit_type` tinyint(4) UNSIGNED NOT NULL DEFAULT 1 COMMENT '审批类型(1个人,2会签,3或签)' AFTER `audit_id`,
 ADD COLUMN `audit_order` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '审批顺序' AFTER `audit_type`;
+
+ALTER TABLE `calculation`.`zh_budget_final`
+MODIFY COLUMN `tz_qc_qty` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '决算-变更令数量' AFTER `grow_dgn_qty`,
+MODIFY COLUMN `tz_qc_tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '决算-变更令金额' AFTER `tz_qc_qty`,
+ADD COLUMN `un_tz_qc_qty` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '未批复变更令数量' AFTER `tz_qc_tp`,
+ADD COLUMN `un_tz_qc_tp` decimal(24, 8) NOT NULL DEFAULT 0 COMMENT '未批复变更令金额' AFTER `un_tz_qc_qty`;
+
 ------------------------------------
 -- 表数据
 ------------------------------------