Explorar o código

1. 新增章节编号
2. 报表,新增清单排序方法

MaiXinRong %!s(int64=5) %!d(string=hai) anos
pai
achega
8319eb40ac

+ 14 - 2
app/extend/helper.js

@@ -386,9 +386,9 @@ module.exports = {
      */
     compareCode(str1, str2, symbol = '-') {
         if (!str1) {
-            return -1;
-        } else if (!str2) {
             return 1;
+        } else if (!str2) {
+            return -1;
         }
 
         const path1 = str1.split(symbol);
@@ -410,6 +410,18 @@ module.exports = {
         return path1.length - path2.length;
     },
 
+    getChapterCode(code, symbol = '-') {
+        if (!code || code === '') return '';
+        const codePath = code.split(symbol);
+        const reg = /^[0-9]*$/;
+        if (reg.text(codePath[0])) {
+            const num = parseInt(codePath[0]);
+            return this.mul(this.div(num, 100, 0), 100);
+        } else {
+            return '';
+        }
+    },
+
     /**
      * 树结构节点排序,要求最顶层节点须在同一父节点下
      * @param treeNodes

+ 1 - 0
app/lib/ledger.js

@@ -248,6 +248,7 @@ 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];

+ 109 - 0
app/lib/rpt_data_analysis.js

@@ -36,7 +36,116 @@ const changeSort = {
         })
     },
 };
+const gatherGcl = {
+    name: '汇总工程量清单',
+    hint: '请使用mem_stage_bills下指标,注意事项:\n' +
+        '1. 以下字段,不管报表是否实际使用,均应添加至指标映射,且在此处应勾选(不要求顺序):\n' +
+        '  清单编号(b_code), 名称(name), 单位(unit), 单价(unit_price), 树结构-是否子项(is_leaf)\n' +
+        '2. 汇总后,以下字段,均会失效, 请勿使用:\n' +
+        '  台账ID(id), 树结构-ID(ledger_id), 树结构父项-ID(ledger_pid),\n' +
+        '  树结构-层级(level), 树结构-同层排序(order), 树结构-完整路径(full_path),\n' +
+        '  图册号(drawing_code), 备注(memo), 节点类型(node_type), 总额计量(is_tp)\n' +
+        '3. 如需汇总"未计入清单章节项",请勾选"章节编号(chapter)"字段\n',
+    fun: function (ctx, data, fieldsKey) {
+        const gatherFields = function(gcl, data, fields) {
+            for (const f of fields) {
+                if (data[f]) {
+                    gcl[f] = ctx.helper.add(gcl[f], data[f]);
+                }
+            }
+        };
+        if (!data.mem_stage_bills) return;
+
+        const fields = ctx.helper._.map(fieldsKey, 'field');
+        const needFields = ['b_code', 'name', 'unit', 'unit_price', 'is_leaf'];
+        for (const nf of needFields) {
+            if (fields.indexOf(nf) === -1) return;
+        }
+        const gatherOther = fields.indexOf('chapter') >= 0;
+
+        ctx.helper._.pull(data.mem_stage_bills, 'is_leaf');
+        const gclBills = [], other = {name: '未计入清单章节项', chapter: '100'};
+
+        for (const b of data.mem_stage_bills) {
+            if (b.b_code && b.b_code !== '') {
+                let gcl = gclBills.find(function (g) {
+                    return g.b_code === b.b_code && g.name === b.name && g.unit === b.unit
+                        && ctx.helper.checkZero(ctx.helper.sub(g.unit_price, b.unit_price));
+                });
+                if (!gcl) {
+                    gcl = {
+                        b_code: b.b_code, name: b.name, unit: b.unit,
+                        unit_price: b.unit_price,
+                        gc_bgl_code: [],
+                    };
+                    gclBills.push(gcl);
+                }
+                gatherFields(gcl, b, [
+                    'deal_qty', 'deal_tp',
+                    'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
+                    'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp',
+                    'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
+                    'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
+                    'final_tp'
+                ]);
+                if (b.qc_bgl_code && b.qc_bgl_code !== '') {
+                    gcl.qc_bgl_code = gcl.qc_bgl_code.concat(b.qc_bgl_code.split(';'));
+                }
+            } else if (gatherOther) {
+                gatherFields(other, b, [
+                    'deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price',
+                    'contract_tp', 'qc_tp', 'gather_tp',
+                    'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp',
+                    'end_contract_tp', 'end_qc_tp', 'end_gather_tp',
+                    'final_tp'
+                ]);
+            }
+        }
+        if (gatherOther) gclBills.push(other);
+        for (const g of gclBills) {
+            if (g.qc_bgl_code) g.qc_bgl_code = g.qc_bgl_code.join(';');
+            g.final_ratio = ctx.helper.mul(ctx.helper.div(g.end_gather_tp, g.final_ratio), 100);
+        }
+
+        data.mem_stage_bills = gclBills;
+    }
+};
+const sortGcl = {
+    name: '工程量清单排序',
+    hint: '只对一张表,进行工程量清单排序,排序哪张表,根据勾选的清单编号字段决定:\n' +
+        'e.g.1 要对mem_stage_bills排序,需要勾选mem_stage_bills下的"清单编号(b_code)"字段\n' +
+        'e.g.2 要对mem_stage_im_zl排序,需要勾选mem_stage_im_zl下的"中间计量总量信息_编号(code)"字段\n' +
+        '特别的,如有"未计入清单章节项": \n' +
+        '  1. 默认"未计入清单章节项"排列在最后\n' +
+        '  2. 如须"未计入清单章节项"排在100章之后,请在清单编号字段后,依次勾选"章节编号(chapter)", "名称(name)"\n',
+    fun: function (ctx, data, fieldsKey) {
+        if (fieldsKey.length !== 1 || fieldsKey.length !== 3) return;
+        const code = fieldsKey[0].field;
+        const chapter = fieldsKey.length > 1 ? fieldsKey[1].field : '';
+        const name = fieldsKey.length > 2 ? fieldsKey[2].field : '';
+
+
+        const sortData = data[fieldsKey[0].table];
+        if (!sortData) return;
+
+        sortData.sort(function (a, b) {
+            if (chapter !== '') {
+                if (a[name] === '未计入清单章节项') {
+                    return b[chapter] === '100' ? 1 : -1;
+                } else if (b[name] === '未计入清单章节项') {
+                    return a[chapter] === '100' ? -1 : 1
+                } else {
+                    return ctx.helper.compareCode(a[code], b[code]);
+                }
+            } else {
+                return ctx.helper.compareCode(a[code], b[code]);
+            }
+        });
+    }
+};
 
 module.exports = {
     changeSort,
+    gatherGcl,
+    sortGcl,
 };

+ 1 - 0
app/service/report_memory.js

@@ -362,6 +362,7 @@ module.exports = app => {
                 'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
                 'final_tp', 'final_ratio',
                 'qc_bgl_code',
+                'chapter',
             ]);
         }
 

+ 3 - 0
test/app/extend/helper.test.js

@@ -123,6 +123,9 @@ describe('test/app/extend/helper.test.js', () => {
         assert(ctx.helper.compareCode('1.1.1', '1.1.2', '.') < 0);
         assert(ctx.helper.compareCode('1.1.3', '1.2.2', '.') < 0);
         assert(ctx.helper.compareCode('2.4.3', '3.1.2', '.') < 0);
+        // 测试空编号
+        assert(ctx.helper.compareCode('', '1-1') < 0);
+        assert(ctx.helper.compareCode('1-1', '') > 0);
     });
 
     it('test arithmetic', function () {

+ 3 - 0
test/app/service/report_memory.test.js

@@ -103,6 +103,7 @@ describe('test/app/service/report_memory.test.js', () => {
             'end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp',
             'final_tp', 'final_ratio',
             'qc_bgl_code',
+            'chapter',
         ]);
         if (mainData instanceof Array) {
             yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_bills.json');
@@ -174,6 +175,8 @@ describe('test/app/service/report_memory.test.js', () => {
 
             addFields(tableDefine, '本期-数量变更-变更令', 'qc_bgl_code', dataType.str);
 
+            addFields(tableDefine, '章节编号', 'chapter', dataType.str);
+
             delete tableDefine.ID;
             delete tableDefine.key;
             yield ctx.helper.saveBufferFile(JSON.stringify(tableDefine,"","\t"), ctx.app.baseDir + '/mem_stage_bills_define.json');