|
@@ -20,6 +20,12 @@ class PayCalculate {
|
|
this.percentReg = /[0-9]+%/g;
|
|
this.percentReg = /[0-9]+%/g;
|
|
this.tenderInfo = tenderInfo;
|
|
this.tenderInfo = tenderInfo;
|
|
this.decimal = tenderInfo.decimal.pay ? tenderInfo.decimal.payTp : tenderInfo.decimal.tp;
|
|
this.decimal = tenderInfo.decimal.pay ? tenderInfo.decimal.payTp : tenderInfo.decimal.tp;
|
|
|
|
+ /* 以下变量在调用calculate方法后获得
|
|
|
|
+ this.add;
|
|
|
|
+ this.pre;
|
|
|
|
+ this.cur;
|
|
|
|
+ this.yf;
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -42,11 +48,11 @@ class PayCalculate {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- calculateTpExpr(pay, addRela) {
|
|
|
|
|
|
+ _calculateTpExpr(pay) {
|
|
let formula = pay.expr;
|
|
let formula = pay.expr;
|
|
for (const b of this.bases) {
|
|
for (const b of this.bases) {
|
|
if ((b.code === 'bqwc') && (!pay.pre_used && pay.sprice)) {
|
|
if ((b.code === 'bqwc') && (!pay.pre_used && pay.sprice)) {
|
|
- formula = formula.replace(b.reg, this.ctx.helper.sub(addRela.gather_tp, pay.sprice));
|
|
|
|
|
|
+ formula = formula.replace(b.reg, this.ctx.helper.sub(this.add.gather_tp, pay.sprice));
|
|
} else {
|
|
} else {
|
|
formula = formula.replace(b.reg, b.value);
|
|
formula = formula.replace(b.reg, b.value);
|
|
}
|
|
}
|
|
@@ -66,7 +72,7 @@ class PayCalculate {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- calculateExpr(expr) {
|
|
|
|
|
|
+ _calculateExpr(expr) {
|
|
let formula = expr;
|
|
let formula = expr;
|
|
for (const b of this.bases) {
|
|
for (const b of this.bases) {
|
|
formula = formula.replace(b.reg, b.value);
|
|
formula = formula.replace(b.reg, b.value);
|
|
@@ -99,12 +105,12 @@ class PayCalculate {
|
|
if (p.csorder === this.stage.order || (p.csorder === 0 || this.stage.order === 1)) {
|
|
if (p.csorder === this.stage.order || (p.csorder === 0 || this.stage.order === 1)) {
|
|
if (p.csaorder === order) {
|
|
if (p.csaorder === order) {
|
|
if (!p.sprice && p.sexpr && p.sexpr !== '') {
|
|
if (!p.sprice && p.sexpr && p.sexpr !== '') {
|
|
- p.sprice = this.ctx.helper.round(this.calculateExpr(p.sexpr), this.decimal);
|
|
|
|
|
|
+ p.sprice = this.ctx.helper.round(this._calculateExpr(p.sexpr), this.decimal);
|
|
} else if (p.sprice && !p.sexpr) {
|
|
} else if (p.sprice && !p.sexpr) {
|
|
p.sprice = this.ctx.helper.round(p.sprice, this.decimal);
|
|
p.sprice = this.ctx.helper.round(p.sprice, this.decimal);
|
|
}
|
|
}
|
|
if (!p.rprice && p.rexpr && p.rexpr !== '') {
|
|
if (!p.rprice && p.rexpr && p.rexpr !== '') {
|
|
- p.rprice = this.ctx.helper.round(this.calculateExpr(p.rexpr), this.decimal);
|
|
|
|
|
|
+ p.rprice = this.ctx.helper.round(this._calculateExpr(p.rexpr), this.decimal);
|
|
} else if (p.rprice && !p.rexpr) {
|
|
} else if (p.rprice && !p.rexpr) {
|
|
p.rprice = this.ctx.helper.round(p.rprice, this.decimal);
|
|
p.rprice = this.ctx.helper.round(p.rprice, this.decimal);
|
|
}
|
|
}
|
|
@@ -116,29 +122,28 @@ class PayCalculate {
|
|
/**
|
|
/**
|
|
* 累计 计量等数据
|
|
* 累计 计量等数据
|
|
*/
|
|
*/
|
|
- async getAddCalcRela() {
|
|
|
|
|
|
+ async _getAddCalcRela() {
|
|
// todo 获取截止上期数据
|
|
// todo 获取截止上期数据
|
|
- const pre = this.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getSumTotalPrice(this.stage.tid, this.stage.order - 1) : null;
|
|
|
|
- const cur = await this.ctx.service.stageBills.getSumTotalPrice(this.stage);
|
|
|
|
- const add = {};
|
|
|
|
- if (pre) {
|
|
|
|
- add.contract_tp = this.ctx.helper.add(pre.contract_tp, cur.contract_tp);
|
|
|
|
- add.qc_tp = this.ctx.helper.add(pre.qc_tp, cur.qc_tp);
|
|
|
|
|
|
+ this.pre = this.stage.order > 1 ? await this.ctx.service.stageBillsFinal.getSumTotalPrice(this.stage.tid, this.stage.order - 1) : null;
|
|
|
|
+ this.cur = await this.ctx.service.stageBills.getSumTotalPrice(this.stage);
|
|
|
|
+ this.add = {};
|
|
|
|
+ if (this.pre) {
|
|
|
|
+ this.add.contract_tp = this.ctx.helper.add(this.pre.contract_tp, this.cur.contract_tp);
|
|
|
|
+ this.add.qc_tp = this.ctx.helper.add(this.pre.qc_tp, this.cur.qc_tp);
|
|
} else {
|
|
} else {
|
|
- add.contract_tp = cur.contract_tp;
|
|
|
|
- add.qc_tp = cur.qc_tp;
|
|
|
|
|
|
+ this.add.contract_tp = this.cur.contract_tp;
|
|
|
|
+ this.add.qc_tp = this.cur.qc_tp;
|
|
}
|
|
}
|
|
- add.gather_tp = this.ctx.helper.add(add.contract_tp, add.qc_tp);
|
|
|
|
- return add;
|
|
|
|
|
|
+ this.add.gather_tp = this.ctx.helper.add(this.add.contract_tp, this.add.qc_tp);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 检查是否到达 计提期限
|
|
* 检查是否到达 计提期限
|
|
* @param pay
|
|
* @param pay
|
|
*/
|
|
*/
|
|
- checkDeadline(pay, addRela) {
|
|
|
|
|
|
+ _checkDeadline(pay) {
|
|
if (pay.dl_type === deadlineType.tp.value) {
|
|
if (pay.dl_type === deadlineType.tp.value) {
|
|
- const deadlineTp = addRela[pay.dl_tp_type + '_tp'];
|
|
|
|
|
|
+ const deadlineTp = this.add[pay.dl_tp_type + '_tp'];
|
|
if (deadlineTp > pay.dl_tp) {
|
|
if (deadlineTp > pay.dl_tp) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -155,19 +160,19 @@ class PayCalculate {
|
|
*/
|
|
*/
|
|
async calculate(pays) {
|
|
async calculate(pays) {
|
|
await this.getCalcBase();
|
|
await this.getCalcBase();
|
|
- const yfPay = pays.find(function (p) {
|
|
|
|
|
|
+ this.yf = pays.find(function (p) {
|
|
return p.ptype === payType.yf;
|
|
return p.ptype === payType.yf;
|
|
});
|
|
});
|
|
- const addRela = await this.getAddCalcRela();
|
|
|
|
- if (!yfPay) return false;
|
|
|
|
- yfPay.tp = 0;
|
|
|
|
|
|
+ if (!this.yf) return false;
|
|
|
|
+ await this._getAddCalcRela();
|
|
|
|
+ this.yf.tp = 0;
|
|
for (const p of pays) {
|
|
for (const p of pays) {
|
|
if (p.ptype === payType.normal || p.ptype === payType.wc) {
|
|
if (p.ptype === payType.normal || p.ptype === payType.wc) {
|
|
- if (!p.pause && (!p.sprice || addRela.gather_tp >= p.sprice)) {
|
|
|
|
|
|
+ if (!p.pause && (!p.sprice || this.add.gather_tp >= p.sprice)) {
|
|
if (p.expr && p.expr !== '') {
|
|
if (p.expr && p.expr !== '') {
|
|
- const value = this.ctx.helper.round(this.calculateTpExpr(p, addRela), this.decimal);
|
|
|
|
|
|
+ const value = this.ctx.helper.round(this._calculateTpExpr(p), this.decimal);
|
|
if (p.rprice) {
|
|
if (p.rprice) {
|
|
- if (this.checkDeadline(p, addRela)) {
|
|
|
|
|
|
+ if (this._checkDeadline(p)) {
|
|
p.tp = this.ctx.helper.sub(p.rprice, p.pre_tp);
|
|
p.tp = this.ctx.helper.sub(p.rprice, p.pre_tp);
|
|
} else {
|
|
} else {
|
|
p.tp = Math.min(this.ctx.helper.sub(p.rprice, p.pre_tp), value);
|
|
p.tp = Math.min(this.ctx.helper.sub(p.rprice, p.pre_tp), value);
|
|
@@ -177,7 +182,7 @@ class PayCalculate {
|
|
}
|
|
}
|
|
} else if (p.tp && !this.ctx.helper.checkZero(p.tp)) {
|
|
} else if (p.tp && !this.ctx.helper.checkZero(p.tp)) {
|
|
if (p.rprice) {
|
|
if (p.rprice) {
|
|
- if (this.checkDeadline(p, addRela)) {
|
|
|
|
|
|
+ if (this._checkDeadline(p)) {
|
|
p.tp = this.ctx.helper.sub(p.rprice, p.pre_tp);
|
|
p.tp = this.ctx.helper.sub(p.rprice, p.pre_tp);
|
|
} else {
|
|
} else {
|
|
p.tp = Math.min(this.ctx.helper.sub(p.rprice, p.pre_tp), this.ctx.helper.round(p.tp, this.decimal));
|
|
p.tp = Math.min(this.ctx.helper.sub(p.rprice, p.pre_tp), this.ctx.helper.round(p.tp, this.decimal));
|
|
@@ -192,15 +197,15 @@ class PayCalculate {
|
|
// 累加 至 应付
|
|
// 累加 至 应付
|
|
if (p.is_yf) {
|
|
if (p.is_yf) {
|
|
if (p.minus) {
|
|
if (p.minus) {
|
|
- yfPay.tp = this.ctx.helper.sub(yfPay.tp, p.tp);
|
|
|
|
|
|
+ this.yf.tp = this.ctx.helper.sub(this.yf.tp, p.tp);
|
|
} else {
|
|
} else {
|
|
- yfPay.tp = this.ctx.helper.add(yfPay.tp, p.tp);
|
|
|
|
|
|
+ this.yf.tp = this.ctx.helper.add(this.yf.tp, p.tp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
p.end_tp = this.ctx.helper.round(this.ctx.helper.add(p.tp, p.pre_tp), this.decimal);
|
|
p.end_tp = this.ctx.helper.round(this.ctx.helper.add(p.tp, p.pre_tp), this.decimal);
|
|
}
|
|
}
|
|
- yfPay.end_tp = this.ctx.helper.add(yfPay.tp, yfPay.pre_tp);
|
|
|
|
|
|
+ this.yf.end_tp = this.ctx.helper.add(this.yf.tp, this.yf.pre_tp);
|
|
}
|
|
}
|
|
|
|
|
|
async calculateAll(pays) {
|
|
async calculateAll(pays) {
|