Sfoglia il codice sorgente

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

laiguoran 5 anni fa
parent
commit
86f872edba

+ 545 - 0
app/const/report_defined_properties.js

@@ -0,0 +1,545 @@
+/**
+ * Created by Tony on 2019/12/26.
+ */
+
+module.exports = {
+    "ctrls": [{
+        "ID": "Default",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "left",
+        "ShowZero": "T",
+        "Vertical": "bottom",
+        "CfgDispName": "默认",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Title",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "center",
+        "ShowZero": "T",
+        "Vertical": "center",
+        "CfgDispName": "标题",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Header",
+        "Wrap": "F",
+        "Shrink": "F",
+        "Horizon": "left",
+        "ShowZero": "T",
+        "Vertical": "center",
+        "CfgDispName": "表头",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Header_Right",
+        "Wrap": "F",
+        "Shrink": "F",
+        "Horizon": "right",
+        "ShowZero": "T",
+        "Vertical": "center",
+        "CfgDispName": "表头_右",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Footer",
+        "Wrap": "F",
+        "Shrink": "F",
+        "Horizon": "left",
+        "ShowZero": "T",
+        "Vertical": "center",
+        "CfgDispName": "表尾",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Footer_Right",
+        "Wrap": "F",
+        "Shrink": "F",
+        "Horizon": "right",
+        "ShowZero": "T",
+        "Vertical": "center",
+        "CfgDispName": "表尾_右",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Column",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "center",
+        "ShowZero": "F",
+        "Vertical": "center",
+        "CfgDispName": "表栏",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F",
+        "FillAfterWrap": "T"
+    }, {
+        "ID": "Column_Left",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "left",
+        "ShowZero": "F",
+        "Vertical": "center",
+        "CfgDispName": "表栏_左",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Column_Right",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "right",
+        "ShowZero": "F",
+        "Vertical": "center",
+        "CfgDispName": "表栏_右",
+        "CloseOutput": "F",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Content_Left",
+        "Wrap": "F",
+        "Shrink": "T",
+        "Horizon": "left",
+        "ShowZero": "F",
+        "Vertical": "bottom",
+        "CfgDispName": "正文内容",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Content_Right",
+        "Wrap": "F",
+        "Shrink": "T",
+        "Horizon": "right",
+        "ShowZero": "F",
+        "Vertical": "bottom",
+        "CfgDispName": "正文内容_右",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Content_Center",
+        "Wrap": "F",
+        "Shrink": "T",
+        "Horizon": "center",
+        "ShowZero": "F",
+        "Vertical": "bottom",
+        "CfgDispName": "正文内容_中",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "NewContent_Left",
+        "Wrap": "F",
+        "Shrink": "T",
+        "Horizon": "left",
+        "ShowZero": "F",
+        "Vertical": "center",
+        "CfgDispName": "正文内容(新)",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "NewContent_Right",
+        "Wrap": "F",
+        "Shrink": "T",
+        "Horizon": "right",
+        "ShowZero": "F",
+        "Vertical": "center",
+        "CfgDispName": "正文内容(新)_右",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "NewContent_Center",
+        "Wrap": "F",
+        "Shrink": "T",
+        "Horizon": "center",
+        "ShowZero": "F",
+        "Vertical": "center",
+        "CfgDispName": "正文内容(新)_中",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Currency",
+        "Wrap": "F",
+        "Shrink": "T",
+        "Horizon": "right",
+        "ShowZero": "F",
+        "Vertical": "center",
+        "CfgDispName": "金额型",
+        "CloseOutput": "F",
+        "ShrinkFirst": "T"
+    }, {
+        "ID": "Left_Top",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "left",
+        "ShowZero": "T",
+        "Vertical": "top",
+        "CfgDispName": "上靠_左",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Center_Top",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "center",
+        "ShowZero": "T",
+        "Vertical": "top",
+        "CfgDispName": "上靠_中",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }, {
+        "ID": "Right_Top",
+        "Wrap": "T",
+        "Shrink": "F",
+        "Horizon": "right",
+        "ShowZero": "T",
+        "Vertical": "top",
+        "CfgDispName": "上靠_右",
+        "CloseOutput": "T",
+        "ShrinkFirst": "F"
+    }
+    ],
+    "fonts": [{
+        "ID": "ReportTitle_Main",
+        "Name": "宋体",
+        "FontBold": "T",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "32",
+        "FontItalic": "F",
+        "CfgDispName": "主标题",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "ReportTitle_Vice_1",
+        "Name": "宋体",
+        "FontBold": "T",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "22",
+        "FontItalic": "F",
+        "CfgDispName": "副标题",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "ReportTitle_Vice_2",
+        "Name": "宋体",
+        "FontBold": "T",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "18",
+        "FontItalic": "F",
+        "CfgDispName": "副标题2",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "HeaderColumn",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "栏头",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "Header",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "表头",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "FooterColumn",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "栏尾",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "Footer",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "表尾",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "GrandTotal",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "总合计",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "SectionTotal",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "章合计",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "Content",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "正文内容",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "Content_Narrow",
+        "Name": "Arial Narrow",
+        "FontBold": "F",
+        "FontAngle": "0",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "CfgDispName": "正文内容-窄体",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "Header_V1",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "90",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }, {
+        "ID": "Header_V2",
+        "Name": "宋体",
+        "FontBold": "F",
+        "FontAngle": "-90",
+        "FontColor": "BLACK",
+        "FontHeight": "12",
+        "FontItalic": "F",
+        "FontStrikeOut": "F",
+        "FontUnderline": "F"
+    }
+    ],
+    "styles": [{
+        "ID": "Default_None",
+        "CfgDispName": "空白",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }
+        ]
+    }, {
+        "ID": "Default",
+        "CfgDispName": "默认",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }
+        ]
+    }, {
+        "ID": "Default_Normal",
+        "CfgDispName": "正常",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }
+        ]
+    }, {
+        "ID": "Label_Underline",
+        "CfgDispName": "字符底线",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }
+        ]
+    }, {
+        "ID": "Label_Left",
+        "CfgDispName": "左边线",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }
+        ]
+    }, {
+        "ID": "Label_Right",
+        "CfgDispName": "右边线",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }
+        ]
+    }, {
+        "ID": "Label_Top",
+        "CfgDispName": "上边线",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "1"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "0"
+        }
+        ]
+    }, {
+        "ID": "BORDER_ALL_AROUND",
+        "CfgDispName": "报表边框",
+        "border_style": [{
+            "Color": "BLACK",
+            "Position": "Left",
+            "DashStyle": "SOLID",
+            "LineWeight": "2.0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Right",
+            "DashStyle": "SOLID",
+            "LineWeight": "2.0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Top",
+            "DashStyle": "SOLID",
+            "LineWeight": "2.0"
+        }, {
+            "Color": "BLACK",
+            "Position": "Bottom",
+            "DashStyle": "SOLID",
+            "LineWeight": "2.0"
+        }
+        ]
+    }
+    ]
+};
+

