Parcourir la source

变更令查询相关

MaiXinRong il y a 1 an
Parent
commit
d1179d5697

+ 6 - 6
app/controller/change_controller.js

@@ -82,7 +82,7 @@ module.exports = app => {
                         case 5:
                             changeAudit = await ctx.service.changeAudit.getLastUser(c.cid, c.times - 1, status);
                             auditStatus = c.uid === ctx.session.sessionUser.accountId ? 1 : 0;
-                            const back_changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, c.cid);
+                            const back_changeUsedData = await ctx.service.stageChange.getAllFinalUsedData(ctx.tender.id, c.cid);
                             c.stageChangeNum = this.ctx.helper.sum(back_changeUsedData.map(x => { return Math.abs(x.qty); }));
                             c.isSettle = await ctx.service.changeSettleList.isSettle(c.cid);
                             break;
@@ -93,7 +93,7 @@ module.exports = app => {
                             break;
                         case 9:
                             auditStatus = c.uid === ctx.session.sessionUser.accountId ? 9 : 0;
-                            const changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, c.cid);
+                            const changeUsedData = await ctx.service.stageChange.getAllFinalUsedData(ctx.tender.id, c.cid);
                             c.stageChangeNum = this.ctx.helper.sum(changeUsedData.map(x => { return Math.abs(x.qty); }));
                             c.isSettle = await ctx.service.changeSettleList.isSettle(c.cid);
                             break;
@@ -591,7 +591,7 @@ module.exports = app => {
                 renderData.auditList = auditList;
 
                 // 获取是否已存在调用变更令
-                const changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, change.cid);
+                const changeUsedData = await ctx.service.stageChange.getAllFinalUsedData(ctx.tender.id, change.cid);
                 renderData.stageChangeNum = this.ctx.helper.sum(changeUsedData.map(x => { return Math.abs(x.qty); }));
                 await this.layout('change/info.ejs', renderData, 'change/info_modal.ejs');
             } catch (err) {
@@ -683,7 +683,7 @@ module.exports = app => {
                     removeSettleNum,
                 };
                 // 获取是否已存在调用变更令
-                let changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, change.cid);
+                let changeUsedData = await ctx.service.stageChange.getAllFinalUsedData(ctx.tender.id, change.cid);
                 changeUsedData = ctx.helper._.orderBy(ctx.helper._.filter(changeUsedData, function(item) {
                     return item.qty !== null;
                 }), ['sorder'], ['desc']);
@@ -919,7 +919,7 @@ module.exports = app => {
                         await ctx.service.changeAuditList.saveLedgerListDatas(data.updateData, data.postData);
                         // 取所有工料表
                         responseData.data = { changeList: await ctx.service.changeAuditList.getList(ctx.change.cid),
-                            usedList: await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, ctx.change.cid) };
+                            usedList: await ctx.service.stageChange.getAllFinalUsedData(ctx.tender.id, ctx.change.cid) };
                         break;
                     case 'remove_list':
                         await ctx.service.changeAuditList.removeLedgerListDatas(data.updateData);
@@ -1630,7 +1630,7 @@ module.exports = app => {
                 }
 
                 // 获取是否已存在调用变更令
-                // const changeUsedData = await ctx.service.stageChange.getFinalUsedData(ctx.tender.id, changeData.cid);
+                // const changeUsedData = await ctx.service.stageChange.getAllFinalUsedData(ctx.tender.id, changeData.cid);
                 // const stageChangeNum = this.ctx.helper.sum(changeUsedData.map(x => { return Math.abs(x.qty); }));
                 // if (stageChangeNum !== 0) {
                 //     throw '该变更令已被调用,无法重新审批';

+ 1 - 1
app/controller/revise_controller.js

@@ -43,7 +43,7 @@ module.exports = app => {
          */
         async _getAddReviseValid(ctx) {
             const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
-            const lastStage = await ctx.service.stage.getLastestStage(ctx.tender.id, true);
+            const lastStage = await ctx.service.stage.getFlowLatestStage(ctx.tender.id, true);
             const addVisible = (ctx.tender.data.user_id === ctx.session.sessionUser.accountId) &&
                 (ctx.tender.data.ledger_status === audit.ledger.status.checked) &&
                 (!revise || !revise.valid || revise.status === audit.revise.status.checked);

+ 2 - 2
app/service/change.js

@@ -750,7 +750,7 @@ module.exports = app => {
                     // 判断是否存在已调用清单,并判断新上限值是否比它小,更新计量上限值
                     const changeList = await this.ctx.service.changeAuditList.getList(this.ctx.change.cid);
                     // 获取是否已存在调用变更令
-                    let changeUsedData = await this.ctx.service.stageChange.getFinalUsedData(this.ctx.tender.id, this.ctx.change.cid);
+                    let changeUsedData = await this.ctx.service.stageChange.getAllFinalUsedData(this.ctx.tender.id, this.ctx.change.cid);
                     changeUsedData = this._.orderBy(this._.filter(changeUsedData, function(item) {
                         return item.qty !== null;
                     }), ['sorder'], ['desc']);
@@ -835,7 +835,7 @@ module.exports = app => {
                 await transaction.update(this.tableName, postData, options);
                 await transaction.commit();
                 result = { changeList,
-                    usedList: await this.ctx.service.stageChange.getFinalUsedData(this.ctx.tender.id, this.ctx.change.cid) };
+                    usedList: await this.ctx.service.stageChange.getAllFinalUsedData(this.ctx.tender.id, this.ctx.change.cid) };
             } catch (error) {
                 await transaction.rollback();
                 result = false;

+ 1 - 1
app/service/revise_audit.js

@@ -463,7 +463,7 @@ module.exports = app => {
                         });
                         await this.ctx.service.tenderTag.saveTenderTag(revise.tid, {revise_time: new Date()}, transaction);
                         // 最新一期跟台账相关的缓存数据应过期
-                        const lastStage = await this.ctx.service.stage.getLastestStage(revise.tid, true);
+                        const lastStage = await this.ctx.service.stage.getFlowLatestStage(revise.tid, true);
                         const cacheTime = new Date();
                         if (lastStage) {
                             await transaction.update(this.ctx.service.stage.tableName, {

+ 21 - 1
app/service/stage_change.js

@@ -559,7 +559,7 @@ module.exports = app => {
         }
 
         async getFinalUsedData(tid, cid) {
-            const stage = await this.ctx.service.stage.getLastestStage(tid, true);
+            const stage = await this.ctx.service.stage.getFlowLatestStage(tid, true);
             if (!stage) { // 防止未创建期时调用
                 return [];
             }
@@ -583,6 +583,26 @@ module.exports = app => {
             }
         }
 
+        async getAllFinalUsedData(tid, cid) {
+            const result = [];
+            const stages = await this.ctx.service.stage.getAllDataByCondition({ where: { tid: tid }, orders: [['order', 'desc']] });
+            for (const stage of stages) {
+                if (stage.status === audit.stage.status.checked) {
+                    const sql = 'SELECT scf.* ' +
+                        '  FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
+                        '  LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
+                        this.ctx.helper.whereSql({ tid, cid }, 'scf') + ' And s.order <= ?';
+                    const pre = await this.db.query(sql, [stage.order]);
+                    result.push(...pre);
+                } else {
+                    const sql = 'SELECT * FROM ' + this.tableName + this.ctx.helper.whereSql({ sid: stage.id, cid });
+                    const curAll = await this.db.query(sql);
+                    const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
+                    result.push(...cur);
+                }
+            }
+        }
+
         /**
          * 获取 变更令 - 变更清单 当期使用情况
          * @param {Number} sid - 查询期id