@resolveio/server-lib 9.0.34 → 9.0.36

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 (192) hide show
  1. package/client-server-app.js +48 -7
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +11 -8
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/app-version.collection.js +11 -8
  6. package/collections/app-version.collection.js.map +1 -1
  7. package/collections/counter.collection.js +11 -8
  8. package/collections/counter.collection.js.map +1 -1
  9. package/collections/cron-job-history.collection.js +12 -9
  10. package/collections/cron-job-history.collection.js.map +1 -1
  11. package/collections/cron-job.collection.js +11 -8
  12. package/collections/cron-job.collection.js.map +1 -1
  13. package/collections/email-history.collection.js +11 -8
  14. package/collections/email-history.collection.js.map +1 -1
  15. package/collections/email-verified.collection.js +12 -9
  16. package/collections/email-verified.collection.js.map +1 -1
  17. package/collections/file.collection.js +11 -8
  18. package/collections/file.collection.js.map +1 -1
  19. package/collections/flag.collection.js +11 -8
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +14 -11
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +16 -13
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +19 -16
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +12 -9
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-call.collection.js +13 -10
  30. package/collections/method-call.collection.js.map +1 -1
  31. package/collections/method-response.collection.js +13 -10
  32. package/collections/method-response.collection.js.map +1 -1
  33. package/collections/monitor-cpu.collection.js +16 -13
  34. package/collections/monitor-cpu.collection.js.map +1 -1
  35. package/collections/monitor-https-inbound.collection.js +16 -13
  36. package/collections/monitor-https-inbound.collection.js.map +1 -1
  37. package/collections/monitor-https-outbound.collection.js +18 -15
  38. package/collections/monitor-https-outbound.collection.js.map +1 -1
  39. package/collections/monitor-memory.collection.js +15 -12
  40. package/collections/monitor-memory.collection.js.map +1 -1
  41. package/collections/monitor-mongo.collection.js +15 -12
  42. package/collections/monitor-mongo.collection.js.map +1 -1
  43. package/collections/notification.collection.js +11 -8
  44. package/collections/notification.collection.js.map +1 -1
  45. package/collections/queue-flag.collection.js +12 -9
  46. package/collections/queue-flag.collection.js.map +1 -1
  47. package/collections/queue-method.collection.js +12 -9
  48. package/collections/queue-method.collection.js.map +1 -1
  49. package/collections/queue-response.collection.js +12 -9
  50. package/collections/queue-response.collection.js.map +1 -1
  51. package/collections/report-builder-dashboard-builder.collection.js +13 -10
  52. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  53. package/collections/report-builder-library.collection.js +14 -11
  54. package/collections/report-builder-library.collection.js.map +1 -1
  55. package/collections/report-builder-report.collection.js +14 -11
  56. package/collections/report-builder-report.collection.js.map +1 -1
  57. package/collections/user-group.collection.js +14 -11
  58. package/collections/user-group.collection.js.map +1 -1
  59. package/collections/user-guide.collection.js +11 -8
  60. package/collections/user-guide.collection.js.map +1 -1
  61. package/collections/user.collection.js +15 -12
  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 +80 -30
  66. package/fixtures/cron-jobs.js.map +1 -1
  67. package/fixtures/init.js +59 -9
  68. package/fixtures/init.js.map +1 -1
  69. package/http/auth.js +460 -344
  70. package/http/auth.js.map +1 -1
  71. package/http/health.js +5 -1
  72. package/http/health.js.map +1 -1
  73. package/http/home.js +11 -7
  74. package/http/home.js.map +1 -1
  75. package/index.js +98 -36
  76. package/index.js.map +1 -1
  77. package/managers/cron.manager.js +157 -78
  78. package/managers/cron.manager.js.map +1 -1
  79. package/managers/method.manager.js +302 -314
  80. package/managers/method.manager.js.map +1 -1
  81. package/managers/mongo.manager.js +1010 -741
  82. package/managers/mongo.manager.js.map +1 -1
  83. package/managers/monitor.manager.js +254 -171
  84. package/managers/monitor.manager.js.map +1 -1
  85. package/managers/queue-method.manager.js +166 -69
  86. package/managers/queue-method.manager.js.map +1 -1
  87. package/managers/subscription.manager.js +714 -515
  88. package/managers/subscription.manager.js.map +1 -1
  89. package/methods/accounts.js +183 -111
  90. package/methods/accounts.js.map +1 -1
  91. package/methods/aws.js +262 -156
  92. package/methods/aws.js.map +1 -1
  93. package/methods/cloudconvert.js +180 -100
  94. package/methods/cloudconvert.js.map +1 -1
  95. package/methods/collections.js +110 -103
  96. package/methods/collections.js.map +1 -1
  97. package/methods/counters.js +79 -29
  98. package/methods/counters.js.map +1 -1
  99. package/methods/cron-jobs.js +884 -819
  100. package/methods/cron-jobs.js.map +1 -1
  101. package/methods/flags.js +5 -1
  102. package/methods/flags.js.map +1 -1
  103. package/methods/logs.js +313 -258
  104. package/methods/logs.js.map +1 -1
  105. package/methods/monitor.js +348 -289
  106. package/methods/monitor.js.map +1 -1
  107. package/methods/pdf.js +340 -341
  108. package/methods/pdf.js.map +1 -1
  109. package/methods/report-builder.js +657 -565
  110. package/methods/report-builder.js.map +1 -1
  111. package/methods/support.js +185 -67
  112. package/methods/support.js.map +1 -1
  113. package/models/app-status.model.js +2 -1
  114. package/models/app-version.model.js +2 -1
  115. package/models/billing-logged-in-users.model.js +2 -1
  116. package/models/collection-document.model.js +2 -1
  117. package/models/counter.model.js +2 -1
  118. package/models/cron-job-history.model.js +2 -1
  119. package/models/cron-job.model.js +2 -1
  120. package/models/dialog.model.js +2 -1
  121. package/models/email-history.model.js +2 -1
  122. package/models/email-verified.model.js +2 -1
  123. package/models/file.model.js +2 -1
  124. package/models/flag.model.js +2 -1
  125. package/models/log-method-latency.model.js +2 -1
  126. package/models/log-subscription.model.js +2 -1
  127. package/models/log.model.js +2 -1
  128. package/models/logged-in-users.model.js +2 -1
  129. package/models/method-call.model.js +2 -1
  130. package/models/method-response.model.js +2 -1
  131. package/models/method.model.js +2 -1
  132. package/models/monitor-cpu.model.js +2 -1
  133. package/models/monitor-https-inbound.model.js +2 -1
  134. package/models/monitor-https-outbound.model.js +2 -1
  135. package/models/monitor-memory.model.js +2 -1
  136. package/models/monitor-mongo.model.js +2 -1
  137. package/models/notification.model.js +2 -1
  138. package/models/pagination.model.js +5 -2
  139. package/models/pagination.model.js.map +1 -1
  140. package/models/permission.model.js +2 -1
  141. package/models/queue-method.model.js +2 -1
  142. package/models/queue-response.model.js +2 -1
  143. package/models/report-builder-dashboard-builder.model.js +2 -1
  144. package/models/report-builder-library.model.js +2 -1
  145. package/models/report-builder-report.model.js +2 -1
  146. package/models/report-builder.model.js +2 -1
  147. package/models/select-data-label.model.js +2 -1
  148. package/models/server-response.model.js +2 -1
  149. package/models/subscription.model.js +2 -1
  150. package/models/support-ticket.model.js +2 -1
  151. package/models/user-group.model.js +2 -1
  152. package/models/user-guide.model.js +2 -1
  153. package/models/user.model.js +2 -1
  154. package/package.json +1 -1
  155. package/public_api.js +82 -70
  156. package/public_api.js.map +1 -1
  157. package/publications/app-status.js +8 -4
  158. package/publications/app-status.js.map +1 -1
  159. package/publications/app-version.js +8 -4
  160. package/publications/app-version.js.map +1 -1
  161. package/publications/cron-jobs.js +13 -9
  162. package/publications/cron-jobs.js.map +1 -1
  163. package/publications/files.js +15 -11
  164. package/publications/files.js.map +1 -1
  165. package/publications/flags.js +11 -7
  166. package/publications/flags.js.map +1 -1
  167. package/publications/logs.js +35 -31
  168. package/publications/logs.js.map +1 -1
  169. package/publications/method-calls.js +8 -4
  170. package/publications/method-calls.js.map +1 -1
  171. package/publications/method-responses.js +8 -4
  172. package/publications/method-responses.js.map +1 -1
  173. package/publications/notifications.js +8 -4
  174. package/publications/notifications.js.map +1 -1
  175. package/publications/report-builder-dashboard-builders.js +12 -8
  176. package/publications/report-builder-dashboard-builders.js.map +1 -1
  177. package/publications/report-builder-libraries.js +66 -16
  178. package/publications/report-builder-libraries.js.map +1 -1
  179. package/publications/report-builder-reports.js +21 -17
  180. package/publications/report-builder-reports.js.map +1 -1
  181. package/publications/super-admin.js +7 -3
  182. package/publications/super-admin.js.map +1 -1
  183. package/publications/user-groups.js +8 -4
  184. package/publications/user-groups.js.map +1 -1
  185. package/publications/user-guides.js +8 -4
  186. package/publications/user-guides.js.map +1 -1
  187. package/server-app.js +534 -393
  188. package/server-app.js.map +1 -1
  189. package/util/common.js +92 -55
  190. package/util/common.js.map +1 -1
  191. package/util/schema-report-builder.js +134 -76
  192. package/util/schema-report-builder.js.map +1 -1
