@resolveio/server-lib 9.0.32 → 9.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/client-server-app.js +7 -48
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +8 -11
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/app-version.collection.js +8 -11
  6. package/collections/app-version.collection.js.map +1 -1
  7. package/collections/counter.collection.js +8 -11
  8. package/collections/counter.collection.js.map +1 -1
  9. package/collections/cron-job-history.collection.js +9 -12
  10. package/collections/cron-job-history.collection.js.map +1 -1
  11. package/collections/cron-job.collection.js +8 -11
  12. package/collections/cron-job.collection.js.map +1 -1
  13. package/collections/email-history.collection.js +8 -11
  14. package/collections/email-history.collection.js.map +1 -1
  15. package/collections/email-verified.collection.js +9 -12
  16. package/collections/email-verified.collection.js.map +1 -1
  17. package/collections/file.collection.js +8 -11
  18. package/collections/file.collection.js.map +1 -1
  19. package/collections/flag.collection.js +8 -11
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +11 -14
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +13 -16
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +16 -19
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +9 -12
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-call.collection.js +10 -13
  30. package/collections/method-call.collection.js.map +1 -1
  31. package/collections/method-response.collection.js +10 -13
  32. package/collections/method-response.collection.js.map +1 -1
  33. package/collections/monitor-cpu.collection.js +13 -16
  34. package/collections/monitor-cpu.collection.js.map +1 -1
  35. package/collections/monitor-https-inbound.collection.js +13 -16
  36. package/collections/monitor-https-inbound.collection.js.map +1 -1
  37. package/collections/monitor-https-outbound.collection.js +15 -18
  38. package/collections/monitor-https-outbound.collection.js.map +1 -1
  39. package/collections/monitor-memory.collection.js +12 -15
  40. package/collections/monitor-memory.collection.js.map +1 -1
  41. package/collections/monitor-mongo.collection.js +12 -15
  42. package/collections/monitor-mongo.collection.js.map +1 -1
  43. package/collections/notification.collection.js +8 -11
  44. package/collections/notification.collection.js.map +1 -1
  45. package/collections/queue-flag.collection.js +9 -12
  46. package/collections/queue-flag.collection.js.map +1 -1
  47. package/collections/queue-method.collection.js +9 -12
  48. package/collections/queue-method.collection.js.map +1 -1
  49. package/collections/queue-response.collection.js +9 -12
  50. package/collections/queue-response.collection.js.map +1 -1
  51. package/collections/report-builder-dashboard-builder.collection.js +10 -13
  52. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  53. package/collections/report-builder-library.collection.js +11 -14
  54. package/collections/report-builder-library.collection.js.map +1 -1
  55. package/collections/report-builder-report.collection.js +11 -14
  56. package/collections/report-builder-report.collection.js.map +1 -1
  57. package/collections/user-group.collection.js +11 -14
  58. package/collections/user-group.collection.js.map +1 -1
  59. package/collections/user-guide.collection.js +8 -11
  60. package/collections/user-guide.collection.js.map +1 -1
  61. package/collections/user.collection.js +12 -15
  62. package/collections/user.collection.js.map +1 -1
  63. package/cron/cron.js +25 -25
  64. package/cron/cron.js.map +1 -1
  65. package/fixtures/cron-jobs.js +30 -80
  66. package/fixtures/cron-jobs.js.map +1 -1
  67. package/fixtures/init.js +9 -59
  68. package/fixtures/init.js.map +1 -1
  69. package/http/auth.js +344 -460
  70. package/http/auth.js.map +1 -1
  71. package/http/health.js +1 -5
  72. package/http/health.js.map +1 -1
  73. package/http/home.js +7 -11
  74. package/http/home.js.map +1 -1
  75. package/index.js +36 -98
  76. package/index.js.map +1 -1
  77. package/managers/cron.manager.js +78 -157
  78. package/managers/cron.manager.js.map +1 -1
  79. package/managers/method.manager.js +323 -303
  80. package/managers/method.manager.js.map +1 -1
  81. package/managers/mongo.manager.d.ts +14 -14
  82. package/managers/mongo.manager.js +794 -865
  83. package/managers/mongo.manager.js.map +1 -1
  84. package/managers/monitor.manager.js +171 -254
  85. package/managers/monitor.manager.js.map +1 -1
  86. package/managers/queue-method.manager.js +69 -166
  87. package/managers/queue-method.manager.js.map +1 -1
  88. package/managers/subscription.manager.js +515 -708
  89. package/managers/subscription.manager.js.map +1 -1
  90. package/methods/accounts.js +111 -183
  91. package/methods/accounts.js.map +1 -1
  92. package/methods/aws.js +156 -262
  93. package/methods/aws.js.map +1 -1
  94. package/methods/cloudconvert.js +100 -180
  95. package/methods/cloudconvert.js.map +1 -1
  96. package/methods/collections.js +114 -530
  97. package/methods/collections.js.map +1 -1
  98. package/methods/counters.js +29 -79
  99. package/methods/counters.js.map +1 -1
  100. package/methods/cron-jobs.js +819 -884
  101. package/methods/cron-jobs.js.map +1 -1
  102. package/methods/flags.js +1 -5
  103. package/methods/flags.js.map +1 -1
  104. package/methods/logs.js +258 -313
  105. package/methods/logs.js.map +1 -1
  106. package/methods/monitor.js +289 -348
  107. package/methods/monitor.js.map +1 -1
  108. package/methods/pdf.js +341 -340
  109. package/methods/pdf.js.map +1 -1
  110. package/methods/report-builder.js +565 -657
  111. package/methods/report-builder.js.map +1 -1
  112. package/methods/support.js +67 -185
  113. package/methods/support.js.map +1 -1
  114. package/models/app-status.model.js +1 -2
  115. package/models/app-version.model.js +1 -2
  116. package/models/billing-logged-in-users.model.js +1 -2
  117. package/models/collection-document.model.js +1 -2
  118. package/models/counter.model.js +1 -2
  119. package/models/cron-job-history.model.js +1 -2
  120. package/models/cron-job.model.js +1 -2
  121. package/models/dialog.model.js +1 -2
  122. package/models/email-history.model.js +1 -2
  123. package/models/email-verified.model.js +1 -2
  124. package/models/file.model.js +1 -2
  125. package/models/flag.model.js +1 -2
  126. package/models/log-method-latency.model.js +1 -2
  127. package/models/log-subscription.model.js +1 -2
  128. package/models/log.model.js +1 -2
  129. package/models/logged-in-users.model.js +1 -2
  130. package/models/method-call.model.js +1 -2
  131. package/models/method-response.model.js +1 -2
  132. package/models/method.model.js +1 -2
  133. package/models/monitor-cpu.model.js +1 -2
  134. package/models/monitor-https-inbound.model.js +1 -2
  135. package/models/monitor-https-outbound.model.js +1 -2
  136. package/models/monitor-memory.model.js +1 -2
  137. package/models/monitor-mongo.model.js +1 -2
  138. package/models/notification.model.js +1 -2
  139. package/models/pagination.model.js +2 -5
  140. package/models/pagination.model.js.map +1 -1
  141. package/models/permission.model.js +1 -2
  142. package/models/queue-method.model.js +1 -2
  143. package/models/queue-response.model.js +1 -2
  144. package/models/report-builder-dashboard-builder.model.js +1 -2
  145. package/models/report-builder-library.model.js +1 -2
  146. package/models/report-builder-report.model.js +1 -2
  147. package/models/report-builder.model.js +1 -2
  148. package/models/select-data-label.model.js +1 -2
  149. package/models/server-response.model.js +1 -2
  150. package/models/subscription.model.js +1 -2
  151. package/models/support-ticket.model.js +1 -2
  152. package/models/user-group.model.js +1 -2
  153. package/models/user-guide.model.js +1 -2
  154. package/models/user.model.js +1 -2
  155. package/package.json +1 -1
  156. package/public_api.js +70 -82
  157. package/public_api.js.map +1 -1
  158. package/publications/app-status.js +4 -8
  159. package/publications/app-status.js.map +1 -1
  160. package/publications/app-version.js +4 -8
  161. package/publications/app-version.js.map +1 -1
  162. package/publications/cron-jobs.js +9 -13
  163. package/publications/cron-jobs.js.map +1 -1
  164. package/publications/files.js +11 -15
  165. package/publications/files.js.map +1 -1
  166. package/publications/flags.js +7 -11
  167. package/publications/flags.js.map +1 -1
  168. package/publications/logs.js +31 -35
  169. package/publications/logs.js.map +1 -1
  170. package/publications/method-calls.js +4 -8
  171. package/publications/method-calls.js.map +1 -1
  172. package/publications/method-responses.js +4 -8
  173. package/publications/method-responses.js.map +1 -1
  174. package/publications/notifications.js +4 -8
  175. package/publications/notifications.js.map +1 -1
  176. package/publications/report-builder-dashboard-builders.js +8 -12
  177. package/publications/report-builder-dashboard-builders.js.map +1 -1
  178. package/publications/report-builder-libraries.js +16 -66
  179. package/publications/report-builder-libraries.js.map +1 -1
  180. package/publications/report-builder-reports.js +17 -21
  181. package/publications/report-builder-reports.js.map +1 -1
  182. package/publications/super-admin.js +3 -7
  183. package/publications/super-admin.js.map +1 -1
  184. package/publications/user-groups.js +4 -8
  185. package/publications/user-groups.js.map +1 -1
  186. package/publications/user-guides.js +4 -8
  187. package/publications/user-guides.js.map +1 -1
  188. package/server-app.js +393 -534
  189. package/server-app.js.map +1 -1
  190. package/util/common.js +55 -92
  191. package/util/common.js.map +1 -1
  192. package/util/schema-report-builder.js +76 -134
  193. package/util/schema-report-builder.js.map +1 -1
@@ -1,948 +1,883 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.loadCronJobMethods = void 0;
40
- var queue_method_collection_1 = require("../collections/queue-method.collection");
41
- var report_builder_report_collection_1 = require("../collections/report-builder-report.collection");
42
- var simpl_schema_1 = require("simpl-schema");
43
- var common_1 = require("../util/common");
44
- var moment = require("moment");
45
- var XLSX = require("xlsx");
46
- var Excel = require("exceljs");
47
- var file_collection_1 = require("../collections/file.collection");
48
- function loadCronJobMethods(methodManager) {
1
+ import { QueueMethods } from '../collections/queue-method.collection';
2
+ import { ReportBuilderReports } from '../collections/report-builder-report.collection';
3
+ import SimpleSchema from 'simpl-schema';
4
+ import { mergeDeep, deepCopy } from '../util/common';
5
+ import * as moment from 'moment';
6
+ import * as XLSX from 'xlsx';
7
+ import * as Excel from 'exceljs';
8
+ import { Files } from '../collections/file.collection';
9
+ export function loadCronJobMethods(methodManager) {
49
10
  methodManager.methods({
50
11
  methodQueue: {
51
12
  function: function () {
52
- var _this = this;
53
- return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
54
- var updateCnt;
55
- return __generator(this, function (_a) {
56
- switch (_a.label) {
57
- case 0: return [4 /*yield*/, queue_method_collection_1.QueueMethods.countDocuments()];
58
- case 1:
59
- updateCnt = _a.sent();
60
- if (updateCnt) {
61
- methodManager.getMainServer().getQueueManager().runMethodQueue();
62
- }
63
- resolve();
64
- return [2 /*return*/];
65
- }
66
- });
67
- }); });
13
+ return new Promise(async (resolve, reject) => {
14
+ let updateCnt = await QueueMethods.countDocuments();
15
+ if (updateCnt) {
16
+ methodManager.getMainServer().getQueueManager().runMethodQueue();
17
+ }
18
+ resolve();
19
+ });
68
20
  }
69
21
  },
