|  | @@ -59,7 +59,15 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  await this.ctx.service.changeAuditList.deleteDataByRevise(transaction, tid, [data.lid], 'gcl_id', '');
 | 
	
		
			
				|  |  |                  await transaction.insert(this.tableName, data);
 | 
	
		
			
				|  |  |                  await transaction.commit();
 | 
	
		
			
				|  |  | -                return { pos: data };
 | 
	
		
			
				|  |  | +                const returnData = { pos: data };
 | 
	
		
			
				|  |  | +                const bills = await this.ctx.service.ledger.getDataById(data.lid);
 | 
	
		
			
				|  |  | +                if (bills) {
 | 
	
		
			
				|  |  | +                    bills.cid = 1;
 | 
	
		
			
				|  |  | +                    returnData.ledger = {
 | 
	
		
			
				|  |  | +                        update: [bills],
 | 
	
		
			
				|  |  | +                    };
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                return returnData;
 | 
	
		
			
				|  |  |              } catch (err) {
 | 
	
		
			
				|  |  |                  await transaction.rollback();
 | 
	
		
			
				|  |  |                  throw err;
 | 
	
	
		
			
				|  | @@ -231,16 +239,21 @@ module.exports = app => {
 | 
	
		
			
				|  |  |              let bills = await this.ctx.service.changeLedger.getDataById(pos[0].lid);
 | 
	
		
			
				|  |  |              let newBills = false;
 | 
	
		
			
				|  |  |              let billsPos = await this.getAllDataByCondition({ where: { tid: tid, lid: pos[0].lid } });
 | 
	
		
			
				|  |  | +            let cid = 1;
 | 
	
		
			
				|  |  |              if (bills) {
 | 
	
		
			
				|  |  |                  newBills = true;
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
 | 
	
		
			
				|  |  |                  const posData = await this.ctx.service.pos.getAllDataByCondition({ where: { tid: tid, lid: pos[0].lid } });
 | 
	
		
			
				|  |  | +                if (billsPos.length === data.length) {
 | 
	
		
			
				|  |  | +                    cid = null;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |                  billsPos = this._.concat(posData, billsPos);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              // const bills = await this.ctx.service.reviseBills.getDataById(pos[0].lid);
 | 
	
		
			
				|  |  |              // const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
 | 
	
		
			
				|  |  |              const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
 | 
	
		
			
				|  |  | +            updateBills.cid = cid;
 | 
	
		
			
				|  |  |              for (const bp of billsPos) {
 | 
	
		
			
				|  |  |                  if (data.indexOf(bp.id) >= 0) continue;
 | 
	
		
			
				|  |  |                  updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
 | 
	
	
		
			
				|  | @@ -340,6 +353,7 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                      if (d.id) {
 | 
	
		
			
				|  |  |                          await transaction.update(this.tableName, d);
 | 
	
		
			
				|  |  |                      } else {
 | 
	
		
			
				|  |  | +                        updateBills.cid = 1;
 | 
	
		
			
				|  |  |                          await this._insertPosData(transaction, d, tid, cid);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -359,7 +373,7 @@ module.exports = app => {
 | 
	
		
			
				|  |  |                  throw err;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              result.pos = data;
 | 
	
		
			
				|  |  | -            result.ledger.update = needUpdateBills ? [updateBills] : [];
 | 
	
		
			
				|  |  | +            result.ledger.update = needUpdateBills ? [updateBills] : updateBills.cid && updateBills.cid === 1 ? [{ id: bills.id, ledger_id: bills.ledger_id, cid: 1 }] : [];
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 |