|  | @@ -23,17 +23,20 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getPosData(condition) {
 | 
	
		
			
				|  |  | +            return await this.db.select(this.tableName, {
 | 
	
		
			
				|  |  | +                where: condition,
 | 
	
		
			
				|  |  | +                columns: ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'in_time', 'porder', 'add_stage'],
 | 
	
		
			
				|  |  | +                order: [['porder', 'ASC']],
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        async getPosDataWithAddStageOrder(condition) {
 | 
	
		
			
				|  |  |              const sql = 'SELECT p.id, p.tid, p.lid, p.name, p.quantity, p.drawing_code, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.porder, p.add_stage, p.add_times, p.add_user, s.order As add_stage_order ' +
 | 
	
		
			
				|  |  |                  '  FROM ' + this.tableName + ' p ' +
 | 
	
		
			
				|  |  |                  '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s' +
 | 
	
		
			
				|  |  | -                '  ON add_stage = s.id'
 | 
	
		
			
				|  |  | +                '  ON p.add_stage = s.id'
 | 
	
		
			
				|  |  |                  + this.ctx.helper.whereSql(condition, 'p');
 | 
	
		
			
				|  |  |              return await this.db.query(sql);
 | 
	
		
			
				|  |  | -            // return await this.db.select(this.tableName, {
 | 
	
		
			
				|  |  | -            //     where: condition,
 | 
	
		
			
				|  |  | -            //     columns: ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'in_time', 'porder', 'add_stage'],
 | 
	
		
			
				|  |  | -            //     order: [['porder', 'ASC']],
 | 
	
		
			
				|  |  | -            // });
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getPosDataByIds(ids) {
 | 
	
	
		
			
				|  | @@ -56,7 +59,6 @@ module.exports = app => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          async getPosDataByUnits(tenderId, units) {
 | 
	
		
			
				|  |  | -            console.log(units);
 | 
	
		
			
				|  |  |              const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
 | 
	
		
			
				|  |  |                  '  FROM ' + this.tableName + ' p' +
 | 
	
		
			
				|  |  |                  '  LEFT JOIN ' + this.ctx.service.ledger.tableName + ' b' +
 | 
	
	
		
			
				|  | @@ -93,7 +95,6 @@ module.exports = app => {
 | 
	
		
			
				|  |  |              const transaction = await this.db.beginTransaction();
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  |                  if (data.updateType === 'add') {
 | 
	
		
			
				|  |  | -                    const tender = await this.ctx.service.tender.getTender(tid);
 | 
	
		
			
				|  |  |                      if (data.updateData instanceof Array) {
 | 
	
		
			
				|  |  |                          for (const d of data.updateData) {
 | 
	
		
			
				|  |  |                              this._insertPosData(transaction, d, tid);
 | 
	
	
		
			
				|  | @@ -104,7 +105,11 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  } else if (data.updateType === 'update') {
 | 
	
		
			
				|  |  |                      const datas = data.updateData instanceof Array ? data.updateData : [data.updateData];
 | 
	
		
			
				|  |  |                      result.ledger.update = [];
 | 
	
		
			
				|  |  | -                    const orgPos = await this.getPosData({tid: tid, id: this._.map(datas, 'id')});
 | 
	
		
			
				|  |  | +                    const orgPos = await this.getAllDataByCondition({
 | 
	
		
			
				|  |  | +                        where: {tid: tid, id: this._.map(datas, 'id')},
 | 
	
		
			
				|  |  | +                        columns: ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'in_time', 'porder', 'add_stage'],
 | 
	
		
			
				|  |  | +                        order: [['porder', 'ASC']],
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  |                      for (const d of datas) {
 | 
	
		
			
				|  |  |                          const op = this._.find(orgPos, function (p) { return p.id = d.id; });
 | 
	
		
			
				|  |  |                          if (d.sgfh_qty !== undefined || d.qtcl_qty !== undefined || d.sjcl_qty !== undefined) {
 |