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