70
22
  cronEmailMergedDocsCleanUp: {
71
23
  skipQueue: true,
72
24
  function: function () {
73
- var _this = this;
74
- return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
75
- var files;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0: return [4 /*yield*/, file_collection_1.Files.find({ $and: [{ type: 'Email Merged Docs' }, { createdAt: { $lte: moment().subtract(1, 'day').toDate() } }] })];
79
- case 1:
80
- files = _a.sent();
81
- if (files.length) {
82
- this.callMethodInternal('deleteFiles');
83
- file_collection_1.Files.deleteMany({ _id: { $in: files.map(function (a) { return a._id; }) } });
84
- }
85
- resolve();
86
- return [2 /*return*/];
87
- }
88
- });
89
- }); });
25
+ return new Promise(async (resolve, reject) => {
26
+ let files = await Files.find({ $and: [{ type: 'Email Merged Docs' }, { createdAt: { $lte: moment().subtract(1, 'day').toDate() } }] });
27
+ if (files.length) {
28
+ this.callMethodInternal('deleteFiles');
29
+ Files.deleteMany({ _id: { $in: files.map(a => a._id) } });
30
+ }
31
+ resolve();
32
+ });
90
33
  }
91
34
  },
92
35
  reportbuilderCronJob: {
93
36
  skipQueue: true,
94
- check: new simpl_schema_1.default({
37
+ check: new SimpleSchema({
95
38
  data: {
96
39
  type: Object,
97
40
  blackbox: true
98
41
  }
99
42
  }),
100
43
  function: function (data) {
101
- var _this = this;
102
- return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
103
- var report, fieldsObj_1, count_1, sortObj_1, rootOptions_1, filters_1;
104
- var _this = this;
105
- return __generator(this, function (_a) {
106
- switch (_a.label) {
107
- case 0: return [4 /*yield*/, report_builder_report_collection_1.ReportBuilderReports.findById(data['id_report'])];
108
- case 1:
109
- report = _a.sent();
110
- report.fields_selected.forEach(function (field) {
111
- var _a, _b;
112
- var dotPath = field.fieldPath.replace(/\.\$/g, '');
113
- var fieldData = dotPath.split('.');
114
- field.fieldPathObj = null;
115
- for (var i = fieldData.length - 1; i >= 0; i--) {
116
- if (!field.fieldPathObj) {
117
- field.fieldPathObj = (_a = {}, _a[fieldData[i]] = 1, _a);
44
+ return new Promise(async (resolve, reject) => {
45
+ let report = await ReportBuilderReports.findById(data['id_report']);
46
+ report.fields_selected.forEach((field) => {
47
+ let dotPath = field.fieldPath.replace(/\.\$/g, '');
48
+ let fieldData = dotPath.split('.');
49
+ field.fieldPathObj = null;
50
+ for (let i = fieldData.length - 1; i >= 0; i--) {
51
+ if (!field.fieldPathObj) {
52
+ field.fieldPathObj = { [fieldData[i]]: 1 };
53
+ }
54
+ else {
55
+ field.fieldPathObj = { [fieldData[i]]: field.fieldPathObj };
56
+ }
57
+ }
58
+ });
59
+ if ((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length)) {
60
+ let fieldsObj = {};
61
+ let count = 0;
62
+ report.fields_selected.forEach((field) => {
63
+ if (field.collection_name === report.collection_root) {
64
+ fieldsObj = mergeDeep(fieldsObj, field.fieldPathObj);
65
+ }
66
+ let sortIndex = report.fields_sort.findIndex(a => a.field === field['id']);
67
+ if (sortIndex >= 0) {
68
+ report.fields_sort[sortIndex].field = ('f_' + count);
69
+ }
70
+ field['id'] = 'f_' + count;
71
+ count += 1;
72
+ });
73
+ let sortObj = {};
74
+ if (report.fields_sort.length) {
75
+ report.fields_sort.forEach(sortField => {
76
+ if (sortField.field.startsWith('gr_')) {
77
+ sortObj['_id.' + sortField.field] = (sortField.order === 'asc' ? 1 : -1);
78
+ }
79
+ else {
80
+ sortObj[sortField.field] = (sortField.order === 'asc' ? 1 : -1);
81
+ }
82
+ });
83
+ }
84
+ else {
85
+ sortObj = null;
86
+ }
87
+ let rootOptions = {
88
+ limit: 0,
89
+ skip: 0,
90
+ fields: fieldsObj,
91
+ sort: sortObj
92
+ };
93
+ let filters = [];
94
+ report.fields_filter.forEach(filterAnd => {
95
+ let ors = [];
96
+ filterAnd.ors.filter(a => !a.field.includes('.$.')).forEach(filter => {
97
+ if (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {
98
+ if (filter.condition === 'bw') {
99
+ if (filter.fieldType === 'Date' && filter.is_rolling) {
100
+ let startDate = null;
101
+ let endDate = null;
102
+ if (filter.rolling_interval === 'Q1') {
103
+ startDate = moment().startOf('year').toDate();
104
+ endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
105
+ }
106
+ else if (filter.rolling_interval === 'Q2') {
107
+ startDate = moment().startOf('year').quarter(2).toDate();
108
+ endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
109
+ }
110
+ else if (filter.rolling_interval === 'Q3') {
111
+ startDate = moment().startOf('year').quarter(3).toDate();
112
+ endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
113
+ }
114
+ else if (filter.rolling_interval === 'Q4') {
115
+ startDate = moment().startOf('year').quarter(4).toDate();
116
+ endDate = moment().endOf('year').toDate();
117
+ }
118
+ else if (filter.rolling_interval === 'Today') {
119
+ startDate = moment().startOf('day').toDate();
120
+ endDate = moment().endOf('day').toDate();
121
+ }
122
+ else if (filter.rolling_interval === 'Yesterday') {
123
+ startDate = moment().subtract(1, 'days').startOf('day').toDate();
124
+ endDate = moment().subtract(1, 'days').endOf('day').toDate();
125
+ }
126
+ else if (filter.rolling_interval === 'Week') {
127
+ startDate = moment().startOf('isoWeek').toDate();
128
+ endDate = moment().endOf('day').toDate();
129
+ }
130
+ else if (filter.rolling_interval === 'Last Week') {
131
+ endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
132
+ startDate = moment(endDate).startOf('isoWeek').toDate();
133
+ }
134
+ else if (filter.rolling_interval === 'Month') {
135
+ startDate = moment().startOf('month').toDate();
136
+ endDate = moment().endOf('day').toDate();
137
+ }
138
+ else if (filter.rolling_interval === 'Last Month') {
139
+ endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
140
+ startDate = moment(endDate).startOf('month').toDate();
141
+ }
142
+ else if (filter.rolling_interval === 'Last 30 Days') {
143
+ endDate = moment().endOf('day').toDate();
144
+ startDate = moment().subtract(30, 'days').startOf('day').toDate();
145
+ }
146
+ else if (filter.rolling_interval === 'Quarter') {
147
+ startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
148
+ endDate = moment().endOf('day').toDate();
149
+ }
150
+ else if (filter.rolling_interval === 'Last Quarter') {
151
+ endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
152
+ startDate = moment(endDate).startOf('quarter').toDate();
153
+ }
154
+ else if (filter.rolling_interval === 'Year') {
155
+ startDate = moment().startOf('year').toDate();
156
+ endDate = moment().endOf('day').toDate();
157
+ }
158
+ else if (filter.rolling_interval === 'Last Year') {
159
+ endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
160
+ startDate = moment(endDate).startOf('year').toDate();
161
+ }
162
+ else if (filter.rolling_interval === 'All') {
163
+ startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
164
+ endDate = moment().endOf('day').toDate();
165
+ }
166
+ ors.push({ $and: [{ [filter.field]: { '$gte': startDate } }, { [filter.field]: { '$lte': endDate } }] });
118
167
  }
119
168
  else {
120
- field.fieldPathObj = (_b = {}, _b[fieldData[i]] = field.fieldPathObj, _b);
169
+ ors.push({ $and: [{ [filter.field]: { '$gte': filter.value } }, { [filter.field]: { '$lte': filter.highValue } }] });
121
170
  }
122
171
  }
123
- });
124
- if ((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length)) {
125
- fieldsObj_1 = {};
126
- count_1 = 0;
127
- report.fields_selected.forEach(function (field) {
128
- if (field.collection_name === report.collection_root) {
129
- fieldsObj_1 = common_1.mergeDeep(fieldsObj_1, field.fieldPathObj);
130
- }
131
- var sortIndex = report.fields_sort.findIndex(function (a) { return a.field === field['id']; });
132
- if (sortIndex >= 0) {
133
- report.fields_sort[sortIndex].field = ('f_' + count_1);
172
+ else if (filter.condition === 'nnull') {
173
+ let and = [];
174
+ and.push({ [filter.field]: { '$exists': true } });
175
+ and.push({ [filter.field]: { '$ne': null } });
176
+ if (filter.fieldType === 'String') {
177
+ and.push({ [filter.field]: { '$ne': '' } });
134
178
  }
135
- field['id'] = 'f_' + count_1;
136
- count_1 += 1;
137
- });
138
- sortObj_1 = {};
139
- if (report.fields_sort.length) {
140
- report.fields_sort.forEach(function (sortField) {
141
- if (sortField.field.startsWith('gr_')) {
142
- sortObj_1['_id.' + sortField.field] = (sortField.order === 'asc' ? 1 : -1);
179
+ ors.push({ $and: and });
180
+ }
181
+ else if (filter.condition === 'null') {
182
+ ors.push({ [filter.field]: { '$eq': null } });
183
+ }
184
+ else {
185
+ if (Array.isArray(filter.value)) {
186
+ if (filter.condition === 'ne') {
187
+ let and = [];
188
+ filter.value.forEach(filt => {
189
+ and.push({ [filter.field]: { ['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt) } });
190
+ });
191
+ if (and.length > 1) {
192
+ ors.push({ $and: and });
193
+ }
194
+ else {
195
+ ors.push(and[0]);
196
+ }
143
197
  }
144
198
  else {
145
- sortObj_1[sortField.field] = (sortField.order === 'asc' ? 1 : -1);
199
+ let or = [];
200
+ filter.value.forEach(filt => {
201
+ or.push({ [filter.field]: { ['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt) } });
202
+ });
203
+ if (or.length > 1) {
204
+ ors.push({ $or: or });
205
+ }
206
+ else {
207
+ ors.push(or[0]);
208
+ }
146
209
  }
147
- });
148
- }
149
- else {
150
- sortObj_1 = null;
210
+ }
211
+ else {
212
+ ors.push({ [filter.field]: { ['$' + filter.condition]: filter.value } });
213
+ }
151
214
  }
152
- rootOptions_1 = {
153
- limit: 0,
154
- skip: 0,
155
- fields: fieldsObj_1,
156
- sort: sortObj_1
157
- };
158
- filters_1 = [];
159
- report.fields_filter.forEach(function (filterAnd) {
160
- var ors = [];
161
- filterAnd.ors.filter(function (a) { return !a.field.includes('.$.'); }).forEach(function (filter) {
162
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
163
- if (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {
164
- if (filter.condition === 'bw') {
165
- if (filter.fieldType === 'Date' && filter.is_rolling) {
166
- var startDate = null;
167
- var endDate = null;
168
- if (filter.rolling_interval === 'Q1') {
169
- startDate = moment().startOf('year').toDate();
170
- endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
171
- }
172
- else if (filter.rolling_interval === 'Q2') {
173
- startDate = moment().startOf('year').quarter(2).toDate();
174
- endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
175
- }
176
- else if (filter.rolling_interval === 'Q3') {
177
- startDate = moment().startOf('year').quarter(3).toDate();
178
- endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
179
- }
180
- else if (filter.rolling_interval === 'Q4') {
181
- startDate = moment().startOf('year').quarter(4).toDate();
182
- endDate = moment().endOf('year').toDate();
183
- }
184
- else if (filter.rolling_interval === 'Today') {
185
- startDate = moment().startOf('day').toDate();
186
- endDate = moment().endOf('day').toDate();
187
- }
188
- else if (filter.rolling_interval === 'Yesterday') {
189
- startDate = moment().subtract(1, 'days').startOf('day').toDate();
190
- endDate = moment().subtract(1, 'days').endOf('day').toDate();
191
- }
192
- else if (filter.rolling_interval === 'Week') {
193
- startDate = moment().startOf('isoWeek').toDate();
194
- endDate = moment().endOf('day').toDate();
195
- }
196
- else if (filter.rolling_interval === 'Last Week') {
197
- endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
198
- startDate = moment(endDate).startOf('isoWeek').toDate();
199
- }
200
- else if (filter.rolling_interval === 'Month') {
201
- startDate = moment().startOf('month').toDate();
202
- endDate = moment().endOf('day').toDate();
203
- }
204
- else if (filter.rolling_interval === 'Last Month') {
205
- endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
206
- startDate = moment(endDate).startOf('month').toDate();
207
- }
208
- else if (filter.rolling_interval === 'Last 30 Days') {
209
- endDate = moment().endOf('day').toDate();
210
- startDate = moment().subtract(30, 'days').startOf('day').toDate();
211
- }
212
- else if (filter.rolling_interval === 'Quarter') {
213
- startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
214
- endDate = moment().endOf('day').toDate();
215
- }
216
- else if (filter.rolling_interval === 'Last Quarter') {
217
- endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
218
- startDate = moment(endDate).startOf('quarter').toDate();
219
- }
220
- else if (filter.rolling_interval === 'Year') {
221
- startDate = moment().startOf('year').toDate();
222
- endDate = moment().endOf('day').toDate();
223
- }
224
- else if (filter.rolling_interval === 'Last Year') {
225
- endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
226
- startDate = moment(endDate).startOf('year').toDate();
227
- }
228
- else if (filter.rolling_interval === 'All') {
229
- startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
230
- endDate = moment().endOf('day').toDate();
231
- }
232
- ors.push({ $and: [(_a = {}, _a[filter.field] = { '$gte': startDate }, _a), (_b = {}, _b[filter.field] = { '$lte': endDate }, _b)] });
215
+ }
216
+ });
217
+ if (ors.length) {
218
+ filters.push({ $or: ors });
219
+ }
220
+ });
221
+ this.callMethodInternal('reportBuilderBuildTree', report.collection_root, (errCollTree, collectionTree) => {
222
+ if (collectionTree) {
223
+ collectionTree.layers = [collectionTree];
224
+ let treeLeaves = [];
225
+ let allLeaves = [];
226
+ getTreeLeaves(collectionTree.children, treeLeaves);
227
+ getTreeLeaves(collectionTree.children, allLeaves, true);
228
+ let filterArrayFields = [];
229
+ let filterArrays = [];
230
+ report.fields_filter.forEach(filterAnd => {
231
+ let ors = [];
232
+ filterAnd.ors.filter(a => a.field.includes('.$.')).forEach(filter => {
233
+ filterArrayFields.push(allLeaves.filter(a => a.fieldPath === filter.field)[0]);
234
+ if (filter.condition && filter.field && filter.value !== null) {
235
+ if (filter.condition === 'bw') {
236
+ if (filter.fieldType === 'Date' && filter.is_rolling) {
237
+ let startDate = null;
238
+ let endDate = null;
239
+ if (filter.rolling_interval === 'Q1') {
240
+ startDate = moment().startOf('year').toDate();
241
+ endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
233
242
  }
234
- else {
235
- ors.push({ $and: [(_c = {}, _c[filter.field] = { '$gte': filter.value }, _c), (_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d)] });
243
+ else if (filter.rolling_interval === 'Q2') {
244
+ startDate = moment().startOf('year').quarter(2).toDate();
245
+ endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
236
246
  }
237
- }
238
- else if (filter.condition === 'nnull') {
239
- var and = [];
240
- and.push((_e = {}, _e[filter.field] = { '$exists': true }, _e));
241
- and.push((_f = {}, _f[filter.field] = { '$ne': null }, _f));
242
- if (filter.fieldType === 'String') {
243
- and.push((_g = {}, _g[filter.field] = { '$ne': '' }, _g));
247
+ else if (filter.rolling_interval === 'Q3') {
248
+ startDate = moment().startOf('year').quarter(3).toDate();
249
+ endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
244
250
  }
245
- ors.push({ $and: and });
246
- }
247
- else if (filter.condition === 'null') {
248
- ors.push((_h = {}, _h[filter.field] = { '$eq': null }, _h));
251
+ else if (filter.rolling_interval === 'Q4') {
252
+ startDate = moment().startOf('year').quarter(4).toDate();
253
+ endDate = moment().endOf('year').toDate();
254
+ }
255
+ else if (filter.rolling_interval === 'Today') {
256
+ startDate = moment().startOf('day').toDate();
257
+ endDate = moment().endOf('day').toDate();
258
+ }
259
+ else if (filter.rolling_interval === 'Yesterday') {
260
+ startDate = moment().subtract(1, 'days').startOf('day').toDate();
261
+ endDate = moment().subtract(1, 'days').endOf('day').toDate();
262
+ }
263
+ else if (filter.rolling_interval === 'Week') {
264
+ startDate = moment().startOf('isoWeek').toDate();
265
+ endDate = moment().endOf('day').toDate();
266
+ }
267
+ else if (filter.rolling_interval === 'Last Week') {
268
+ endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
269
+ startDate = moment(endDate).startOf('isoWeek').toDate();
270
+ }
271
+ else if (filter.rolling_interval === 'Month') {
272
+ startDate = moment().startOf('month').toDate();
273
+ endDate = moment().endOf('day').toDate();
274
+ }
275
+ else if (filter.rolling_interval === 'Last Month') {
276
+ endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
277
+ startDate = moment(endDate).startOf('month').toDate();
278
+ }
279
+ else if (filter.rolling_interval === 'Last 30 Days') {
280
+ endDate = moment().endOf('day').toDate();
281
+ startDate = moment().subtract(30, 'days').startOf('day').toDate();
282
+ }
283
+ else if (filter.rolling_interval === 'Quarter') {
284
+ startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
285
+ endDate = moment().endOf('day').toDate();
286
+ }
287
+ else if (filter.rolling_interval === 'Last Quarter') {
288
+ endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
289
+ startDate = moment(endDate).startOf('quarter').toDate();
290
+ }
291
+ else if (filter.rolling_interval === 'Year') {
292
+ startDate = moment().startOf('year').toDate();
293
+ endDate = moment().endOf('day').toDate();
294
+ }
295
+ else if (filter.rolling_interval === 'Last Year') {
296
+ endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
297
+ startDate = moment(endDate).startOf('year').toDate();
298
+ }
299
+ else if (filter.rolling_interval === 'All') {
300
+ startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
301
+ endDate = moment().endOf('day').toDate();
302
+ }
303
+ ors.push({ $and: [{ [filter.field]: { '$gte': startDate } }, { [filter.field]: { '$lte': endDate } }] });
249
304
  }
250
305
  else {
251
- if (Array.isArray(filter.value)) {
252
- if (filter.condition === 'ne') {
253
- var and_1 = [];
254
- filter.value.forEach(function (filt) {
255
- var _a, _b;
256
- and_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
257
- });
258
- if (and_1.length > 1) {
259
- ors.push({ $and: and_1 });
260
- }
261
- else {
262
- ors.push(and_1[0]);
263
- }
306
+ filterArrays.push({ $and: [{ [filter.field]: { '$gte': filter.value } }, { [filter.field]: { '$lte': filter.highValue } }] });
307
+ }
308
+ }
309
+ else if (filter.condition === 'nnull') {
310
+ let and = [];
311
+ and.push({ [filter.field.replace(/\.\$/g, '')]: { '$exists': true } });
312
+ and.push({ [filter.field.replace(/\.\$/g, '')]: { '$ne': null } });
313
+ if (filter.fieldType === 'String') {
314
+ and.push({ [filter.field.replace(/\.\$/g, '')]: { '$ne': '' } });
315
+ }
316
+ ors.push({ $and: and });
317
+ }
318
+ else if (filter.condition === 'null') {
319
+ ors.push({ [filter.field.replace(/\.\$/g, '')]: { '$eq': null } });
320
+ }
321
+ else {
322
+ if (Array.isArray(filter.value)) {
323
+ if (filter.condition === 'ne') {
324
+ let and = [];
325
+ filter.value.forEach(filt => {
326
+ and.push({ [filter.field.replace(/\.\$/g, '')]: { ['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt) } });
327
+ });
328
+ if (and.length > 1) {
329
+ ors.push({ $and: and });
264
330
  }
265
331
  else {
266
- var or_1 = [];
267
- filter.value.forEach(function (filt) {
268
- var _a, _b;
269
- or_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
270
- });
271
- if (or_1.length > 1) {
272
- ors.push({ $or: or_1 });
273
- }
274
- else {
275
- ors.push(or_1[0]);
276
- }
332
+ ors.push(and[0]);
277
333
  }
278
334
  }
279
335
  else {
280
- ors.push((_j = {}, _j[filter.field] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
336
+ let or = [];
337
+ filter.value.forEach(filt => {
338
+ or.push({ [filter.field.replace(/\.\$/g, '')]: { ['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt) } });
339
+ });
340
+ if (or.length > 1) {
341
+ ors.push({ $or: or });
342
+ }
343
+ else {
344
+ ors.push(or[0]);
345
+ }
281
346
  }
282
347
  }
348
+ else {
349
+ ors.push({ [filter.field.replace(/\.\$/g, '')]: { ['$' + filter.condition]: filter.value } });
350
+ }
283
351
  }
284
- });
285
- if (ors.length) {
286
- filters_1.push({ $or: ors });
287
352
  }
288
353
  });
289
- this.callMethodInternal('reportBuilderBuildTree', report.collection_root, function (errCollTree, collectionTree) {
290
- if (collectionTree) {
291
- collectionTree.layers = [collectionTree];
292
- var treeLeaves = [];
293
- var allLeaves_1 = [];
294
- getTreeLeaves(collectionTree.children, treeLeaves);
295
- getTreeLeaves(collectionTree.children, allLeaves_1, true);
296
- var filterArrayFields_1 = [];
297
- var filterArrays_1 = [];
298
- report.fields_filter.forEach(function (filterAnd) {
299
- var ors = [];
300
- filterAnd.ors.filter(function (a) { return a.field.includes('.$.'); }).forEach(function (filter) {
301
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
302
- filterArrayFields_1.push(allLeaves_1.filter(function (a) { return a.fieldPath === filter.field; })[0]);
303
- if (filter.condition && filter.field && filter.value !== null) {
304
- if (filter.condition === 'bw') {
305
- if (filter.fieldType === 'Date' && filter.is_rolling) {
306
- var startDate = null;
307
- var endDate = null;
308
- if (filter.rolling_interval === 'Q1') {
309
- startDate = moment().startOf('year').toDate();
310
- endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
311
- }
312
- else if (filter.rolling_interval === 'Q2') {
313
- startDate = moment().startOf('year').quarter(2).toDate();
314
- endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
315
- }
316
- else if (filter.rolling_interval === 'Q3') {
317
- startDate = moment().startOf('year').quarter(3).toDate();
318
- endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
319
- }
320
- else if (filter.rolling_interval === 'Q4') {
321
- startDate = moment().startOf('year').quarter(4).toDate();
322
- endDate = moment().endOf('year').toDate();
323
- }
324
- else if (filter.rolling_interval === 'Today') {
325
- startDate = moment().startOf('day').toDate();
326
- endDate = moment().endOf('day').toDate();
327
- }
328
- else if (filter.rolling_interval === 'Yesterday') {
329
- startDate = moment().subtract(1, 'days').startOf('day').toDate();
330
- endDate = moment().subtract(1, 'days').endOf('day').toDate();
331
- }
332
- else if (filter.rolling_interval === 'Week') {
333
- startDate = moment().startOf('isoWeek').toDate();
334
- endDate = moment().endOf('day').toDate();
335
- }
336
- else if (filter.rolling_interval === 'Last Week') {
337
- endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
338
- startDate = moment(endDate).startOf('isoWeek').toDate();
339
- }
340
- else if (filter.rolling_interval === 'Month') {
341
- startDate = moment().startOf('month').toDate();
342
- endDate = moment().endOf('day').toDate();
343
- }
344
- else if (filter.rolling_interval === 'Last Month') {
345
- endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
346
- startDate = moment(endDate).startOf('month').toDate();
347
- }
348
- else if (filter.rolling_interval === 'Last 30 Days') {
349
- endDate = moment().endOf('day').toDate();
350
- startDate = moment().subtract(30, 'days').startOf('day').toDate();
351
- }
352
- else if (filter.rolling_interval === 'Quarter') {
353
- startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
354
- endDate = moment().endOf('day').toDate();
355
- }
356
- else if (filter.rolling_interval === 'Last Quarter') {
357
- endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
358
- startDate = moment(endDate).startOf('quarter').toDate();
359
- }
360
- else if (filter.rolling_interval === 'Year') {
361
- startDate = moment().startOf('year').toDate();
362
- endDate = moment().endOf('day').toDate();
363
- }
364
- else if (filter.rolling_interval === 'Last Year') {
365
- endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
366
- startDate = moment(endDate).startOf('year').toDate();
367
- }
368
- else if (filter.rolling_interval === 'All') {
369
- startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
370
- endDate = moment().endOf('day').toDate();
371
- }
372
- ors.push({ $and: [(_a = {}, _a[filter.field] = { '$gte': startDate }, _a), (_b = {}, _b[filter.field] = { '$lte': endDate }, _b)] });
373
- }
374
- else {
375
- filterArrays_1.push({ $and: [(_c = {}, _c[filter.field] = { '$gte': filter.value }, _c), (_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d)] });
376
- }
354
+ if (ors.length) {
355
+ filterArrays.push({ $or: ors });
356
+ }
357
+ });
358
+ this.callMethodInternal('reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters, filterArrays, filterArrayFields, report.fields_selected, report.fields_custom, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type, (err, res) => {
359
+ if (res && res[0]) {
360
+ let results = res[0].results;
361
+ let reportTotals = res[0].totals;
362
+ if (report.type === 'List') {
363
+ report.fields_selected.filter(a => a.show).forEach(field => {
364
+ if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
365
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
366
+ result[field.id] = result[field.id].toLocaleString();
367
+ });
368
+ }
369
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
370
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
371
+ result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
372
+ });
373
+ }
374
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
375
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
376
+ result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
377
+ });
378
+ }
379
+ else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
380
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
381
+ result[field.id] = result[field.id] === true ? 'True' : 'False';
382
+ });
383
+ }
384
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
385
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
386
+ result[field.id] = result[field.id] === true ? 'Yes' : 'No';
387
+ });
388
+ }
389
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
390
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
391
+ result[field.id] = result[field.id] === true ? 1 : 0;
392
+ });
393
+ }
394
+ else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
395
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
396
+ result[field.id] = moment(result[field.id]).format('L');
397
+ });
398
+ }
399
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
400
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
401
+ result[field.id] = moment(result[field.id]).format('LT');
402
+ });
403
+ }
404
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
405
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
406
+ result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
407
+ });
408
+ }
409
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
410
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
411
+ result[field.id] = moment(result[field.id]).format('LL');
412
+ });
413
+ }
414
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
415
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
416
+ result[field.id] = moment(result[field.id]).format('LLL');
417
+ });
418
+ }
419
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
420
+ results.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {
421
+ result[field.id] = moment(result[field.id]).toDate().getTime();
422
+ });
423
+ }
424
+ });
425
+ let lines = [];
426
+ let tmpHeaders = {};
427
+ report.groups_row.forEach(group => {
428
+ tmpHeaders[group.id] = group.columnName;
429
+ });
430
+ report.fields_selected.filter(a => a.show).forEach(header => {
431
+ tmpHeaders[header.columnName] = header.columnName;
432
+ });
433
+ let wb = XLSX.utils.book_new();
434
+ results.forEach(result => {
435
+ let tmp = {};
436
+ report.groups_row.forEach(group => {
437
+ if (Array.isArray(result._id[group.id])) {
438
+ tmp[group.columnName] = result._id[group.id].join(',');
439
+ }
440
+ else {
441
+ if (group.treeItem.fieldType === 'Number') {
442
+ tmp[group.columnName] = result._id[group.id] ? (typeof (result._id[group.id]) === 'string' ? parseFloat(result._id[group.id].replace(/,/g, '').replace(/\$/g, '')) : result._id[group.id]) : '';
377
443
  }
378
- else if (filter.condition === 'nnull') {
379
- var and = [];
380
- and.push((_e = {}, _e[filter.field.replace(/\.\$/g, '')] = { '$exists': true }, _e));
381
- and.push((_f = {}, _f[filter.field.replace(/\.\$/g, '')] = { '$ne': null }, _f));
382
- if (filter.fieldType === 'String') {
383
- and.push((_g = {}, _g[filter.field.replace(/\.\$/g, '')] = { '$ne': '' }, _g));
384
- }
385
- ors.push({ $and: and });
444
+ else {
445
+ tmp[group.columnName] = result._id[group.id] || '';
386
446
  }
387
- else if (filter.condition === 'null') {
388
- ors.push((_h = {}, _h[filter.field.replace(/\.\$/g, '')] = { '$eq': null }, _h));
447
+ }
448
+ });
449
+ report.fields_selected.filter(a => a.show).forEach(header => {
450
+ if (Array.isArray(result[header.id])) {
451
+ tmp[header.columnName] = result[header.id].join(',');
452
+ }
453
+ else {
454
+ if (header.fieldType === 'Number' || header.leafValueType === 'Count') {
455
+ tmp[header.columnName] = result[header.id] ? (typeof (result[header.id]) === 'string' ? parseFloat(result[header.id].replace(/,/g, '').replace(/\$/g, '')) : result[header.id]) : '';
389
456
  }
390
457
  else {
391
- if (Array.isArray(filter.value)) {
392
- if (filter.condition === 'ne') {
393
- var and_2 = [];
394
- filter.value.forEach(function (filt) {
395
- var _a, _b;
396
- and_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
397
- });
398
- if (and_2.length > 1) {
399
- ors.push({ $and: and_2 });
400
- }
401
- else {
402
- ors.push(and_2[0]);
403
- }
404
- }
405
- else {
406
- var or_2 = [];
407
- filter.value.forEach(function (filt) {
408
- var _a, _b;
409
- or_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
410
- });
411
- if (or_2.length > 1) {
412
- ors.push({ $or: or_2 });
413
- }
414
- else {
415
- ors.push(or_2[0]);
416
- }
417
- }
418
- }
419
- else {
420
- ors.push((_j = {}, _j[filter.field.replace(/\.\$/g, '')] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
421
- }
458
+ tmp[header.columnName] = result[header.id] || '';
459
+ }
460
+ }
461
+ });
462
+ lines.push(tmp);
463
+ });
464
+ let ws = XLSX.utils.json_to_sheet(lines);
465
+ XLSX.utils.book_append_sheet(wb, ws, 'RB Data');
466
+ let wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'base64' });
467
+ data['emails'].forEach(email => {
468
+ this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', `
469
+ <b>` + this.serverConfig['CLIENT_NAME'] + ` Automated Report</b><br>
470
+ <b>Report Name: </b>` + report.report_name + `<br>
471
+ <b>Prepared By: </b>` + data['user'] + `<br><br>
472
+ Attached are the results of this automated report.<br><br>
473
+ ResolveIO<br><br>`, [
474
+ {
475
+ filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',
476
+ content: wbout,
477
+ encoding: 'base64'
478
+ }
479
+ ], this.serverConfig['MAIL_FROM_REPORTS']);
480
+ });
481
+ }
482
+ else if (report.type === 'Group') {
483
+ report.fields_selected.filter(a => a.show).forEach(field => {
484
+ results.forEach(result => {
485
+ modifyDataTypeField(report, result, field, 1);
486
+ });
487
+ });
488
+ let wb = new Excel.Workbook();
489
+ let ws = wb.addWorksheet('RB_1', { views: [{ showGridLines: false }] });
490
+ wb.properties.date1904 = false;
491
+ wb.calcProperties.fullCalcOnLoad = true;
492
+ let currentRow = 1;
493
+ let row = ws.getRow(currentRow);
494
+ row.getCell(2).font = {
495
+ name: 'Arial',
496
+ bold: true,
497
+ size: 14
498
+ };
499
+ row.getCell(4).font = {
500
+ name: 'Arial',
501
+ size: 14
502
+ };
503
+ row.getCell(2).value = 'Report Name:';
504
+ row.getCell(4).value = report.report_name;
505
+ currentRow += 1;
506
+ row = ws.getRow(currentRow);
507
+ row.getCell(2).font = {
508
+ name: 'Arial',
509
+ bold: true,
510
+ size: 14
511
+ };
512
+ row.getCell(4).font = {
513
+ name: 'Arial',
514
+ size: 14
515
+ };
516
+ row.getCell(2).value = 'Run Date:';
517
+ row.getCell(4).value = moment().format('LLL');
518
+ currentRow += 2;
519
+ let copy = deepCopy(results);
520
+ let widths = [];
521
+ copy.forEach(res => {
522
+ currentRow = tabGroupExcelRecursive(report, ws, currentRow, 1, res);
523
+ tabGroupExcelWidthRecursive(report, 1, res, widths);
524
+ });
525
+ for (let i = 1; i < ws.columns.length; i++) {
526
+ ws.columns[i].width = widths[i - 1];
527
+ }
528
+ let now = new Date();
529
+ wb.xlsx.writeBuffer().then(buffer => {
530
+ data['emails'].forEach(email => {
531
+ this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', `
532
+ <b>` + this.serverConfig['CLIENT_NAME'] + ` Automated Report</b><br>
533
+ <b>Report Name: </b>` + report.report_name + `<br>
534
+ <b>Prepared By: </b>` + data['user'] + `<br><br>
535
+ Attached are the results of this automated report.<br><br>
536
+ Have a great day!<br><br>
537
+ ResolveIO<br><br>`, [
538
+ {
539
+ filename: 'Group_Report_' + report.report_name + '_' + now.getFullYear() + '_' + (now.getMonth() + 1) + '_' + now.getDate() + '.xlsx',
540
+ content: buffer
422
541
  }
542
+ ], this.serverConfig['MAIL_FROM_REPORTS']);
543
+ });
544
+ }).catch(err => console.log('Error writing excel export', err));
545
+ }
546
+ else if (report.type === 'Dated') {
547
+ let lines = [];
548
+ let tmpHeaders = {};
549
+ report.groups_row.forEach(group => {
550
+ tmpHeaders[group.id] = group.columnName;
551
+ });
552
+ tmpHeaders[''] = '';
553
+ let datedUniqueDates = [];
554
+ let datedUniqueGroups = [];
555
+ if (report.date_interval === 'Quarterly') {
556
+ results.forEach(dataPt => {
557
+ if (dataPt._id.month < 4) {
558
+ dataPt._id.quarter = 1;
559
+ }
560
+ else if (dataPt._id.month < 7) {
561
+ dataPt._id.quarter = 2;
423
562
  }
563
+ else if (dataPt._id.month < 10) {
564
+ dataPt._id.quarter = 3;
565
+ }
566
+ else {
567
+ dataPt._id.quarter = 4;
568
+ }
569
+ delete dataPt._id.month;
424
570
  });
425
- if (ors.length) {
426
- filterArrays_1.push({ $or: ors });
571
+ for (let i = results.length - 1; i >= 1; i--) {
572
+ let dataPt = results[i];
573
+ if (results.filter(a => JSON.stringify(a._id) === JSON.stringify(dataPt._id)).length > 1) {
574
+ let tmpData = results.filter(a => JSON.stringify(a._id) === JSON.stringify(dataPt._id))[0];
575
+ Object.keys(tmpData).filter(a => a !== '_id').forEach(key => {
576
+ tmpData[key] += dataPt[key];
577
+ });
578
+ results.splice(i, 1);
579
+ }
580
+ }
581
+ }
582
+ let tmpResults = deepCopy(results);
583
+ tmpResults.forEach(result => {
584
+ delete result._id.day;
585
+ delete result._id.week;
586
+ delete result._id.month;
587
+ delete result._id.quarter;
588
+ delete result._id.year;
589
+ let tmp = {};
590
+ Object.keys(result._id).forEach(key => {
591
+ tmp[key] = result._id[key];
592
+ });
593
+ if (!datedUniqueGroups.filter(a => JSON.stringify(a) === JSON.stringify(tmp)).length) {
594
+ datedUniqueGroups.push(tmp);
427
595
  }
428
596
  });
429
- _this.callMethodInternal('reportBuilderGetResults', report.type, report.collection_root, rootOptions_1, filters_1, filterArrays_1, filterArrayFields_1, report.fields_selected, report.fields_custom, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type, function (err, res) {
430
- if (res && res[0]) {
431
- var results_1 = res[0].results;
432
- var reportTotals = res[0].totals;
433
- if (report.type === 'List') {
434
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field) {
435
- if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
436
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
437
- result[field.id] = result[field.id].toLocaleString();
438
- });
439
- }
440
- else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
441
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
442
- result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
443
- });
444
- }
445
- else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
446
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
447
- result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
448
- });
449
- }
450
- else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
451
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
452
- result[field.id] = result[field.id] === true ? 'True' : 'False';
453
- });
454
- }
455
- else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
456
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
457
- result[field.id] = result[field.id] === true ? 'Yes' : 'No';
458
- });
459
- }
460
- else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
461
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
462
- result[field.id] = result[field.id] === true ? 1 : 0;
463
- });
464
- }
465
- else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
466
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
467
- result[field.id] = moment(result[field.id]).format('L');
468
- });
469
- }
470
- else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
471
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
472
- result[field.id] = moment(result[field.id]).format('LT');
473
- });
474
- }
475
- else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
476
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
477
- result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
478
- });
479
- }
480
- else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
481
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
482
- result[field.id] = moment(result[field.id]).format('LL');
483
- });
484
- }
485
- else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
486
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
487
- result[field.id] = moment(result[field.id]).format('LLL');
488
- });
489
- }
490
- else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
491
- results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
492
- result[field.id] = moment(result[field.id]).toDate().getTime();
493
- });
597
+ tmpResults = deepCopy(results);
598
+ tmpResults.forEach(result => {
599
+ Object.keys(result._id).filter(a => a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year').forEach(key => {
600
+ delete result._id[key];
601
+ });
602
+ let tmp = {};
603
+ Object.keys(result._id).forEach(key => {
604
+ tmp[key] = result._id[key];
605
+ });
606
+ if (!datedUniqueDates.filter(a => JSON.stringify(a) === JSON.stringify(tmp)).length) {
607
+ datedUniqueDates.push(tmp);
608
+ }
609
+ });
610
+ datedUniqueDates.forEach(result => {
611
+ if (!result.year) {
612
+ result.dateString = 'No Date';
613
+ }
614
+ else {
615
+ if (report.date_interval === 'Daily') {
616
+ result.date = new Date(result.year, result.month - 1, result.day, 0, 0, 0, 0);
617
+ result.dateString = moment(result.date).format('MMM DD YYYY');
618
+ }
619
+ else if (report.date_interval === 'Weekly') {
620
+ result.date = moment().day('Monday').isoWeekYear(result.year).isoWeek(result.week).toDate();
621
+ result.dateLast = moment().day('Sunday').isoWeekYear(result.year).isoWeek(result.week).toDate();
622
+ result.dateString = 'Week #' + result.week + ' ' + result.year + '(' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';
623
+ }
624
+ else if (report.date_interval === 'Monthly') {
625
+ result.date = new Date(result.year, result.month - 1, 1, 0, 0, 0, 0);
626
+ result.dateString = moment(result.date).format('MMM YYYY');
627
+ }
628
+ else if (report.date_interval === 'Quarterly') {
629
+ result.date = moment().quarter(result.quarter).year(result.year).toDate();
630
+ result.dateString = 'Q' + result.quarter + ' ' + result.year;
631
+ }
632
+ else if (report.date_interval === 'Yearly') {
633
+ result.date = new Date(result.year);
634
+ result.dateString = result.year.toString();
635
+ }
636
+ }
637
+ });
638
+ datedUniqueDates = datedUniqueDates.filter(a => !a.date).concat(datedUniqueDates.filter(a => a.date).sort((a, b) => a.date.getTime() - b.date.getTime()));
639
+ let reportTotalGroups = [];
640
+ let reportTotalDates = [];
641
+ let datedData = [];
642
+ datedUniqueDates.forEach(date => {
643
+ let tmpData = [];
644
+ let tmpTotalDated = {};
645
+ let tmpTotalCnt = {};
646
+ let tmpTotalType = {};
647
+ datedUniqueGroups.forEach(group => {
648
+ let result = results.filter(a => {
649
+ let res = true;
650
+ Object.keys(date).filter(a => a !== 'date' && a !== 'dateLast' && a !== 'dateString').forEach(key => {
651
+ if (a._id[key] !== date[key]) {
652
+ res = false;
494
653
  }
495
654
  });
496
- var lines_1 = [];
497
- var tmpHeaders_1 = {};
498
- report.groups_row.forEach(function (group) {
499
- tmpHeaders_1[group.id] = group.columnName;
500
- });
501
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (header) {
502
- tmpHeaders_1[header.columnName] = header.columnName;
655
+ Object.keys(group).forEach(key => {
656
+ if (a._id[key] !== group[key]) {
657
+ res = false;
658
+ }
503
659
  });
504
- var wb = XLSX.utils.book_new();
505
- results_1.forEach(function (result) {
506
- var tmp = {};
507
- report.groups_row.forEach(function (group) {
508
- if (Array.isArray(result._id[group.id])) {
509
- tmp[group.columnName] = result._id[group.id].join(',');
660
+ return res;
661
+ })[0];
662
+ if (result) {
663
+ tmpData.push(result);
664
+ Object.keys(result._id).filter(a => a).forEach(key => {
665
+ if (report.fields_total.filter(a => a.fields.includes(key)).length) {
666
+ if (!tmpTotalDated[key]) {
667
+ tmpTotalDated[key] = result._id[key];
510
668
  }
511
669
  else {
512
- if (group.treeItem.fieldType === 'Number') {
513
- tmp[group.columnName] = result._id[group.id] ? (typeof (result._id[group.id]) === 'string' ? parseFloat(result._id[group.id].replace(/,/g, '').replace(/\$/g, '')) : result._id[group.id]) : '';
514
- }
515
- else {
516
- tmp[group.columnName] = result._id[group.id] || '';
517
- }
670
+ tmpTotalDated[key] += result._id[key];
518
671
  }
519
- });
520
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (header) {
521
- if (Array.isArray(result[header.id])) {
522
- tmp[header.columnName] = result[header.id].join(',');
672
+ if (!tmpTotalCnt[key]) {
673
+ tmpTotalCnt[key] = 1;
523
674
  }
524
675
  else {
525
- if (header.fieldType === 'Number' || header.leafValueType === 'Count') {
526
- tmp[header.columnName] = result[header.id] ? (typeof (result[header.id]) === 'string' ? parseFloat(result[header.id].replace(/,/g, '').replace(/\$/g, '')) : result[header.id]) : '';
527
- }
528
- else {
529
- tmp[header.columnName] = result[header.id] || '';
530
- }
531
- }
532
- });
533
- lines_1.push(tmp);
534
- });
535
- var ws = XLSX.utils.json_to_sheet(lines_1);
536
- XLSX.utils.book_append_sheet(wb, ws, 'RB Data');
537
- var wbout_1 = XLSX.write(wb, { bookType: 'xlsx', type: 'base64' });
538
- data['emails'].forEach(function (email) {
539
- _this.sendEmail(email, _this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t<b>" + _this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
540
- {
541
- filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',
542
- content: wbout_1,
543
- encoding: 'base64'
676
+ tmpTotalCnt[key] += 1;
544
677
  }
545
- ], _this.serverConfig['MAIL_FROM_REPORTS']);
546
- });
547
- }
548
- else if (report.type === 'Group') {
549
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field) {
550
- results_1.forEach(function (result) {
551
- modifyDataTypeField(report, result, field, 1);
552
- });
553
- });
554
- var wb = new Excel.Workbook();
555
- var ws_1 = wb.addWorksheet('RB_1', { views: [{ showGridLines: false }] });
556
- wb.properties.date1904 = false;
557
- wb.calcProperties.fullCalcOnLoad = true;
558
- var currentRow_1 = 1;
559
- var row = ws_1.getRow(currentRow_1);
560
- row.getCell(2).font = {
561
- name: 'Arial',
562
- bold: true,
563
- size: 14
564
- };
565
- row.getCell(4).font = {
566
- name: 'Arial',
567
- size: 14
568
- };
569
- row.getCell(2).value = 'Report Name:';
570
- row.getCell(4).value = report.report_name;
571
- currentRow_1 += 1;
572
- row = ws_1.getRow(currentRow_1);
573
- row.getCell(2).font = {
574
- name: 'Arial',
575
- bold: true,
576
- size: 14
577
- };
578
- row.getCell(4).font = {
579
- name: 'Arial',
580
- size: 14
581
- };
582
- row.getCell(2).value = 'Run Date:';
583
- row.getCell(4).value = moment().format('LLL');
584
- currentRow_1 += 2;
585
- var copy = common_1.deepCopy(results_1);
586
- var widths_1 = [];
587
- copy.forEach(function (res) {
588
- currentRow_1 = tabGroupExcelRecursive(report, ws_1, currentRow_1, 1, res);
589
- tabGroupExcelWidthRecursive(report, 1, res, widths_1);
590
- });
591
- for (var i = 1; i < ws_1.columns.length; i++) {
592
- ws_1.columns[i].width = widths_1[i - 1];
593
- }
594
- var now_1 = new Date();
595
- wb.xlsx.writeBuffer().then(function (buffer) {
596
- data['emails'].forEach(function (email) {
597
- _this.sendEmail(email, _this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>" + _this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
598
- {
599
- filename: 'Group_Report_' + report.report_name + '_' + now_1.getFullYear() + '_' + (now_1.getMonth() + 1) + '_' + now_1.getDate() + '.xlsx',
600
- content: buffer
601
- }
602
- ], _this.serverConfig['MAIL_FROM_REPORTS']);
603
- });
604
- }).catch(function (err) { return console.log('Error writing excel export', err); });
605
- }
606
- else if (report.type === 'Dated') {
607
- var lines_2 = [];
608
- var tmpHeaders_2 = {};
609
- report.groups_row.forEach(function (group) {
610
- tmpHeaders_2[group.id] = group.columnName;
678
+ tmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;
679
+ }
611
680
  });
612
- tmpHeaders_2[''] = '';
613
- var datedUniqueDates_1 = [];
614
- var datedUniqueGroups_1 = [];
615
- if (report.date_interval === 'Quarterly') {
616
- results_1.forEach(function (dataPt) {
617
- if (dataPt._id.month < 4) {
618
- dataPt._id.quarter = 1;
681
+ Object.keys(result).filter(a => a && a !== '_id').forEach(key => {
682
+ if (report.fields_total.filter(a => a.fields.includes(key)).length) {
683
+ if (!tmpTotalDated[key]) {
684
+ tmpTotalDated[key] = result[key];
619
685
  }
620
- else if (dataPt._id.month < 7) {
621
- dataPt._id.quarter = 2;
686
+ else {
687
+ tmpTotalDated[key] += result[key];
622
688
  }
623
- else if (dataPt._id.month < 10) {
624
- dataPt._id.quarter = 3;
689
+ if (!tmpTotalCnt[key]) {
690
+ tmpTotalCnt[key] = 1;
625
691
  }
626
692
  else {
627
- dataPt._id.quarter = 4;
628
- }
629
- delete dataPt._id.month;
630
- });
631
- var _loop_1 = function (i) {
632
- var dataPt = results_1[i];
633
- if (results_1.filter(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); }).length > 1) {
634
- var tmpData_1 = results_1.filter(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); })[0];
635
- Object.keys(tmpData_1).filter(function (a) { return a !== '_id'; }).forEach(function (key) {
636
- tmpData_1[key] += dataPt[key];
637
- });
638
- results_1.splice(i, 1);
693
+ tmpTotalCnt[key] += 1;
639
694
  }
640
- };
641
- for (var i = results_1.length - 1; i >= 1; i--) {
642
- _loop_1(i);
643
- }
644
- }
645
- var tmpResults = common_1.deepCopy(results_1);
646
- tmpResults.forEach(function (result) {
647
- delete result._id.day;
648
- delete result._id.week;
649
- delete result._id.month;
650
- delete result._id.quarter;
651
- delete result._id.year;
652
- var tmp = {};
653
- Object.keys(result._id).forEach(function (key) {
654
- tmp[key] = result._id[key];
655
- });
656
- if (!datedUniqueGroups_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(tmp); }).length) {
657
- datedUniqueGroups_1.push(tmp);
695
+ tmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;
658
696
  }
659
697
  });
660
- tmpResults = common_1.deepCopy(results_1);
661
- tmpResults.forEach(function (result) {
662
- Object.keys(result._id).filter(function (a) { return a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
663
- delete result._id[key];
664
- });
665
- var tmp = {};
666
- Object.keys(result._id).forEach(function (key) {
667
- tmp[key] = result._id[key];
668
- });
669
- if (!datedUniqueDates_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(tmp); }).length) {
670
- datedUniqueDates_1.push(tmp);
698
+ }
699
+ else {
700
+ tmpData.push(null);
701
+ }
702
+ });
703
+ Object.keys(tmpTotalType).forEach(totalKey => {
704
+ if (tmpTotalType[totalKey] === 'avg') {
705
+ tmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];
706
+ }
707
+ tmpTotalDated[totalKey] = Math.round(tmpTotalDated[totalKey] * 100) / 100;
708
+ });
709
+ reportTotalDates.push(tmpTotalDated);
710
+ datedData.push(tmpData);
711
+ });
712
+ datedUniqueGroups.forEach(group => {
713
+ let tmpTotalGroup = {};
714
+ let filteredData = results.filter(a => {
715
+ let res = (!Object.keys(group).length || group._id === null) ? false : true;
716
+ Object.keys(group).filter(a => a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year').forEach(key => {
717
+ if (a._id[key] !== group[key]) {
718
+ res = false;
719
+ }
720
+ });
721
+ return res;
722
+ });
723
+ report.fields_total.forEach(total => {
724
+ total.fields.forEach(field => {
725
+ if (filteredData.length) {
726
+ tmpTotalGroup[field] = filteredData.filter(a => a && a[field]).map(a => a[field]).reduce((a, b) => a + b, 0);
727
+ if (total.type === 'avg') {
728
+ tmpTotalGroup[field] = Math.round(tmpTotalGroup[field] / filteredData.length * 100) / 100;
671
729
  }
672
- });
673
- datedUniqueDates_1.forEach(function (result) {
674
- if (!result.year) {
675
- result.dateString = 'No Date';
730
+ }
731
+ else {
732
+ tmpTotalGroup[field] = 0;
733
+ }
734
+ });
735
+ });
736
+ reportTotalGroups.push(tmpTotalGroup);
737
+ });
738
+ datedUniqueDates.forEach(date => {
739
+ tmpHeaders[date.dateString] = date.dateString;
740
+ });
741
+ tmpHeaders['Totals'] = 'Totals';
742
+ lines.push(tmpHeaders);
743
+ for (let i = 0; i <= datedUniqueGroups.length - 1; i++) {
744
+ let group = datedUniqueGroups[i];
745
+ for (let j = 0; j <= report.fields_selected.filter(a => a.show).length - 1; j++) {
746
+ let field = report.fields_selected.filter(a => a.show)[j];
747
+ let tmp = {};
748
+ for (let k = 0; k <= report.groups_row.length - 1; k++) {
749
+ let groupRow = report.groups_row[k];
750
+ if (j === 0) {
751
+ tmp[group[groupRow.id]] = group[groupRow.id];
752
+ }
753
+ else {
754
+ tmp[group[groupRow.id]] = '';
755
+ }
756
+ }
757
+ tmp[field.columnName] = field.columnName;
758
+ for (let k = 0; k <= datedData.length - 1; k++) {
759
+ let result = datedData[k];
760
+ if (result[i]) {
761
+ if (allLeaves.filter(a => a.id === field.id)[0] && allLeaves.filter(a => a.id === field.id)[0].fieldType === 'Number') {
762
+ tmp[i + ' ' + j + ' ' + k] = result[i][field.id] ? (typeof (result[i][field.id]) === 'string' ? parseInt(result[i][field.id].replace(/,/g, '')) : result[i][field.id]) : '';
676
763
  }
677
764
  else {
678
- if (report.date_interval === 'Daily') {
679
- result.date = new Date(result.year, result.month - 1, result.day, 0, 0, 0, 0);
680
- result.dateString = moment(result.date).format('MMM DD YYYY');
681
- }
682
- else if (report.date_interval === 'Weekly') {
683
- result.date = moment().day('Monday').isoWeekYear(result.year).isoWeek(result.week).toDate();
684
- result.dateLast = moment().day('Sunday').isoWeekYear(result.year).isoWeek(result.week).toDate();
685
- result.dateString = 'Week #' + result.week + ' ' + result.year + '(' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';
686
- }
687
- else if (report.date_interval === 'Monthly') {
688
- result.date = new Date(result.year, result.month - 1, 1, 0, 0, 0, 0);
689
- result.dateString = moment(result.date).format('MMM YYYY');
690
- }
691
- else if (report.date_interval === 'Quarterly') {
692
- result.date = moment().quarter(result.quarter).year(result.year).toDate();
693
- result.dateString = 'Q' + result.quarter + ' ' + result.year;
694
- }
695
- else if (report.date_interval === 'Yearly') {
696
- result.date = new Date(result.year);
697
- result.dateString = result.year.toString();
698
- }
765
+ tmp[i + ' ' + j + ' ' + k] = result[i][field.id] ? (typeof (result[i][field.id]) === 'string' ? result[i][field.id].replace(/,/g, '') : result[i][field.id]) : '';
699
766
  }
700
- });
701
- datedUniqueDates_1 = datedUniqueDates_1.filter(function (a) { return !a.date; }).concat(datedUniqueDates_1.filter(function (a) { return a.date; }).sort(function (a, b) { return a.date.getTime() - b.date.getTime(); }));
702
- var reportTotalGroups_1 = [];
703
- var reportTotalDates_1 = [];
704
- var datedData_1 = [];
705
- datedUniqueDates_1.forEach(function (date) {
706
- var tmpData = [];
707
- var tmpTotalDated = {};
708
- var tmpTotalCnt = {};
709
- var tmpTotalType = {};
710
- datedUniqueGroups_1.forEach(function (group) {
711
- var result = results_1.filter(function (a) {
712
- var res = true;
713
- Object.keys(date).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString'; }).forEach(function (key) {
714
- if (a._id[key] !== date[key]) {
715
- res = false;
716
- }
717
- });
718
- Object.keys(group).forEach(function (key) {
719
- if (a._id[key] !== group[key]) {
720
- res = false;
721
- }
722
- });
723
- return res;
724
- })[0];
725
- if (result) {
726
- tmpData.push(result);
727
- Object.keys(result._id).filter(function (a) { return a; }).forEach(function (key) {
728
- if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
729
- if (!tmpTotalDated[key]) {
730
- tmpTotalDated[key] = result._id[key];
731
- }
732
- else {
733
- tmpTotalDated[key] += result._id[key];
734
- }
735
- if (!tmpTotalCnt[key]) {
736
- tmpTotalCnt[key] = 1;
737
- }
738
- else {
739
- tmpTotalCnt[key] += 1;
740
- }
741
- tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
742
- }
743
- });
744
- Object.keys(result).filter(function (a) { return a && a !== '_id'; }).forEach(function (key) {
745
- if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
746
- if (!tmpTotalDated[key]) {
747
- tmpTotalDated[key] = result[key];
748
- }
749
- else {
750
- tmpTotalDated[key] += result[key];
751
- }
752
- if (!tmpTotalCnt[key]) {
753
- tmpTotalCnt[key] = 1;
754
- }
755
- else {
756
- tmpTotalCnt[key] += 1;
757
- }
758
- tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
759
- }
760
- });
761
- }
762
- else {
763
- tmpData.push(null);
764
- }
765
- });
766
- Object.keys(tmpTotalType).forEach(function (totalKey) {
767
- if (tmpTotalType[totalKey] === 'avg') {
768
- tmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];
769
- }
770
- tmpTotalDated[totalKey] = Math.round(tmpTotalDated[totalKey] * 100) / 100;
771
- });
772
- reportTotalDates_1.push(tmpTotalDated);
773
- datedData_1.push(tmpData);
774
- });
775
- datedUniqueGroups_1.forEach(function (group) {
776
- var tmpTotalGroup = {};
777
- var filteredData = results_1.filter(function (a) {
778
- var res = (!Object.keys(group).length || group._id === null) ? false : true;
779
- Object.keys(group).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
780
- if (a._id[key] !== group[key]) {
781
- res = false;
782
- }
783
- });
784
- return res;
785
- });
786
- report.fields_total.forEach(function (total) {
787
- total.fields.forEach(function (field) {
788
- if (filteredData.length) {
789
- tmpTotalGroup[field] = filteredData.filter(function (a) { return a && a[field]; }).map(function (a) { return a[field]; }).reduce(function (a, b) { return a + b; }, 0);
790
- if (total.type === 'avg') {
791
- tmpTotalGroup[field] = Math.round(tmpTotalGroup[field] / filteredData.length * 100) / 100;
792
- }
793
- }
794
- else {
795
- tmpTotalGroup[field] = 0;
796
- }
797
- });
798
- });
799
- reportTotalGroups_1.push(tmpTotalGroup);
800
- });
801
- datedUniqueDates_1.forEach(function (date) {
802
- tmpHeaders_2[date.dateString] = date.dateString;
803
- });
804
- tmpHeaders_2['Totals'] = 'Totals';
805
- lines_2.push(tmpHeaders_2);
806
- for (var i = 0; i <= datedUniqueGroups_1.length - 1; i++) {
807
- var group = datedUniqueGroups_1[i];
808
- var _loop_2 = function (j) {
809
- var field = report.fields_selected.filter(function (a) { return a.show; })[j];
810
- var tmp = {};
811
- for (var k = 0; k <= report.groups_row.length - 1; k++) {
812
- var groupRow = report.groups_row[k];
813
- if (j === 0) {
814
- tmp[group[groupRow.id]] = group[groupRow.id];
815
- }
816
- else {
817
- tmp[group[groupRow.id]] = '';
818
- }
819
- }
820
- tmp[field.columnName] = field.columnName;
821
- for (var k = 0; k <= datedData_1.length - 1; k++) {
822
- var result = datedData_1[k];
823
- if (result[i]) {
824
- if (allLeaves_1.filter(function (a) { return a.id === field.id; })[0] && allLeaves_1.filter(function (a) { return a.id === field.id; })[0].fieldType === 'Number') {
825
- tmp[i + ' ' + j + ' ' + k] = result[i][field.id] ? (typeof (result[i][field.id]) === 'string' ? parseInt(result[i][field.id].replace(/,/g, '')) : result[i][field.id]) : '';
826
- }
827
- else {
828
- tmp[i + ' ' + j + ' ' + k] = result[i][field.id] ? (typeof (result[i][field.id]) === 'string' ? result[i][field.id].replace(/,/g, '') : result[i][field.id]) : '';
829
- }
830
- }
831
- else {
832
- tmp[i + ' ' + j + ' ' + k] = '';
833
- }
834
- }
835
- for (var k = 0; k <= report.fields_total.length - 1; k++) {
836
- var total = report.fields_total[k];
837
- if (total.fields.includes(field.id)) {
838
- tmp['total' + i + ' ' + j + ' ' + k] = reportTotalGroups_1[i][field.id] ? (typeof (reportTotalGroups_1[i][field.id]) === 'string' ? parseInt(reportTotalGroups_1[i][field.id].replace(/,/g, '')) : reportTotalGroups_1[i][field.id]) : '';
839
- }
840
- else {
841
- tmp['total' + i + ' ' + j + ' ' + k] = '';
842
- }
843
- }
844
- lines_2.push(tmp);
845
- };
846
- for (var j = 0; j <= report.fields_selected.filter(function (a) { return a.show; }).length - 1; j++) {
847
- _loop_2(j);
767
+ }
768
+ else {
769
+ tmp[i + ' ' + j + ' ' + k] = '';
770
+ }
771
+ }
772
+ for (let k = 0; k <= report.fields_total.length - 1; k++) {
773
+ let total = report.fields_total[k];
774
+ if (total.fields.includes(field.id)) {
775
+ tmp['total' + i + ' ' + j + ' ' + k] = reportTotalGroups[i][field.id] ? (typeof (reportTotalGroups[i][field.id]) === 'string' ? parseInt(reportTotalGroups[i][field.id].replace(/,/g, '')) : reportTotalGroups[i][field.id]) : '';
776
+ }
777
+ else {
778
+ tmp['total' + i + ' ' + j + ' ' + k] = '';
779
+ }
780
+ }
781
+ lines.push(tmp);
782
+ }
783
+ }
784
+ if (reportTotals) {
785
+ for (let j = 0; j <= report.fields_selected.filter(a => a.show).length - 1; j++) {
786
+ let field = report.fields_selected.filter(a => a.show)[j];
787
+ let tmp = {};
788
+ for (let k = 0; k <= report.groups_row.length - 1; k++) {
789
+ let groupRow = report.groups_row[k];
790
+ for (let l = 0; l <= report.fields_total.length - 1; l++) {
791
+ let total = report.fields_total[l];
792
+ if (j === 0) {
793
+ tmp[total.type + k] = total.type + ' TOTALS';
794
+ }
795
+ else {
796
+ tmp[total.type + k] = '';
848
797
  }
849
798
  }
850
- if (reportTotals) {
851
- for (var j = 0; j <= report.fields_selected.filter(function (a) { return a.show; }).length - 1; j++) {
852
- var field = report.fields_selected.filter(function (a) { return a.show; })[j];
853
- var tmp = {};
854
- for (var k = 0; k <= report.groups_row.length - 1; k++) {
855
- var groupRow = report.groups_row[k];
856
- for (var l = 0; l <= report.fields_total.length - 1; l++) {
857
- var total = report.fields_total[l];
858
- if (j === 0) {
859
- tmp[total.type + k] = total.type + ' TOTALS';
860
- }
861
- else {
862
- tmp[total.type + k] = '';
863
- }
864
- }
865
- }
866
- tmp[field.columnName] = field.columnName;
867
- for (var k = 0; k <= datedData_1.length - 1; k++) {
868
- var result = datedData_1[k];
869
- for (var l = 0; l <= report.fields_total.length - 1; l++) {
870
- var total = report.fields_total[l];
871
- if (total.fields.includes(field.id)) {
872
- tmp['total' + j + ' ' + k + ' ' + l] = reportTotalDates_1[k][field.id];
873
- }
874
- else {
875
- tmp['total' + j + ' ' + k + ' ' + l] = '';
876
- }
877
- }
878
- }
879
- for (var k = 0; k <= report.groups_row.length - 1; k++) {
880
- var groupRow = report.groups_row[k];
881
- for (var l = 0; l <= report.fields_total.length - 1; l++) {
882
- var total = report.fields_total[l];
883
- if (total.fields.includes(groupRow.id)) {
884
- tmp['totalreportTotals' + j + ' ' + k + ' ' + l] = reportTotals[total.id + groupRow.id];
885
- }
886
- }
887
- }
888
- for (var l = 0; l <= report.fields_total.length - 1; l++) {
889
- var total = report.fields_total[l];
890
- if (total.fields.includes(field.id)) {
891
- tmp['totalreportTotals' + j + ' ' + l] = reportTotals[total.id + '_' + field.id];
892
- }
893
- }
894
- lines_2.push(tmp);
799
+ }
800
+ tmp[field.columnName] = field.columnName;
801
+ for (let k = 0; k <= datedData.length - 1; k++) {
802
+ let result = datedData[k];
803
+ for (let l = 0; l <= report.fields_total.length - 1; l++) {
804
+ let total = report.fields_total[l];
805
+ if (total.fields.includes(field.id)) {
806
+ tmp['total' + j + ' ' + k + ' ' + l] = reportTotalDates[k][field.id];
807
+ }
808
+ else {
809
+ tmp['total' + j + ' ' + k + ' ' + l] = '';
895
810
  }
896
811
  }
897
- var newCSV_1 = '';
898
- lines_2.forEach(function (row, index) {
899
- Object.keys(row).forEach(function (key, keyIndex) {
900
- if (row[key] && typeof (row[key]) === 'string') {
901
- row[key] = row[key].replace(new RegExp(/,/g), '');
902
- }
903
- newCSV_1 += row[key];
904
- if (keyIndex < Object.keys(row).length - 1) {
905
- newCSV_1 += ',';
906
- }
907
- });
908
- if (index < lines_2.length - 1) {
909
- newCSV_1 += '\r\n';
812
+ }
813
+ for (let k = 0; k <= report.groups_row.length - 1; k++) {
814
+ let groupRow = report.groups_row[k];
815
+ for (let l = 0; l <= report.fields_total.length - 1; l++) {
816
+ let total = report.fields_total[l];
817
+ if (total.fields.includes(groupRow.id)) {
818
+ tmp['totalreportTotals' + j + ' ' + k + ' ' + l] = reportTotals[total.id + groupRow.id];
910
819
  }
911
- });
912
- data['emails'].forEach(function (email) {
913
- _this.sendEmail(email, _this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t<b>" + _this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
914
- {
915
- filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
916
- content: newCSV_1
917
- }
918
- ], _this.serverConfig['MAIL_FROM_REPORTS']);
919
- });
920
- resolve();
820
+ }
921
821
  }
822
+ for (let l = 0; l <= report.fields_total.length - 1; l++) {
823
+ let total = report.fields_total[l];
824
+ if (total.fields.includes(field.id)) {
825
+ tmp['totalreportTotals' + j + ' ' + l] = reportTotals[total.id + '_' + field.id];
826
+ }
827
+ }
828
+ lines.push(tmp);
922
829
  }
923
- else {
924
- console.log(res);
925
- _this.callMethodInternal('insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [
926
- err
927
- ]);
928
- reject(err);
830
+ }
831
+ let newCSV = '';
832
+ lines.forEach((row, index) => {
833
+ Object.keys(row).forEach((key, keyIndex) => {
834
+ if (row[key] && typeof (row[key]) === 'string') {
835
+ row[key] = row[key].replace(new RegExp(/,/g), '');
836
+ }
837
+ newCSV += row[key];
838
+ if (keyIndex < Object.keys(row).length - 1) {
839
+ newCSV += ',';
840
+ }
841
+ });
842
+ if (index < lines.length - 1) {
843
+ newCSV += '\r\n';
929
844
  }
930
845
  });
846
+ data['emails'].forEach(email => {
847
+ this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', `
848
+ <b>` + this.serverConfig['CLIENT_NAME'] + ` Automated Report</b><br>
849
+ <b>Report Name: </b>` + report.report_name + `<br>
850
+ <b>Prepared By: </b>` + data['user'] + `<br><br>
851
+ Attached are the results of this automated report.<br><br>
852
+ Have a great day!<br><br>
853
+ ResolveIO<br><br>`, [
854
+ {
855
+ filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
856
+ content: newCSV
857
+ }
858
+ ], this.serverConfig['MAIL_FROM_REPORTS']);
859
+ });
860
+ resolve();
931
861
  }
932
- });
933
- }
934
- return [2 /*return*/];
935
- }
936
- });
937
- }); });
862
+ }
863
+ else {
864
+ console.log(res);
865
+ this.callMethodInternal('insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [
866
+ err
867
+ ]);
868
+ reject(err);
869
+ }
870
+ });
871
+ }
872
+ });
873
+ }
874
+ });
938
875
  }
939
876
  }
940
877
  });
941
878
  }
942
- exports.loadCronJobMethods = loadCronJobMethods;
943
- function getTreeLeaves(items, resArray, allowLookups) {
944
- if (allowLookups === void 0) { allowLookups = false; }
945
- items.forEach(function (item) {
879
+ function getTreeLeaves(items, resArray, allowLookups = false) {
880
+ items.forEach(item => {
946
881
  if (item.isLeaf) {
947
882
  resArray.push(item);
948
883
  }
@@ -956,13 +891,13 @@ function getTreeLeaves(items, resArray, allowLookups) {
956
891
  function modifyDataTypeField(report, result, field, index) {
957
892
  if (index < report.groups_row.length) {
958
893
  result = result['gr_' + (index + 1)];
959
- result.forEach(function (tDataRes, tIndex) {
894
+ result.forEach((tDataRes, tIndex) => {
960
895
  modifyDataTypeField(report, tDataRes, field, index + 1);
961
896
  });
962
897
  }
963
898
  else {
964
899
  if (Array.isArray(result[field.id])) {
965
- result[field.id].forEach(function (arr, arrIndex) {
900
+ result[field.id].forEach((arr, arrIndex) => {
966
901
  if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
967
902
  result[field.id].splice(arrIndex, 1, arr.toLocaleString());
968
903
  }
@@ -1042,7 +977,7 @@ function modifyDataTypeField(report, result, field, index) {
1042
977
  }
1043
978
  }
1044
979
  function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1045
- var row = ws.getRow(currentRow);
980
+ let row = ws.getRow(currentRow);
1046
981
  if (level < report.groups_row.length) {
1047
982
  row.getCell(2).fill = {
1048
983
  fgColor: { argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff' },
@@ -1056,17 +991,17 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1056
991
  size: 14
1057
992
  };
1058
993
  row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
1059
- ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(function (a) { return a.show; }).length + 1).$col$row);
994
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);
1060
995
  row.getCell(2).border = {
1061
996
  top: { style: 'thick' },
1062
997
  left: { style: 'thick' },
1063
998
  right: { style: 'thick' }
1064
999
  };
1065
1000
  if (report.fields_total.length) {
1066
- report.fields_total.forEach(function (total) {
1001
+ report.fields_total.forEach(total => {
1067
1002
  currentRow += 1;
1068
1003
  row = ws.getRow(currentRow);
1069
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1004
+ report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1070
1005
  if (total.fields.includes(field.id)) {
1071
1006
  row.getCell(fieldIndex + 2).value = field.columnName;
1072
1007
  row.getCell(fieldIndex + 2).font = {
@@ -1086,7 +1021,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1086
1021
  left: { style: 'thick' }
1087
1022
  };
1088
1023
  }
1089
- else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1024
+ else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1090
1025
  row.getCell(fieldIndex + 2).border = {
1091
1026
  right: { style: 'thick' }
1092
1027
  };
@@ -1095,10 +1030,10 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1095
1030
  });
1096
1031
  }
1097
1032
  // Totals
1098
- report.fields_total.forEach(function (total) {
1033
+ report.fields_total.forEach(total => {
1099
1034
  currentRow += 1;
1100
1035
  row = ws.getRow(currentRow);
1101
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1036
+ report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1102
1037
  if (total.fields.includes(field.id)) {
1103
1038
  row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1104
1039
  row.getCell(fieldIndex + 2).font = {
@@ -1120,7 +1055,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1120
1055
  bottom: { style: 'thick' }
1121
1056
  };
1122
1057
  }
1123
- else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1058
+ else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1124
1059
  row.getCell(fieldIndex + 2).border = {
1125
1060
  top: { style: 'thin' },
1126
1061
  bottom: { style: 'thick' },
@@ -1137,7 +1072,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1137
1072
  });
1138
1073
  currentRow += 1;
1139
1074
  result = result['gr_' + (level + 1)];
1140
- result.forEach(function (tDataRes, tIndex) {
1075
+ result.forEach((tDataRes, tIndex) => {
1141
1076
  currentRow = tabGroupExcelRecursive(report, ws, currentRow, level + 1, tDataRes);
1142
1077
  });
1143
1078
  }
@@ -1154,7 +1089,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1154
1089
  size: 12
1155
1090
  };
1156
1091
  row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
1157
- ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(function (a) { return a.show; }).length + 1).$col$row);
1092
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);
1158
1093
  row.getCell(2).border = {
1159
1094
  top: { style: 'thick' },
1160
1095
  left: { style: 'thick' },
@@ -1163,7 +1098,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1163
1098
  currentRow += 1;
1164
1099
  row = ws.getRow(currentRow);
1165
1100
  // Headers
1166
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1101
+ report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1167
1102
  row.getCell(fieldIndex + 2).value = field.columnName;
1168
1103
  row.getCell(fieldIndex + 2).font = {
1169
1104
  name: 'Arial',
@@ -1181,17 +1116,17 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1181
1116
  left: { style: 'thick' }
1182
1117
  };
1183
1118
  }
1184
- else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1119
+ else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1185
1120
  row.getCell(fieldIndex + 2).border = {
1186
1121
  right: { style: 'thick' }
1187
1122
  };
1188
1123
  }
1189
1124
  });
1190
1125
  // Data
1191
- result['f_0'].forEach(function (res, resIndex) {
1126
+ result['f_0'].forEach((res, resIndex) => {
1192
1127
  currentRow += 1;
1193
1128
  row = ws.getRow(currentRow);
1194
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1129
+ report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1195
1130
  if (field.fieldType === 'Number' && typeof (result[field.id][resIndex] === 'string') && result[field.id][resIndex]) {
1196
1131
  row.getCell(fieldIndex + 2).value = parseFloat(result[field.id][resIndex].replace(new RegExp(/\,/g), '').replace(new RegExp(/\$/g), ''));
1197
1132
  }
@@ -1213,7 +1148,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1213
1148
  left: { style: 'thick' }
1214
1149
  };
1215
1150
  }
1216
- else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1151
+ else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1217
1152
  row.getCell(fieldIndex + 2).border = {
1218
1153
  right: { style: 'thick' }
1219
1154
  };
@@ -1221,10 +1156,10 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1221
1156
  });
1222
1157
  });
1223
1158
  // Totals
1224
- report.fields_total.forEach(function (total) {
1159
+ report.fields_total.forEach(total => {
1225
1160
  currentRow += 1;
1226
1161
  row = ws.getRow(currentRow);
1227
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1162
+ report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1228
1163
  if (total.fields.includes(field.id)) {
1229
1164
  row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1230
1165
  row.getCell(fieldIndex + 2).font = {
@@ -1246,7 +1181,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1246
1181
  bottom: { style: 'thick' }
1247
1182
  };
1248
1183
  }
1249
- else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1184
+ else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1250
1185
  row.getCell(fieldIndex + 2).border = {
1251
1186
  top: { style: 'thin' },
1252
1187
  bottom: { style: 'thick' },
@@ -1267,15 +1202,15 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1267
1202
  function tabGroupExcelWidthRecursive(report, level, result, cols) {
1268
1203
  if (level < report.groups_row.length) {
1269
1204
  result = result['gr_' + (level + 1)];
1270
- result.forEach(function (tDataRes, tIndex) {
1205
+ result.forEach((tDataRes, tIndex) => {
1271
1206
  cols = tabGroupExcelWidthRecursive(report, level + 1, tDataRes, cols);
1272
1207
  });
1273
1208
  }
1274
1209
  else {
1275
- report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1210
+ report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1276
1211
  if (Array.isArray(result[field.id])) {
1277
- result[field.id].forEach(function (res) {
1278
- var length = 10;
1212
+ result[field.id].forEach(res => {
1213
+ let length = 10;
1279
1214
  if (res) {
1280
1215
  length = res.length + 3;
1281
1216
  }
@@ -1288,7 +1223,7 @@ function tabGroupExcelWidthRecursive(report, level, result, cols) {
1288
1223
  });
1289
1224
  }
1290
1225
  else {
1291
- var res = result[field.id];
1226
+ let res = result[field.id];
1292
1227
  if (res) {
1293
1228
  length = res.length + 3;
1294
1229
  }