@resolveio/server-lib 20.2.8 → 20.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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(L){var e=this;return new Promise(function(M,$){return __awaiter(e,void 0,void 0,function(){var N,r,o,t,n,l,k=this;return __generator(this,function(e){switch(e.label){case 0:return[4,report_builder_report_collection_1.ReportBuilderReports.findById(L.id_report)];case 1:return(N=e.sent()).fields_selected.forEach(function(e){var t,r=e.fieldPath.replace(/\.\$/g,"").split(".");e.fieldPathObj=null;for(var o=r.length-1;0<=o;o--)e.fieldPathObj?e.fieldPathObj=((t={})[r[o]]=e.fieldPathObj,t):e.fieldPathObj=((t={})[r[o]]=1,t)}),(N.fields_selected&&N.fields_selected.length||N.groups_row&&N.groups_row.length)&&(r={},o=0,N.fields_selected.forEach(function(t){t.collection_name===N.collection_root&&(r=(0,common_1.mergeDeep)(r,t.fieldPathObj));var e=N.fields_sort.findIndex(function(e){return e.field===t.id});0<=e&&(N.fields_sort[e].field="f_"+o),t.id="f_"+o,o+=1}),t={},N.fields_sort.length?N.fields_sort.forEach(function(e){e.field.startsWith("gr_")?t["_id."+e.field]="asc"===e.order?1:-1:t[e.field]="asc"===e.order?1:-1}):t=null,n={limit:0,skip:0,fields:r,sort:t},l=[],N.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return!e.field.includes(".$.")}).forEach(function(o){var e,t,r,n,l;o.condition&&o.field&&(null!==o.value&&(!Array.isArray(o.value)||o.value.length)||"null"===o.condition||"nnull"===o.condition)&&("bw"===o.condition?"Date"===o.fieldType&&o.is_rolling?(t=r=null,"Q1"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===o.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===o.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===o.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===o.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===o.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===o.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===o.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===o.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===o.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===o.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===o.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===o.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===o.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===o.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[o.field]={$gte:r},e),((r={})[o.field]={$lte:t},r)]})):a.push({$and:[((e={})[o.field]={$gte:o.value},e),((t={})[o.field]={$lte:o.highValue},t)]}):"nnull"===o.condition?((r=[]).push(((e={})[o.field]={$exists:!0},e)),r.push(((t={})[o.field]={$ne:null},t)),"String"===o.fieldType&&r.push(((e={})[o.field]={$ne:""},e)),a.push({$and:r})):"null"===o.condition?a.push(((t={})[o.field]={$eq:null},t)):Array.isArray(o.value)?"ne"===o.condition?(n=[],o.value.forEach(function(e){var t,r;n.push(((t={})[o.field]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<n.length?{$and:n}:n[0])):(l=[],o.value.forEach(function(e){var t,r;l.push(((t={})[o.field]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[o.field]=((r={})["$"+o.condition]=o.value,r),e)))}),a.length&&l.push({$or:a})}),this.callMethodInternal("reportBuilderBuildTree",N.collection_root,function(e,t){var F,i,f;t&&(t.layers=[t],F=[],getTreeLeaves(t.children,[]),getTreeLeaves(t.children,F,!0),i=[],f=[],N.fields_filter.forEach(function(e){var a=[];e.ors.filter(function(e){return e.field.includes(".$.")}).forEach(function(o){var e,t,r,n,l;F.filter(function(e){return e.fieldPath===o.field})[0]&&i.push(F.filter(function(e){return e.fieldPath===o.field})[0]),o.condition&&o.field&&(null!==o.value&&(!Array.isArray(o.value)||o.value.length)||"null"===o.condition||"nnull"===o.condition)&&("bw"===o.condition?"Date"===o.fieldType&&o.is_rolling?(t=r=null,"Q1"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().startOf("year").quarter(2).subtract(1,"days").toDate()):"Q2"===o.rolling_interval?(r=moment().startOf("year").quarter(2).toDate(),t=moment().startOf("year").quarter(3).subtract(1,"days").toDate()):"Q3"===o.rolling_interval?(r=moment().startOf("year").quarter(3).toDate(),t=moment().startOf("year").quarter(4).subtract(1,"days").toDate()):"Q4"===o.rolling_interval?(r=moment().startOf("year").quarter(4).toDate(),t=moment().endOf("year").toDate()):"Today"===o.rolling_interval?(r=moment().startOf("day").toDate(),t=moment().endOf("day").toDate()):"Yesterday"===o.rolling_interval?(r=moment().subtract(1,"days").startOf("day").toDate(),t=moment().subtract(1,"days").endOf("day").toDate()):"Week"===o.rolling_interval?(r=moment().startOf("isoWeek").toDate(),t=moment().endOf("day").toDate()):"Last Week"===o.rolling_interval?(t=moment().startOf("isoWeek").subtract(1,"days").toDate(),r=moment(t).startOf("isoWeek").toDate()):"Month"===o.rolling_interval?(r=moment().startOf("month").toDate(),t=moment().endOf("day").toDate()):"Last Month"===o.rolling_interval?(t=moment().startOf("month").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("month").toDate()):"Last 30 Days"===o.rolling_interval?(t=moment().endOf("day").toDate(),r=moment().subtract(30,"days").startOf("day").toDate()):"Quarter"===o.rolling_interval?(r=moment().startOf("year").quarter(moment().quarter()).toDate(),t=moment().endOf("day").toDate()):"Last Quarter"===o.rolling_interval?(t=moment().startOf("year").quarter(moment().quarter()).subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("quarter").toDate()):"Year"===o.rolling_interval?(r=moment().startOf("year").toDate(),t=moment().endOf("day").toDate()):"Last Year"===o.rolling_interval?(t=moment().startOf("year").subtract(1,"days").endOf("day").toDate(),r=moment(t).startOf("year").toDate()):"All"===o.rolling_interval&&(r=new Date(2017,0,1,0,0,0,0),t=moment().endOf("day").toDate()),t.setHours(23),t.setMinutes(59),t.setSeconds(59),t.setMilliseconds(999),a.push({$and:[((e={})[o.field.replace(/\.\$/g,"")]={$gte:r},e),((r={})[o.field.replace(/\.\$/g,"")]={$lte:t},r)]})):f.push({$and:[((e={})[o.field.replace(/\.\$/g,"")]={$gte:o.value},e),((t={})[o.field.replace(/\.\$/g,"")]={$lte:o.highValue},t)]}):"nnull"===o.condition?((r=[]).push(((e={})[o.field.replace(/\.\$/g,"")]={$exists:!0},e)),r.push(((t={})[o.field.replace(/\.\$/g,"")]={$ne:null},t)),"String"===o.fieldType&&r.push(((e={})[o.field.replace(/\.\$/g,"")]={$ne:""},e)),a.push({$and:r})):"null"===o.condition?a.push(((t={})[o.field.replace(/\.\$/g,"")]={$eq:null},t)):Array.isArray(o.value)?"ne"===o.condition?(n=[],o.value.forEach(function(e){var t,r;n.push(((t={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<n.length?{$and:n}:n[0])):(l=[],o.value.forEach(function(e){var t,r;l.push(((t={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=Array.isArray(e)?e[0]:e,r),t))}),a.push(1<l.length?{$or:l}:l[0])):a.push(((e={})[o.field.replace(/\.\$/g,"")]=((r={})["$"+o.condition]=o.value,r),e)))}),a.length&&f.push({$or:a})}),k.callMethodInternal("reportBuilderGetResults",N.type,N.collection_root,n,l,f,i,N.fields_selected,N.fields_custom,N.groups_row,N.fields_total,N.fields_link,N.id_date_field||null,N.date_interval||null,N.group_type,function(e,t){if(t&&t[0]){var i=t[0].results,r=t[0].totals;if("List"===N.type){N.fields_selected.filter(function(e){return e.show}).forEach(function(t){"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Number"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"String"!==t.leafFormatType?"Number"!==t.fieldType&&"Count"!==t.leafValueType||"Currency"!==t.leafFormatType?"Boolean"!==t.fieldType||t.leafFormatType&&"Boolean"!==t.leafFormatType?"Boolean"===t.fieldType&&"String"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"Yes":"No"}):"Boolean"===t.fieldType&&"Boolean_Number"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?1:0}):"Date"===t.fieldType&&"Date"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("L")}):"Date"===t.fieldType&&"Time"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LT")}):"Date"===t.fieldType&&"DateTime"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("MM/DD/YYYY h:mm A")}):"Date"===t.fieldType&&"Date_long"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LL")}):"Date"===t.fieldType&&"DateTime_long"===t.leafFormatType?i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).format("LLL")}):"Date"===t.fieldType&&"Timestamp"===t.leafFormatType&&i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=moment(e[t.id]).toDate().getTime()}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=!0===e[t.id]?"True":"False"}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=(Math.round(100*e[t.id])/100).toLocaleString("en-US",{style:"currency",currency:"USD"})}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString("en-US",{style:"currency",currency:"USD"})}):i.filter(function(e){return null!==e[t.id]&&void 0!==e[t.id]}).forEach(function(e){e[t.id]=e[t.id].toLocaleString()})});var o=[],n=(N.groups_row.forEach(function(e){e.id,e.columnName}),N.fields_selected.filter(function(e){return e.show}).forEach(function(e){e.columnName,e.columnName}),XLSX.utils.book_new()),t=(i.forEach(function(t){var r={};N.groups_row.forEach(function(e){Array.isArray(t._id[e.id])?r[e.columnName]=t._id[e.id].join(","):"Number"===e.treeItem.fieldType?r[e.columnName]=t._id[e.id]?"string"==typeof t._id[e.id]?parseFloat(t._id[e.id].replace(/,/g,"").replace(/\$/g,"")):t._id[e.id]:"":r[e.columnName]=t._id[e.id]||""}),N.fields_selected.filter(function(e){return e.show}).forEach(function(e){Array.isArray(t[e.id])?r[e.columnName]=t[e.id].join(","):"Number"===e.fieldType||"Count"===e.leafValueType?r[e.columnName]=t[e.id]?"string"==typeof t[e.id]?parseFloat(t[e.id].replace(/,/g,"").replace(/\$/g,"")):t[e.id]:"":r[e.columnName]=t[e.id]||""}),o.push(r)}),XLSX.utils.json_to_sheet(o)),l=(XLSX.utils.book_append_sheet(n,t,"RB Data"),XLSX.write(n,{bookType:"xlsx",type:"base64"}));L.emails.forEach(function(e){k.sendEmail(e,k.serverConfig.CLIENT_NAME+" Scheduled Report - "+N.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t<b>"+k.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+N.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+L.user+"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>",[{filename:N.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:l,encoding:"base64"}],k.serverConfig.MAIL_FROM_REPORTS,"")})}else if("Group"===N.type){N.fields_selected.filter(function(e){return e.show}).forEach(function(t){i.forEach(function(e){modifyDataTypeField(N,e,t,1)})});var a=(n=new Excel.Workbook).addWorksheet("RB_1",{views:[{showGridLines:!1}]}),f=(n.properties.date1904=!1,n.calcProperties.fullCalcOnLoad=!0,1),t=a.getRow(f),t=(t.getCell(2).font={name:"Arial",bold:!0,size:14},t.getCell(4).font={name:"Arial",size:14},t.getCell(2).value="Report Name:",t.getCell(4).value=N.report_name,f+=1,(t=a.getRow(f)).getCell(2).font={name:"Arial",bold:!0,size:14},t.getCell(4).font={name:"Arial",size:14},t.getCell(2).value="Run Date:",t.getCell(4).value=moment().format("LLL"),f+=2,(0,common_1.deepCopy)(i)),d=[];t.forEach(function(e){f=tabGroupExcelRecursive(N,a,f,1,e),tabGroupExcelWidthRecursive(N,1,e,d)});for(var u=1;u<a.columns.length;u++)a.columns[u].width=d[u-1];var s=new Date;n.xlsx.writeBuffer().then(function(t){L.emails.forEach(function(e){k.sendEmail(e,k.serverConfig.CLIENT_NAME+" Scheduled Report - "+N.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>"+k.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+N.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+L.user+"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>",[{filename:"Group_Report_"+N.report_name+"_"+s.getFullYear()+"_"+(s.getMonth()+1)+"_"+s.getDate()+".xlsx",content:t}],k.serverConfig.MAIL_FROM_REPORTS,"")})}).catch(function(e){return console.log("Error writing excel export",e)})}else if("Dated"===N.type){var c=[],m={},y=(N.groups_row.forEach(function(e){m[e.id]=e.columnName}),m[""]="",[]),p=[];if("Quarterly"===N.date_interval){i.forEach(function(e){e._id.month<4?e._id.quarter=1:e._id.month<7?e._id.quarter=2:e._id.month<10?e._id.quarter=3:e._id.quarter=4,delete e._id.month});for(u=i.length-1;1<=u;u--)!function(e){var t,r=i[e];1<i.filter(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)}).length&&(t=i.filter(function(e){return JSON.stringify(e._id)===JSON.stringify(r._id)})[0],Object.keys(t).filter(function(e){return"_id"!==e}).forEach(function(e){t[e]+=r[e]}),i.splice(e,1))}(u)}var t=(0,common_1.deepCopy)(i),h=(t.forEach(function(t){delete t._id.day,delete t._id.week,delete t._id.month,delete t._id.quarter,delete t._id.year;var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),p.filter(function(e){return JSON.stringify(e)===JSON.stringify(r)}).length||p.push(r)}),(t=(0,common_1.deepCopy)(i)).forEach(function(t){Object.keys(t._id).filter(function(e){return"second"!==e&&"hour"!==e&&"minute"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){delete t._id[e]});var r={};Object.keys(t._id).forEach(function(e){r[e]=t._id[e]}),y.filter(function(e){return JSON.stringify(e)===JSON.stringify(r)}).length||y.push(r)}),y.forEach(function(e){e.year?"Seconds"===N.date_interval?(e.date=new Date(e.year,e.month-1,e.day,e.hour,e.minute,e.second,0),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm:ss")):"Minutes"===N.date_interval?(e.date=new Date(e.year,e.month-1,e.day,e.hour,e.minute,0,0),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm")):"Hours"===N.date_interval?(e.date=new Date(e.year,e.month-1,e.day,e.hour,0,0,0),e.dateString=moment(e.date).format("MMM DD YYYY HH")):"Daily"===N.date_interval?(e.date=new Date(e.year,e.month-1,e.day,0,0,0,0),e.dateString=moment(e.date).format("MMM DD YYYY")):"Weekly"===N.date_interval?(e.date=moment().day("Monday").isoWeekYear(e.year).isoWeek(e.week).toDate(),e.dateLast=moment().day("Sunday").isoWeekYear(e.year).isoWeek(e.week).toDate(),e.dateString="Week #"+e.week+" "+e.year+"("+moment(e.date).format("MM/DD/YY")+" - "+moment(e.dateLast).format("MM/DD/YY")+")"):"Monthly"===N.date_interval?(e.date=new Date(e.year,e.month-1,1,0,0,0,0),e.dateString=moment(e.date).format("MMM YYYY")):"Quarterly"===N.date_interval?(e.date=moment().quarter(e.quarter).year(e.year).toDate(),e.dateString="Q"+e.quarter+" "+e.year):"Yearly"===N.date_interval&&(e.date=new Date(e.year),e.dateString=e.year.toString()):e.dateString="No Date"}),y=y.filter(function(e){return!e.date}).concat(y.filter(function(e){return e.date}).sort(function(e,t){return e.date.getTime()-t.date.getTime()})),[]),g=[],_=[],b=(y.forEach(function(n){var t=[],r={},l={},a={};p.forEach(function(o){var e=i.filter(function(t){var r=!0;return Object.keys(n).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e}).forEach(function(e){t._id[e]!==n[e]&&(r=!1)}),Object.keys(o).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),r})[0];e?(t.push(e),Object.keys(e._id).filter(function(e){return e}).forEach(function(t){N.fields_total.filter(function(e){return e.fields.includes(t)}).length&&(r[t]?r[t]+=e._id[t]:r[t]=e._id[t],l[t]?l[t]+=1:l[t]=1,a[t]=N.fields_total.filter(function(e){return e.fields.includes(t)})[0].type)}),Object.keys(e).filter(function(e){return e&&"_id"!==e}).forEach(function(t){N.fields_total.filter(function(e){return e.fields.includes(t)}).length&&(r[t]?r[t]+=e[t]:r[t]=e[t],l[t]?l[t]+=1:l[t]=1,a[t]=N.fields_total.filter(function(e){return e.fields.includes(t)})[0].type)})):t.push(null)}),Object.keys(a).forEach(function(e){"avg"===a[e]&&(r[e]=r[e]/l[e]),r[e]=Math.round(100*r[e])/100}),g.push(r),_.push(t)}),p.forEach(function(o){var r={},n=i.filter(function(t){var r=!(!Object.keys(o).length||null===o._id);return Object.keys(o).filter(function(e){return"date"!==e&&"dateLast"!==e&&"dateString"!==e&&"second"!==e&&"minute"!==e&&"hour"!==e&&"day"!==e&&"week"!==e&&"month"!==e&&"quarter"!==e&&"year"!==e}).forEach(function(e){t._id[e]!==o[e]&&(r=!1)}),r});N.fields_total.forEach(function(e){e.fields.forEach(function(t){n.length?(r[t]=n.filter(function(e){return e&&e[t]}).map(function(e){return e[t]}).reduce(function(e,t){return e+t},0),"avg"===e.type&&(r[t]=Math.round(r[t]/n.length*100)/100)):r[t]=0})}),h.push(r)}),y.forEach(function(e){m[e.dateString]=e.dateString}),N.fields_total.forEach(function(e){m["Totals - "+e.type.toUpperCase()]="Totals - "+(0,common_1.toTitleCase)(e.type)}),c.push(m),(0,common_1.deepCopy)(N.fields_selected));N.fields_custom.forEach(function(e){b.push({collection_name:"",columnName:e.columnName,fieldName:e.selFieldId,fieldType:"Number",fieldTypeName:"Number",distinctFieldValues:[],fieldPath:e.selFieldId,fieldPathName:"Custom Field",lookup_collection:"",lookup_local_key:"",lookup_foreign_key:"",lookup_as:"",text:"",value:"",isLeaf:!0,isActive:!0,isSelected:!0,depth:0,leafValueType:e.leafValueType,leafValueTypes:[],leafFormatType:"Number",leafFormatTypes:[],id:e.selFieldId,show:!0})});for(u=0;u<p.length;u++)for(var v=p[u],T=b.filter(function(e){return e.show}),D=0;D<T.length;D++)!function(e){for(var t=T[e],r={},o=0;o<=N.groups_row.length-1;o++){var n=N.groups_row[o];r[v[n.id]]=0===e?v[n.id]:""}r[t.columnName]=t.columnName;for(o=0;o<=_.length-1;o++){var l=_[o];l[u]?F.filter(function(e){return e.id===t.id})[0]&&"Number"===F.filter(function(e){return e.id===t.id})[0].fieldType?r[u+" "+e+" "+o]=l[u][t.id]?"string"==typeof l[u][t.id]?parseInt(l[u][t.id].replace(/,/g,"")):l[u][t.id]:"":r[u+" "+e+" "+o]=l[u][t.id]?"string"==typeof l[u][t.id]?l[u][t.id].replace(/,/g,""):l[u][t.id]:"":r[u+" "+e+" "+o]=""}for(o=0;o<=N.fields_total.length-1;o++)N.fields_total[o].fields.includes(t.id)?r["total"+u+" "+e+" "+o]=h[u][t.id]?"string"==typeof h[u][t.id]?parseInt(h[u][t.id].replace(/,/g,"")):h[u][t.id]:"":r["total"+u+" "+e+" "+o]="";c.push(r)}(D);if(r)for(u=0;u<N.fields_total.length;u++){var E=N.fields_total[u],C={};C[E.type]=(0,common_1.toTitleCase)(E.type)+" Totals";for(D=0;D<N.groups_row.length-1;D++)C.total_gr_j="";C["Total - Fields"]="";for(D=0;D<_.length;D++)C["Total - Dated "+D]="";for(D=0;D<=N.fields_selected.filter(function(e){return e.show}).length-1;D++){var O=N.fields_selected.filter(function(e){return e.show})[D];E.fields.includes(O.id)?C["totalreportTotals"+D]=r[E.id+"_"+O.id]:C["totalreportTotals"+D]=""}c.push(C)}var w="";c.forEach(function(r,e){Object.keys(r).forEach(function(e,t){r[e]&&"string"==typeof r[e]&&(r[e]=r[e].replace(new RegExp(/,/g),"")),w+=r[e],t<Object.keys(r).length-1&&(w+=",")}),e<c.length-1&&(w+="\r\n")}),L.emails.forEach(function(e){k.sendEmail(e,k.serverConfig.CLIENT_NAME+" Scheduled Report - "+N.report_name,"","\n\t\t\t\t\t\t\t\t\t\t\t\t<b>"+k.serverConfig.CLIENT_NAME+" Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>"+N.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+L.user+"<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>",[{filename:N.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".csv",content:w}],k.serverConfig.MAIL_FROM_REPORTS,"")}),M(!0)}}else k.callMethodInternal("insertErrorLog","Report Builder Cron Job - Report Builder Get Results",[e]),$(e)}))})),[2]}})})})}}})}function getTreeLeaves(e,t,r){void 0===r&&(r=!1),e.forEach(function(e){e.isLeaf?t.push(e):e.lookup_collection&&!r||getTreeLeaves(e.children,t,r)})}function modifyDataTypeField(r,o,n,l){l<r.groups_row.length?(o=o["gr_"+(l+1)]).forEach(function(e,t){modifyDataTypeField(r,e,n,l+1)}):Array.isArray(o[n.id])?o[n.id].forEach(function(e,t){"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id].splice(t,1,!0===e?"Yes":"No"):"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id].splice(t,1,!0===e?1:0):"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("L")):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LT")):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("MM/DD/YYYY h:mm A")):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LL")):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LLL")):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&o[n.id].splice(t,1,moment(e).toDate().getTime()):o[n.id].splice(t,1,!0===e?"True":"False"):o[n.id].splice(t,1,(Math.round(100*e)/100).toLocaleString("en-US",{style:"currency",currency:"USD"})):o[n.id].splice(t,1,e.toString()):o[n.id].splice(t,1,e.toLocaleString())}):"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id]=!0===o[n.id]?"Yes":"No":"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id]=!0===o[n.id]?1:0:"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("L"):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LT"):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("MM/DD/YYYY h:mm A"):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LL"):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LLL"):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&(o[n.id]=moment(o[n.id]).toDate().getTime()):o[n.id]=!0===o[n.id]?"True":"False":o[n.id]=(Math.round(100*o[n.id])/100).toLocaleString("en-US",{style:"currency",currency:"USD"}):o[n.id]=o[n.id].toString():o[n.id]=o[n.id].toLocaleString()}function tabGroupExcelRecursive(o,n,l,r,a){var i=n.getRow(l);return r<o.groups_row.length?(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:14},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},o.fields_total.length&&o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10}),"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})}),l+=1,(a=a["gr_"+(r+1)]).forEach(function(e,t){l=tabGroupExcelRecursive(o,n,l,r+1,e)})):(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:12},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})}),a.f_0.forEach(function(e,r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){"Number"===e.fieldType&&(a[e.id][r],1)&&a[e.id][r]?i.getCell(t+2).value=parseFloat(a[e.id][r].replace(new RegExp(/\,/g),"").replace(new RegExp(/\$/g),"")):i.getCell(t+2).value=a[e.id][r],"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),i.getCell(t+2).font={name:"Arial",size:10},0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})})),l+1}function tabGroupExcelWidthRecursive(r,o,t,n){return o<r.groups_row.length?(t=t["gr_"+(o+1)]).forEach(function(e,t){n=tabGroupExcelWidthRecursive(r,o+1,e,n)}):r.fields_selected.filter(function(e){return e.show}).forEach(function(r,o){var e;Array.isArray(t[r.id])?t[r.id].forEach(function(e){var t=10;e&&(t=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),t>n[o]&&(n[o]=t)}):((e=t[r.id])&&(length=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),length>n[o]&&(n[o]=length))}),n}exports.loadCronJobMethods=loadCronJobMethods;
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(M){var e=this;return new Promise(function(F,L){return __awaiter(e,void 0,void 0,function(){var E,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(M.id_report)];case 1:return(E=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)}),(E.fields_selected&&E.fields_selected.length||E.groups_row&&E.groups_row.length)&&(r={},o=0,E.fields_selected.forEach(function(t){t.collection_name===E.collection_root&&(r=(0,common_1.mergeDeep)(r,t.fieldPathObj));var e=E.fields_sort.findIndex(function(e){return e.field===t.id});0<=e&&(E.fields_sort[e].field="f_"+o),t.id="f_"+o,o+=1}),t={},E.fields_sort.length?E.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=[],E.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",E.collection_root,function(e,t){var i,f,d;t&&(t.layers=[t],i=[],getTreeLeaves(t.children,[]),getTreeLeaves(t.children,i,!0),f=[],d=[],E.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",E.type,E.collection_root,n,l,d,f,E.fields_selected,E.fields_custom,E.groups_row,E.fields_total,E.fields_link,E.id_date_field||null,E.date_interval||null,E.group_type,function(e,t){if(t&&t[0]){var i=t[0].results,r=t[0].totals;if("List"===E.type){E.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=(E.groups_row.forEach(function(e){e.id,e.columnName}),E.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={};E.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]||""}),E.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"}));M.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+E.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>"+E.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+M.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:E.report_name+"-"+moment().format("MM-DD-YYYY-hh-mm-A")+".xlsx",content:l,encoding:"base64"}],O.serverConfig.MAIL_FROM_REPORTS,"")})}else if("Group"===E.type){E.fields_selected.filter(function(e){return e.show}).forEach(function(t){i.forEach(function(e){modifyDataTypeField(E,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=E.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(E,f,d,1,e),tabGroupExcelWidthRecursive(E,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){M.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+E.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>"+E.report_name+"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>"+M.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_"+E.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"===E.type){var m=[],y=[],h=[],p=[],g=[];if("Quarterly"===E.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"===E.date_interval?(e.date=new Date(e.year,e.month-1,e.day,e.hour,e.minute,e.second,0),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm:ss")):"Minutes"===E.date_interval?(e.date=new Date(e.year,e.month-1,e.day,e.hour,e.minute,0,0),e.dateString=moment(e.date).format("MMM DD YYYY HH:mm")):"Hours"===E.date_interval?(e.date=new Date(e.year,e.month-1,e.day,e.hour,0,0,0),e.dateString=moment(e.date).format("MMM DD YYYY HH")):"Daily"===E.date_interval?(e.date=new Date(e.year,e.month-1,e.day,0,0,0,0),e.dateString=moment(e.date).format("MMM DD YYYY")):"Weekly"===E.date_interval?(e.date=moment().day("Monday").isoWeekYear(e.year).isoWeek(e.week).toDate(),e.dateLast=moment().day("Sunday").isoWeekYear(e.year).isoWeek(e.week).toDate(),e.dateString="Week #"+e.week+" "+e.year+" ("+moment(e.date).format("MM/DD/YY")+" - "+moment(e.dateLast).format("MM/DD/YY")+")"):"Monthly"===E.date_interval?(e.date=new Date(e.year,e.month-1,1,0,0,0,0),e.dateString=moment(e.date).format("MMM YYYY")):"Quarterly"===E.date_interval?(e.date=moment().quarter(e.quarter).year(e.year).toDate(),e.dateString="Q"+e.quarter+" "+e.year):"Yearly"===E.date_interval&&(e.date=new Date(e.year),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){E.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]=E.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){E.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]=E.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});E.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),b=1,v=((T=a.getRow(_)).getCell(1).value="Report Name:",T.getCell(2).value=E.report_name,_++,(T=a.getRow(_)).getCell(1).value="Run Date:",T.getCell(2).value=moment().format("LLL"),_+=2,E.groups_row.forEach(function(e){T.getCell(b).value=e.columnName,b++}),E.fields_selected.filter(function(e){return e.show}).forEach(function(e){T.getCell(b).value=e.columnName,b++}),E.fields_selected.filter(function(e){return e.show}).forEach(function(){m.forEach(function(e){T.getCell(b).value=e.dateString,b++})}),E.fields_total.forEach(function(e){T.getCell(b).value="Totals - "+(0,common_1.toTitleCase)(e.type),b++}),b=1,_++,function(n){for(var l=y[n],e=0;e<E.fields_selected.filter(function(e){return e.show}).length;e++)!function(t){var e=E.fields_selected.filter(function(e){return e.show})[t];b=1,T=a.getRow(_),E.groups_row.forEach(function(e){T.getCell(b).value=0===t?l[e.id]:"",b++}),T.getCell(b).value=e.columnName,b++;for(var r=0;r<m.length;r++){var o=h[r];o[n]?T.getCell(b).value=o[n][e.id]||"":T.getCell(b).value="",b++}for(r=0;r<E.fields_total.length;r++){E.fields_total[r];T.getCell(b).value=p[n][e.id]||"",b++}_++}(e)}),c=0;c<y.length;c++)v(c);if(r)for(c=0;c<E.fields_total.length;c++){var D=E.fields_total[c],T=a.getRow(_),b=1;T.getCell(b).value=(0,common_1.toTitleCase)(D.type)+" Totals",b+=E.groups_row.length,E.fields_selected.filter(function(e){return e.show}).forEach(function(){m.forEach(function(){T.getCell(b).value="",b++})});for(var C=0;C<E.fields_selected.filter(function(e){return e.show}).length;C++){var w=E.fields_selected.filter(function(e){return e.show})[C];T.getCell(b).value=r[D.id+"_"+w.id]||"",b++}_++}n.xlsx.writeBuffer().then(function(t){M.emails.forEach(function(e){O.sendEmail(e,O.serverConfig.CLIENT_NAME+" Scheduled Report - "+E.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(E.report_name,"<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>").concat(M.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:E.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)}),F(!0)}}else O.callMethodInternal("insertErrorLog","Report Builder Cron Job - Report Builder Get Results",[e]),L(e)}))})),[2]}})})})}}})}function getTreeLeaves(e,t,r){void 0===r&&(r=!1),e.forEach(function(e){e.isLeaf?t.push(e):e.lookup_collection&&!r||getTreeLeaves(e.children,t,r)})}function modifyDataTypeField(r,o,n,l){l<r.groups_row.length?(o=o["gr_"+(l+1)]).forEach(function(e,t){modifyDataTypeField(r,e,n,l+1)}):Array.isArray(o[n.id])?o[n.id].forEach(function(e,t){"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id].splice(t,1,!0===e?"Yes":"No"):"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id].splice(t,1,!0===e?1:0):"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("L")):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LT")):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("MM/DD/YYYY h:mm A")):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LL")):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id].splice(t,1,moment(e).format("LLL")):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&o[n.id].splice(t,1,moment(e).toDate().getTime()):o[n.id].splice(t,1,!0===e?"True":"False"):o[n.id].splice(t,1,(Math.round(100*e)/100).toLocaleString("en-US",{style:"currency",currency:"USD"})):o[n.id].splice(t,1,e.toString()):o[n.id].splice(t,1,e.toLocaleString())}):"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Number"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"String"!==n.leafFormatType?"Number"!==n.fieldType&&"Count"!==n.leafValueType||"Currency"!==n.leafFormatType?"Boolean"!==n.fieldType||n.leafFormatType&&"Boolean"!==n.leafFormatType?"Boolean"===n.fieldType&&"String"===n.leafFormatType?o[n.id]=!0===o[n.id]?"Yes":"No":"Boolean"===n.fieldType&&"Boolean_Number"===n.leafFormatType?o[n.id]=!0===o[n.id]?1:0:"Date"===n.fieldType&&"Date"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("L"):"Date"===n.fieldType&&"Time"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LT"):"Date"===n.fieldType&&"DateTime"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("MM/DD/YYYY h:mm A"):"Date"===n.fieldType&&"Date_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LL"):"Date"===n.fieldType&&"DateTime_long"===n.leafFormatType?o[n.id]=moment(o[n.id]).format("LLL"):"Date"===n.fieldType&&"Timestamp"===n.leafFormatType&&(o[n.id]=moment(o[n.id]).toDate().getTime()):o[n.id]=!0===o[n.id]?"True":"False":o[n.id]=(Math.round(100*o[n.id])/100).toLocaleString("en-US",{style:"currency",currency:"USD"}):o[n.id]=o[n.id].toString():o[n.id]=o[n.id].toLocaleString()}function tabGroupExcelRecursive(o,n,l,r,a){var i=n.getRow(l);return r<o.groups_row.length?(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:14},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},o.fields_total.length&&o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10}),"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})}),l+=1,(a=a["gr_"+(r+1)]).forEach(function(e,t){l=tabGroupExcelRecursive(o,n,l,r+1,e)})):(i.getCell(2).fill={fgColor:{argb:o.groups_row[r-1].fill_color?o.groups_row[r-1].fill_color.replace("#",""):"ffffff"},type:"pattern",pattern:"solid"},i.getCell(2).font={color:{argb:o.groups_row[r-1].font_color?o.groups_row[r-1].font_color.replace("#",""):"000000"},name:"Arial",bold:!0,size:12},i.getCell(2).value=o.groups_row[r-1].columnName+": "+a._id["gr_"+r],n.mergeCells(i.getCell(2).$col$row+":"+i.getCell(o.fields_selected.filter(function(e){return e.show}).length+1).$col$row),i.getCell(2).border={top:{style:"thick"},left:{style:"thick"},right:{style:"thick"}},l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){i.getCell(t+2).value=e.columnName,i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})}),a.f_0.forEach(function(e,r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){"Number"===e.fieldType&&(a[e.id][r],1)&&a[e.id][r]?i.getCell(t+2).value=parseFloat(a[e.id][r].replace(new RegExp(/\,/g),"").replace(new RegExp(/\$/g),"")):i.getCell(t+2).value=a[e.id][r],"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0"),i.getCell(t+2).font={name:"Arial",size:10},0===t?i.getCell(t+2).border={left:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1&&(i.getCell(t+2).border={right:{style:"thick"}})})}),o.fields_total.forEach(function(r){l+=1,i=n.getRow(l),o.fields_selected.filter(function(e){return e.show}).forEach(function(e,t){r.fields.includes(e.id)&&(i.getCell(t+2).value=a[r.id+"_"+e.id],i.getCell(t+2).font={name:"Arial",bold:!0,size:10},"Currency"===e.leafFormatType?i.getCell(t+2).numFmt='"$"#,##0.00':"Number"===e.leafFormatType&&(i.getCell(t+2).numFmt="#,##0")),0===t?i.getCell(t+2).border={top:{style:"thin"},left:{style:"thick"},bottom:{style:"thick"}}:t===o.fields_selected.filter(function(e){return e.show}).length-1?i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"},right:{style:"thick"}}:i.getCell(t+2).border={top:{style:"thin"},bottom:{style:"thick"}}})})),l+1}function tabGroupExcelWidthRecursive(r,o,t,n){return o<r.groups_row.length?(t=t["gr_"+(o+1)]).forEach(function(e,t){n=tabGroupExcelWidthRecursive(r,o+1,e,n)}):r.fields_selected.filter(function(e){return e.show}).forEach(function(r,o){var e;Array.isArray(t[r.id])?t[r.id].forEach(function(e){var t=10;e&&(t=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),t>n[o]&&(n[o]=t)}):((e=t[r.id])&&(length=e.length+3),n[o]||(n[o]=Math.max(10,r.columnName.length)),length>n[o]&&(n[o]=length))}),n}exports.loadCronJobMethods=loadCronJobMethods;
2
2
  //# sourceMappingURL=cron-jobs.js.map