|  | @@ -18,6 +18,8 @@ class loadStageExcelTree {
 | 
												
													
														
															|  |          this.insertPos = [];
 |  |          this.insertPos = [];
 | 
												
													
														
															|  |          this.updateBills = [];
 |  |          this.updateBills = [];
 | 
												
													
														
															|  |          this.updatePos = [];
 |  |          this.updatePos = [];
 | 
												
													
														
															|  | 
 |  | +        this.insertDgn = [];
 | 
												
													
														
															|  | 
 |  | +        this.updateDgn = [];
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |      init(source) {
 |  |      init(source) {
 | 
												
													
														
															|  |          this.default = source.default;
 |  |          this.default = source.default;
 | 
												
											
												
													
														
															|  | @@ -32,6 +34,8 @@ class loadStageExcelTree {
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |          this.stageBills = source.stageBills;
 |  |          this.stageBills = source.stageBills;
 | 
												
													
														
															|  |          this.stagePos = source.stagePos;
 |  |          this.stagePos = source.stagePos;
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        this.stageBillsDgn = source.stageBillsDgn;
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |      findNode(node, parent) {
 |  |      findNode(node, parent) {
 | 
												
													
														
															|  |          const _ = this.ctx.helper._;
 |  |          const _ = this.ctx.helper._;
 | 
												
											
												
													
														
															|  | @@ -46,7 +50,7 @@ class loadStageExcelTree {
 | 
												
													
														
															|  |                      x.has_pos = !!relaPos && relaPos.length > 0;
 |  |                      x.has_pos = !!relaPos && relaPos.length > 0;
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  |                  return node.b_code === _.trimEnd(x.b_code) && node.name === _.trimEnd(x.name) && node.unit === _.trimEnd(x.unit)
 |  |                  return node.b_code === _.trimEnd(x.b_code) && node.name === _.trimEnd(x.name) && node.unit === _.trimEnd(x.unit)
 | 
												
													
														
															|  | -                    && node.unit_price === x.unit_price && node.has_pos === x.has_pos ;
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    && node.unit_price === x.unit_price && node.has_pos === x.has_pos;
 | 
												
													
														
															|  |              } else {
 |  |              } else {
 | 
												
													
														
															|  |                  return node.code === _.trimEnd(x.code) && node.name === _.trimEnd(x.name);
 |  |                  return node.code === _.trimEnd(x.code) && node.name === _.trimEnd(x.name);
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
											
												
													
														
															|  | @@ -96,6 +100,16 @@ class loadStageExcelTree {
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  | 
 |  | +    loadDgn(node, cur) {
 | 
												
													
														
															|  | 
 |  | +        if (!node.deal_dgn_qty1 && !node.deal_dgn_qty2 && !node.c_dgn_qty1 && !node.c_dgn_qty2) return;
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        const dgn = this.stageBillsDgn.find(x => { return x.id === cur.id; });
 | 
												
													
														
															|  | 
 |  | +        if (dgn) {
 | 
												
													
														
															|  | 
 |  | +            this.updateDgn.push({ id: cur.id, deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2, c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2 });
 | 
												
													
														
															|  | 
 |  | +        } else {
 | 
												
													
														
															|  | 
 |  | +            this.insertDgn.push({ id: cur.id, tid: this.default.tid, deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2, c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2 });
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +    }
 | 
												
													
														
															|  |      loadNode(node, parent) {
 |  |      loadNode(node, parent) {
 | 
												
													
														
															|  |          node.is_leaf = !node.children || node.children.length === 0 ? 1 : 0;
 |  |          node.is_leaf = !node.children || node.children.length === 0 ? 1 : 0;
 | 
												
													
														
															|  |          node.has_pos = node.pos && node.pos.length > 0;
 |  |          node.has_pos = node.pos && node.pos.length > 0;
 | 
												
											
												
													
														
															|  | @@ -103,6 +117,7 @@ class loadStageExcelTree {
 | 
												
													
														
															|  |          if (!cur) return;
 |  |          if (!cur) return;
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |          if (cur) {
 |  |          if (cur) {
 | 
												
													
														
															|  | 
 |  | +            if (!node.b_code) this.loadDgn(node, cur);
 | 
												
													
														
															|  |              if (node.is_leaf) {
 |  |              if (node.is_leaf) {
 | 
												
													
														
															|  |                  this.loadLeaf(node, cur);
 |  |                  this.loadLeaf(node, cur);
 | 
												
													
														
															|  |              } else {
 |  |              } else {
 | 
												
											
												
													
														
															|  | @@ -316,9 +331,10 @@ module.exports = app => {
 | 
												
													
														
															|  |                  });
 |  |                  });
 | 
												
													
														
															|  |                  const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id }});
 |  |                  const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id }});
 | 
												
													
														
															|  |                  const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id }});
 |  |                  const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id }});
 | 
												
													
														
															|  | 
 |  | +                const stageBillsDgn = await this.ctx.service.stageBillsDgn.getAllDataByCondition({ where: { tid: stage.tid } });
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |                  const loadModal = new loadStageExcelTree(this.ctx);
 |  |                  const loadModal = new loadStageExcelTree(this.ctx);
 | 
												
													
														
															|  | -                loadModal.load(cacheTree, {ledgerData, posData, stageBills, stagePos, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
 |  | 
 | 
												
													
														
															|  | 
 |  | +                loadModal.load(cacheTree, {ledgerData, posData, stageBills, stagePos, stageBillsDgn, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } });
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |                  const conn = await this.db.beginTransaction();
 |  |                  const conn = await this.db.beginTransaction();
 | 
												
													
														
															|  |                  try {
 |  |                  try {
 | 
												
											
												
													
														
															|  | @@ -326,6 +342,8 @@ module.exports = app => {
 | 
												
													
														
															|  |                      if (loadModal.updateBills.length > 0) conn.updateRows(this.ctx.service.stageBills.tableName, loadModal.updateBills);
 |  |                      if (loadModal.updateBills.length > 0) conn.updateRows(this.ctx.service.stageBills.tableName, loadModal.updateBills);
 | 
												
													
														
															|  |                      if (loadModal.insertPos.length > 0) conn.insert(this.ctx.service.stagePos.tableName, loadModal.insertPos);
 |  |                      if (loadModal.insertPos.length > 0) conn.insert(this.ctx.service.stagePos.tableName, loadModal.insertPos);
 | 
												
													
														
															|  |                      if (loadModal.updatePos.length > 0) conn.updateRows(this.ctx.service.stagePos.tableName, loadModal.updatePos);
 |  |                      if (loadModal.updatePos.length > 0) conn.updateRows(this.ctx.service.stagePos.tableName, loadModal.updatePos);
 | 
												
													
														
															|  | 
 |  | +                    if (loadModal.insertDgn.length > 0) conn.insert(this.ctx.service.stageBillsDgn.tableName, loadModal.insertDgn);
 | 
												
													
														
															|  | 
 |  | +                    if (loadModal.updateDgn.length > 0) conn.updateRows(this.ctx.service.stageBillsDgn.tableName, loadModal.updateDgn);
 | 
												
													
														
															|  |                      await conn.commit();
 |  |                      await conn.commit();
 | 
												
													
														
															|  |                  } catch (err) {
 |  |                  } catch (err) {
 | 
												
													
														
															|  |                      await conn.rollback();
 |  |                      await conn.rollback();
 |