@@ -1,883 +1,948 @@
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) {
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) {
10
49
  methodManager.methods({
11
50
  methodQueue: {
12
51
  function: function () {
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
- });
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
+ }); });
20
68
  }
21
69
  },
22
70
  cronEmailMergedDocsCleanUp: {
23
71
  skipQueue: true,
24
72
  function: function () {
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
- });
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
+ }); });
33
90
  }
34
91
  },
35
92
  reportbuilderCronJob: {
36
93
  skipQueue: true,
37
- check: new SimpleSchema({
94
+ check: new simpl_schema_1.default({
38
95
  data: {
39
96
  type: Object,
40
97
  blackbox: true
41
98
  }
42
99
  }),
43
100
  function: function (data) {
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 } }] });
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);
167
118
  }
168
119
  else {
169
- ors.push({ $and: [{ [filter.field]: { '$gte': filter.value } }, { [filter.field]: { '$lte': filter.highValue } }] });
120
+ field.fieldPathObj = (_b = {}, _b[fieldData[i]] = field.fieldPathObj, _b);
170
121
  }
171
122
  }
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': '' } });
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);
178
130
  }
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
- }
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);
134
+ }
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);
197
143
  }
198
144
  else {
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
- }
145
+ sortObj_1[sortField.field] = (sortField.order === 'asc' ? 1 : -1);
209
146
  }
