Parcourir la source

进度图表完善和进度记录总设计值

laiguoran il y a 4 ans
Parent
commit
68b7756768
3 fichiers modifiés avec 61 ajouts et 65 suppressions
  1. 9 1
      app/public/js/schedule_ledger.js
  2. 26 1
      app/service/schedule_ledger.js
  3. 26 63
      app/view/schedule/index.ejs

+ 9 - 1
app/public/js/schedule_ledger.js

@@ -184,7 +184,15 @@ $(function () {
             return;
         }
         $(this).attr('disabled', true);
-        postData(window.location.pathname + '/save',  _.map(select_ledger, 'ledger_id'), function (result) {
+        // 找出所选的最底层,并统计总设计金额用
+        const under_ledger = [];
+        for (const sl of select_ledger) {
+            const hadChild = _.find(select_ledger, { ledger_pid: sl.ledger_id });
+            if (!hadChild) {
+                under_ledger.push({ ledger_id: sl.ledger_id, gcl: sl.dgn_qty1, tp: sl.total_price });
+            }
+        }
+        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger } , function (result) {
             toastr.success('设置成功');
             setTimeout(function () {
                 window.location.reload();

+ 26 - 1
app/service/schedule_ledger.js

@@ -15,7 +15,7 @@ module.exports = app => {
                 });
                 const oldLids = this._.map(oldDatas, 'ledger_id');
                 const insertDatas = [];
-                for (const l of datas) {
+                for (const l of datas.select_ledger) {
                     if (oldLids.indexOf(l) === -1) {
                         const data = {
                             tid: this.ctx.tender.id,
@@ -32,13 +32,38 @@ module.exports = app => {
                     }
                 }
                 if (insertDatas.length > 0) await transaction.insert(this.tableName, insertDatas);
+                // 更新所有为null
+                await transaction.update(this.tableName, { gcl: null, tp: null }, { where: { tid: this.ctx.tender.id } });
+                const updateOptions = [];
+                let total_tp = 0;
+                let total_gcl = 0;
+                // 更新最底层和总设计值
+                for (const u of datas.under_ledger) {
+                    updateOptions.push({
+                        row: {
+                            gcl: u.gcl,
+                            tp: u.tp,
+                        },
+                        where: {
+                            ledger_id: u.ledger_id,
+                            tid: this.ctx.tender.id,
+                        },
+                    });
+                    total_gcl = this.ctx.helper.add(total_gcl, u.gcl);
+                    total_tp = this.ctx.helper.add(total_tp, u.tp);
+                }
+                if (updateOptions.length > 0) await transaction.updateRows(this.tableName, updateOptions);
                 // 判断是否已创建了形象进度表
                 const scheduleInfo = await this.ctx.service.schedule.getDataByCondition({ tid: this.ctx.tender.id });
                 if (!scheduleInfo) {
                     const newSchedule = {
                         tid: this.ctx.tender.id,
+                        total_tp,
+                        total_gcl,
                     };
                     await transaction.insert(this.ctx.service.schedule.tableName, newSchedule);
+                } else {
+                    await transaction.update(this.ctx.service.schedule.tableName, { id: scheduleInfo.id, total_gcl, total_tp });
                 }
                 await transaction.commit();
                 return true;

+ 26 - 63
app/view/schedule/index.ejs

@@ -31,7 +31,7 @@
                         <div class="col-auto p-0">
                             <div class="card text-center">
                                 <div class="card-body">
-                                    <h5 class="card-title"><%- scheduleInfo ? ctx.helper.formatNum(scheduleInfo.plan_tp, '#,##0.######') : '' %> <small class="text-danger"  data-toggle="tooltip" data-placement="bottom" title="" data-original-title="占设计比例">20%</small></h5>
+                                    <h5 class="card-title"><%- scheduleInfo ? ctx.helper.formatNum(scheduleInfo.plan_tp, '#,##0.######') : '' %> <small class="text-danger"  data-toggle="tooltip" data-placement="bottom" title="" data-original-title="占设计比例"><%- scheduleInfo && scheduleInfo.total_tp !== 0 ? ctx.helper.round(ctx.helper.div(scheduleInfo.plan_tp, scheduleInfo.total_tp)*100, 0) + '%' : '' %></small></h5>
                                     <p class="card-text text-muted">计划完成金额</p>
                                 </div>
                             </div>
@@ -47,7 +47,7 @@
                         <div class="col-auto pr-0">
                             <div class="card text-center">
                                 <div class="card-body">
-                                    <h5 class="card-title"><%- scheduleInfo ? ctx.helper.formatNum(scheduleInfo.sj_tp, '#,##0.######') : '' %> <small class="text-danger"  data-toggle="tooltip" data-placement="bottom" title="" data-original-title="占设计比例">15%</small></h5>
+                                    <h5 class="card-title"><%- scheduleInfo ? ctx.helper.formatNum(scheduleInfo.sj_tp, '#,##0.######') : '' %> <small class="text-danger"  data-toggle="tooltip" data-placement="bottom" title="" data-original-title="占设计比例"><%- scheduleInfo && scheduleInfo.total_tp !== 0 ? ctx.helper.round(ctx.helper.div(scheduleInfo.sj_tp, scheduleInfo.total_tp)*100, 0) + '%' : '' %></small></h5>
                                     <p class="card-text text-muted">实际完成金额</p>
                                 </div>
                             </div>
@@ -57,16 +57,18 @@
                         <div id="tp" class="tab-pane fade show active" role="tabpanel" aria-labelledby="tp-tab">
                             <!--进度条-->
                             <div class="mb-3">
+                                <% if (scheduleInfo && scheduleInfo.total_tp !== 0) { %>
                                 计划金额进度(元)
                                 <div class="progress">
-                                    <div class="progress-bar bg-success" style="width:24%;" data-placement="bottom" data-toggle="tooltip" data-original-title="计划完成金额:¥300.00">24%</div>
-                                    <div class="progress-bar bg-gray" style="width:76%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未计划:¥930.00">66%</div>
+                                    <div class="progress-bar bg-success" style="width:<%- ctx.helper.round(ctx.helper.div(scheduleInfo.plan_tp, scheduleInfo.total_tp)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="计划完成金额:¥<%- ctx.helper.formatNum(scheduleInfo.plan_tp, '#,##0.######') %>"><%- ctx.helper.round(ctx.helper.div(scheduleInfo.plan_tp, scheduleInfo.total_tp)*100, 0) %>%</div>
+                                    <div class="progress-bar bg-gray" style="width:<%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.plan_tp, scheduleInfo.total_tp)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未计划:¥<%- ctx.helper.formatNum(ctx.helper.sub(scheduleInfo.total_tp, scheduleInfo.plan_tp), '#,##0.######') %>"><%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.plan_tp, scheduleInfo.total_tp)*100, 0) %>%</div>
                                 </div>
                                 <p class="mt-2 mb-0">实际金额进度哦(元)</p>
                                 <div class="progress">
-                                    <div class="progress-bar bg-success" style="width: 18%;" data-placement="bottom" data-toggle="tooltip" data-original-title="实际完成金额:¥400.00">18%</div>
-                                    <div class="progress-bar bg-gray" style="width:82%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未完成:¥930.00">72%</div>
+                                    <div class="progress-bar bg-success" style="width:<%- ctx.helper.round(ctx.helper.div(scheduleInfo.sj_tp, scheduleInfo.total_tp)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="实际完成金额:¥<%- ctx.helper.formatNum(scheduleInfo.sj_tp, '#,##0.######') %>"><%- ctx.helper.round(ctx.helper.div(scheduleInfo.sj_tp, scheduleInfo.total_tp)*100, 0) %>%</div>
+                                    <div class="progress-bar bg-gray" style="width:<%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.sj_tp, scheduleInfo.total_tp)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未完成:¥<%- ctx.helper.formatNum(ctx.helper.sub(scheduleInfo.total_tp, scheduleInfo.sj_tp), '#,##0.######') %>"><%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.sj_tp, scheduleInfo.total_tp)*100, 0) %>%</div>
                                 </div>
+                                <% } %>
                             </div>
                             <div class="card mb-3">
                                 <div class="card-body">
@@ -78,16 +80,18 @@
                         </div>
                         <div id="gcl" class="tab-pane fade" role="tabpanel" aria-labelledby="gcl-tab">
                             <div class="mb-3">
+                                <% if (scheduleInfo && scheduleInfo.total_gcl !== 0) { %>
                                 计划工程量进度
                                 <div class="progress">
-                                    <div class="progress-bar bg-info" style="width:24%;" data-placement="bottom" data-toggle="tooltip" data-original-title="计划完成工程量:30,000.00">24%</div>
-                                    <div class="progress-bar bg-gray" style="width:76%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未计划:930,00.00">66%</div>
+                                    <div class="progress-bar bg-info" style="width:<%- ctx.helper.round(ctx.helper.div(scheduleInfo.plan_gcl, scheduleInfo.total_gcl)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="计划完成工程量:¥<%- ctx.helper.formatNum(scheduleInfo.plan_gcl, '#,##0.######') %>"><%- ctx.helper.round(ctx.helper.div(scheduleInfo.plan_gcl, scheduleInfo.total_gcl)*100, 0) %>%</div>
+                                    <div class="progress-bar bg-gray" style="width:<%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.plan_gcl, scheduleInfo.total_gcl)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未计划:¥<%- ctx.helper.formatNum(ctx.helper.sub(scheduleInfo.total_gcl, scheduleInfo.plan_gcl), '#,##0.######') %>"><%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.plan_gcl, scheduleInfo.total_gcl)*100, 0) %>%</div>
                                 </div>
                                 <p class="mt-2 mb-0">实际工程量进度</p>
                                 <div class="progress">
-                                    <div class="progress-bar bg-info" style="width: 18%;" data-placement="bottom" data-toggle="tooltip" data-original-title="实际完成工程量:40,000.00">18%</div>
-                                    <div class="progress-bar bg-gray" style="width:82%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未完成:930,00.00">72%</div>
+                                    <div class="progress-bar bg-info" style="width:<%- ctx.helper.round(ctx.helper.div(scheduleInfo.sj_gcl, scheduleInfo.total_gcl)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="实际完成工程量:¥<%- ctx.helper.formatNum(scheduleInfo.sj_gcl, '#,##0.######') %>"><%- ctx.helper.round(ctx.helper.div(scheduleInfo.sj_gcl, scheduleInfo.total_gcl)*100, 0) %>%</div>
+                                    <div class="progress-bar bg-gray" style="width:<%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.sj_gcl, scheduleInfo.total_gcl)*100, 0) %>%;" data-placement="bottom" data-toggle="tooltip" data-original-title="合同未完成:¥<%- ctx.helper.formatNum(ctx.helper.sub(scheduleInfo.total_gcl, scheduleInfo.sj_gcl), '#,##0.######') %>"><%- 100 - ctx.helper.round(ctx.helper.div(scheduleInfo.sj_gcl, scheduleInfo.total_gcl)*100, 0) %>%</div>
                                 </div>
+                                <% } %>
                             </div>
                             <!--图表-->
                             <div class="card mb-3">
@@ -105,6 +109,7 @@
     </div>
 </div>
 <script src="/public/js/echarts/echarts.min.js"></script>
+<% if (scheduleInfo && scheduleInfo.total_tp !== 0 && scheduleInfo.total_gcl !== 0) { %>
 <script type="text/javascript">
     var charts = new Array();
     //计划进度//
@@ -187,7 +192,11 @@
                 type:'line',
                 tooltip : {trigger: 'axis',formatter: "{b}占合同比例<br/>{a}:{c} %"},
                 yAxisIndex: 1,
-                data:[10, 15, 20, 13, 11,]
+                data:[<% if (scheduleMonth.length > 0) { %>
+                    <% for (const sm of scheduleMonth) { %>
+                    '<%- ctx.helper.round(ctx.helper.div(sm.sj_gcl, scheduleInfo.total_gcl)*100, 2)  %>',
+                    <% } %>
+                    <% } %>]
             },
         ]
     };
