Bläddra i källkod

计量台账,调用变更令,数据显示问题

MaiXinRong 4 år sedan
förälder
incheckning
fbb524a027

+ 6 - 2
app/controller/stage_controller.js

@@ -439,8 +439,12 @@ module.exports = app => {
                 }
                 const bills = data.bills ? data.bills : await ctx.service.ledger.getDataById(data.pos.lid);
                 const pos = data.pos;
-                const changes = await ctx.service.change.getValidChanges(ctx.tender.id, bills);
-                const useChanges = await ctx.service.stageChange.getLastestStageData(ctx.tender.id, ctx.stage.id, bills.id, pos ? pos.id : -1);
+                const changes = ctx.stage.readOnly
+                    ? await ctx.service.change.getAuditValidChanges(ctx.tender.id, bills, null, ctx.stage.curTimes, ctx.stage.curOrder)
+                    : await ctx.service.change.getValidChanges(ctx.tender.id, bills);
+                const useChanges = ctx.stage.readOnly
+                    ? await ctx.service.stageChange.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.curTimes, ctx.stage.curOrder, bills.id, pos ? pos.id : -1)
+                    : await ctx.service.stageChange.getLastestStageData(ctx.tender.id, ctx.stage.id, bills.id, pos ? pos.id : -1);
                 ctx.body = { err: 0, msg: '', data: { changes, useChanges } };
             } catch (err) {
                 this.log(err);

+ 1 - 1
app/controller/tender_controller.js

@@ -128,7 +128,7 @@ module.exports = app => {
                     if (t.ledger_status === auditConst.ledger.status.checked) {
                         t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
                         if (t.lastStage && t.lastStage.status === auditConst.stage.status.uncheck &&
-                            t.lastStage.user_id !== this.ctx.session.sessionUser.accountId) {c
+                            t.lastStage.user_id !== this.ctx.session.sessionUser.accountId) {
                             t.lastStage = await this.ctx.service.stage.getLastestStage(t.id);
                         }
                         if (t.lastStage) await this.ctx.service.stage.checkStageGatherData(t.lastStage);

+ 64 - 28
app/service/change.js

@@ -958,51 +958,87 @@ module.exports = app => {
         async getValidChanges(tid, bills, pos) {
             const timesLen = 100;
             const filter =
-                'cb.`code` = ' +
-                this.db.escape(bills.b_code) +
-                ' And cb.`name` = ' +
-                this.db.escape(bills.name) +
-                ' And cb.`unit` = ' +
-                this.db.escape(bills.unit) +
-                ' And cb.`unit_price` = ' +
-                this.db.escape(bills.unit_price) +
+                'cb.`code` = ' + this.db.escape(bills.b_code) +
+                ' And cb.`name` = ' + this.db.escape(bills.name) +
+                ' And cb.`unit` = ' + this.db.escape(bills.unit) +
+                ' And cb.`unit_price` = ' + this.db.escape(bills.unit_price) +
                 (pos ? ' And cb.`bwmx` = ' + this.db.escape(pos.name) : '');
             const sql =
                 'SELECT c.cid, c.code, c.name, c.w_code, c.p_code, c.peg, c.org_name, c.org_code, c.new_name, c.new_code,' +
                 '    c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
                 '    cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail, cb.bwmx As b_bwmx, ' +
                 '    scb.used_amount' +
-                '  FROM ' +
-                this.tableName +
-                ' As c ' +
-                '  Left Join ' +
-                this.ctx.service.changeAuditList.tableName +
-                ' As cb On c.cid = cb.cid ' +
+                '  FROM ' + this.tableName + ' As c ' +
+                '  Left Join ' + this.ctx.service.changeAuditList.tableName + ' As cb On c.cid = cb.cid ' +
                 '  Left Join (' +
                 '    SELECT SUM(sc.qty) As used_amount, sc.cbid' +
-                '      FROM ' +
-                this.ctx.service.stageChange.tableName +
-                ' As sc' +
-                '      INNER JOIN (SELECT MAX(`stimes` * ' +
-                timesLen +
-                ' + `sorder`) As `flow`, cbid, sid ' +
-                '        FROM ' +
-                this.ctx.service.stageChange.tableName +
+                '      FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
+                '      INNER JOIN (SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, cbid, sid ' +
+                '        FROM ' + this.ctx.service.stageChange.tableName +
                 '        WHERE tid = ?' +
                 '        GROUP BY cbid, sid' +
                 '      ) As MF' +
-                '      ON (sc.stimes * ' +
-                timesLen +
-                ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
+                '      ON (sc.stimes * ' + timesLen + ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
                 '    GROUP BY sc.cbid' +
                 '  ) As scb ON cb.id = scb.cbid' +
-                '  WHERE c.tid = ? And c.status = ? And c.valid And ' +
-                filter +
+                '  WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
                 '  ORDER BY c.in_time';
             const sqlParam = [tid, tid, audit.flow.status.checked];
             const changes = await this.db.query(sql, sqlParam);
             for (const c of changes) {
-                const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' + '  FROM ?? As ca ' + '  Left Join ?? As pa ' + '  On ca.uid = pa.id ' + '  Where ca.cid = ?';
+                const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
+                    '  FROM ?? As ca ' +
+                    '  Left Join ?? As pa ' +
+                    '  On ca.uid = pa.id ' +
+                    '  Where ca.cid = ?';
+                const aSqlParam = [this.ctx.service.changeAtt.tableName, this.ctx.service.projectAccount.tableName, c.cid];
+                c.attachments = await this.db.query(aSql, aSqlParam);
+            }
+            return changes;
+        }
+
+        /**
+         * 查询审批人可用的变更令
+         * @param bills - 查询的清单
+         * @param pos - 查询的部位
+         * @return {Promise<*>} - 可用的变更令列表
+         */
+        async getAuditValidChanges(tid, bills, pos, times, order) {
+            const timesLen = 100;
+            const filter =
+                'cb.`code` = ' + this.db.escape(bills.b_code) +
+                ' And cb.`name` = ' + this.db.escape(bills.name) +
+                ' And cb.`unit` = ' + this.db.escape(bills.unit) +
+                ' And cb.`unit_price` = ' + this.db.escape(bills.unit_price) +
+                (pos ? ' And cb.`bwmx` = ' + this.db.escape(pos.name) : '');
+            const sql =
+                'SELECT c.cid, c.code, c.name, c.w_code, c.p_code, c.peg, c.org_name, c.org_code, c.new_name, c.new_code,' +
+                '    c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
+                '    cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail, cb.bwmx As b_bwmx, ' +
+                '    scb.used_amount' +
+                '  FROM ' + this.tableName + ' As c ' +
+                '  Left Join ' + this.ctx.service.changeAuditList.tableName + ' As cb On c.cid = cb.cid ' +
+                '  Left Join (' +
+                '    SELECT SUM(sc.qty) As used_amount, sc.cbid' +
+                '      FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
+                '      INNER JOIN (SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, cbid, sid ' +
+                '        FROM ' + this.ctx.service.stageChange.tableName +
+                '        WHERE tid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) ' +
+                '        GROUP BY cbid, sid' +
+                '      ) As MF' +
+                '      ON (sc.stimes * ' + timesLen + ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
+                '    GROUP BY sc.cbid' +
+                '  ) As scb ON cb.id = scb.cbid' +
+                '  WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
+                '  ORDER BY c.in_time';
+            const sqlParam = [tid, times, times, order, tid, audit.flow.status.checked];
+            const changes = await this.db.query(sql, sqlParam);
+            for (const c of changes) {
+                const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
+                    '  FROM ?? As ca ' +
+                    '  Left Join ?? As pa ' +
+                    '  On ca.uid = pa.id ' +
+                    '  Where ca.cid = ?';
                 const aSqlParam = [this.ctx.service.changeAtt.tableName, this.ctx.service.projectAccount.tableName, c.cid];
                 c.attachments = await this.db.query(aSql, aSqlParam);
             }

+ 9 - 9
app/service/stage_change.js

@@ -10,7 +10,7 @@
 
 const defaultPid = -1; // 非pid
 const audit = require('../const/audit');
-const timesLen = 100;
+const timesLen = audit.stage.timesLen;
 
 module.exports = app => {
 
@@ -40,11 +40,11 @@ module.exports = app => {
                 '  oc.p_code As c_code, oc.new_code As c_new_code' +
                 '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
-                '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
+                '    SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ? And lid = ? And pid = ?' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
+                '  ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
                 '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
                 '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, lid, pid ? pid : -1];
@@ -66,11 +66,11 @@ module.exports = app => {
                 '  oc.p_code As c_code, oc.new_code As c_new_code' +
                 '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
-                '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
+                '    SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
+                '  ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
                 '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
                 '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, times, times, order, lid, pid ? pid : -1];
@@ -82,11 +82,11 @@ module.exports = app => {
                 '  oc.p_code As c_code, oc.new_code As c_new_code' +
                 '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
-                '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
+                '    SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ?' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid` And c.lid = m.lid And c.pid = m.pid' +
+                '  ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
                 '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
                 '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid];
@@ -98,11 +98,11 @@ module.exports = app => {
                 '  oc.p_code As c_code, oc.new_code As c_new_code' +
                 '  FROM ' + this.tableName + ' As c ' +
                 '  INNER JOIN ( ' +
-                '    SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `sid` From ' + this.tableName +
+                '    SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid` From ' + this.tableName +
                 '      WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid` And c.lid = m.lid And c.pid = m.pid' +
+                '  ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid`' +
                 '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
                 '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, times, times, order];