Browse Source

1. 章级汇总,关联其他清单的解决方案
2. 变更清单,mem_change_bills

MaiXinRong 5 years ago
parent
commit
a827479d6a

+ 51 - 3
app/lib/rpt_data_analysis.js

@@ -233,6 +233,16 @@ const gatherChapter = {
             {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', part: '暂定金额'}]},
             {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
             {name: '投标报价、台账价(8+11+12)=13', order_calc: 'o1+o4+o5', order: 6},
         ],
         ],
+        rela: [
+            {
+                table: 'deal_bills', key: 'code',
+                fields: {source: 'total_price', target: 'ex_value1'},
+            },
+            {
+                table: 'mem_change_bills', key: 'code',
+                fields: {source: '', target: 'ex_value2'},
+            }
+        ]
     },
     },
     _getCalcChapter: function (chapter, options) {
     _getCalcChapter: function (chapter, options) {
         const gclChapter = [], otherChapter = [], customChapter = [];
         const gclChapter = [], otherChapter = [], customChapter = [];
@@ -285,11 +295,11 @@ const gatherChapter = {
         }
         }
         return [gclChapter, otherChapter, customChapter];
         return [gclChapter, otherChapter, customChapter];
     },
     },
-    _getGclChapter: function (chapter, data) {
+    _getGclChapter: function (chapter, data, field) {
         for (const c of chapter) {
         for (const c of chapter) {
             if (c.filter) {
             if (c.filter) {
                 const reg = new RegExp(c.filter);
                 const reg = new RegExp(c.filter);
-                if (reg.test(data.b_code)) {
+                if (reg.test(data[field])) {
                     return c;
                     return c;
                 }
                 }
             } else {
             } else {
@@ -303,6 +313,40 @@ const gatherChapter = {
         }
         }
         return false;
         return false;
     },
     },
+    _gatherRela: function (ctx, data, rela, gclChapter, otherChapter) {
+        if (!rela) return;
+
+        const gatherRelaFields = function (chapter, source, field) {
+            const fields = field instanceof Array ? field : [field];
+            for (const f of fields) {
+                chapter[f.target] = ctx.helper.add(chapter[f.target], source[f.source]);
+            }
+        };
+
+        const relaBills = rela instanceof Array ? rela : [rela];
+        for (const rb of relaBills) {
+            if (!rb.table) continue;
+
+            const relaData = data[rb.table];
+            if (!relaData) continue;
+
+            for (const rd of relaData) {
+                for (const c of otherChapter) {
+                    if (c.cType === 41) {
+                        gatherRelaFields(c, rd, rb.fields);
+                    } else if (c.cType === 31 && (!rd[rb.key] || rd[rb.key] === '')) {
+                        gatherRelaFields(c, rd, rb.fields);
+                    } else if (c.cType === 11 && (rd[rb.key])) {
+                        gatherRelaFields(c, rd, rb.fields);
+                    }
+                }
+                if (rd[rb.key]) {
+                    const c = this._getGclChapter(gclChapter, rd, rb.key);
+                    gatherRelaFields(c, rd, rb.fields);
+                }
+            }
+        }
+    },
     _orderCalc: function (ctx, chapter, fields) {
     _orderCalc: function (ctx, chapter, fields) {
         const orderMatch = new RegExp('o[0-9]+', 'igm');
         const orderMatch = new RegExp('o[0-9]+', 'igm');
         for (const c of chapter) {
         for (const c of chapter) {
@@ -387,10 +431,11 @@ const gatherChapter = {
                 }
                 }
             }
             }
             if (d.b_code) {
             if (d.b_code) {
-                const c = this._getGclChapter(gclChapter, d);
+                const c = this._getGclChapter(gclChapter, d, 'b_code');
                 gatherData(c, d);
                 gatherData(c, d);
             }
             }
         }
         }
+        this._gatherRela(ctx, data, options.rela, gclChapter, otherChapter);
         const chapter = gclChapter.concat(otherChapter).concat(customChapter);
         const chapter = gclChapter.concat(otherChapter).concat(customChapter);
         this._orderCalc(ctx, chapter, calcFields);
         this._orderCalc(ctx, chapter, calcFields);
         chapter.sort(function (a, b) {return a.serialNo - b.serialNo});
         chapter.sort(function (a, b) {return a.serialNo - b.serialNo});
@@ -405,6 +450,7 @@ const gatherChapter = {
                 return true;
                 return true;
             }
             }
         });
         });