@@ -273,7 +282,11 @@
                 type:'line',
                 tooltip : {trigger: 'axis',formatter: "{b}占合同比例<br/>{a}:{c} %"},
                 yAxisIndex: 1,
-                data:[10, 15, 20, 13, 11,]
+                data:[<% if (scheduleMonth.length > 0) { %>
+                    <% for (const sm of scheduleMonth) { %>
+                    '<%- ctx.helper.round(ctx.helper.div(sm.sj_tp, scheduleInfo.total_tp)*100, 2)  %>',
+                    <% } %>
+                    <% } %>]
             },
         ]
     };
@@ -285,64 +298,14 @@
 <!--sjs-->
 <script>
     $(document).ready(function () {
-        const data = [
-            {
-                单位:'稍等',
-                精度:3,
-            },{
-                单位:'km',
-                精度:3,
-            },{
-                单位:'m',
-                精度:3,
-            },{
-                单位:'m2',
-                精度:3,
-            },{
-                单位:'m3',
-                精度:3,
-            },{
-                单位:'kg',
-                精度:3,
-            },{
-                单位:'个',
-                精度:3,
-            },{
-                单位:'台',
-                精度:3,
-            },{
-                单位:'套',
-                精度:3,
-            },{
-                单位:'棵',
-                精度:3,
-            },{
-                单位:'组',
-                精度:3,
-            },{
-                单位:'总额',
-                精度:3,
-            },{
-                单位:'系统',
-                精度:3,
-            },{
-                单位:'其他未列单位',
-                精度:3,
-            }
-        ];
-
         $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
             for(var i = 0; i < charts.length; i++) {
                 charts[i].resize();
             }
         });
-        // const spread = new GC.Spread.Sheets.Workbook($('#option-spread1')[0], {
-        //     sheetCount: 1
-        // });
-        // spread.getActiveSheet().setDataSource(data);
-        // spread.options.tabStripVisible = false;
     })
 </script>
+<% } %>
 <script src="/public/js/sub_menu.js"></script>
 <script>
     $.subMenu({