|
@@ -244,6 +244,43 @@ module.exports = app => {
|
|
|
}
|
|
|
return changeBills;
|
|
|
}
|
|
|
+
|
|
|
+ async _reCalcStageBills(tenderId, newDecimal, oldDecimal) {
|
|
|
+ let updateStageBills = [], insertStageBills = [];
|
|
|
+ const stage = await this.ctx.service.stage.getLastestStage(tenderId, true);
|
|
|
+ if (!stage || stage.status === auditConst.stage.status.checking ||
|
|
|
+ stage.status === auditConst.stage.status.checked || newDecimal.tp === oldDecimal.tp)
|
|
|
+ return [updateStageBills, insertStageBills];
|
|
|
+
|
|
|
+ const stageBills = await this.ctx.service.stageBills.getLastestStageData2(stage.tid, stage.id);
|
|
|
+ const bills = await this.ctx.service.ledger.getAllDataByCondition({
|
|
|
+ columns: ['id', 'unit_price'],
|
|
|
+ where: { tender_id: tenderId, is_leaf: true },
|
|
|
+ });
|
|
|
+ for (const sb of stageBills) {
|
|
|
+ const b = bills.find(x => {return x.id === sb.lid});
|
|
|
+ const contract_tp = this.ctx.helper.mul(b.unit_price, sb.contract_qty, newDecimal.tp);
|
|
|
+ const qc_tp = this.ctx.helper.mul(b.unit_price, sb.qc_qty, newDecimal.tp);
|
|
|
+ if (contract_tp == sb.contract_tp && qc_tp === sb.qc_tp) continue;
|
|
|
+
|
|
|
+ //if (sb.)
|
|
|
+ if (sb.times === stage.times && sb.order === 0) {
|
|
|
+ updateStageBills.push({
|
|
|
+ id: sb.id, contract_tp, qc_tp
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ insertStageBills.push({
|
|
|
+ tid: stage.tid, lid: sb.lid, sid: stage.id, said: this.ctx.session.sessionUser.accountId,
|
|
|
+ times: stage.times, order: 0,
|
|
|
+ contract_qty: sb.contract_qty, contract_expr: sb.contract_expr, contract_tp,
|
|
|
+ qc_qty: sb.qc_qty, qc_tp,
|
|
|
+ postil: sb.postil,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return [updateStageBills, insertStageBills];
|
|
|
+ }
|
|
|
+
|
|
|
async _reCalcStageExtra(tenderId, newDecimal, oldDecimal) {
|
|
|
let changeSj = [], changeSb = [], changeSo = [];
|
|
|
const stage = await this.ctx.service.stage.getLastestStage(tenderId, true);
|
|
@@ -309,15 +346,19 @@ module.exports = app => {
|
|
|
const [billsService] = await this._getLedgerService();
|
|
|
|
|
|
const changeBills = await this._reCalcLedger(tenderId, billsService, newDecimal, oldDecimal);
|
|
|
+ const [updateStageBills, insertStageBills] = await this._reCalcStageBills(tenderId, newDecimal, oldDecimal);
|
|
|
const [changeSj, changeSb, changeSo] = await this._reCalcStageExtra(tenderId, newDecimal, oldDecimal);
|
|
|
if (changeBills.length > 0 ||
|
|
|
changeAdvanceBills.length > 0 ||
|
|
|
+ updateStageBills.length > 0 || insertStageBills.length > 0 ||
|
|
|
changeSj.length > 0 || changeSb.length > 0 || changeSo.length > 0) {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
await transaction.update(this.tableName,
|
|
|
{ decimal: JSON.stringify(newDecimal) }, { where: { tid: tenderId } });
|
|
|
if (changeBills.length > 0) await transaction.updateRows(billsService.tableName, changeBills);
|
|
|
+ if (updateStageBills.length > 0) await transaction.updateRows(this.ctx.service.stageBills.tableName, updateStageBills);
|
|
|
+ if (insertStageBills.length > 0) await transaction.insert(this.ctx.service.stageBills.tableName, insertStageBills);
|
|
|
if (changeSj.length > 0) await transaction.updateRows(this.ctx.service.stageJgcl.tableName, changeSj);
|
|
|
if (changeSb.length > 0) await transaction.updateRows(this.ctx.service.stageBonus.tableName, changeSb);
|
|
|
if (changeSo.length > 0) await transaction.updateRows(this.ctx.service.stageOther.tableName, changeSo);
|