@resolveio/server-lib 4.6.9 → 4.6.10
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/methods/cron-jobs.js +504 -482
- package/methods/report-builder.js +52 -15
- package/package.json +1 -1
package/methods/cron-jobs.js
CHANGED
|
@@ -142,7 +142,7 @@ function loadCronJobMethods(methodManager) {
|
|
|
142
142
|
function: function (data) {
|
|
143
143
|
var _this = this;
|
|
144
144
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
145
|
-
var report, fieldsObj_1, count_1, sortObj_1,
|
|
145
|
+
var report, fieldsObj_1, count_1, sortObj_1, rootOptions_1, filters_1;
|
|
146
146
|
var _this = this;
|
|
147
147
|
return __generator(this, function (_a) {
|
|
148
148
|
switch (_a.label) {
|
|
@@ -191,7 +191,7 @@ function loadCronJobMethods(methodManager) {
|
|
|
191
191
|
else {
|
|
192
192
|
sortObj_1 = null;
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
rootOptions_1 = {
|
|
195
195
|
limit: 0,
|
|
196
196
|
skip: 0,
|
|
197
197
|
fields: fieldsObj_1,
|
|
@@ -292,527 +292,536 @@ function loadCronJobMethods(methodManager) {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
});
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
295
|
+
this.callMethodInternal.call(this, 'reportBuilderBuildTree', this.form.value.collection_root, function (errCollTree, collectionTree) {
|
|
296
|
+
if (collectionTree) {
|
|
297
|
+
collectionTree.layers = [collectionTree];
|
|
298
|
+
var treeLeaves = [];
|
|
299
|
+
var allLeaves_1 = [];
|
|
300
|
+
getTreeLeaves(collectionTree.children, treeLeaves);
|
|
301
|
+
getTreeLeaves(collectionTree.children, allLeaves_1, true);
|
|
302
|
+
var filterArrayFields_1 = [];
|
|
303
|
+
var filterArrays_1 = [];
|
|
304
|
+
report.fields_filter.filter(function (a) { return a.field.includes('.$.'); }).forEach(function (filter) {
|
|
305
|
+
var _a, _b, _c, _d, _e, _f;
|
|
306
|
+
filterArrayFields_1.push(allLeaves_1.filter(function (a) { return a.fieldPath === filter.field; })[0]);
|
|
307
|
+
if (filter.condition && filter.field && filter.value !== null) {
|
|
308
|
+
if (filter.condition === 'bw') {
|
|
309
|
+
if (filter.fieldType === 'Date' && filter.is_rolling) {
|
|
310
|
+
var startDate = null;
|
|
311
|
+
var endDate = null;
|
|
312
|
+
if (filter.rolling_interval === 'Q1') {
|
|
313
|
+
startDate = moment().startOf('year').toDate();
|
|
314
|
+
endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
|
|
315
|
+
}
|
|
316
|
+
else if (filter.rolling_interval === 'Q2') {
|
|
317
|
+
startDate = moment().startOf('year').quarter(2).toDate();
|
|
318
|
+
endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
|
|
319
|
+
}
|
|
320
|
+
else if (filter.rolling_interval === 'Q3') {
|
|
321
|
+
startDate = moment().startOf('year').quarter(3).toDate();
|
|
322
|
+
endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
|
|
323
|
+
}
|
|
324
|
+
else if (filter.rolling_interval === 'Q4') {
|
|
325
|
+
startDate = moment().startOf('year').quarter(4).toDate();
|
|
326
|
+
endDate = moment().endOf('year').toDate();
|
|
327
|
+
}
|
|
328
|
+
else if (filter.rolling_interval === 'Today') {
|
|
329
|
+
startDate = moment().startOf('day').toDate();
|
|
330
|
+
endDate = moment().endOf('day').toDate();
|
|
331
|
+
}
|
|
332
|
+
else if (filter.rolling_interval === 'Yesterday') {
|
|
333
|
+
startDate = moment().subtract(1, 'days').startOf('day').toDate();
|
|
334
|
+
endDate = moment().subtract(1, 'days').endOf('day').toDate();
|
|
335
|
+
}
|
|
336
|
+
else if (filter.rolling_interval === 'Week') {
|
|
337
|
+
startDate = moment().startOf('isoWeek').toDate();
|
|
338
|
+
endDate = moment().endOf('day').toDate();
|
|
339
|
+
}
|
|
340
|
+
else if (filter.rolling_interval === 'Last Week') {
|
|
341
|
+
endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
|
|
342
|
+
startDate = moment(endDate).startOf('isoWeek').toDate();
|
|
343
|
+
}
|
|
344
|
+
else if (filter.rolling_interval === 'Month') {
|
|
345
|
+
startDate = moment().startOf('month').toDate();
|
|
346
|
+
endDate = moment().endOf('day').toDate();
|
|
347
|
+
}
|
|
348
|
+
else if (filter.rolling_interval === 'Last Month') {
|
|
349
|
+
endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
|
|
350
|
+
startDate = moment(endDate).startOf('month').toDate();
|
|
351
|
+
}
|
|
352
|
+
else if (filter.rolling_interval === 'Last 30 Days') {
|
|
353
|
+
endDate = moment().endOf('day').toDate();
|
|
354
|
+
startDate = moment().subtract(30, 'days').startOf('day').toDate();
|
|
355
|
+
}
|
|
356
|
+
else if (filter.rolling_interval === 'Quarter') {
|
|
357
|
+
startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
|
|
358
|
+
endDate = moment().endOf('day').toDate();
|
|
359
|
+
}
|
|
360
|
+
else if (filter.rolling_interval === 'Last Quarter') {
|
|
361
|
+
endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
|
|
362
|
+
startDate = moment(endDate).startOf('quarter').toDate();
|
|
363
|
+
}
|
|
364
|
+
else if (filter.rolling_interval === 'Year') {
|
|
365
|
+
startDate = moment().startOf('year').toDate();
|
|
366
|
+
endDate = moment().endOf('day').toDate();
|
|
367
|
+
}
|
|
368
|
+
else if (filter.rolling_interval === 'Last Year') {
|
|
369
|
+
endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
|
|
370
|
+
startDate = moment(endDate).startOf('year').toDate();
|
|
371
|
+
}
|
|
372
|
+
else if (filter.rolling_interval === 'All') {
|
|
373
|
+
startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
|
|
374
|
+
endDate = moment().endOf('day').toDate();
|
|
375
|
+
}
|
|
376
|
+
filterArrays_1.push((_a = {}, _a[filter.field] = { '$gte': startDate }, _a));
|
|
377
|
+
filterArrays_1.push((_b = {}, _b[filter.field] = { '$lte': endDate }, _b));
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
filterArrays_1.push((_c = {}, _c[filter.field] = { '$gte': filter.value }, _c));
|
|
381
|
+
filterArrays_1.push((_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d));
|
|
382
|
+
}
|
|
364
383
|
}
|
|
365
|
-
else
|
|
366
|
-
|
|
367
|
-
|
|
384
|
+
else {
|
|
385
|
+
if (Array.isArray(filter.value)) {
|
|
386
|
+
var or_2 = [];
|
|
387
|
+
filter.value.forEach(function (filt) {
|
|
388
|
+
var _a, _b;
|
|
389
|
+
or_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
390
|
+
});
|
|
391
|
+
filterArrays_1.push({ $or: or_2 });
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
filterArrays_1.push((_e = {}, _e[filter.field.replace(/\.\$/g, '')] = (_f = {}, _f['$' + filter.condition] = filter.value, _f), _e));
|
|
395
|
+
}
|
|
368
396
|
}
|
|
369
|
-
filterArrays_1.push((_a = {}, _a[filter.field] = { '$gte': startDate }, _a));
|
|
370
|
-
filterArrays_1.push((_b = {}, _b[filter.field] = { '$lte': endDate }, _b));
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
filterArrays_1.push((_c = {}, _c[filter.field] = { '$gte': filter.value }, _c));
|
|
374
|
-
filterArrays_1.push((_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d));
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
if (Array.isArray(filter.value)) {
|
|
379
|
-
var or_2 = [];
|
|
380
|
-
filter.value.forEach(function (filt) {
|
|
381
|
-
var _a, _b;
|
|
382
|
-
or_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
|
|
383
|
-
});
|
|
384
|
-
filterArrays_1.push({ $or: or_2 });
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
filterArrays_1.push((_e = {}, _e[filter.field.replace(/\.\$/g, '')] = (_f = {}, _f['$' + filter.condition] = filter.value, _f), _e));
|
|
388
397
|
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
398
|
+
});
|
|
399
|
+
_this.callMethodInternal.call(_this, 'reportBuilderGetResults', report.type, report.collection_root, rootOptions_1, filters_1, filterArrays_1, filterArrayFields_1, report.fields_selected, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type, function (err, res) {
|
|
400
|
+
if (res && res[0]) {
|
|
401
|
+
var fields_1 = [];
|
|
402
|
+
var results_1 = res[0].results;
|
|
403
|
+
var reportTotals = res[0].totals;
|
|
404
|
+
if (report.type === 'Tabular') {
|
|
405
|
+
report.fields_selected.forEach(function (field) {
|
|
406
|
+
if (field.fieldType === 'Number' && field.leafFormatType === 'Number') {
|
|
407
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
408
|
+
result[field.id] = result[field.id].toLocaleString();
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
|
|
412
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
413
|
+
result[field.id] = result[field.id].toString();
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
|
|
417
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
418
|
+
result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
|
|
422
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
423
|
+
result[field.id] = result[field.id] === true ? 'Yes' : 'No';
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
|
|
427
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
428
|
+
result[field.id] = result[field.id] === true ? 'True' : 'False';
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
|
|
432
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
433
|
+
result[field.id] = result[field.id] === true ? 1 : 0;
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
|
|
437
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
438
|
+
result[field.id] = moment(result[field.id]).format('L');
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
|
|
442
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
443
|
+
result[field.id] = moment(result[field.id]).format('LT');
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
|
|
447
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
448
|
+
result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
|
|
452
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
453
|
+
result[field.id] = moment(result[field.id]).format('LL');
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
|
|
457
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
458
|
+
result[field.id] = moment(result[field.id]).format('LLL');
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
|
|
462
|
+
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
463
|
+
result[field.id] = moment(result[field.id]).toDate().getTime();
|
|
464
|
+
});
|
|
465
|
+
}
|
|
442
466
|
});
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
446
|
-
result[field.id] = moment(result[field.id]).format('LL');
|
|
467
|
+
report.groups_row.forEach(function (group) {
|
|
468
|
+
fields_1.push('_id.' + group.id);
|
|
447
469
|
});
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
|
|
451
|
-
result[field.id] = moment(result[field.id]).format('LLL');
|
|
470
|
+
report.fields_selected.forEach(function (selectedField) {
|
|
471
|
+
fields_1.push(selectedField.id);
|
|
452
472
|
});
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
473
|
+
var opts = { fields: fields_1 };
|
|
474
|
+
json2csv_1.parseAsync(results_1, opts)
|
|
475
|
+
.then(function (csv) {
|
|
476
|
+
var rows = csv.split(/(?:\r\n|\n)+/).filter(function (el) {
|
|
477
|
+
return el.length !== 0;
|
|
478
|
+
});
|
|
479
|
+
report.groups_row.forEach(function (group) {
|
|
480
|
+
rows[0] = rows[0].replace('_id.' + group.id, group.columnName);
|
|
481
|
+
});
|
|
482
|
+
report.fields_selected.forEach(function (selectedField) {
|
|
483
|
+
rows[0] = rows[0].replace(selectedField.id, selectedField.columnName);
|
|
484
|
+
});
|
|
485
|
+
var newCSV = '';
|
|
486
|
+
rows.forEach(function (row, index) {
|
|
487
|
+
newCSV += row;
|
|
488
|
+
if (index < rows.length - 1) {
|
|
489
|
+
newCSV += '\r\n';
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
data['emails'].forEach(function (email) {
|
|
493
|
+
_this.sendEmail(email, 'AAIMOS Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>AAIMOS Automated Report<b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tReport Name: " + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tPrepared By: " + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this report in a CSV formatted file.<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>", [
|
|
494
|
+
{
|
|
495
|
+
filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
|
|
496
|
+
content: newCSV
|
|
497
|
+
}
|
|
498
|
+
], _this.serverConfig['MAIL_FROM_REPORTS']);
|
|
499
|
+
});
|
|
500
|
+
})
|
|
501
|
+
.catch(function (errCSV) { return console.error(errCSV); });
|
|
502
|
+
}
|
|
503
|
+
else if (report.type === 'Dated') {
|
|
504
|
+
var lines_1 = [];
|
|
505
|
+
var tmpHeaders_1 = {};
|
|
506
|
+
report.groups_row.forEach(function (group) {
|
|
507
|
+
tmpHeaders_1[group.id] = group.columnName;
|
|
457
508
|
});
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
{
|
|
488
|
-
|
|
489
|
-
content: newCSV
|
|
509
|
+
tmpHeaders_1[''] = '';
|
|
510
|
+
var datedUniqueDates_1 = [];
|
|
511
|
+
var datedUniqueGroups_1 = [];
|
|
512
|
+
if (report.date_interval === 'Quarterly') {
|
|
513
|
+
results_1.forEach(function (dataPt) {
|
|
514
|
+
if (dataPt._id.month < 4) {
|
|
515
|
+
dataPt._id.quarter = 1;
|
|
516
|
+
}
|
|
517
|
+
else if (dataPt._id.month < 7) {
|
|
518
|
+
dataPt._id.quarter = 2;
|
|
519
|
+
}
|
|
520
|
+
else if (dataPt._id.month < 10) {
|
|
521
|
+
dataPt._id.quarter = 3;
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
dataPt._id.quarter = 4;
|
|
525
|
+
}
|
|
526
|
+
delete dataPt._id.month;
|
|
527
|
+
});
|
|
528
|
+
var _loop_1 = function (i) {
|
|
529
|
+
var dataPt = results_1[i];
|
|
530
|
+
if (results_1.filter(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); }).length > 1) {
|
|
531
|
+
var tmpData_1 = results_1.filter(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); })[0];
|
|
532
|
+
Object.keys(tmpData_1).filter(function (a) { return a !== '_id'; }).forEach(function (key) {
|
|
533
|
+
tmpData_1[key] += dataPt[key];
|
|
534
|
+
});
|
|
535
|
+
results_1.splice(i, 1);
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
for (var i = results_1.length - 1; i >= 1; i--) {
|
|
539
|
+
_loop_1(i);
|
|
490
540
|
}
|
|
491
|
-
], _this.serverConfig['MAIL_FROM_REPORTS']);
|
|
492
|
-
});
|
|
493
|
-
})
|
|
494
|
-
.catch(function (errCSV) { return console.error(errCSV); });
|
|
495
|
-
}
|
|
496
|
-
else if (report.type === 'Dated') {
|
|
497
|
-
var lines_1 = [];
|
|
498
|
-
var tmpHeaders_1 = {};
|
|
499
|
-
report.groups_row.forEach(function (group) {
|
|
500
|
-
tmpHeaders_1[group.id] = group.columnName;
|
|
501
|
-
});
|
|
502
|
-
tmpHeaders_1[''] = '';
|
|
503
|
-
var datedUniqueDates_1 = [];
|
|
504
|
-
var datedUniqueGroups_1 = [];
|
|
505
|
-
if (report.date_interval === 'Quarterly') {
|
|
506
|
-
results_1.forEach(function (dataPt) {
|
|
507
|
-
if (dataPt._id.month < 4) {
|
|
508
|
-
dataPt._id.quarter = 1;
|
|
509
|
-
}
|
|
510
|
-
else if (dataPt._id.month < 7) {
|
|
511
|
-
dataPt._id.quarter = 2;
|
|
512
|
-
}
|
|
513
|
-
else if (dataPt._id.month < 10) {
|
|
514
|
-
dataPt._id.quarter = 3;
|
|
515
|
-
}
|
|
516
|
-
else {
|
|
517
|
-
dataPt._id.quarter = 4;
|
|
518
541
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
542
|
+
var tmpResults = common_1.deepCopy(results_1);
|
|
543
|
+
tmpResults.forEach(function (result) {
|
|
544
|
+
delete result._id.day;
|
|
545
|
+
delete result._id.week;
|
|
546
|
+
delete result._id.month;
|
|
547
|
+
delete result._id.quarter;
|
|
548
|
+
delete result._id.year;
|
|
549
|
+
var tmp = {};
|
|
550
|
+
Object.keys(result._id).forEach(function (key) {
|
|
551
|
+
tmp[key] = result._id[key];
|
|
527
552
|
});
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
553
|
+
if (!datedUniqueGroups_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(tmp); }).length) {
|
|
554
|
+
datedUniqueGroups_1.push(tmp);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
tmpResults = common_1.deepCopy(results_1);
|
|
558
|
+
tmpResults.forEach(function (result) {
|
|
559
|
+
Object.keys(result._id).filter(function (a) { return a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
|
|
560
|
+
delete result._id[key];
|
|
561
|
+
});
|
|
562
|
+
var tmp = {};
|
|
563
|
+
Object.keys(result._id).forEach(function (key) {
|
|
564
|
+
tmp[key] = result._id[key];
|
|
565
|
+
});
|
|
566
|
+
if (!datedUniqueDates_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(tmp); }).length) {
|
|
567
|
+
datedUniqueDates_1.push(tmp);
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
datedUniqueDates_1.forEach(function (result) {
|
|
571
|
+
if (!result.year) {
|
|
572
|
+
result.dateString = 'No Date';
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
if (report.date_interval === 'Daily') {
|
|
576
|
+
result.date = new Date(result.year, result.month, result.day, 0, 0, 0, 0);
|
|
577
|
+
result.dateString = moment(result.date).format('MMM DD YYYY');
|
|
578
|
+
}
|
|
579
|
+
else if (report.date_interval === 'Weekly') {
|
|
580
|
+
result.date = moment().day('Sunday').week(result.week + 1).toDate();
|
|
581
|
+
result.dateLast = moment().day('Saturday').week(result.week + 1).toDate();
|
|
582
|
+
result.dateString = 'Week #' + (result.week + 1) + ' ' + result.year + '(' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';
|
|
583
|
+
}
|
|
584
|
+
else if (report.date_interval === 'Monthly') {
|
|
585
|
+
result.date = new Date(result.year, result.month, 0, 0, 0, 0, 0);
|
|
586
|
+
result.dateString = moment(result.date).format('MMM YYYY');
|
|
587
|
+
}
|
|
588
|
+
else if (report.date_interval === 'Quarterly') {
|
|
589
|
+
result.date = moment().quarter(result.quarter).year(result.year).toDate();
|
|
590
|
+
result.dateString = 'Q' + result.quarter + ' ' + result.year;
|
|
591
|
+
}
|
|
592
|
+
else if (report.date_interval === 'Yearly') {
|
|
593
|
+
result.date = new Date(result.year);
|
|
594
|
+
result.dateString = result.year.toString();
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
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(); }));
|
|
599
|
+
var reportTotalGroups_1 = [];
|
|
600
|
+
var reportTotalDates_1 = [];
|
|
601
|
+
var datedData_1 = [];
|
|
602
|
+
datedUniqueDates_1.forEach(function (date) {
|
|
603
|
+
var tmpData = [];
|
|
604
|
+
var tmpTotalDated = {};
|
|
605
|
+
var tmpTotalCnt = {};
|
|
606
|
+
var tmpTotalType = {};
|
|
607
|
+
datedUniqueGroups_1.forEach(function (group) {
|
|
608
|
+
var result = results_1.filter(function (a) {
|
|
609
|
+
var res = true;
|
|
610
|
+
Object.keys(date).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString'; }).forEach(function (key) {
|
|
611
|
+
if (a._id[key] !== date[key]) {
|
|
612
|
+
res = false;
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
Object.keys(group).forEach(function (key) {
|
|
616
|
+
if (a._id[key] !== group[key]) {
|
|
617
|
+
res = false;
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
return res;
|
|
621
|
+
})[0];
|
|
622
|
+
if (result) {
|
|
623
|
+
tmpData.push(result);
|
|
624
|
+
Object.keys(result._id).filter(function (a) { return a; }).forEach(function (key) {
|
|
625
|
+
if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
|
|
626
|
+
if (!tmpTotalDated[key]) {
|
|
627
|
+
tmpTotalDated[key] = result._id[key];
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
tmpTotalDated[key] += result._id[key];
|
|
631
|
+
}
|
|
632
|
+
if (!tmpTotalCnt[key]) {
|
|
633
|
+
tmpTotalCnt[key] = 1;
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
tmpTotalCnt[key] += 1;
|
|
637
|
+
}
|
|
638
|
+
tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
Object.keys(result).filter(function (a) { return a && a !== '_id'; }).forEach(function (key) {
|
|
642
|
+
if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
|
|
643
|
+
if (!tmpTotalDated[key]) {
|
|
644
|
+
tmpTotalDated[key] = result[key];
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
tmpTotalDated[key] += result[key];
|
|
648
|
+
}
|
|
649
|
+
if (!tmpTotalCnt[key]) {
|
|
650
|
+
tmpTotalCnt[key] = 1;
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
tmpTotalCnt[key] += 1;
|
|
654
|
+
}
|
|
655
|
+
tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
tmpData.push(null);
|
|
606
661
|
}
|
|
607
662
|
});
|
|
608
|
-
Object.keys(
|
|
609
|
-
if (
|
|
610
|
-
|
|
663
|
+
Object.keys(tmpTotalType).forEach(function (totalKey) {
|
|
664
|
+
if (tmpTotalType[totalKey] === 'avg') {
|
|
665
|
+
tmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];
|
|
611
666
|
}
|
|
667
|
+
tmpTotalDated[totalKey] = Math.round(tmpTotalDated[totalKey] * 100) / 100;
|
|
668
|
+
});
|
|
669
|
+
reportTotalDates_1.push(tmpTotalDated);
|
|
670
|
+
datedData_1.push(tmpData);
|
|
671
|
+
});
|
|
672
|
+
datedUniqueGroups_1.forEach(function (group) {
|
|
673
|
+
var tmpTotalGroup = {};
|
|
674
|
+
var filteredData = results_1.filter(function (a) {
|
|
675
|
+
var res = true;
|
|
676
|
+
Object.keys(group).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
|
|
677
|
+
if (a._id[key] !== group[key]) {
|
|
678
|
+
res = false;
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
return res;
|
|
612
682
|
});
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
683
|
+
report.fields_total.forEach(function (total) {
|
|
684
|
+
total.fields.forEach(function (field) {
|
|
685
|
+
if (filteredData.length) {
|
|
686
|
+
if (!tmpTotalGroup[field]) {
|
|
687
|
+
tmpTotalGroup[field] = filteredData.filter(function (a) { return a && a[field]; }).map(function (a) { return a[field]; }).reduce(function (a, b) { return a + b; }, 0);
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
tmpTotalGroup[field] += filteredData.filter(function (a) { return a && a[field]; }).map(function (a) { return a[field]; }).reduce(function (a, b) { return a + b; }, 0);
|
|
691
|
+
}
|
|
692
|
+
if (total.type === 'avg') {
|
|
693
|
+
tmpTotalGroup[field] = Math.round(tmpTotalGroup[field] / filteredData.length * 100) / 100;
|
|
694
|
+
}
|
|
621
695
|
}
|
|
622
696
|
else {
|
|
623
|
-
|
|
697
|
+
tmpTotalGroup[field] = 0;
|
|
624
698
|
}
|
|
625
|
-
|
|
626
|
-
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
reportTotalGroups_1.push(tmpTotalGroup);
|
|
702
|
+
});
|
|
703
|
+
datedUniqueDates_1.forEach(function (date) {
|
|
704
|
+
tmpHeaders_1[date.dateString] = date.dateString;
|
|
705
|
+
});
|
|
706
|
+
tmpHeaders_1['Totals'] = 'Totals';
|
|
707
|
+
lines_1.push(tmpHeaders_1);
|
|
708
|
+
for (var i = 0; i <= datedUniqueGroups_1.length - 1; i++) {
|
|
709
|
+
var group = datedUniqueGroups_1[i];
|
|
710
|
+
for (var j = 0; j <= report.fields_selected.length - 1; j++) {
|
|
711
|
+
var field = report.fields_selected[j];
|
|
712
|
+
var tmp = {};
|
|
713
|
+
for (var k = 0; k <= report.groups_row.length - 1; k++) {
|
|
714
|
+
var groupRow = report.groups_row[k];
|
|
715
|
+
if (j === 0) {
|
|
716
|
+
tmp[group[groupRow.id]] = group[groupRow.id];
|
|
627
717
|
}
|
|
628
718
|
else {
|
|
629
|
-
|
|
719
|
+
tmp[group[groupRow.id]] = '';
|
|
630
720
|
}
|
|
631
|
-
tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
|
|
632
721
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (
|
|
637
|
-
|
|
722
|
+
tmp[field.columnName] = field.columnName;
|
|
723
|
+
for (var k = 0; k <= datedData_1.length - 1; k++) {
|
|
724
|
+
var result = datedData_1[k];
|
|
725
|
+
if (result[i]) {
|
|
726
|
+
tmp[i + ' ' + j + ' ' + k] = result[i][field.id];
|
|
638
727
|
}
|
|
639
728
|
else {
|
|
640
|
-
|
|
729
|
+
tmp[i + ' ' + j + ' ' + k] = '';
|
|
641
730
|
}
|
|
642
|
-
|
|
643
|
-
|
|
731
|
+
}
|
|
732
|
+
for (var k = 0; k <= report.fields_total.length - 1; k++) {
|
|
733
|
+
var total = report.fields_total[k];
|
|
734
|
+
if (total.fields.includes(field.id)) {
|
|
735
|
+
tmp['total' + i + ' ' + j + ' ' + k] = reportTotalGroups_1[i][field.id];
|
|
644
736
|
}
|
|
645
737
|
else {
|
|
646
|
-
|
|
738
|
+
tmp['total' + i + ' ' + j + ' ' + k] = '';
|
|
647
739
|
}
|
|
648
|
-
tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
|
|
649
740
|
}
|
|
650
|
-
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
tmpData.push(null);
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
Object.keys(tmpTotalType).forEach(function (totalKey) {
|
|
657
|
-
if (tmpTotalType[totalKey] === 'avg') {
|
|
658
|
-
tmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];
|
|
659
|
-
}
|
|
660
|
-
tmpTotalDated[totalKey] = Math.round(tmpTotalDated[totalKey] * 100) / 100;
|
|
661
|
-
});
|
|
662
|
-
reportTotalDates_1.push(tmpTotalDated);
|
|
663
|
-
datedData_1.push(tmpData);
|
|
664
|
-
});
|
|
665
|
-
datedUniqueGroups_1.forEach(function (group) {
|
|
666
|
-
var tmpTotalGroup = {};
|
|
667
|
-
var filteredData = results_1.filter(function (a) {
|
|
668
|
-
var res = true;
|
|
669
|
-
Object.keys(group).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
|
|
670
|
-
if (a._id[key] !== group[key]) {
|
|
671
|
-
res = false;
|
|
741
|
+
lines_1.push(tmp);
|
|
672
742
|
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
743
|
+
}
|
|
744
|
+
if (reportTotals) {
|
|
745
|
+
for (var j = 0; j <= report.fields_selected.length - 1; j++) {
|
|
746
|
+
var field = report.fields_selected[j];
|
|
747
|
+
var tmp = {};
|
|
748
|
+
for (var k = 0; k <= report.groups_row.length - 1; k++) {
|
|
749
|
+
var groupRow = report.groups_row[k];
|
|
750
|
+
for (var l = 0; l <= report.fields_total.length - 1; l++) {
|
|
751
|
+
var total = report.fields_total[l];
|
|
752
|
+
if (j === 0) {
|
|
753
|
+
tmp[total.type + k] = total.type + ' TOTALS';
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
tmp[total.type + k] = '';
|
|
757
|
+
}
|
|
758
|
+
}
|
|
684
759
|
}
|
|
685
|
-
|
|
686
|
-
|
|
760
|
+
tmp[field.columnName] = field.columnName;
|
|
761
|
+
for (var k = 0; k <= datedData_1.length - 1; k++) {
|
|
762
|
+
var result = datedData_1[k];
|
|
763
|
+
for (var l = 0; l <= report.fields_total.length - 1; l++) {
|
|
764
|
+
var total = report.fields_total[l];
|
|
765
|
+
if (total.fields.includes(field.id)) {
|
|
766
|
+
tmp['total' + j + ' ' + k + ' ' + l] = reportTotalDates_1[k][field.id];
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
tmp['total' + j + ' ' + k + ' ' + l] = '';
|
|
770
|
+
}
|
|
771
|
+
}
|
|
687
772
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
datedUniqueDates_1.forEach(function (date) {
|
|
697
|
-
tmpHeaders_1[date.dateString] = date.dateString;
|
|
698
|
-
});
|
|
699
|
-
tmpHeaders_1['Totals'] = 'Totals';
|
|
700
|
-
lines_1.push(tmpHeaders_1);
|
|
701
|
-
for (var i = 0; i <= datedUniqueGroups_1.length - 1; i++) {
|
|
702
|
-
var group = datedUniqueGroups_1[i];
|
|
703
|
-
for (var j = 0; j <= report.fields_selected.length - 1; j++) {
|
|
704
|
-
var field = report.fields_selected[j];
|
|
705
|
-
var tmp = {};
|
|
706
|
-
for (var k = 0; k <= report.groups_row.length - 1; k++) {
|
|
707
|
-
var groupRow = report.groups_row[k];
|
|
708
|
-
if (j === 0) {
|
|
709
|
-
tmp[group[groupRow.id]] = group[groupRow.id];
|
|
710
|
-
}
|
|
711
|
-
else {
|
|
712
|
-
tmp[group[groupRow.id]] = '';
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
tmp[field.columnName] = field.columnName;
|
|
716
|
-
for (var k = 0; k <= datedData_1.length - 1; k++) {
|
|
717
|
-
var result = datedData_1[k];
|
|
718
|
-
if (result[i]) {
|
|
719
|
-
tmp[i + ' ' + j + ' ' + k] = result[i][field.id];
|
|
720
|
-
}
|
|
721
|
-
else {
|
|
722
|
-
tmp[i + ' ' + j + ' ' + k] = '';
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
for (var k = 0; k <= report.fields_total.length - 1; k++) {
|
|
726
|
-
var total = report.fields_total[k];
|
|
727
|
-
if (total.fields.includes(field.id)) {
|
|
728
|
-
tmp['total' + i + ' ' + j + ' ' + k] = reportTotalGroups_1[i][field.id];
|
|
729
|
-
}
|
|
730
|
-
else {
|
|
731
|
-
tmp['total' + i + ' ' + j + ' ' + k] = '';
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
lines_1.push(tmp);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if (reportTotals) {
|
|
738
|
-
for (var j = 0; j <= report.fields_selected.length - 1; j++) {
|
|
739
|
-
var field = report.fields_selected[j];
|
|
740
|
-
var tmp = {};
|
|
741
|
-
for (var k = 0; k <= report.groups_row.length - 1; k++) {
|
|
742
|
-
var groupRow = report.groups_row[k];
|
|
743
|
-
for (var l = 0; l <= report.fields_total.length - 1; l++) {
|
|
744
|
-
var total = report.fields_total[l];
|
|
745
|
-
if (j === 0) {
|
|
746
|
-
tmp[total.type + k] = total.type + ' TOTALS';
|
|
773
|
+
for (var k = 0; k <= report.groups_row.length - 1; k++) {
|
|
774
|
+
var groupRow = report.groups_row[k];
|
|
775
|
+
for (var l = 0; l <= report.fields_total.length - 1; l++) {
|
|
776
|
+
var total = report.fields_total[l];
|
|
777
|
+
if (total.fields.includes(groupRow.id)) {
|
|
778
|
+
tmp['totalreportTotals' + j + ' ' + k + ' ' + l] = reportTotals[total.id + groupRow.id];
|
|
779
|
+
}
|
|
780
|
+
}
|
|
747
781
|
}
|
|
748
|
-
|
|
749
|
-
|
|
782
|
+
for (var l = 0; l <= report.fields_total.length - 1; l++) {
|
|
783
|
+
var total = report.fields_total[l];
|
|
784
|
+
if (total.fields.includes(field.id)) {
|
|
785
|
+
tmp['totalreportTotals' + j + ' ' + l] = reportTotals[total.id + '_' + field.id];
|
|
786
|
+
}
|
|
750
787
|
}
|
|
788
|
+
lines_1.push(tmp);
|
|
751
789
|
}
|
|
752
790
|
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
if (total.fields.includes(field.id)) {
|
|
759
|
-
tmp['total' + j + ' ' + k + ' ' + l] = reportTotalDates_1[k][field.id];
|
|
791
|
+
var newCSV_1 = '';
|
|
792
|
+
lines_1.forEach(function (row, index) {
|
|
793
|
+
Object.keys(row).forEach(function (key, keyIndex) {
|
|
794
|
+
if (row[key] && typeof (row[key]) === 'string') {
|
|
795
|
+
row[key] = row[key].replace(new RegExp(/,/g), '');
|
|
760
796
|
}
|
|
761
|
-
|
|
762
|
-
|
|
797
|
+
newCSV_1 += row[key];
|
|
798
|
+
if (keyIndex < Object.keys(row).length - 1) {
|
|
799
|
+
newCSV_1 += ',';
|
|
763
800
|
}
|
|
801
|
+
});
|
|
802
|
+
if (index < lines_1.length - 1) {
|
|
803
|
+
newCSV_1 += '\r\n';
|
|
764
804
|
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
tmp['totalreportTotals' + j + ' ' + k + ' ' + l] = reportTotals[total.id + groupRow.id];
|
|
805
|
+
});
|
|
806
|
+
data['emails'].forEach(function (email) {
|
|
807
|
+
_this.sendEmail(email, 'AAIMOS Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t<b>AAIMOS Automated Report<b><br>\n\t\t\t\t\t\t\t\t\t\t\t\tReport Name: " + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\tPrepared By: " + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this report in a CSV formatted file.<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>", [
|
|
808
|
+
{
|
|
809
|
+
filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
|
|
810
|
+
content: newCSV_1
|
|
772
811
|
}
|
|
773
|
-
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
var total = report.fields_total[l];
|
|
777
|
-
if (total.fields.includes(field.id)) {
|
|
778
|
-
tmp['totalreportTotals' + j + ' ' + l] = reportTotals[total.id + '_' + field.id];
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
lines_1.push(tmp);
|
|
812
|
+
], _this.serverConfig['MAIL_FROM_REPORTS']);
|
|
813
|
+
});
|
|
814
|
+
resolve();
|
|
782
815
|
}
|
|
783
816
|
}
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
newCSV_1 += ',';
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
if (index < lines_1.length - 1) {
|
|
796
|
-
newCSV_1 += '\r\n';
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
data['emails'].forEach(function (email) {
|
|
800
|
-
_this.sendEmail(email, 'AAIMOS Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t<b>AAIMOS Automated Report<b><br>\n\t\t\t\t\t\t\t\t\t\tReport Name: " + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\tPrepared By: " + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\tAttached are the results of this report in a CSV formatted file.<br><br>\n\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\tResolveIO<br><br>", [
|
|
801
|
-
{
|
|
802
|
-
filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
|
|
803
|
-
content: newCSV_1
|
|
804
|
-
}
|
|
805
|
-
], _this.serverConfig['MAIL_FROM_REPORTS']);
|
|
806
|
-
});
|
|
807
|
-
resolve();
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
811
|
-
console.log(res);
|
|
812
|
-
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [
|
|
813
|
-
err
|
|
814
|
-
]);
|
|
815
|
-
reject(err);
|
|
817
|
+
else {
|
|
818
|
+
console.log(res);
|
|
819
|
+
_this.callMethodInternal.call(_this, 'insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [
|
|
820
|
+
err
|
|
821
|
+
]);
|
|
822
|
+
reject(err);
|
|
823
|
+
}
|
|
824
|
+
});
|
|
816
825
|
}
|
|
817
826
|
});
|
|
818
827
|
}
|
|
@@ -825,3 +834,16 @@ function loadCronJobMethods(methodManager) {
|
|
|
825
834
|
});
|
|
826
835
|
}
|
|
827
836
|
exports.loadCronJobMethods = loadCronJobMethods;
|
|
837
|
+
function getTreeLeaves(items, resArray, allowLookups) {
|
|
838
|
+
if (allowLookups === void 0) { allowLookups = false; }
|
|
839
|
+
items.forEach(function (item) {
|
|
840
|
+
if (item.isLeaf) {
|
|
841
|
+
resArray.push(item);
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
if (!item.lookup_collection || allowLookups) {
|
|
845
|
+
getTreeLeaves(item.children, resArray, allowLookups);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
}
|