210
- }
211
- else {
212
- ors.push({ [filter.field]: { ['$' + filter.condition]: filter.value } });
213
- }
147
+ });
214
148
  }
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();
242
- }
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();
246
- }
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();
250
- }
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();
149
+ else {
150
+ sortObj_1 = null;
151
+ }
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)] });
298
233
  }
299
- else if (filter.rolling_interval === 'All') {
300
- startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
301
- endDate = moment().endOf('day').toDate();
234
+ else {
235
+ ors.push({ $and: [(_c = {}, _c[filter.field] = { '$gte': filter.value }, _c), (_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d)] });
302
236
  }
303
- ors.push({ $and: [{ [filter.field]: { '$gte': startDate } }, { [filter.field]: { '$lte': endDate } }] });
304
237
  }
305
- else {
306
- filterArrays.push({ $and: [{ [filter.field]: { '$gte': filter.value } }, { [filter.field]: { '$lte': filter.highValue } }] });
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));
244
+ }
245
+ ors.push({ $and: and });
307
246
  }
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': '' } });
247
+ else if (filter.condition === 'null') {
248
+ ors.push((_h = {}, _h[filter.field] = { '$eq': null }, _h));
315
249
  }
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 });
250
+ 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
+ }
330
264
  }
331
265
  else {
332
- ors.push(and[0]);
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
+ }
333
277
  }
