| 
					
				 | 
			
			
				@@ -88,7 +88,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        async _filterLastestData(stagePos) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        _filterLastestData(stagePos) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const stagePosIndex = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (const sp of stagePos) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 const key = 'sp-' + sp.pid; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -545,20 +545,28 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @returns {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getStagesData(tid, stage_id_list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            let stage_id_listSql = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            stage_id_list = stage_id_list.indexOf(',') !== -1 ? stage_id_list.split(',') : stage_id_list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (stage_id_list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (stage_id_list instanceof Array) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    stage_id_listSql = stage_id_list.length > 0 ? ' And sid in (' + this.ctx.helper.getInArrStrSqlFilter(stage_id_list) + ')' : ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    stage_id_listSql = ' And sid in (' + this.db.escape(stage_id_list) + ')'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const sids = stage_id_list.split(','); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const result = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const sid of sids) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`, `contract_expr`' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '  FROM ' + this.tableName + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    '  WHERE tid = ? And sid = ? '; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const sqlParam = [tid, sid]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const stagePos = await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const stagePosFilter = this._filterLastestData(stagePos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (const sp of stagePosFilter) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const rsp = result.find(function (x) { return x.pid === sp.pid}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (rsp) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        rsp.contract_qty = this.ctx.helper.add(rsp.contract_qty, sp.contract_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        rsp.qc_qty = this.ctx.helper.add(rsp.qc_qty, sp.qc_qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result.push({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            id: sp.id, tid: sp.tid, lid: sp.lid, pid: sp.pid, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            contract_qty: sp.contract_qty, qc_qty: sp.qc_qty, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const sql = 'SELECT `id`, `tid`, `sid`, `pid`, `lid`, SUM(`contract_qty`) as `contract_qty`, SUM(`qc_qty`) as `qc_qty`' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ' FROM ' + this.tableName + ' WHERE `tid` = ? ' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                stage_id_listSql + 'GROUP BY `pid`'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const sqlParam = [tid]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const result = await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |