@resolveio/server-lib 20.3.28 → 20.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/managers/cron.manager.js +1 -1
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.d.ts +2 -2
- package/managers/method.manager.js +1 -1
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +8 -24
- package/managers/mongo.manager.js +1 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +1 -1
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.d.ts +6 -6
- package/managers/subscription.manager.js +1 -1
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +1 -1
- package/managers/subscription.performance.js.map +1 -1
- package/managers/websocket.manager.d.ts +25 -0
- package/managers/websocket.manager.js +2 -0
- package/managers/websocket.manager.js.map +1 -0
- package/methods/accounts.js +1 -1
- package/methods/accounts.js.map +1 -1
- package/methods/cron-jobs.js +1 -1
- package/methods/cron-jobs.js.map +1 -1
- package/methods/report-builder.js +1 -1
- package/methods/report-builder.js.map +1 -1
- package/package.json +5 -2
- package/server-app.d.ts +4 -5
- package/server-app.js +1 -1
- package/server-app.js.map +1 -1
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +1 -1
- package/util/schema-report-builder.js.map +1 -1
package/methods/cron-jobs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,n,l){return new(n=n||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 n?t:new n(function(e){e(t)})).then(fulfilled,rejected)}step((l=l.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(o,n){var l,a,i,f={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},d={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(d[Symbol.iterator]=function(){return this}),d;function verb(r){return function(e){var t=[r,e];if(l)throw new TypeError("Generator is already executing.");for(;f=d&&t[d=0]?0:f;)try{if(l=1,a&&(i=2&t[0]?a.return:t[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,t[1])).done)return i;switch(a=0,(t=i?[2&t[0],i.value]:t)[0]){case 0:case 1:i=t;break;case 4:return f.label++,{value:t[1],done:!1};case 5:f.label++,a=t[1],t=[0];continue;case 7:t=f.ops.pop(),f.trys.pop();continue;default:if(!(i=0<(i=f.trys).length&&i[i.length-1])&&(6===t[0]||2===t[0])){f=0;continue}if(3===t[0]&&(!i||t[1]>i[0]&&t[1]<i[3]))f.label=t[1];else if(6===t[0]&&f.label<i[1])f.label=i[1],i=t;else{if(!(i&&f.label<i[2])){i[2]&&f.ops.pop(),f.trys.pop();continue}f.label=i[2],f.ops.push(t)}}t=n.call(o,f)}catch(e){t=[6,e],a=0}finally{l=i=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},report_builder_report_collection_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadCronJobMethods=void 0,require("../collections/report-builder-report.collection")),simpl_schema_1=require("simpl-schema"),common_1=require("../util/common"),moment=require("moment-timezone"),XLSX=require("xlsx"),Excel=require("exceljs"),file_collection_1=require("../collections/file.collection"),cron_job_collection_1=require("../collections/cron-job.collection");function loadCronJobMethods(e){e.methods({cronEmailMergedDocsCleanUp:{function:function(){var t=this;return new Promise(function(r,e){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.find({$and:[{type:"Email Merged Docs"},{createdAt:{$lte:moment().subtract(1,"day").toDate()}}]})];case 1:return(t=e.sent()).length&&(this.callMethodInternal("deleteFiles"),file_collection_1.Files.deleteMany({_id:{$in:t.map(function(e){return e._id})}})),r(!0),[2]}})})})}},stuckCronJob:{function:function(){var t=this;return new Promise(function(r,e){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return t=moment().subtract(5,"minutes").toDate(),[4,cron_job_collection_1.CronJobs.find({running:!0,updatedAt:{$lte:t}})];case 1:return(t=e.sent()).length&&cron_job_collection_1.CronJobs.updateMany({_id:{$in:t.map(function(e){return e._id})}},{$set:{running:!1}}),r(!0),[2]}})})})}},reportbuilderCronJob:{check:new simpl_schema_1.default({data:{type:Object,blackbox:!0}}),function:function(F){var e=this;return new Promise(function(L,N){return __awaiter(e,void 0,void 0,function(){var w,r,o,t,n,l,O=this;return __generator(this,function(e){switch(e.label){case 0:return[4,report_builder_report_collection_1.ReportBuilderReports.findById(F.id_report)];case 1:return(w=e.sent()).fields_selected.forEach(function(e){var t,r=e.fieldPath.replace(/\.\$/g,"").split(".");e.fieldPathObj=null;for(var o=r.length-1;0<=o;o--)e.fieldPathObj?e.fieldPathObj=((t={})[r[o]]=e.fieldPathObj,t):e.fieldPathObj=((t={})[r[o]]=1,t)}),(w.fields_selected&&w.fields_selected.length||w.groups_row&&w.groups_row.length)&&(r={},o=0,w.fields_selected.forEach(function(t){t.collection_name===w.collection_root&&(r=(0,common_1.mergeDeep)(r,t.fieldPathObj));var e=w.fields_sort.findIndex(function(e){return e.field===t.id});0<=e&&(w.fields_sort[e].field="f_"+o),t.id="f_"+o,o+=1}),t={},w.fields_sort.length?w.fields_sort.forEach(function(e){e.field.startsWith("gr_")?t["_id."+e.field]="asc"===e.order?1:-1:t[e.field]="asc"===e.order?1:-1}):t=null,n={limit:0,skip:0,fields:r,sort:t},l=[],w.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return!e.field.includes(".$.")}).forEach(function(o){var e,t,r,n,l;o.condition&&o.field&&(null!==o.value&&(!Array.isArray(o.value)||o.value.length)||"null"===o.condition||"nnull"===o.condition)&&("bw"===o.condition?"Date"===o.fieldType&&o.is_rolling?(t=r=null,"Q1"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===o.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===o.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===o.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===o.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===o.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===o.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===o.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===o.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===o.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===o.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===o.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===o.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===o.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===o.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[o.field]={$gte:r},e),((r={})[o.field]={$lte:t},r)]})):a.push({$and:[((e={})[o.field]={$gte:o.value},e),((t={})[o.field]={$lte:o.highValue},t)]}):"nnull"===o.condition?((r=[]).push(((e={})[o.field]={$exists:!0},e)),r.push(((t={})[o.field]={$ne:null},t)),"String"===o.fieldType&&r.push(((e={})[o.field]={$ne:""},e)),a.push({$and:r})):"null"===o.condition?a.push(((t={})[o.field]={$eq:null},t)):Array.isArray(o.value)?"ne"===o.condition?(n=[],o.value.forEach(function(e){var t,r;n.push(((t={})[o.field]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<n.length?{$and:n}:n[0])):(l=[],o.value.forEach(function(e){var t,r;l.push(((t={})[o.field]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[o.field]=((r={})["$"+o.condition]=o.value,r),e)))}),a.length&&l.push({$or:a})}),this.callMethodInternal("reportBuilderBuildTree",w.collection_root,function(e,t){var i,f,d;t&&(t.layers=[t],i=[],getTreeLeaves(t.children,[]),getTreeLeaves(t.children,i,!0),f=[],d=[],w.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return e.field.includes(".$.")}).forEach(function(o){var e,t,r,n,l;i.filter(function(e){return e.fieldPath===o.field})[0]&&f.push(i.filter(function(e){return e.fieldPath===o.field})[0]),o.condition&&o.field&&(null!==o.value&&(!Array.isArray(o.value)||o.value.length)||"null"===o.condition||"nnull"===o.condition)&&("bw"===o.condition?"Date"===o.fieldType&&o.is_rolling?(t=r=null,"Q1"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===o.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===o.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===o.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===o.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===o.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===o.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===o.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===o.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===o.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===o.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===o.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===o.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===o.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===o.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[o.field.replace(/\.\$/g,"")]={$gte:r},e),((r={})[o.field.replace(/\.\$/g,"")]={$lte:t},r)]})):d.push({$and:[((e={})[o.field.replace(/\.\$/g,"")]={$gte:o.value},e),((t={})[o.field.replace(/\.\$/g,"")]={$lte:o.highValue},t)]}):"nnull"===o.condition?((r=[]).push(((e={})[o.field.replace(/\.\$/g,"")]={$exists:!0},e)),r.push(((t={})[o.field.replace(/\.\$/g,"")]={$ne:null},t)),"String"===o.fieldType&&r.push(((e={})[o.field.replace(/\.\$/g,"")]={$ne:""},e)),a.push({$and:r})):"null"===o.condition?a.push(((t={})[o.field.replace(/\.\$/g,"")]={$eq:null},t)):Array.isArray(o.value)?"ne"===o.condition?(n=[],o.value.forEach(function(e){var t,r;n.push(((t={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<n.length?{$and:n}:n[0])):(l=[],o.value.forEach(function(e){var t,r;l.push(((t={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=o.value,r),e)))}),a.length&&d.push({$or:a})}),O.callMethodInternal("reportBuilderGetResults",w.type,w.collection_root,n,l,d,f,w.fields_selected,w.fields_custom,w.groups_row,w.fields_total,w.fields_link,w.id_date_field||null,w.date_interval||null,w.group_type,function(e,t){if(t&&t[0]){var i=t[0].results,r=t[0].totals;if("List"===w.type){w.fields_selected.filter(function(e){return e.show}).forEach(function(t){"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Number"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"String"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Currency"!==t.leafFormatType?"Boolean"!==t.fieldType||t.leafFormatType&&"Boolean"!==t.leafFormatType?"Boolean"===t.fieldType&&"String"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"Yes":"No"}):"Boolean"===t.fieldType&&"Boolean_Number"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?1:0}):"Date"===t.fieldType&&"Date"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("L")}):"Date"===t.fieldType&&"Time"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LT")}):"Date"===t.fieldType&&"DateTime"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("MM/DD/YYYY h:mm A")}):"Date"===t.fieldType&&"Date_long"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LL")}):"Date"===t.fieldType&&"DateTime_long"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LLL")}):"Date"===t.fieldType&&"Timestamp"===t.leafFormatType&&i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).toDate().getTime()}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"True":"False"}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=(Math.round(100*e[t.id])/100).toLocaleString("en-US",{style:"currency",currency:"USD"})}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString("en-US",{style:"currency",currency:"USD"})}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString()})});var o=[],n=(w.groups_row.forEach(function(e){e.id,e.columnName}),w.fields_selected.filter(function(e){return e.show}).forEach(function(e){e.columnName,e.columnName}),XLSX.utils.book_new()),a=(i.forEach(function(t){var r={};w.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]||""}),w.fields_selected.filter(function(e){return e.show}).forEach(function(e){Array.isArray(t[e.id])?r[e.columnName]=t[e.id].join(","):"Number"===e.fieldType||"Count"===e.leafValueType?r[e.columnName]=t[e.id]?"string"==typeof t[e.id]?parseFloat(t[e.id].replace(/,/g,"").replace(/\$/g,"")):t[e.id]:"":r[e.columnName]=t[e.id]||""}),o.push(r)}),XLSX.utils.json_to_sheet(o)),l=(XLSX.utils.book_append_sheet(n,a,"RB Data"),XLSX.write(n,{bookType:"xlsx",type:"base64"}));F.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+w.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t<b>"+O.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+w.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+F.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:w.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:l,encoding:"base64"}],O.serverConfig.MAIL_FROM_REPORTS,"")})}else if("Group"===w.type){w.fields_selected.filter(function(e){return e.show}).forEach(function(t){i.forEach(function(e){modifyDataTypeField(w,e,t,1)})});var f=(n=new Excel.Workbook).addWorksheet("RB_1",{views:[{showGridLines:!1}]}),d=(n.properties.date1904=!1,n.calcProperties.fullCalcOnLoad=!0,1),t=f.getRow(d),t=(t.getCell(2).font={name:"Arial",bold:!0,size:14},t.getCell(4).font={name:"Arial",size:14},t.getCell(2).value="Report Name:",t.getCell(4).value=w.report_name,d+=1,(t=f.getRow(d)).getCell(2).font={name:"Arial",bold:!0,size:14},t.getCell(4).font={name:"Arial",size:14},t.getCell(2).value="Run Date:",t.getCell(4).value=moment().format("LLL"),d+=2,(0,common_1.deepCopy)(i)),u=[];t.forEach(function(e){d=tabGroupExcelRecursive(w,f,d,1,e),tabGroupExcelWidthRecursive(w,1,e,u)});for(var c=1;c<f.columns.length;c++)f.columns[c].width=u[c-1];var s=new Date;n.xlsx.writeBuffer().then(function(t){F.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+w.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>"+O.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>"+w.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+F.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_"+w.report_name+"_"+s.getFullYear()+"_"+(s.getMonth()+1)+"_"+s.getDate()+".xlsx",content:t}],O.serverConfig.MAIL_FROM_REPORTS,"")})}).catch(function(e){return console.log("Error writing excel export",e)})}else if("Dated"===w.type){var m=[],y=[],h=[],p=[],g=[];if("Quarterly"===w.date_interval){i.forEach(function(e){e._id.month<4?e._id.quarter=1:e._id.month<7?e._id.quarter=2:e._id.month<10?e._id.quarter=3:e._id.quarter=4,delete e._id.month});for(c=i.length-1;1<=c;c--)!function(e){var t,r=i[e];1<i.filter(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)}).length&&(t=i.filter(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)})[0],Object.keys(t).filter(function(e){return"_id"!==e}).forEach(function(e){t[e]+=r[e]}),i.splice(e,1))}(c)}t=(0,common_1.deepCopy)(i);t.forEach(function(t){delete t._id.day,delete t._id.week,delete t._id.month,delete t._id.quarter,delete t._id.year;var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),y.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||y.push(r)}),(t=(0,common_1.deepCopy)(i)).forEach(function(t){Object.keys(t._id).filter(function(e){return"second"!==e&&"hour"!==e&&"minute"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){delete t._id[e]});var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),m.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||m.push(r)}),m.forEach(function(e){e.year?"Seconds"===w.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"===w.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"===w.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"===w.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"===w.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"===w.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"===w.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"===w.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"}),(m=m.filter(function(e){return!e.date}).concat(m.filter(function(e){return e.date}).sort(function(e,t){return e.date.getTime()-t.date.getTime()}))).forEach(function(n){var t=[],r={},l={},a={};y.forEach(function(o){var e=i.find(function(t){var r=!0;return Object.keys(o).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),Object.keys(n).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e}).forEach(function(e){t._id[e]!==n[e]&&(r=!1)}),r});e?(t.push(e),Object.keys(e._id).filter(function(e){return e}).forEach(function(t){w.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]=w.fields_total.filter(function(e){return e.fields.includes(t)})[0].type)}),Object.keys(e).filter(function(e){return e&&"_id"!==e}).forEach(function(t){w.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]=w.fields_total.filter(function(e){return e.fields.includes(t)})[0].type)})):t.push(null)}),Object.keys(a).forEach(function(e){"avg"===a[e]&&(r[e]=r[e]/l[e]),r[e]=Math.round(100*r[e])/100}),g.push(r),h.push(t)}),y.forEach(function(o){var r={},n=i.filter(function(t){var r=!(!Object.keys(o).length||null===o._id);return Object.keys(o).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e&&"second"!==e&&"minute"!==e&&"hour"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),r});w.fields_total.forEach(function(e){e.fields.forEach(function(t){n.length?(r[t]=n.filter(function(e){return e&&e[t]}).map(function(e){return e[t]}).reduce(function(e,t){return e+t},0),"avg"===e.type&&(r[t]=Math.round(r[t]/n.length*100)/100)):r[t]=0})}),p.push(r)});for(var a=(n=new Excel.Workbook).addWorksheet("Dated_Report",{views:[{showGridLines:!0}]}),_=(n.properties.date1904=!1,n.calcProperties.fullCalcOnLoad=!0,1),v=1,b=((D=a.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},D.getCell(4).font={name:"Arial",size:14},D.getCell(2).value="Report Name:",D.getCell(4).value=w.report_name,_+=1,(D=a.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},D.getCell(4).font={name:"Arial",size:14},D.getCell(2).value="Run Date:",D.getCell(4).value=moment().format("LLL"),_+=2,D=a.getRow(_),w.groups_row.forEach(function(e){D.getCell(v).value=e.columnName,v++}),w.fields_selected.filter(function(e){return e.show}).forEach(function(e){v++}),w.fields_selected.filter(function(e){return e.show}).forEach(function(){m.forEach(function(e){D.getCell(v).value=e.dateString,v++})}),w.fields_total.forEach(function(e){D.getCell(v).value="Totals - "+(0,common_1.toTitleCase)(e.type),v++}),_+=v=1,D=a.getRow(_),function(n){for(var l=y[n],e=0;e<w.fields_selected.filter(function(e){return e.show}).length;e++)!function(t){var e=w.fields_selected.filter(function(e){return e.show})[t];v=1,D=a.getRow(_),w.groups_row.forEach(function(e){D.getCell(v).value=0===t?l[e.id]:"",v++}),D.getCell(v).value=e.columnName,v++;for(var r=0;r<m.length;r++){var o=h[r];o[n]?D.getCell(v).value=o[n][e.id]||"":D.getCell(v).value="",v++}for(r=0;r<w.fields_total.length;r++){w.fields_total[r];D.getCell(v).value=p[n][e.id]||"",v++}_++}(e)}),c=0;c<y.length;c++)b(c);if(r)for(c=0;c<w.fields_total.length;c++){var T=w.fields_total[c],D=a.getRow(_),v=1;D.getCell(v).value=(0,common_1.toTitleCase)(T.type)+" Totals",v+=w.groups_row.length,w.fields_selected.filter(function(e){return e.show}).forEach(function(){v+=1}),m.forEach(function(){v++});for(var C=0;C<w.fields_selected.filter(function(e){return e.show}).length;C++){var E=w.fields_selected.filter(function(e){return e.show})[C];D.getCell(v).value=r[T.id+"_"+E.id]||"",v++}_++}n.xlsx.writeBuffer().then(function(t){F.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+w.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>".concat(O.serverConfig.CLIENT_NAME," Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>").concat(w.report_name,"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>").concat(F.user,"<br><br>\n\t\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\t\tResolveIO<br><br>"),[{filename:w.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:t}],O.serverConfig.MAIL_FROM_REPORTS,"")})}).catch(function(e){return console.log("Error writing excel export",e)}),L(!0)}}else O.callMethodInternal("insertErrorLog","Report Builder Cron Job - Report Builder Get Results",[e]),N(e)}))})),[2]}})})})}}})}function getTreeLeaves(e,t,r){void 0===r&&(r=!1),e.forEach(function(e){e.isLeaf?t.push(e):e.lookup_collection&&!r||getTreeLeaves(e.children,t,r)})}function modifyDataTypeField(r,o,n,l){l<r.groups_row.length?(o=o["gr_"+(l+1)])&&o.forEach(function(e,t){modifyDataTypeField(r,e,n,l+1)}):Array.isArray(o[n.id])?o[n.id].forEach(function(e,t){"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id].splice(t,1,!0===e?"Yes":"No"):"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id].splice(t,1,!0===e?1:0):"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("L")):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LT")):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("MM/DD/YYYY h:mm A")):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LL")):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LLL")):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&o[n.id].splice(t,1,moment(e).toDate().getTime()):o[n.id].splice(t,1,!0===e?"True":"False"):o[n.id].splice(t,1,(Math.round(100*e)/100).toLocaleString("en-US",{style:"currency",currency:"USD"})):o[n.id].splice(t,1,e.toString()):o[n.id].splice(t,1,e.toLocaleString())}):"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id]=!0===o[n.id]?"Yes":"No":"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id]=!0===o[n.id]?1:0:"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("L"):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LT"):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("MM/DD/YYYY h:mm A"):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LL"):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LLL"):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&(o[n.id]=moment(o[n.id]).toDate().getTime()):o[n.id]=!0===o[n.id]?"True":"False":o[n.id]=(Math.round(100*o[n.id])/100).toLocaleString("en-US",{style:"currency",currency:"USD"}):o[n.id]=o[n.id].toString():o[n.id]=o[n.id].toLocaleString()}function tabGroupExcelRecursive(o,n,l,r,a){var i=n.getRow(l);return r<o.groups_row.length?(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:14},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},o.fields_total.length&&o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10}),"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})}),l+=1,(a=a["gr_"+(r+1)]).forEach(function(e,t){l=tabGroupExcelRecursive(o,n,l,r+1,e)})):(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:12},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})}),a.f_0.forEach(function(e,r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){"Number"===e.fieldType&&(a[e.id][r],1)&&a[e.id][r]?i.getCell(t+2).value=parseFloat(a[e.id][r].replace(new RegExp(/\,/g),"").replace(new RegExp(/\$/g),"")):i.getCell(t+2).value=a[e.id][r],"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),i.getCell(t+2).font={name:"Arial",size:10},0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})})),l+1}function tabGroupExcelWidthRecursive(r,o,t,n){return o<r.groups_row.length?(t=t["gr_"+(o+1)]).forEach(function(e,t){n=tabGroupExcelWidthRecursive(r,o+1,e,n)}):r.fields_selected.filter(function(e){return e.show}).forEach(function(r,o){var e;Array.isArray(t[r.id])?t[r.id].forEach(function(e){var t=10;e&&(t=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),t>n[o]&&(n[o]=t)}):((e=t[r.id])&&(length=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),length>n[o]&&(n[o]=length))}),n}exports.loadCronJobMethods=loadCronJobMethods;
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,n,l){return new(n=n||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 n?t:new n(function(e){e(t)})).then(fulfilled,rejected)}step((l=l.apply(e,o||[])).next())})},__generator=this&&this.__generator||function(o,n){var l,a,i,f={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},d={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(d[Symbol.iterator]=function(){return this}),d;function verb(r){return function(e){var t=[r,e];if(l)throw new TypeError("Generator is already executing.");for(;f=d&&t[d=0]?0:f;)try{if(l=1,a&&(i=2&t[0]?a.return:t[0]?a.throw||((i=a.return)&&i.call(a),0):a.next)&&!(i=i.call(a,t[1])).done)return i;switch(a=0,(t=i?[2&t[0],i.value]:t)[0]){case 0:case 1:i=t;break;case 4:return f.label++,{value:t[1],done:!1};case 5:f.label++,a=t[1],t=[0];continue;case 7:t=f.ops.pop(),f.trys.pop();continue;default:if(!(i=0<(i=f.trys).length&&i[i.length-1])&&(6===t[0]||2===t[0])){f=0;continue}if(3===t[0]&&(!i||t[1]>i[0]&&t[1]<i[3]))f.label=t[1];else if(6===t[0]&&f.label<i[1])f.label=i[1],i=t;else{if(!(i&&f.label<i[2])){i[2]&&f.ops.pop(),f.trys.pop();continue}f.label=i[2],f.ops.push(t)}}t=n.call(o,f)}catch(e){t=[6,e],a=0}finally{l=i=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},report_builder_report_collection_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadCronJobMethods=void 0,require("../collections/report-builder-report.collection")),simpl_schema_1=require("simpl-schema"),common_1=require("../util/common"),moment=require("moment-timezone"),XLSX=require("xlsx"),Excel=require("exceljs"),file_collection_1=require("../collections/file.collection"),cron_job_collection_1=require("../collections/cron-job.collection");function loadCronJobMethods(e){e.methods({cronEmailMergedDocsCleanUp:{function:function(){var t=this;return new Promise(function(r,e){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,file_collection_1.Files.find({$and:[{type:"Email Merged Docs"},{createdAt:{$lte:moment().subtract(1,"day").toDate()}}]})];case 1:return(t=e.sent()).length&&(this.callMethodInternal("deleteFiles"),file_collection_1.Files.deleteMany({_id:{$in:t.map(function(e){return e._id})}})),r(!0),[2]}})})})}},stuckCronJob:{function:function(){var t=this;return new Promise(function(r,e){return __awaiter(t,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return t=moment().subtract(5,"minutes").toDate(),[4,cron_job_collection_1.CronJobs.find({running:!0,updatedAt:{$lte:t}})];case 1:return(t=e.sent()).length&&cron_job_collection_1.CronJobs.updateMany({_id:{$in:t.map(function(e){return e._id})}},{$set:{running:!1}}),r(!0),[2]}})})})}},reportbuilderCronJob:{check:new simpl_schema_1.default({data:{type:Object,blackbox:!0}}),function:function(F){var e=this;return new Promise(function(L,N){return __awaiter(e,void 0,void 0,function(){var w,r,o,t,n,l,O=this;return __generator(this,function(e){switch(e.label){case 0:return[4,report_builder_report_collection_1.ReportBuilderReports.findById(F.id_report)];case 1:return(w=e.sent()).fields_selected.forEach(function(e){var t,r=e.fieldPath.replace(/\.\$/g,"").split(".");e.fieldPathObj=null;for(var o=r.length-1;0<=o;o--)e.fieldPathObj?e.fieldPathObj=((t={})[r[o]]=e.fieldPathObj,t):e.fieldPathObj=((t={})[r[o]]=1,t)}),(w.fields_selected&&w.fields_selected.length||w.groups_row&&w.groups_row.length)&&(r={},o=0,w.fields_selected.forEach(function(t){t.collection_name===w.collection_root&&(r=(0,common_1.mergeDeep)(r,t.fieldPathObj));var e=w.fields_sort.findIndex(function(e){return e.field===t.id});0<=e&&(w.fields_sort[e].field="f_"+o),t.id="f_"+o,o+=1}),t={},w.fields_sort.length?w.fields_sort.forEach(function(e){e.field.startsWith("gr_")?t["_id."+e.field]="asc"===e.order?1:-1:t[e.field]="asc"===e.order?1:-1}):t=null,n={limit:0,skip:0,fields:r,sort:t},l=[],w.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return!e.field.includes(".$.")}).forEach(function(o){var e,t,r,n,l;o.condition&&o.field&&(null!==o.value&&(!Array.isArray(o.value)||o.value.length)||"null"===o.condition||"nnull"===o.condition)&&("bw"===o.condition?"Date"===o.fieldType&&o.is_rolling?(t=r=null,"Q1"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===o.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===o.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===o.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===o.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===o.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===o.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===o.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===o.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===o.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===o.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===o.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===o.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===o.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===o.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[o.field]={$gte:r},e),((r={})[o.field]={$lte:t},r)]})):a.push({$and:[((e={})[o.field]={$gte:o.value},e),((t={})[o.field]={$lte:o.highValue},t)]}):"nnull"===o.condition?((r=[]).push(((e={})[o.field]={$exists:!0},e)),r.push(((t={})[o.field]={$ne:null},t)),"String"===o.fieldType&&r.push(((e={})[o.field]={$ne:""},e)),a.push({$and:r})):"null"===o.condition?a.push(((t={})[o.field]={$eq:null},t)):Array.isArray(o.value)?"ne"===o.condition?(n=[],o.value.forEach(function(e){var t,r;n.push(((t={})[o.field]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<n.length?{$and:n}:n[0])):(l=[],o.value.forEach(function(e){var t,r;l.push(((t={})[o.field]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[o.field]=((r={})["$"+o.condition]=o.value,r),e)))}),a.length&&l.push({$or:a})}),this.callMethodInternal("reportBuilderBuildTree",w.collection_root,function(e,t){var i,f,d;t&&(t.layers=[t],i=[],getTreeLeaves(t.children,[]),getTreeLeaves(t.children,i,!0),f=[],d=[],w.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return e.field.includes(".$.")}).forEach(function(o){var e,t,n,l,r=i.find(function(e){return e.fieldPath===o.field});r&&f.push(r),o.condition&&o.field&&(null!==o.value&&(!Array.isArray(o.value)||o.value.length)||"null"===o.condition||"nnull"===o.condition)&&("bw"===o.condition?"Date"===o.fieldType&&o.is_rolling?(t=r=null,"Q1"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===o.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===o.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===o.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===o.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===o.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===o.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===o.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===o.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===o.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===o.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===o.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===o.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===o.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===o.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[o.field.replace(/\.\$/g,"")]={$gte:r},e),((r={})[o.field.replace(/\.\$/g,"")]={$lte:t},r)]})):d.push({$and:[((e={})[o.field.replace(/\.\$/g,"")]={$gte:o.value},e),((t={})[o.field.replace(/\.\$/g,"")]={$lte:o.highValue},t)]}):"nnull"===o.condition?((r=[]).push(((e={})[o.field.replace(/\.\$/g,"")]={$exists:!0},e)),r.push(((t={})[o.field.replace(/\.\$/g,"")]={$ne:null},t)),"String"===o.fieldType&&r.push(((e={})[o.field.replace(/\.\$/g,"")]={$ne:""},e)),a.push({$and:r})):"null"===o.condition?a.push(((t={})[o.field.replace(/\.\$/g,"")]={$eq:null},t)):Array.isArray(o.value)?"ne"===o.condition?(n=[],o.value.forEach(function(e){var t,r;n.push(((t={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<n.length?{$and:n}:n[0])):(l=[],o.value.forEach(function(e){var t,r;l.push(((t={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=o.value,r),e)))}),a.length&&d.push({$or:a})}),O.callMethodInternal("reportBuilderGetResults",w.type,w.collection_root,n,l,d,f,w.fields_selected,w.fields_custom,w.groups_row,w.fields_total,w.fields_link,w.id_date_field||null,w.date_interval||null,w.group_type,function(e,t){if(t&&t[0]){var i=t[0].results,r=t[0].totals;if("List"===w.type){w.fields_selected.filter(function(e){return e.show}).forEach(function(t){"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Number"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"String"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Currency"!==t.leafFormatType?"Boolean"!==t.fieldType||t.leafFormatType&&"Boolean"!==t.leafFormatType?"Boolean"===t.fieldType&&"String"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"Yes":"No"}):"Boolean"===t.fieldType&&"Boolean_Number"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?1:0}):"Date"===t.fieldType&&"Date"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("L")}):"Date"===t.fieldType&&"Time"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LT")}):"Date"===t.fieldType&&"DateTime"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("MM/DD/YYYY h:mm A")}):"Date"===t.fieldType&&"Date_long"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LL")}):"Date"===t.fieldType&&"DateTime_long"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LLL")}):"Date"===t.fieldType&&"Timestamp"===t.leafFormatType&&i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).toDate().getTime()}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"True":"False"}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=(0,common_1.round)(e[t.id],2).toLocaleString("en-US",{style:"currency",currency:"USD"})}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString("en-US",{style:"currency",currency:"USD"})}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString()})});var o=[],n=(w.groups_row.forEach(function(e){e.id,e.columnName}),w.fields_selected.filter(function(e){return e.show}).forEach(function(e){e.columnName,e.columnName}),XLSX.utils.book_new()),a=(i.forEach(function(t){var r={};w.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]||""}),w.fields_selected.filter(function(e){return e.show}).forEach(function(e){Array.isArray(t[e.id])?r[e.columnName]=t[e.id].join(","):"Number"===e.fieldType||"Count"===e.leafValueType?r[e.columnName]=t[e.id]?"string"==typeof t[e.id]?parseFloat(t[e.id].replace(/,/g,"").replace(/\$/g,"")):t[e.id]:"":r[e.columnName]=t[e.id]||""}),o.push(r)}),XLSX.utils.json_to_sheet(o)),l=(XLSX.utils.book_append_sheet(n,a,"RB Data"),XLSX.write(n,{bookType:"xlsx",type:"base64"}));F.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+w.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>"+O.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>"+w.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+F.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:w.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:l,encoding:"base64"}],O.serverConfig.MAIL_FROM_REPORTS,"")})}else if("Group"===w.type){w.fields_selected.filter(function(e){return e.show}).forEach(function(t){i.forEach(function(e){modifyDataTypeField(w,e,t,1)})});var f=(n=new Excel.Workbook).addWorksheet("RB_1",{views:[{showGridLines:!1}]}),d=(n.properties.date1904=!1,n.calcProperties.fullCalcOnLoad=!0,1),t=f.getRow(d),t=(t.getCell(2).font={name:"Arial",bold:!0,size:14},t.getCell(4).font={name:"Arial",size:14},t.getCell(2).value="Report Name:",t.getCell(4).value=w.report_name,d+=1,(t=f.getRow(d)).getCell(2).font={name:"Arial",bold:!0,size:14},t.getCell(4).font={name:"Arial",size:14},t.getCell(2).value="Run Date:",t.getCell(4).value=moment().format("LLL"),d+=2,(0,common_1.deepCopy)(i)),u=[];t.forEach(function(e){d=tabGroupExcelRecursive(w,f,d,1,e),tabGroupExcelWidthRecursive(w,1,e,u)});for(var c=1;c<f.columns.length;c++)f.columns[c].width=u[c-1];var s=new Date;n.xlsx.writeBuffer().then(function(t){F.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+w.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>"+O.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>"+w.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+F.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_"+w.report_name+"_"+s.getFullYear()+"_"+(s.getMonth()+1)+"_"+s.getDate()+".xlsx",content:t}],O.serverConfig.MAIL_FROM_REPORTS,"")})}).catch(function(e){return console.log("Error writing excel export",e)})}else if("Dated"===w.type){var m=[],y=[],h=[],p=[],g=[];if("Quarterly"===w.date_interval){i.forEach(function(e){e._id.month<4?e._id.quarter=1:e._id.month<7?e._id.quarter=2:e._id.month<10?e._id.quarter=3:e._id.quarter=4,delete e._id.month});for(c=i.length-1;1<=c;c--)!function(e){var t,r=i[e];1<i.filter(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)}).length&&(t=i.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]}),i.splice(e,1))}(c)}t=(0,common_1.deepCopy)(i);t.forEach(function(t){delete t._id.day,delete t._id.week,delete t._id.month,delete t._id.quarter,delete t._id.year;var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),y.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||y.push(r)}),(t=(0,common_1.deepCopy)(i)).forEach(function(t){Object.keys(t._id).filter(function(e){return"second"!==e&&"hour"!==e&&"minute"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){delete t._id[e]});var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),m.find(function(e){return JSON.stringify(e)===JSON.stringify(r)})||m.push(r)}),m.forEach(function(e){e.year?"Seconds"===w.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"===w.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"===w.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"===w.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"===w.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"===w.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"===w.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"===w.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"}),(m=m.filter(function(e){return!e.date}).concat(m.filter(function(e){return e.date}).sort(function(e,t){return e.date.getTime()-t.date.getTime()}))).forEach(function(n){var t=[],r={},l={},a={};y.forEach(function(o){var e=i.find(function(t){var r=!0;return Object.keys(o).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),Object.keys(n).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e}).forEach(function(e){t._id[e]!==n[e]&&(r=!1)}),r});e?(t.push(e),Object.keys(e._id).filter(function(e){return e}).forEach(function(t){w.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]=w.fields_total.find(function(e){return e.fields.includes(t)}).type)}),Object.keys(e).filter(function(e){return e&&"_id"!==e}).forEach(function(t){w.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]=w.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)}),g.push(r),h.push(t)}),y.forEach(function(o){var r={},n=i.filter(function(t){var r=!(!Object.keys(o).length||null===o._id);return Object.keys(o).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e&&"second"!==e&&"minute"!==e&&"hour"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),r});w.fields_total.forEach(function(e){e.fields.forEach(function(t){n.length?(r[t]=n.filter(function(e){return e&&e[t]}).map(function(e){return e[t]}).reduce(function(e,t){return e+t},0),"avg"===e.type&&(r[t]=(0,common_1.round)(r[t]/n.length,2))):r[t]=0})}),p.push(r)});for(var a=(n=new Excel.Workbook).addWorksheet("Dated_Report",{views:[{showGridLines:!0}]}),_=(n.properties.date1904=!1,n.calcProperties.fullCalcOnLoad=!0,1),v=1,b=((D=a.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},D.getCell(4).font={name:"Arial",size:14},D.getCell(2).value="Report Name:",D.getCell(4).value=w.report_name,_+=1,(D=a.getRow(_)).getCell(2).font={name:"Arial",bold:!0,size:14},D.getCell(4).font={name:"Arial",size:14},D.getCell(2).value="Run Date:",D.getCell(4).value=moment().format("LLL"),_+=2,D=a.getRow(_),w.groups_row.forEach(function(e){D.getCell(v).value=e.columnName,v++}),w.fields_selected.filter(function(e){return e.show}).forEach(function(e){v++}),w.fields_selected.filter(function(e){return e.show}).forEach(function(){m.forEach(function(e){D.getCell(v).value=e.dateString,v++})}),w.fields_total.forEach(function(e){D.getCell(v).value="Totals - "+(0,common_1.toTitleCase)(e.type),v++}),_+=v=1,D=a.getRow(_),function(n){for(var l=y[n],e=0;e<w.fields_selected.filter(function(e){return e.show}).length;e++)!function(t){var e=w.fields_selected.filter(function(e){return e.show})[t];v=1,D=a.getRow(_),w.groups_row.forEach(function(e){D.getCell(v).value=0===t?l[e.id]:"",v++}),D.getCell(v).value=e.columnName,v++;for(var r=0;r<m.length;r++){var o=h[r];o[n]?D.getCell(v).value=o[n][e.id]||"":D.getCell(v).value="",v++}for(r=0;r<w.fields_total.length;r++){w.fields_total[r];D.getCell(v).value=p[n][e.id]||"",v++}_++}(e)}),c=0;c<y.length;c++)b(c);if(r)for(c=0;c<w.fields_total.length;c++){var T=w.fields_total[c],D=a.getRow(_),v=1;D.getCell(v).value=(0,common_1.toTitleCase)(T.type)+" Totals",v+=w.groups_row.length,w.fields_selected.filter(function(e){return e.show}).forEach(function(){v+=1}),m.forEach(function(){v++});for(var C=0;C<w.fields_selected.filter(function(e){return e.show}).length;C++){var E=w.fields_selected.filter(function(e){return e.show})[C];D.getCell(v).value=r[T.id+"_"+E.id]||"",v++}_++}n.xlsx.writeBuffer().then(function(t){F.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+w.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>".concat(O.serverConfig.CLIENT_NAME," Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>").concat(w.report_name,"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>").concat(F.user,"<br><br>\n\t\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\t\tResolveIO<br><br>"),[{filename:w.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:t}],O.serverConfig.MAIL_FROM_REPORTS,"")})}).catch(function(e){return console.log("Error writing excel export",e)}),L(!0)}}else O.callMethodInternal("insertErrorLog","Report Builder Cron Job - Report Builder Get Results",[e]),N(e)}))})),[2]}})})})}}})}function getTreeLeaves(e,t,r){void 0===r&&(r=!1),e.forEach(function(e){e.isLeaf?t.push(e):e.lookup_collection&&!r||getTreeLeaves(e.children,t,r)})}function modifyDataTypeField(r,o,n,l){l<r.groups_row.length?(o=o["gr_"+(l+1)])&&o.forEach(function(e,t){modifyDataTypeField(r,e,n,l+1)}):Array.isArray(o[n.id])?o[n.id].forEach(function(e,t){"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id].splice(t,1,!0===e?"Yes":"No"):"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id].splice(t,1,!0===e?1:0):"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("L")):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LT")):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("MM/DD/YYYY h:mm A")):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LL")):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LLL")):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&o[n.id].splice(t,1,moment(e).toDate().getTime()):o[n.id].splice(t,1,!0===e?"True":"False"):o[n.id].splice(t,1,(0,common_1.round)(e,2).toLocaleString("en-US",{style:"currency",currency:"USD"})):o[n.id].splice(t,1,e.toString()):o[n.id].splice(t,1,e.toLocaleString())}):"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id]=!0===o[n.id]?"Yes":"No":"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id]=!0===o[n.id]?1:0:"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("L"):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LT"):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("MM/DD/YYYY h:mm A"):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LL"):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LLL"):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&(o[n.id]=moment(o[n.id]).toDate().getTime()):o[n.id]=!0===o[n.id]?"True":"False":o[n.id]=(0,common_1.round)(o[n.id],2).toLocaleString("en-US",{style:"currency",currency:"USD"}):o[n.id]=o[n.id].toString():o[n.id]=o[n.id].toLocaleString()}function tabGroupExcelRecursive(o,n,l,r,a){var i=n.getRow(l);return r<o.groups_row.length?(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:14},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},o.fields_total.length&&o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10}),"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})}),l+=1,(a=a["gr_"+(r+1)]).forEach(function(e,t){l=tabGroupExcelRecursive(o,n,l,r+1,e)})):(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:12},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})}),a.f_0.forEach(function(e,r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){"Number"===e.fieldType&&(a[e.id][r],1)&&a[e.id][r]?i.getCell(t+2).value=parseFloat(a[e.id][r].replace(new RegExp(/\,/g),"").replace(new RegExp(/\$/g),"")):i.getCell(t+2).value=a[e.id][r],"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),i.getCell(t+2).font={name:"Arial",size:10},0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})})),l+1}function tabGroupExcelWidthRecursive(r,o,t,n){return o<r.groups_row.length?(t=t["gr_"+(o+1)]).forEach(function(e,t){n=tabGroupExcelWidthRecursive(r,o+1,e,n)}):r.fields_selected.filter(function(e){return e.show}).forEach(function(r,o){var e;Array.isArray(t[r.id])?t[r.id].forEach(function(e){var t=10;e&&(t=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),t>n[o]&&(n[o]=t)}):((e=t[r.id])&&(length=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),length>n[o]&&(n[o]=length))}),n}exports.loadCronJobMethods=loadCronJobMethods;
|
|
2
2
|
//# sourceMappingURL=cron-jobs.js.map
|