浏览代码

价差,主从交叉

MaiXinRong 2 年之前
父节点
当前提交
d8390a65d4
共有 3 个文件被更改,包括 65 次插入3 次删除
  1. 0 2
      app/lib/gcl_gather.js
  2. 2 1
      app/lib/rm/material.js
  3. 63 0
      app/lib/rpt_data_analysis.js

+ 0 - 2
app/lib/gcl_gather.js

@@ -245,8 +245,6 @@ const gclGatherModel = class {
             const dx = helper._.assign({}, cacheLeafXmj);
             dx.gcl_id = gcl.id;
             dx.org_gcl_id = node.id;
-            // dx.org_gcl_id = gcl.id;
-            // dx.gcl_id = node.id;
             if (detail.name !== node.name) {
                 dx.bwmx = detail.name;
                 dx.mx_id = detail.id;

+ 2 - 1
app/lib/rm/material.js

@@ -330,13 +330,14 @@ class ReportMemoryMaterial {
                     return gl.gcl_id === x.org_gcl_id && gl.xmj_id === x.id && (x.mx_id && x.mx_id !== x.id ? x.mx_id === gl.mx_id : true);
                 });
                 for (const l of list) {
+                    x.gather_gcl_id = x.gcl_id;
                     x.jiacha = helper.add(x.jiacha, helper.mul(helper.mul(x.gather_qty, l.quantity), l.m_spread));
                 }
                 x.jiacha = helper.round(x.jiacha, decimal.tp);
                 g.jiacha = helper.add(g.jiacha, x.jiacha);
             }
         }
-        return [gatherUtil.gclList, gatherUtil.leafXmjs ];
+        return [gatherUtil.gclList, gatherUtil.leafXmjs];
     }
 
     async getMaterialGatherBills(tender_id, material_order) {

+ 63 - 0
app/lib/rpt_data_analysis.js

@@ -1900,6 +1900,68 @@ const gatherMaterialGl = {
         data.mem_material_gl_detail = result;
     }
 };
+const masterCross = {
+    name: '主从交叉(汇总)数据-通用',
+    hint: '此版本,要求表必须是主从关系',
+    defaultSetting: {
+        main: {
+            tableName: 'mem_material_gather_bills',
+            prefix: 'm_',
+            fields: ['b_code', 'name', 'units', 'unit_price', 'quantity', 'total_price', 'gather_qty', 'gather_tp', 'jiacha'],
+        },
+        sub: {
+            tableName: 'mem_material_gather_gl',
+            masterKey: 'id', subKey: 'gather_gcl_id', gatherKey: 'mb_id',
+            prefix: 's_',
+            fields: ['code', 'name', 'units'],
+            gatherFields: ['quantity'],
+        },
+        target: 'master_converse'
+    },
+    _converse: function(ctx, options, mainTable, subTable) {
+        const data = [];
+        const converseData = [];
+        subTable.forEach(x => {
+            let cd = converseData.find(y => { return x[options.sub.gatherKey] === y[options.sub.gatherKey]});
+            if (cd) return;
+
+            cd = {};
+            cd[options.sub.gatherKey] = x[options.sub.gatherKey];
+            for (const f of options.sub.fields) {
+                cd[f] = x[f];
+            }
+            converseData.push(cd);
+        });
+        for (const [i, m] of mainTable.entries()) {
+            const temp = { cross_index: i+1 };
+            for (const f of options.main.fields) {
+                temp[options.main.prefix + f] = m[f];
+            }
+            const rela = subTable.filter(x => { return x[options.sub.subKey] === m[options.masterKey]; });
+            for (const cd of converseData) {
+                const nd = JSON.parse(JSON.stringify(temp));
+                for (const prop in cd) {
+                    nd[options.sub.prefix + prop] = cd[prop];
+                }
+                rela.forEach(x => {
+                    if (x[options.sub.gatherKey] !== cd[options.sub.gatherKey]) return;
+                    for (const f of options.sub.gatherFields) {
+                        nd[options.sub.prefix + f] = ctx.helper.add(nd[options.sub.prefix + f], x[f]);
+                    }
+                });
+                data.push(nd);
+            }
+        }
+        return data;
+    },
+    fun(ctx, data, fieldsKey, options, csRela) {
+        if (!options || !options.main || !options.sub || !options.target) return;
+        const mainTable = data[options.main.tableName], subTable = data[options.sub.tableName];
+        if (!mainTable || !subTable) return;
+
+        data[options.target] = this._converse(ctx, options, mainTable, subTable);
+    },
+};
 
 const analysisObj = {
     changeSort,
@@ -1925,6 +1987,7 @@ const analysisObj = {
     treeFilter,
     gatherGcl2,
     gatherMaterialGl,
+    masterCross
 };
 const analysisDefine = (function(obj) {
     const result = [];