@resolveio/server-lib 5.2.71 → 5.3.0

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.
@@ -42,7 +42,8 @@ var simpl_schema_1 = require("simpl-schema");
42
42
  var mongoose_1 = require("mongoose");
43
43
  var common_1 = require("../util/common");
44
44
  var moment = require("moment");
45
- var json2csv_1 = require("json2csv");
45
+ var XLSX = require("xlsx");
46
+ var Excel = require("exceljs");
46
47
  function loadCronJobMethods(methodManager) {
47
48
  methodManager.methods({
48
49
  methodQueue: {
@@ -180,7 +181,7 @@ function loadCronJobMethods(methodManager) {
180
181
  sortObj_1 = {};
181
182
  if (report.fields_sort.length) {
182
183
  report.fields_sort.forEach(function (sortField) {
183
- if (sortField.field.startsWith('gr_') && (report.type === 'Tabular' || report.type === 'Dated')) {
184
+ if (sortField.field.startsWith('gr_')) {
184
185
  sortObj_1['_id.' + sortField.field] = (sortField.order === 'asc' ? 1 : -1);
185
186
  }
186
187
  else {
@@ -199,8 +200,8 @@ function loadCronJobMethods(methodManager) {
199
200
  };
200
201
  filters_1 = [];
201
202
  report.fields_filter.filter(function (a) { return !a.field.includes('.$.'); }).forEach(function (filter) {
202
- var _a, _b, _c, _d, _e, _f;
203
- if (filter.condition && filter.field && filter.value !== null) {
203
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
204
+ if (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {
204
205
  if (filter.condition === 'bw') {
205
206
  if (filter.fieldType === 'Date' && filter.is_rolling) {
206
207
  var startDate = null;
@@ -272,22 +273,40 @@ function loadCronJobMethods(methodManager) {
272
273
  filters_1.push((_a = {}, _a[filter.field] = { '$gte': startDate }, _a));
273
274
  filters_1.push((_b = {}, _b[filter.field] = { '$lte': endDate }, _b));
274
275
  }
275
- else {
276
+ else if (filter.fieldType === 'Date') {
276
277
  filters_1.push((_c = {}, _c[filter.field] = { '$gte': filter.value }, _c));
277
278
  filters_1.push((_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d));
278
279
  }
279
280
  }
281
+ else if (filter.condition === 'nnull') {
282
+ filters_1.push((_e = {}, _e[filter.field] = { '$exists': true }, _e));
283
+ filters_1.push((_f = {}, _f[filter.field] = { '$ne': null }, _f));
284
+ if (filter.fieldType === 'String') {
285
+ filters_1.push((_g = {}, _g[filter.field] = { '$ne': '' }, _g));
286
+ }
287
+ }
288
+ else if (filter.condition === 'null') {
289
+ filters_1.push((_h = {}, _h[filter.field] = { '$eq': null }, _h));
290
+ }
280
291
  else {
281
292
  if (Array.isArray(filter.value)) {
282
- var or_1 = [];
283
- filter.value.forEach(function (filt) {
284
- var _a, _b;
285
- or_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
286
- });
287
- filters_1.push({ $or: or_1 });
293
+ if (filter.condition === 'ne') {
294
+ filter.value.forEach(function (filt) {
295
+ var _a, _b;
296
+ filters_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
297
+ });
298
+ }
299
+ else {
300
+ var or_1 = [];
301
+ filter.value.forEach(function (filt) {
302
+ var _a, _b;
303
+ or_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
304
+ });
305
+ filters_1.push({ $or: or_1 });
306
+ }
288
307
  }
289
308
  else {
290
- filters_1.push((_e = {}, _e[filter.field] = (_f = {}, _f['$' + filter.condition] = filter.value, _f), _e));
309
+ filters_1.push((_j = {}, _j[filter.field] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
291
310
  }
292
311
  }
293
312
  }
@@ -398,115 +417,189 @@ function loadCronJobMethods(methodManager) {
398
417
  });
399
418
  _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
419
  if (res && res[0]) {
401
- var fields_1 = [];
420
+ var fields = [];
402
421
  var results_1 = res[0].results;
403
422
  var reportTotals = res[0].totals;
404
423
  if (report.type === 'Tabular') {
405
424
  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) {
425
+ if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
426
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
408
427
  result[field.id] = result[field.id].toLocaleString();
409
428
  });
410
429
  }
411
430
  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();
431
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
432
+ result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
414
433
  });
415
434
  }
416
435
  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) {
436
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
418
437
  result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
419
438
  });
420
439
  }
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
440
  else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
427
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
441
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
428
442
  result[field.id] = result[field.id] === true ? 'True' : 'False';
429
443
  });
430
444
  }
445
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
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] === true ? 'Yes' : 'No';
448
+ });
449
+ }
431
450
  else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
432
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
451
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
433
452
  result[field.id] = result[field.id] === true ? 1 : 0;
434
453
  });
435
454
  }
