|  | @@ -395,23 +395,32 @@ module.exports = app => {
 | 
	
		
			
				|  |  |              return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid']);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        async getQualityTotalPrice(sid) {
 | 
	
		
			
				|  |  | +        async _getTender(stage) {
 | 
	
		
			
				|  |  | +            if (this.ctx.tender) return this.ctx.tender;
 | 
	
		
			
				|  |  | +            const tender = { id: stage.tid };
 | 
	
		
			
				|  |  | +            tender.data = await this.ctx.service.tender.getTender(stage.tid);
 | 
	
		
			
				|  |  | +            tender.info = await this.service.tenderInfo.getTenderInfo(tender.id);
 | 
	
		
			
				|  |  | +            return tender;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        async getQualityTotalPrice(stage) {
 | 
	
		
			
				|  |  |              const helper = this.ctx.helper;
 | 
	
		
			
				|  |  | +            const tender = await this._getTender(stage);
 | 
	
		
			
				|  |  |              const sql = 'SELECT sc.*, c.quality FROM ' + this.tableName + ' sc' +
 | 
	
		
			
				|  |  |                  '  LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON sc.cid = c.cid' +
 | 
	
		
			
				|  |  |                  '  WHERE sid = ?';
 | 
	
		
			
				|  |  | -            const data = await this.db.query(sql, [sid]);
 | 
	
		
			
				|  |  | +            const data = await this.db.query(sql, [stage.id]);
 | 
	
		
			
				|  |  |              const bqData = [];
 | 
	
		
			
				|  |  |              for (const d of data) {
 | 
	
		
			
				|  |  |                  if (!d.qty) continue;
 | 
	
		
			
				|  |  |                  let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
 | 
	
		
			
				|  |  |                  if (!bd) {
 | 
	
		
			
				|  |  | -                    const bills = await this.ctx.service.ledger.getDataById(d.lid);
 | 
	
		
			
				|  |  | +                    const bills = await this.db.get(this.ctx.service.ledger.departTableName(tender.id), { id: d.lid });
 | 
	
		
			
				|  |  |                      if (!bills) continue;
 | 
	
		
			
				|  |  |                      bd = { lid: d.lid, quality: d.quality, unit_price: bills.unit_price };
 | 
	
		
			
				|  |  |                      bqData.push(bd);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                const tp = this.ctx.helper.mul(d.qty, bd.unit_price, this.ctx.tender.info.decimal.tp);
 | 
	
		
			
				|  |  | +                const tp = this.ctx.helper.mul(d.qty, bd.unit_price, tender.info.decimal.tp);
 | 
	
		
			
				|  |  |                  bd.tp = this.ctx.helper.add(bd.tp, tp);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              const result = {};
 |