Browse Source

变更申请、变更立项、变更方案,报表数据源

MaiXinRong 1 year ago
parent
commit
e24abdb712
4 changed files with 262 additions and 1 deletions
  1. 80 0
      app/lib/rm/change_apply.js
  2. 92 0
      app/lib/rm/change_plan.js
  3. 61 0
      app/lib/rm/change_project.js
  4. 29 1
      app/service/report.js

+ 80 - 0
app/lib/rm/change_apply.js

@@ -0,0 +1,80 @@
+'use strict';
+
+/**
+ * 变更申请
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const RptMemBase = require('./base');
+const bindData = {};
+
+class rptMemChange extends RptMemBase {
+    constructor(ctx) {
+        super(ctx, bindData);
+    }
+
+    async doCheckChangeApply(id) {
+        if (this.ctx.change_apply) return;
+        this.ctx.change_apply = await this.ctx.service.change.getDataById(id);
+    }
+
+    async doCheckTender(tenderId) {
+        if (this.ctx.tender) return;
+        this.ctx.tender = { id: tenderId };
+        this.ctx.tender.data = await this.ctx.service.getTender(tenderId);
+        this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
+    }
+
+    async doBeforeLoadReport(params) {
+        await this.doCheckChangeApply(params.change_apply_id);
+        await this.doCheckTender(this.ctx.change_apply.tid);
+    }
+
+    async _getChangeApplyBills() {
+        const helper = this.ctx.helper;
+        const decimal = this.ctx.tender.info.decimal;
+        const apply = this.ctx.change_apply;
+
+        const bills = await this.ctx.service.changeApplyList.getAllDataByCondition({ where: { caid: apply.id} });
+        bills.forEach(x => {
+            const a_decimal = apply.decimal ? JSON.stringify(apply.decimal) : { tp: decimal.tp, up: decimal.up };
+            x.o_tp = helper.mul(x.oamount, x.unit_price, a_decimal.tp);
+            x.c_tp = helper.mul(x.camount, x.unit_price, a_decimal.tp);
+        });
+        bills.sort(function(a, b ) {
+            return helper.compareCode(a.code, b.code);
+        });
+        return bills;
+    }
+
+    async _getChangeApplyAudit() {
+        const changeAudit = await this.ctx.service.changeApplyAudit.getAllDataByCondition({ where: { caid: this.ctx.change_apply.id, times: this.ctx.change_apply.times }});
+        return this.ctx.helper.filterLastestData(changeAudit, ['aid']);
+    }
+
+    getCommonData(params, tableName, fields, customDefine, customSelect) {
+        switch (tableName) {
+            case 'mem_change_apply':
+                return this.ctx.change_apply;
+            case 'mem_change_apply_bills':
+                return this._getChangeApplyBills();
+            case 'mem_change_apply_audit':
+                return this._getChangeApplyAudit();
+            case 'mem_change_apply_att':
+                return this.ctx.service.changeApplyAtt.getChangeAttachment(this.ctx.change_apply.id);
+            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;
+            default:
+                return [];
+        }
+    }
+}
+
+module.exports = rptMemChange;

+ 92 - 0
app/lib/rm/change_plan.js

@@ -0,0 +1,92 @@
+'use strict';
+
+/**
+ * 变更方案
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const RptMemBase = require('./base');
+const bindData = {};
+
+class rptMemChange extends RptMemBase {
+    constructor(ctx) {
+        super(ctx, bindData);
+    }
+
+    async doCheckChangePlan(id) {
+        if (this.ctx.change_plan) return;
+        this.ctx.change_plan = await this.ctx.service.change.getDataById(id);
+    }
+
+    async doCheckTender(tenderId) {
+        if (this.ctx.tender) return;
+        this.ctx.tender = { id: tenderId };
+        this.ctx.tender.data = await this.ctx.service.getTender(tenderId);
+        this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
+    }
+
+    async doBeforeLoadReport(params) {
+        await this.doCheckChangePlan(params.change_plan_id);
+        await this.doCheckTender(this.ctx.change_plan.tid);
+    }
+
+    async _getChangePlanBills() {
+        const helper = this.ctx.helper;
+        const decimal = this.ctx.tender.info.decimal;
+        const plan = this.ctx.change_plan;
+
+        const bills = await this.ctx.service.changePlanList.getAllDataByCondition({ where: { cpid: this.ctx.change_plan.id} });
+        bills.forEach(x => {
+            const p_decimal = plan.decimal ? JSON.stringify(plan.decimal) : { tp: decimal.tp, up: decimal.up };
+            x.o_tp = helper.mul(x.oamount, x.unit_price, p_decimal.tp);
+            x.c_tp = helper.mul(x.camount, x.unit_price, p_decimal.tp);
+            x.s_tp = helper.mul(x.samount, x.unit_price, p_decimal.tp);
+            x.sp_tp = helper.mul(x.spamount, x.unit_price, p_decimal.tp);
+
+            const auditAmount = x.audit_amount ? x.audit_amount.split(',') : [];
+            for (const [i, aa] of auditAmount.entries()) {
+                const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
+                x[amountField] = aa ? parseFloat(aa) : 0;
+                x[tpField] = helper.mul(x[amountField], x.unit_price, p_decimal.tp);
+                if (plan) {
+                    plan[tpField] = helper.add(plan[tpField], x[tpField]);
+                }
+            }
+        });
+        bills.sort(function(a, b) {
+            return helper.compareCode(a.code, b.code);
+        });
+        return bills;
+    }
+
+    async _getChangePlanAudit() {
+        const changeAudit = await this.ctx.service.changePlanAudit.getAllDataByCondition({ where: { cpid: this.ctx.change_plan.id, times: this.ctx.change_plan.times }});
+        return this.ctx.helper.filterLastestData(changeAudit, ['aid']);
+    }
+
+    getCommonData(params, tableName, fields, customDefine, customSelect) {
+        switch (tableName) {
+            case 'mem_change_plan':
+                return this.ctx.change_plan;
+            case 'mem_change_plan_bills':
+                return this._getChangePlanBills();
+            case 'mem_change_plan_audit':
+                return this._getChangePlanAudit();
+            case 'mem_change_plan_att':
+                return this.ctx.service.changePlanAtt.getChangeAttachment(this.ctx.change_plan.id);
+            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;
+            default:
+                return [];
+        }
+    }
+}
+
+module.exports = rptMemChange;

+ 61 - 0
app/lib/rm/change_project.js

@@ -0,0 +1,61 @@
+'use strict';
+
+/**
+ * 变更立项
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const RptMemBase = require('./base');
+const bindData = {};
+
+class rptMemChange extends RptMemBase {
+    constructor(ctx) {
+        super(ctx, bindData);
+    }
+
+    async doCheckChangeProject(id) {
+        if (this.ctx.change_project) return;
+        this.ctx.change_project = await this.ctx.service.change.getDataById(id);
+    }
+
+    async doCheckTender(tenderId) {
+        if (this.ctx.tender) return;
+        this.ctx.tender = { id: tenderId };
+        this.ctx.tender.data = await this.ctx.service.getTender(tenderId);
+        this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
+    }
+
+    async doBeforeLoadReport(params) {
+        await this.doCheckChangeProject(params.change_project_id);
+        await this.doCheckTender(this.ctx.change_project.tid);
+    }
+
+    async _getChangeProjectAudit() {
+        const changeAudit = await this.ctx.service.changeProjectAudit.getAllDataByCondition({ where: { cpid: this.ctx.change_project.id, times: this.ctx.change_project.times }});
+        return this.ctx.helper.filterLastestData(changeAudit, ['aid']);
+    }
+
+    getCommonData(params, tableName, fields, customDefine, customSelect) {
+        switch (tableName) {
+            case 'mem_change_project':
+                return this.ctx.change_project;
+            case 'mem_change_project_audit':
+                return this._getChangeProjectAudit();
+            case 'mem_change_project_att':
+                return this.ctx.service.changeProjectAtt.getChangeAttachment(this.ctx.change_project.id);
+            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;
+            default:
+                return [];
+        }
+    }
+}
+
+module.exports = rptMemChange;

+ 29 - 1
app/service/report.js

@@ -533,6 +533,7 @@ module.exports = app => {
             return rst;
         }
 
+        // params = { tender_id: int, detail_id: int }
         async payment_safe(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
             const RptPaymentSafe = require('../lib/rm/payment_safe');
             const rptPaymentSafe = new RptPaymentSafe(this.ctx);
@@ -540,6 +541,7 @@ module.exports = app => {
             return rptPaymentSafe.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
         }
 
+        // params = { tender_id: int, detail_id: int }
         async payment(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
             const RptPayment = require('../lib/rm/payment');
             const rptPayment = new RptPayment(this.ctx);
@@ -547,6 +549,7 @@ module.exports = app => {
             return rptPayment.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
         }
 
+        // params = { sp_id: int, budget_id: int }
         async budget(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
             const RptPayment = require('../lib/rm/budget');
             const rptPayment = new RptPayment(this.ctx);
@@ -554,13 +557,38 @@ module.exports = app => {
             return rptPayment.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
         }
 
-        async budget(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
+        // params = { change_id: uuid }
+        async change(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
             const RptPayment = require('../lib/rm/change');
             const rptPayment = new RptPayment(this.ctx);
 
             return rptPayment.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
         }
 
+        // params = { change_plan_id: int }
+        async changePlan(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
+            const RptPayment = require('../lib/rm/change_plan');
+            const rptPayment = new RptPayment(this.ctx);
+
+            return rptPayment.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
+        }
+
+        // params = { change_project_id: int }
+        async changeProject(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
+            const RptPayment = require('../lib/rm/change_project');
+            const rptPayment = new RptPayment(this.ctx);
+
+            return rptPayment.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
+        }
+
+        // params = { change_apply_id: int }
+        async changeApply(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
+            const RptPayment = require('../lib/rm/change_apply');
+            const rptPayment = new RptPayment(this.ctx);
+
+            return rptPayment.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
+        }
+
         async getReportData(source_type, params, sourceFilters, memFieldKeys, customDefine, customSelect) {
             const sourceType = sourceTypeConst.sourceTypeData.find(x => { return x.id === source_type; });
             if (!sourceType && !this[sourceType.key]) return {};