436
455
  else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
437
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
456
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
438
457
  result[field.id] = moment(result[field.id]).format('L');
439
458
  });
440
459
  }
441
460
  else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
442
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
461
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
443
462
  result[field.id] = moment(result[field.id]).format('LT');
444
463
  });
445
464
  }
446
465
  else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
447
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
466
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
448
467
  result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
449
468
  });
450
469
  }
451
470
  else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
452
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
471
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
453
472
  result[field.id] = moment(result[field.id]).format('LL');
454
473
  });
455
474
  }
456
475
  else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
457
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
476
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
458
477
  result[field.id] = moment(result[field.id]).format('LLL');
459
478
  });
460
479
  }
461
480
  else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
462
- results_1.filter(function (a) { return a[field.id] !== null; }).forEach(function (result) {
481
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
463
482
  result[field.id] = moment(result[field.id]).toDate().getTime();
464
483
  });
465
484
  }
466
485
  });
486
+ var lines_1 = [];
487
+ var tmpHeaders_1 = {};
467
488
  report.groups_row.forEach(function (group) {
468
- fields_1.push('_id.' + group.id);
489
+ tmpHeaders_1[group.id] = group.columnName;
469
490
  });
470
- report.fields_selected.forEach(function (selectedField) {
471
- fields_1.push(selectedField.id);
491
+ report.fields_selected.forEach(function (header) {
492
+ tmpHeaders_1[header.columnName] = header.columnName;
472
493
  });
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
- });
494
+ var wb = XLSX.utils.book_new();
495
+ results_1.forEach(function (result) {
496
+ var tmp = {};
479
497
  report.groups_row.forEach(function (group) {
480
- rows[0] = rows[0].replace('_id.' + group.id, group.columnName);
498
+ if (Array.isArray(result._id[group.id])) {
499
+ tmp[group.columnName] = result._id[group.id].join(',');
500
+ }
501
+ else {
502
+ if (group.treeItem.fieldType === 'Number') {
503
+ 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]) : '';
504
+ }
505
+ else {
506
+ tmp[group.columnName] = result._id[group.id] || '';
507
+ }
508
+ }
481
509
  });