334
278
  }
335
279
  else {
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
- }
280
+ ors.push((_j = {}, _j[filter.field] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
346
281
  }
347
282
  }
348
- else {
349
- ors.push({ [filter.field.replace(/\.\$/g, '')]: { ['$' + filter.condition]: filter.value } });
350
- }
351
283
  }
284
+ });
285
+ if (ors.length) {
286
+ filters_1.push({ $or: ors });
352
287
  }
353
288
  });
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]) : '';
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
+ }
443
377
  }
444
- else {
445
- tmp[group.columnName] = result._id[group.id] || '';
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 });
446
386
  }
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]) : '';
387
+ else if (filter.condition === 'null') {
388
+ ors.push((_h = {}, _h[filter.field.replace(/\.\$/g, '')] = { '$eq': null }, _h));
456
389
  }
457
390
  else {
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
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
+ }
541
422
  }
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;
562
423
  }
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;
570
424
  });
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);
595
- }
596
- });
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
- }
425
+ if (ors.length) {
426
+ filterArrays_1.push({ $or: ors });
636
427
  }
637
428
  });
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;
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
+ });
653
439
  }
654
- });
655
- Object.keys(group).forEach(key => {
656
- if (a._id[key] !== group[key]) {
657
- res = false;
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
+ });
658
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
+ });
494
+ }
495
+ });
496
+ var lines_1 = [];
497
+ var tmpHeaders_1 = {};
498
+ report.groups_row.forEach(function (group) {
499
+ tmpHeaders_1[group.id] = group.columnName;
659
500
  });
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];
501
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (header) {
502
+ tmpHeaders_1[header.columnName] = header.columnName;
503
+ });
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(',');
668
510
  }
669
511
  else {
670
- tmpTotalDated[key] += result._id[key];
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
+ }
671
518
  }
672
- if (!tmpTotalCnt[key]) {
673
- tmpTotalCnt[key] = 1;
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(',');
674
523
  }
675
524
  else {
676
- tmpTotalCnt[key] += 1;
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
+ }
677
531
  }
678
- tmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;
679
- }
532
+ });
533
+ lines_1.push(tmp);
680
534
  });
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];
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'
685
544
  }
686
- else {
687
- tmpTotalDated[key] += result[key];
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;
611
+ });
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;
688
619
  }
689
- if (!tmpTotalCnt[key]) {
690
- tmpTotalCnt[key] = 1;
620
+ else if (dataPt._id.month < 7) {
621
+ dataPt._id.quarter = 2;
622
+ }
623
+ else if (dataPt._id.month < 10) {
624
+ dataPt._id.quarter = 3;
691
625
  }
692
626
  else {
693
- tmpTotalCnt[key] += 1;
627
+ dataPt._id.quarter = 4;
694
628
  }
695
- tmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;
696
- }
697
- });
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;
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);
639
+ }
640
+ };
641
+ for (var i = results_1.length - 1; i >= 1; i--) {
642
+ _loop_1(i);
729
643
  }
730
644
  }
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]) : '';
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);
763
658
  }
764
- else {
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]) : '';
659
+ });
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);
766
671
  }
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';
672
+ });
673
+ datedUniqueDates_1.forEach(function (result) {
674
+ if (!result.year) {
675
+ result.dateString = 'No Date';
794
676
  }
795
677
  else {
796
- tmp[total.type + k] = '';
797
- }
798
- }
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];
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
+ }
807
699
  }
808
- else {
809
- tmp['total' + j + ' ' + k + ' ' + l] = '';
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);
810
848
  }
811
849
  }
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];
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);
819
895
  }
820
896
  }
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';
910
+ }
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();
821
921
  }
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);
829
922
  }
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';
923
+ else {
924
+ console.log(res);
925
+ _this.callMethodInternal('insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [
926
+ err
927
+ ]);
928
+ reject(err);
844
929
  }
845
930
  });
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();
861
931
  }
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
- });
932
+ });
933
+ }
934
+ return [2 /*return*/];
935
+ }
936
+ });
937
+ }); });
875
938
  }
876
939
  }
877
940
  });
878
941
  }
879
- function getTreeLeaves(items, resArray, allowLookups = false) {
880
- items.forEach(item => {
942
+ exports.loadCronJobMethods = loadCronJobMethods;
943
+ function getTreeLeaves(items, resArray, allowLookups) {
944
+ if (allowLookups === void 0) { allowLookups = false; }
945
+ items.forEach(function (item) {
881
946
  if (item.isLeaf) {
882
947
  resArray.push(item);
883
948
  }
@@ -891,13 +956,13 @@ function getTreeLeaves(items, resArray, allowLookups = false) {
891
956
  function modifyDataTypeField(report, result, field, index) {
892
957
  if (index < report.groups_row.length) {
893
958
  result = result['gr_' + (index + 1)];
894
- result.forEach((tDataRes, tIndex) => {
959
+ result.forEach(function (tDataRes, tIndex) {
895
960
  modifyDataTypeField(report, tDataRes, field, index + 1);
896
961
  });
897
962
  }
898
963
  else {
899
964
  if (Array.isArray(result[field.id])) {
900
- result[field.id].forEach((arr, arrIndex) => {
965
+ result[field.id].forEach(function (arr, arrIndex) {
901
966
  if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
902
967
  result[field.id].splice(arrIndex, 1, arr.toLocaleString());
903
968
  }
@@ -977,7 +1042,7 @@ function modifyDataTypeField(report, result, field, index) {
977
1042
  }
978
1043
  }
979
1044
  function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
980
- let row = ws.getRow(currentRow);
1045
+ var row = ws.getRow(currentRow);
981
1046
  if (level < report.groups_row.length) {
982
1047
  row.getCell(2).fill = {
983
1048
  fgColor: { argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff' },
@@ -991,17 +1056,17 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
991
1056
  size: 14
992
1057
  };
993
1058
  row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
994
- ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);
1059
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(function (a) { return a.show; }).length + 1).$col$row);
995
1060
  row.getCell(2).border = {
996
1061
  top: { style: 'thick' },
997
1062
  left: { style: 'thick' },
998
1063
  right: { style: 'thick' }
999
1064
  };
1000
1065
  if (report.fields_total.length) {
1001
- report.fields_total.forEach(total => {
1066
+ report.fields_total.forEach(function (total) {
1002
1067
  currentRow += 1;
1003
1068
  row = ws.getRow(currentRow);
1004
- report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1069
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1005
1070
  if (total.fields.includes(field.id)) {
1006
1071
  row.getCell(fieldIndex + 2).value = field.columnName;
1007
1072
  row.getCell(fieldIndex + 2).font = {
@@ -1021,7 +1086,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1021
1086
  left: { style: 'thick' }
1022
1087
  };
1023
1088
  }
1024
- else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1089
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1025
1090
  row.getCell(fieldIndex + 2).border = {
1026
1091
  right: { style: 'thick' }
1027
1092
  };
@@ -1030,10 +1095,10 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1030
1095
  });
1031
1096
  }
1032
1097
  // Totals
1033
- report.fields_total.forEach(total => {
1098
+ report.fields_total.forEach(function (total) {
1034
1099
  currentRow += 1;
1035
1100
  row = ws.getRow(currentRow);
1036
- report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1101
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1037
1102
  if (total.fields.includes(field.id)) {
1038
1103
  row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1039
1104
  row.getCell(fieldIndex + 2).font = {
@@ -1055,7 +1120,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1055
1120
  bottom: { style: 'thick' }
1056
1121
  };
1057
1122
  }
1058
- else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1123
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1059
1124
  row.getCell(fieldIndex + 2).border = {
1060
1125
  top: { style: 'thin' },
1061
1126
  bottom: { style: 'thick' },
@@ -1072,7 +1137,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1072
1137
  });
1073
1138
  currentRow += 1;
1074
1139
  result = result['gr_' + (level + 1)];
1075
- result.forEach((tDataRes, tIndex) => {
1140
+ result.forEach(function (tDataRes, tIndex) {
1076
1141
  currentRow = tabGroupExcelRecursive(report, ws, currentRow, level + 1, tDataRes);
1077
1142
  });
1078
1143
  }
@@ -1089,7 +1154,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1089
1154
  size: 12
1090
1155
  };
1091
1156
  row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
1092
- ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);
1157
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(function (a) { return a.show; }).length + 1).$col$row);
1093
1158
  row.getCell(2).border = {
1094
1159
  top: { style: 'thick' },
1095
1160
  left: { style: 'thick' },
@@ -1098,7 +1163,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1098
1163
  currentRow += 1;
1099
1164
  row = ws.getRow(currentRow);
1100
1165
  // Headers
1101
- report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1166
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1102
1167
  row.getCell(fieldIndex + 2).value = field.columnName;
1103
1168
  row.getCell(fieldIndex + 2).font = {
1104
1169
  name: 'Arial',
@@ -1116,17 +1181,17 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1116
1181
  left: { style: 'thick' }
1117
1182
  };
1118
1183
  }
1119
- else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1184
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1120
1185
  row.getCell(fieldIndex + 2).border = {
1121
1186
  right: { style: 'thick' }
1122
1187
  };
1123
1188
  }
1124
1189
  });
1125
1190
  // Data
1126
- result['f_0'].forEach((res, resIndex) => {
1191
+ result['f_0'].forEach(function (res, resIndex) {
1127
1192
  currentRow += 1;
1128
1193
  row = ws.getRow(currentRow);
1129
- report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1194
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1130
1195
  if (field.fieldType === 'Number' && typeof (result[field.id][resIndex] === 'string') && result[field.id][resIndex]) {
1131
1196
  row.getCell(fieldIndex + 2).value = parseFloat(result[field.id][resIndex].replace(new RegExp(/\,/g), '').replace(new RegExp(/\$/g), ''));
1132
1197
  }
@@ -1148,7 +1213,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1148
1213
  left: { style: 'thick' }
1149
1214
  };
1150
1215
  }
1151
- else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1216
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1152
1217
  row.getCell(fieldIndex + 2).border = {
1153
1218
  right: { style: 'thick' }
1154
1219
  };
@@ -1156,10 +1221,10 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1156
1221
  });
1157
1222
  });
1158
1223
  // Totals
1159
- report.fields_total.forEach(total => {
1224
+ report.fields_total.forEach(function (total) {
1160
1225
  currentRow += 1;
1161
1226
  row = ws.getRow(currentRow);
1162
- report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1227
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1163
1228
  if (total.fields.includes(field.id)) {
1164
1229
  row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1165
1230
  row.getCell(fieldIndex + 2).font = {
@@ -1181,7 +1246,7 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1181
1246
  bottom: { style: 'thick' }
1182
1247
  };
1183
1248
  }
1184
- else if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {
1249
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1185
1250
  row.getCell(fieldIndex + 2).border = {
1186
1251
  top: { style: 'thin' },
1187
1252
  bottom: { style: 'thick' },
@@ -1202,15 +1267,15 @@ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1202
1267
  function tabGroupExcelWidthRecursive(report, level, result, cols) {
1203
1268
  if (level < report.groups_row.length) {
1204
1269
  result = result['gr_' + (level + 1)];
1205
- result.forEach((tDataRes, tIndex) => {
1270
+ result.forEach(function (tDataRes, tIndex) {
1206
1271
  cols = tabGroupExcelWidthRecursive(report, level + 1, tDataRes, cols);
1207
1272
  });
1208
1273
  }
1209
1274
  else {
1210
- report.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {
1275
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1211
1276
  if (Array.isArray(result[field.id])) {
1212
- result[field.id].forEach(res => {
1213
- let length = 10;
1277
+ result[field.id].forEach(function (res) {
1278
+ var length = 10;
1214
1279
  if (res) {
1215
1280
  length = res.length + 3;
1216
1281
  }
@@ -1223,7 +1288,7 @@ function tabGroupExcelWidthRecursive(report, level, result, cols) {
1223
1288
  });
1224
1289
  }
1225
1290
  else {
1226
- let res = result[field.id];
1291
+ var res = result[field.id];
1227
1292
  if (res) {
1228
1293
  length = res.length + 3;
1229
1294
  }