|
@@ -53,6 +53,14 @@ class revisePriceCalc {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ findCommonChangeBillsPrice(b_code, name, unit, unit_price) {
|
|
|
+ const helper = this.ctx.helper;
|
|
|
+ const p = this.price.find(x => {
|
|
|
+ return b_code === x.b_code && name === x.name && unit === x.unit && helper.numEqual(unit_price, x.org_price);
|
|
|
+ });
|
|
|
+ return p;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增一期计量,检查单价调整
|
|
|
* @param {Object} newStage - 新计量期
|
|
@@ -250,6 +258,72 @@ class revisePriceCalc {
|
|
|
}
|
|
|
if (revisePriceUpdate.length > 0) await transaction.updateRows(this.ctx.service.revisePrice.tableName, revisePriceUpdate);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 重算变更方案(调整单价)
|
|
|
+ * @param {Object} change - 工程变更
|
|
|
+ * @param {Object} transaction - 事务 (无则非事务提交)
|
|
|
+ */
|
|
|
+ async calcChangePlan(changePlan, transaction) {
|
|
|
+ const decimal = changePlan.decimal ? JSON.parse(changePlan.decimal) : this.ctx.tender.info.decimal;
|
|
|
+ const changeBills = await this.ctx.service.changePlanList.getAllDataByCondition({ where: { cpid: changePlan.id } });
|
|
|
+ const updateBills = [];
|
|
|
+ let total_price = 0;
|
|
|
+ for (const b of changeBills) {
|
|
|
+ const p = this.findCommonChangeBillsPrice(b.code, b.name, b.unit, b.unit_price);
|
|
|
+ let bills_tp;
|
|
|
+ if (p) {
|
|
|
+ bills_tp = this.ctx.helper.mul(p.new_price, b.spamount, decimal.tp);
|
|
|
+ updateBills.push({ id: b.id, unit_price: p.new_price });
|
|
|
+ } else {
|
|
|
+ bills_tp = this.ctx.helper.mul(b.unit_price, b.spamount, decimal.tp);
|
|
|
+ }
|
|
|
+ total_price = this.ctx.helper.add(total_price, bills_tp);
|
|
|
+ }
|
|
|
+ if (updateBills.length > 0) {
|
|
|
+ await transaction.updateRows(this.ctx.service.changePlanList.tableName, updateBills);
|
|
|
+ await transaction.update(this.ctx.service.changePlan.tableName, { id: changePlan.id, total_price});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ async calcAllChangePlan(tid, transaction) {
|
|
|
+ const changePlan = await this.ctx.service.changePlan.getAllDataByCondition({ where: { tid } });
|
|
|
+ if (changePlan.length === 0) return;
|
|
|
+ for (const c of changePlan) {
|
|
|
+ await this.calcChangePlan(c, transaction);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 重算变更申请(调整单价)
|
|
|
+ * @param {Object} change - 工程变更
|
|
|
+ * @param {Object} transaction - 事务 (无则非事务提交)
|
|
|
+ */
|
|
|
+ async calcChangeApply(changeApply, transaction) {
|
|
|
+ const decimal = changeApply.decimal ? JSON.parse(changeApply.decimal) : this.ctx.tender.info.decimal;
|
|
|
+ const changeBills = await this.ctx.service.changeApplyList.getAllDataByCondition({ where: { caid: changeApply.id } });
|
|
|
+ const updateBills = [];
|
|
|
+ let total_price = 0;
|
|
|
+ for (const b of changeBills) {
|
|
|
+ const p = this.findCommonChangeBillsPrice(b.code, b.name, b.unit, b.unit_price);
|
|
|
+ let bills_tp;
|
|
|
+ if (p) {
|
|
|
+ bills_tp = this.ctx.helper.mul(p.new_price, b.camount, decimal.tp);
|
|
|
+ updateBills.push({ id: b.id, unit_price: p.new_price });
|
|
|
+ } else {
|
|
|
+ bills_tp = this.ctx.helper.mul(b.unit_price, b.camount, decimal.tp);
|
|
|
+ }
|
|
|
+ total_price = this.ctx.helper.add(total_price, bills_tp);
|
|
|
+ }
|
|
|
+ if (updateBills.length > 0) {
|
|
|
+ await transaction.updateRows(this.ctx.service.changeApplyList.tableName, updateBills);
|
|
|
+ await transaction.update(this.ctx.service.changeApply.tableName, { id: changeApply.id, total_price});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ async calcAllChangeApply(tid, transaction) {
|
|
|
+ const changeApply = await this.ctx.service.changeApply.getAllDataByCondition({ where: { tid } });
|
|
|
+ if (changeApply.length === 0) return;
|
|
|
+ for (const c of changeApply) {
|
|
|
+ await this.calcChangeApply(c, transaction);
|
|
|
+ }
|
|
|
+ }
|
|
|
async _calcStage(stage, bills, transaction) {
|
|
|
const pcTp = { contract_pc_tp: 0, qc_pc_tp: 0, pc_tp: 0, positive_qc_pc_tp: 0, negative_qc_pc_tp: 0 };
|
|
|
// 无单价变更不执行
|
|
@@ -454,6 +528,8 @@ class revisePriceCalc {
|
|
|
const pcTp = await this.calcReviseLedger(revise, transaction);
|
|
|
// 引用到所有工程变更
|
|
|
await this.calcAllChanges(revise.tid, transaction);
|
|
|
+ await this.calcAllChangePlan(revise.tid, transaction);
|
|
|
+ await this.calcAllChangeApply(revise.tid, transaction);
|
|
|
return pcTp;
|
|
|
}
|
|
|
}
|