482
- report.fields_selected.forEach(function (selectedField) {
483
- rows[0] = rows[0].replace(selectedField.id, selectedField.columnName);
510
+ report.fields_selected.forEach(function (header) {
511
+ if (Array.isArray(result[header.id])) {
512
+ tmp[header.columnName] = result[header.id].join(',');
513
+ }
514
+ else {
515
+ if (header.fieldType === 'Number' || header.leafValueType === 'Count') {
516
+ tmp[header.columnName] = result[header.id] ? (typeof (result[header.id]) === 'string' ? parseFloat(result[header.id].replace(/,/g, '').replace(/\$/g, '')) : result[header.id]) : '';
517
+ }
518
+ else {
519
+ tmp[header.columnName] = result[header.id] || '';
520
+ }
521
+ }
484
522
  });
485
- var newCSV = '';
486
- rows.forEach(function (row, index) {
487
- newCSV += row;
488
- if (index < rows.length - 1) {
489
- newCSV += '\r\n';
523
+ lines_1.push(tmp);
524
+ });
525
+ var ws = XLSX.utils.json_to_sheet(lines_1);
526
+ XLSX.utils.book_append_sheet(wb, ws, 'RB Data');
527
+ var wbout_1 = XLSX.write(wb, { bookType: 'xlsx', type: 'binary' });
528
+ data['emails'].forEach(function (email) {
529
+ _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>", [
530
+ {
531
+ filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
532
+ content: wbout_1,
533
+ contentType: 'application/octet/stream'
490
534
  }
535
+ ], _this.serverConfig['MAIL_FROM_REPORTS']);
536
+ });
537
+ }
538
+ else if (report.type === 'Tabular Group') {
539
+ report.fields_selected.forEach(function (field) {
540
+ results_1.forEach(function (result) {
541
+ modifyDataTypeField(report, result, field, 1);
491
542
  });
543
+ });
544
+ var wb = new Excel.Workbook();
545
+ var ws_1 = wb.addWorksheet('RB_1', { views: [{ showGridLines: false }] });
546
+ wb.properties.date1904 = false;
547
+ wb.calcProperties.fullCalcOnLoad = true;
548
+ var currentRow_1 = 1;
549
+ var row = ws_1.getRow(currentRow_1);
550
+ row.getCell(2).font = {
551
+ name: 'Arial',
552
+ bold: true,
553
+ size: 14
554
+ };
555
+ row.getCell(4).font = {
556
+ name: 'Arial',
557
+ size: 14
558
+ };
559
+ row.getCell(2).value = 'Report Name:';
560
+ row.getCell(4).value = report.report_name;
561
+ currentRow_1 += 1;
562
+ row = ws_1.getRow(currentRow_1);
563
+ row.getCell(2).font = {
564
+ name: 'Arial',
565
+ bold: true,
566
+ size: 14
567
+ };
568
+ row.getCell(4).font = {
569
+ name: 'Arial',
570
+ size: 14
571
+ };
572
+ row.getCell(2).value = 'Run Date:';
573
+ row.getCell(4).value = moment().format('LLL');
574
+ currentRow_1 += 2;
575
+ var copy = common_1.deepCopy(results_1);
576
+ var widths_1 = [];
577
+ copy.forEach(function (res) {
578
+ currentRow_1 = tabGroupExcelRecursive(report, ws_1, currentRow_1, 1, res);
579
+ tabGroupExcelWidthRecursive(report, 1, res, widths_1);
580
+ });
581
+ for (var i = 1; i < ws_1.columns.length; i++) {
582
+ ws_1.columns[i].width = widths_1[i - 1];
583
+ }
584
+ var now_1 = new Date();
585
+ wb.xlsx.writeBuffer().then(function (buffer) {
492
586
  data['emails'].forEach(function (email) {
493
587
  _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
588
  {
495
- filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
496
- content: newCSV
589
+ filename: 'Tabular_Group_Report_' + report.report_name + '_' + now_1.getFullYear() + '_' + (now_1.getMonth() + 1) + '_' + now_1.getDate() + '.xlsx',
590
+ content: buffer
497
591
  }
498
592
  ], _this.serverConfig['MAIL_FROM_REPORTS']);
499
593
  });
500
- })
501
- .catch(function (errCSV) { return console.error(errCSV); });
594
+ }).catch(function (err) { return console.log('Error writing excel export', err); });
502
595
  }
