|
@@ -99,7 +99,7 @@ module.exports = app => {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- async getNewOrder(tid) {
|
|
|
|
|
|
+ async getMaxOrder(tid) {
|
|
const sql = 'SELECT Max(`phase_order`) As max_order FROM ' + this.tableName + ' Where `tid` = ?';
|
|
const sql = 'SELECT Max(`phase_order`) As max_order FROM ' + this.tableName + ' Where `tid` = ?';
|
|
const sqlParam = [tid];
|
|
const sqlParam = [tid];
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
@@ -117,7 +117,7 @@ module.exports = app => {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- async getCalcBase(relaStage) {
|
|
|
|
|
|
+ async getCalcBase(relaStage, prePhase) {
|
|
const result = {};
|
|
const result = {};
|
|
for (const stage of relaStage) {
|
|
for (const stage of relaStage) {
|
|
result.contract_tp = this.ctx.helper.add(result.contract_tp, stage.contract_tp);
|
|
result.contract_tp = this.ctx.helper.add(result.contract_tp, stage.contract_tp);
|
|
@@ -125,33 +125,53 @@ module.exports = app => {
|
|
result.pc_tp = this.ctx.helper.add(result.pc_tp, stage.pc_tp);
|
|
result.pc_tp = this.ctx.helper.add(result.pc_tp, stage.pc_tp);
|
|
|
|
|
|
const qdSum = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage);
|
|
const qdSum = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage);
|
|
- result.qd_contract_tp = qdSum.contract_tp;
|
|
|
|
- result.qd_qc_tp = qdSum.qc_tp;
|
|
|
|
- result.qd_pc_tp = qdSum.pc_tp;
|
|
|
|
|
|
+ result.qd_contract_tp = qdSum.contract_tp || 0;
|
|
|
|
+ result.qd_qc_tp = qdSum.qc_tp || 0;
|
|
|
|
+ result.qd_pc_tp = qdSum.pc_tp || 0;
|
|
|
|
|
|
const sumGcl = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
|
|
const sumGcl = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
|
|
const sumPc = await this.ctx.service.stageBillsPc.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
|
|
const sumPc = await this.ctx.service.stageBillsPc.getSumTotalPriceGcl(stage, '^[^0-9]*1[0-9]{2}(-|$)');
|
|
result.gather_100_tp = this.ctx.helper.sum([sumGcl.contract_tp, sumGcl.qc_tp, sumPc.pc_tp]);
|
|
result.gather_100_tp = this.ctx.helper.sum([sumGcl.contract_tp, sumGcl.qc_tp, sumPc.pc_tp]);
|
|
|
|
|
|
const bg = await this.ctx.service.stage.getChangeSubtotal(stage);
|
|
const bg = await this.ctx.service.stage.getChangeSubtotal(stage);
|
|
- result.common_bg_tp = bg.common;
|
|
|
|
- result.more_bg_tp = bg.more;
|
|
|
|
- result.great_bg_tp = bg.great;
|
|
|
|
|
|
+ result.common_bg_tp = bg.common || 0;
|
|
|
|
+ result.more_bg_tp = bg.more || 0;
|
|
|
|
+ result.great_bg_tp = bg.great || 0;
|
|
}
|
|
}
|
|
- result.gather_tp = this.ctx.helper.sum([result.contract_tp, result.qc_tp, result.pc_tp]);
|
|
|
|
- result.qd_gather_tp = this.ctx.helper.sum([result.qd_contract_tp, result.qd_qc_tp, result.qd_pc_tp]);
|
|
|
|
|
|
+ result.gather_tp = this.ctx.helper.sum([result.contract_tp, result.qc_tp, result.pc_tp]) || 0;
|
|
|
|
+ result.qd_gather_tp = this.ctx.helper.sum([result.qd_contract_tp, result.qd_qc_tp, result.qd_pc_tp]) || 0;
|
|
const bonusSum = await this.ctx.service.stageBonus.getSumTp(relaStage);
|
|
const bonusSum = await this.ctx.service.stageBonus.getSumTp(relaStage);
|
|
- result.bonus_positive_tp = bonusSum.positive_tp;
|
|
|
|
- result.bonus_negative_tp = bonusSum.negative_tp;
|
|
|
|
- result.bonus_tp = bonusSum.sum_tp;
|
|
|
|
|
|
+ result.bonus_positive_tp = bonusSum.positive_tp || 0;
|
|
|
|
+ result.bonus_negative_tp = bonusSum.negative_tp || 0;
|
|
|
|
+ result.bonus_tp = bonusSum.sum_tp || 0;
|
|
const jgclSum = await this.ctx.service.stageJgcl.getSumTp(relaStage);
|
|
const jgclSum = await this.ctx.service.stageJgcl.getSumTp(relaStage);
|
|
- result.jgcl_tp = jgclSum.sum_tp;
|
|
|
|
|
|
+ result.jgcl_tp = jgclSum.sum_tp || 0;
|
|
const otherSum = await this.ctx.service.stageOther.getSumTp(relaStage);
|
|
const otherSum = await this.ctx.service.stageOther.getSumTp(relaStage);
|
|
- result.other_tp = otherSum.sum_tp;
|
|
|
|
|
|
+ result.other_tp = otherSum.sum_tp || 0;
|
|
const safeProdSum = await this.ctx.service.stageSafeProd.getSumTp(relaStage);
|
|
const safeProdSum = await this.ctx.service.stageSafeProd.getSumTp(relaStage);
|
|
- result.safe_prod_tp = safeProdSum.sum_tp;
|
|
|
|
|
|
+ result.safe_prod_tp = safeProdSum.sum_tp || 0;
|
|
const tempLandSum = await this.ctx.service.stageTempLand.getSumTp(relaStage);
|
|
const tempLandSum = await this.ctx.service.stageTempLand.getSumTp(relaStage);
|
|
- result.temp_land_tp = tempLandSum.sum_tp;
|
|
|
|
|
|
+ result.temp_land_tp = tempLandSum.sum_tp || 0;
|
|
|
|
+
|
|
|
|
+ if (prePhase && prePhase.calc_base) {
|
|
|
|
+ result.pre_contract_tp = this.ctx.helper.add(prePhase.calc_base.contract_tp, prePhase.calc_base.pre_contract_tp);
|
|
|
|
+ result.pre_qc_tp = this.ctx.helper.add(prePhase.calc_base.qc_tp, prePhase.calc_base.pre_qc_tp);
|
|
|
|
+ result.pre_pc_tp = this.ctx.helper.add(prePhase.calc_base.pc_tp, prePhase.calc_base.pre_pc_tp);
|
|
|
|
+ result.pre_gather_tp = this.ctx.helper.add(prePhase.calc_base.gather_tp, prePhase.calc_base.pre_gather_tp);
|
|
|
|
+
|
|
|
|
+ result.pre_qd_contract_tp = this.ctx.helper.add(prePhase.calc_base.qd_contract_tp, prePhase.calc_base.pre_qd_contract_tp);
|
|
|
|
+ result.pre_qd_qc_tp = this.ctx.helper.add(prePhase.calc_base.qd_qc_tp, prePhase.calc_base.pre_qd_qc_tp);
|
|
|
|
+ result.pre_qd_pc_tp = this.ctx.helper.add(prePhase.calc_base.qd_pc_tp, prePhase.calc_base.pre_qd_pc_tp);
|
|
|
|
+ result.pre_qd_gather_tp = this.ctx.helper.add(prePhase.calc_base.qd_gather_tp, prePhase.calc_base.pre_qd_gather_tp);
|
|
|
|
+
|
|
|
|
+ result.pre_bonus_positive_tp = this.ctx.helper.add(prePhase.calc_base.bonus_positive_tp, prePhase.calc_base.pre_bonus_positive_tp);
|
|
|
|
+ result.pre_bonus_negative_tp = this.ctx.helper.add(prePhase.calc_base.bonus_negative_tp, prePhase.calc_base.pre_bonus_negative_tp);
|
|
|
|
+ result.pre_bonus_tp = this.ctx.helper.add(prePhase.calc_base.bonus_tp, prePhase.calc_base.pre_bonus_tp);
|
|
|
|
+ result.pre_jgcl_tp = this.ctx.helper.add(prePhase.calc_base.jgcl_tp, prePhase.calc_base.pre_jgcl_tp);
|
|
|
|
+ result.pre_other_tp = this.ctx.helper.add(prePhase.calc_base.other_tp, prePhase.calc_base.pre_other_tp);
|
|
|
|
+ result.pre_safe_prod_tp = this.ctx.helper.add(prePhase.calc_base.safe_prod_tp, prePhase.calc_base.pre_safe_prod_tp);
|
|
|
|
+ result.pre_temp_land_tp = this.ctx.helper.add(prePhase.calc_base.temp_land_tp, prePhase.calc_base.pre_temp_land_tp);
|
|
|
|
+ }
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -188,40 +208,40 @@ module.exports = app => {
|
|
cb.value = phasePay.calc_base.qc_tp;
|
|
cb.value = phasePay.calc_base.qc_tp;
|
|
break;
|
|
break;
|
|
case 'bqqdwc':
|
|
case 'bqqdwc':
|
|
- cb.value = phasePay.qd_gather_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.qd_gather_tp;
|
|
break;
|
|
break;
|
|
case 'bqqdht':
|
|
case 'bqqdht':
|
|
- cb.value = phasePay.qd_contract_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.qd_contract_tp;
|
|
break;
|
|
break;
|
|
case 'bqqdbg':
|
|
case 'bqqdbg':
|
|
- cb.value = phasePay.qd_qc_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.qd_qc_tp;
|
|
break;
|
|
break;
|
|
case 'ybbqwc':
|
|
case 'ybbqwc':
|
|
- cb.value = phasePay.gather_100_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.gather_100_tp;
|
|
break;
|
|
break;
|
|
case 'ybbqbg':
|
|
case 'ybbqbg':
|
|
- cb.value = phasePay.common_bg_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.common_bg_tp;
|
|
break;
|
|
break;
|
|
case 'jdbqbg':
|
|
case 'jdbqbg':
|
|
- cb.value = phasePay.more_bg_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.more_bg_tp;
|
|
break;
|
|
break;
|
|
case 'zdbqbg':
|
|
case 'zdbqbg':
|
|
- cb.value = phasePay.great_bg_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.great_bg_tp;
|
|
break;
|
|
break;
|
|
case 'bonus':
|
|
case 'bonus':
|
|
- cb.value = phasePay.bonus_positive_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.bonus_positive_tp;
|
|
break;
|
|
break;
|
|
case 'fine':
|
|
case 'fine':
|
|
- cb.value = phasePay.bonus_negative_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.bonus_negative_tp;
|
|
break;
|
|
break;
|
|
case 'jgcl':
|
|
case 'jgcl':
|
|
- cb.value = phasePay.jgcl_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.jgcl_tp;
|
|
break;
|
|
break;
|
|
case 'aqsc':
|
|
case 'aqsc':
|
|
- cb.value = phasePay.safe_prod_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.safe_prod_tp;
|
|
break;
|
|
break;
|
|
case 'lsyd':
|
|
case 'lsyd':
|
|
- cb.value = phasePay.temp_land_tp;
|
|
|
|
|
|
+ cb.value = phasePay.calc_base.temp_land_tp;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
cb.value = 0;
|
|
cb.value = 0;
|
|
@@ -234,7 +254,7 @@ module.exports = app => {
|
|
if (!tid) throw '数据错误';
|
|
if (!tid) throw '数据错误';
|
|
const user_id = this.ctx.session.sessionUser.accountId;
|
|
const user_id = this.ctx.session.sessionUser.accountId;
|
|
|
|
|
|
- const maxOrder = await this.getNewOrder();
|
|
|
|
|
|
+ const maxOrder = await this.getMaxOrder();
|
|
const data = {
|
|
const data = {
|
|
id: this.uuid.v4(), tid: tid, create_user_id: user_id, update_user_id: user_id,
|
|
id: this.uuid.v4(), tid: tid, create_user_id: user_id, update_user_id: user_id,
|
|
phase_order: maxOrder + 1, phase_date: phaseDate, memo,
|
|
phase_order: maxOrder + 1, phase_date: phaseDate, memo,
|
|
@@ -243,7 +263,8 @@ module.exports = app => {
|
|
};
|
|
};
|
|
if (await this._checkRelaStageConflict(relaStage, data)) throw '选择的计量期,已被调用,请刷新页面后选择计量期新增合同支付';
|
|
if (await this._checkRelaStageConflict(relaStage, data)) throw '选择的计量期,已被调用,请刷新页面后选择计量期新增合同支付';
|
|
|
|
|
|
- const calcBase = await this.getCalcBase(relaStage);
|
|
|
|
|
|
+ const prePhase = maxOrder > 0 ? await this.getPhasePayByOrder(tid, maxOrder) : null;
|
|
|
|
+ const calcBase = await this.getCalcBase(relaStage, prePhase);
|
|
data.calc_base = JSON.stringify(calcBase);
|
|
data.calc_base = JSON.stringify(calcBase);
|
|
const transaction = await this.db.beginTransaction();
|
|
const transaction = await this.db.beginTransaction();
|
|
try {
|
|
try {
|
|
@@ -260,7 +281,9 @@ module.exports = app => {
|
|
}
|
|
}
|
|
|
|
|
|
async refreshCalcBase(phasePay) {
|
|
async refreshCalcBase(phasePay) {
|
|
- const calcBase = await this.getCalcBase(relaStage);
|
|
|
|
|
|
+ const prePhase = phasePay.phase_order > 1 ? await this.getPhasePayByOrder(phasePay.tid, phasePay.phase_order - 1) : null;
|
|
|
|
+ const relaStage = await this.ctx.service.stage.getAllDataByCondition({ where: { tid: phasePay.tid, order: phasePay.rela_stage.map(x => { return x.stage_order; }) } });
|
|
|
|
+ const calcBase = await this.getCalcBase(relaStage, prePhase);
|
|
const conn = await this.db.beginTransaction();
|
|
const conn = await this.db.beginTransaction();
|
|
try {
|
|
try {
|
|
await conn.update(this.tableName, {
|
|
await conn.update(this.tableName, {
|
|
@@ -270,6 +293,7 @@ module.exports = app => {
|
|
});
|
|
});
|
|
phasePay.calc_base = calcBase;
|
|
phasePay.calc_base = calcBase;
|
|
await this.ctx.service.phasePayDetail.calculateSave(phasePay, conn);
|
|
await this.ctx.service.phasePayDetail.calculateSave(phasePay, conn);
|
|
|
|
+ await conn.commit();
|
|
} catch(err) {
|
|
} catch(err) {
|
|
await conn.rollback();
|
|
await conn.rollback();
|
|
throw err;
|
|
throw err;
|
|
@@ -277,7 +301,8 @@ module.exports = app => {
|
|
}
|
|
}
|
|
async resetRelaStageId(phasePay, relaStage) {
|
|
async resetRelaStageId(phasePay, relaStage) {
|
|
if (await this._checkRelaStageConflict(relaStage, phasePay)) throw '选择的计量期,已被调用,请刷新页面后选择计量期新增合同支付';
|
|
if (await this._checkRelaStageConflict(relaStage, phasePay)) throw '选择的计量期,已被调用,请刷新页面后选择计量期新增合同支付';
|
|
- const calcBase = await this.getCalcBase(relaStage);
|
|
|
|
|
|
+ const prePhase = prePhase.phase_order > 1 ? await this.getPhasePayByOrder(phasePay.tid, phasePay.phase_order - 1) : null;
|
|
|
|
+ const calcBase = await this.getCalcBase(relaStage, prePhase);
|
|
const rela_stage = relaStage.map(s => { return {stage_id: s.id, stage_order: s.order}; });
|
|
const rela_stage = relaStage.map(s => { return {stage_id: s.id, stage_order: s.order}; });
|
|
const conn = await this.db.beginTransaction();
|
|
const conn = await this.db.beginTransaction();
|
|
try {
|
|
try {
|