|
@@ -1518,14 +1518,25 @@ module.exports = app => {
|
|
const type = x.TreeType - y.TreeType;
|
|
const type = x.TreeType - y.TreeType;
|
|
return type ? type : x.Serail - y.Serail;
|
|
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) {
|
|
for (const c of children) {
|
|
data.push(c);
|
|
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 });
|
|
result.forEach(x => { delete x.children });
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|