소스 검색

台账截止上期数据,第二期

MaiXinRong 6 년 전
부모
커밋
74e2ebcd90

+ 7 - 3
app/controller/stage_controller.js

@@ -148,9 +148,13 @@ module.exports = app => {
                 renderData.curStageData = await ctx.service.stageBills.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.times, 0);
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.index);
                 // 查询截止上期数据
-                // if (ctx.stage.order > 0) {
-                // renderData.preStageData
-                // }
+                if (ctx.stage.order > 1) {
+                    renderData.preStageData = await ctx.service.stageBillsFinal.getAllDataByCondition({
+                        where: {tid: this.ctx.tender.id, sorder: ctx.stage.order - 1}
+                    });
+                } else {
+                    renderData.preStageData = [];
+                }
                 await this.layout('stage/index.ejs', renderData, 'stage/modal.ejs');
             } catch (err) {
                 this.log(err);

+ 2 - 2
app/public/js/path_tree.js

@@ -910,7 +910,7 @@ const createNewPathTree = function (type, setting) {
                 let node = this.getStageItems(data.lid);
                 if (node) {
                     for (const prop of fields) {
-                        if (data[fieldPre + prop] !== undefined) {
+                        if (data[prop] !== undefined) {
                             node[fieldPre + prop] = data[prop];
                         }
                     }
@@ -920,7 +920,7 @@ const createNewPathTree = function (type, setting) {
         }
 
         loadPreStageData(preStageData) {
-            this.loadStageData(curStageData, 'pre_', this.setting.updateFields);
+            this.loadStageData(preStageData, 'pre_', this.setting.updateFields);
         }
 
         loadCurStageData(curStageData) {

+ 1 - 0
app/public/js/stage.js

@@ -274,6 +274,7 @@ $(document).ready(() => {
     SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
     stageTree.loadDatas(ledgerData);
     stageTree.loadCurStageData(curStageData);
+    stageTree.loadPreStageData(preStageData);
     // 根据设置 计算 台账树结构
     treeCalc.calculateAll(stageTree);
     // 绘制界面

+ 4 - 2
app/service/stage.js

@@ -133,9 +133,11 @@ module.exports = app => {
                 times: 1,
                 status: auditConst.status.uncheck,
                 user_id: this.ctx.session.sessionUser.accountId,
-                pre_contract_tp: this.ctx.helper.plus(preStage.pre_contract_tp, preStage.contract_tp),
-                pre_qc_tp: this.ctx.helper.plus(preStage.pre_qc_tp, preStage.qc_tp),
             };
+            if (preStage) {
+                newStage.pre_contract_tp = this.ctx.helper.plus(preStage.pre_contract_tp, preStage.contract_tp);
+                newStage.pre_qc_tp = this.ctx.helper.plus(preStage.pre_qc_tp, preStage.qc_tp);
+            }
             const transaction = await this.db.beginTransaction();
             try {
                 // 新增期记录

+ 3 - 0
app/service/stage_audit.js

@@ -243,6 +243,9 @@ module.exports = app => {
                         });
                     } else {
                         // 本期结束
+                        // 生成截止本期数据 final数据
+                        await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
+                        //await this.ctx.service.stagePF.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
                         // 计算并合同支付最终数据
                         await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
                         // 同步 期信息

+ 69 - 0
app/service/stage_bills_final.js

@@ -0,0 +1,69 @@
+'use strict';
+
+/**
+ * stage_bills_final 期-清单-最终数据(截止本期)
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+module.exports = app => {
+
+    class StageBillsFinal extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'stage_bills_final';
+        }
+
+        /**
+         * 生成本期最终数据
+         * @param transaction - 所属事务
+         * @param {Number} tender - 标段
+         * @param {Number}stage - 本期
+         * @returns {Promise<void>}
+         */
+        async generateFinalData(transaction, tender, stage) {
+            if (!transaction || !tender || !stage) {
+                throw '数据错误';
+            }
+            let preStage;
+            if (stage.order > 1) {
+                preStage = await this.ctx.stage.getDataByCondition({tid: stage.tid, order: stage.order - 1});
+            }
+            if (preStage) {
+                const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp, postil)' +
+                    '  SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp, b.postil' +
+                    '  FROM ' + this.ctx.service.stageBills.tableName + ' AS b' +
+                    '  INNER JOIN(' +
+                    '    SELECT Max(`times`) As `times`, MAX(`order`) As `order`, `lid` FROM ' + this.ctx.service.stageBills.tableName +
+                    '    WHERE `sid` = ?' +
+                    '    GROUP By `lid`) As MF' +
+                    '  ON b.times = MF.times AND b.order = MF.order AND b.lid = MF.lid' +
+                    '  WHERE b.sid = ?';
+                const sqlParam = [this.tableName, stage.order, stage.id, stage.id];
+                await transaction.query(sql, sqlParam);
+            } else {
+                const sql = 'Insert Into ??(tid, sid, lid, sorder, contract_qty, contract_tp, qc_qty, qc_tp, postil)' +
+                    '  SELECT b.tid, b.sid, b.lid, ? As `sorder`, b.contract_qty, b.contract_tp, b.qc_qty, b.qc_tp, b.postil' +
+                    '  FROM ' + this.ctx.service.stageBills.tableName + ' AS b' +
+                    '  INNER JOIN(' +
+                    '    SELECT Max(`times`) As `times`, MAX(`order`) As `order`, `lid` FROM ' + this.ctx.service.stageBills.tableName +
+                    '    WHERE `sid` = ?' +
+                    '    GROUP By `lid`) As MF' +
+                    '  ON b.times = MF.times AND b.order = MF.order AND b.lid = MF.lid' +
+                    '  WHERE b.sid = ?';
+                const sqlParam = [this.tableName, stage.order, stage.id, stage.id];
+                await transaction.query(sql, sqlParam);
+            }
+        }
+    }
+
+    return StageBillsFinal;
+}

+ 1 - 1
app/view/dashboard/index.ejs

@@ -110,7 +110,7 @@
                         <span class="pull-right text-muted"><%- ns.end_time.toLocaleString() %></span>
                         <h5 class="mt-0"><%- ns.su_name %><small class="ml-3 text-muted"><%- ns.su_role %></small></h5>
                         <p>
-                            <a href="/tender/<%- ns.tid %>"><%- ns.su_name %></a>
+                            <a href="/tender/<%- ns.tid %>"><%- ns.name %></a>
                             <a href="/tender/<%- ns.tid %>/measure/stage/<%- ns.s_order %>">第<%- ns.s_order %>期 </a>
                             <%- acStage.statusString[ns.status]%>。
                         </p>

+ 1 - 0
app/view/stage/index.ejs

@@ -276,6 +276,7 @@
     const stage = JSON.parse('<%- JSON.stringify(ctx.stage) %>');
     const ledgerData = JSON.parse('<%- JSON.stringify(ledgerData) %>');
     const curStageData = JSON.parse('<%- JSON.stringify(curStageData) %>');
+    const preStageData = JSON.parse('<%- JSON.stringify(preStageData) %>');
 </script>
 <% if (ctx.stage.status === auditConst.status.uncheck && ctx.session.sessionUser.accountId === ctx.stage.user_id) {%>
 <script>