|
@@ -14,8 +14,9 @@ const timesLen = audit.stage.timesLen;
|
|
|
const changeConst = require('../const/change');
|
|
|
|
|
|
class autoUseChange {
|
|
|
- constructor(helper, info, settleStatus) {
|
|
|
- this.helper = helper;
|
|
|
+ constructor(ctx, info, settleStatus) {
|
|
|
+ this.helper = ctx.helper;
|
|
|
+ this.correct = ctx.subProject.page_show.correctCalcContractTp;
|
|
|
this.info = info;
|
|
|
this.precision = info.precision;
|
|
|
this.decimal = info.decimal;
|
|
@@ -156,16 +157,32 @@ class autoUseChange {
|
|
|
this._calculateQty(cb, minus, bills);
|
|
|
}
|
|
|
}
|
|
|
- calcContractTp(bills, contract_qty, qc_minus_qty) {
|
|
|
- const preSb = this.preStageBills.find(x => { return x.lid === bills.id; });
|
|
|
- let activeQty = this.helper.add(bills.quantity, qc_minus_qty);
|
|
|
- let end_contract_qty = contract_qty;
|
|
|
- if (preSb) {
|
|
|
- activeQty = this.helper.add(activeQty, preSb.qc_minus_qty);
|
|
|
- end_contract_qty = this.helper.add(end_contract_qty, preSb.contract_qty);
|
|
|
- }
|
|
|
- const end_contract_tp = this.helper.mul(this.helper.div(end_contract_qty, activeQty), bills.total_price, this.decimal.tp);
|
|
|
- return preSb ? this.helper.sub(end_contract_tp, preSb.pre_contract_tp) : end_contract_tp;
|
|
|
+ calcContractTp(info, bills, contract_qty, qc_minus_qty) {
|
|
|
+ if (info.calc_type === 'tp') {
|
|
|
+ const preSb = this.preStageBills.find(x => { return x.lid === bills.id; });
|
|
|
+ let activeQty = this.helper.add(bills.quantity, qc_minus_qty);
|
|
|
+ let end_contract_qty = contract_qty;
|
|
|
+ if (preSb) {
|
|
|
+ activeQty = this.helper.add(activeQty, preSb.qc_minus_qty);
|
|
|
+ end_contract_qty = this.helper.add(end_contract_qty, preSb.contract_qty);
|
|
|
+ }
|
|
|
+ const end_contract_tp = this.helper.mul(this.helper.div(end_contract_qty, activeQty), bills.total_price, this.decimal.tp);
|
|
|
+ return preSb ? this.helper.sub(end_contract_tp, preSb.pre_contract_tp) : end_contract_tp;
|
|
|
+ } else if (info.calc_type === 'up') {
|
|
|
+ if (this.correct) {
|
|
|
+ const preSb = this.preStageBills.find(x => { return x.lid === bills.id; });
|
|
|
+ let activeQty = this.helper.add(bills.quantity, qc_minus_qty);
|
|
|
+ let end_contract_qty = contract_qty;
|
|
|
+ if (preSb) {
|
|
|
+ activeQty = this.helper.add(activeQty, preSb.qc_minus_qty);
|
|
|
+ end_contract_qty = this.helper.add(end_contract_qty, preSb.contract_qty);
|
|
|
+ }
|
|
|
+ const end_contract_tp = this.helper.mul(end_contract_qty, bills.unit_price, this.decimal.tp);
|
|
|
+ return activeQty === end_contract_qty ? this.helper.sub(end_contract_tp, preSb.pre_contract_tp) : this.helper.mul(contract_qty, bills.unit_price, this.decimal.tp);
|
|
|
+ } else {
|
|
|
+ return this.helper.mul(contract_qty, bills.unit_price, this.decimal.tp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
calculateAll() {
|
|
|
for (const cd of this.changeDetail) {
|
|
@@ -232,7 +249,7 @@ class autoUseChange {
|
|
|
const sb = this.stageBills.find(x => {return x.lid === lid});
|
|
|
|
|
|
if (sb) {
|
|
|
- const contract_tp = qc_minus_qty && this.info.calc_type === 'tp' && sb.contract_qty ? this.calcContractTp(cb.bills, sb.contract_qty, qc_minus_qty) : 0;
|
|
|
+ const contract_tp = qc_minus_qty && sb.contract_qty ? this.calcContractTp(this.info, cb.bills, sb.contract_qty, qc_minus_qty) : 0;
|
|
|
this.updateBills.push({ id: sb.id, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp, qc_minus_qty, contract_tp });
|
|
|
} else {
|
|
|
this.insertBills.push({
|
|
@@ -845,7 +862,7 @@ module.exports = app => {
|
|
|
const stageChange = await this.ctx.service.stageChange.getAllDataByCondition({ where: { sid: stage.id, lid }});
|
|
|
const preStageBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData(stage.tid, stage.preCheckedStage.order) : [];
|
|
|
|
|
|
- const useModal = new autoUseChange(this.ctx.helper, tender.info);
|
|
|
+ const useModal = new autoUseChange(this.ctx, tender.info);
|
|
|
const projectFunInfo = this.ctx.subProject.fun_rela;
|
|
|
const minusNoValue = projectFunInfo.minusNoValue && tender.info.fun_rela.stage_change.minusNoValue;
|
|
|
useModal.use({ledgerData, posData, stageBills, stagePos, stageChange, preStageBills, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);
|
|
@@ -895,7 +912,7 @@ module.exports = app => {
|
|
|
const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
const preStageBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData(stage.tid, stage.preCheckedStage.order) : [];
|
|
|
- const useModal = new autoUseChange(this.ctx.helper, tender.info, this.ctx.service.settle.settleStatus);
|
|
|
+ const useModal = new autoUseChange(this.ctx, tender.info, this.ctx.service.settle.settleStatus);
|
|
|
const projectFunInfo = this.ctx.subProject.fun_rela;
|
|
|
const minusNoValue = projectFunInfo.minusNoValue && tender.info.fun_rela.stage_change.minusNoValue;
|
|
|
useModal.use({ledgerData, posData, stageBills, stagePos, preStageBills, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills, minusNoValue);
|