| 
					
				 | 
			
			
				@@ -29,6 +29,7 @@ const billsFields = (function () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const pre = ['pre_contract_qty', 'pre_contract_tp', 'pre_qc_qty', 'pre_qc_tp', 'pre_gather_qty', 'pre_gather_tp']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const end = ['end_contract_qty', 'end_contract_tp', 'end_qc_qty', 'end_qc_tp', 'end_gather_qty', 'end_gather_tp']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const final = ['final_tp', 'final_ratio']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const final1 = ['minus_qc_qty', 'pre_minus_qc_qty', 'end_minus_qc_qty', 'final_1_qty', 'final_1_tp', 'final_1_ratio']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const stageDgn = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const stage = cur.concat(pre, end, final); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -36,19 +37,20 @@ const billsFields = (function () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const bgl = ['qc_bgl_code']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const leafXmj = ['leaf_xmj_id']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return {cur, pre, end, final, stageDgn, stage, stageEnd, bgl, leafXmj}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return {cur, pre, end, final, final1, stageDgn, stage, stageEnd, bgl, leafXmj}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 })(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const posFields = (function () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const cur = ['contract_qty', 'qc_qty', 'gather_qty', 'postil']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const pre = ['pre_contract_qty', 'pre_qc_qty', 'pre_gather_qty']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const end = ['end_contract_qty', 'end_qc_qty', 'end_gather_qty']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const final = ['final_ratio']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const final1 = ['minus_qc_qty', 'pre_minus_qc_qty', 'end_minus_qc_qty', 'final_1_qty', 'final_1_ratio']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const stage = cur.concat(pre, end, final); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const stageEnd = pre.concat(end, final); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     const bgl = ['qc_bgl_code']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return {cur, pre, end, final, stage, stageEnd, bgl}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return {cur, pre, end, final, final1, stage, stageEnd, bgl}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 })(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 module.exports = app => { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -71,10 +73,20 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 updateFields: ['contract_qty', 'qc_qty', 'postil'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 calc: function (p) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     p.pre_gather_qty = ctx.helper.add(p.pre_contract_qty, p.pre_qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     p.gather_qty = ctx.helper.add(p.contract_qty, p.qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     p.end_contract_qty = self.ctx.helper.add(p.pre_contract_qty, p.contract_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     p.end_qc_qty = self.ctx.helper.add(p.pre_qc_qty, p.qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     p.end_gather_qty = self.ctx.helper.add(p.pre_gather_qty, p.gather_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    p.final_qty = ctx.helper.add(p.end_qc_qty, p.quantity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    p.final_ratio = ctx.helper.mul(ctx.helper.div(p.end_gather_qty, p.final_qty, 4), 100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    p.end_minus_qc_qty = ctx.helper.add(p.pre_minus_qc_qty, p.minus_qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    p.final_1_qty = ctx.helper.add(p.end_minus_qc_qty, p.quantity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    p.end_final_1_qty = ctx.helper.add(p.final_1_qty, p.end_qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    p.final_1_ratio = ctx.helper.mul(ctx.helper.div(p.end_gather_qty, p.end_final_1_qty, 4), 100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 需要缓存的数据 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -94,14 +106,17 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 rootId: -1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 keys: ['id', 'tender_id', 'ledger_id'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 stageId: 'id', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                calcFields: calcFields || ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                calc: function (node, helper) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                calcFields: calcFields || ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'final_1_tp'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                calc: function (node, helper, decimal) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     if (node.children && node.children.length === 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         node.pre_gather_qty = helper.add(node.pre_contract_qty, node.pre_qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         node.gather_qty = helper.add(node.contract_qty, node.qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         node.end_contract_qty = helper.add(node.pre_contract_qty, node.contract_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         node.end_qc_qty = helper.add(node.pre_qc_qty, node.qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         node.end_gather_qty = helper.add(node.pre_gather_qty, node.gather_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        node.end_minus_qc_qty = helper.add(node.pre_minus_qc_qty, node.minus_qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        node.final_1_qty = helper.add(node.quantity, node.end_minus_qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        node.end_final_1_qty = helper.add(node.final_1_qty, node.end_qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     node.pre_gather_tp = helper.add(node.pre_contract_tp, node.pre_qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     node.gather_tp = helper.add(node.contract_tp, node.qc_tp); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -111,6 +126,10 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     node.final_tp = helper.add(node.total_price, node.end_qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     node.final_ratio = helper.mul(helper.div(node.end_gather_tp, node.final_tp, 4), 100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    node.final_1_tp = helper.mul(node.unit_price, node.final_1_qty, decimal.tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    node.end_final_1_tp = helper.add(node.final_1_tp, node.end_qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    node.final_1_ratio = helper.mul(helper.div(node.end_gather_tp, node.end_final_1_tp, 4), 100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -373,24 +392,29 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         this.ctx.helper._.assignIn(l, d); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let preStage = [], curStage = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (this._checkFieldsExist(fields, billsFields.stage)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     if (this.ctx.stage.readOnly) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        const curStage = await this.ctx.service.stageBills.getAuditorStageData2(this.ctx.tender.id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        curStage = await this.ctx.service.stageBills.getAuditorStageData2(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.getLastestStageData2(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'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        curStage = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 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'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    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.final1)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const preMinusChange = await this.ctx.service.stageChangeFinal.getPreMinusChange(this.ctx.stage.tid, this.ctx.stage.order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const changeData = await this._getStageChangeData(this.ctx); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const minusChange = changeData.filter(x => { return x.minus }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    this.ctx.helper.assignSumRelaData(billsData, 'id', [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'lid'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'lid'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -443,24 +467,29 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 const posData = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: this.ctx.tender.id }}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let curPosStage = [], prePosStage = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (this._checkFieldsExist(fields, posFields.stage)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     if (this.ctx.stage.readOnly) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        const curPosStage = await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        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'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        curPosStage = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 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'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    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.final1)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const preMinusChange = await this.ctx.service.stageChangeFinal.getPreMinusChange(this.ctx.stage.tid, this.ctx.stage.order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const changeData = await this._getStageChangeData(this.ctx); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const minusChange = changeData.filter(x => { return x.minus }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    this.ctx.helper.assignSumRelaData(posData, 'id', [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        {data: preMinusChange, fields: [{source: 'qty', target: 'pre_minus_qc_qty'}], relaField: 'pid'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        {data: minusChange, fields: [{source: 'qty', target: 'minus_qc_qty'}], relaField: 'pid'}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 this.pos.loadDatas(posData); 
			 |