|  | @@ -684,12 +684,23 @@ module.exports = app => {
 | 
	
		
			
				|  |  |              const filter = 'cb.`code` = ' + this.db.escape(bills.b_code) + (pos ? ' And cb.`detail` = ' + this.db.escape(pos.name) : '');
 | 
	
		
			
				|  |  |              const sql = 'SELECT c.cid, c.code, c.name, c.w_code, c.p_code, c.peg, c.org_name, c.org_code, c.new_name, c.new_code,' +
 | 
	
		
			
				|  |  |                          '    c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
 | 
	
		
			
				|  |  | -                        '    cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail ' +
 | 
	
		
			
				|  |  | -                        '  FROM ?? As c ' +
 | 
	
		
			
				|  |  | -                        '  Left Join ?? As cb ' +
 | 
	
		
			
				|  |  | -                        '  On c.cid = cb.cid ' +
 | 
	
		
			
				|  |  | +                        '    cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail, ' +
 | 
	
		
			
				|  |  | +                        '    scb.used_amount' +
 | 
	
		
			
				|  |  | +                        '  FROM ' + this.tableName + ' As c ' +
 | 
	
		
			
				|  |  | +                        '  Left Join ' + this.ctx.service.changeAuditList.tableName +' As cb On c.cid = cb.cid ' +
 | 
	
		
			
				|  |  | +                        '  Left Join (' +
 | 
	
		
			
				|  |  | +                        '    SELECT SUM(sc.qty) As used_amount, sc.cbid' +
 | 
	
		
			
				|  |  | +                        '      FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
 | 
	
		
			
				|  |  | +                        '      INNER JOIN (SELECT Max(stimes) As `stimes`, Max(sorder) As `sorder`, cbid ' +
 | 
	
		
			
				|  |  | +                        '        FROM ' + this.ctx.service.stageChange.tableName +
 | 
	
		
			
				|  |  | +                        '        WHERE tid = ?' +
 | 
	
		
			
				|  |  | +                        '        GROUP BY cbid' +
 | 
	
		
			
				|  |  | +                        '      ) As MF' +
 | 
	
		
			
				|  |  | +                        '      ON sc.stimes = MF.stimes And sc.sorder = MF.sorder And sc.cbid = MF.cbid' +
 | 
	
		
			
				|  |  | +                        '    GROUP BY sc.cbid' +
 | 
	
		
			
				|  |  | +                        '  ) As scb ON cb.id = scb.cbid' +
 | 
	
		
			
				|  |  |                          '  WHERE c.tid = ? And c.status = ? And ' + filter;
 | 
	
		
			
				|  |  | -            const sqlParam = [this.tableName, this.ctx.service.changeAuditList.tableName, tid, audit.flow.status.checked];
 | 
	
		
			
				|  |  | +            const sqlParam = [tid, tid, audit.flow.status.checked];
 | 
	
		
			
				|  |  |              const changes = await this.db.query(sql, sqlParam);
 | 
	
		
			
				|  |  |              for (const c of changes) {
 | 
	
		
			
				|  |  |                  const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
 |