|
@@ -1674,16 +1674,11 @@ module.exports = app => {
|
|
|
if (row.qtcl_qty === undefined) calcData.qtcl_qty = updateNode.qtcl_qty;
|
|
|
if (row.deal_qty === undefined) calcData.deal_qty = updateNode.deal_qty;
|
|
|
calcData.quantity = this.ctx.helper.sum([calcData.sgfh_qty, calcData.sjcl_qty, calcData.qtcl_qty]);
|
|
|
- calcData.sgfh_tp = this.ctx.helper.round(
|
|
|
- this.ctx.helper.mul(calcData.sgfh_qty, calcData.unit_price), info.decimal.tp);
|
|
|
- calcData.sjcl_tp = this.ctx.helper.round(
|
|
|
- this.ctx.helper.mul(calcData.sjcl_qty, calcData.unit_price), info.decimal.tp);
|
|
|
- calcData.qtcl_tp = this.ctx.helper.round(
|
|
|
- this.ctx.helper.mul(calcData.qtcl_qty, calcData.unit_price), info.decimal.tp);
|
|
|
- calcData.total_price = this.ctx.helper.round(
|
|
|
- this.ctx.helper.mul(calcData.quantity, calcData.unit_price), info.decimal.tp);
|
|
|
- calcData.deal_tp = this.ctx.helper.round(
|
|
|
- this.ctx.helper.mul(calcData.deal_qty, calcData.unit_price), info.decimal.tp);
|
|
|
+ calcData.sgfh_tp = this.ctx.helper.mul(calcData.sgfh_qty, calcData.unit_price, info.decimal.tp);
|
|
|
+ calcData.sjcl_tp = this.ctx.helper.mul(calcData.sjcl_qty, calcData.unit_price, info.decimal.tp);
|
|
|
+ calcData.qtcl_tp = this.ctx.helper.mul(calcData.qtcl_qty, calcData.unit_price, info.decimal.tp);
|
|
|
+ calcData.total_price = this.ctx.helper.mul(calcData.quantity, calcData.unit_price, info.decimal.tp);
|
|
|
+ calcData.deal_tp = this.ctx.helper.mul(calcData.deal_qty, calcData.unit_price, info.decimal.tp);
|
|
|
} else if (row.sgfh_tp !== undefined || row.sjcl_tp !== undefined || row.qtcl_tp !== undefined || row.deal_tp !== undefined) {
|
|
|
calcData.sgfh_qty = null;
|
|
|
calcData.sjcl_qty = null;
|
|
@@ -1758,8 +1753,7 @@ module.exports = app => {
|
|
|
quantity: gcl.quantity,
|
|
|
};
|
|
|
child.full_path = parent.full_path + '.' + child.ledger_id;
|
|
|
- child.total_price = this.ctx.helper.round(
|
|
|
- this.ctx.helper.mul(child.unit_price, child.quantity), this.ctx.tender.info.decimal.tp);
|
|
|
+ child.total_price = this.ctx.helper.mul(child.unit_price, child.quantity, this.ctx.tender.info.decimal.tp);
|
|
|
tp = this.ctx.helper.add(tp, child.total_price);
|
|
|
result.push(child);
|
|
|
newIds.push(child.ledger_id);
|
|
@@ -1940,10 +1934,10 @@ module.exports = app => {
|
|
|
data.sjcl_qty = this.round(data.sjcl_qty, precision.value);
|
|
|
data.qtcl_qty = this.round(data.qtcl_qty, precision.value);
|
|
|
data.quantity = this.round(data.quantity, precision.value);
|
|
|
- data.sgfh_tp = this.round(this.ctx.helper.mul(data.sgfh_qty, node.unit_price), info.decimal.tp);
|
|
|
- data.sjcl_tp = this.round(this.ctx.helper.mul(data.sjcl_qty, node.unit_price), info.decimal.tp);
|
|
|
- data.qtcl_tp = this.round(this.ctx.helper.mul(data.qtcl_qty, node.unit_price), info.decimal.tp);
|
|
|
- data.total_price = this.round(this.ctx.helper.mul(data.quantity, node.unit_price), info.decimal.tp);
|
|
|
+ data.sgfh_tp = this.ctx.helper.mul(data.sgfh_qty, node.unit_price, info.decimal.tp);
|
|
|
+ data.sjcl_tp = this.ctx.helper.mul(data.sjcl_qty, node.unit_price, info.decimal.tp);
|
|
|
+ data.qtcl_tp = this.ctx.helper.mul(data.qtcl_qty, node.unit_price, info.decimal.tp);
|
|
|
+ data.total_price = this.ctx.helper.mul(data.quantity, node.unit_price, info.decimal.tp);
|
|
|
const result = await transaction.update(this.tableName, data);
|
|
|
}
|
|
|
|
|
@@ -2011,6 +2005,51 @@ module.exports = app => {
|
|
|
} else if (node.pos && node.pos.length > 0) {
|
|
|
await this.ctx.service.pos.insertLedgerPosData(transaction, this.ctx.tender.id, data, node.pos);
|
|
|
}
|
|
|
+ if (node.pos && node.pos.length > 0) {
|
|
|
+ for (const p of node.pos) {
|
|
|
+ p.lid = result.insertId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async _importCacheTreeNodes(transaction, nodes) {
|
|
|
+ const datas = [];
|
|
|
+ for (const node of nodes) {
|
|
|
+ datas.push({
|
|
|
+ tender_id: this.ctx.tender.id,
|
|
|
+ ledger_id: node.ledger_id,
|
|
|
+ ledger_pid: node.ledger_pid,
|
|
|
+ level: node.level,
|
|
|
+ order: node.order,
|
|
|
+ is_leaf: !node.children || node.children.length === 0,
|
|
|
+ full_path: node.full_path,
|
|
|
+ code: node.code,
|
|
|
+ b_code: node.b_code,
|
|
|
+ name: node.name,
|
|
|
+ unit: node.unit,
|
|
|
+ sgfh_qty: node.sgfh_qty,
|
|
|
+ sgfh_tp: node.sgfh_tp,
|
|
|
+ quantity: node.quantity,
|
|
|
+ unit_price: node.unit_price,
|
|
|
+ total_price: node.total_price,
|
|
|
+ dgn_qty1: node.dgn_qty1,
|
|
|
+ dgn_qty2: node.dgn_qty2,
|
|
|
+ memo: node.memo,
|
|
|
+ drawing_code: node.drawing_code,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ await transaction.insert(this.tableName, datas);
|
|
|
+ const sql = 'SELECT id, ledger_id FROM ' + this.tableName + ' WHERE tender_id = ?';
|
|
|
+ const sqlParam = [this.ctx.tender.id];
|
|
|
+ const insertDatas = await transaction.query(sql, sqlParam);
|
|
|
+ for (const iD of insertDatas) {
|
|
|
+ const node = this.ctx.helper._.find(nodes, {ledger_id: iD.ledger_id});
|
|
|
+ if (node.pos && node.pos.length > 0) {
|
|
|
+ for (const p of node.pos) {
|
|
|
+ p.lid = iD.id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -2029,9 +2068,11 @@ module.exports = app => {
|
|
|
try {
|
|
|
await transaction.delete(this.tableName, {tender_id: this.ctx.tender.id});
|
|
|
await transaction.delete(this.ctx.service.pos.tableName, {tid: this.ctx.tender.id});
|
|
|
- for (const node of cacheTree.roots) {
|
|
|
- await this._importCacheTreeNode(transaction, node);
|
|
|
- }
|
|
|
+ // for (const node of cacheTree.roots) {
|
|
|
+ // await this._importCacheTreeNode(transaction, node);
|
|
|
+ // }
|
|
|
+ await this._importCacheTreeNodes(transaction, cacheTree.items);
|
|
|
+ await transaction.insert(this.ctx.service.pos.tableName, cacheTree.pos);
|
|
|
await transaction.commit();
|
|
|
this.cache.set(cacheKey, cacheTree.items.length + 1, 'EX', this.ctx.app.config.cacheTime);
|
|
|
} catch (err) {
|