瀏覽代碼

1. 0号台账,部位台账,调整
2. 期计量,部位台账,调整

MaiXinRong 5 年之前
父節點
當前提交
8ab7acf17c

+ 16 - 0
app/controller/ledger_controller.js

@@ -23,6 +23,7 @@ const LzString = require('lz-string');
 const accountGroup = require('../const/account_group').group;
 const path = require('path');
 const exportExcel = require('../lib/export_excel');
+const billsPosConvert = require('../lib/bills_pos_convert');
 const xlsx = require('js-xlsx');
 
 module.exports = app => {
@@ -617,6 +618,21 @@ module.exports = app => {
             }
         }
 
+        async loadBwtz(ctx) {
+            try {
+                const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
+                const posData = this.ctx.tender.data.measure_type === measureType.tz.value
+                    ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
+                const convert = new billsPosConvert(ctx);
+                convert.loadData(ledgerData, posData, []);
+                const result = convert.convert();
+                ctx.body = {err: 0, msg: '', data: result};
+            } catch(err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '加载合同支付数据错误');
+            }
+        }
+
         /**
          * 台账对比 页面 (Get)
          * @param ctx

+ 16 - 0
app/controller/stage_controller.js

@@ -20,6 +20,7 @@ const path = require('path');
 const PayCalculator = require('../lib/pay_calc');
 const accountGroup = require('../const/account_group').group;
 const sendToWormhole = require('stream-wormhole');
+const billsPosConvert = require('../lib/bills_pos_convert');
 const fs = require('fs');
 
 module.exports = app => {
@@ -1152,6 +1153,21 @@ module.exports = app => {
             }
         }
 
+        async loadBwtz(ctx) {
+            try {
+                const ledgerData = await this._getStageLedgerData(ctx);
+                const posData = await this._getStagePosData(ctx);
+                const changeData = await this._getStageChangeData(ctx);
+                const convert = new billsPosConvert(ctx);
+                convert.loadData(ledgerData, posData, changeData);
+                const result = convert.convert();
+                ctx.body = {err: 0, msg: '', data: result};
+            } catch(err) {
+                this.log(err);
+                ctx.body = this.ajaxErrorBody(err, '加载合同支付数据错误');
+            }
+        }
+
         /**
          * 报表
          * @param ctx

+ 174 - 47
app/lib/ledger.js

@@ -10,7 +10,7 @@
 
 const itemsPre = 'id_';
 
-class billsTree {
+class baseTree {
     /**
      * 构造函数
      */
@@ -60,7 +60,11 @@ class billsTree {
         });
         return children;
     };
-
+    /**
+     * 获取节点的 index
+     * @param node
+     * @returns {number}
+     */
     getNodeSerialNo(node) {
         return this.nodes.indexOf(node);
     }
@@ -95,7 +99,6 @@ class billsTree {
         }
         addSortNodes(this.children);
     }
-
     /**
      * 加载数据(初始化), 并给数据添加部分树结构必须数据
      * @param datas
@@ -165,37 +168,47 @@ class billsTree {
     };
 
     /**
-     * 检查节点是否是最底层项目节
-     * @param node
-     * @returns {boolean}
+     * 根据 字段名称 获取数据
+     * @param fields
+     * @returns {Array}
      */
