浏览代码

汇总表,变更令汇总相关

MaiXinRong 2 年之前
父节点
当前提交
e07ac309fc
共有 5 个文件被更改,包括 73 次插入5 次删除
  1. 30 0
      app/lib/rm/rm_utils.js
  2. 1 1
      app/lib/rpt_data_analysis.js
  3. 9 1
      app/service/report.js
  4. 23 3
      app/service/rpt_gather_memory.js
  5. 10 0
      app/service/stage_change_final.js

+ 30 - 0
app/lib/rm/rm_utils.js

@@ -0,0 +1,30 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+
+module.exports = {
+    checkFieldsExist(source, check) {
+        for (const s of source) {
+            if (check.indexOf(s) >= 0) {
+                return true;
+            }
+        }
+        return false;
+    },
+    checkFieldsExistReg(source, regStr) {
+        const reg = new RegExp(regStr, 'igm');
+        for (const s of source) {
+            if (reg.test(s)) {
+                return true;
+            }
+        }
+        return false;
+    }
+};

+ 1 - 1
app/lib/rpt_data_analysis.js

@@ -299,7 +299,7 @@ const gatherGcl = {
         if (gatherOther) gclBills.push(other);
         for (const g of gclBills) {
             if (g.qc_bgl_code) g.qc_bgl_code = g.qc_bgl_code.join(';');
-            g.final_ratio = ctx.helper.mul(ctx.helper.div(g.end_gather_tp, g.final_ratio), 100);
+            g.final_ratio = ctx.helper.mul(ctx.helper.div(g.end_gather_tp, g.final_tp), 100);
         }
 
         data[tableName] = gclBills;

+ 9 - 1
app/service/report.js

@@ -60,6 +60,14 @@ module.exports = app => {
             return [common, spec];
         }
 
+        getFieldKeys(source, filter) {
+            const result = [];
+            for (const f of filter) {
+                if (source[f]) result.push(...source[f]);
+            }
+            return result;
+        }
+
         async getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
             const [filters, specFilters] = this.getFilter(sourceFilters);
             const service = this.ctx.service;
@@ -463,7 +471,7 @@ module.exports = app => {
                         }
                         break;
                     case 'gatherChange':
-                        const gcResult = await service.rptGatherMemory.getGatherChange(memFieldKeys['mem_gather_change'],
+                        const gcResult = await service.rptGatherMemory.getGatherChange(this.getFieldKeys(memFieldKeys, bindData.gatherChange),
                             customDefine.gather_select, customSelect ? customSelect.gather_select : null);
                         for (const d in gcResult) {
                             rst[d] = gcResult[d];

+ 23 - 3
app/service/rpt_gather_memory.js

@@ -220,6 +220,7 @@ const gatherUtils = {
         gatherNode[prefix + "qty"] = helper.add(gatherNode[prefix + "qty"], sourceNode.quantity);
     },
 };
+const rmUtils = require('../lib/rm/rm_utils');
 
 module.exports = app => {
     class RptGatherMemory extends app.BaseService {
@@ -1182,7 +1183,7 @@ module.exports = app => {
             return '';
         }
 
-        async _gatherChange(tender) {
+        async _gatherChange(tender, hasUsed) {
             const self = this;
             try {
                 const info = await this.ctx.service.tenderInfo.getTenderInfo(tender.id);
@@ -1205,7 +1206,9 @@ module.exports = app => {
                     });
                     c.attNames = names.join('\n');
                 }
-                const changeBills = await this.ctx.service.changeAuditList.getChangeAuditBills(tender.id, this.ctx.session.sessionProject.page_show.isOnlyChecked);
+                const changeBills = hasUsed
+                    ? await this.ctx.service.stageChangeFinal.getChangeBillsWithUsedQty(tender.id, this.ctx.session.sessionProject.page_show.isOnlyChecked)
+                    : await this.ctx.service.changeAuditList.getChangeAuditBills(tender.id, this.ctx.session.sessionProject.page_show.isOnlyChecked);
                 for (const d of changeBills) {
                     d.tender_name = tender.name;
                     d.o_qty = d.oamount;
@@ -1217,8 +1220,16 @@ module.exports = app => {
                     d.sp_qty = d.spamount;
                     d.sp_tp = this.ctx.helper.mul(d.sp_qty, d.unit_price, decimal.tp);
 
+                    d.used_tp = this.ctx.helper.mul(d.used_qty, d.unit_price, decimal.tp);
+                    d.is_used = !!d.used_qty;
+
                     const auditAmount = d.audit_amount ? d.audit_amount.split(',') : [];
                     const relaChange = ctx.helper._.find(change, {cid: d.cid});
+                    d.relaChange = relaChange;
+                    if (relaChange) {
+                        if (d.is_used) relaChange.is_used = true;
+                        relaChange.used_tp = ctx.helper.add(relaChange.used_tp, d.used_tp);
+                    }
                     for (const [i, aa] of auditAmount.entries()) {
                         const amountField = 'qty_' + (i+1), tpField = 'tp_' + (i+1);
                         d[amountField] = aa ? parseFloat(aa) : 0;
@@ -1228,6 +1239,14 @@ module.exports = app => {
                         }
                     }
                 }
+                for (const c of change) {
+                    c.is_used = !!c.is_used;
+                    c.used_ratio = c.total_price ? ctx.helper.mul(ctx.helper.div(c.used_tp, c.total_price), 100) : 0;
+                }
+                for (const cb of changeBills) {
+                    cb.is_used_bgl = cb.relaChange ? cb.relaChange.is_used : cb.is_used;
+                    delete cb.relaChange;
+                }
 
                 change.sort(function (a, b) {
                     return a.code.localeCompare(b.code);
@@ -1255,9 +1274,10 @@ module.exports = app => {
             if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return [];
 
             const result = { mem_gather_change: [], mem_gather_change_bills: [] };
+            const hasUsed = rmUtils.checkFieldsExist(memFieldKeys, ['used_qty', 'is_used_bgl', 'is_used', 'used_ratio']);
             for (const t of gsCustom.tenders) {
                 const tender = await this.ctx.service.tender.getCheckTender(t.tid);
-                const [change, changeBills] = await this._gatherChange(tender);
+                const [change, changeBills] = await this._gatherChange(tender, hasUsed);
                 result.mem_gather_change.push(...change);
                 result.mem_gather_change_bills.push(...changeBills);
             }

+ 10 - 0
app/service/stage_change_final.js

@@ -106,6 +106,16 @@ module.exports = app => {
                 return cb.valid_qty;
             });
         }
+
+        async getChangeBillsWithUsedQty(tid, onlyChecked) {
+            const sql = 'SELECT cal.*, scf.used_qty FROM ' + this.ctx.service.changeAuditList.tableName + ' cal' +
+                '  LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON cal.cid = c.cid ' +
+                '  LEFT JOIN (' +
+                '    SELECT cbid, SUM(qty) as used_qty FROM ' + this.tableName + ' WHERE tid = ? GROUP BY cbid ' +
+                '  ) scf ON cal.id = scf.cbid ' +
+                '  WHERE c.tid = ? AND c.valid' + (onlyChecked ? ' AND c.status = 3' : '');
+            return await this.db.query(sql, [tid, tid]);
+        }
     }
 
     return StageChangeFinal;