Преглед изворни кода

动态投资,决算对比,汇总变更令金额

MaiXinRong пре 1 месец
родитељ
комит
b920884bc7
4 измењених фајлова са 135 додато и 1 уклоњено
  1. 11 1
      app/lib/budget_final.js
  2. 68 0
      app/lib/ledger.js
  3. 52 0
      app/service/change.js
  4. 4 0
      sql/update.sql

+ 11 - 1
app/lib/budget_final.js

@@ -10,6 +10,7 @@
 
 const itemsPre = 'id_';
 const BillsTree = require('./ledger').billsTree;
+const TreeUtils = require('./ledger').treeUtils;
 const auditConst = require('../const/audit');
 
 class FinalTree extends BillsTree {
@@ -94,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'] };
+        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.finalTree = new FinalTree(this.ctx, { id: 'id', pid: 'pid', order: 'order', level: 'level', fullPath: 'full_path', rootId: -1 });
     }
 
@@ -199,6 +200,11 @@ class BudgetFinal {
         }
         const tree = new BillsTree(this.ctx, this.tenderSetting);
         tree.loadDatas(bills);
+
+        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);
+
         tree.calculateAll();
         this.finalTree.loadTree(tree, function (cur, source) {
             cur.total_price = helper.add(cur.total_price, source.total_price);
@@ -213,6 +219,9 @@ class BudgetFinal {
             cur.final_contract_tp = helper.add(cur.final_contract_tp, source.end_contract_tp);
             cur.final_qc_tp = helper.add(cur.final_qc_tp, source.end_qc_tp);
             cur.final_tp = helper.add(cur.final_tp, source.end_gather_tp);
+
+            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);
         });
     }
 
@@ -291,6 +300,7 @@ class BudgetFinal {
                 final_dgn_qty1: x.final_dgn_qty1 || 0, final_dgn_qty2: x.final_dgn_qty2 || 0, final_tp: x.final_tp || 0,
                 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,
                 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,
             })
         });

+ 68 - 0
app/lib/ledger.js

@@ -1427,6 +1427,73 @@ class reviseTree extends billsTree {
     }
 }
 
+const treeUtils = {
+    loadChangeData: function(tree, pos, changes, tenderInfo, helper) {
+        const findEmptyBills = function(tree, change, changeBills) {
+            const cb = {
+                b_code: changeBills.code || '',
+                name: changeBills.name || '',
+                unit: changeBills.unit || '',
+                unit_price: changeBills.unit_price || 0,
+            };
+            for (const node of tree.nodes) {
+                if (node.children && node.children.length > 0) continue;
+
+                const b = {
+                    b_code: node.b_code || '',
+                    name: node.name || '',
+                    unit: node.unit || '',
+                    unit_price: node.unit_price || 0,
+                };
+                if (_.isMatch(cb, b)) return node;
+            }
+            return null;
+        };
+        for (const change of changes) {
+            for (const changeBills of change.bills) {
+                const node = changeBills.gcl_id
+                    ? tree.nodes.find(x => {return x.id === changeBills.gcl_id})
+                    : 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 (tenderInfo.calc_type === 'up') {
+                    node.tz_qc_tp = helper.add(node.tz_qc_tp, changeBills.checked_price);
+                } else {
+                    node.tz_qc_tp = helper.add(node.tz_qc_tp, changeBills.tp);
+                }
+
+                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({
+                                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({
+                                code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
+                                qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: changePos.name,
+                            });
+                        }
+                    }
+                } else {
+                    for (const p of changeBills.pos) {
+                        node.changeBills.push({
+                            code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
+                            qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: '',
+                        });
+                    }
+                }
+            }
+        }
+    }
+};
+
 module.exports = {
     baseTree,
     billsTree,
@@ -1437,4 +1504,5 @@ module.exports = {
     gatherPos,
     checkData,
     reviseTree,
+    treeUtils,
 };

+ 52 - 0
app/service/change.js

@@ -2229,6 +2229,58 @@ 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 },
+                orders: [['code', 'asc']],
+            });
+            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'],
+                where: { tid: tenderId }
+            });
+            const changeIndex = {};
+            change.forEach(x => { changeIndex[x.cid] = x; x.bills = [] });
+            changeBills.forEach(cb => {
+                const c = changeIndex[cb.cid];
+                if (!c) return;
+                if (cb.gcl_id) {
+                    let b = c.bills.find(x => { return x.gcl_id === cb.gcl_id; });
+                    if (!b) {
+                        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);
+                    if (cb.is_valuation) {
+                        b.qty = this.ctx.helper.add(b.qty, cb.checked_amount);
+                    } else {
+                        b.minus_qty = this.ctx.helper.add(b.minus_qty, cb.checked_amount);
+                    }
+                    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,
+                        pos: [cb],
+                    });
+                }
+            });
+            const helper = this.ctx.helper;
+            change.forEach(x => {
+                const tpDecimal = x.tp_decimal || tenderInfo.decimal.tp;
+                x.bills.forEach(b => {
+                    if (!b.gcl_id) return;
+                    b.checked_price = helper.mul(b.unit_price, b.checked_amount, tpDecimal);
+                    b.tp = helper.mul(b.unit_price, b.qty, tpDecimal);
+                    b.minus_tp = helper.mul(b.unit_price, b.minus_qty, tpDecimal);
+                });
+                x.bills.sort((a, b) => { return helper.compareCode(a.code, b.code)});
+            });
+            return change;
+        }
     }
 
     return Change;

+ 4 - 0
sql/update.sql

@@ -134,6 +134,10 @@ CREATE TABLE `zh_spss_stash`  (
   PRIMARY KEY (`id`)
 );
 
+ALTER TABLE `zh_budget_final`
+ADD COLUMN `tz_qc_qty` decimal(24, 8) NOT NULL COMMENT '决算-变更令数量' AFTER `grow_dgn_qty`,
+ADD COLUMN `tz_qc_tp` decimal(24, 8) NOT NULL COMMENT '决算-变更令金额' AFTER `tz_qc_qty`;
+
 ------------------------------------
 -- 表数据
 ------------------------------------