-    isLeafXmj(node) {
-        if (node.b_code && node.b_code !== '') {
-            return false;
-        }
-        for (const child of node.children) {
-            if (!child.b_code || child.b_code === '') {
-                return false;
+    getDatas (fields) {
+        const datas = [];
+        for (const node of this.nodes) {
+            if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
+            const data = {};
+            for (const field of fields) {
+                data[field] = node[field];
             }
+            datas.push(data);
         }
-        return true;
+        return datas;
     }
-
     /**
-     * 查询最底层项目节(本身或父项)
-     * @param {Object} node - 查询节点
-     * @returns {Object}
+     * 排除 某些字段 获取数据
+     * @param fields
+     * @returns {Array}
      */
-    getLeafXmjParent(node) {
-        let parent = node;
-        while (parent) {
-            if (this.isLeafXmj(parent)) {
-                return parent;
-            } else {
-                parent = this.getParent(parent);
+    getDatasWithout (fields) {
+        const datas = [];
+        for (const node of this.nodes) {
+            if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
+            const data = {};
+            for (const field in node) {
+                if (fields.indexOf(field) === -1) {
+                    data[field] = node[field];
+                }
             }
+            datas.push(data);
         }
-        return null;
+        return datas;
+    }
+    /**
+     * 获取默认数据 剔除一些树结构需要的缓存数据
+     * @returns {Array}
+     */
+    getDefaultDatas() {
+        return this.getDatasWithout(['expanded', 'visible', 'children', 'index']);
     }
 
     _mapTreeNode () {
@@ -250,37 +263,149 @@ class billsTree {
             }
         }
     }
+}
 
-    getDatas (fields) {
-        const datas = [];
-        for (const node of this.nodes) {
-            if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
-            const data = {};
-            for (const field of fields) {
-                data[field] = node[field];
+class billsTree extends baseTree {
+    /**
+     * 检查节点是否是最底层项目节
+     * @param node
+     * @returns {boolean}
+     */
+    isLeafXmj(node) {
+        if (node.b_code && node.b_code !== '') {
+            return false;
+        }
+        for (const child of node.children) {
+            if (!child.b_code || child.b_code === '') {
+                return false;
             }
-            datas.push(data);
         }
-        return datas;
+        return true;
     }
+    /**
+     * 查询最底层项目节(本身或父项)
+     * @param {Object} node - 查询节点
+     * @returns {Object}
+     */
+    getLeafXmjParent(node) {
+        let parent = node;
+        while (parent) {
+            if (this.isLeafXmj(parent)) {
+                return parent;
+            } else {
+                parent = this.getParent(parent);
+            }
+        }
+        return null;
+    }
+}
 
-    getDatasWithout (fields) {
-        const datas = [];
-        for (const node of this.nodes) {
-            if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
-            const data = {};
-            for (const field in node) {
-                if (fields.indexOf(field) === -1) {
-                    data[field] = node[field];
+class filterTree extends baseTree {
+    addData(data, fields) {
+        const item = {};
+        for (const prop in data) {
+            if (fields.indexOf(prop) >= 0) {
+                item[prop] = data[prop];
+            }
+        }
+        const keyName = itemsPre + item[this.setting.id];
+        if (!this.items[keyName]) {
+            item.children = [];
+            item.is_leaf = true;
+            item.expanded = true;
+            item.visible = true;
+            this.items[keyName] = item;
+            this.datas.push(item);
+            if (item[this.setting.pid] === this.setting.rootId) {
+                this.children.push(item);
+            } else {
+                const parent = this.getParent(item);
+                if (parent) {
+                    parent.is_leaf = false;
+                    parent.children.push(item);
                 }
             }
-            datas.push(data);
+        } else {
+            return this.items[keyName];
         }
-        return datas;
+        return item;
+    }
+}
+
+class filterGatherTree extends baseTree {
+
+    clearDatas() {
+        this.items = {};
+        this.nodes = [];
+        this.datas = [];
+        this.children = [];
     }
 
-    getDefaultDatas() {
-        return this.getDatasWithout(['expanded', 'visible', 'children', 'index']);
+    get newId() {
+        if (!this._maxId) {
+            this._maxId = 0;
+        }
+        this._maxId++;
+        return this._maxId;
+    }
+
+    addNode(data, parent) {
+        data[this.setting.pid] = parent ? parent[this.setting.id] : this.setting.rootId;
+        let item = this.ctx.helper._.find(this.items, data);
+        if (item) return item;
+
+        item = data;
+        item[this.setting.id] = this.newId;
+        const keyName = itemsPre + item[this.setting.id];
+        item.children = [];
+        item.is_leaf = true;
+        item.expanded = true;
+        item.visible = true;
+        this.items[keyName] = item;
+        this.datas.push(item);
+        if (parent) {
+            item[this.setting.fullPath] = parent[this.setting.fullPath] + '-' + item[this.setting.id];
+            item[this.setting.level] = parent[this.setting.level] + 1;
+            item[this.setting.order] = parent.children.length + 1;
+            parent.is_leaf = false;
+            parent.children.push(item);
+        } else {
+            item[this.setting.fullPath] = '' + item[this.setting.id];
+            item[this.setting.level] = 1;
+            item[this.setting.order] = this.children.length + 1;
+            this.children.push(item);
+        }
+        return item;
+    }
+
+    sortTreeNodeCustom(field, fun, isResort) {
+        const self = this;
+        const sortNodes = function (nodes) {
+            nodes.sort(function (a, b) {
+                return fun(a[field], b[field]);
+            });
+            for (const [i, node] of nodes.entries()) {
+                node.order = i + 1;
+            }
+        };
+        const addSortNodes = function (nodes) {
+            if (!nodes) { return }
+            for (let i = 0; i < nodes.length; i++) {
+                self.nodes.push(nodes[i]);
+                nodes[i].index = self.nodes.length - 1;
+                if (!isResort) {
+                    nodes[i].children = self.getChildren(nodes[i]);
+                }
+                sortNodes(nodes[i].children);
+                addSortNodes(nodes[i].children);
+            }
+        };
+        this.nodes = [];
+        if (!isResort) {
+            this.children = this.getChildren();
+        }
+        sortNodes(this.children);
+        addSortNodes(this.children);
     }
 }
 
@@ -355,4 +480,6 @@ class pos {
 module.exports = {
     billsTree,
     pos,
+    filterTree,
+    filterGatherTree,
 };

+ 3 - 1
app/lib/rpt_data_analysis.js

@@ -231,7 +231,7 @@ const gatherChapter = {
             {name: '已包含在清单合计中的材料、工程设备、专业工程暂估价', order: 2, visible: false},
             {name: '清单合计减去材料、工程设备、专业工程暂估价(即8-9=10)', order_calc: 'o1-o2', order: 3},
             {name: '计日工合计', node_type: '计日工', order: 4},
-            {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', order: 5, match: [{node_type: '暂列金额'}, {field: 'name', part: '暂列金额'}, {field: 'name', part: '暂定金额'}]},
+            {name: '暂列金额(不含计日工总额)(即10×暂列金额比列)', order: 5, match: [{node_type: '暂列金额'}, {field: 'name', part: '暂列金额'}, {field: 'name', all: '暂定金额'}]},
             {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
         ],
         rela: [
@@ -400,6 +400,8 @@ const gatherChapter = {
                 const value = d[m.field];
                 if (m.part && value) {
                     if (value.indexOf(m.part) >= 0) return true;
+                } else if (m.all && value) {
+                    if (m.all === value) return true;
                 }
             }
         }

+ 17 - 4
app/public/js/ledger_bwtz.js

@@ -9,7 +9,6 @@
  */
 
 $(document).ready(() => {
-    const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
     autoFlashHeight();
     const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]);
     const xmjSheet = xmjSpread.getActiveSheet();
@@ -34,9 +33,23 @@ $(document).ready(() => {
         unitTreeObj.loadCurUnitData();
     });
 
-    postData(preUrl + '/load', {}, function (result) {
-        billsPosConvertModel.loadData(result.bills, result.pos, [], decimal);
-        const xmjTree = billsPosConvertModel.convert();
+    postData(window.location.pathname + '/load', {}, function (result) {
+        const setting = {
+            id: 'ledger_id',
+            pid: 'ledger_pid',
+            order: 'order',
+            level: 'level',
+            rootId: -1,
+            fullPath: 'full_path',
+        };
+        const xmjTree = createNewPathTree('base', setting);
+        xmjTree.loadDatas(result);
+        for (const n of xmjTree.nodes) {
+            if (n.unitTreeData) {
+                n.unitTree = createNewPathTree('base', setting);
+                n.unitTree.loadDatas(n.unitTreeData);
+            }
+        }
         SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree);
         unitTreeObj.loadCurUnitData();
     });

+ 17 - 3
app/public/js/stage_bwtz.js

@@ -34,9 +34,23 @@ $(document).ready(() => {
         unitTreeObj.loadCurUnitData();
     });
 
-    postData(preUrl + '/load', { filter: 'ledger;pos;change' }, function (result) {
-        billsPosConvertModel.loadData(result.ledgerData, result.posData, result.changeData, decimal);
-        const xmjTree = billsPosConvertModel.convert();
+    postData(window.location.pathname + '/load', {}, function (result) {
+        const setting = {
+            id: 'ledger_id',
+            pid: 'ledger_pid',
+            order: 'order',
+            level: 'level',
+            rootId: -1,
+            fullPath: 'full_path',
+        };
+        const xmjTree = createNewPathTree('base', setting);
+        xmjTree.loadDatas(result);
+        for (const n of xmjTree.nodes) {
+            if (n.unitTreeData) {
+                n.unitTree = createNewPathTree('base', setting);
+                n.unitTree.loadDatas(n.unitTreeData);
+            }
+        }
         SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree);
         unitTreeObj.loadCurUnitData();
     });

+ 2 - 0
app/router.js

@@ -113,6 +113,7 @@ module.exports = app => {
 
     // 部位台账
     app.get('/tender/:id/ledger/bwtz', sessionAuth, tenderCheck, 'ledgerController.bwtz');
+    app.post('/tender/:id/ledger/bwtz/load', sessionAuth, tenderCheck, 'ledgerController.loadBwtz');
 
     // 台账对比
     app.get('/tender/:id/ledger/gather', sessionAuth, tenderCheck, 'ledgerController.gather');
@@ -198,6 +199,7 @@ module.exports = app => {
     app.get('/tender/:id/measure/stage/:order/audit/check/again', sessionAuth, tenderCheck, stageCheck, 'stageController.checkAuditAgain');
     // 部位台账
     app.get('/tender/:id/measure/stage/:order/bwtz', sessionAuth, tenderCheck, stageCheck, 'stageController.bwtz');
+    app.post('/tender/:id/measure/stage/:order/bwtz/load', sessionAuth, tenderCheck, stageCheck, 'stageController.loadBwtz');
     // 清单汇总
     app.get('/tender/:id/measure/stage/:order/gather', sessionAuth, tenderCheck, stageCheck, 'stageController.gather');
     // 审核比较