+        //console.log(data[fieldsKey[0].table]);
     },
     },
 };
 };
 const join = {
 const join = {
@@ -691,6 +737,7 @@ const union = {
     fun: function(ctx, data, fields, options) {
     fun: function(ctx, data, fields, options) {
         if (!options || !options.union) return;
         if (!options || !options.union) return;
 
 
+        console.log(data.mem_stage_pay);
         const result = [];
         const result = [];
         for (const u of options.union) {
         for (const u of options.union) {
             const unionData = data[u.table];
             const unionData = data[u.table];
@@ -707,6 +754,7 @@ const union = {
             }
             }
         }
         }
         data.mem_union_data = result;
         data.mem_union_data = result;
+        //console.log(data.mem_union_data);
     }
     }
 };
 };
 
 

+ 3 - 1
app/reports/util/rpt_calculation_data_util.js

@@ -554,10 +554,12 @@ function preDefineProcess(ctx, tpl, preDefineCfg, rawDataObj, $CURRENT_RPT) {
                         preSetup = JSON.parse(preSetup);
                         preSetup = JSON.parse(preSetup);
                     }
                     }
                 } catch (ex) {
                 } catch (ex) {
-                    console.log(ex);
+                    console.log(analysisKey);
+                    ctx.helper.log(ex);
                 }
                 }
                 data_analyze_util[analysisKey].fun(ctx, rawDataObj, fields, preSetup);
                 data_analyze_util[analysisKey].fun(ctx, rawDataObj, fields, preSetup);
             } catch (err) {
             } catch (err) {
+                ctx.helper.log(err);
                 throw '报表预处理数据出错';
                 throw '报表预处理数据出错';
             }
             }
         } else {
         } else {

+ 4 - 1
app/service/report.js

@@ -94,7 +94,10 @@ module.exports = app => {
                             break;
                             break;
                         case 'mem_stage_pay':
                         case 'mem_stage_pay':
                             runnableRst.push(service.reportMemory.getStagePayData(params.tender_id, params.stage_id, memFieldKeys[filter]));
                             runnableRst.push(service.reportMemory.getStagePayData(params.tender_id, params.stage_id, memFieldKeys[filter]));
-                            runnableKey.push(filter);
+                            runnableKey.push('mem_stage_pay');
+                        case 'mem_change_bills':
+                            runnableRst.push(service.reportMemory.getChangeBillsData(params.tender_id, params.stage_id, memFieldKeys[filter]));
+                            runnableKey.push('mem_change_bills');
                             break;
                             break;
                         case 'change':
                         case 'change':
                             runnableRst.push(service.change.getListByStatus(params.tender_id, 3)); // 获取所有审核通过的变更主信息
                             runnableRst.push(service.change.getListByStatus(params.tender_id, 3)); // 获取所有审核通过的变更主信息

+ 16 - 0
app/service/report_memory.js

@@ -524,6 +524,22 @@ module.exports = app => {
             }
             }
             return dealPay;
             return dealPay;
         }
         }
