|  | @@ -196,69 +196,81 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStageImTzData(tid, sid, fields, readCache = true) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            if (readCache) {
 | 
	
		
			
				|  |  | -                const cache = await this._getReportMemoryCache('mem_stage_im_tz', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
 | 
	
		
			
				|  |  | -                if (cache) return cache;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                if (readCache) {
 | 
	
		
			
				|  |  | +                    const cache = await this._getReportMemoryCache('mem_stage_im_tz', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
 | 
	
		
			
				|  |  | +                    if (cache) return cache;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (!this.stageImData) {
 | 
	
		
			
				|  |  | -                this.stageImData = {};
 | 
	
		
			
				|  |  | -                try {
 | 
	
		
			
				|  |  | -                    await this._generateStageIm(tid, sid);
 | 
	
		
			
				|  |  | -                } catch (err) {
 | 
	
		
			
				|  |  | -                    if (err.stack) {
 | 
	
		
			
				|  |  | -                        this.ctx.logger.error(err);
 | 
	
		
			
				|  |  | +                if (!this.stageImData) {
 | 
	
		
			
				|  |  | +                    this.stageImData = {};
 | 
	
		
			
				|  |  | +                    try {
 | 
	
		
			
				|  |  | +                        await this._generateStageIm(tid, sid);
 | 
	
		
			
				|  |  | +                    } catch (err) {
 | 
	
		
			
				|  |  | +                        if (err.stack) {
 | 
	
		
			
				|  |  | +                            this.ctx.logger.error(err);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        this.stageImData.main = err.stack ? '数据错误' : err;
 | 
	
		
			
				|  |  | +                        this.stageImData.bills = this.stageImData.main;
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    this.stageImData.main = err.stack ? '数据错误' : err;
 | 
	
		
			
				|  |  | -                    this.stageImData.bills = this.stageImData.main;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                return this.stageImData.main;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            return this.stageImData.main;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStageImTzBillsData(tid, sid, fields, readCache = true) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            if (readCache) {
 | 
	
		
			
				|  |  | -                const cache = await this._getReportMemoryCache('mem_stage_im_tz_bills', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
 | 
	
		
			
				|  |  | -                if (cache) return cache;
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                if (readCache) {
 | 
	
		
			
				|  |  | +                    const cache = await this._getReportMemoryCache('mem_stage_im_tz_bills', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
 | 
	
		
			
				|  |  | +                    if (cache) return cache;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (!this.stageImData) {
 | 
	
		
			
				|  |  | +                    this.stageImData = {};
 | 
	
		
			
				|  |  | +                    try {
 | 
	
		
			
				|  |  | +                        await this._generateStageIm(tid, sid);
 | 
	
		
			
				|  |  | +                    } catch (err) {
 | 
	
		
			
				|  |  | +                        if (err.stack) {
 | 
	
		
			
				|  |  | +                            this.ctx.logger.error(err);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        this.stageImData.main = err.stack ? '数据错误' : err;
 | 
	
		
			
				|  |  | +                        this.stageImData.bills = this.stageImData.main;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                return this.stageImData.bills;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        async getStageImZlData(tid, sid, fields, readCache = true) {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                if (readCache) {
 | 
	
		
			
				|  |  | +                    const cache = await this._getReportMemoryCache('mem_stage_im_zl', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
 | 
	
		
			
				|  |  | +                    if (cache) return cache;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (!this.stageImData) {
 | 
	
		
			
				|  |  |                  this.stageImData = {};
 | 
	
		
			
				|  |  |                  try {
 | 
	
		
			
				|  |  | -                    await this._generateStageIm(tid, sid);
 | 
	
		
			
				|  |  | +                    await this._generateStageIm(tid, sid, false);
 | 
	
		
			
				|  |  |                  } catch (err) {
 | 
	
		
			
				|  |  |                      if (err.stack) {
 | 
	
		
			
				|  |  |                          this.ctx.logger.error(err);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    this.stageImData.main = err.stack ? '数据错误' : err;
 | 
	
		
			
				|  |  | -                    this.stageImData.bills = this.stageImData.main;
 | 
	
		
			
				|  |  | +                    this.stageImData.main = err.statck ? '数据错误' : err;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            return this.stageImData.bills;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        async getStageImZlData(tid, sid, fields, readCache = true) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            if (readCache) {
 | 
	
		
			
				|  |  | -                const cache = await this._getReportMemoryCache('mem_stage_im_zl', tid, sid, this.ctx.stage.cacheTime, stageImVersion);
 | 
	
		
			
				|  |  | -                if (cache) return cache;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            this.stageImData = {};
 | 
	
		
			
				|  |  | -            try {
 | 
	
		
			
				|  |  | -                await this._generateStageIm(tid, sid, false);
 | 
	
		
			
				|  |  | +                return this.stageImData.main;
 | 
	
		
			
				|  |  |              } catch (err) {
 | 
	
		
			
				|  |  | -                if (err.stack) {
 | 
	
		
			
				|  |  | -                    this.ctx.logger.error(err);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                this.stageImData.main = err.statck ? '数据错误' : err;
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            return this.stageImData.main;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getMonthProgress(tid, fields) {
 | 
	
	
		
			
				|  | @@ -343,67 +355,71 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStageBillsData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            if (sid) {
 | 
	
		
			
				|  |  | -                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                if (sid) {
 | 
	
		
			
				|  |  | +                    await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, billsFields.stageDgn)) {
 | 
	
		
			
				|  |  | -                const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | -                for (const d of dgnData) {
 | 
	
		
			
				|  |  | -                    const l = this.ctx.helper._.find(billsData, {id: d.id});
 | 
	
		
			
				|  |  | -                    this.ctx.helper._.assignIn(l, d);
 | 
	
		
			
				|  |  | +                const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, billsFields.stageDgn)) {
 | 
	
		
			
				|  |  | +                    const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | +                    for (const d of dgnData) {
 | 
	
		
			
				|  |  | +                        const l = this.ctx.helper._.find(billsData, {id: d.id});
 | 
	
		
			
				|  |  | +                        this.ctx.helper._.assignIn(l, d);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, billsFields.stage)) {
 | 
	
		
			
				|  |  | -                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', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'}
 | 
	
		
			
				|  |  | -                    ]);
 | 
	
		
			
				|  |  | -                } else {
 | 
	
		
			
				|  |  | -                    const curStage = await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id);
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, billsFields.stage)) {
 | 
	
		
			
				|  |  | +                    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', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], 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', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'}
 | 
	
		
			
				|  |  | +                        ]);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
 | 
	
		
			
				|  |  | +                    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', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid'}
 | 
	
		
			
				|  |  | +                        {data: preStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'pre_', relaId: 'lid'}
 | 
	
		
			
				|  |  |                      ]);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
 | 
	
		
			
				|  |  | -                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, billsFields.bgl)) {
 | 
	
		
			
				|  |  | +                    await this._calcBillsBgl();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
 | 
	
		
			
				|  |  | +                    this._calcLeafXmjRela();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                return this.billsTree.getDatas([
 | 
	
		
			
				|  |  | +                    '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',
 | 
	
		
			
				|  |  | +                    'chapter',
 | 
	
		
			
				|  |  | +                    'leaf_xmj_id',
 | 
	
		
			
				|  |  | +                    'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'contract_expr',
 | 
	
		
			
				|  |  | +                    'deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2',
 | 
	
		
			
				|  |  |                  ]);
 | 
	
		
			
				|  |  | +            } catch(err) {
 | 
	
		
			
				|  |  | +                return []
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            this.billsTree.loadDatas(billsData);
 | 
	
		
			
				|  |  | -            this.billsTree.calculateAll();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, billsFields.bgl)) {
 | 
	
		
			
				|  |  | -                await this._calcBillsBgl();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
 | 
	
		
			
				|  |  | -                this._calcLeafXmjRela();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            return this.billsTree.getDatas([
 | 
	
		
			
				|  |  | -                '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',
 | 
	
		
			
				|  |  | -                'chapter',
 | 
	
		
			
				|  |  | -                'leaf_xmj_id',
 | 
	
		
			
				|  |  | -                'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'contract_expr',
 | 
	
		
			
				|  |  | -                'deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2',
 | 
	
		
			
				|  |  | -            ]);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async _calcPosBgl() {
 | 
	
	
		
			
				|  | @@ -430,40 +446,44 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStagePosData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            if (sid) {
 | 
	
		
			
				|  |  | -                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                if (sid) {
 | 
	
		
			
				|  |  | +                    await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, posFields.stage)) {
 | 
	
		
			
				|  |  | -                if (this.ctx.stage.readOnly) {
 | 
	
		
			
				|  |  | -                    const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
 | 
	
		
			
				|  |  | -                        this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
 | 
	
		
			
				|  |  | -                    this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | -                        {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
 | 
	
		
			
				|  |  | -                    ]);
 | 
	
		
			
				|  |  | -                } else {
 | 
	
		
			
				|  |  | -                    const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
 | 
	
		
			
				|  |  | +                const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, posFields.stage)) {
 | 
	
		
			
				|  |  | +                    if (this.ctx.stage.readOnly) {
 | 
	
		
			
				|  |  | +                        const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id,
 | 
	
		
			
				|  |  | +                            this.ctx.stage.id, this.ctx.stage.curTimes, this.ctx.stage.curOrder);
 | 
	
		
			
				|  |  | +                        this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | +                            {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
 | 
	
		
			
				|  |  | +                        ]);
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        const curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id);
 | 
	
		
			
				|  |  | +                        this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | +                            {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
 | 
	
		
			
				|  |  | +                        ]);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, posFields.stageEnd)) {
 | 
	
		
			
				|  |  | +                    const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
 | 
	
		
			
				|  |  |                      this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | -                        {data: curPosStage, fields: ['contract_qty', 'qc_qty', 'contract_expr', 'postil'], prefix: '', relaId: 'pid'}
 | 
	
		
			
				|  |  | +                        {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
 | 
	
		
			
				|  |  |                      ]);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, posFields.stageEnd)) {
 | 
	
		
			
				|  |  | -                const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
 | 
	
		
			
				|  |  | -                this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | -                    {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
 | 
	
		
			
				|  |  | -                ]);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            this.pos.loadDatas(posData);
 | 
	
		
			
				|  |  | -            this.pos.calculateAll();
 | 
	
		
			
				|  |  | +                this.pos.loadDatas(posData);
 | 
	
		
			
				|  |  | +                this.pos.calculateAll();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, posFields.bgl)) {
 | 
	
		
			
				|  |  | -                await this._calcPosBgl();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, posFields.bgl)) {
 | 
	
		
			
				|  |  | +                    await this._calcPosBgl();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            return this.pos.getDatas();
 | 
	
		
			
				|  |  | +                return this.pos.getDatas();
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          _getStageValidRole () {
 | 
	
	
		
			
				|  | @@ -492,193 +512,205 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStageBillsCompareData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            await this._getStageValidRole();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            const stage = this.ctx.stage, helper = this.ctx.helper;
 | 
	
		
			
				|  |  | -            const validRole = this.stageValidRole;
 | 
	
		
			
				|  |  | -            const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | -            const allStageBills = await this.ctx.service.stageBills.getAllDataByCondition({where: {sid: sid}});
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            const stageBillsIndex = {}, timesLen = 100;
 | 
	
		
			
				|  |  | -            for (const role of validRole) {
 | 
	
		
			
				|  |  | -                const stageBills = this.ctx.helper._.filter(allStageBills, function (x) {
 | 
	
		
			
				|  |  | -                    return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -                this.ctx.helper._.pullAll(allStageBills, stageBills);
 | 
	
		
			
				|  |  | -                for (const sb of stageBills) {
 | 
	
		
			
				|  |  | -                    const key = 'sb-' + sb.lid;
 | 
	
		
			
				|  |  | -                    const sbi = stageBillsIndex[key];
 | 
	
		
			
				|  |  | -                    if (sbi) {
 | 
	
		
			
				|  |  | -                        if ((sbi.times * timesLen + sbi.order) < (sb.times * timesLen + sb.order)) stageBillsIndex[key] = sb;
 | 
	
		
			
				|  |  | -                    } else {
 | 
	
		
			
				|  |  | -                        stageBillsIndex[key] = sb;
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                await this._getStageValidRole();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                const stage = this.ctx.stage, helper = this.ctx.helper;
 | 
	
		
			
				|  |  | +                const validRole = this.stageValidRole;
 | 
	
		
			
				|  |  | +                const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | +                const allStageBills = await this.ctx.service.stageBills.getAllDataByCondition({where: {sid: sid}});
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                const stageBillsIndex = {}, timesLen = 100;
 | 
	
		
			
				|  |  | +                for (const role of validRole) {
 | 
	
		
			
				|  |  | +                    const stageBills = this.ctx.helper._.filter(allStageBills, function (x) {
 | 
	
		
			
				|  |  | +                        return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  | +                    this.ctx.helper._.pullAll(allStageBills, stageBills);
 | 
	
		
			
				|  |  | +                    for (const sb of stageBills) {
 | 
	
		
			
				|  |  | +                        const key = 'sb-' + sb.lid;
 | 
	
		
			
				|  |  | +                        const sbi = stageBillsIndex[key];
 | 
	
		
			
				|  |  | +                        if (sbi) {
 | 
	
		
			
				|  |  | +                            if ((sbi.times * timesLen + sbi.order) < (sb.times * timesLen + sb.order)) stageBillsIndex[key] = sb;
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            stageBillsIndex[key] = sb;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                    const filterStageBills = [];
 | 
	
		
			
				|  |  | +                    for (const prop in stageBillsIndex) {
 | 
	
		
			
				|  |  | +                        filterStageBills.push(stageBillsIndex[prop]);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    this.ctx.helper.assignRelaData(billsData, [
 | 
	
		
			
				|  |  | +                        {data: filterStageBills, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'r' + role.flowOrder + '_', relaId: 'lid'}
 | 
	
		
			
				|  |  | +                    ]);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                const filterStageBills = [];
 | 
	
		
			
				|  |  | -                for (const prop in stageBillsIndex) {
 | 
	
		
			
				|  |  | -                    filterStageBills.push(stageBillsIndex[prop]);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                this.ctx.helper.assignRelaData(billsData, [
 | 
	
		
			
				|  |  | -                    {data: filterStageBills, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: 'r' + role.flowOrder + '_', relaId: 'lid'}
 | 
	
		
			
				|  |  | -                ]);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
 | 
	
		
			
				|  |  | -                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);
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, billsFields.stageEnd)) {
 | 
	
		
			
				|  |  | +                    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.setting.calcFields = ['deal_tp', 'total_price', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'];
 | 
	
		
			
				|  |  | -            for (const role of validRole) {
 | 
	
		
			
				|  |  | -                const prefix = 'r' + role.flowOrder + '_';
 | 
	
		
			
				|  |  | -                this.billsTree.setting.calcFields.push(prefix + 'contract_tp', prefix + 'qc_tp', prefix + 'gather_tp');
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +                this.billsTree.setting.calcFields = ['deal_tp', 'total_price', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'];
 | 
	
		
			
				|  |  | +                for (const role of validRole) {
 | 
	
		
			
				|  |  | +                    const prefix = 'r' + role.flowOrder + '_';
 | 
	
		
			
				|  |  | +                    this.billsTree.setting.calcFields.push(prefix + 'contract_tp', prefix + 'qc_tp', prefix + 'gather_tp');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            this.billsTree.calculateAll(function(node) {
 | 
	
		
			
				|  |  | -                let prefix = '';
 | 
	
		
			
				|  |  | -                if (node.children && node.children.length === 0) {
 | 
	
		
			
				|  |  | -                    node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
 | 
	
		
			
				|  |  | +                this.billsTree.calculateAll(function(node) {
 | 
	
		
			
				|  |  | +                    let prefix = '';
 | 
	
		
			
				|  |  | +                    if (node.children && node.children.length === 0) {
 | 
	
		
			
				|  |  | +                        node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty);
 | 
	
		
			
				|  |  | +                        for (const role of validRole) {
 | 
	
		
			
				|  |  | +                            prefix = 'r' + role.flowOrder + '_';
 | 
	
		
			
				|  |  | +                            node[prefix + 'gather_qty'] = helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
 | 
	
		
			
				|  |  |                      for (const role of validRole) {
 | 
	
		
			
				|  |  |                          prefix = 'r' + role.flowOrder + '_';
 | 
	
		
			
				|  |  | -                        node[prefix + 'gather_qty'] = helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
 | 
	
		
			
				|  |  | +                        node[prefix + 'gather_tp'] = helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
 | 
	
		
			
				|  |  | +                    this._calcLeafXmjRela();
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp);
 | 
	
		
			
				|  |  | -                for (const role of validRole) {
 | 
	
		
			
				|  |  | -                    prefix = 'r' + role.flowOrder + '_';
 | 
	
		
			
				|  |  | -                    node[prefix + 'gather_tp'] = helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, billsFields.leafXmj)) {
 | 
	
		
			
				|  |  | -                this._calcLeafXmjRela();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            return this.billsTree.getDefaultDatas();
 | 
	
		
			
				|  |  | -            // return this.billsTree.getDatas([
 | 
	
		
			
				|  |  | -            //     'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',                 //8
 | 
	
		
			
				|  |  | -            //     'code', 'b_code', 'name', 'unit', 'unit_price',                                                         //5
 | 
	
		
			
				|  |  | -            //     'deal_qty', 'deal_tp', 'quantity', 'total_price', 'dgn_qty1', 'dgn_qty2',                               //6
 | 
	
		
			
				|  |  | -            //     'drawing_code', 'memo', 'node_type', 'is_tp',                                                           //4
 | 
	
		
			
				|  |  | -            //     'r0_contract_qty', 'r0_contract_tp', 'r0_qc_qty', 'r0_qc_tp', 'r0_gather_qty', 'r0_gather_tp',          //6
 | 
	
		
			
				|  |  | -            //     'r1_contract_qty', 'r1_contract_tp', 'r1_qc_qty', 'r1_qc_tp', 'r1_gather_qty', 'r1_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r2_contract_qty', 'r2_contract_tp', 'r2_qc_qty', 'r2_qc_tp', 'r2_gather_qty', 'r2_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r3_contract_qty', 'r3_contract_tp', 'r3_qc_qty', 'r3_qc_tp', 'r3_gather_qty', 'r3_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r4_contract_qty', 'r4_contract_tp', 'r4_qc_qty', 'r4_qc_tp', 'r4_gather_qty', 'r4_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r5_contract_qty', 'r5_contract_tp', 'r5_qc_qty', 'r5_qc_tp', 'r5_gather_qty', 'r5_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r6_contract_qty', 'r6_contract_tp', 'r6_qc_qty', 'r6_qc_tp', 'r6_gather_qty', 'r6_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r7_contract_qty', 'r7_contract_tp', 'r7_qc_qty', 'r7_qc_tp', 'r7_gather_qty', 'r7_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r8_contract_qty', 'r8_contract_tp', 'r8_qc_qty', 'r8_qc_tp', 'r8_gather_qty', 'r8_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r9_contract_qty', 'r9_contract_tp', 'r9_qc_qty', 'r9_qc_tp', 'r9_gather_qty', 'r9_gather_tp',
 | 
	
		
			
				|  |  | -            //     'r10_contract_qty', 'r10_contract_tp', 'r10_qc_qty', 'r10_qc_tp', 'r10_gather_qty', 'r10_gather_tp',
 | 
	
		
			
				|  |  | -            //     'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
 | 
	
		
			
				|  |  | -            //     'chapter',                                                                                              //1
 | 
	
		
			
				|  |  | -            // ]);
 | 
	
		
			
				|  |  | +                return this.billsTree.getDefaultDatas();
 | 
	
		
			
				|  |  | +                // return this.billsTree.getDatas([
 | 
	
		
			
				|  |  | +                //     'id', 'tender_id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',                 //8
 | 
	
		
			
				|  |  | +                //     'code', 'b_code', 'name', 'unit', 'unit_price',                                                         //5
 | 
	
		
			
				|  |  | +                //     'deal_qty', 'deal_tp', 'quantity', 'total_price', 'dgn_qty1', 'dgn_qty2',                               //6
 | 
	
		
			
				|  |  | +                //     'drawing_code', 'memo', 'node_type', 'is_tp',                                                           //4
 | 
	
		
			
				|  |  | +                //     'r0_contract_qty', 'r0_contract_tp', 'r0_qc_qty', 'r0_qc_tp', 'r0_gather_qty', 'r0_gather_tp',          //6
 | 
	
		
			
				|  |  | +                //     'r1_contract_qty', 'r1_contract_tp', 'r1_qc_qty', 'r1_qc_tp', 'r1_gather_qty', 'r1_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r2_contract_qty', 'r2_contract_tp', 'r2_qc_qty', 'r2_qc_tp', 'r2_gather_qty', 'r2_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r3_contract_qty', 'r3_contract_tp', 'r3_qc_qty', 'r3_qc_tp', 'r3_gather_qty', 'r3_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r4_contract_qty', 'r4_contract_tp', 'r4_qc_qty', 'r4_qc_tp', 'r4_gather_qty', 'r4_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r5_contract_qty', 'r5_contract_tp', 'r5_qc_qty', 'r5_qc_tp', 'r5_gather_qty', 'r5_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r6_contract_qty', 'r6_contract_tp', 'r6_qc_qty', 'r6_qc_tp', 'r6_gather_qty', 'r6_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r7_contract_qty', 'r7_contract_tp', 'r7_qc_qty', 'r7_qc_tp', 'r7_gather_qty', 'r7_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r8_contract_qty', 'r8_contract_tp', 'r8_qc_qty', 'r8_qc_tp', 'r8_gather_qty', 'r8_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r9_contract_qty', 'r9_contract_tp', 'r9_qc_qty', 'r9_qc_tp', 'r9_gather_qty', 'r9_gather_tp',
 | 
	
		
			
				|  |  | +                //     'r10_contract_qty', 'r10_contract_tp', 'r10_qc_qty', 'r10_qc_tp', 'r10_gather_qty', 'r10_gather_tp',
 | 
	
		
			
				|  |  | +                //     'pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp',
 | 
	
		
			
				|  |  | +                //     'chapter',                                                                                              //1
 | 
	
		
			
				|  |  | +                // ]);
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStagePosCompareData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            await this._getStageValidRole();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            const stage = this.ctx.stage, helper = this.ctx.helper;
 | 
	
		
			
				|  |  | -            const validRole = this.stageValidRole;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            const allStagePos = await this.ctx.service.stagePos.getAllDataByCondition({where: {sid: sid}});
 | 
	
		
			
				|  |  | -            const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
 | 
	
		
			
				|  |  | -            const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
 | 
	
		
			
				|  |  | -            this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | -                {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
 | 
	
		
			
				|  |  | -            ]);
 | 
	
		
			
				|  |  | -            const stagePosIndex = {}, timesLen = 100;
 | 
	
		
			
				|  |  | -            for (const role of validRole) {
 | 
	
		
			
				|  |  | -                const stagePos = this.ctx.helper._.filter(allStagePos, function (x) {
 | 
	
		
			
				|  |  | -                    return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | -                this.ctx.helper._.pullAll(allStagePos, stagePos);
 | 
	
		
			
				|  |  | -                for (const sp of stagePos) {
 | 
	
		
			
				|  |  | -                    const key = 'sp-' + sp.pid;
 | 
	
		
			
				|  |  | -                    const spi = stagePosIndex[key];
 | 
	
		
			
				|  |  | -                    if (spi) {
 | 
	
		
			
				|  |  | -                        if ((spi.times * timesLen + spi.order) < (sp.times * timesLen + sp.order)) stagePosIndex[key] = sp;
 | 
	
		
			
				|  |  | -                    } else {
 | 
	
		
			
				|  |  | -                        stagePosIndex[key] = sp;
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                const filterStagePos = [];
 | 
	
		
			
				|  |  | -                for (const prop in stagePosIndex) {
 | 
	
		
			
				|  |  | -                    filterStagePos.push(stagePosIndex[prop]);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                await this._getStageValidRole();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                const stage = this.ctx.stage, helper = this.ctx.helper;
 | 
	
		
			
				|  |  | +                const validRole = this.stageValidRole;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                const allStagePos = await this.ctx.service.stagePos.getAllDataByCondition({where: {sid: sid}});
 | 
	
		
			
				|  |  | +                const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }});
 | 
	
		
			
				|  |  | +                const prePosStage = this.ctx.stage.order > 1 ? await this.ctx.service.stagePosFinal.getFinalData(this.ctx.tender, this.ctx.stage.order - 1) : [];
 | 
	
		
			
				|  |  |                  this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | -                    {data: filterStagePos, fields: ['contract_qty', 'qc_qty'], prefix: 'r' + role.flowOrder + '_', relaId: 'pid'}
 | 
	
		
			
				|  |  | +                    {data: prePosStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'}
 | 
	
		
			
				|  |  |                  ]);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            this.pos.loadDatas(posData);
 | 
	
		
			
				|  |  | -            this.pos.calculateAll(function (p) {
 | 
	
		
			
				|  |  | -                p.pre_gather_qty = helper.add(p.pre_contract_qty, p.pre_qc_qty);
 | 
	
		
			
				|  |  | +                const stagePosIndex = {}, timesLen = 100;
 | 
	
		
			
				|  |  |                  for (const role of validRole) {
 | 
	
		
			
				|  |  | -                    const prefix = 'r' + role.flowOrder + '_';
 | 
	
		
			
				|  |  | -                    p[prefix + 'gather_qty'] = helper.add(p[prefix + 'contract_qty'], p[prefix + 'qc_qty']);
 | 
	
		
			
				|  |  | +                    const stagePos = this.ctx.helper._.filter(allStagePos, function (x) {
 | 
	
		
			
				|  |  | +                        return x.times < stage.curTimes || (x.times === stage.curTimes && x.order <= role.dataOrder);
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  | +                    this.ctx.helper._.pullAll(allStagePos, stagePos);
 | 
	
		
			
				|  |  | +                    for (const sp of stagePos) {
 | 
	
		
			
				|  |  | +                        const key = 'sp-' + sp.pid;
 | 
	
		
			
				|  |  | +                        const spi = stagePosIndex[key];
 | 
	
		
			
				|  |  | +                        if (spi) {
 | 
	
		
			
				|  |  | +                            if ((spi.times * timesLen + spi.order) < (sp.times * timesLen + sp.order)) stagePosIndex[key] = sp;
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            stagePosIndex[key] = sp;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    const filterStagePos = [];
 | 
	
		
			
				|  |  | +                    for (const prop in stagePosIndex) {
 | 
	
		
			
				|  |  | +                        filterStagePos.push(stagePosIndex[prop]);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    this.ctx.helper.assignRelaData(posData, [
 | 
	
		
			
				|  |  | +                        {data: filterStagePos, fields: ['contract_qty', 'qc_qty'], prefix: 'r' + role.flowOrder + '_', relaId: 'pid'}
 | 
	
		
			
				|  |  | +                    ]);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                this.pos.loadDatas(posData);
 | 
	
		
			
				|  |  | +                this.pos.calculateAll(function (p) {
 | 
	
		
			
				|  |  | +                    p.pre_gather_qty = helper.add(p.pre_contract_qty, p.pre_qc_qty);
 | 
	
		
			
				|  |  | +                    for (const role of validRole) {
 | 
	
		
			
				|  |  | +                        const prefix = 'r' + role.flowOrder + '_';
 | 
	
		
			
				|  |  | +                        p[prefix + 'gather_qty'] = helper.add(p[prefix + 'contract_qty'], p[prefix + 'qc_qty']);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            });
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            return this.pos.getDatas();
 | 
	
		
			
				|  |  | +                return this.pos.getDatas();
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStagePayData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | -            const stage = this.ctx.stage;
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +                const stage = this.ctx.stage;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const dealPay = await this.ctx.service.stagePay.getStagePays(this.ctx.stage);
 | 
	
		
			
				|  |  | +                const dealPay = await this.ctx.service.stagePay.getStagePays(this.ctx.stage);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (!this.ctx.stage.readOnly) {
 | 
	
		
			
				|  |  | -                // 计算 本期金额
 | 
	
		
			
				|  |  | -                const PayCalculator = require('../lib/pay_calc');
 | 
	
		
			
				|  |  | -                const payCalculator = new PayCalculator(this.ctx, this.ctx.stage, this.ctx.tender.info);
 | 
	
		
			
				|  |  | -                await payCalculator.calculateAll(dealPay);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExist(fields, ['start_stage_order']) && this.ctx.stage.status !== audit.stage.status.checked) {
 | 
	
		
			
				|  |  | -                for (const dp of dealPay) {
 | 
	
		
			
				|  |  | -                    if (!dp.start_stage_order || dp.start_stage_order === this.ctx.stage.order) {
 | 
	
		
			
				|  |  | -                        dp.start_stage_order = this.ctx.helper.checkZero(dp.tp) ? null : this.ctx.stage.order;
 | 
	
		
			
				|  |  | +                if (!this.ctx.stage.readOnly) {
 | 
	
		
			
				|  |  | +                    // 计算 本期金额
 | 
	
		
			
				|  |  | +                    const PayCalculator = require('../lib/pay_calc');
 | 
	
		
			
				|  |  | +                    const payCalculator = new PayCalculator(this.ctx, this.ctx.stage, this.ctx.tender.info);
 | 
	
		
			
				|  |  | +                    await payCalculator.calculateAll(dealPay);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExist(fields, ['start_stage_order']) && this.ctx.stage.status !== audit.stage.status.checked) {
 | 
	
		
			
				|  |  | +                    for (const dp of dealPay) {
 | 
	
		
			
				|  |  | +                        if (!dp.start_stage_order || dp.start_stage_order === this.ctx.stage.order) {
 | 
	
		
			
				|  |  | +                            dp.start_stage_order = this.ctx.helper.checkZero(dp.tp) ? null : this.ctx.stage.order;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (this._checkFieldsExistReg(fields, 'r[0-9]+_tp')) {
 | 
	
		
			
				|  |  | -                this._getStageValidRole();
 | 
	
		
			
				|  |  | -                const allStagePays = await this.ctx.service.stagePay.getAllDataByCondition({
 | 
	
		
			
				|  |  | -                    where: {sid: stage.id, stimes: stage.curTimes}
 | 
	
		
			
				|  |  | -                });
 | 
	
		
			
				|  |  | +                if (this._checkFieldsExistReg(fields, 'r[0-9]+_tp')) {
 | 
	
		
			
				|  |  | +                    this._getStageValidRole();
 | 
	
		
			
				|  |  | +                    const allStagePays = await this.ctx.service.stagePay.getAllDataByCondition({
 | 
	
		
			
				|  |  | +                        where: {sid: stage.id, stimes: stage.curTimes}
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                for (const [i, role] of this.stageValidRole.entries()) {
 | 
	
		
			
				|  |  | -                    if (i < this.stageValidRole.length - 1) {
 | 
	
		
			
				|  |  | -                        const stagePays = this.ctx.helper._.filter(allStagePays, function (x) {
 | 
	
		
			
				|  |  | -                            return x.stimes === stage.curTimes && x.sorder === role.dataOrder;
 | 
	
		
			
				|  |  | -                        });
 | 
	
		
			
				|  |  | -                        this.ctx.helper._.pullAll(allStagePays, stagePays);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                        for (const sp of stagePays) {
 | 
	
		
			
				|  |  | -                            const dp = dealPay.find(function (x) {return x.pid === sp.pid});
 | 
	
		
			
				|  |  | -                            if (dp) {
 | 
	
		
			
				|  |  | -                                dp['r' + role.flowOrder + '_tp'] = sp.tp;
 | 
	
		
			
				|  |  | +                    for (const [i, role] of this.stageValidRole.entries()) {
 | 
	
		
			
				|  |  | +                        if (i < this.stageValidRole.length - 1) {
 | 
	
		
			
				|  |  | +                            const stagePays = this.ctx.helper._.filter(allStagePays, function (x) {
 | 
	
		
			
				|  |  | +                                return x.stimes === stage.curTimes && x.sorder === role.dataOrder;
 | 
	
		
			
				|  |  | +                            });
 | 
	
		
			
				|  |  | +                            this.ctx.helper._.pullAll(allStagePays, stagePays);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            for (const sp of stagePays) {
 | 
	
		
			
				|  |  | +                                const dp = dealPay.find(function (x) {return x.pid === sp.pid});
 | 
	
		
			
				|  |  | +                                if (dp) {
 | 
	
		
			
				|  |  | +                                    dp['r' + role.flowOrder + '_tp'] = sp.tp;
 | 
	
		
			
				|  |  | +                                }
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            for (const dp of dealPay) {
 | 
	
		
			
				|  |  | +                                dp['r' + role.flowOrder + '_tp'] = dp.tp;
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    } else {
 | 
	
		
			
				|  |  | -                        for (const dp of dealPay) {
 | 
	
		
			
				|  |  | -                            dp['r' + role.flowOrder + '_tp'] = dp.tp;
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                return dealPay;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            return dealPay;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          _getChangeConstName(define, value) {
 | 
	
	
		
			
				|  | @@ -755,58 +787,78 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getChangeData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            await this._generateChange(tid);
 | 
	
		
			
				|  |  | -            return this.changeData.change;
 | 
	
		
			
				|  |  | +                await this._generateChange(tid);
 | 
	
		
			
				|  |  | +                return this.changeData.change;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getChangeBillsData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            await this._generateChange(tid);
 | 
	
		
			
				|  |  | -            return this.changeData.bills;
 | 
	
		
			
				|  |  | +                await this._generateChange(tid);
 | 
	
		
			
				|  |  | +                return this.changeData.bills;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStageJgcl(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const data = await this.ctx.service.stageJgcl.getStageData(this.ctx.stage);
 | 
	
		
			
				|  |  | -            const preData = await this.ctx.service.stageJgcl.getPreStageData(this.ctx.stage.order);
 | 
	
		
			
				|  |  | -            for (const d of data) {
 | 
	
		
			
				|  |  | -                const pd = this.ctx.helper._.find(preData, {uuid: d.uuid});
 | 
	
		
			
				|  |  | -                if (pd) {
 | 
	
		
			
				|  |  | -                    d.pre_arrive_qty = pd.arrive_qty;
 | 
	
		
			
				|  |  | -                    d.pre_arrive_tp = pd.arrive_tp;
 | 
	
		
			
				|  |  | -                    d.pre_deduct_qty = pd.deduct_qty;
 | 
	
		
			
				|  |  | -                    d.pre_deduct_tp = pd.deduct_tp;
 | 
	
		
			
				|  |  | +                const data = await this.ctx.service.stageJgcl.getStageData(this.ctx.stage);
 | 
	
		
			
				|  |  | +                const preData = await this.ctx.service.stageJgcl.getPreStageData(this.ctx.stage.order);
 | 
	
		
			
				|  |  | +                for (const d of data) {
 | 
	
		
			
				|  |  | +                    const pd = this.ctx.helper._.find(preData, {uuid: d.uuid});
 | 
	
		
			
				|  |  | +                    if (pd) {
 | 
	
		
			
				|  |  | +                        d.pre_arrive_qty = pd.arrive_qty;
 | 
	
		
			
				|  |  | +                        d.pre_arrive_tp = pd.arrive_tp;
 | 
	
		
			
				|  |  | +                        d.pre_deduct_qty = pd.deduct_qty;
 | 
	
		
			
				|  |  | +                        d.pre_deduct_tp = pd.deduct_tp;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                return data;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            return data;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStageBonus(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const data = await this.ctx.service.stageBonus.getEndStageData(this.ctx.stage.order);
 | 
	
		
			
				|  |  | -            return data;
 | 
	
		
			
				|  |  | +                const data = await this.ctx.service.stageBonus.getEndStageData(this.ctx.stage.order);
 | 
	
		
			
				|  |  | +                return data;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getStageOther(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | -            await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +                await this.ctx.service.stage.checkStage(sid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const data = await this.ctx.service.stageOther.getStageData(this.ctx.stage);
 | 
	
		
			
				|  |  | -            const preData = await this.ctx.service.stageOther.getPreStageData(this.ctx.stage.order);
 | 
	
		
			
				|  |  | -            for (const d of data) {
 | 
	
		
			
				|  |  | -                const pd = this.ctx.helper._.find(preData, {uuid: d.uuid});
 | 
	
		
			
				|  |  | -                if (pd) {
 | 
	
		
			
				|  |  | -                    d.pre_tp = pd.tp;
 | 
	
		
			
				|  |  | +                const data = await this.ctx.service.stageOther.getStageData(this.ctx.stage);
 | 
	
		
			
				|  |  | +                const preData = await this.ctx.service.stageOther.getPreStageData(this.ctx.stage.order);
 | 
	
		
			
				|  |  | +                for (const d of data) {
 | 
	
		
			
				|  |  | +                    const pd = this.ctx.helper._.find(preData, {uuid: d.uuid});
 | 
	
		
			
				|  |  | +                    if (pd) {
 | 
	
		
			
				|  |  | +                        d.pre_tp = pd.tp;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | +                return data;
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            return data;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getMaterial(tender_id, material_order, memFieldKeys) {
 | 
	
	
		
			
				|  | @@ -861,58 +913,62 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getSumStageBillsData(tid, sid, fields) {
 | 
	
		
			
				|  |  | -            await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                await this.ctx.service.tender.checkTender(tid);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | -            const checkStageField = function (stageOrder) {
 | 
	
		
			
				|  |  | -                for (const f of fields) {
 | 
	
		
			
				|  |  | -                    if (f.indexOf('s' + stageOrder + '_') >= 0) {
 | 
	
		
			
				|  |  | -                        return true;
 | 
	
		
			
				|  |  | +                const billsData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
 | 
	
		
			
				|  |  | +                const checkStageField = function (stageOrder) {
 | 
	
		
			
				|  |  | +                    for (const f of fields) {
 | 
	
		
			
				|  |  | +                        if (f.indexOf('s' + stageOrder + '_') >= 0) {
 | 
	
		
			
				|  |  | +                            return true;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                    return false;
 | 
	
		
			
				|  |  | +                };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                const calcFields = ['deal_tp', 'total_price'], calcPrefix = [];
 | 
	
		
			
				|  |  | +                const stages = this.ctx.service.stage.getValidStages(this.ctx.tender.id);
 | 
	
		
			
				|  |  | +                for (const stage of stages) {
 | 
	
		
			
				|  |  | +                    if (!checkStageField(stage.order)) return;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    await this.ctx.service.stage.doCheckStage(stage);
 | 
	
		
			
				|  |  | +                    calcFields.push('s' + stage.order + '_contract_tp');
 | 
	
		
			
				|  |  | +                    calcFields.push('s' + stage.order + '_qc_tp');
 | 
	
		
			
				|  |  | +                    calcFields.push('s' + stage.order + '_gather_tp');
 | 
	
		
			
				|  |  | +                    calcFields.push('s' + stage.order + '_');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    const curStage = stage.readOnly
 | 
	
		
			
				|  |  | +                        ? await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id, stage.id, stage.curTimes, stage.curOrder)
 | 
	
		
			
				|  |  | +                        : await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, stage.id);
 | 
	
		
			
				|  |  | +                    this.ctx.helper.assignRelaData(billsData, [
 | 
	
		
			
				|  |  | +                        {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp'], prefix: 's' + stage.order + '_', relaId: 'lid'}
 | 
	
		
			
				|  |  | +                    ]);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                return false;
 | 
	
		
			
				|  |  | -            };
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            const calcFields = ['deal_tp', 'total_price'], calcPrefix = [];
 | 
	
		
			
				|  |  | -            const stages = this.ctx.service.stage.getValidStages(this.ctx.tender.id);
 | 
	
		
			
				|  |  | -            for (const stage of stages) {
 | 
	
		
			
				|  |  | -                if (!checkStageField(stage.order)) return;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                await this.ctx.service.stage.doCheckStage(stage);
 | 
	
		
			
				|  |  | -                calcFields.push('s' + stage.order + '_contract_tp');
 | 
	
		
			
				|  |  | -                calcFields.push('s' + stage.order + '_qc_tp');
 | 
	
		
			
				|  |  | -                calcFields.push('s' + stage.order + '_gather_tp');
 | 
	
		
			
				|  |  | -                calcFields.push('s' + stage.order + '_');
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                const curStage = stage.readOnly
 | 
	
		
			
				|  |  | -                    ? await this.ctx.service.stageBills.getAuditorStageData(this.ctx.tender.id, stage.id, stage.curTimes, stage.curOrder)
 | 
	
		
			
				|  |  | -                    : await this.ctx.service.stageBills.getLastestStageData(this.ctx.tender.id, stage.id);
 | 
	
		
			
				|  |  | -                this.ctx.helper.assignRelaData(billsData, [
 | 
	
		
			
				|  |  | -                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp'], prefix: 's' + stage.order + '_', relaId: 'lid'}
 | 
	
		
			
				|  |  | -                ]);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            const billsTree = new Ledger.billsTree(this.ctx, {
 | 
	
		
			
				|  |  | -                id: 'ledger_id',
 | 
	
		
			
				|  |  | -                pid: 'ledger_pid',
 | 
	
		
			
				|  |  | -                order: 'order',
 | 
	
		
			
				|  |  | -                level: 'level',
 | 
	
		
			
				|  |  | -                rootId: -1,
 | 
	
		
			
				|  |  | -                keys: ['id', 'tender_id', 'ledger_id'],
 | 
	
		
			
				|  |  | -                stageId: 'id',
 | 
	
		
			
				|  |  | -                calcFields: calcFields,
 | 
	
		
			
				|  |  | -                calc: function (node) {
 | 
	
		
			
				|  |  | -                    for (const prefix of calcPrefix) {
 | 
	
		
			
				|  |  | -                        if (node.children && node.children.length === 0) {
 | 
	
		
			
				|  |  | -                            node[prefix + 'gather_qty'] = self.ctx.helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
 | 
	
		
			
				|  |  | +                const billsTree = new Ledger.billsTree(this.ctx, {
 | 
	
		
			
				|  |  | +                    id: 'ledger_id',
 | 
	
		
			
				|  |  | +                    pid: 'ledger_pid',
 | 
	
		
			
				|  |  | +                    order: 'order',
 | 
	
		
			
				|  |  | +                    level: 'level',
 | 
	
		
			
				|  |  | +                    rootId: -1,
 | 
	
		
			
				|  |  | +                    keys: ['id', 'tender_id', 'ledger_id'],
 | 
	
		
			
				|  |  | +                    stageId: 'id',
 | 
	
		
			
				|  |  | +                    calcFields: calcFields,
 | 
	
		
			
				|  |  | +                    calc: function (node) {
 | 
	
		
			
				|  |  | +                        for (const prefix of calcPrefix) {
 | 
	
		
			
				|  |  | +                            if (node.children && node.children.length === 0) {
 | 
	
		
			
				|  |  | +                                node[prefix + 'gather_qty'] = self.ctx.helper.add(node[prefix + 'contract_qty'], node[prefix + 'qc_qty']);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                            node[prefix + 'gather_tp'] = self.ctx.helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        node[prefix + 'gather_tp'] = self.ctx.helper.add(node[prefix + 'contract_tp'], node[prefix + 'qc_tp']);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            });
 | 
	
		
			
				|  |  | -            billsTree.loadDatas(billsData);
 | 
	
		
			
				|  |  | -            billsTree.calculateAll();
 | 
	
		
			
				|  |  | -            return billsTree.getDefaultDatas();
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                billsTree.loadDatas(billsData);
 | 
	
		
			
				|  |  | +                billsTree.calculateAll();
 | 
	
		
			
				|  |  | +                return billsTree.getDefaultDatas();
 | 
	
		
			
				|  |  | +            } catch (err) {
 | 
	
		
			
				|  |  | +                return [];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 |