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