+ 4 - 2
app/controller/report_controller.js

@@ -14,6 +14,7 @@ const rptDataExtractor = require('../reports/util/rpt_calculation_data_util');
 const fsUtil = require('../public/js/fsUtil');
 const fs = require('fs');
 const rptCronJob = require('../reports/util/rpt_tmp_file_sweep');
+const RPT_DEF_PROPERTIES = require('../const/report_defined_properties');
 
 module.exports = app => {
     class ReportController extends app.BaseController {
@@ -423,10 +424,11 @@ async function getAllPagesCommon(ctx, rptTpl, params, option, outputType, baseDi
         const printCom = JpcEx.createNew();
         if (params.pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = params.pageSize;
         if (params.orientation && (params.orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = params.orientation;
-        let defProperties = await ctx.service.rptPreDefineCfg.getCfgById('Administrator');
+        // let defProperties = await ctx.service.rptPreDefineCfg.getCfgById('Administrator');
         // console.log('defProperties: ');
         // console.log(defProperties[0].defined_content);
-        defProperties = JSON.parse(defProperties[0].defined_content);
+        // defProperties = JSON.parse(defProperties[0].defined_content);
+        const defProperties = RPT_DEF_PROPERTIES;
         if (params.custCfg) {
             setupCustomizeCfg(params.custCfg, rptTpl, defProperties);
         } else {

+ 60 - 14
app/service/report_memory.js

@@ -8,6 +8,8 @@
  * @version
  */
 
+const _ = require('lodash');
+
 const StageIm = require('../lib/stage_im');
 const imType = require('../const/tender').imType;
 const audit = require('../const/audit');
@@ -21,6 +23,15 @@ const stageImVersion = '1.0';
 
 const Ledger = require('../lib/ledger');
 
+const curFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil'];
+const preFields = ['pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp'];
+const endFields = ['end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp'];
+const finalFields = ['final_tp', 'final_ratio'];
+
+const stageFields = curFields.concat(preFields, endFields, finalFields);
+const stageEndFields = preFields.concat(endFields, finalFields);
+const bglFields = ['qc_bgl_code'];
+
 module.exports = app => {
     class ReportMemory extends app.BaseService {
 
@@ -78,6 +89,13 @@ module.exports = app => {
             this.stageImData = null;
         }
 
+        _checkFieldsExist(source, check) {
+            for (const s of source) {
+                if (check.indexOf(s)) return true;
+            }
+            return false;
+        }
+
         // build-time: 162-384ms, redis-cache: 0-41ms, mysql + IO: 116-146ms
         // 一定程度上算是大Value缓存,数据多了以后:
         // 1. 达到redis内存阈值时,数据会swap到磁盘,此时将消耗IO时间
@@ -280,31 +298,58 @@ module.exports = app => {
             return monthProgress;
         }
 
+        async _calcBillsBgl() {
+            const helper = this.ctx.helper;
+            const tender = this.ctx.tender;
+            const stage = this.ctx.stage;
+            const bglData = this.ctx.stage.readOnly
+                ? await this.ctx.service.stageChange.getAuditorAllStageData(tender.id, stage.id, stage.curTimes, stage.curOrder)
+                : await this.ctx.service.stageChange.getLastestAllStageData(tender.id, stage.id);
+
+            for (const node of this.billsTree.nodes) {
+                node.qc_bgl_code = '';
+                if (node.children && node.children.length > 0) continue;
+
+                const nodeBgl = helper._.pullAllBy(bglData, [{lid: node.id}], 'lid');
+                const validBgl = helper._.filter(nodeBgl, function (x) {
+                    return !helper.checkZero(x.qty);
+                });
+                node.qc_bgl_code = helper._.uniq(helper._.map(validBgl, 'c_code')).join(';');
+            }
+        }
+
         async getStageBillsData(tid, sid, fields) {
             await this.ctx.service.tender.checkTender(tid);
             await this.ctx.service.stage.checkStage(sid);
 
             const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
-            if (this.ctx.stage.readOnly) {
-                const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
-                    this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
-                this.ctx.helper.assignRelaData(billsData, [
-                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
-                ]);
-            } else {
-                const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
+            if (this._checkFieldsExist(fields, stageFields)) {
+                if (this.ctx.stage.readOnly) {
+                    const curStage = await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id,
+                        this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
+                    this.ctx.helper.assignRelaData(billsData, [
+                        {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
+                    ]);
+                } else {
+                    const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
+                    this.ctx.helper.assignRelaData(billsData, [
+                        {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
+                    ]);
+                }
+            }
+            if (this._checkFieldsExist(fields, preFields)) {
+                const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
                 this.ctx.helper.assignRelaData(billsData, [
-                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'}
+                    {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
                 ]);
             }
-            const preStage = this.ctx.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
-
-            this.ctx.helper.assignRelaData(billsData, [
-                {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
-            ]);
             this.billsTree.loadDatas(billsData);
             this.billsTree.calculateAll();
 
+            if (this._checkFieldsExist(fields, bglFields)) {
+                await this._calcBillsBgl();
+            }
+
             return this.billsTree.getDatas([
                 'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
                 'code', 'b_code', 'name', 'unit', 'unit_price',
@@ -316,6 +361,7 @@ module.exports = app => {
                 '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', 'final_ratio',
+                'qc_bgl_code',
             ]);
         }
 

+ 2 - 1
app/service/stage_bills.js

@@ -115,7 +115,8 @@ module.exports = app => {
         }
 
         async getStageUsedBills(tid, sid) {
-            const sql = 'SELECT Bills.lid, (Bills.contract_qty <> 0 or Bills.qc_qty <> 0) As used FROM ' + this.tableName + ' As Bills ' +
+            const sql = 'SELECT Bills.lid, ((not IsNull(Bills.contract_qty) and Bills.contract_qty <> 0) or (not IsNull(Bills.qc_qty) and Bills.qc_qty <> 0)) As used' +
+                '  FROM ' + this.tableName + ' As Bills ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `progress`, `lid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ?' +

+ 1 - 1
app/service/stage_pos.js

@@ -128,7 +128,7 @@ module.exports = app => {
             const self = this;
             const stagePos = await this.getLastestStageData2(tid, sid, where);
             const pids = this._.map(stagePos, function (sp) {
-                if (self.ctx.helper.checkZero(sp.contract_qty) || self.ctx.helper.checkZero(sp.qc_qty)) {
+                if (!self.ctx.helper.checkZero(sp.contract_qty) || !self.ctx.helper.checkZero(sp.qc_qty)) {
                     return sp.pid;
                 } else {
                     return -1;

+ 15 - 1
test/app/service/report_memory.test.js

@@ -91,7 +91,19 @@ describe('test/app/service/report_memory.test.js', () => {
 
         // test12 - 第6期
         const stage = yield ctx.service.stage.getDataByCondition({tid: 12, order: 6});
-        const mainData = yield ctx.service.reportMemory.getStageBillsData(12, stage.id);
+        const mainData = yield ctx.service.reportMemory.getStageBillsData(12, stage.id, [
+            'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
+            'code', 'b_code', 'name', 'unit', 'unit_price',
+            'deal_qty', 'deal_tp',
+            'sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'quantity', 'total_price',
+            'dgn_qty1', 'dgn_qty2',
+            'drawing_code', 'memo', 'node_type', 'is_tp',
+            'contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'gather_qty', 'gather_tp', 'postil',
+            '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', 'final_ratio',
+            'qc_bgl_code',
+        ]);
         if (mainData instanceof Array) {
             yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_bills.json');
             const tableDefine = {};
@@ -160,6 +172,8 @@ describe('test/app/service/report_memory.test.js', () => {
             addFields(tableDefine, '(台账 + 截止本期变更)-金额', 'final_tp', dataType.currency);
             addFields(tableDefine, '截止本期完成率(%)', 'final_ratio', dataType.double);
 
+            addFields(tableDefine, '本期-数量变更-变更令', 'qc_bgl_code', dataType.str);
+
             delete tableDefine.ID;
             delete tableDefine.key;
             yield ctx.helper.saveBufferFile(JSON.stringify(tableDefine,"","\t"), ctx.app.baseDir + '/mem_stage_bills_define.json');