Просмотр исходного кода

报表内存表,月进度数据

MaiXinRong 5 лет назад
Родитель
Сommit
e5c14280b6

+ 4 - 0
app/controller/report_controller.js

@@ -355,6 +355,10 @@ async function getReportData(ctx, params, filters) {
                     runnableRst.push(ctx.service.reportMemory.getStageImZlData(params.tender_id, params.stage_id));
                     runnableKey.push('mem_stage_im_zl');
                     break;
+                case 'mem_month_progress':
+                    runnableRst.push(ctx.service.reportMemory.getMonthProgress(params.tender_id));
+                    runnableKey.push('mem_month_progress');
+                    break;
                 default:
                     break;
             }

+ 48 - 0
app/service/report_memory.js

@@ -187,6 +187,54 @@ module.exports = app => {
             }
             return this.stageImData.main;
         }
+
+        async getMonthProgress(tid) {
+            const helper = this.ctx.helper;
+            await this.ctx.service.tender.checkTender(tid);
+            const tender = this.ctx.tender;
+
+            const stages = await this.ctx.service.stage.getValidStages(tender.id);
+            const lastStage = stages.length > 0 ? stages[0] : null;
+            if (lastStage) {
+                await this.ctx.service.stage.checkStageGatherData(lastStage);
+                tender.gather_tp = helper.add(lastStage.contract_tp, lastStage.qc_tp);
+                tender.end_contract_tp = helper.add(lastStage.contract_tp, lastStage.pre_contract_tp);
+                tender.end_qc_tp = helper.add(lastStage.qc_tp, lastStage.pre_qc_tp);
+                tender.end_gather_tp = helper.add(tender.end_contract_tp, tender.end_qc_tp);
+                tender.pre_gather_tp = helper.add(lastStage.pre_contract_tp, lastStage.pre_qc_tp);
+                tender.yf_tp = lastStage.yf_tp;
+                tender.qc_ratio = helper.mul(helper.div(tender.end_qc_tp, tender.info.deal_param.contractPrice, 2), 100);
+                tender.sum = helper.add(tender.total_price, tender.end_qc_tp);
+                tender.pre_ratio = helper.mul(helper.div(tender.pre_gather_tp, tender.sum, 2), 100);
+                tender.cur_ratio = helper.mul(helper.div(tender.gather_tp, tender.sum, 2), 100);
+                tender.other_tp = helper.sub(helper.sub(tender.sum, tender.pre_gather_tp), tender.gather_tp);
+                tender.other_ratio = Math.max(0, 100 - tender.pre_ratio - tender.cur_ratio);
+            }
+            const monthProgress = [];
+            for (const s of stages) {
+                if (s.s_time) {
+                    let progress = monthProgress.find(function (x) {
+                        return x.month === s.s_time;
+                    });
+                    if (!progress) {
+                        progress = {month: s.s_time};
+                        monthProgress.push(progress);
+                    }
+                    progress.tp = helper.add(helper.add(progress.tp, s.contract_tp), s.qc_tp);
+                }
+            }
+            monthProgress.sort(function (x, y) {
+                return Date.parse(x.month) - Date.parse(y.month);
+            });
+            let sum = 0;
+            for (const p of monthProgress) {
+                p.ratio = helper.mul(helper.div(p.tp, tender.sum, 4), 100);
+                sum = helper.add(sum, p.tp);
+                p.end_tp = sum;
+                p.end_ratio = helper.mul(helper.div(p.end_tp, tender.sum, 4), 100);
+            }
+            return monthProgress;
+        }
     }
 
     return ReportMemory;

+ 12 - 2
test/app/service/report_memory.test.js

@@ -31,7 +31,7 @@ describe('test/app/service/report_memory.test.js', () => {
         assert(loginResult);
         mockData.session = ctx.session;
     });
-    // 生成中间计量表数据 - 台账
+    // 中间计量表数据 - 台账
     it('test getStageImTzData & getStageImTzBillsData', function* () {
         const ctx = app.mockContext(mockData);
 
@@ -48,7 +48,7 @@ describe('test/app/service/report_memory.test.js', () => {
             yield ctx.helper.saveBufferFile(JSON.stringify(billsData,"","\t"), ctx.app.baseDir + '/mem_stage_im_tz_bills.json');
         }
     });
-    // 生成中间计量表数据 - 总量
+    // 中间计量表数据 - 总量
     it('test getStageImZlData', function* () {
         const ctx = app.mockContext(mockData);
 
@@ -59,4 +59,14 @@ describe('test/app/service/report_memory.test.js', () => {
             yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_stage_im_zl.json');
         }
     });
+    // 月进度数据
+    it('test getMonthProgress', function* () {
+        const ctx = app.mockContext(mockData);
+
+        // test12
+        const mainData = yield ctx.service.reportMemory.getMonthProgress(12);
+        if (mainData instanceof Array) {
+            yield ctx.helper.saveBufferFile(JSON.stringify(mainData,"","\t"), ctx.app.baseDir + '/mem_month_progress.json');
+        }
+    });
 });