@resolveio/server-lib 20.12.47 → 20.12.48
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.
- package/managers/subscription.manager.js +21 -9
- package/managers/subscription.manager.js.map +1 -1
- package/methods/cron-jobs.js +498 -394
- package/methods/cron-jobs.js.map +1 -1
- package/methods/pdf.js +399 -217
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +657 -156
- package/methods/report-builder.js.map +1 -1
- package/methods.ts +3 -0
- package/package.json +1 -1
package/methods/cron-jobs.js
CHANGED
|
@@ -57,6 +57,31 @@ var __values = (this && this.__values) || function(o) {
|
|
|
57
57
|
};
|
|
58
58
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
59
|
};
|
|
60
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
61
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
62
|
+
if (!m) return o;
|
|
63
|
+
var i = m.call(o), r, ar = [], e;
|
|
64
|
+
try {
|
|
65
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
66
|
+
}
|
|
67
|
+
catch (error) { e = { error: error }; }
|
|
68
|
+
finally {
|
|
69
|
+
try {
|
|
70
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
71
|
+
}
|
|
72
|
+
finally { if (e) throw e.error; }
|
|
73
|
+
}
|
|
74
|
+
return ar;
|
|
75
|
+
};
|
|
76
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
77
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
78
|
+
if (ar || !(i in from)) {
|
|
79
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
80
|
+
ar[i] = from[i];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
|
+
};
|
|
60
85
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
86
|
exports.loadCronJobMethods = loadCronJobMethods;
|
|
62
87
|
var Excel = require("exceljs");
|
|
@@ -67,6 +92,309 @@ var cron_job_collection_1 = require("../collections/cron-job.collection");
|
|
|
67
92
|
var file_collection_1 = require("../collections/file.collection");
|
|
68
93
|
var report_builder_report_collection_1 = require("../collections/report-builder-report.collection");
|
|
69
94
|
var common_1 = require("../util/common");
|
|
95
|
+
function getFilterTargets(fieldPath, report) {
|
|
96
|
+
if (!fieldPath) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
if (fieldPath.startsWith('layout_col_')) {
|
|
100
|
+
var normalized = fieldPath.replace(/^layout_col_/, '');
|
|
101
|
+
var parts = normalized.split('_');
|
|
102
|
+
var idx_1 = parseInt(parts[parts.length - 1], 10);
|
|
103
|
+
if (!isNaN(idx_1)) {
|
|
104
|
+
var layoutTargets = ((report === null || report === void 0 ? void 0 : report.fields_selected) || [])
|
|
105
|
+
.filter(function (f) { return f && (f.layoutColumnIndex === idx_1 || (f.id || '').includes("f_layout_".concat(idx_1, "_"))); })
|
|
106
|
+
.map(function (f) { return f.fieldPath; });
|
|
107
|
+
if (layoutTargets.length) {
|
|
108
|
+
return layoutTargets;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [fieldPath];
|
|
113
|
+
}
|
|
114
|
+
function buildFilterExpression(filter, path) {
|
|
115
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
116
|
+
if (!filter || !filter.condition || (!filter.field && !path)) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
var hasValue = filter.value !== null && (Array.isArray(filter.value) ? filter.value.length > 0 : true);
|
|
120
|
+
if (!hasValue && filter.condition !== 'null' && filter.condition !== 'nnull') {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
if (filter.condition === 'bw') {
|
|
124
|
+
if (filter.fieldType === 'Date' && filter.is_rolling) {
|
|
125
|
+
var startDate = null;
|
|
126
|
+
var endDate = null;
|
|
127
|
+
if (filter.rolling_interval === 'Q1') {
|
|
128
|
+
startDate = moment().startOf('year').toDate();
|
|
129
|
+
endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
|
|
130
|
+
}
|
|
131
|
+
else if (filter.rolling_interval === 'Q2') {
|
|
132
|
+
startDate = moment().startOf('year').quarter(2).toDate();
|
|
133
|
+
endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
|
|
134
|
+
}
|
|
135
|
+
else if (filter.rolling_interval === 'Q3') {
|
|
136
|
+
startDate = moment().startOf('year').quarter(3).toDate();
|
|
137
|
+
endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
|
|
138
|
+
}
|
|
139
|
+
else if (filter.rolling_interval === 'Q4') {
|
|
140
|
+
startDate = moment().startOf('year').quarter(4).toDate();
|
|
141
|
+
endDate = moment().endOf('year').toDate();
|
|
142
|
+
}
|
|
143
|
+
else if (filter.rolling_interval === 'Today') {
|
|
144
|
+
startDate = moment().startOf('day').toDate();
|
|
145
|
+
endDate = moment().endOf('day').toDate();
|
|
146
|
+
}
|
|
147
|
+
else if (filter.rolling_interval === 'Yesterday') {
|
|
148
|
+
startDate = moment().subtract(1, 'days').startOf('day').toDate();
|
|
149
|
+
endDate = moment().subtract(1, 'days').endOf('day').toDate();
|
|
150
|
+
}
|
|
151
|
+
else if (filter.rolling_interval === 'Week') {
|
|
152
|
+
startDate = moment().startOf('isoWeek').toDate();
|
|
153
|
+
endDate = moment().endOf('day').toDate();
|
|
154
|
+
}
|
|
155
|
+
else if (filter.rolling_interval === 'Last Week') {
|
|
156
|
+
endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
|
|
157
|
+
startDate = moment(endDate).startOf('isoWeek').toDate();
|
|
158
|
+
}
|
|
159
|
+
else if (filter.rolling_interval === 'Month') {
|
|
160
|
+
startDate = moment().startOf('month').toDate();
|
|
161
|
+
endDate = moment().endOf('day').toDate();
|
|
162
|
+
}
|
|
163
|
+
else if (filter.rolling_interval === 'Last Month') {
|
|
164
|
+
endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
|
|
165
|
+
startDate = moment(endDate).startOf('month').toDate();
|
|
166
|
+
}
|
|
167
|
+
else if (filter.rolling_interval === 'Last 30 Days') {
|
|
168
|
+
endDate = moment().endOf('day').toDate();
|
|
169
|
+
startDate = moment().subtract(30, 'days').startOf('day').toDate();
|
|
170
|
+
}
|
|
171
|
+
else if (filter.rolling_interval === 'Quarter') {
|
|
172
|
+
startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
|
|
173
|
+
endDate = moment().endOf('day').toDate();
|
|
174
|
+
}
|
|
175
|
+
else if (filter.rolling_interval === 'Last Quarter') {
|
|
176
|
+
endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
|
|
177
|
+
startDate = moment(endDate).startOf('quarter').toDate();
|
|
178
|
+
}
|
|
179
|
+
else if (filter.rolling_interval === 'Year') {
|
|
180
|
+
startDate = moment().startOf('year').toDate();
|
|
181
|
+
endDate = moment().endOf('day').toDate();
|
|
182
|
+
}
|
|
183
|
+
else if (filter.rolling_interval === 'Last Year') {
|
|
184
|
+
endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
|
|
185
|
+
startDate = moment(endDate).startOf('year').toDate();
|
|
186
|
+
}
|
|
187
|
+
else if (filter.rolling_interval === 'All') {
|
|
188
|
+
startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
|
|
189
|
+
endDate = moment().endOf('day').toDate();
|
|
190
|
+
}
|
|
191
|
+
return { $and: [(_a = {}, _a[path] = { '$gte': startDate }, _a), (_b = {}, _b[path] = { '$lte': endDate }, _b)] };
|
|
192
|
+
}
|
|
193
|
+
return { $and: [(_c = {}, _c[path] = { '$gte': filter.value }, _c), (_d = {}, _d[path] = { '$lte': filter.highValue }, _d)] };
|
|
194
|
+
}
|
|
195
|
+
else if (filter.condition === 'nnull') {
|
|
196
|
+
var and = [];
|
|
197
|
+
and.push((_e = {}, _e[path] = { '$exists': true }, _e));
|
|
198
|
+
and.push((_f = {}, _f[path] = { '$ne': null }, _f));
|
|
199
|
+
if (filter.fieldType === 'String') {
|
|
200
|
+
and.push((_g = {}, _g[path] = { '$ne': '' }, _g));
|
|
201
|
+
}
|
|
202
|
+
return { $and: and };
|
|
203
|
+
}
|
|
204
|
+
else if (filter.condition === 'null') {
|
|
205
|
+
return _h = {}, _h[path] = { '$eq': null }, _h;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
if (Array.isArray(filter.value)) {
|
|
209
|
+
if (filter.condition === 'ne') {
|
|
210
|
+
var and_1 = [];
|
|
211
|
+
filter.value.forEach(function (filt) {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
and_1.push((_a = {}, _a[path] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
214
|
+
});
|
|
215
|
+
if (and_1.length > 1) {
|
|
216
|
+
return { $and: and_1 };
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
return and_1[0];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
var or_1 = [];
|
|
224
|
+
filter.value.forEach(function (filt) {
|
|
225
|
+
var _a, _b;
|
|
226
|
+
or_1.push((_a = {}, _a[path] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
227
|
+
});
|
|
228
|
+
if (or_1.length > 1) {
|
|
229
|
+
return { $or: or_1 };
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return or_1[0];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
return _j = {}, _j[path] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
function parseLayoutColIndex(fieldRef) {
|
|
243
|
+
if (!fieldRef || !fieldRef.startsWith('layout_col_')) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
var normalized = fieldRef.replace(/^layout_col_/, '');
|
|
247
|
+
var parts = normalized.split('_');
|
|
248
|
+
var idx = parseInt(parts[parts.length - 1], 10);
|
|
249
|
+
return isNaN(idx) ? null : idx;
|
|
250
|
+
}
|
|
251
|
+
function resolveLayoutColumnPrimaryLeafId(fieldRef, report) {
|
|
252
|
+
var idx = parseLayoutColIndex(fieldRef);
|
|
253
|
+
if (idx === null) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
var candidates = ((report === null || report === void 0 ? void 0 : report.fields_selected) || []).filter(function (f) { return f && typeof f.layoutColumnIndex !== 'undefined' && f.layoutColumnIndex === idx; });
|
|
257
|
+
if (!candidates.length) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
var root = report === null || report === void 0 ? void 0 : report.collection_root;
|
|
261
|
+
var preferred = candidates.find(function (c) { return c.collection_name === root || c.layoutCollection === root; }) || candidates[0];
|
|
262
|
+
return (preferred === null || preferred === void 0 ? void 0 : preferred.id) || null;
|
|
263
|
+
}
|
|
264
|
+
function resolveFieldRefToLeafId(fieldRef, report) {
|
|
265
|
+
if (!fieldRef) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
if (fieldRef.startsWith('layout_col_')) {
|
|
269
|
+
return resolveLayoutColumnPrimaryLeafId(fieldRef, report);
|
|
270
|
+
}
|
|
271
|
+
return fieldRef;
|
|
272
|
+
}
|
|
273
|
+
function applyClientGroupSortToData(results, report, sorts) {
|
|
274
|
+
if (sorts === void 0) { sorts = []; }
|
|
275
|
+
if (!Array.isArray(results) || !results.length) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
var groupIds = ((report === null || report === void 0 ? void 0 : report.groups_row) || []).map(function (g) { return g.id; }).filter(Boolean);
|
|
279
|
+
if (!groupIds.length) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
var groupOrderById = {};
|
|
283
|
+
var leafSorts = [];
|
|
284
|
+
(sorts || []).forEach(function (s) {
|
|
285
|
+
if (!(s === null || s === void 0 ? void 0 : s.field)) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (groupIds.includes(s.field)) {
|
|
289
|
+
groupOrderById[s.field] = s.order || 'asc';
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
var leafId = resolveFieldRefToLeafId(s.field, report);
|
|
293
|
+
if (leafId) {
|
|
294
|
+
leafSorts.push({ leafId: leafId, order: s.order || 'asc' });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
var compareScalar = function (aVal, bVal, order) {
|
|
299
|
+
var dir = order === 'desc' ? -1 : 1;
|
|
300
|
+
var aNull = aVal === null || aVal === undefined || aVal === '';
|
|
301
|
+
var bNull = bVal === null || bVal === undefined || bVal === '';
|
|
302
|
+
if (aNull && bNull) {
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
305
|
+
if (aNull) {
|
|
306
|
+
return 1;
|
|
307
|
+
}
|
|
308
|
+
if (bNull) {
|
|
309
|
+
return -1;
|
|
310
|
+
}
|
|
311
|
+
var aNum = typeof aVal === 'number' ? aVal : Number(aVal);
|
|
312
|
+
var bNum = typeof bVal === 'number' ? bVal : Number(bVal);
|
|
313
|
+
if (!isNaN(aNum) && !isNaN(bNum)) {
|
|
314
|
+
if (aNum === bNum) {
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
return aNum > bNum ? dir : -dir;
|
|
318
|
+
}
|
|
319
|
+
var aStr = ('' + aVal).toLowerCase();
|
|
320
|
+
var bStr = ('' + bVal).toLowerCase();
|
|
321
|
+
if (aStr === bStr) {
|
|
322
|
+
return 0;
|
|
323
|
+
}
|
|
324
|
+
return aStr > bStr ? dir : -dir;
|
|
325
|
+
};
|
|
326
|
+
var selectedIds = ((report === null || report === void 0 ? void 0 : report.fields_selected) || []).map(function (f) { return f.id; }).filter(Boolean);
|
|
327
|
+
var sortLeafArraysInRow = function (row) {
|
|
328
|
+
if (!row || !leafSorts.length) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
var arraysToReorder = selectedIds.filter(function (id) { return Array.isArray(row[id]); });
|
|
332
|
+
if (!arraysToReorder.length) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
var length = 0;
|
|
336
|
+
arraysToReorder.forEach(function (id) {
|
|
337
|
+
length = Math.max(length, row[id].length || 0);
|
|
338
|
+
});
|
|
339
|
+
if (length <= 1) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
var getArrayVal = function (id, idx) {
|
|
343
|
+
var arr = row[id];
|
|
344
|
+
if (!Array.isArray(arr) || !arr.length) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
return arr[idx] !== undefined ? arr[idx] : arr[arr.length - 1];
|
|
348
|
+
};
|
|
349
|
+
var indices = Array.from({ length: length }, function (_, i) { return i; });
|
|
350
|
+
indices.sort(function (i, j) {
|
|
351
|
+
var e_1, _a;
|
|
352
|
+
try {
|
|
353
|
+
for (var leafSorts_1 = __values(leafSorts), leafSorts_1_1 = leafSorts_1.next(); !leafSorts_1_1.done; leafSorts_1_1 = leafSorts_1.next()) {
|
|
354
|
+
var s = leafSorts_1_1.value;
|
|
355
|
+
var aVal = Array.isArray(row[s.leafId]) ? getArrayVal(s.leafId, i) : row[s.leafId];
|
|
356
|
+
var bVal = Array.isArray(row[s.leafId]) ? getArrayVal(s.leafId, j) : row[s.leafId];
|
|
357
|
+
var cmp = compareScalar(aVal, bVal, s.order);
|
|
358
|
+
if (cmp !== 0) {
|
|
359
|
+
return cmp;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
364
|
+
finally {
|
|
365
|
+
try {
|
|
366
|
+
if (leafSorts_1_1 && !leafSorts_1_1.done && (_a = leafSorts_1.return)) _a.call(leafSorts_1);
|
|
367
|
+
}
|
|
368
|
+
finally { if (e_1) throw e_1.error; }
|
|
369
|
+
}
|
|
370
|
+
return 0;
|
|
371
|
+
});
|
|
372
|
+
arraysToReorder.forEach(function (id) {
|
|
373
|
+
row[id] = indices.map(function (idx) { return getArrayVal(id, idx); });
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
var sortGroupLevel = function (rows, depth) {
|
|
377
|
+
if (!Array.isArray(rows) || !rows.length) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
var groupId = groupIds[depth];
|
|
381
|
+
var order = groupOrderById[groupId] || 'asc';
|
|
382
|
+
rows.sort(function (a, b) { var _a, _b; return compareScalar((_a = a === null || a === void 0 ? void 0 : a._id) === null || _a === void 0 ? void 0 : _a[groupId], (_b = b === null || b === void 0 ? void 0 : b._id) === null || _b === void 0 ? void 0 : _b[groupId], order); });
|
|
383
|
+
if (depth < groupIds.length - 1) {
|
|
384
|
+
var childId_1 = groupIds[depth + 1];
|
|
385
|
+
rows.forEach(function (r) {
|
|
386
|
+
var children = r ? r[childId_1] : null;
|
|
387
|
+
if (Array.isArray(children)) {
|
|
388
|
+
sortGroupLevel(children, depth + 1);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
rows.forEach(function (r) { return sortLeafArraysInRow(r); });
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
sortGroupLevel(results, 0);
|
|
397
|
+
}
|
|
70
398
|
function loadCronJobMethods(methodManager) {
|
|
71
399
|
methodManager.methods({
|
|
72
400
|
cronEmailMergedDocsCleanUp: {
|
|
@@ -123,13 +451,16 @@ function loadCronJobMethods(methodManager) {
|
|
|
123
451
|
}),
|
|
124
452
|
function: function (data) {
|
|
125
453
|
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
-
var report, fieldsObj_1, count_1,
|
|
127
|
-
var
|
|
454
|
+
var report, fieldsObj_1, count_1, idRemap_1, groupIds_1, userSorts, userSortByField_1, groupSorts, nonGroupSorts, effectiveSorts, sortObj_1, totalsForQuery, rootOptions, filters_1, filterArrayFields_1, filterArrays_1, res, results_1, reportTotals, customFields, exportFields_1, lines_1, tmpHeaders_1, wb, ws, wbout, _a, _b, email, e_2_1, wb, ws_1, currentRow_1, row, copy, widths_1, i, now, buffer, _c, _d, email, e_3_1, err_1, datedUniqueDates_1, datedUniqueGroups_1, datedData_1, reportTotalGroups_1, reportTotalDates_1, _loop_1, i, tmpResults, wb, ws, currentRow, currentCol_1, row_1, _loop_2, i, i, total, j, field, buffer, _e, _f, email, e_4_1, err_2, err_3;
|
|
455
|
+
var e_2, _g, e_3, _h, e_4, _j;
|
|
128
456
|
return __generator(this, function (_k) {
|
|
129
457
|
switch (_k.label) {
|
|
130
458
|
case 0: return [4 /*yield*/, report_builder_report_collection_1.ReportBuilderReports.findById(data['id_report'])];
|
|
131
459
|
case 1:
|
|
132
460
|
report = _k.sent();
|
|
461
|
+
_k.label = 2;
|
|
462
|
+
case 2:
|
|
463
|
+
_k.trys.push([2, 39, , 40]);
|
|
133
464
|
report.fields_selected.forEach(function (field) {
|
|
134
465
|
var _a, _b;
|
|
135
466
|
var dotPath = field.fieldPath.replace(/\.\$/g, '');
|
|
@@ -144,34 +475,74 @@ function loadCronJobMethods(methodManager) {
|
|
|
144
475
|
}
|
|
145
476
|
}
|
|
146
477
|
});
|
|
147
|
-
if (!((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length))) return [3 /*break*/,
|
|
478
|
+
if (!((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length))) return [3 /*break*/, 38];
|
|
148
479
|
fieldsObj_1 = {};
|
|
149
480
|
count_1 = 0;
|
|
481
|
+
idRemap_1 = {};
|
|
482
|
+
report.fields_sort = report.fields_sort || [];
|
|
150
483
|
report.fields_selected.forEach(function (field) {
|
|
151
484
|
if (field.collection_name === report.collection_root) {
|
|
152
485
|
fieldsObj_1 = (0, common_1.mergeDeep)(fieldsObj_1, field.fieldPathObj);
|
|
153
486
|
}
|
|
154
|
-
var
|
|
487
|
+
var oldId = field['id'];
|
|
488
|
+
var newId = 'f_' + count_1;
|
|
489
|
+
if (oldId) {
|
|
490
|
+
idRemap_1[oldId] = newId;
|
|
491
|
+
}
|
|
492
|
+
var sortIndex = report.fields_sort.findIndex(function (a) { return a.field === oldId; });
|
|
155
493
|
if (sortIndex >= 0) {
|
|
156
|
-
report.fields_sort[sortIndex].field =
|
|
494
|
+
report.fields_sort[sortIndex].field = newId;
|
|
157
495
|
}
|
|
158
|
-
field['id'] =
|
|
496
|
+
field['id'] = newId;
|
|
159
497
|
count_1 += 1;
|
|
160
498
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
499
|
+
groupIds_1 = (report.groups_row || []).map(function (g) { return g.id; }).filter(Boolean);
|
|
500
|
+
userSorts = (report.fields_sort || []).filter(function (s) { return !!s.field; });
|
|
501
|
+
userSortByField_1 = {};
|
|
502
|
+
userSorts.forEach(function (s) {
|
|
503
|
+
userSortByField_1[s.field] = s;
|
|
504
|
+
});
|
|
505
|
+
groupSorts = groupIds_1.map(function (id) { return userSortByField_1[id] || { field: id, order: 'asc' }; });
|
|
506
|
+
nonGroupSorts = userSorts.filter(function (s) { return !groupIds_1.includes(s.field); });
|
|
507
|
+
effectiveSorts = groupIds_1.length ? __spreadArray(__spreadArray([], __read(groupSorts), false), __read(nonGroupSorts), false) : userSorts;
|
|
508
|
+
sortObj_1 = null;
|
|
509
|
+
if (effectiveSorts.length) {
|
|
510
|
+
sortObj_1 = {};
|
|
511
|
+
effectiveSorts.forEach(function (sortField) {
|
|
512
|
+
var targetField = sortField.field;
|
|
513
|
+
if (!targetField) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (!targetField.startsWith('gr_') && !targetField.startsWith('layout_col_')) {
|
|
517
|
+
targetField = idRemap_1[targetField] || targetField;
|
|
518
|
+
}
|
|
519
|
+
if (targetField.startsWith('layout_col_')) {
|
|
520
|
+
var resolved = resolveFieldRefToLeafId(targetField, report);
|
|
521
|
+
targetField = resolved || targetField;
|
|
522
|
+
}
|
|
523
|
+
if (targetField.startsWith('gr_')) {
|
|
524
|
+
sortObj_1['_id.' + targetField] = (sortField.order === 'asc' ? 1 : -1);
|
|
166
525
|
}
|
|
167
526
|
else {
|
|
168
|
-
sortObj_1[
|
|
527
|
+
sortObj_1[targetField] = (sortField.order === 'asc' ? 1 : -1);
|
|
169
528
|
}
|
|
170
529
|
});
|
|
171
530
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
531
|
+
totalsForQuery = (report.fields_total || []).map(function (total) {
|
|
532
|
+
var mappedFields = (total.fields || [])
|
|
533
|
+
.map(function (ref) {
|
|
534
|
+
if (!ref) {
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
if (ref.startsWith('layout_col_')) {
|
|
538
|
+
return resolveFieldRefToLeafId(ref, report);
|
|
539
|
+
}
|
|
540
|
+
return idRemap_1[ref] || ref;
|
|
541
|
+
})
|
|
542
|
+
.filter(function (f) { return !!f; });
|
|
543
|
+
return __assign(__assign({}, total), { fields: mappedFields });
|
|
544
|
+
}).filter(function (total) { return (total.fields || []).length; });
|
|
545
|
+
report.fields_total = totalsForQuery;
|
|
175
546
|
rootOptions = {
|
|
176
547
|
limit: 0,
|
|
177
548
|
skip: 0,
|
|
@@ -179,304 +550,54 @@ function loadCronJobMethods(methodManager) {
|
|
|
179
550
|
sort: sortObj_1
|
|
180
551
|
};
|
|
181
552
|
filters_1 = [];
|
|
182
|
-
report.fields_filter.forEach(function (filterAnd) {
|
|
183
|
-
var ors = [];
|
|
184
|
-
filterAnd.ors.filter(function (a) { return !a.field.includes('.$.'); }).forEach(function (filter) {
|
|
185
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
186
|
-
if (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {
|
|
187
|
-
if (filter.condition === 'bw') {
|
|
188
|
-
if (filter.fieldType === 'Date' && filter.is_rolling) {
|
|
189
|
-
var startDate = null;
|
|
190
|
-
var endDate = null;
|
|
191
|
-
if (filter.rolling_interval === 'Q1') {
|
|
192
|
-
startDate = moment().startOf('year').toDate();
|
|
193
|
-
endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
|
|
194
|
-
}
|
|
195
|
-
else if (filter.rolling_interval === 'Q2') {
|
|
196
|
-
startDate = moment().startOf('year').quarter(2).toDate();
|
|
197
|
-
endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
|
|
198
|
-
}
|
|
199
|
-
else if (filter.rolling_interval === 'Q3') {
|
|
200
|
-
startDate = moment().startOf('year').quarter(3).toDate();
|
|
201
|
-
endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
|
|
202
|
-
}
|
|
203
|
-
else if (filter.rolling_interval === 'Q4') {
|
|
204
|
-
startDate = moment().startOf('year').quarter(4).toDate();
|
|
205
|
-
endDate = moment().endOf('year').toDate();
|
|
206
|
-
}
|
|
207
|
-
else if (filter.rolling_interval === 'Today') {
|
|
208
|
-
startDate = moment().startOf('day').toDate();
|
|
209
|
-
endDate = moment().endOf('day').toDate();
|
|
210
|
-
}
|
|
211
|
-
else if (filter.rolling_interval === 'Yesterday') {
|
|
212
|
-
startDate = moment().subtract(1, 'days').startOf('day').toDate();
|
|
213
|
-
endDate = moment().subtract(1, 'days').endOf('day').toDate();
|
|
214
|
-
}
|
|
215
|
-
else if (filter.rolling_interval === 'Week') {
|
|
216
|
-
startDate = moment().startOf('isoWeek').toDate();
|
|
217
|
-
endDate = moment().endOf('day').toDate();
|
|
218
|
-
}
|
|
219
|
-
else if (filter.rolling_interval === 'Last Week') {
|
|
220
|
-
endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
|
|
221
|
-
startDate = moment(endDate).startOf('isoWeek').toDate();
|
|
222
|
-
}
|
|
223
|
-
else if (filter.rolling_interval === 'Month') {
|
|
224
|
-
startDate = moment().startOf('month').toDate();
|
|
225
|
-
endDate = moment().endOf('day').toDate();
|
|
226
|
-
}
|
|
227
|
-
else if (filter.rolling_interval === 'Last Month') {
|
|
228
|
-
endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
|
|
229
|
-
startDate = moment(endDate).startOf('month').toDate();
|
|
230
|
-
}
|
|
231
|
-
else if (filter.rolling_interval === 'Last 30 Days') {
|
|
232
|
-
endDate = moment().endOf('day').toDate();
|
|
233
|
-
startDate = moment().subtract(30, 'days').startOf('day').toDate();
|
|
234
|
-
}
|
|
235
|
-
else if (filter.rolling_interval === 'Quarter') {
|
|
236
|
-
startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
|
|
237
|
-
endDate = moment().endOf('day').toDate();
|
|
238
|
-
}
|
|
239
|
-
else if (filter.rolling_interval === 'Last Quarter') {
|
|
240
|
-
endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
|
|
241
|
-
startDate = moment(endDate).startOf('quarter').toDate();
|
|
242
|
-
}
|
|
243
|
-
else if (filter.rolling_interval === 'Year') {
|
|
244
|
-
startDate = moment().startOf('year').toDate();
|
|
245
|
-
endDate = moment().endOf('day').toDate();
|
|
246
|
-
}
|
|
247
|
-
else if (filter.rolling_interval === 'Last Year') {
|
|
248
|
-
endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
|
|
249
|
-
startDate = moment(endDate).startOf('year').toDate();
|
|
250
|
-
}
|
|
251
|
-
else if (filter.rolling_interval === 'All') {
|
|
252
|
-
startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
|
|
253
|
-
endDate = moment().endOf('day').toDate();
|
|
254
|
-
}
|
|
255
|
-
endDate.setHours(23);
|
|
256
|
-
endDate.setMinutes(59);
|
|
257
|
-
endDate.setSeconds(59);
|
|
258
|
-
endDate.setMilliseconds(999);
|
|
259
|
-
ors.push({ $and: [(_a = {}, _a[filter.field] = { '$gte': startDate }, _a), (_b = {}, _b[filter.field] = { '$lte': endDate }, _b)] });
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
ors.push({ $and: [(_c = {}, _c[filter.field] = { '$gte': filter.value }, _c), (_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d)] });
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else if (filter.condition === 'nnull') {
|
|
266
|
-
var and = [];
|
|
267
|
-
and.push((_e = {}, _e[filter.field] = { '$exists': true }, _e));
|
|
268
|
-
and.push((_f = {}, _f[filter.field] = { '$ne': null }, _f));
|
|
269
|
-
if (filter.fieldType === 'String') {
|
|
270
|
-
and.push((_g = {}, _g[filter.field] = { '$ne': '' }, _g));
|
|
271
|
-
}
|
|
272
|
-
ors.push({ $and: and });
|
|
273
|
-
}
|
|
274
|
-
else if (filter.condition === 'null') {
|
|
275
|
-
ors.push((_h = {}, _h[filter.field] = { '$eq': null }, _h));
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
if (Array.isArray(filter.value)) {
|
|
279
|
-
if (filter.condition === 'ne') {
|
|
280
|
-
var and_1 = [];
|
|
281
|
-
filter.value.forEach(function (filt) {
|
|
282
|
-
var _a, _b;
|
|
283
|
-
and_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
284
|
-
});
|
|
285
|
-
if (and_1.length > 1) {
|
|
286
|
-
ors.push({ $and: and_1 });
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
ors.push(and_1[0]);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
var or_1 = [];
|
|
294
|
-
filter.value.forEach(function (filt) {
|
|
295
|
-
var _a, _b;
|
|
296
|
-
or_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
297
|
-
});
|
|
298
|
-
if (or_1.length > 1) {
|
|
299
|
-
ors.push({ $or: or_1 });
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
ors.push(or_1[0]);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
ors.push((_j = {}, _j[filter.field] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
if (ors.length) {
|
|
313
|
-
filters_1.push({ $or: ors });
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
_k.label = 2;
|
|
317
|
-
case 2:
|
|
318
|
-
_k.trys.push([2, 43, , 44]);
|
|
319
|
-
return [4 /*yield*/, this.callMethod('reportBuilderBuildTree', report.collection_root, report.collection_joins || [])];
|
|
320
|
-
case 3:
|
|
321
|
-
collectionTree = _k.sent();
|
|
322
|
-
if (!collectionTree) return [3 /*break*/, 42];
|
|
323
|
-
collectionTree.layers = [collectionTree];
|
|
324
|
-
treeLeaves = [];
|
|
325
|
-
allLeaves_1 = [];
|
|
326
|
-
getTreeLeaves(collectionTree.children, treeLeaves);
|
|
327
|
-
getTreeLeaves(collectionTree.children, allLeaves_1, true);
|
|
328
553
|
filterArrayFields_1 = [];
|
|
329
554
|
filterArrays_1 = [];
|
|
330
|
-
report.fields_filter.forEach(function (filterAnd) {
|
|
555
|
+
(report.fields_filter || []).forEach(function (filterAnd) {
|
|
331
556
|
var ors = [];
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
var
|
|
335
|
-
if (
|
|
336
|
-
|
|
557
|
+
var hasArrayTarget = false;
|
|
558
|
+
(filterAnd.ors || []).forEach(function (filter) {
|
|
559
|
+
var targets = getFilterTargets(filter.field, report);
|
|
560
|
+
if (!targets.length) {
|
|
561
|
+
return;
|
|
337
562
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
startDate = moment().startOf('year').toDate();
|
|
345
|
-
endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
|
|
346
|
-
}
|
|
347
|
-
else if (filter.rolling_interval === 'Q2') {
|
|
348
|
-
startDate = moment().startOf('year').quarter(2).toDate();
|
|
349
|
-
endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
|
|
350
|
-
}
|
|
351
|
-
else if (filter.rolling_interval === 'Q3') {
|
|
352
|
-
startDate = moment().startOf('year').quarter(3).toDate();
|
|
353
|
-
endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
|
|
354
|
-
}
|
|
355
|
-
else if (filter.rolling_interval === 'Q4') {
|
|
356
|
-
startDate = moment().startOf('year').quarter(4).toDate();
|
|
357
|
-
endDate = moment().endOf('year').toDate();
|
|
358
|
-
}
|
|
359
|
-
else if (filter.rolling_interval === 'Today') {
|
|
360
|
-
startDate = moment().startOf('day').toDate();
|
|
361
|
-
endDate = moment().endOf('day').toDate();
|
|
362
|
-
}
|
|
363
|
-
else if (filter.rolling_interval === 'Yesterday') {
|
|
364
|
-
startDate = moment().subtract(1, 'days').startOf('day').toDate();
|
|
365
|
-
endDate = moment().subtract(1, 'days').endOf('day').toDate();
|
|
366
|
-
}
|
|
367
|
-
else if (filter.rolling_interval === 'Week') {
|
|
368
|
-
startDate = moment().startOf('isoWeek').toDate();
|
|
369
|
-
endDate = moment().endOf('day').toDate();
|
|
370
|
-
}
|
|
371
|
-
else if (filter.rolling_interval === 'Last Week') {
|
|
372
|
-
endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
|
|
373
|
-
startDate = moment(endDate).startOf('isoWeek').toDate();
|
|
374
|
-
}
|
|
375
|
-
else if (filter.rolling_interval === 'Month') {
|
|
376
|
-
startDate = moment().startOf('month').toDate();
|
|
377
|
-
endDate = moment().endOf('day').toDate();
|
|
378
|
-
}
|
|
379
|
-
else if (filter.rolling_interval === 'Last Month') {
|
|
380
|
-
endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
|
|
381
|
-
startDate = moment(endDate).startOf('month').toDate();
|
|
382
|
-
}
|
|
383
|
-
else if (filter.rolling_interval === 'Last 30 Days') {
|
|
384
|
-
endDate = moment().endOf('day').toDate();
|
|
385
|
-
startDate = moment().subtract(30, 'days').startOf('day').toDate();
|
|
386
|
-
}
|
|
387
|
-
else if (filter.rolling_interval === 'Quarter') {
|
|
388
|
-
startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
|
|
389
|
-
endDate = moment().endOf('day').toDate();
|
|
390
|
-
}
|
|
391
|
-
else if (filter.rolling_interval === 'Last Quarter') {
|
|
392
|
-
endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
|
|
393
|
-
startDate = moment(endDate).startOf('quarter').toDate();
|
|
394
|
-
}
|
|
395
|
-
else if (filter.rolling_interval === 'Year') {
|
|
396
|
-
startDate = moment().startOf('year').toDate();
|
|
397
|
-
endDate = moment().endOf('day').toDate();
|
|
398
|
-
}
|
|
399
|
-
else if (filter.rolling_interval === 'Last Year') {
|
|
400
|
-
endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
|
|
401
|
-
startDate = moment(endDate).startOf('year').toDate();
|
|
402
|
-
}
|
|
403
|
-
else if (filter.rolling_interval === 'All') {
|
|
404
|
-
startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
|
|
405
|
-
endDate = moment().endOf('day').toDate();
|
|
406
|
-
}
|
|
407
|
-
endDate.setHours(23);
|
|
408
|
-
endDate.setMinutes(59);
|
|
409
|
-
endDate.setSeconds(59);
|
|
410
|
-
endDate.setMilliseconds(999);
|
|
411
|
-
ors.push({ $and: [(_a = {}, _a[filter.field.replace(/\.\$/g, '')] = { '$gte': startDate }, _a), (_b = {}, _b[filter.field.replace(/\.\$/g, '')] = { '$lte': endDate }, _b)] });
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
filterArrays_1.push({ $and: [(_c = {}, _c[filter.field.replace(/\.\$/g, '')] = { '$gte': filter.value }, _c), (_d = {}, _d[filter.field.replace(/\.\$/g, '')] = { '$lte': filter.highValue }, _d)] });
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
else if (filter.condition === 'nnull') {
|
|
418
|
-
var and = [];
|
|
419
|
-
and.push((_e = {}, _e[filter.field.replace(/\.\$/g, '')] = { '$exists': true }, _e));
|
|
420
|
-
and.push((_f = {}, _f[filter.field.replace(/\.\$/g, '')] = { '$ne': null }, _f));
|
|
421
|
-
if (filter.fieldType === 'String') {
|
|
422
|
-
and.push((_g = {}, _g[filter.field.replace(/\.\$/g, '')] = { '$ne': '' }, _g));
|
|
423
|
-
}
|
|
424
|
-
ors.push({ $and: and });
|
|
425
|
-
}
|
|
426
|
-
else if (filter.condition === 'null') {
|
|
427
|
-
ors.push((_h = {}, _h[filter.field.replace(/\.\$/g, '')] = { '$eq': null }, _h));
|
|
563
|
+
targets.forEach(function (path) {
|
|
564
|
+
var isArrayTarget = path.includes('.$.');
|
|
565
|
+
var normalizedPath = path.replace(/\.\$/g, '');
|
|
566
|
+
var expr = buildFilterExpression(filter, normalizedPath);
|
|
567
|
+
if (expr) {
|
|
568
|
+
ors.push(expr);
|
|
428
569
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var _a, _b;
|
|
435
|
-
and_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
436
|
-
});
|
|
437
|
-
if (and_2.length > 1) {
|
|
438
|
-
ors.push({ $and: and_2 });
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
ors.push(and_2[0]);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
var or_2 = [];
|
|
446
|
-
filter.value.forEach(function (filt) {
|
|
447
|
-
var _a, _b;
|
|
448
|
-
or_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
449
|
-
});
|
|
450
|
-
if (or_2.length > 1) {
|
|
451
|
-
ors.push({ $or: or_2 });
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
ors.push(or_2[0]);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
ors.push((_j = {}, _j[filter.field.replace(/\.\$/g, '')] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
|
|
570
|
+
if (isArrayTarget) {
|
|
571
|
+
hasArrayTarget = true;
|
|
572
|
+
var leaf_1 = (report.fields_selected || []).find(function (a) { return a.fieldPath === path; });
|
|
573
|
+
if (leaf_1 && !filterArrayFields_1.some(function (f) { return (f === null || f === void 0 ? void 0 : f.fieldPath) === leaf_1.fieldPath; })) {
|
|
574
|
+
filterArrayFields_1.push(leaf_1);
|
|
460
575
|
}
|
|
461
576
|
}
|
|
462
|
-
}
|
|
577
|
+
});
|
|
463
578
|
});
|
|
464
579
|
if (ors.length) {
|
|
465
|
-
|
|
580
|
+
var filterObj = { $or: ors };
|
|
581
|
+
if (hasArrayTarget) {
|
|
582
|
+
filterArrays_1.push(filterObj);
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
filters_1.push(filterObj);
|
|
586
|
+
}
|
|
466
587
|
}
|
|
467
588
|
});
|
|
468
|
-
|
|
469
|
-
case
|
|
470
|
-
_k.trys.push([4, 41, , 42]);
|
|
471
|
-
return [4 /*yield*/, this.callMethod('reportBuilderGetResults', report.type, report.collection_root, rootOptions, 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)];
|
|
472
|
-
case 5:
|
|
589
|
+
return [4 /*yield*/, this.callMethod('reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters_1, filterArrays_1, filterArrayFields_1, report.fields_selected, report.fields_custom, report.groups_row, totalsForQuery, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type)];
|
|
590
|
+
case 3:
|
|
473
591
|
res = _k.sent();
|
|
474
|
-
if (!(res && res[0])) return [3 /*break*/,
|
|
592
|
+
if (!(res && res[0])) return [3 /*break*/, 38];
|
|
475
593
|
results_1 = res[0].results;
|
|
476
594
|
reportTotals = res[0].totals;
|
|
595
|
+
if (report.type === 'Group') {
|
|
596
|
+
applyClientGroupSortToData(results_1, report, effectiveSorts);
|
|
597
|
+
}
|
|
477
598
|
customFields = (report.fields_custom || []).map(function (cust) { return (__assign(__assign({}, cust), { id: cust.selFieldId, fieldType: 'Number', leafValueType: cust.leafValueType || 'Value', leafFormatType: 'Number', columnName: cust.columnName || cust.id, show: true })); });
|
|
478
599
|
exportFields_1 = report.fields_selected.filter(function (a) { return a.show; }).concat(customFields);
|
|
479
|
-
if (!(report.type === 'List')) return [3 /*break*/,
|
|
600
|
+
if (!(report.type === 'List')) return [3 /*break*/, 12];
|
|
480
601
|
exportFields_1.forEach(function (field) {
|
|
481
602
|
if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
|
|
482
603
|
results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
|
|
@@ -581,41 +702,41 @@ function loadCronJobMethods(methodManager) {
|
|
|
581
702
|
ws = XLSX.utils.json_to_sheet(lines_1);
|
|
582
703
|
XLSX.utils.book_append_sheet(wb, ws, 'RB Data');
|
|
583
704
|
wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'base64' });
|
|
584
|
-
_k.label =
|
|
585
|
-
case
|
|
586
|
-
_k.trys.push([
|
|
705
|
+
_k.label = 4;
|
|
706
|
+
case 4:
|
|
707
|
+
_k.trys.push([4, 9, 10, 11]);
|
|
587
708
|
_a = __values(data['emails']), _b = _a.next();
|
|
588
|
-
_k.label =
|
|
589
|
-
case
|
|
590
|
-
if (!!_b.done) return [3 /*break*/,
|
|
709
|
+
_k.label = 5;
|
|
710
|
+
case 5:
|
|
711
|
+
if (!!_b.done) return [3 /*break*/, 8];
|
|
591
712
|
email = _b.value;
|
|
592
|
-
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t
|
|
713
|
+
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\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<b>Report Name: </b>" + report.report_name + "<br>\n\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\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
|
|
593
714
|
{
|
|
594
715
|
filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',
|
|
595
716
|
content: wbout,
|
|
596
717
|
encoding: 'base64'
|
|
597
718
|
}
|
|
598
719
|
], this.serverConfig['MAIL_FROM_REPORTS'], '')];
|
|
599
|
-
case
|
|
720
|
+
case 6:
|
|
600
721
|
_k.sent();
|
|
601
|
-
_k.label =
|
|
602
|
-
case
|
|
722
|
+
_k.label = 7;
|
|
723
|
+
case 7:
|
|
603
724
|
_b = _a.next();
|
|
604
|
-
return [3 /*break*/,
|
|
605
|
-
case
|
|
606
|
-
case
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return [3 /*break*/,
|
|
610
|
-
case
|
|
725
|
+
return [3 /*break*/, 5];
|
|
726
|
+
case 8: return [3 /*break*/, 11];
|
|
727
|
+
case 9:
|
|
728
|
+
e_2_1 = _k.sent();
|
|
729
|
+
e_2 = { error: e_2_1 };
|
|
730
|
+
return [3 /*break*/, 11];
|
|
731
|
+
case 10:
|
|
611
732
|
try {
|
|
612
733
|
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
|
|
613
734
|
}
|
|
614
|
-
finally { if (
|
|
735
|
+
finally { if (e_2) throw e_2.error; }
|
|
615
736
|
return [7 /*endfinally*/];
|
|
616
|
-
case
|
|
617
|
-
case
|
|
618
|
-
if (!(report.type === 'Group')) return [3 /*break*/,
|
|
737
|
+
case 11: return [3 /*break*/, 38];
|
|
738
|
+
case 12:
|
|
739
|
+
if (!(report.type === 'Group')) return [3 /*break*/, 25];
|
|
619
740
|
exportFields_1.forEach(function (field) {
|
|
620
741
|
results_1.forEach(function (result) {
|
|
621
742
|
modifyDataTypeField(report, result, field, 1);
|
|
@@ -662,53 +783,53 @@ function loadCronJobMethods(methodManager) {
|
|
|
662
783
|
ws_1.columns[i].width = widths_1[i - 1];
|
|
663
784
|
}
|
|
664
785
|
now = new Date();
|
|
665
|
-
_k.label =
|
|
666
|
-
case
|
|
667
|
-
_k.trys.push([
|
|
786
|
+
_k.label = 13;
|
|
787
|
+
case 13:
|
|
788
|
+
_k.trys.push([13, 23, , 24]);
|
|
668
789
|
return [4 /*yield*/, wb.xlsx.writeBuffer()];
|
|
669
|
-
case
|
|
790
|
+
case 14:
|
|
670
791
|
buffer = _k.sent();
|
|
671
|
-
_k.label =
|
|
672
|
-
case
|
|
673
|
-
_k.trys.push([
|
|
792
|
+
_k.label = 15;
|
|
793
|
+
case 15:
|
|
794
|
+
_k.trys.push([15, 20, 21, 22]);
|
|
674
795
|
_c = __values(data['emails']), _d = _c.next();
|
|
675
|
-
_k.label =
|
|
676
|
-
case
|
|
677
|
-
if (!!_d.done) return [3 /*break*/,
|
|
796
|
+
_k.label = 16;
|
|
797
|
+
case 16:
|
|
798
|
+
if (!!_d.done) return [3 /*break*/, 19];
|
|
678
799
|
email = _d.value;
|
|
679
|
-
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t
|
|
800
|
+
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\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<b>Report Name: </b>" + report.report_name + "<br>\n\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\tAttached are the results of this automated report.<br><br>\n\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\tResolveIO<br><br>", [
|
|
680
801
|
{
|
|
681
802
|
filename: 'Group_Report_' + report.report_name + '_' + now.getFullYear() + '_' + (now.getMonth() + 1) + '_' + now.getDate() + '.xlsx',
|
|
682
803
|
content: buffer
|
|
683
804
|
}
|
|
684
805
|
], this.serverConfig['MAIL_FROM_REPORTS'], '')];
|
|
685
|
-
case
|
|
806
|
+
case 17:
|
|
686
807
|
_k.sent();
|
|
687
|
-
_k.label =
|
|
688
|
-
case
|
|
808
|
+
_k.label = 18;
|
|
809
|
+
case 18:
|
|
689
810
|
_d = _c.next();
|
|
690
|
-
return [3 /*break*/,
|
|
691
|
-
case
|
|
692
|
-
case
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
return [3 /*break*/,
|
|
696
|
-
case
|
|
811
|
+
return [3 /*break*/, 16];
|
|
812
|
+
case 19: return [3 /*break*/, 22];
|
|
813
|
+
case 20:
|
|
814
|
+
e_3_1 = _k.sent();
|
|
815
|
+
e_3 = { error: e_3_1 };
|
|
816
|
+
return [3 /*break*/, 22];
|
|
817
|
+
case 21:
|
|
697
818
|
try {
|
|
698
819
|
if (_d && !_d.done && (_h = _c.return)) _h.call(_c);
|
|
699
820
|
}
|
|
700
|
-
finally { if (
|
|
821
|
+
finally { if (e_3) throw e_3.error; }
|
|
701
822
|
return [7 /*endfinally*/];
|
|
702
|
-
case
|
|
703
|
-
case
|
|
823
|
+
case 22: return [3 /*break*/, 24];
|
|
824
|
+
case 23:
|
|
704
825
|
err_1 = _k.sent();
|
|
705
826
|
console.log('Error writing excel export', err_1);
|
|
706
|
-
return [3 /*break*/,
|
|
707
|
-
case
|
|
827
|
+
return [3 /*break*/, 24];
|
|
828
|
+
case 24:
|
|
708
829
|
;
|
|
709
|
-
return [3 /*break*/,
|
|
710
|
-
case
|
|
711
|
-
if (!(report.type === 'Dated')) return [3 /*break*/,
|
|
830
|
+
return [3 /*break*/, 38];
|
|
831
|
+
case 25:
|
|
832
|
+
if (!(report.type === 'Dated')) return [3 /*break*/, 38];
|
|
712
833
|
datedUniqueDates_1 = [];
|
|
713
834
|
datedUniqueGroups_1 = [];
|
|
714
835
|
datedData_1 = [];
|
|
@@ -1081,59 +1202,55 @@ function loadCronJobMethods(methodManager) {
|
|
|
1081
1202
|
currentRow++; // Move to the next row for the next total
|
|
1082
1203
|
}
|
|
1083
1204
|
}
|
|
1084
|
-
_k.label =
|
|
1085
|
-
case
|
|
1086
|
-
_k.trys.push([
|
|
1205
|
+
_k.label = 26;
|
|
1206
|
+
case 26:
|
|
1207
|
+
_k.trys.push([26, 36, , 37]);
|
|
1087
1208
|
return [4 /*yield*/, wb.xlsx.writeBuffer()];
|
|
1088
|
-
case
|
|
1209
|
+
case 27:
|
|
1089
1210
|
buffer = _k.sent();
|
|
1090
|
-
_k.label =
|
|
1091
|
-
case
|
|
1092
|
-
_k.trys.push([
|
|
1211
|
+
_k.label = 28;
|
|
1212
|
+
case 28:
|
|
1213
|
+
_k.trys.push([28, 33, 34, 35]);
|
|
1093
1214
|
_e = __values(data['emails']), _f = _e.next();
|
|
1094
|
-
_k.label =
|
|
1095
|
-
case
|
|
1096
|
-
if (!!_f.done) return [3 /*break*/,
|
|
1215
|
+
_k.label = 29;
|
|
1216
|
+
case 29:
|
|
1217
|
+
if (!!_f.done) return [3 /*break*/, 32];
|
|
1097
1218
|
email = _f.value;
|
|
1098
|
-
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t
|
|
1219
|
+
return [4 /*yield*/, this.sendEmail(email, this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t<b>".concat(this.serverConfig['CLIENT_NAME'], " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>").concat(report.report_name, "<br>\n\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>").concat(data['user'], "<br><br>\n\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\tResolveIO<br><br>"), [
|
|
1099
1220
|
{
|
|
1100
1221
|
filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',
|
|
1101
1222
|
content: buffer
|
|
1102
1223
|
}
|
|
1103
1224
|
], this.serverConfig['MAIL_FROM_REPORTS'], '')];
|
|
1104
|
-
case
|
|
1225
|
+
case 30:
|
|
1105
1226
|
_k.sent();
|
|
1106
|
-
_k.label =
|
|
1107
|
-
case
|
|
1227
|
+
_k.label = 31;
|
|
1228
|
+
case 31:
|
|
1108
1229
|
_f = _e.next();
|
|
1109
|
-
return [3 /*break*/,
|
|
1110
|
-
case
|
|
1111
|
-
case
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
return [3 /*break*/,
|
|
1115
|
-
case
|
|
1230
|
+
return [3 /*break*/, 29];
|
|
1231
|
+
case 32: return [3 /*break*/, 35];
|
|
1232
|
+
case 33:
|
|
1233
|
+
e_4_1 = _k.sent();
|
|
1234
|
+
e_4 = { error: e_4_1 };
|
|
1235
|
+
return [3 /*break*/, 35];
|
|
1236
|
+
case 34:
|
|
1116
1237
|
try {
|
|
1117
1238
|
if (_f && !_f.done && (_j = _e.return)) _j.call(_e);
|
|
1118
1239
|
}
|
|
1119
|
-
finally { if (
|
|
1240
|
+
finally { if (e_4) throw e_4.error; }
|
|
1120
1241
|
return [7 /*endfinally*/];
|
|
1121
|
-
case
|
|
1122
|
-
case
|
|
1242
|
+
case 35: return [3 /*break*/, 37];
|
|
1243
|
+
case 36:
|
|
1123
1244
|
err_2 = _k.sent();
|
|
1124
1245
|
console.log('Error writing excel export', err_2);
|
|
1125
|
-
return [3 /*break*/,
|
|
1126
|
-
case
|
|
1127
|
-
case
|
|
1128
|
-
case
|
|
1246
|
+
return [3 /*break*/, 37];
|
|
1247
|
+
case 37: return [2 /*return*/, true];
|
|
1248
|
+
case 38: return [3 /*break*/, 40];
|
|
1249
|
+
case 39:
|
|
1129
1250
|
err_3 = _k.sent();
|
|
1251
|
+
err_3.message = "Error in Report Builder Cron Job - Report Builder Build Tree: ".concat(err_3.message);
|
|
1130
1252
|
throw err_3;
|
|
1131
|
-
case
|
|
1132
|
-
case 43:
|
|
1133
|
-
err_4 = _k.sent();
|
|
1134
|
-
err_4.message = "Error in Report Builder Cron Job - Report Builder Build Tree: ".concat(err_4.message);
|
|
1135
|
-
throw err_4;
|
|
1136
|
-
case 44: return [2 /*return*/, true];
|
|
1253
|
+
case 40: return [2 /*return*/, true];
|
|
1137
1254
|
}
|
|
1138
1255
|
});
|
|
1139
1256
|
});
|
|
@@ -1141,19 +1258,6 @@ function loadCronJobMethods(methodManager) {
|
|
|
1141
1258
|
}
|
|
1142
1259
|
});
|
|
1143
1260
|
}
|
|
1144
|
-
function getTreeLeaves(items, resArray, allowLookups) {
|
|
1145
|
-
if (allowLookups === void 0) { allowLookups = false; }
|
|
1146
|
-
items.forEach(function (item) {
|
|
1147
|
-
if (item.isLeaf) {
|
|
1148
|
-
resArray.push(item);
|
|
1149
|
-
}
|
|
1150
|
-
else {
|
|
1151
|
-
if (!item.lookup_collection || allowLookups) {
|
|
1152
|
-
getTreeLeaves(item.children, resArray, allowLookups);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
1261
|
function modifyDataTypeField(report, result, field, index) {
|
|
1158
1262
|
var processFieldValue = function (value, field) {
|
|
1159
1263
|
if (value === undefined || value === null) {
|