503
596
  else if (report.type === 'Dated') {
504
- var lines_1 = [];
505
- var tmpHeaders_1 = {};
597
+ var lines_2 = [];
598
+ var tmpHeaders_2 = {};
506
599
  report.groups_row.forEach(function (group) {
507
- tmpHeaders_1[group.id] = group.columnName;
600
+ tmpHeaders_2[group.id] = group.columnName;
508
601
  });
509
- tmpHeaders_1[''] = '';
602
+ tmpHeaders_2[''] = '';
510
603
  var datedUniqueDates_1 = [];
511
604
  var datedUniqueGroups_1 = [];
512
605
  if (report.date_interval === 'Quarterly') {
@@ -573,16 +666,16 @@ function loadCronJobMethods(methodManager) {
573
666
  }
574
667
  else {
575
668
  if (report.date_interval === 'Daily') {
576
- result.date = new Date(result.year, result.month, result.day, 0, 0, 0, 0);
669
+ result.date = new Date(result.year, result.month - 1, result.day, 0, 0, 0, 0);
577
670
  result.dateString = moment(result.date).format('MMM DD YYYY');
578
671
  }
579
672
  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') + ')';
673
+ result.date = moment().day('Monday').isoWeekYear(result.year).isoWeek(result.week).toDate();
674
+ result.dateLast = moment().day('Sunday').isoWeekYear(result.year).isoWeek(result.week).toDate();
675
+ result.dateString = 'Week #' + result.week + ' ' + result.year + '(' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';
583
676
  }
584
677
  else if (report.date_interval === 'Monthly') {
585
- result.date = new Date(result.year, result.month, 0, 0, 0, 0, 0);
678
+ result.date = new Date(result.year, result.month - 1, 1, 0, 0, 0, 0);
586
679
  result.dateString = moment(result.date).format('MMM YYYY');
587
680
  }
588
681
  else if (report.date_interval === 'Quarterly') {
@@ -672,7 +765,7 @@ function loadCronJobMethods(methodManager) {
672
765
  datedUniqueGroups_1.forEach(function (group) {
673
766
  var tmpTotalGroup = {};
674
767
  var filteredData = results_1.filter(function (a) {
675
- var res = true;
768
+ var res = (!Object.keys(group).length || group._id === null) ? false : true;
676
769
  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
770
  if (a._id[key] !== group[key]) {
678
771
  res = false;
@@ -683,12 +776,7 @@ function loadCronJobMethods(methodManager) {
683
776
  report.fields_total.forEach(function (total) {
684
777
  total.fields.forEach(function (field) {
685
778
  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
- }
779
+ tmpTotalGroup[field] = filteredData.filter(function (a) { return a && a[field]; }).map(function (a) { return a[field]; }).reduce(function (a, b) { return a + b; }, 0);
692
780
  if (total.type === 'avg') {
693
781
  tmpTotalGroup[field] = Math.round(tmpTotalGroup[field] / filteredData.length * 100) / 100;
694
782
  }
@@ -701,13 +789,13 @@ function loadCronJobMethods(methodManager) {
701
789
  reportTotalGroups_1.push(tmpTotalGroup);
702
790
  });
703
791
  datedUniqueDates_1.forEach(function (date) {
704
- tmpHeaders_1[date.dateString] = date.dateString;
792
+ tmpHeaders_2[date.dateString] = date.dateString;
705
793
  });
706
- tmpHeaders_1['Totals'] = 'Totals';
707
- lines_1.push(tmpHeaders_1);
794
+ tmpHeaders_2['Totals'] = 'Totals';
795
+ lines_2.push(tmpHeaders_2);
708
796
  for (var i = 0; i <= datedUniqueGroups_1.length - 1; i++) {
709
797
  var group = datedUniqueGroups_1[i];
710
- for (var j = 0; j <= report.fields_selected.length - 1; j++) {
798
+ var _loop_2 = function (j) {
711
799
  var field = report.fields_selected[j];
712
800
  var tmp = {};
713
801
  for (var k = 0; k <= report.groups_row.length - 1; k++) {
@@ -723,7 +811,12 @@ function loadCronJobMethods(methodManager) {
723
811
  for (var k = 0; k <= datedData_1.length - 1; k++) {
724
812
  var result = datedData_1[k];
725
813
  if (result[i]) {
726
- tmp[i + ' ' + j + ' ' + k] = result[i][field.id];
814
+ 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') {
815
+ 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]) : '';
816
+ }
817
+ else {
818
+ tmp[i + ' ' + j + ' ' + k] = result[i][field.id] ? (typeof (result[i][field.id]) === 'string' ? result[i][field.id].replace(/,/g, '') : result[i][field.id]) : '';
819
+ }
727
820
  }
728
821
  else {
729
822
  tmp[i + ' ' + j + ' ' + k] = '';
@@ -732,13 +825,16 @@ function loadCronJobMethods(methodManager) {
732
825
  for (var k = 0; k <= report.fields_total.length - 1; k++) {
733
826
  var total = report.fields_total[k];
734
827
  if (total.fields.includes(field.id)) {
735
- tmp['total' + i + ' ' + j + ' ' + k] = reportTotalGroups_1[i][field.id];
828
+ 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]) : '';
736
829
  }
737
830
  else {
738
831
  tmp['total' + i + ' ' + j + ' ' + k] = '';
739
832
  }
740
833
  }
741
- lines_1.push(tmp);
834
+ lines_2.push(tmp);
835
+ };
836
+ for (var j = 0; j <= report.fields_selected.length - 1; j++) {
837
+ _loop_2(j);
742
838
  }
743
839
  }
744
840
  if (reportTotals) {
@@ -785,11 +881,11 @@ function loadCronJobMethods(methodManager) {
785
881
  tmp['totalreportTotals' + j + ' ' + l] = reportTotals[total.id + '_' + field.id];
786
882
  }
787
883
  }
788
- lines_1.push(tmp);
884
+ lines_2.push(tmp);
789
885
  }
790
886
  }
791
887
  var newCSV_1 = '';
792
- lines_1.forEach(function (row, index) {
888
+ lines_2.forEach(function (row, index) {
793
889
  Object.keys(row).forEach(function (key, keyIndex) {
794
890
  if (row[key] && typeof (row[key]) === 'string') {
795
891
  row[key] = row[key].replace(new RegExp(/,/g), '');
@@ -799,7 +895,7 @@ function loadCronJobMethods(methodManager) {
799
895
  newCSV_1 += ',';
800
896
  }
801
897
  });
802
- if (index < lines_1.length - 1) {
898
+ if (index < lines_2.length - 1) {
803
899
  newCSV_1 += '\r\n';
804
900
  }
805
901
  });
@@ -847,5 +943,314 @@ function getTreeLeaves(items, resArray, allowLookups) {
847
943
  }
848
944
  });
849
945
  }
946
+ function modifyDataTypeField(report, result, field, index) {
947
+ if (index < report.groups_row.length) {
948
+ result = result['gr_' + (index + 1)];
949
+ result.forEach(function (tDataRes, tIndex) {
950
+ modifyDataTypeField(report, tDataRes, field, index + 1);
951
+ });
952
+ }
953
+ else {
954
+ if (Array.isArray(result[field.id])) {
955
+ result[field.id].forEach(function (arr, arrIndex) {
956
+ if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
957
+ result[field.id].splice(arrIndex, 1, arr.toLocaleString());
958
+ }
959
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
960
+ result[field.id].splice(arrIndex, 1, arr.toString());
961
+ }
962
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
963
+ result[field.id].splice(arrIndex, 1, arr.toLocaleString('en-US', { style: 'currency', currency: 'USD' }));
964
+ }
965
+ else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
966
+ result[field.id].splice(arrIndex, 1, arr === true ? 'True' : 'False');
967
+ }
968
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
969
+ result[field.id].splice(arrIndex, 1, arr === true ? 'Yes' : 'No');
970
+ }
971
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
972
+ result[field.id].splice(arrIndex, 1, arr === true ? 1 : 0);
973
+ }
974
+ else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
975
+ result[field.id].splice(arrIndex, 1, moment(arr).format('L'));
976
+ }
977
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
978
+ result[field.id].splice(arrIndex, 1, moment(arr).format('LT'));
979
+ }
980
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
981
+ result[field.id].splice(arrIndex, 1, moment(arr).format('MM/DD/YYYY h:mm A'));
982
+ }
983
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
984
+ result[field.id].splice(arrIndex, 1, moment(arr).format('LL'));
985
+ }
986
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
987
+ result[field.id].splice(arrIndex, 1, moment(arr).format('LLL'));
988
+ }
989
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
990
+ result[field.id].splice(arrIndex, 1, moment(arr).toDate().getTime());
991
+ }
992
+ });
993
+ }
994
+ else {
995
+ if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
996
+ result[field.id] = result[field.id].toLocaleString();
997
+ }
998
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
999
+ result[field.id] = result[field.id].toString();
1000
+ }
1001
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
1002
+ result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
1003
+ }
1004
+ else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
1005
+ result[field.id] = result[field.id] === true ? 'True' : 'False';
1006
+ }
1007
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
1008
+ result[field.id] = result[field.id] === true ? 'Yes' : 'No';
1009
+ }
1010
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
1011
+ result[field.id] = result[field.id] === true ? 1 : 0;
1012
+ }
1013
+ else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
1014
+ result[field.id] = moment(result[field.id]).format('L');
1015
+ }
1016
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
1017
+ result[field.id] = moment(result[field.id]).format('LT');
1018
+ }
1019
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
1020
+ result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
1021
+ }
1022
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
1023
+ result[field.id] = moment(result[field.id]).format('LL');
1024
+ }
1025
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
1026
+ result[field.id] = moment(result[field.id]).format('LLL');
1027
+ }
1028
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
1029
+ result[field.id] = moment(result[field.id]).toDate().getTime();
1030
+ }
1031
+ }
1032
+ }
1033
+ }
1034
+ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1035
+ var row = ws.getRow(currentRow);
1036
+ if (level < report.groups_row.length) {
1037
+ row.getCell(2).fill = {
1038
+ fgColor: { argb: report.groups_row[level - 1].fill_color.replace('#', '') },
1039
+ type: 'pattern',
1040
+ pattern: 'solid'
1041
+ };
1042
+ row.getCell(2).font = {
1043
+ color: { argb: report.groups_row[level - 1].font_color.replace('#', '') },
1044
+ name: 'Arial',
1045
+ bold: true,
1046
+ size: 14
1047
+ };
1048
+ row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
1049
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.length + 1).$col$row);
1050
+ row.getCell(2).border = {
1051
+ top: { style: 'thick' },
1052
+ left: { style: 'thick' },
1053
+ right: { style: 'thick' }
1054
+ };
1055
+ if (report.fields_total.length) {
1056
+ report.fields_total.forEach(function (total) {
1057
+ currentRow += 1;
1058
+ row = ws.getRow(currentRow);
1059
+ report.fields_selected.forEach(function (field, fieldIndex) {
1060
+ if (total.fields.includes(field.id)) {
1061
+ row.getCell(fieldIndex + 2).value = field.columnName;
1062
+ row.getCell(fieldIndex + 2).font = {
1063
+ name: 'Arial',
1064
+ bold: true,
1065
+ size: 10
1066
+ };
1067
+ }
1068
+ if (fieldIndex === 0) {
1069
+ row.getCell(fieldIndex + 2).border = {
1070
+ left: { style: 'thick' }
1071
+ };
1072
+ }
1073
+ else if (fieldIndex === report.fields_selected.length - 1) {
1074
+ row.getCell(fieldIndex + 2).border = {
1075
+ right: { style: 'thick' }
1076
+ };
1077
+ }
1078
+ });
1079
+ });
1080
+ }
1081
+ // Totals
1082
+ report.fields_total.forEach(function (total) {
1083
+ currentRow += 1;
1084
+ row = ws.getRow(currentRow);
1085
+ report.fields_selected.forEach(function (field, fieldIndex) {
1086
+ if (total.fields.includes(field.id)) {
1087
+ row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1088
+ row.getCell(fieldIndex + 2).font = {
1089
+ name: 'Arial',
1090
+ bold: true,
1091
+ size: 10
1092
+ };
1093
+ }
1094
+ if (fieldIndex === 0) {
1095
+ row.getCell(fieldIndex + 2).border = {
1096
+ top: { style: 'thin' },
1097
+ left: { style: 'thick' },
1098
+ bottom: { style: 'thick' }
1099
+ };
1100
+ }
1101
+ else if (fieldIndex === report.fields_selected.length - 1) {
1102
+ row.getCell(fieldIndex + 2).border = {
1103
+ top: { style: 'thin' },
1104
+ bottom: { style: 'thick' },
1105
+ right: { style: 'thick' }
1106
+ };
1107
+ }
1108
+ else {
1109
+ row.getCell(fieldIndex + 2).border = {
1110
+ top: { style: 'thin' },
1111
+ bottom: { style: 'thick' }
1112
+ };
1113
+ }
1114
+ });
1115
+ });
1116
+ currentRow += 1;
1117
+ result = result['gr_' + (level + 1)];
1118
+ result.forEach(function (tDataRes, tIndex) {
1119
+ currentRow = tabGroupExcelRecursive(report, ws, currentRow, level + 1, tDataRes);
1120
+ });
1121
+ }
1122
+ else {
1123
+ row.getCell(2).fill = {
1124
+ fgColor: { argb: report.groups_row[level - 1].fill_color.replace('#', '') },
1125
+ type: 'pattern',
1126
+ pattern: 'solid'
1127
+ };
1128
+ row.getCell(2).font = {
1129
+ color: { argb: report.groups_row[level - 1].font_color.replace('#', '') },
1130
+ name: 'Arial',
1131
+ bold: true,
1132
+ size: 12
1133
+ };
1134
+ row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
1135
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.length + 1).$col$row);
1136
+ row.getCell(2).border = {
1137
+ top: { style: 'thick' },
1138
+ left: { style: 'thick' },
1139
+ right: { style: 'thick' }
1140
+ };
1141
+ currentRow += 1;
1142
+ row = ws.getRow(currentRow);
1143
+ // Headers
1144
+ report.fields_selected.forEach(function (field, fieldIndex) {
1145
+ row.getCell(fieldIndex + 2).value = field.columnName;
1146
+ row.getCell(fieldIndex + 2).font = {
1147
+ name: 'Arial',
1148
+ bold: true,
1149
+ size: 10
1150
+ };
1151
+ if (fieldIndex === 0) {
1152
+ row.getCell(fieldIndex + 2).border = {
1153
+ left: { style: 'thick' }
1154
+ };
1155
+ }
1156
+ else if (fieldIndex === report.fields_selected.length - 1) {
1157
+ row.getCell(fieldIndex + 2).border = {
1158
+ right: { style: 'thick' }
1159
+ };
1160
+ }
1161
+ });
1162
+ // Data
1163
+ result['f_0'].forEach(function (res, resIndex) {
1164
+ currentRow += 1;
1165
+ row = ws.getRow(currentRow);
1166
+ report.fields_selected.forEach(function (field, fieldIndex) {
1167
+ if (field.fieldType === 'Number' && typeof (result[field.id][resIndex] === 'string') && result[field.id][resIndex]) {
1168
+ row.getCell(fieldIndex + 2).value = parseFloat(result[field.id][resIndex].replace(new RegExp(/\,/g), '').replace(new RegExp(/\$/g), ''));
1169
+ }
1170
+ else {
1171
+ row.getCell(fieldIndex + 2).value = result[field.id][resIndex];
1172
+ }
1173
+ row.getCell(fieldIndex + 2).font = {
1174
+ name: 'Arial',
1175
+ size: 10
1176
+ };
1177
+ if (fieldIndex === 0) {
1178
+ row.getCell(fieldIndex + 2).border = {
1179
+ left: { style: 'thick' }
1180
+ };
1181
+ }
1182
+ else if (fieldIndex === report.fields_selected.length - 1) {
1183
+ row.getCell(fieldIndex + 2).border = {
1184
+ right: { style: 'thick' }
1185
+ };
1186
+ }
1187
+ });
1188
+ });
1189
+ // Totals
1190
+ report.fields_total.forEach(function (total) {
1191
+ currentRow += 1;
1192
+ row = ws.getRow(currentRow);
1193
+ report.fields_selected.forEach(function (field, fieldIndex) {
1194
+ if (total.fields.includes(field.id)) {
1195
+ row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1196
+ row.getCell(fieldIndex + 2).font = {
1197
+ name: 'Arial',
1198
+ bold: true,
1199
+ size: 10
1200
+ };
1201
+ }
1202
+ if (fieldIndex === 0) {
1203
+ row.getCell(fieldIndex + 2).border = {
1204
+ top: { style: 'thin' },
1205
+ left: { style: 'thick' },
1206
+ bottom: { style: 'thick' }
1207
+ };
1208
+ }
1209
+ else if (fieldIndex === report.fields_selected.length - 1) {
1210
+ row.getCell(fieldIndex + 2).border = {
1211
+ top: { style: 'thin' },
1212
+ bottom: { style: 'thick' },
1213
+ right: { style: 'thick' }
1214
+ };
1215
+ }
1216
+ else {
1217
+ row.getCell(fieldIndex + 2).border = {
1218
+ top: { style: 'thin' },
1219
+ bottom: { style: 'thick' }
1220
+ };
1221
+ }
1222
+ });
1223
+ });
1224
+ }
1225
+ return currentRow + 1;
1226
+ }
1227
+ function tabGroupExcelWidthRecursive(report, level, result, cols) {
1228
+ if (level < report.groups_row.length) {
1229
+ result = result['gr_' + (level + 1)];
1230
+ result.forEach(function (tDataRes, tIndex) {
1231
+ cols = tabGroupExcelWidthRecursive(report, level + 1, tDataRes, cols);
1232
+ });
1233
+ }
1234
+ else {
1235
+ report.fields_selected.forEach(function (field, fieldIndex) {
1236
+ result[field.id].forEach(function (res) {
1237
+ var length = 10;
1238
+ if (typeof (res) === 'number') {
1239
+ res = res.toLocaleString('en-US');
1240
+ }
1241
+ if (res) {
1242
+ length = res.length;
1243
+ }
1244
+ if (!cols[fieldIndex]) {
1245
+ cols[fieldIndex] = Math.max(10, field.columnName.length);
1246
+ }
1247
+ if (length > cols[fieldIndex]) {
1248
+ cols[fieldIndex] = length;
1249
+ }
1250
+ });
1251
+ });
1252
+ }
1253
+ return cols;
1254
+ }
850
1255
 
851
1256
  //# sourceMappingURL=cron-jobs.js.map