|
|
@@ -131,6 +131,7 @@ module.exports = app => {
|
|
|
const orgDatas = orgDataIds.length > 0 ? await this.getAllDataByCondition({ where: { id: orgDataIds } }) : [];
|
|
|
|
|
|
const updateDetail = [], insertDetail = [];
|
|
|
+ let calc = false;
|
|
|
for (const d of datas) {
|
|
|
const od = orgDatas.find(x => { return x.id === d.book_id; });
|
|
|
const cd = orgDetail.find(x => { return x.id === d.detail_id });
|
|
|
@@ -143,6 +144,7 @@ module.exports = app => {
|
|
|
if (d[prop] !== undefined) nd[prop] = d[prop];
|
|
|
}
|
|
|
if (d.in_tp !== undefined ) {
|
|
|
+ calc = true;
|
|
|
nd.in_tp = d.in_tp !== undefined ? this.ctx.helper.round(d.in_tp || 0, this.ctx.costStage.decimal.tp) : (od.in_tp ? od.in_tp : 0);
|
|
|
const divNum = this.ctx.helper.add(1, this.ctx.helper.div(cd.tax, 100));
|
|
|
nd.in_excl_tax_tp = this.ctx.helper.div(nd.in_tp, divNum, this.ctx.costStage.decimal.tp);
|
|
|
@@ -153,25 +155,29 @@ module.exports = app => {
|
|
|
insertDetail.push(nd);
|
|
|
}
|
|
|
}
|
|
|
- const bookUpdate = await this._getBookUpdateData([...insertDetail, ...updateDetail], orgDetail[0].ledger_id);
|
|
|
+ const bookUpdate = calc ? await this._getBookUpdateData([...insertDetail, ...updateDetail], orgDetail[0].ledger_id) : null;
|
|
|
const orgBook = await this.ctx.service.costStageBook.getDataByCondition({ ledger_id: orgDetail[0].ledger_id });
|
|
|
const orgLedger = await this.ctx.service.costStageLedger.getDataById(orgDetail[0].ledger_id);
|
|
|
- if (!orgBook) {
|
|
|
- bookUpdate.tender_id = this.ctx.costStage.tid;
|
|
|
- bookUpdate.stage_id = this.ctx.costStage.id;
|
|
|
- bookUpdate.ledger_id = orgLedger.id;
|
|
|
- bookUpdate.cost_id = orgLedger.cost_id;
|
|
|
- bookUpdate.add_user_id = user_id;
|
|
|
+ if (bookUpdate) {
|
|
|
+ if (!orgBook) {
|
|
|
+ bookUpdate.tender_id = this.ctx.costStage.tid;
|
|
|
+ bookUpdate.stage_id = this.ctx.costStage.id;
|
|
|
+ bookUpdate.ledger_id = orgLedger.id;
|
|
|
+ bookUpdate.cost_id = orgLedger.cost_id;
|
|
|
+ bookUpdate.add_user_id = user_id;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const conn = await this.db.beginTransaction();
|
|
|
try {
|
|
|
if (updateDetail.length > 0) await conn.updateRows(this.tableName, updateDetail);
|
|
|
if (insertDetail.length > 0) await conn.insert(this.tableName, insertDetail);
|
|
|
- if (orgBook) {
|
|
|
- await conn.update(this.ctx.service.costStageBook.tableName, bookUpdate);
|
|
|
- } else {
|
|
|
- await conn.insert(this.ctx.service.costStageBook.tableName, bookUpdate);
|
|
|
+ if (bookUpdate) {
|
|
|
+ if (orgBook) {
|
|
|
+ await conn.update(this.ctx.service.costStageBook.tableName, bookUpdate);
|
|
|
+ } else {
|
|
|
+ await conn.insert(this.ctx.service.costStageBook.tableName, bookUpdate);
|
|
|
+ }
|
|
|
}
|
|
|
await conn.commit();
|
|
|
} catch (err) {
|
|
|
@@ -190,9 +196,11 @@ module.exports = app => {
|
|
|
const cl = orgDetail.find(x => { return x.id === od.detail_id; });
|
|
|
u.id = cl.id;
|
|
|
});
|
|
|
- bookUpdate.book_id = bookUpdate.id;
|
|
|
- delete bookUpdate.id;
|
|
|
- bookUpdate.tree_id = orgLedger.tree_id;
|
|
|
+ if (bookUpdate) {
|
|
|
+ bookUpdate.book_id = bookUpdate.id;
|
|
|
+ delete bookUpdate.id;
|
|
|
+ bookUpdate.tree_id = orgLedger.tree_id;
|
|
|
+ }
|
|
|
return { detail: { update: [...insertDetail, ...updateDetail] }, ledger: bookUpdate };
|
|
|
}
|
|
|
|