Преглед на файлове

调用变更令,可变更数量

MaiXinRong преди 6 години
родител
ревизия
0f0922a7a8
променени са 3 файла, в които са добавени 28 реда и са изтрити 8 реда
  1. 2 1
      app/public/js/stage.js
  2. 16 5
      app/service/change.js
  3. 10 2
      app/service/stage_change.js

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

@@ -278,10 +278,11 @@ $(document).ready(() => {
         _calculateAmount() {
             for (const c of this.changes) {
                 c.bamount = _.toNumber(c.b_amount);
-                c.vamount = _.toNumber(c.b_amount);
+                c.vamount = _.round(_.subtract(c.bamount, c.used_amount), 6);
                 const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
                 if (uc) {
                     c.uamount = uc.qty;
+                    c.vamount = _.round(_.add(c.vamount, c.uamount), 6);
                 }
             }
         }

+ 16 - 5
app/service/change.js

@@ -684,12 +684,23 @@ module.exports = app => {
             const filter = 'cb.`code` = ' + this.db.escape(bills.b_code) + (pos ? ' And cb.`detail` = ' + 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 ' +
-                        '  FROM ?? As c ' +
-                        '  Left Join ?? As cb ' +
-                        '  On c.cid = cb.cid ' +
+                        '    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, ' +
+                        '    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) As `stimes`, Max(sorder) As `sorder`, cbid ' +
+                        '        FROM ' + this.ctx.service.stageChange.tableName +
+                        '        WHERE tid = ?' +
+                        '        GROUP BY cbid' +
+                        '      ) As MF' +
+                        '      ON sc.stimes = MF.stimes And sc.sorder = MF.sorder And sc.cbid = MF.cbid' +
+                        '    GROUP BY sc.cbid' +
+                        '  ) As scb ON cb.id = scb.cbid' +
                         '  WHERE c.tid = ? And c.status = ? And ' + filter;
-            const sqlParam = [this.tableName, this.ctx.service.changeAuditList.tableName, tid, audit.flow.status.checked];
+            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 ' +

+ 10 - 2
app/service/stage_change.js

@@ -45,8 +45,9 @@ module.exports = app => {
         }
 
         /**
-         * 调用变更令
-         * @param {Object} target - 台账|部位
+         * 台账,调用变更令
+         *
+         * @param {Object} bills - 台账节点数据
          * @param {Array} changes - 调用的变更令
          * @returns {Promise<void>}
          */
@@ -120,6 +121,13 @@ module.exports = app => {
             return { bills: result };
         }
 
+        /**
+         * 部位明细,调用变更令
+         *
+         * @param {Object} pos - 部位明细数据
+         * @param {Array} changes - 调用的变更令
+         * @returns {Promise<{}>}
+         */
         async posChange(pos, changes) {
             const self = this;
             function getNewChange(cid, cbid, times, order, qty) {