소스 검색

台账修订对进度数据影响 ok

laiguoran 4 년 전
부모
커밋
3605c6aab7

+ 6 - 3
app/controller/schedule_controller.js

@@ -41,10 +41,10 @@ module.exports = app => {
 
         async index(ctx) {
             try {
-                const scheduleInfo = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
+                const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
                 const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
                 const renderData = {
-                    scheduleInfo,
+                    schedule,
                     scheduleMonth,
                     tender: ctx.tender.data,
                     tenderMenu: this.menu.tenderMenu,
@@ -62,6 +62,7 @@ module.exports = app => {
 
         async ledger(ctx) {
             const tender = ctx.tender;
+            const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
             const scheduleLedgerList = await this._getSelectedLedgerList(ctx);
             const allSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
             const hadDataLidList = [];
@@ -77,6 +78,7 @@ module.exports = app => {
                 }
             }
             const renderData = {
+                schedule,
                 tender: tender.data,
                 tenderInfo: tender.info,
                 measureType,
@@ -268,7 +270,8 @@ module.exports = app => {
                 // convert.loadData(ledgerData, posData, []);
                 // const result = await convert.convert();
                 const scheduleLedgerMonthData = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
-                ctx.body = { err: 0, msg: '', data: { bills: ledgerData, slm: scheduleLedgerMonthData } };
+                const scheduleLedgerHistoryData = await ctx.service.scheduleLedgerHistory.getAllDataByCondition({ where: { tid: ctx.tender.id } });
+                ctx.body = { err: 0, msg: '', data: { bills: ledgerData, slm: scheduleLedgerMonthData, slh: scheduleLedgerHistoryData } };
             } catch (err) {
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: [] };

+ 48 - 19
app/public/js/schedule_ledger.js

@@ -9,6 +9,7 @@ function getTenderId() {
     return window.location.pathname.split('/')[2];
 }
 const selects = [];
+let slh = [];
 $(function () {
     autoFlashHeight();
     // 初始化台账
@@ -77,6 +78,8 @@ $(function () {
                 node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
             }
         });
+        // slh = _.map(data.slh, 'ledger_id');
+        slh = data.slh;
         const datas = addIsSelect(data.bills);
         baseLedgerTree.loadDatas(datas);
         treeCalc.calculateAll(baseLedgerTree);
@@ -149,6 +152,9 @@ $(function () {
             });
         },
         buttonClicked: function (e, info) {
+            if(revising) {
+                return;
+            }
             if (info.sheet.zh_setting) {
                 const select = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
@@ -194,6 +200,46 @@ $(function () {
             return;
         }
         $(this).attr('disabled', true);
+        const [under_ledger, parent_ledger] = getPAndULedger(select_ledger);
+        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger } , function (result) {
+            toastr.success('设置成功');
+            setTimeout(function () {
+                window.location.reload();
+            },1500);
+        });
+    });
+    $('#update-ledger').click(function () {
+        const addLedgerData = _.map(_.differenceBy(ledgerTree.nodes, slh, 'ledger_id'), 'ledger_id');
+        const select_ledger = _.filter(ledgerTree.nodes, { 'is_select': 1 });
+        // 找出addLedgerData父节点并一起加入到select_ledger中
+        if (addLedgerData.length > 0) {
+            for (const a of addLedgerData) {
+                const ainfo = _.find(ledgerTree.nodes, { 'ledger_id': a });
+                select_ledger.push(ainfo);
+                findandpush(ainfo.ledger_pid);
+            }
+        }
+        function findandpush(ledger) {
+            const parent = _.find(ledgerTree.nodes, { ledger_id: ledger });
+            if (parent) {
+                const hadinfo = _.find(select_ledger, { ledger_id: parent.ledger_id });
+                if (!hadinfo) {
+                    select_ledger.push(parent);
+                    findandpush(parent);
+                }
+            }
+        }
+        $(this).attr('disabled', true);
+        const [under_ledger, parent_ledger] = getPAndULedger(select_ledger);
+        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger } , function (result) {
+            toastr.success('进度台账数据修正成功');
+            setTimeout(function () {
+                window.location.reload();
+            },1500);
+        });
+    });
+
+    function getPAndULedger(select_ledger) {
         // 找出所选的最底层,并统计总设计金额用
         const under_ledger = [];
         for (const sl of select_ledger) {
@@ -218,13 +264,8 @@ $(function () {
                 }
             }
         }
-        postData(window.location.pathname + '/save',  { select_ledger: _.map(select_ledger, 'ledger_id'), under_ledger, parent_ledger } , function (result) {
-            toastr.success('设置成功');
-            setTimeout(function () {
-                window.location.reload();
-            },1500);
-        });
-    });
+        return [under_ledger, parent_ledger];
+    }
 
     $.subMenu({
         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
@@ -304,9 +345,6 @@ function updateParentCanSelect(datas, ledger_pid) {
 }
 
 function updateChildrenSelect(datas, is_select) {
-    if(revising) {
-        return;
-    }
     for (const data of datas) {
         if (data.can_select) {
             data.is_select = is_select;
@@ -319,9 +357,6 @@ function updateChildrenSelect(datas, is_select) {
 }
 
 function updateSiblingsSelect(tree, pid, is_select, select_msg) {
-    if(revising) {
-        return;
-    }
     const parent = pid !== -1 ? _.find(tree.nodes, { 'ledger_id': pid }) : tree;
     if (parent) {
         for(const d of parent.children) {
@@ -338,9 +373,6 @@ function updateSiblingsSelect(tree, pid, is_select, select_msg) {
 }
 
 function updateOtherSiblingsSelect(tree, pid, is_select, select_msg) {
-    if(revising) {
-        return;
-    }
     if(pid === -1) {
         return;
     }
@@ -376,9 +408,6 @@ function updateOtherSiblingsSelect(tree, pid, is_select, select_msg) {
 }
 
 function updateParentSelect(tree, pid, is_select) {
-    if(revising) {
-        return;
-    }
     if (pid !== -1) {
         const parent = _.find(tree.nodes, { 'ledger_id': pid });
         if (parent) {

+ 1 - 1
app/public/js/schedule_plan.js

@@ -10,7 +10,7 @@ function getTenderId() {
 }
 $(function () {
     autoFlashHeight();
-    if(schedule && !schedule.mode) {
+    if(schedule && !schedule.mode && !revising && !schedule.revising) {
         $('#mode').modal('show');
     }
     // 初始化台账

+ 16 - 7
app/service/ledger_revise.js

@@ -205,15 +205,24 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async cancelRevise(revise) {
-            const [billsHis, posHis] = await this.backupReviseHistoryFile(revise);
-            const result = await this.db.update(this.tableName, {
-                id: revise.id, valid: false, end_time: new Date(),
-                bills_file: billsHis, pos_file: posHis,
-            });
-            return result.affectedRows === 1;
+            const transaction = await this.db.beginTransaction();
+            try {
+                const [billsHis, posHis] = await this.backupReviseHistoryFile(revise);
+                const result = await transaction.update(this.tableName, {
+                    id: revise.id, valid: false, end_time: new Date(),
+                    bills_file: billsHis, pos_file: posHis,
+                });
+                // 形象进度改变状态
+                await transaction.update(this.ctx.service.schedule.tableName, { revising: 0 }, { where: { tid: this.ctx.tender.id } });
+                await transaction.commit();
+                return result.affectedRows === 1;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
         }
 
     }
 
     return LedgerRevise;
-};
+};

+ 3 - 0
app/service/revise_audit.js

@@ -258,6 +258,9 @@ module.exports = app => {
                 }
                 await transaction.update(this.ctx.service.ledgerRevise.tableName, reviseData);
 
+                // 形象进度改变状态
+                await transaction.update(this.ctx.service.schedule.tableName, { revising: 1 }, { where: { tid: this.ctx.tender.id } });
+
                 // 添加短信通知-需要审批提醒功能
                 // 下一人
                 // await this.ctx.helper.sendUserSms(audit.audit_id, smsTypeConst.const.XD,

+ 35 - 5
app/service/schedule_ledger.js

@@ -1,5 +1,5 @@
 'use strict';
-
+const scheduleConst = require('../const/schedule');
 module.exports = app => {
     class ScheduleLedger extends app.BaseService {
         constructor(ctx) {
@@ -38,7 +38,7 @@ module.exports = app => {
                 await transaction.update(this.tableName, { gcl: null, tp: null }, { where: { tid: this.ctx.tender.id } });
                 const updateOptions = [];
                 let total_tp = 0;
-                // 更新最底层和总设计值
+                // 更新最底层和总设计值并更新最底层已填的计划与实际(金额、工程量)
                 for (const u of datas.under_ledger) {
                     updateOptions.push({
                         row: {
@@ -61,16 +61,46 @@ module.exports = app => {
                         total_tp,
                     };
                     await transaction.insert(this.ctx.service.schedule.tableName, newSchedule);
+                    const ledgerData = await this.ctx.service.ledger.getData(this.ctx.tender.id);
+                    const insertDatas = [];
+                    for (const le of ledgerData) {
+                        insertDatas.push({ tid: this.ctx.tender.id, ledger_id: le.ledger_id });
+                    }
+                    await transaction.insert(this.ctx.service.scheduleLedgerHistory.tableName, insertDatas);
                 } else {
-                    await transaction.update(this.ctx.service.schedule.tableName, { id: scheduleInfo.id, total_tp });
+                    await transaction.update(this.ctx.service.schedule.tableName, { id: scheduleInfo.id, total_tp, revising: 0 });
                 }
                 // 判断是否已存在计划月,并更新计划月统计数据,再更新总的统计数据
-                const smList = await this.ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
-                if (smList.length > 0) {
+                const smList = await this.ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
+                if (scheduleInfo && smList.length > 0) {
                     // 删除所有父节点已填过的值
                     for (const p of datas.parent_ledger) {
                         await transaction.delete(this.ctx.service.scheduleLedgerMonth.tableName, { tid: this.ctx.tender.id, lid: p });
                     }
+                    const mode = scheduleInfo.mode;
+                    const slmUpdateOption = [];
+                    for (const u of datas.under_ledger) {
+                        const dgn_price = this.ctx.helper.round(this.ctx.helper.div(u.tp, u.gcl), 2);
+                        if (dgn_price && dgn_price !== 0) {
+                            const sql = 'SELECT * FROM ?? WHERE tid = ? and lid = ?';
+                            const sqlParam = [this.ctx.service.scheduleLedgerMonth.tableName, this.ctx.tender.id, u.ledger_id];
+                            const lidList = await transaction.query(sql, sqlParam);
+                            if (lidList > 0) {
+                                for (const l of lidList) {
+                                    if (mode === scheduleConst.plan_mode.tp) {
+                                        const new_plan_gcl = l.plan_tp ? this.ctx.helper.round(this.ctx.helper.div(l.plan_tp, dgn_price), 3) : null;
+                                        const new_sj_gcl = l.sj_tp ? this.ctx.helper.round(this.ctx.helper.div(l.sj_tp, dgn_price), 3) : null;
+                                        slmUpdateOption.push({ id: l.id, plan_gcl: new_plan_gcl, sj_gcl: new_sj_gcl });
+                                    } else if (mode === scheduleConst.plan_mode.gcl) {
+                                        const new_plan_tp = l.plan_gcl ? this.ctx.helper.round(this.ctx.helper.div(l.plan_gcl, dgn_price), 0) : null;
+                                        const new_sj_tp = l.sj_gcl ? this.ctx.helper.round(this.ctx.helper.div(l.sj_gcl, dgn_price), 0) : null;
+                                        slmUpdateOption.push({ id: l.id, plan_tp: new_plan_tp, sj_tp: new_sj_tp });
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    if (slmUpdateOption.length > 0) await transaction.updateRows(this.ctx.service.scheduleLedgerMonth.tableName, slmUpdateOption);
                     for (const sm of smList) {
                         await this.ctx.service.scheduleLedgerMonth.calcMonthPlan(transaction, this.ctx.tender.id, sm.yearmonth);
                         await this.ctx.service.scheduleLedgerMonth.calcMonthSj(transaction, this.ctx.tender.id, sm.yearmonth);

+ 11 - 0
app/service/schedule_ledger_history.js

@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = app => {
+    class ScheduleLedgerHistory extends app.BaseService {
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'schedule_ledger_history';
+        }
+    }
+    return ScheduleLedgerHistory;
+};

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 9 - 9
app/view/schedule/index.ejs


+ 28 - 1
app/view/schedule/modal.ejs

@@ -1,4 +1,4 @@
-<% if (scheduleLedgerList.length === 0 && !revising) { %>
+<% if (scheduleLedgerList.length === 0 && ctx.url !== '/tender/' + ctx.tender.id + '/schedule/ledger') { %>
 <!--首次使用提示-->
 <div class="modal fade" id="first" data-backdrop="static">
     <div class="modal-dialog" role="document">
@@ -44,6 +44,33 @@
     </div>
     <script type="text/javascript">$('#unedit').modal('show');</script>
 <% } %>
+<% if (!revising && schedule && schedule.revising === 1) { %>
+    <!--正在修订提示-->
+    <div class="modal fade" id="okedit" data-backdrop="static">
+        <div class="modal-dialog " role="document" >
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">提示</h5>
+                </div>
+                <div class="modal-body">
+                    <% if (ctx.url === '/tender/' + ctx.tender.id + '/schedule/ledger') { %>
+                        <h5>台账已完成修订,点击更新进度台账更新进度数据</h5>
+                    <% } else { %>
+                        <h5>台账已完成修订,进入进度台账并更新最新台账数据。</h5>
+                    <% } %>
+                </div>
+                <div class="modal-footer">
+                    <% if (ctx.url === '/tender/' + ctx.tender.id + '/schedule/ledger') { %>
+                    <button type="button" class="btn btn-primary" id="update-ledger">更新进度台账</button>
+                    <% } else { %>
+                    <a href="/tender/<%- ctx.tender.id %>/schedule/ledger" class="btn btn-primary">进入进度台账</a>
+                    <% } %>
+                </div>
+            </div>
+        </div>
+    </div>
+    <script type="text/javascript">$('#okedit').modal('show');</script>
+<% } %>
 <script>
     const selectedLedgerList = JSON.parse('<%- JSON.stringify(scheduleLedgerList) %>');
     const revising = <%- revising %>;