|
@@ -9,6 +9,27 @@
|
|
|
*/
|
|
|
|
|
|
const audit = require('../const/audit').common;
|
|
|
+const calcBase = [
|
|
|
+ {name: '签约合同价', code: 'htj', sort: 10},
|
|
|
+ {name: '暂列金额', code: 'zlje', sort: 2},
|
|
|
+ {name: '签约合同价(不含暂列金)', code: 'htjszl', sort: 1},
|
|
|
+ {name: '签约开工预付款', code: 'kgyfk', sort: 2},
|
|
|
+ {name: '签约材料预付款', code: 'clyfk', sort: 2},
|
|
|
+ {name: '本期完成计量', code: 'bqwc', limit: true, sort: 10},
|
|
|
+ {name: '本期合同计量', code: 'bqht', limit: true, sort: 10},
|
|
|
+ {name: '本期变更计量', code: 'bqbg', limit: true, sort: 10},
|
|
|
+ {name: '本期清单完成计量', code: 'bqqdwc', limit: true, sort: 10},
|
|
|
+ {name: '本期清单合同计量', code: 'bqqdht', limit: true, sort: 10},
|
|
|
+ {name: '本期清单变更计量', code: 'bqqdbg', limit: true, sort: 10},
|
|
|
+ {name: '本期一般变更计量', code: 'ybbqbg', limit: true, sort: 5},
|
|
|
+ {name: '本期较大变更计量', code: 'jdbqbg', limit: true, sort: 5},
|
|
|
+ {name: '本期重大变更计量', code: 'zdbqbg', limit: true, sort: 5},
|
|
|
+ {name: '100章本期完成计量', code: 'ybbqwc', limit: true, sort: 1},
|
|
|
+ {name: '本期应付', code: 'bqyf', limit: true, ptNormalLimit: true, sort: 20},
|
|
|
+ {name: '奖金', code: 'bonus', limit: true, sort: 1},
|
|
|
+ {name: '罚金', code: 'fine', limit: true, sort: 1},
|
|
|
+ {name: '甲供材料', code: 'jgcl', limit: true, sort: 1},
|
|
|
+];
|
|
|
|
|
|
module.exports = app => {
|
|
|
class PhasePay extends app.BaseService {
|
|
@@ -25,6 +46,8 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
analysisPhasePay(data) {
|
|
|
+ if (!data) return;
|
|
|
+
|
|
|
const datas = data instanceof Array ? data : [data];
|
|
|
datas.forEach(x => {
|
|
|
x.rela_stage = x.rela_stage ? JSON.parse(x.rela_stage) : [];
|
|
@@ -42,7 +65,6 @@ module.exports = app => {
|
|
|
x.end_cut_tp = helper.add(x.cut_tp, x.pre_cut_tp);
|
|
|
x.end_sf_tp = helper.add(x.sf_tp, x.pre_sf_tp);
|
|
|
x.end_yf_tp = helper.add(x.yf_tp, x.pre_yf_tp);
|
|
|
- if (thousandth)
|
|
|
for (const prop in x) {
|
|
|
if (prop.indexOf('_tp') > 0) {
|
|
|
x['display_' + prop] = formatNum(x[prop]);
|
|
@@ -77,10 +99,6 @@ module.exports = app => {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- async loadUser(phasePay) {
|
|
|
- // todo 加载审批人
|
|
|
- }
|
|
|
-
|
|
|
async getNewOrder(tid) {
|
|
|
const sql = 'SELECT Max(`phase_order`) As max_order FROM ' + this.tableName + ' Where `tid` = ?';
|
|
|
const sqlParam = [tid];
|
|
@@ -89,7 +107,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async _checkRelaStageConflict(relaStage, phasePay) {
|
|
|
- const pays = this.getAllPhasePay(phasePay.tid);
|
|
|
+ const pays = await this.getAllPhasePay(phasePay.tid);
|
|
|
for (const p of pays) {
|
|
|
if (p.id === phasePay.id) continue;
|
|
|
for (const s of relaStage) {
|
|
@@ -100,14 +118,123 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async getCalcBase(relaStage) {
|
|
|
- // todo 获取计算基数
|
|
|
+ const result = {};
|
|
|
+ for (const stage of relaStage) {
|
|
|
+ result.contract_tp = this.ctx.helper.add(result.contract_tp, stage.contract_tp);
|
|
|
+ result.qc_tp = this.ctx.helper.add(result.contract_tp, stage.qc_tp);
|
|
|
+ result.pc_tp = this.ctx.helper.add(result.pc_tp, stage.pc_tp);
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+ 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}(-|$)');
|
|
|
+ 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);
|
|
|
+ result.common_bg_tp = bg.common;
|
|
|
+ result.more_bg_tp = bg.more;
|
|
|
+ result.great_bg_tp = bg.great;
|
|
|
+ }
|
|
|
+ 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]);
|
|
|
+ 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;
|
|
|
+ const jgclSum = await this.ctx.service.stageJgcl.getSumTp(relaStage);
|
|
|
+ result.jgcl_tp = jgclSum.sum_tp;
|
|
|
+ const otherSum = await this.ctx.service.stageOther.getSumTp(relaStage);
|
|
|
+ result.other_tp = otherSum.sum_tp;
|
|
|
+ const safeProdSum = await this.ctx.service.stageSafeProd.getSumTp(relaStage);
|
|
|
+ result.safe_prod_tp = safeProdSum.sum_tp;
|
|
|
+ const tempLandSum = await this.ctx.service.stageTempLand.getSumTp(relaStage);
|
|
|
+ result.temp_land_tp = tempLandSum.sum_tp;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取 当期的 计算基数
|
|
|
+ * @return {Promise<any>}
|
|
|
+ */
|
|
|
+ getPhasePayCalcBase(phasePay, tenderInfo) {
|
|
|
+ const payCalcBase = JSON.parse(JSON.stringify(calcBase));
|
|
|
+ for (const cb of payCalcBase) {
|
|
|
+ switch (cb.code) {
|
|
|
+ case 'htj':
|
|
|
+ cb.value = tenderInfo.deal_param.contractPrice;
|
|
|
+ break;
|
|
|
+ case 'zlje':
|
|
|
+ cb.value = tenderInfo.deal_param.zanLiePrice;
|
|
|
+ break;
|
|
|
+ case 'htjszl':
|
|
|
+ cb.value = this.ctx.helper.sub(tenderInfo.deal_param.contractPrice, tenderInfo.deal_param.zanLiePrice);
|
|
|
+ break;
|
|
|
+ case 'kgyfk':
|
|
|
+ cb.value = tenderInfo.deal_param.startAdvance;
|
|
|
+ break;
|
|
|
+ case 'clyfk':
|
|
|
+ cb.value = tenderInfo.deal_param.materialAdvance;
|
|
|
+ break;
|
|
|
+ case 'bqwc':
|
|
|
+ cb.value = phasePay.calc_base.gather_tp;
|
|
|
+ break;
|
|
|
+ case 'bqht':
|
|
|
+ cb.value = phasePay.calc_base.contract_tp;
|
|
|
+ break;
|
|
|
+ case 'bqbg':
|
|
|
+ cb.value = phasePay.calc_base.qc_tp;
|
|
|
+ break;
|
|
|
+ case 'bqqdwc':
|
|
|
+ cb.value = phasePay.qd_gather_tp;
|
|
|
+ break;
|
|
|
+ case 'bqqdht':
|
|
|
+ cb.value = phasePay.qd_contract_tp;
|
|
|
+ break;
|
|
|
+ case 'bqqdbg':
|
|
|
+ cb.value = phasePay.qd_qc_tp;
|
|
|
+ break;
|
|
|
+ case 'ybbqwc':
|
|
|
+ cb.value = phasePay.gather_100_tp;
|
|
|
+ break;
|
|
|
+ case 'ybbqbg':
|
|
|
+ cb.value = phasePay.common_bg_tp;
|
|
|
+ break;
|
|
|
+ case 'jdbqbg':
|
|
|
+ cb.value = phasePay.more_bg_tp;
|
|
|
+ break;
|
|
|
+ case 'zdbqbg':
|
|
|
+ cb.value = phasePay.great_bg_tp;
|
|
|
+ break;
|
|
|
+ case 'bonus':
|
|
|
+ cb.value = phasePay.bonus_positive_tp;
|
|
|
+ break;
|
|
|
+ case 'fine':
|
|
|
+ cb.value = phasePay.bonus_negative_tp;
|
|
|
+ break;
|
|
|
+ case 'jgcl':
|
|
|
+ cb.value = phasePay.jgcl_tp;
|
|
|
+ break;
|
|
|
+ case 'aqsc':
|
|
|
+ cb.value = phasePay.safe_prod_tp;
|
|
|
+ break;
|
|
|
+ case 'lsyd':
|
|
|
+ cb.value = phasePay.temp_land_tp;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ cb.value = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return payCalcBase;
|
|
|
}
|
|
|
|
|
|
async add(tid, relaStage, phaseDate, memo) {
|
|
|
if (!tid) throw '数据错误';
|
|
|
const user_id = this.ctx.session.sessionUser.accountId;
|
|
|
|
|
|
- const maxOrder = await this.getNewOrder(tid);
|
|
|
+ const maxOrder = await this.getNewOrder();
|
|
|
const data = {
|
|
|
id: this.uuid.v4(), tid: tid, create_user_id: user_id, update_user_id: user_id,
|
|
|
phase_order: maxOrder + 1, phase_date: phaseDate, memo,
|
|
@@ -123,7 +250,7 @@ module.exports = app => {
|
|
|
const result = await transaction.insert(this.tableName, data);
|
|
|
if (result.affectedRows !== 1) throw '新增合同支付失败';
|
|
|
|
|
|
- await this.ctx.service.phasePayDetail.initPhaseData(data);
|
|
|
+ await this.ctx.service.phasePayDetail.initPhaseData(transaction, data);
|
|
|
await transaction.commit();
|
|
|
return data;
|
|
|
} catch(err) {
|
|
@@ -133,7 +260,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async refreshCalcBase(id) {
|
|
|
- const curPay = this.getPhasePay(id);
|
|
|
+ const curPay = await this.getPhasePay(id);
|
|
|
if (!curPay) throw '合同支付不存在, 请刷新页面重试';
|
|
|
|
|
|
const calcBase = await this.getCalcBase(relaStage);
|
|
@@ -146,7 +273,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async resetRelaStageId(id, relaStage) {
|
|
|
- const curPay = this.getPhasePay(id);
|
|
|
+ const curPay = await this.getPhasePay(id);
|
|
|
if (!curPay) throw '合同支付不存在, 请刷新页面重试';
|
|
|
|
|
|
if (await this._checkRelaStageConflict(relaStage, curPay)) throw '选择的计量期,已被调用,请刷新页面后选择计量期新增合同支付';
|
|
@@ -159,6 +286,53 @@ module.exports = app => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async loadUser(phasePay) {
|
|
|
+ // todo 加载审批人
|
|
|
+ phasePay.user = await this.ctx.service.projectAccount.getAccountInfoById(phasePay.create_user_id);
|
|
|
+ phasePay.curAuditors = [];
|
|
|
+ // phasePay.curAuditors = await this.ctx.service.phasePayAudit.getAllDataByCondition({
|
|
|
+ // where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_status: audit.status.checking }
|
|
|
+ // });
|
|
|
+ phasePay.curAuditorIds = phasePay.curAuditors.map(x => { return x.audit_id; });
|
|
|
+ phasePay.flowAuditors = phasePay.curAuditors.length === 0 ? []
|
|
|
+ : await this.ctx.service.phasePayAudit.getAllDataByCondition({
|
|
|
+ where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_sort: phasePay.curAuditors[0].audit_sort }
|
|
|
+ });
|
|
|
+ phasePay.flowAuditorIds = phasePay.curAuditors.map(x => { return x.audit_id; });
|
|
|
+ }
|
|
|
+ async doCheckPhase(phasePay) {
|
|
|
+ await this.loadUser(phasePay);
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
+
|
|
|
+ if (phasePay.audit_status === audit.status.uncheck) {
|
|
|
+ phasePay.readOnly = accountId !== phasePay.create_user_id;
|
|
|
+ phasePay.curTimes = phasePay.audit_times;
|
|
|
+ phasePay.curOrder = 0;
|
|
|
+ } else if (phasePay.audit_status === audit.status.checkNo) {
|
|
|
+ phasePay.readOnly = accountId !== phasePay.create_user_id;
|
|
|
+ if (!phasePay.readOnly) {
|
|
|
+ phasePay.curTimes = phasePay.times;
|
|
|
+ phasePay.curOrder = 0;
|
|
|
+ } else {
|
|
|
+ const checkNoAudit = await this.service.phasePayAudit.getDataByCondition({
|
|
|
+ phase_id: phasePay.id, audit_times: phasePay.audit_times - 1, status: audit.status.checkNo,
|
|
|
+ });
|
|
|
+ phasePay.curTimes = phasePay.times - 1;
|
|
|
+ phasePay.curOrder = checkNoAudit.audit_order;
|
|
|
+ }
|
|
|
+ } else if (phasePay.audit_status === audit.status.checked) {
|
|
|
+ phasePay.readOnly = true;
|
|
|
+ phasePay.curTimes = phasePay.audit_times;
|
|
|
+ phasePay.curOrder = phasePay.audit_max_order;
|
|
|
+ } else {
|
|
|
+ // 会签,会签人部分审批通过时,只读,但是curOrder需按原来的取值
|
|
|
+ phasePay.curTimes = phasePay.audit_times;
|
|
|
+ phasePay.curOrder = phasePay.flowAuditorIds.indexOf(accountId) < 0 ? phasePay.curAuditors[0].order : phasePay.curAuditors[0].order - 1;
|
|
|
+ phasePay.readOnly = !_.isEqual(stage.flowAuditorIds, stage.curAuditorIds);
|
|
|
+ phasePay.canCheck = phasePay.readOnly && stage.curAuditorIds.indexOf(accountId) > 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return PhasePay;
|