|
|
@@ -169,21 +169,86 @@ class BudgetFinal {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- async _loadTender(id) {
|
|
|
+
|
|
|
+ async _getValidStages(tenderId, sort = 'desc', checked = false) {
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
+ const condition = { tid: tenderId };
|
|
|
+ if (checked) condition.status = auditConst.stage.status.checked;
|
|
|
+ const stages = await this.ctx.service.stage.getAllDataByCondition({ where: condition, orders: [['order', sort]] });
|
|
|
+ return stages.filter(s => { return s.status !== auditConst.stage.status.uncheck || s.user_id === accountId; });
|
|
|
+ }
|
|
|
+ async _filterOrder(id, order, checked) {
|
|
|
+ const stages = await this._getValidStages(id, 'desc', checked);
|
|
|
+ const stage = this.ctx.helper._.find(stages, { order });
|
|
|
+ if (stage) await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ return { type: 'stage', stage, filter: `第${order}期` };
|
|
|
+ }
|
|
|
+ async _filterMonth(id, month, checked) {
|
|
|
+ const stages = await this._getValidStages(id, 'desc', checked);
|
|
|
+ const stage = this.ctx.helper._.find(stages, { s_time: month });
|
|
|
+ if (stage) await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ return { type: 'stage', stage, filter: month };
|
|
|
+ }
|
|
|
+ async _filterFinal(id, checked) {
|
|
|
+ const stages = await this._getValidStages(id, 'desc', checked);
|
|
|
+ const stage = stages[0];
|
|
|
+ if (stage) await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ return { type: 'stage', stage, filter: stage ? `第${stage.order}期` : '' };
|
|
|
+ }
|
|
|
+ async _filterCheckedFinal(id, checked) {
|
|
|
+ const stages = await this._getValidStages(id, 'desc', checked);
|
|
|
+ const checkedStages = stages.filter(x => { return x.status === status.checked; });
|
|
|
+ const stage = checkedStages[0];
|
|
|
+ if (stage && stage.status !== auditConst.stage.status.checked) await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ return { type: 'stage', stage, filter: stage ? `第${stage.order}期` : '' };
|
|
|
+ }
|
|
|
+ async _filterUnderMonth(id, month, checked) {
|
|
|
+ const stages = await this._getValidStages(id, 'desc', checked);
|
|
|
+ let stage = this.ctx.helper._.find(stages, { s_time: month });
|
|
|
+ if (!stage) {
|
|
|
+ const checkTime = this.ctx.moment(month);
|
|
|
+ for (const s of stages) {
|
|
|
+ const rela_time = this.ctx.moment(s.s_time);
|
|
|
+ if (rela_time.isBefore(checkTime)) {
|
|
|
+ stage = s;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (stage) await this.ctx.service.stage.doCheckStage(stage);
|
|
|
+ return { type: 'stage', stage, filter: stage ? stage.s_time : '' };
|
|
|
+ }
|
|
|
+ async _filterStage(tender, stageInfo) {
|
|
|
+ switch(stageInfo.type) {
|
|
|
+ case 'stage':
|
|
|
+ return await this._filterOrder(tender, stageInfo.stage, stageInfo.checked);
|
|
|
+ case 'month':
|
|
|
+ return await this._filterMonth(tender, stageInfo.month, stageInfo.checked);
|
|
|
+ case 'final':
|
|
|
+ return await this._filterFinal(tender, stageInfo.checked);
|
|
|
+ case 'checked-final':
|
|
|
+ return await this._filterCheckedFinal(tender, stageInfo.checked);
|
|
|
+ case 'under-month':
|
|
|
+ return await this._filterUnderMonth(tender, stageInfo.month, stageInfo.checked);
|
|
|
+ default:
|
|
|
+ return await this._filterFinal(tender, stageInfo.checked);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ async _loadTender(id, stageInfo) {
|
|
|
const helper = this.ctx.helper;
|
|
|
const bills = await this.ctx.service.ledger.getFinalData(id, ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf',
|
|
|
'code', 'b_code', 'name', 'unit', 'unit_price', 'dgn_qty1', 'dgn_qty2', 'total_price']);
|
|
|
|
|
|
const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(id);
|
|
|
// 使用最新一期对比
|
|
|
- const stage = await this.ctx.service.stage.getLastestStage(id);
|
|
|
- if (!stage) {
|
|
|
+ const stageFilter = await this._filterStage(id, stageInfo);
|
|
|
+ if (!stageFilter.stage) {
|
|
|
helper.assignRelaData(bills, [
|
|
|
{ data: dgnData, fields: ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'], prefix: '', relaId: 'id' },
|
|
|
]);
|
|
|
this.final.tender_info.push({ id, stageCount: 0 });
|
|
|
- } else if (stage.status === auditConst.stage.status.checked) {
|
|
|
- const finalBills = await this.ctx.service.stageBillsFinal.getFinalData({id}, stage.order);
|
|
|
+ } else if (stageFilter.stage.status === auditConst.stage.status.checked) {
|
|
|
+ const finalBills = await this.ctx.service.stageBillsFinal.getFinalData({ id }, stageFilter.stage.order);
|
|
|
helper.assignRelaData(bills, [
|
|
|
{ data: finalBills, fields: ['contract_tp', 'qc_tp'], prefix: 'end_', relaId: 'lid' },
|
|
|
{ data: dgnData, fields: ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'], prefix: '', relaId: 'id' },
|
|
|
@@ -191,14 +256,13 @@ class BudgetFinal {
|
|
|
bills.forEach(b => {
|
|
|
b.end_gather_tp = helper.add(b.end_qc_tp, b.end_contract_tp);
|
|
|
});
|
|
|
- this.final.tender_info.push({ id, stageOrder: stage.order });
|
|
|
+ this.final.tender_info.push({ id, stageOrder: stageFilter.stage.order });
|
|
|
} else {
|
|
|
- await this.ctx.service.stage.doCheckStage(stage);
|
|
|
- const curBills = stage.readOnly
|
|
|
- ? await this.ctx.service.stageBills.getAuditorStageData2(id, stage.id, stage.curTimes, stage.curOrder)
|
|
|
- : await this.ctx.service.stageBills.getLastestStageData2(id, stage.id);
|
|
|
- const preBills = stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData({id}, stage.preCheckedStage.order) : [];
|
|
|
- const bpcData = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stage.id } });
|
|
|
+ const curBills = stageFilter.stage.readOnly
|
|
|
+ ? await this.ctx.service.stageBills.getAuditorStageData2(id, stageFilter.stage.id, stageFilter.stage.curTimes, stageFilter.stage.curOrder)
|
|
|
+ : await this.ctx.service.stageBills.getLastestStageData2(id, stageFilter.stage.id);
|
|
|
+ const preBills = stageFilter.stage.preCheckedStage ? await this.ctx.service.stageBillsFinal.getFinalData({ id }, stageFilter.stage.preCheckedStage.order) : [];
|
|
|
+ const bpcData = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stageFilter.stage.id } });
|
|
|
helper.assignRelaData(bills, [
|
|
|
{ data: curBills, fields: ['contract_tp', 'qc_tp'], prefix: '', relaId: 'lid' },
|
|
|
{ data: preBills, fields: ['contract_tp', 'qc_tp'], prefix: 'pre_', relaId: 'lid' },
|
|
|
@@ -210,7 +274,7 @@ class BudgetFinal {
|
|
|
b.end_qc_tp = helper.sum([b.qc_tp, b.pre_qc_tp, b.qc_pc_tp]);
|
|
|
b.end_gather_tp = helper.sum([b.qc_tp, b.contract_tp, b.pre_qc_tp, b.pre_contract_tp, b.pc_tp]);
|
|
|
});
|
|
|
- this.final.tender_info.push({ id, stageOrder: stage.order, stageStatus: stage.status, stageFlow: stage.curTimes + '-' + stage.curOrder });
|
|
|
+ this.final.tender_info.push({ id, stageOrder: stageFilter.stage.order, stageStatus: stageFilter.stage.status, stageFlow: stageFilter.stage.curTimes + '-' + stageFilter.stage.curOrder });
|
|
|
}
|
|
|
const tree = new BillsTree(this.ctx, this.tenderSetting);
|
|
|
tree.loadDatas(bills);
|
|
|
@@ -239,6 +303,10 @@ class BudgetFinal {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ async _loadDeal(deal) {
|
|
|
+ // todo
|
|
|
+ }
|
|
|
+
|
|
|
async _afterLoad() {
|
|
|
const helper = this.ctx.helper;
|
|
|
const checkGaiExist = this.finalTree.datas.findIndex(x => {
|
|
|
@@ -326,19 +394,20 @@ class BudgetFinal {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
- async doFinal(budget, final) {
|
|
|
+ async doFinal(budget, final, stage) {
|
|
|
this.budget = budget;
|
|
|
this.final = final;
|
|
|
this.finalTree.checkField = budget.final_type.split('_');
|
|
|
|
|
|
for (const t of final.tender) {
|
|
|
- await this._loadTender(t);
|
|
|
+ await this._loadTender(t, stage);
|
|
|
}
|
|
|
await this._loadCtrl(budget);
|
|
|
await this._loadZb(budget);
|
|
|
await this._loadYu(budget);
|
|
|
await this._loadGai(budget);
|
|
|
await this._loadGu(budget);
|
|
|
+ await this._loadDeal(final.deal);
|
|
|
this._afterLoad();
|
|
|
return this.getFinalData();
|
|
|
}
|