|
@@ -274,7 +274,7 @@ class BaseBudget extends TreeService {
|
|
|
ids.push(row.id);
|
|
|
}
|
|
|
|
|
|
- this.transaction = await this.db.beginTransaction();
|
|
|
+ const conn = await this.db.beginTransaction();
|
|
|
try {
|
|
|
for (const row of datas) {
|
|
|
const updateNode = await this.getDataById(row.id);
|
|
@@ -292,25 +292,23 @@ class BaseBudget extends TreeService {
|
|
|
if (this._checkCalcField(row)) {
|
|
|
let calcData = JSON.parse(JSON.stringify(row));
|
|
|
if (row.quantity !== undefined || row.unit_price !== undefined) {
|
|
|
- calcData.quantity = row.quantity === undefined ? updateNode.quantity : helper.round(row.quantity, 2);
|
|
|
- calcData.unit_price = row.unit_price === undefined ? updateNode.unit_price : helper.round(row.unit_price, 2);
|
|
|
- calcData.total_price = helper.mul(calcData.quantity, calcData.unit_price, 2);
|
|
|
+ calcData.quantity = row.quantity === undefined ? updateNode.quantity : helper.round(row.quantity, this.ctx.budget.decimal.qty);
|
|
|
+ calcData.unit_price = row.unit_price === undefined ? updateNode.unit_price : helper.round(row.unit_price, this.ctx.budget.decimal.up);
|
|
|
+ calcData.total_price = helper.mul(calcData.quantity, calcData.unit_price, this.ctx.budget.decimal.tp);
|
|
|
} else if (row.total_price !== undefined ) {
|
|
|
calcData.quantity = 0;
|
|
|
calcData.unit_price = 0;
|
|
|
- calcData.total_price = helper.round(row.total_price, 2);
|
|
|
+ calcData.total_price = helper.round(row.total_price, this.ctx.budget.decimal.tp);
|
|
|
}
|
|
|
- updateData = this._filterUpdateInvalidField(updateNode.id, calcData);
|
|
|
+ updateData = this._filterUpdateInvalidField(updateNode.id, this._.default(row, calcData));
|
|
|
} else {
|
|
|
updateData = this._filterUpdateInvalidField(updateNode.id, row);
|
|
|
}
|
|
|
- await this.transaction.update(this.tableName, updateData);
|
|
|
+ await conn.update(this.tableName, updateData);
|
|
|
}
|
|
|
- await this.transaction.commit();
|
|
|
- this.transaction = null;
|
|
|
+ await conn.commit();
|
|
|
} catch (err) {
|
|
|
- await this.transaction.rollback();
|
|
|
- this.transaction = null;
|
|
|
+ await conn.rollback();
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
@@ -363,14 +361,18 @@ class BaseBudget extends TreeService {
|
|
|
for (const c of d.children) {
|
|
|
c.tree_pid = newBills.tree_id;
|
|
|
}
|
|
|
- if (d.b_code) {
|
|
|
- newBills.unit_price = this.ctx.helper.round(d.unit_price, 2);
|
|
|
- newBills.quantity = this.ctx.helper.round(d.quantity, 2);
|
|
|
- newBills.total_price = this.ctx.helper.mul(newBills.quantity, newBills.unit_price, 2);
|
|
|
+ if (d.b_code && d.is_leaf) {
|
|
|
+ newBills.dgn_qty1 = 0;
|
|
|
+ newBills.dgn_qty2 = 0;
|
|
|
+ newBills.unit_price = this.ctx.helper.round(d.unit_price, this.ctx.budget.decimal.up);
|
|
|
+ newBills.quantity = this.ctx.helper.round(d.quantity, this.ctx.budget.decimal.qty);
|
|
|
+ newBills.total_price = this.ctx.helper.mul(newBills.quantity, newBills.unit_price, this.ctx.budget.decimal.tp);
|
|
|
} else {
|
|
|
- newBills.dgn_qty1 = this.ctx.helper.round(d.dgn_qty1, 2);
|
|
|
- newBills.dgn_qty2 = this.ctx.helper.round(d.dgn_qty2, 2);
|
|
|
- newBills.total_price = this.ctx.helper.round(d.total_price, 2);
|
|
|
+ newBills.dgn_qty1 = this.ctx.helper.round(d.dgn_qty1, this.ctx.budget.decimal.qty);
|
|
|
+ newBills.dgn_qty2 = this.ctx.helper.round(d.dgn_qty2, this.ctx.budget.decimal.qty);
|
|
|
+ newBills.unit_price = 0;
|
|
|
+ newBills.quantity = 0;
|
|
|
+ newBills.total_price = d.is_leaf ? this.ctx.helper.round(d.total_price, this.ctx.budget.decimal.tp) : 0;
|
|
|
}
|
|
|
if (defaultData) this.ctx.helper._.assignIn(newBills, defaultData);
|
|
|
pbd.push(newBills);
|
|
@@ -406,7 +408,6 @@ class BaseBudget extends TreeService {
|
|
|
return { create: pasteBillsData, update: updateData };
|
|
|
}
|
|
|
|
|
|
-
|
|
|
async importExcel(templateId, excelData, needGcl, filter) {
|
|
|
const AnalysisExcel = require('../lib/analysis_excel').AnalysisExcelTree;
|
|
|
const analysisExcel = new AnalysisExcel(this.ctx, this.setting, needGcl ? ['code', 'b_code'] : ['code']);
|
|
@@ -415,9 +416,9 @@ class BaseBudget extends TreeService {
|
|
|
filterZeroGcl: filter, filterPos: true, filterGcl: !needGcl, filterCalc: true,
|
|
|
});
|
|
|
const orgMaxId = await this._getMaxLid(this.ctx.budget.id);
|
|
|
- const transaction = await this.db.beginTransaction();
|
|
|
+ const conn = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- await transaction.delete(this.tableName, { bid: this.ctx.budget.id });
|
|
|
+ await conn.delete(this.tableName, { bid: this.ctx.budget.id });
|
|
|
const datas = [];
|
|
|
for (const node of cacheTree.items) {
|
|
|
const data = {
|
|
@@ -444,18 +445,18 @@ class BaseBudget extends TreeService {
|
|
|
};
|
|
|
datas.push(data);
|
|
|
}
|
|
|
- await transaction.insert(this.tableName, datas);
|
|
|
- await transaction.commit();
|
|
|
+ await conn.insert(this.tableName, datas);
|
|
|
+ await conn.commit();
|
|
|
if (orgMaxId) this._cacheMaxLid(this.ctx.budget.id, cacheTree.keyNodeId);
|
|
|
return datas;
|
|
|
} catch (err) {
|
|
|
- await transaction.rollback();
|
|
|
+ await conn.rollback();
|
|
|
throw err;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async getSumTp(bid) {
|
|
|
- const sql = 'SELECT Sum(total_price) As total_price FROM ' + this.tableName + ' Where bid = ?';
|
|
|
+ const sql = 'SELECT Sum(total_price) As total_price FROM ' + this.tableName + ' Where bid = ? and is_leaf = true';
|
|
|
const result = await this.db.queryOne(sql, [bid]);
|
|
|
return result.total_price;
|
|
|
}
|