|
@@ -448,7 +448,6 @@ module.exports = app => {
|
|
|
tid,
|
|
|
};
|
|
|
delData[column] = d.id;
|
|
|
- console.log(delData);
|
|
|
await transaction.delete(this.tableName, delData);
|
|
|
} else {
|
|
|
const options = {
|
|
@@ -493,7 +492,6 @@ module.exports = app => {
|
|
|
// 再找出上一个项目节节点并更新
|
|
|
this.newBills = false;
|
|
|
const parents = await this.ctx.service.changeLedger.getDataByKid(tid, select.ledger_pid);
|
|
|
- console.log('hello :', parents);
|
|
|
d.xmj_code = parents.code;
|
|
|
d.xmj_jldy = parents.name;
|
|
|
}
|
|
@@ -727,6 +725,137 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async updateToLedger(transaction, tid, cid) {
|
|
|
+ // 找出本条变更属于新增部位的数据
|
|
|
+ const sql = 'SELECT a.* FROM ?? a LEFT JOIN ?? b ON a.id = b.gcl_id WHERE b.tid = ? AND b.cid = ? GROUP BY a.id';
|
|
|
+ const sqlParam = [this.ctx.service.changeLedger.tableName, this.tableName, tid, cid];
|
|
|
+ const result = await transaction.query(sql, sqlParam);
|
|
|
+ const sql2 = 'SELECT a.* FROM ?? a LEFT JOIN ?? b ON a.id = b.mx_id WHERE b.tid = ? AND b.cid = ?';
|
|
|
+ const sqlParam2 = [this.ctx.service.changePos.tableName, this.tableName, tid, cid];
|
|
|
+ const result2 = await transaction.query(sql2, sqlParam2);
|
|
|
+ if (result.length > 0 || result2.length > 0) {
|
|
|
+ const changeLedgerGclIdList = this._.map(result, 'id');
|
|
|
+ const changeLedgerIdList = this._.uniq(this._.map(result, 'ledger_pid'));// 父节点集合
|
|
|
+ const needUpdateLedgerList = [];// 找出需要更新的原台账清单的id
|
|
|
+ const needUpdateChangeLedgerList = [];// 找出需要更新的新台账清单的id
|
|
|
+ const tpDecimal = this.ctx.tender.info.decimal.tp;
|
|
|
+ // 要更新的ledger节点,数量及总数
|
|
|
+ for (const data of result2) {
|
|
|
+ if (this._.indexOf(changeLedgerGclIdList, data.lid) === -1) {
|
|
|
+ const info = this._.find(needUpdateLedgerList, { id: data.lid });
|
|
|
+ if (info) {
|
|
|
+ info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
|
|
|
+ } else {
|
|
|
+ needUpdateLedgerList.push({ id: data.lid, quantity: data.quantity });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const info = this._.find(needUpdateChangeLedgerList, { id: data.lid });
|
|
|
+ if (info) {
|
|
|
+ info.quantity = this.ctx.helper.add(info.quantity, data.quantity);
|
|
|
+ } else {
|
|
|
+ needUpdateChangeLedgerList.push({ id: data.lid, quantity: data.quantity });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 更新到result上
|
|
|
+ if (needUpdateChangeLedgerList.length > 0) {
|
|
|
+ for (const nucl of needUpdateChangeLedgerList) {
|
|
|
+ const now = this._.find(result, { id: nucl.id });
|
|
|
+ now.quantity = nucl.quantity;
|
|
|
+ now.sgfh_qty = nucl.quantity;
|
|
|
+ now.sgfh_tp = this.ctx.helper.mul(now.sgfh_qty, now.unit_price, tpDecimal);
|
|
|
+ now.total_price = this.ctx.helper.mul(now.quantity, now.unit_price, tpDecimal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 更新到ledger上
|
|
|
+ if (needUpdateLedgerList.length > 0) {
|
|
|
+ for (const nul of needUpdateLedgerList) {
|
|
|
+ const ledgerInfo = await this.ctx.service.ledger.getDataById(nul.id);
|
|
|
+ ledgerInfo.quantity = this.ctx.helper.add(ledgerInfo.quantity, nul.quantity);
|
|
|
+ ledgerInfo.sgfh_qty = this.ctx.helper.add(ledgerInfo.sgfh_qty, nul.quantity);
|
|
|
+ ledgerInfo.sgfh_tp = this.ctx.helper.mul(ledgerInfo.sgfh_qty, ledgerInfo.unit_price, tpDecimal);
|
|
|
+ ledgerInfo.total_price = this.ctx.helper.mul(ledgerInfo.quantity, ledgerInfo.unit_price, tpDecimal);
|
|
|
+ await transaction.update(this.ctx.service.ledger.tableName, ledgerInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 找出所有新增的父节点并插入到result中
|
|
|
+ for (const r of changeLedgerIdList) {
|
|
|
+ await this._findParents(transaction, tid, r, result);
|
|
|
+ }
|
|
|
+ // 插入到计量单元表,并删除变更的计量单元数据, 插入清单表,并删除变更的清单表
|
|
|
+ await this._insertByChangeRevise(transaction, tid, result, result2);
|
|
|
+ // 更新标段总金额
|
|
|
+ const sumSql = 'SELECT Sum(total_price) As total_price, Sum(deal_tp) As deal_tp' +
|
|
|
+ ' FROM ' + this.ctx.service.ledger.tableName + this.ctx.helper.whereSql({ tender_id: tid });
|
|
|
+ const sum = await transaction.queryOne(sumSql);
|
|
|
+ await transaction.update(this.ctx.service.tender.tableName, {
|
|
|
+ id: tid,
|
|
|
+ total_price: sum.total_price,
|
|
|
+ deal_tp: sum.deal_tp,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _findParents(transaction, tid, id, result) {
|
|
|
+ const info = await transaction.get(this.ctx.service.changeLedger.tableName, { tender_id: tid, ledger_id: id });
|
|
|
+ if (info && this._.findIndex(result, { ledger_id: info.id }) === -1) {
|
|
|
+ result.push(info);
|
|
|
+ await this._findParents(transaction, tid, info.ledger_pid, result);
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _insertByChangeRevise(transaction, tid, ledgerList, posList) {
|
|
|
+ if (ledgerList.length > 0) {
|
|
|
+ const insertLedgerArr = [];
|
|
|
+ for (const l of ledgerList) {
|
|
|
+ const insertL = [
|
|
|
+ l.id, l.code, l.b_code, l.name, l.unit, l.source, l.remark, l.ledger_id,
|
|
|
+ l.ledger_pid, l.level, l.order, l.full_path, l.is_leaf, l.quantity, l.total_price,
|
|
|
+ l.unit_price, l.drawing_code, l.memo, l.dgn_qty1, l.dgn_qty2, l.deal_qty, l.deal_tp,
|
|
|
+ l.sgfh_qty, l.sgfh_tp, l.sjcl_qty, l.sjcl_tp, l.qtcl_qty, l.qtcl_tp, l.node_type, l.crid,
|
|
|
+ l.tender_id, l.is_tp, l.sgfh_expr, l.sjcl_expr, l.qtcl_expr, l.check_calc, l.gxby_status,
|
|
|
+ l.dagl_status, l.dagl_url, l.gxby_limit, l.dagl_limit, l.ex_memo1, l.ex_memo2, l.ex_memo3,
|
|
|
+ ];
|
|
|
+ insertLedgerArr.push('(' + this.ctx.helper.getInArrStrSqlFilter(insertL) + ')');
|
|
|
+ await transaction.delete(this.ctx.service.changeLedger.tableName, { id: l.id });
|
|
|
+ }
|
|
|
+ const bSql = 'Insert Into ' +
|
|
|
+ this.ctx.service.ledger.tableName +
|
|
|
+ ' (id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
|
|
|
+ ' quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
|
|
|
+ ' sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
|
|
|
+ ' sgfh_expr, sjcl_expr, qtcl_expr, check_calc,' +
|
|
|
+ ' gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit,' +
|
|
|
+ ' ex_memo1, ex_memo2, ex_memo3) VALUES ' + insertLedgerArr.join(',') + ';';
|
|
|
+ await transaction.query(bSql, []);
|
|
|
+ }
|
|
|
+ if (posList.length > 0) {
|
|
|
+ const insertPosArr = [];
|
|
|
+ for (const p of posList) {
|
|
|
+ const insertp = [
|
|
|
+ p.id, p.tid, p.lid, p.name, p.drawing_code, p.quantity, p.add_stage, p.add_times,
|
|
|
+ p.add_user, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.crid, p.porder, p.position,
|
|
|
+ p.sgfh_expr, p.sjcl_expr, p.qtcl_expr, p.real_qty,
|
|
|
+ p.gxby_status, p.dagl_status, p.dagl_url, p.gxby_limit, p.dagl_limit,
|
|
|
+ p.ex_memo1, p.ex_memo2, p.ex_memo3,
|
|
|
+ ];
|
|
|
+ insertPosArr.push('(' + this.ctx.helper.getInArrStrSqlFilter(insertp) + ')');
|
|
|
+ await transaction.delete(this.ctx.service.changePos.tableName, { id: p.id });
|
|
|
+ }
|
|
|
+ const pSql =
|
|
|
+ 'Insert Into ' +
|
|
|
+ this.ctx.service.pos.tableName +
|
|
|
+ ' (id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
|
|
|
+ ' sgfh_qty, sjcl_qty, qtcl_qty, crid, porder, position, ' +
|
|
|
+ ' sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
|
|
|
+ ' gxby_status, dagl_status, dagl_url, gxby_limit, dagl_limit,' +
|
|
|
+ ' ex_memo1, ex_memo2, ex_memo3) VALUES ' + insertPosArr.join(',') + ';';
|
|
|
+ await transaction.query(pSql, []);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ChangeAuditList;
|