فهرست منبع

1. 台账修订,最新一期计量未审批完成时,可新增
2. 最新一次台账修订未完成时,期不允许提交任何数据

MaiXinRong 5 سال پیش
والد
کامیت
e0d985322e

+ 2 - 5
app/controller/revise_controller.js

@@ -22,7 +22,6 @@ const fs = require('fs');
 const LzString = require('lz-string');
 
 module.exports = app => {
-
     class ReviseController extends app.BaseController {
 
         /**
@@ -42,11 +41,9 @@ module.exports = app => {
          * @private
          */
         async _getAddReviseValid(ctx) {
-            const stage  = await ctx.service.stage.getLastestStage(ctx.tender.id, true);
             const revise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
             return (ctx.tender.data.user_id === ctx.session.sessionUser.accountId) &&
                 (ctx.tender.data.ledger_status === audit.revise.status.checked) &&
-                (!stage || stage.status === audit.stage.status.checked) &&
                 (!revise || !revise.valid || revise.status === audit.revise.status.checked);
         }
 
@@ -296,9 +293,9 @@ module.exports = app => {
                     b.used = usedPreBills.indexOf(b.id) >= 0 || usedCurBills.indexOf(b.id) >= 0;
                 }
                 const usedPrePos = lastStage.order > 1 ? await ctx.service.stagePosFinal.getUsedPos(ctx.tender.id, lastStage.order - 1) : [];
-                const usedCurPos = await ctx.service.stageBills.getStageUsedPos(ctx.tender.id, lastStage.id);
+                const usedCurPos = await ctx.service.stagePos.getStageUsedPos(ctx.tender.id, lastStage.id);
                 for (const p of renderData.revisePos) {
-                    p.used = usedPrePos.indexOf(b.id) >= 0 || usedCurPos.indexOf(p.id) >= 0;
+                    p.used = usedPrePos.indexOf(p.id) >= 0 || usedCurPos.indexOf(p.id) >= 0;
                 }
             }
             // 修订历史

+ 42 - 44
app/controller/stage_controller.js

@@ -65,10 +65,6 @@ module.exports = app => {
             return data;
         }
 
-        _stageReadOnly(stage) {
-            return stage.status === auditConst.status.checked;
-        }
-
         /**
          * 获取SpreadSetting
          * @private
@@ -101,7 +97,7 @@ module.exports = app => {
                 removeFieldCols(ledger, spreadConst.filterCols.stageDgnCols);
             }
             const pos = JSON.parse(JSON.stringify(stageSetting.pos));
-            if (this.ctx.stage.readOnly) {
+            if (this.ctx.stage.readOnly || this.ctx.stage.revising) {
                 ledger.readOnly = true;
                 pos.readOnly = true;
             }
@@ -130,6 +126,16 @@ module.exports = app => {
             }
         }
 
+        _checkStageCanModify(ctx) {
+            // 检查登录用户,是否可操作
+            if (ctx.stage.readOnly) {
+                throw '该计量期当前您无权操作';
+            }
+            if (ctx.stage.revising) {
+                throw '台账修订中,请勿修改提交期数据';
+            }
+        }
+
         /**
          * 期计量页面 (Get)
          * @param {Object} ctx - egg全局变量
@@ -235,10 +241,7 @@ module.exports = app => {
          */
         async updateStageData(ctx) {
             try {
-                // 检查登录用户,是否可操作
-                if (ctx.stage.readOnly) {
-                    throw '该计量期当前您无权操作';
-                }
+                this._checkStageCanModify(ctx);
 
                 const data = JSON.parse(ctx.request.body.data);
                 const responseData = { err: 0, msg: '', data: {}, };
@@ -266,10 +269,6 @@ module.exports = app => {
          */
         async searchValidChange(ctx) {
             try {
-                // if (ctx.stage.readOnly) {
-                //     throw '您无权调用变更令';
-                // }
-
                 const data = JSON.parse(ctx.request.body.data);
                 if (!data.bills && !data.pos) {
                     throw '数据错误';
@@ -291,9 +290,7 @@ module.exports = app => {
          */
         async useChange(ctx) {
             try {
-                if (ctx.stage.readOnly) {
-                    throw '您无权使用变更令';
-                }
+                this._checkStageCanModify(ctx);
 
                 const data = JSON.parse(ctx.request.body.data);
                 if (!data.target || (!data.target.bills && !data.target.pos) || !data.change) {
@@ -357,10 +354,7 @@ module.exports = app => {
          */
         async buildDetailData (ctx) {
             try {
-                // 检查登录用户,是否可操作
-                if (ctx.stage.readOnly) {
-                    throw '该计量期当前您无权操作';
-                }
+                this._checkStageCanModify(ctx);
 
                 const data = JSON.parse(ctx.request.body.data);
                 await ctx.service.stage.buildDetailData(ctx.tender.id, ctx.stage.order, data);
@@ -425,10 +419,7 @@ module.exports = app => {
          */
         async setAdvancedConfig(ctx) {
             try {
-                // 检查登录用户,是否可操作
-                if (ctx.stage.readOnly) {
-                    throw '该计量期当前您无权操作';
-                }
+                this._checkStageCanModify(ctx);
 
                 const data = JSON.parse(ctx.request.body.data);
                 await ctx.service.stage.update(data, { id: ctx.stage.id });
@@ -448,10 +439,7 @@ module.exports = app => {
          */
         async saveDetailData(ctx) {
             try {
-                // 检查登录用户,是否可操作
-                if (ctx.stage.readOnly) {
-                    throw '该计量期当前您无权操作';
-                }
+                this._checkStageCanModify(ctx);
 
                 const data = JSON.parse(ctx.request.body.data);
                 const responseData = { err: 0, msg: '', data: {}, };
@@ -475,9 +463,8 @@ module.exports = app => {
          */
         async addCalcImage(ctx) {
             try {
-                if (ctx.stage.readOnly) {
-                    throw '该计量期当前您无权操作';
-                }
+                this._checkStageCanModify(ctx);
+
                 const stream = await ctx.getFileStream();
                 const create_time = Date.parse(new Date()) / 1000;
                 const fileInfo = path.parse(stream.filename);
@@ -498,10 +485,8 @@ module.exports = app => {
          */
         async mergeCalcImage(ctx) {
             try {
-                // 检查登录用户,是否可操作
-                if (ctx.stage.readOnly) {
-                    throw '该计量期当前您无权操作';
-                }
+                this._checkStageCanModify(ctx);
+
                 const data = JSON.parse(ctx.request.body.data);
 
                 if (data.updateType === 'update') {
@@ -538,6 +523,8 @@ module.exports = app => {
          */
         async doneDetail(ctx) {
             try {
+                this._checkStageCanModify(ctx);
+
                 await ctx.service.stage.updateCheckDetailFlag(ctx.stage.id, false);
                 ctx.stage.check_detail = false;
                 ctx.body = {err: 0, msg: '', data: false}
@@ -609,10 +596,7 @@ module.exports = app => {
                 || data.minus !== undefined || data.is_yf !== undefined || data.dl_type !== undefined
             }
             try {
-                // 检查登录用户,是否可操作
-                if (ctx.stage.readOnly) {
-                    throw '该计量期当前您无权操作';
-                }
+                this._checkStageCanModify(ctx);
 
                 const data = JSON.parse(ctx.request.body.data);
                 const responseData = { err: 0, msg: '', data: {}, };
@@ -787,11 +771,13 @@ module.exports = app => {
          */
         async addAudit(ctx) {
             try {
+                this._checkStageCanModify(ctx);
                 const data = JSON.parse(ctx.request.body.data);
                 const id = this.app._.toInteger(data.auditorId);
                 if (isNaN(id) || id <= 0) {
                     throw '参数错误';
                 }
+
                 // 检查权限等
                 if (ctx.stage.user_id !== ctx.session.sessionUser.accountId) {
                     throw '您无权添加审核人';
@@ -826,6 +812,7 @@ module.exports = app => {
          */
         async deleteAudit(ctx) {
             try {
+                this._checkStageCanModify(ctx);
                 const data = JSON.parse(ctx.request.body.data);
                 const id = data.auditorId instanceof Number ? data.auditorId : this.app._.toNumber(data.auditorId);
                 if (isNaN(id) || id <= 0) {
@@ -850,10 +837,8 @@ module.exports = app => {
          */
         async startAudit(ctx) {
             try {
-                // 检查权限等
-                if (!ctx.stage) {
-                    throw '数据错误';
-                }
+                this._checkStageCanModify(ctx);
+
                 if (ctx.stage.user_id !== ctx.session.sessionUser.accountId) {
                     throw '您无权上报该期数据';
                 }
@@ -880,6 +865,8 @@ module.exports = app => {
          */
         async checkAudit(ctx) {
             try {
+                this._checkStageCanModify(ctx);
+
                 if (!this.ctx.stage || (this.ctx.stage.status !== auditConst.status.checking && this.ctx.stage.status !== auditConst.status.checkNoPre)) {
                     throw '当前期数据有误';
                 }
@@ -912,7 +899,6 @@ module.exports = app => {
                 ctx.redirect(ctx.request.header.referer);
             }
         }
-
         /**
          * 重新审批
          * @param ctx
@@ -920,6 +906,8 @@ module.exports = app => {
          */
         async checkAuditAgain(ctx) {
             try {
+                this._checkStageCanModify(ctx);
+
                 if (ctx.stage.auditors[ctx.stage.auditors.length - 1].aid === ctx.session.sessionUser.accountId && ctx.stage.status === auditConst.status.checked && ctx.stage.order === ctx.stage.highOrder) {
                     await ctx.service.stageAudit.checkAgain(ctx.stage.id, ctx.stage.times);
                     console.log('success');
@@ -1092,6 +1080,8 @@ module.exports = app => {
             };
             let stream;
             try {
+                this._checkStageCanModify(ctx);
+
                 const parts = ctx.multipart({ autoFields: true });
                 const files = [];
                 let index = 0;
@@ -1200,6 +1190,8 @@ module.exports = app => {
                 data: '',
             };
             try {
+                this._checkStageCanModify(ctx);
+
                 const data = JSON.parse(ctx.request.body.data);
                 const fileInfo = await ctx.service.stageAtt.getDataById(data.id);
                 if (fileInfo !== undefined && fileInfo !== '') {
@@ -1238,6 +1230,8 @@ module.exports = app => {
             };
             let stream;
             try {
+                this._checkStageCanModify(ctx);
+
                 stream = await ctx.getFileStream({ requireFile: false });
                 let fileData = {};
                 if (stream.filename !== undefined) {
@@ -1291,6 +1285,8 @@ module.exports = app => {
             };
             let stream;
             try {
+                this._checkStageCanModify(ctx);
+
                 const parts = ctx.multipart({ autoFields: true });
                 const files = [];
                 let index = 0;
@@ -1396,6 +1392,8 @@ module.exports = app => {
                 data: '',
             };
             try {
+                this._checkStageCanModify(ctx);
+
                 const data = JSON.parse(ctx.request.body.data);
                 const payInfo = await ctx.service.stagePay.getDataById(data.id);
                 if (payInfo !== undefined) {

+ 4 - 0
app/middleware/stage_check.js

@@ -8,6 +8,7 @@
  */
 
 const status = require('../const/audit').stage.status;
+const reviseStatus = require('../const/audit').revise.status;
 const _ = require('lodash');
 
 module.exports = options => {
@@ -92,6 +93,9 @@ module.exports = options => {
                 throw '您无权查看该数据';
             }
 
+            const lastRevise = yield this.service.ledgerRevise.getLastestRevise(this.tender.id);
+            stage.revising = (lastRevise && lastRevise.status !== reviseStatus.checked) || false;
+
             // 获取最新的期
             stage.highOrder = yield this.service.stage.count({
                 tid: this.tender.id,

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

@@ -735,7 +735,7 @@ $(document).ready(() => {
             const sortData = info.sheet.zh_data || [];
             if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
                 if (info.cellRange.col !== 0) {
-                    toast('新增部位请先输入名称', 'warning');
+                    toastr.warning('新增部位请先输入名称');
                     posSpreadObj.loadCurPosData();
                     return;
                 }

+ 2 - 2
app/service/stage_bills.js

@@ -114,7 +114,7 @@ module.exports = app => {
             }
         }
 
-        async getUsedStageBills(tid, sid) {
+        async getStageUsedBills(tid, sid) {
             const sql = 'SELECT Bills.lid, (Bills.contract_qty <> 0 and Bills.qc_qty <> 0) As used FROM ' + this.tableName + ' As Bills ' +
                 '  INNER JOIN ( ' +
                 '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `progress`, `lid`, `sid` From ' + this.tableName +
@@ -124,7 +124,7 @@ module.exports = app => {
                 '  ON (Bills.times * ' + timesLen + ' + `order`) = MaxFilter.progress And Bills.lid = MaxFilter.lid And Bills.`sid` = MaxFilter.`sid`';
             const sqlParam = [tid, sid];
             const stageBills = await this.db.query(sql, sqlParam);
-            return this._.map(this._.filter(stageBills, 'used'), pid);
+            return this._.map(this._.filter(stageBills, 'used'), 'lid');
         }
 
         /**

+ 3 - 2
app/service/stage_pos.js

@@ -125,15 +125,16 @@ module.exports = app => {
         }
 
         async getStageUsedPos(tid, sid, where) {
+            const self = this;
             const stagePos = await this.getLastestStageData2(tid, sid, where);
             const pids = this._.map(stagePos, function (sp) {
-                if (this.ctx.helper.checkZero(sp.contract_qty) && this.ctx.helper.checkZero(sp.qc_qty)) {
+                if (self.ctx.helper.checkZero(sp.contract_qty) && self.ctx.helper.checkZero(sp.qc_qty)) {
                     return sp.pid;
                 } else {
                     return -1;
                 }
             });
-            return this._.full(pids, -1);
+            return this._.pull(pids, -1);
         }
 
         /**

+ 1 - 1
app/view/revise/info_modal.ejs

@@ -478,7 +478,7 @@
     // 检查上报情况
     function checkAuditorFrom () {
         if ($('#auditors li').length === 0) {
-            toast('请先选择审批人,再上报数据', 'error', 'exclamation-circle');
+            toastr.error('请先选择审批人,再上报数据');
             return false;
         }
     }

+ 1 - 1
app/view/stage/detail.ejs

@@ -130,7 +130,7 @@
     </div>
 </div>
 <script>
-    const readOnly = <%- (stage.readOnly) %>;
+    const readOnly = <%- (stage.readOnly || stage.revising) %>;
     const stage = JSON.parse('<%- JSON.stringify(ctx.stage) %>');
     const imType = JSON.parse('<%- JSON.stringify(imType) %>');
 </script>

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

@@ -247,7 +247,7 @@
         regExp = new RegExp(FindText, 'g');
         return this.replace(regExp, RepText);
     }
-    const readOnly = <%- stage.readOnly %>;
+    const readOnly = <%- stage.readOnly || stage.revising %>;
     const ledgerSpreadSetting = JSON.parse('<%- JSON.stringify(ledgerSpread) %>');
     const posSpreadSetting = JSON.parse('<%- JSON.stringify(posSpread) %>');
     const tender = JSON.parse('<%- JSON.stringify(tender) %>');

+ 1 - 1
app/view/stage/pay.ejs

@@ -54,7 +54,7 @@
 <script>
     const tender = JSON.parse('<%- JSON.stringify(tender) %>');
     const stage = JSON.parse('<%- JSON.stringify(ctx.stage) %>');
-    const readOnly = <%- stage.readOnly %>;
+    const readOnly = <%- stage.readOnly || stage.revising %>;
     const dealPay = JSON.parse('<%- JSON.stringify(dealPay) %>');
     const calcBase = JSON.parse('<%- JSON.stringify(calcBase) %>');
     const decimal = JSON.parse('<%- JSON.stringify(ctx.tender.info.decimal) %>');