Browse Source

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

Tony Kang 1 year ago
parent
commit
9eab40d607
1 changed files with 15 additions and 4 deletions
  1. 15 4
      app/service/report_memory.js

+ 15 - 4
app/service/report_memory.js

@@ -1518,14 +1518,25 @@ module.exports = app => {
                 const type = x.TreeType - y.TreeType;
                 return type ? type : x.Serail - y.Serail;
             });
-            const sortChildren = function (children, data) {
-                if (!children || children.length === 0) return;
+            const helper = this.ctx.helper;
+            const sortSumChildren = function (children, data, fields) {
+                if (!children || children.length === 0) return null;
+                const sum = {};
                 for (const c of children) {
                     data.push(c);
-                    sortChildren(c.children, data);
+                    const cSum = sortSumChildren(c.children, data, fields);
+                    if (cSum) {
+                        for (const f of fields) {
+                            c[f] = cSum[f].toFixed(2);
+                        }
+                    }
+                    for (const f of fields) {
+                        sum[f] = helper.add(sum[f], parseFloat(c[f]));
+                    }
                 }
+                return sum;
             };
-            sortChildren(root, result);
+            sortSumChildren(root, result, ['ContractPrice', 'ContractReturned', 'ContractPaid']);
             result.forEach(x => { delete x.children });
             return result;
         }