+
+        async getChangeBillsData(tid, sid, fields) {
+            await this.ctx.service.tender.checkTender(tid);
+
+            const data = await this.ctx.service.changeAuditList.getChangeAuditBills(tid);
+            for (const d of data) {
+                const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, d.unit);
+                d.o_qty = d.oamount;
+                d.o_tp = this.ctx.helper.mul(d.o_qty, d.unit_price, precision.value);
+                d.c_qty = d.camount;
+                d.c_tp = this.ctx.helper.mul(d.c_qty, d.unit_price, precision.value);
+                d.s_qty = d.samount ? parseFloat(d.samount) : 0;
+                d.s_tp = this.ctx.helper.mul(d.s_qty, d.unit_price, precision.value);
+            }
+            return data;
+        }
     }
     }
 
 
     return ReportMemory;
     return ReportMemory;

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

@@ -9,6 +9,8 @@
  */
  */
 
 
 const { app, assert } = require('egg-mock/bootstrap');
 const { app, assert } = require('egg-mock/bootstrap');
+const path = require('path');
+let savePath;
 const mockData = {};
 const mockData = {};
 const dataType = {
 const dataType = {
     int: 'int',
     int: 'int',
@@ -51,6 +53,7 @@ describe('test/app/service/report_memory.test.js', () => {
     // 准备测试数据
     // 准备测试数据
     before(function* () {
     before(function* () {
         const ctx = app.mockContext();
         const ctx = app.mockContext();
+        savePath = path.join(ctx.app.baseDir,'report_temp');
         // 模拟登录session
         // 模拟登录session
         const postData = {
         const postData = {
             account: '734406061@qq.com',
             account: '734406061@qq.com',
@@ -370,4 +373,36 @@ describe('test/app/service/report_memory.test.js', () => {
         addFields(tableDefine, prefix + '金额10', 'tp10', dataType.currency);
         addFields(tableDefine, prefix + '金额10', 'tp10', dataType.currency);
         yield saveTableDefine(ctx, tableDefine, ctx.app.baseDir + '/mem_union_data.json');
         yield saveTableDefine(ctx, tableDefine, ctx.app.baseDir + '/mem_union_data.json');
     });
     });
+    it('test mem_change_bills', function* () {
+        const ctx = app.mockContext(mockData);
+
+        const data = yield ctx.service.reportMemory.getChangeBillsData(12);
+        if (data instanceof Array) {
+            yield ctx.helper.saveBufferFile(JSON.stringify(data, '', '\t'), path.join(savePath, 'mem_change_bills.json'));
+
+            const tableDefine = {};
+            tableDefine.Name = '变更清单-(mem_change_bills)';
+            tableDefine.remark = '';
+            tableDefine.ID = 29;
+            tableDefine.key = 'mem_change_bills';
+            tableDefine.items = [];
+            const prefix = '变更清单-';
+
+            addFields(tableDefine, prefix + '变更令id', 'cid', dataType.str);
+            addFields(tableDefine, prefix + '签约清单id或台账id', 'lid', dataType.str);
+            addFields(tableDefine, prefix + '清单编号', 'code', dataType.str);
+            addFields(tableDefine, prefix + '名称', 'name', dataType.str);
+            addFields(tableDefine, prefix + '单位', 'unit', dataType.str);
+            addFields(tableDefine, prefix + '单价', 'unit_price', dataType.currency);
+            addFields(tableDefine, prefix + '原数量', 'o_qty', dataType.currency);
+            addFields(tableDefine, prefix + '变更数量', 'c_qty', dataType.currency);
+            addFields(tableDefine, prefix + '审批变更后数量', 's_qty', dataType.currency);
+            addFields(tableDefine, prefix + '原-金额', 'o_tp', dataType.currency);
+            addFields(tableDefine, prefix + '变更-金额', 'c_tp', dataType.currency);
+            addFields(tableDefine, prefix + '审批变更后-金额', 's_tp', dataType.currency);
+            addFields(tableDefine, prefix + '部位明细', 'bwmx', dataType.str);
+            addFields(tableDefine, prefix + '变更详情', 'detail', dataType.str);
+            yield saveTableDefine(ctx, tableDefine, path.join(savePath, 'mem_change_bills_define.json'));
+        }
+    });
 });
 });