|
@@ -147,7 +147,7 @@ module.exports = app => {
|
|
|
* @private
|
|
|
*/
|
|
|
async _addStagePosData(data) {
|
|
|
- let bills , precision, updateBills = null;
|
|
|
+ let bills , precision;
|
|
|
const result = {pos: [], ledger: []};
|
|
|
const datas = data instanceof Array ? data : [data], calcStageBills = [];
|
|
|
if (datas[0].sgfh_qty !== undefined || datas[0].sjcl_qty !== undefined || datas[0].qtcl_qty !== undefined
|
|
@@ -176,8 +176,6 @@ module.exports = app => {
|
|
|
if (d.sjcl_expr !== undefined) p.sjcl_expr = d.sjcl_expr;
|
|
|
if (d.qtcl_expr !== undefined) p.qtcl_expr = d.qtcl_expr;
|
|
|
p.quantity = this.ctx.helper.sum([p.sgfh_qty, p.sjcl_qty, p.qtcl_qty]);
|
|
|
- if (!updateBills)
|
|
|
- updateBills = {id: bills.id, sgfh_qty: bills.sgfh_qty, sjcl_qty: bills.sjcl_qty, qtcl_qty: bills.qtcl_qty};
|
|
|
}
|
|
|
if (d.real_qty!== undefined) p.real_qty = this.round(d.real_qty, precision.value);
|
|
|
insertPos.push(p);
|
|
@@ -203,34 +201,10 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (updateBills) {
|
|
|
- for (const d of insertPos) {
|
|
|
- if (d.sgfh_qty) {
|
|
|
- d.sgfh_qty = this.ctx.helper.round(d.sgfh_qty, precision.value);
|
|
|
- updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
|
|
|
- }
|
|
|
- if (d.sjcl_qty) {
|
|
|
- d.sjcl_qty = this.ctx.helper.round(d.sjcl_qty, precision.value);
|
|
|
- updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
|
|
|
- }
|
|
|
- if (d.qtcl_qty) {
|
|
|
- d.qtcl_qty = this.ctx.helper.round(d.qtcl_qty, precision.value);
|
|
|
- updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
|
|
|
- }
|
|
|
- d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
|
|
|
- }
|
|
|
- updateBills.quantity = this.ctx.helper.sum([updateBills.sgfh_qty, updateBills.qtcl_qty, updateBills.sjcl_qty]);
|
|
|
- const info = this.ctx.tender.info;
|
|
|
- updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
|
|
|
- updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
- updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
- updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
- }
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
if (insertPos.length > 0) await transaction.insert(this.ctx.service.pos.tableName, insertPos);
|
|
|
- if (updateBills) await transaction.update(this.ctx.service.ledger.tableName, updateBills);
|
|
|
if (insertPosStage.length > 0) await transaction.insert(this.tableName, insertPosStage);
|
|
|
|
|
|
for (const lid of calcStageBills) {
|
|
@@ -489,7 +463,7 @@ module.exports = app => {
|
|
|
*/
|
|
|
async _deleteStagePosData(data) {
|
|
|
const pos = await this.ctx.service.pos.getPosData({tid: this.ctx.tender.id, id: data});
|
|
|
- const result = { pos: data, isDeletePos: true};
|
|
|
+ const result = { pos: data, isDeletePos: true };
|
|
|
if (pos instanceof Array) {
|
|
|
for (const p of pos) {
|
|
|
if (p.add_stage !== this.ctx.stage.id /*|| p.add_times !== this.ctx.stage.curTimes || p.add_user !== this.ctx.session.sessionUser.accountId*/) {
|
|
@@ -502,33 +476,17 @@ module.exports = app => {
|
|
|
} else if (pos.add_stage !== this.ctx.stage.id /*|| pos.add_times !== this.ctx.stage.curTimes || pos.add_user !== this.ctx.session.sessionUser.accountId*/) {
|
|
|
throw '不可删除该数据';
|
|
|
}
|
|
|
- const bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
|
|
|
- const billsPos = await this.ctx.service.pos.getAllDataByCondition({ where: {tid: bills.tender_id, lid: bills.id} });
|
|
|
- const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
|
|
|
- for (const bp of billsPos) {
|
|
|
- if (data.indexOf(bp.id) >= 0) continue;
|
|
|
- updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
|
|
|
- updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
|
|
|
- updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
|
|
|
- updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
|
|
|
- }
|
|
|
- const info = this.ctx.tender.info;
|
|
|
- updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
|
|
|
- updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
- updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
|
|
|
- updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 删除部位明细
|
|
|
await transaction.delete(this.ctx.service.pos.tableName, {tid: this.ctx.tender.id, id: data});
|
|
|
- await transaction.update(this.ctx.service.ledger.tableName, updateBills);
|
|
|
// 删除部位明细计量数据
|
|
|
await transaction.delete(this.tableName, {tid: this.ctx.tender.id, lid: data});
|
|
|
- await this.ctx.service.stageBills.calc(this.ctx.tender.id, this.ctx.stage.id, bills.id, transaction);
|
|
|
+ await this.ctx.service.stageBills.calc(this.ctx.tender.id, this.ctx.stage.id, pos[0].lid, transaction);
|
|
|
await transaction.commit();
|
|
|
// 获取需要更新的数据
|
|
|
- result.ledger = [bills.id];
|
|
|
+ result.ledger = [pos[0].lid];
|
|
|
result.stageUpdate = true;
|
|
|
return result;
|
|
|
} catch (err) {
|