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