|
|
@@ -0,0 +1,134 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+const RptMemBase = require('./base');
|
|
|
+const bindData = {};
|
|
|
+const Ledger = require('../ledger');
|
|
|
+
|
|
|
+class rptMemChange extends RptMemBase {
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx, bindData);
|
|
|
+ }
|
|
|
+
|
|
|
+ async doCheckSafeStage(stage_id) {
|
|
|
+ if (this.ctx.safeStage) return;
|
|
|
+ this.ctx.safeStage = await this.ctx.service.safeStage.getDataById(stage_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ async doCheckTender(tenderId) {
|
|
|
+ if (this.ctx.tender) return;
|
|
|
+ this.ctx.tender = { id: tenderId };
|
|
|
+ this.ctx.tender.data = await this.ctx.service.tender.getTender(tenderId);
|
|
|
+ this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
|
|
|
+ }
|
|
|
+
|
|
|
+ async doBeforeLoadReport(params) {
|
|
|
+ await this.doCheckSafeStage(params.safe_stage_id);
|
|
|
+ await this.doCheckTender(this.ctx.safeStage.tid);
|
|
|
+ }
|
|
|
+
|
|
|
+ async getSafeBills() {
|
|
|
+ const bills = this.ctx.detail.readOnly
|
|
|
+ ? await this.ctx.service.safeStageBills.getReadData(this.ctx.safeStage)
|
|
|
+ : await this.ctx.service.safeStageBills.getEditData(this.ctx.safeStage);
|
|
|
+ const setting = {
|
|
|
+ id: 'tree_id',
|
|
|
+ pid: 'tree_pid',
|
|
|
+ order: 'tree_order',
|
|
|
+ level: 'tree_level',
|
|
|
+ isLeaf: 'tree_is_leaf',
|
|
|
+ fullPath: 'tree_full_path',
|
|
|
+ rootId: -1,
|
|
|
+ calcFields: ['pre_tp', 'cur_tp', 'end_tp'],
|
|
|
+ };
|
|
|
+ const billsTree = new Ledger.billsTree(this.ctx, setting);
|
|
|
+ billsTree.loadDatas(bills);
|
|
|
+ billsTree.calculateAll();
|
|
|
+ return billsTree.getDefaultDatas();
|
|
|
+ }
|
|
|
+ _analysisCompareData(datas, roles){
|
|
|
+ const findHis = function (role, history) {
|
|
|
+ let his = null;
|
|
|
+ for (const h of history) {
|
|
|
+ if (h.times < role.times || (h.audit_times === role.audit_times && h.active_order <= role.active_order)) {
|
|
|
+ his = h;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return his;
|
|
|
+ };
|
|
|
+ for (const d of datas) {
|
|
|
+ if (!d.tree_is_leaf) continue;
|
|
|
+ d.his_qty = [];
|
|
|
+ d.his_tp = [];
|
|
|
+ d.cur_his.sort((x, y) => { return x.audit_times === y.audit_times ? x.active_order - y.active_order : x.audit_times - y.audit_times; });
|
|
|
+ for (const r of roles) {
|
|
|
+ if (r.latest) {
|
|
|
+ d[`r_qty_${r.order}`] = d.cur_qty;
|
|
|
+ d[`r_tp_${r.order}`] = d.cur_tp;
|
|
|
+ d.his_qty.push(d.cur_qty);
|
|
|
+ d.his_tp.push(d.cur_tp);
|
|
|
+ } else {
|
|
|
+ const rHis = findHis(r, d.cur_his);
|
|
|
+ if (rHis) {
|
|
|
+ d[`r_qty_${r.order}`] = rHis.qty;
|
|
|
+ d[`r_tp_${r.order}`] = rHis.tp;
|
|
|
+ }
|
|
|
+ d.his_qty.push(rHis ? rHis.qty : 0);
|
|
|
+ d.his_tp.push(rHis ? rHis.tp : 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ async getSafeBillsCompare() {
|
|
|
+ const bills = await this.ctx.service.safeStageBills.getCompareData(this.ctx.safeStage);
|
|
|
+ const roles = await this.ctx.service.safeStageAudit.getViewFlow(this.ctx.safeStage);
|
|
|
+ this._analysisCompareData(bills, roles);
|
|
|
+ const setting = {
|
|
|
+ id: 'tree_id',
|
|
|
+ pid: 'tree_pid',
|
|
|
+ order: 'tree_order',
|
|
|
+ level: 'tree_level',
|
|
|
+ isLeaf: 'tree_is_leaf',
|
|
|
+ fullPath: 'tree_full_path',
|
|
|
+ rootId: -1,
|
|
|
+ };
|
|
|
+ setting.calcFields = roles.map(x => { return `r_tp_${x.order}`});
|
|
|
+ setting.calcFields.push('pre_tp');
|
|
|
+ const compareTree = new Ledger.billsTree(this.ctx, setting);
|
|
|
+ compareTree.loadDatas(bills);
|
|
|
+ compareTree.calculateAll();
|
|
|
+ return compareTree.getDefaultDatas();
|
|
|
+ }
|
|
|
+
|
|
|
+ getCommonData(params, tableName, fields, customDefine, customSelect) {
|
|
|
+ switch (tableName) {
|
|
|
+ case 'mem_project':
|
|
|
+ return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
|
|
|
+ case 'mem_tender':
|
|
|
+ return [this.ctx.tender.data];
|
|
|
+ case 'mem_tender_info':
|
|
|
+ return [this.ctx.tender.info];
|
|
|
+ case 'mem_safe_stage':
|
|
|
+ return [this.ctx.safeStage];
|
|
|
+ case 'mem_safe_stage_audit':
|
|
|
+ return this.ctx.service.safeStageAudit.getFinalUniqAuditors(this.ctx.safeStage);
|
|
|
+ case 'mem_safe_stage_bills':
|
|
|
+ return this.getSafeBills();
|
|
|
+ case 'mem_safe_stage_bills_compare':
|
|
|
+ return this.getSafeBillsCompare();
|
|
|
+ default:
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = rptMemChange;
|