@resolveio/server-lib 20.2.12 → 20.2.13

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(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(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,_+=1,(T=a.getRow(_)).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"),_+=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){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,T=a.getRow(_),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;
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(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,_+=1,(T=a.getRow(_)).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"),_+=2,T=a.getRow(_),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){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,T=a.getRow(_),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(){b+=1}),m.forEach(function(){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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/methods/cron-jobs.ts"],"names":["report_builder_report_collection_1","require","simpl_schema_1","common_1","moment","XLSX","Excel","file_collection_1","cron_job_collection_1","loadCronJobMethods","methodManager","methods","cronEmailMergedDocsCleanUp","function","_this","this","Promise","resolve","reject","__awaiter","Files","find","$and","type","createdAt","$lte","subtract","toDate","files","_a","sent","length","callMethodInternal","deleteMany","_id","$in","map","a","stuckCronJob","fiveMin","CronJobs","running","updatedAt","cronJobs","updateMany","$set","reportbuilderCronJob","check","default","data","Object","blackbox","ReportBuilderReports","findById","report","fields_selected","forEach","field","fieldData","fieldPath","replace","split","fieldPathObj","i","_b","groups_row","fieldsObj_1","count_1","collection_name","collection_root","mergeDeep","sortIndex","fields_sort","findIndex","sortObj_1","sortField","startsWith","order","rootOptions_1","limit","skip","fields","sort","filters_1","fields_filter","filterAnd","ors","filter","includes","endDate","and","and_1","or_1","condition","value","Array","isArray","fieldType","is_rolling","startDate","rolling_interval","startOf","quarter","endOf","Date","setHours","setMinutes","setSeconds","setMilliseconds","push","$gte","_c","_d","highValue","_e","$exists","_f","$ne","_g","_h","$eq","filt","$or","_j","_k","errCollTree","collectionTree","allLeaves_1","filterArrayFields_1","filterArrays_1","layers","getTreeLeaves","children","and_2","or_2","fields_custom","fields_total","fields_link","id_date_field","date_interval","group_type","err","res","results_1","results","reportTotals","totals","show","leafValueType","leafFormatType","id","undefined","result","format","getTime","Math","round","toLocaleString","style","currency","lines_1","wb","group","columnName","header","utils","book_new","ws","tmp","join","treeItem","parseFloat","json_to_sheet","wbout_1","book_append_sheet","write","bookType","email","sendEmail","serverConfig","report_name","filename","content","encoding","modifyDataTypeField","ws_1","Workbook","addWorksheet","views","showGridLines","currentRow_1","properties","date1904","calcProperties","fullCalcOnLoad","row","getRow","copy","getCell","font","name","bold","size","deepCopy","widths_1","tabGroupExcelRecursive","tabGroupExcelWidthRecursive","columns","width","now_1","xlsx","writeBuffer","then","buffer","getFullYear","getMonth","getDate","catch","console","log","datedUniqueDates_1","datedUniqueGroups_1","datedData_1","reportTotalGroups_1","reportTotalDates_1","dataPt","month","tmpData_1","JSON","stringify","keys","key","splice","tmpResults","day","week","year","tmpGroup","tmpDate","date","hour","minute","second","dateString","isoWeekYear","isoWeek","dateLast","toString","concat","b","tmpData","tmpTotalDated","tmpTotalCnt","tmpTotalType","match","totalKey","tmpTotalGroup","filteredData","total","reduce","currentRow","currentCol_1","row_1","toTitleCase","j","groupRow","k","items","resArray","allowLookups","item","isLeaf","lookup_collection","index","tDataRes","tIndex","arr","arrIndex","level","fill","fgColor","argb","fill_color","pattern","color","font_color","mergeCells","$col$row","border","top","left","right","fieldIndex","numFmt","bottom","resIndex","RegExp","cols","max","exports"],"mappings":"k8CACAA,oC,yFAAAC,QAAA,iDAAA,GACAC,eAAAD,QAAA,cAAA,EACAE,SAAAF,QAAA,gBAAA,EAEAG,OAAAH,QAAA,iBAAA,EACAI,KAAAJ,QAAA,MAAA,EACAK,MAAAL,QAAA,SAAA,EACAM,kBAAAN,QAAA,gCAAA,EACAO,sBAAAP,QAAA,oCAAA,EAEA,SAAgBQ,mBAAmBC,GAClCA,EAAcC,QAAQ,CACrBC,2BAA4B,CAC3BC,SAAU,WAAA,IAAAC,EAAAC,KACT,OAAO,IAAIC,QAAQ,SAAOC,EAASC,GAAM,OAAAC,UAAAL,EAAA,KAAA,EAAA,KAAA,EAAA,W,iEAC5B,MAAA,CAAA,EAAMP,kBAAAa,MAAMC,KAAK,CAACC,KAAM,CAAC,CAACC,KAAM,mBAAmB,EAAG,CAACC,UAAW,CAACC,KAAMrB,OAAM,EAAGsB,SAAS,EAAG,KAAK,EAAEC,OAAM,CAAE,CAAC,EAAE,CAAC,G,cAAzHC,EAAQC,EAAAC,KAAA,GAEFC,SACThB,KAAKiB,mBAAmB,aAAa,EACrCzB,kBAAAa,MAAMa,WAAW,CAACC,IAAK,CAACC,IAAKP,EAAMQ,IAAI,SAAAC,GAAK,OAAAA,EAAEH,GAAF,CAAK,CAAC,CAAC,CAAC,GAGrDjB,EAAQ,CAAA,CAAI,E,SACZ,CACF,C,EAEDqB,aAAc,CACbzB,SAAU,WAAA,IAAAC,EAAAC,KACT,OAAO,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J,EAAUuB,CAAI,CACrE,CAAC,EAGDnP,EAAOC,gBAAgBgC,OAAO,SAAAlD,GAAK,OAAAA,EAAE8G,IAAF,CAAM,EAAE3F,QAAQ,SAACC,EAAO2O,GAC1D,IAkBKtJ,EAlBD/C,MAAMC,QAAQwD,EAAO/F,EAAM6F,GAAG,EACjCE,EAAO/F,EAAM6F,IAAI9F,QAAQ,SAAAsF,GACxB,IAAI/G,EAAS,GAET+G,IACH/G,EAAS+G,EAAI/G,OAAS,GAGlB0Q,EAAKL,KACTK,EAAKL,GAAczI,KAAK+I,IAAI,GAAIjP,EAAM0G,WAAWpI,MAAM,GAGpDA,EAAS0Q,EAAKL,KACjBK,EAAKL,GAAcrQ,EAErB,CAAC,IAGG+G,EAAMU,EAAO/F,EAAM6F,OAGtBvH,OAAS+G,EAAI/G,OAAS,GAGlB0Q,EAAKL,KACTK,EAAKL,GAAczI,KAAK+I,IAAI,GAAIjP,EAAM0G,WAAWpI,MAAM,GAGpDA,OAAS0Q,EAAKL,KACjBK,EAAKL,GAAcrQ,QAGtB,CAAC,EAGK0Q,CACR,CA76CAE,QAAAlS,mBAAAA","file":"cron-jobs.js","sourcesContent":["import { MethodManager } from '../managers/method.manager';\nimport { ReportBuilderReports } from '../collections/report-builder-report.collection';\nimport SimpleSchema from 'simpl-schema';\nimport { mergeDeep, deepCopy, toTitleCase } from '../util/common';\nimport { PaginationOptions } from '../models/pagination.model';\nimport * as moment from 'moment-timezone';\nimport * as XLSX from 'xlsx';\nimport * as Excel from 'exceljs';\nimport { Files } from '../collections/file.collection';\nimport { CronJobs } from '../collections/cron-job.collection';\n\nexport function loadCronJobMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcronEmailMergedDocsCleanUp: {\n\t\t\tfunction: function() {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet files = await Files.find({$and: [{type: 'Email Merged Docs'}, {createdAt: {$lte: moment().subtract(1, 'day').toDate()}}]});\n\t\t\t\t\t\n\t\t\t\t\tif (files.length) {\n\t\t\t\t\t\tthis.callMethodInternal('deleteFiles');\n\t\t\t\t\t\tFiles.deleteMany({_id: {$in: files.map(a => a._id)}});\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tstuckCronJob: {\n\t\t\tfunction: function() {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet fiveMin = moment().subtract(5, 'minutes').toDate();\n\t\t\t\t\tlet cronJobs = await CronJobs.find({running: true, updatedAt: {$lte: fiveMin}});\n\n\t\t\t\t\tif (cronJobs.length) {\n\t\t\t\t\t\tCronJobs.updateMany({_id: {$in: cronJobs.map(a => a._id)}}, {$set: {running: false}});\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\treportbuilderCronJob: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdata: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(data: Object) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet report = await ReportBuilderReports.findById(data['id_report']);\n\n\t\t\t\t\treport.fields_selected.forEach((field: any) => {\n\t\t\t\t\t\tlet dotPath = field.fieldPath.replace(/\\.\\$/g, '');\n\t\t\t\t\t\tlet fieldData = dotPath.split('.');\n\t\t\t\t\t\tfield.fieldPathObj = null;\n\t\t\t\t\t\tfor (let i = fieldData.length - 1; i >= 0; i--) {\n\t\t\t\t\t\t\tif (!field.fieldPathObj) {\n\t\t\t\t\t\t\t\tfield.fieldPathObj = {[fieldData[i]]: 1};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tfield.fieldPathObj = {[fieldData[i]]: field.fieldPathObj};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tif ((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length)) {\n\t\t\t\t\t\tlet fieldsObj = {};\n\n\t\t\t\t\t\tlet count = 0;\n\n\t\t\t\t\t\treport.fields_selected.forEach((field: any) => {\n\t\t\t\t\t\t\tif (field.collection_name === report.collection_root) {\n\t\t\t\t\t\t\t\tfieldsObj = mergeDeep(fieldsObj, field.fieldPathObj);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tlet sortIndex = report.fields_sort.findIndex(a => a.field === field['id']);\n\n\t\t\t\t\t\t\tif (sortIndex >= 0) {\n\t\t\t\t\t\t\t\treport.fields_sort[sortIndex].field = ('f_' + count);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tfield['id'] = 'f_' + count;\n\n\t\t\t\t\t\t\tcount += 1;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tlet sortObj = {};\n\t\t\t\t\t\tif (report.fields_sort.length) {\n\t\t\t\t\t\t\treport.fields_sort.forEach(sortField => {\n\t\t\t\t\t\t\t\tif (sortField.field.startsWith('gr_')) {\n\t\t\t\t\t\t\t\t\tsortObj['_id.' + sortField.field] = (sortField.order === 'asc' ? 1 : -1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tsortObj[sortField.field] = (sortField.order === 'asc' ? 1 : -1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tsortObj = null;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet rootOptions: PaginationOptions = {\n\t\t\t\t\t\t\tlimit: 0,\n\t\t\t\t\t\t\tskip: 0,\n\t\t\t\t\t\t\tfields: fieldsObj,\n\t\t\t\t\t\t\tsort: sortObj\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tlet filters = [];\n\t\t\t\t\t\treport.fields_filter.forEach(filterAnd => {\n\t\t\t\t\t\t\tlet ors = [];\n\t\t\t\t\t\t\tfilterAnd.ors.filter(a => !a.field.includes('.$.')).forEach(filter => {\n\t\t\t\t\t\t\t\tif (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {\n\t\t\t\t\t\t\t\t\tif (filter.condition === 'bw') {\n\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'Date' && filter.is_rolling) {\n\t\t\t\t\t\t\t\t\t\t\tlet startDate = null;\n\t\t\t\t\t\t\t\t\t\t\tlet endDate = null;\n\n\t\t\t\t\t\t\t\t\t\t\tif (filter.rolling_interval === 'Q1') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q2') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(2).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q3') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(3).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q4') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(4).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Today') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Yesterday') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(1, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Week') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Week') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Month') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Month') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last 30 Days') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(30, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(moment().quarter()).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('quarter').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Year') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Year') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'All') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = new Date(2017, 0, 1, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tendDate.setHours(23);\n\t\t\t\t\t\t\t\t\t\t\tendDate.setMinutes(59);\n\t\t\t\t\t\t\t\t\t\t\tendDate.setSeconds(59);\n\t\t\t\t\t\t\t\t\t\t\tendDate.setMilliseconds(999);\n\n\t\t\t\t\t\t\t\t\t\t\tors.push({$and: [{[filter.field]: {'$gte': startDate}}, {[filter.field]: {'$lte': endDate}}]});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tors.push({$and: [{[filter.field]: {'$gte': filter.value}}, {[filter.field]: {'$lte': filter.highValue}}]});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse if (filter.condition === 'nnull') {\n\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {'$exists': true}});\n\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {'$ne': null}});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {'$ne': ''}});\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse if (filter.condition === 'null') {\n\t\t\t\t\t\t\t\t\t\tors.push({[filter.field]: {'$eq': null}});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tif (Array.isArray(filter.value)) {\n\t\t\t\t\t\t\t\t\t\t\tif (filter.condition === 'ne') {\n\t\t\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tif (and.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(and[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\tlet or = [];\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tor.push({[filter.field]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tif (or.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$or: or});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(or[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tors.push({[filter.field]: {['$' + filter.condition]: filter.value}});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (ors.length) {\n\t\t\t\t\t\t\t\tfilters.push({$or: ors});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tthis.callMethodInternal('reportBuilderBuildTree', report.collection_root, (errCollTree, collectionTree) => {\n\t\t\t\t\t\t\tif (collectionTree) {\n\t\t\t\t\t\t\t\tcollectionTree.layers = [collectionTree];\n\t\t\t\t\n\t\t\t\t\t\t\t\tlet treeLeaves = [];\n\t\t\t\t\t\t\t\tlet allLeaves = [];\n\t\t\t\t\t\t\t\tgetTreeLeaves(collectionTree.children, treeLeaves);\n\t\t\t\t\t\t\t\tgetTreeLeaves(collectionTree.children, allLeaves, true);\n\n\t\t\t\t\t\t\t\tlet filterArrayFields = [];\n\t\t\t\t\t\t\t\tlet filterArrays = [];\n\t\t\t\t\t\t\t\treport.fields_filter.forEach(filterAnd => {\n\t\t\t\t\t\t\t\t\tlet ors = [];\n\t\t\t\t\t\t\t\t\tfilterAnd.ors.filter(a => a.field.includes('.$.')).forEach(filter => {\n\t\t\t\t\t\t\t\t\t\tif (allLeaves.filter(a => a.fieldPath === filter.field)[0]) {\n\t\t\t\t\t\t\t\t\t\t\tfilterArrayFields.push(allLeaves.filter(a => a.fieldPath === filter.field)[0]);\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tif (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {\n\t\t\t\t\t\t\t\t\t\t\tif (filter.condition === 'bw') {\n\t\t\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'Date' && filter.is_rolling) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet startDate = null;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet endDate = null;\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (filter.rolling_interval === 'Q1') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q2') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(2).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q3') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(3).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q4') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(4).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Today') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Yesterday') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(1, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Week') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Week') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Month') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Month') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last 30 Days') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(30, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(moment().quarter()).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('quarter').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Year') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Year') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'All') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = new Date(2017, 0, 1, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setHours(23);\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setMinutes(59);\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setSeconds(59);\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setMilliseconds(999);\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: [{[filter.field.replace(/\\.\\$/g, '')]: {'$gte': startDate}}, {[filter.field.replace(/\\.\\$/g, '')]: {'$lte': endDate}}]});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfilterArrays.push({$and: [{[filter.field.replace(/\\.\\$/g, '')]: {'$gte': filter.value}}, {[filter.field.replace(/\\.\\$/g, '')]: {'$lte': filter.highValue}}]});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.condition === 'nnull') {\n\t\t\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {'$exists': true}});\n\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {'$ne': null}});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {'$ne': ''}});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.condition === 'null') {\n\t\t\t\t\t\t\t\t\t\t\t\tors.push({[filter.field.replace(/\\.\\$/g, '')]: {'$eq': null}});\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\tif (Array.isArray(filter.value)) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (filter.condition === 'ne') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (and.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(and[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet or = [];\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tor.push({[filter.field.replace(/\\.\\$/g, '')]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (or.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$or: or});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(or[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({[filter.field.replace(/\\.\\$/g, '')]: {['$' + filter.condition]: filter.value}});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\tif (ors.length) {\n\t\t\t\t\t\t\t\t\t\tfilterArrays.push({$or: ors});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tthis.callMethodInternal('reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters, filterArrays, filterArrayFields, report.fields_selected, report.fields_custom, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type, (err, res) => {\n\t\t\t\t\t\t\t\t\tif (res && res[0]) {\n\t\t\t\t\t\t\t\t\t\tlet results = res[0].results;\n\t\t\t\t\t\t\t\t\t\tlet reportTotals = res[0].totals;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tif (report.type === 'List') {\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\tif ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined ).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id].toLocaleString();\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = (Math.round(result[field.id] * 100) / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' });\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id] === true ? 'True' : 'False';\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id] === true ? 'Yes' : 'No';\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id] === true ? 1 : 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('L');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('LT');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('LL');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('LLL');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).toDate().getTime();\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet lines: any = [];\n\n\t\t\t\t\t\t\t\t\t\t\tlet tmpHeaders = {};\n\n\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\ttmpHeaders[group.id] = group.columnName;\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(header => {\n\t\t\t\t\t\t\t\t\t\t\t\ttmpHeaders[header.columnName] = header.columnName;\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet wb = XLSX.utils.book_new();\n\n\t\t\t\t\t\t\t\t\t\t\tresults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmp = {};\n\t\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (Array.isArray(result._id[group.id])) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[group.columnName] = result._id[group.id].join(',');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (group.treeItem.fieldType === 'Number') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[group.columnName] = result._id[group.id] ? (typeof(result._id[group.id]) === 'string' ? parseFloat(result._id[group.id].replace(/,/g, '').replace(/\\$/g, '')) : result._id[group.id]) : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[group.columnName] = result._id[group.id] || '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(header => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (Array.isArray(result[header.id])) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[header.columnName] = result[header.id].join(',');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (header.fieldType === 'Number' || header.leafValueType === 'Count') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[header.columnName] = result[header.id] ? (typeof(result[header.id]) === 'string' ? parseFloat(result[header.id].replace(/,/g, '').replace(/\\$/g, '')) : result[header.id]) : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[header.columnName] = result[header.id] || '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tlines.push(tmp);\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet ws = XLSX.utils.json_to_sheet(lines);\n\t\t\t\t\t\t\t\t\t\t\tXLSX.utils.book_append_sheet(wb, ws, 'RB Data');\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tlet wbout = XLSX.write(wb, {bookType: 'xlsx', type: 'base64'});\n\n\t\t\t\t\t\t\t\t\t\t\tdata['emails'].forEach(email => {\n\t\t\t\t\t\t\t\t\t\t\t\tthis.sendEmail(email,\n\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name,\n\t\t\t\t\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t\t\t\t\t<b>` + this.serverConfig['CLIENT_NAME'] + ` Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>` + report.report_name + `<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>` + data['user'] + `<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>`,\n\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: wbout,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tencoding: 'base64'\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['MAIL_FROM_REPORTS'],\n\t\t\t\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if (report.type === 'Group') {\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\tresults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tmodifyDataTypeField(report, result, field, 1);\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet wb = new Excel.Workbook();\n\t\t\t\t\t\t\t\t\t\t\tlet ws = wb.addWorksheet('RB_1', {views: [{showGridLines: false}]});\n\t\t\t\t\t\t\t\t\t\t\twb.properties.date1904 = false;\n\t\t\t\t\t\t\t\t\t\t\twb.calcProperties.fullCalcOnLoad = true;\n\n\t\t\t\t\t\t\t\t\t\t\tlet currentRow = 1;\n\t\t\t\t\t\t\t\t\t\t\tlet row = ws.getRow(currentRow);\n\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Report Name:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = report.report_name;\n\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 1;\n\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Run Date:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = moment().format('LLL');\n\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 2;\n\n\t\t\t\t\t\t\t\t\t\t\tlet copy = deepCopy(results);\n\t\t\t\t\t\t\t\t\t\t\tlet widths = [];\n\t\t\t\t\t\t\t\t\t\t\tcopy.forEach(res => {\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentRow = tabGroupExcelRecursive(report, ws, currentRow, 1, res);\n\t\t\t\t\t\t\t\t\t\t\t\ttabGroupExcelWidthRecursive(report, 1, res, widths);\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tfor (let i = 1; i < ws.columns.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\tws.columns[i].width = widths[i - 1];\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tlet now = new Date();\n\n\t\t\t\t\t\t\t\t\t\t\twb.xlsx.writeBuffer().then(buffer => {\n\t\t\t\t\t\t\t\t\t\t\t\tdata['emails'].forEach(email => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.sendEmail(email,\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>` + this.serverConfig['CLIENT_NAME'] + ` Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>` + report.report_name + `<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>` + data['user'] + `<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilename: 'Group_Report_' + report.report_name + '_' + now.getFullYear() + '_' + (now.getMonth() + 1) + '_' + now.getDate() + '.xlsx',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: buffer\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['MAIL_FROM_REPORTS'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t}).catch(err => console.log('Error writing excel export', err));\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if (report.type === 'Dated') {\n\t\t\t\t\t\t\t\t\t\t\tlet datedUniqueDates = [];\n\t\t\t\t\t\t\t\t\t\t\tlet datedUniqueGroups = [];\n\t\t\t\t\t\t\t\t\t\t\tlet datedData = [];\n\t\t\t\t\t\t\t\t\t\t\tlet reportTotalGroups = [];\n\t\t\t\t\t\t\t\t\t\t\tlet reportTotalDates = [];\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Step 1: Handle quarterly dates if applicable\n\t\t\t\t\t\t\t\t\t\t\tif (report.date_interval === 'Quarterly') {\n\t\t\t\t\t\t\t\t\t\t\t\tresults.forEach(dataPt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (dataPt._id.month < 4) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (dataPt._id.month < 7) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 2;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (dataPt._id.month < 10) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 3;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 4;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tdelete dataPt._id.month;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\t// Deduplicate quarterly data\n\t\t\t\t\t\t\t\t\t\t\t\tfor (let i = results.length - 1; i >= 1; i--) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet dataPt = results[i];\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (results.filter(a => JSON.stringify(a._id) === JSON.stringify(dataPt._id)).length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet tmpData = results.filter(a => JSON.stringify(a._id) === JSON.stringify(dataPt._id))[0];\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(tmpData)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.filter(a => a !== '_id')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpData[key] += dataPt[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresults.splice(i, 1); // Remove the duplicate entry\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Step 2: Prepare unique groups\n\t\t\t\t\t\t\t\t\t\t\tlet tmpResults = deepCopy(results);\n\t\t\t\t\t\t\t\t\t\t\ttmpResults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.day;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.week;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.month;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.quarter;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.year;\n\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpGroup = {};\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttmpGroup[key] = result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tif (!datedUniqueGroups.find(a => JSON.stringify(a) === JSON.stringify(tmpGroup))) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueGroups.push(tmpGroup);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t// Step 3: Prepare unique dates\n\t\t\t\t\t\t\t\t\t\t\ttmpResults = deepCopy(results);\n\t\t\t\t\t\t\t\t\t\t\ttmpResults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t.filter(a => a !== 'second' && a !== 'hour' && a !== 'minute' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year')\n\t\t\t\t\t\t\t\t\t\t\t\t\t.forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpDate = {};\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttmpDate[key] = result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tif (!datedUniqueDates.find(a => JSON.stringify(a) === JSON.stringify(tmpDate))) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.push(tmpDate);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t// Build the date strings\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (!result.year) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = 'No Date';\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (report.date_interval === 'Seconds') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, result.hour, result.minute, result.second, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY HH:mm:ss');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Minutes') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, result.hour, result.minute, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY HH:mm');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Hours') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, result.hour, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY HH');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Daily') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Weekly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = moment().day('Monday').isoWeekYear(result.year).isoWeek(result.week).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateLast = moment().day('Sunday').isoWeekYear(result.year).isoWeek(result.week).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = 'Week #' + result.week + ' ' + result.year + ' (' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Monthly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, 1, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM YYYY');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Quarterly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = moment().quarter(result.quarter).year(result.year).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = 'Q' + result.quarter + ' ' + result.year;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Yearly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = result.year.toString();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates = datedUniqueDates.filter(a => !a.date)\n\t\t\t\t\t\t\t\t\t\t\t\t.concat(datedUniqueDates.filter(a => a.date).sort((a, b) => a.date.getTime() - b.date.getTime()));\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Step 4: Build datedData and reportTotalGroups\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(date => {\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpData = [];\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalDated = {};\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalCnt = {};\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalType = {};\n\n\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueGroups.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet result = results.find(a => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet match = true;\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// Match the group fields\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(group).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (a._id[key] !== group[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmatch = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// Match the date fields\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(date).filter(key => key !== 'date' && key !== 'dateLast' && key !== 'dateString').forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (a._id[key] !== date[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmatch = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn match;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (result) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpData.push(result);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id).filter(a => a).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (report.fields_total.filter(a => a.fields.includes(key)).length) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalDated[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] = result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] += result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalCnt[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] += 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result).filter(a => a && a !== '_id').forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (report.fields_total.filter(a => a.fields.includes(key)).length) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalDated[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] = result[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] += result[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalCnt[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] += 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpData.push(null);\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\t// Handle averaging for totals\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(tmpTotalType).forEach(totalKey => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (tmpTotalType[totalKey] === 'avg') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[totalKey] = Math.round(tmpTotalDated[totalKey] * 100) / 100;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\treportTotalDates.push(tmpTotalDated);\n\t\t\t\t\t\t\t\t\t\t\t\tdatedData.push(tmpData);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Calculate group-level totals\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueGroups.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalGroup = {};\n\t\t\t\t\t\t\t\t\t\t\t\tlet filteredData = results.filter(a => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet match = (!Object.keys(group).length || group._id === null) ? false : true;\n\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(group).filter(a => a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'second' && a !== 'minute' && a !== 'hour' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year').forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (a._id[key] !== group[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmatch = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn match;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\treport.fields_total.forEach(total => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttotal.fields.forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (filteredData.length) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalGroup[field] = filteredData.filter(a => a && a[field])\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.map(a => a[field])\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.reduce((a, b) => a + b, 0);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (total.type === 'avg') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalGroup[field] = Math.round(tmpTotalGroup[field] / filteredData.length * 100) / 100;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalGroup[field] = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\treportTotalGroups.push(tmpTotalGroup);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Step 5: Proceed with Excel generation using datedData and reportTotalGroups\n\t\t\t\t\t\t\t\t\t\t\tlet wb = new Excel.Workbook();\n\t\t\t\t\t\t\t\t\t\t\tlet ws = wb.addWorksheet('Dated_Report', {views: [{showGridLines: true}]});\n\t\t\t\t\t\t\t\t\t\t\twb.properties.date1904 = false;\n\t\t\t\t\t\t\t\t\t\t\twb.calcProperties.fullCalcOnLoad = true;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tlet currentRow = 1;\n\t\t\t\t\t\t\t\t\t\t\tlet currentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\tlet row = ws.getRow(currentRow);\n\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Report Name:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = report.report_name;\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 1;\n\n\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Run Date:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = moment().format('LLL');\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 2;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add group column headers\n\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = group.columnName;\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add field headers\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add the date interval headers\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(() => {\n\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(date => {\n\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = date.dateString;\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add totals headers\n\t\t\t\t\t\t\t\t\t\t\treport.fields_total.forEach(total => {\n\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = 'Totals - ' + toTitleCase(total.type);\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tcurrentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 1;\n\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Populate data for each group and field with date intervals\n\t\t\t\t\t\t\t\t\t\t\tfor (let i = 0; i < datedUniqueGroups.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\tlet group = datedUniqueGroups[i];\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tfor (let j = 0; j < report.fields_selected.filter(a => a.show).length; j++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet field = report.fields_selected.filter(a => a.show)[j];\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Populate group data\n\t\t\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(groupRow => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = (j === 0) ? group[groupRow.id] : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Populate field data\n\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = field.columnName;\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Populate date interval data for each field\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor (let k = 0; k < datedUniqueDates.length; k++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet result = datedData[k];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (result[i]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = result[i][field.id] ? result[i][field.id] : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Add totals for each field in the report\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor (let k = 0; k < report.fields_total.length; k++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet total = report.fields_total[k];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = reportTotalGroups[i][field.id] ? reportTotalGroups[i][field.id] : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentRow++; // Move to the next row for the next field\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add report totals at the bottom\n\t\t\t\t\t\t\t\t\t\t\tif (reportTotals) {\n\t\t\t\t\t\t\t\t\t\t\t\tfor (let i = 0; i < report.fields_total.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet total = report.fields_total[i];\n\t\t\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = toTitleCase(total.type) + ' Totals';\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol += report.groups_row.length; // Skip group columns\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Skip the date columns for the totals row\n\t\t\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = ''; // Skip the date cells\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Set totals in the correct fields\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor (let j = 0; j < report.fields_selected.filter(a => a.show).length; j++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet field = report.fields_selected.filter(a => a.show)[j];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = reportTotals[total.id + '_' + field.id] || '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentRow++; // Move to the next row for the next total\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Save the Excel file and send it via email\n\t\t\t\t\t\t\t\t\t\t\twb.xlsx.writeBuffer().then(buffer => {\n\t\t\t\t\t\t\t\t\t\t\t\tdata['emails'].forEach(email => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.sendEmail(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>${this.serverConfig['CLIENT_NAME']} Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>${report.report_name}<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>${data['user']}<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\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>`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: buffer\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['MAIL_FROM_REPORTS'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t}).catch(err => console.log('Error writing excel export', err));\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tthis.callMethodInternal('insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [\n\t\t\t\t\t\t\t\t\t\t\terr\n\t\t\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction getTreeLeaves(items, resArray, allowLookups = false) {\n\titems.forEach(item => {\n\t\tif (item.isLeaf) {\n\t\t\tresArray.push(item);\n\t\t}\n\t\telse {\n\t\t\tif (!item.lookup_collection || allowLookups) {\n\t\t\t\tgetTreeLeaves(item.children, resArray, allowLookups);\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction modifyDataTypeField(report, result, field, index) {\n\tif (index < report.groups_row.length) {\n\t\tresult = result['gr_' + (index + 1)];\n\t\tresult.forEach((tDataRes, tIndex) => {\n\t\t\tmodifyDataTypeField(report, tDataRes, field, index + 1)\n\t\t});\n\t}\n\telse {\n\t\tif (Array.isArray(result[field.id])) {\n\t\t\tresult[field.id].forEach((arr, arrIndex) => {\n\t\t\t\tif ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr.toLocaleString());\n\t\t\t\t}\n\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr.toString());\n\t\t\t\t}\n\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, (Math.round(arr * 100) / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' }));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr === true ? 'True' : 'False');\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr === true ? 'Yes' : 'No');\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr === true ? 1 : 0);\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('L'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('LT'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('MM/DD/YYYY h:mm A'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('LL'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('LLL'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).toDate().getTime());\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tif ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {\n\t\t\t\tresult[field.id] = result[field.id].toLocaleString();\n\t\t\t}\n\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {\n\t\t\t\tresult[field.id] = result[field.id].toString();\n\t\t\t}\n\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {\n\t\t\t\tresult[field.id] = (Math.round(result[field.id] * 100) / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' });\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {\n\t\t\t\tresult[field.id] = result[field.id] === true ? 'True' : 'False';\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {\n\t\t\t\tresult[field.id] = result[field.id] === true ? 'Yes' : 'No';\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {\n\t\t\t\tresult[field.id] = result[field.id] === true ? 1 : 0;\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('L');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('LT');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('LL');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('LLL');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).toDate().getTime();\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction tabGroupExcelRecursive(report, ws: Excel.Worksheet, currentRow, level, result) {\n\tlet row = ws.getRow(currentRow);\n\n\tif (level < report.groups_row.length) {\n\t\trow.getCell(2).fill = {\n\t\t\tfgColor: {argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff'},\n\t\t\ttype: 'pattern',\n\t\t\tpattern: 'solid'\n\t\t};\n\t\trow.getCell(2).font = {\n\t\t\tcolor: {argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000'},\n\t\t\tname: 'Arial',\n\t\t\tbold: true,\n\t\t\tsize: 14\n\t\t};\n\n\t\trow.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];\n\t\tws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);\n\t\t\n\t\trow.getCell(2).border = {\n\t\t\ttop: {style:'thick'},\n\t\t\tleft: {style:'thick'},\n\t\t\tright: {style: 'thick'}\n\t\t};\n\n\t\tif (report.fields_total.length) {\n\t\t\treport.fields_total.forEach(total => {\n\t\t\t\tcurrentRow += 1;\n\t\t\t\trow = ws.getRow(currentRow);\n\n\t\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\t\tif (total.fields.includes(field.id)) {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).value = field.columnName;\n\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\tsize: 10\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t\t}\n\t\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t\t}\n\n\t\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\t\tleft: {style:'thick'}\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t\t\n\t\t// Totals\n\t\treport.fields_total.forEach(total => {\n\t\t\tcurrentRow += 1;\n\t\t\trow = ws.getRow(currentRow);\n\n\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\tif (total.fields.includes(field.id)) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];\n\n\t\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\tsize: 10\n\t\t\t\t\t};\n\n\t\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t\t}\n\t\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tleft: {style:'thick'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'},\n\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\t\n\t\tcurrentRow += 1;\n\n\t\tresult = result['gr_' + (level + 1)];\n\t\tresult.forEach((tDataRes, tIndex) => {\n\t\t\tcurrentRow = tabGroupExcelRecursive(report, ws, currentRow, level + 1, tDataRes);\n\t\t});\n\t}\n\telse {\n\t\trow.getCell(2).fill = {\n\t\t\tfgColor: {argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff'},\n\t\t\ttype: 'pattern',\n\t\t\tpattern: 'solid'\n\t\t};\n\t\trow.getCell(2).font = {\n\t\t\tcolor: {argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000'},\n\t\t\tname: 'Arial',\n\t\t\tbold: true,\n\t\t\tsize: 12\n\t\t};\n\n\t\trow.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];\n\t\tws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);\n\n\t\trow.getCell(2).border = {\n\t\t\ttop: {style:'thick'},\n\t\t\tleft: {style:'thick'},\n\t\t\tright: {style: 'thick'}\n\t\t};\n\n\t\tcurrentRow += 1;\n\t\trow = ws.getRow(currentRow);\n\t\t// Headers\n\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\trow.getCell(fieldIndex + 2).value = field.columnName;\n\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\tname: 'Arial',\n\t\t\t\tbold: true,\n\t\t\t\tsize: 10\n\t\t\t};\n\n\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t}\n\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t}\n\n\t\t\tif (fieldIndex === 0) {\n\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\tleft: {style:'thick'}\n\t\t\t\t};\n\t\t\t}\n\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\n\t\t// Data\n\t\tresult['f_0'].forEach((res, resIndex) => {\n\t\t\tcurrentRow += 1;\n\t\t\trow = ws.getRow(currentRow);\n\n\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\tif (field.fieldType === 'Number' && typeof(result[field.id][resIndex] === 'string') && result[field.id][resIndex]) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = parseFloat(result[field.id][resIndex].replace(new RegExp(/\\,/g), '').replace(new RegExp(/\\$/g), ''));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = result[field.id][resIndex];\n\t\t\t\t}\n\n\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t}\n\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t}\n\n\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\tname: 'Arial',\n\t\t\t\t\tsize: 10\n\t\t\t\t};\n\n\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\tleft: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\t\n\t\t// Totals\n\t\treport.fields_total.forEach(total => {\n\t\t\tcurrentRow += 1;\n\t\t\trow = ws.getRow(currentRow);\n\n\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\tif (total.fields.includes(field.id)) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];\n\n\t\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\tsize: 10\n\t\t\t\t\t};\n\n\t\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t\t}\n\t\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tleft: {style:'thick'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'},\n\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\treturn currentRow + 1;\n}\n\nfunction tabGroupExcelWidthRecursive(report, level, result, cols) {\n\tif (level < report.groups_row.length) {\n\t\tresult = result['gr_' + (level + 1)];\n\t\tresult.forEach((tDataRes, tIndex) => {\n\t\t\tcols = tabGroupExcelWidthRecursive(report, level + 1, tDataRes, cols);\n\t\t});\n\t}\n\telse {\n\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\tif (Array.isArray(result[field.id])) {\n\t\t\t\tresult[field.id].forEach(res => {\n\t\t\t\t\tlet length = 10;\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\tlength = res.length + 3;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!cols[fieldIndex]) {\n\t\t\t\t\t\tcols[fieldIndex] = Math.max(10, field.columnName.length);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (length > cols[fieldIndex]) {\n\t\t\t\t\t\tcols[fieldIndex] = length;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet res = result[field.id];\n\n\t\t\t\tif (res) {\n\t\t\t\t\tlength = res.length + 3;\n\t\t\t\t}\n\n\t\t\t\tif (!cols[fieldIndex]) {\n\t\t\t\t\tcols[fieldIndex] = Math.max(10, field.columnName.length);\n\t\t\t\t}\n\n\t\t\t\tif (length > cols[fieldIndex]) {\n\t\t\t\t\tcols[fieldIndex] = length;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\treturn cols;\n}"]}
1
+ {"version":3,"sources":["../../src/methods/cron-jobs.ts"],"names":["report_builder_report_collection_1","require","simpl_schema_1","common_1","moment","XLSX","Excel","file_collection_1","cron_job_collection_1","loadCronJobMethods","methodManager","methods","cronEmailMergedDocsCleanUp","function","_this","this","Promise","resolve","reject","__awaiter","Files","find","$and","type","createdAt","$lte","subtract","toDate","files","_a","sent","length","callMethodInternal","deleteMany","_id","$in","map","a","stuckCronJob","fiveMin","CronJobs","running","updatedAt","cronJobs","updateMany","$set","reportbuilderCronJob","check","default","data","Object","blackbox","ReportBuilderReports","findById","report","fields_selected","forEach","field","fieldData","fieldPath","replace","split","fieldPathObj","i","_b","groups_row","fieldsObj_1","count_1","collection_name","collection_root","mergeDeep","sortIndex","fields_sort","findIndex","sortObj_1","sortField","startsWith","order","rootOptions_1","limit","skip","fields","sort","filters_1","fields_filter","filterAnd","ors","filter","includes","endDate","and","and_1","or_1","condition","value","Array","isArray","fieldType","is_rolling","startDate","rolling_interval","startOf","quarter","endOf","Date","setHours","setMinutes","setSeconds","setMilliseconds","push","$gte","_c","_d","highValue","_e","$exists","_f","$ne","_g","_h","$eq","filt","$or","_j","_k","errCollTree","collectionTree","allLeaves_1","filterArrayFields_1","filterArrays_1","layers","getTreeLeaves","children","and_2","or_2","fields_custom","fields_total","fields_link","id_date_field","date_interval","group_type","err","res","results_1","results","reportTotals","totals","show","leafValueType","leafFormatType","id","undefined","result","format","getTime","Math","round","toLocaleString","style","currency","lines_1","wb","group","columnName","header","utils","book_new","ws","tmp","join","treeItem","parseFloat","json_to_sheet","wbout_1","book_append_sheet","write","bookType","email","sendEmail","serverConfig","report_name","filename","content","encoding","modifyDataTypeField","ws_1","Workbook","addWorksheet","views","showGridLines","currentRow_1","properties","date1904","calcProperties","fullCalcOnLoad","row","getRow","copy","getCell","font","name","bold","size","deepCopy","widths_1","tabGroupExcelRecursive","tabGroupExcelWidthRecursive","columns","width","now_1","xlsx","writeBuffer","then","buffer","getFullYear","getMonth","getDate","catch","console","log","datedUniqueDates_1","datedUniqueGroups_1","datedData_1","reportTotalGroups_1","reportTotalDates_1","dataPt","month","tmpData_1","JSON","stringify","keys","key","splice","tmpResults","day","week","year","tmpGroup","tmpDate","date","hour","minute","second","dateString","isoWeekYear","isoWeek","dateLast","toString","concat","b","tmpData","tmpTotalDated","tmpTotalCnt","tmpTotalType","match","totalKey","tmpTotalGroup","filteredData","total","reduce","currentRow","currentCol_1","row_1","toTitleCase","j","groupRow","k","items","resArray","allowLookups","item","isLeaf","lookup_collection","index","tDataRes","tIndex","arr","arrIndex","level","fill","fgColor","argb","fill_color","pattern","color","font_color","mergeCells","$col$row","border","top","left","right","fieldIndex","numFmt","bottom","resIndex","RegExp","cols","max","exports"],"mappings":"k8CACAA,oC,yFAAAC,QAAA,iDAAA,GACAC,eAAAD,QAAA,cAAA,EACAE,SAAAF,QAAA,gBAAA,EAEAG,OAAAH,QAAA,iBAAA,EACAI,KAAAJ,QAAA,MAAA,EACAK,MAAAL,QAAA,SAAA,EACAM,kBAAAN,QAAA,gCAAA,EACAO,sBAAAP,QAAA,oCAAA,EAEA,SAAgBQ,mBAAmBC,GAClCA,EAAcC,QAAQ,CACrBC,2BAA4B,CAC3BC,SAAU,WAAA,IAAAC,EAAAC,KACT,OAAO,IAAIC,QAAQ,SAAOC,EAASC,GAAM,OAAAC,UAAAL,EAAA,KAAA,EAAA,KAAA,EAAA,W,iEAC5B,MAAA,CAAA,EAAMP,kBAAAa,MAAMC,KAAK,CAACC,KAAM,CAAC,CAACC,KAAM,mBAAmB,EAAG,CAACC,UAAW,CAACC,KAAMrB,OAAM,EAAGsB,SAAS,EAAG,KAAK,EAAEC,OAAM,CAAE,CAAC,EAAE,CAAC,G,cAAzHC,EAAQC,EAAAC,KAAA,GAEFC,SACThB,KAAKiB,mBAAmB,aAAa,EACrCzB,kBAAAa,MAAMa,WAAW,CAACC,IAAK,CAACC,IAAKP,EAAMQ,IAAI,SAAAC,GAAK,OAAAA,EAAEH,GAAF,CAAK,CAAC,CAAC,CAAC,GAGrDjB,EAAQ,CAAA,CAAI,E,SACZ,CACF,C,EAEDqB,aAAc,CACbzB,SAAU,WAAA,IAAAC,EAAAC,KACT,OAAO,IAAIC,QAAQ,SAAOC,EAASC,GAAM,OAAAC,UAAAL,EAAA,KAAA,EAAA,KAAA,EAAA,W,iEAEzB,OADXyB,EAAUnC,OAAM,EAAGsB,SAAS,EAAG,SAAS,EAA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C1D,IAkBKtJ,EAlBD/C,MAAMC,QAAQwD,EAAO/F,EAAM6F,GAAG,EACjCE,EAAO/F,EAAM6F,IAAI9F,QAAQ,SAAAsF,GACxB,IAAI/G,EAAS,GAET+G,IACH/G,EAAS+G,EAAI/G,OAAS,GAGlB0Q,EAAKL,KACTK,EAAKL,GAAczI,KAAK+I,IAAI,GAAIjP,EAAM0G,WAAWpI,MAAM,GAGpDA,EAAS0Q,EAAKL,KACjBK,EAAKL,GAAcrQ,EAErB,CAAC,IAGG+G,EAAMU,EAAO/F,EAAM6F,OAGtBvH,OAAS+G,EAAI/G,OAAS,GAGlB0Q,EAAKL,KACTK,EAAKL,GAAczI,KAAK+I,IAAI,GAAIjP,EAAM0G,WAAWpI,MAAM,GAGpDA,OAAS0Q,EAAKL,KACjBK,EAAKL,GAAcrQ,QAGtB,CAAC,EAGK0Q,CACR,CA/6CAE,QAAAlS,mBAAAA","file":"cron-jobs.js","sourcesContent":["import { MethodManager } from '../managers/method.manager';\nimport { ReportBuilderReports } from '../collections/report-builder-report.collection';\nimport SimpleSchema from 'simpl-schema';\nimport { mergeDeep, deepCopy, toTitleCase } from '../util/common';\nimport { PaginationOptions } from '../models/pagination.model';\nimport * as moment from 'moment-timezone';\nimport * as XLSX from 'xlsx';\nimport * as Excel from 'exceljs';\nimport { Files } from '../collections/file.collection';\nimport { CronJobs } from '../collections/cron-job.collection';\n\nexport function loadCronJobMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcronEmailMergedDocsCleanUp: {\n\t\t\tfunction: function() {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet files = await Files.find({$and: [{type: 'Email Merged Docs'}, {createdAt: {$lte: moment().subtract(1, 'day').toDate()}}]});\n\t\t\t\t\t\n\t\t\t\t\tif (files.length) {\n\t\t\t\t\t\tthis.callMethodInternal('deleteFiles');\n\t\t\t\t\t\tFiles.deleteMany({_id: {$in: files.map(a => a._id)}});\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tstuckCronJob: {\n\t\t\tfunction: function() {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet fiveMin = moment().subtract(5, 'minutes').toDate();\n\t\t\t\t\tlet cronJobs = await CronJobs.find({running: true, updatedAt: {$lte: fiveMin}});\n\n\t\t\t\t\tif (cronJobs.length) {\n\t\t\t\t\t\tCronJobs.updateMany({_id: {$in: cronJobs.map(a => a._id)}}, {$set: {running: false}});\n\t\t\t\t\t}\n\n\t\t\t\t\tresolve(true);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\treportbuilderCronJob: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tdata: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(data: Object) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet report = await ReportBuilderReports.findById(data['id_report']);\n\n\t\t\t\t\treport.fields_selected.forEach((field: any) => {\n\t\t\t\t\t\tlet dotPath = field.fieldPath.replace(/\\.\\$/g, '');\n\t\t\t\t\t\tlet fieldData = dotPath.split('.');\n\t\t\t\t\t\tfield.fieldPathObj = null;\n\t\t\t\t\t\tfor (let i = fieldData.length - 1; i >= 0; i--) {\n\t\t\t\t\t\t\tif (!field.fieldPathObj) {\n\t\t\t\t\t\t\t\tfield.fieldPathObj = {[fieldData[i]]: 1};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tfield.fieldPathObj = {[fieldData[i]]: field.fieldPathObj};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tif ((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length)) {\n\t\t\t\t\t\tlet fieldsObj = {};\n\n\t\t\t\t\t\tlet count = 0;\n\n\t\t\t\t\t\treport.fields_selected.forEach((field: any) => {\n\t\t\t\t\t\t\tif (field.collection_name === report.collection_root) {\n\t\t\t\t\t\t\t\tfieldsObj = mergeDeep(fieldsObj, field.fieldPathObj);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tlet sortIndex = report.fields_sort.findIndex(a => a.field === field['id']);\n\n\t\t\t\t\t\t\tif (sortIndex >= 0) {\n\t\t\t\t\t\t\t\treport.fields_sort[sortIndex].field = ('f_' + count);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tfield['id'] = 'f_' + count;\n\n\t\t\t\t\t\t\tcount += 1;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tlet sortObj = {};\n\t\t\t\t\t\tif (report.fields_sort.length) {\n\t\t\t\t\t\t\treport.fields_sort.forEach(sortField => {\n\t\t\t\t\t\t\t\tif (sortField.field.startsWith('gr_')) {\n\t\t\t\t\t\t\t\t\tsortObj['_id.' + sortField.field] = (sortField.order === 'asc' ? 1 : -1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tsortObj[sortField.field] = (sortField.order === 'asc' ? 1 : -1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tsortObj = null;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet rootOptions: PaginationOptions = {\n\t\t\t\t\t\t\tlimit: 0,\n\t\t\t\t\t\t\tskip: 0,\n\t\t\t\t\t\t\tfields: fieldsObj,\n\t\t\t\t\t\t\tsort: sortObj\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tlet filters = [];\n\t\t\t\t\t\treport.fields_filter.forEach(filterAnd => {\n\t\t\t\t\t\t\tlet ors = [];\n\t\t\t\t\t\t\tfilterAnd.ors.filter(a => !a.field.includes('.$.')).forEach(filter => {\n\t\t\t\t\t\t\t\tif (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {\n\t\t\t\t\t\t\t\t\tif (filter.condition === 'bw') {\n\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'Date' && filter.is_rolling) {\n\t\t\t\t\t\t\t\t\t\t\tlet startDate = null;\n\t\t\t\t\t\t\t\t\t\t\tlet endDate = null;\n\n\t\t\t\t\t\t\t\t\t\t\tif (filter.rolling_interval === 'Q1') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q2') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(2).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q3') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(3).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q4') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(4).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Today') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Yesterday') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(1, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Week') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Week') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Month') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Month') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last 30 Days') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(30, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(moment().quarter()).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('quarter').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Year') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Year') {\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'All') {\n\t\t\t\t\t\t\t\t\t\t\t\tstartDate = new Date(2017, 0, 1, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tendDate.setHours(23);\n\t\t\t\t\t\t\t\t\t\t\tendDate.setMinutes(59);\n\t\t\t\t\t\t\t\t\t\t\tendDate.setSeconds(59);\n\t\t\t\t\t\t\t\t\t\t\tendDate.setMilliseconds(999);\n\n\t\t\t\t\t\t\t\t\t\t\tors.push({$and: [{[filter.field]: {'$gte': startDate}}, {[filter.field]: {'$lte': endDate}}]});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tors.push({$and: [{[filter.field]: {'$gte': filter.value}}, {[filter.field]: {'$lte': filter.highValue}}]});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse if (filter.condition === 'nnull') {\n\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {'$exists': true}});\n\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {'$ne': null}});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {'$ne': ''}});\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse if (filter.condition === 'null') {\n\t\t\t\t\t\t\t\t\t\tors.push({[filter.field]: {'$eq': null}});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tif (Array.isArray(filter.value)) {\n\t\t\t\t\t\t\t\t\t\t\tif (filter.condition === 'ne') {\n\t\t\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tif (and.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(and[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\tlet or = [];\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tor.push({[filter.field]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tif (or.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$or: or});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(or[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tors.push({[filter.field]: {['$' + filter.condition]: filter.value}});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (ors.length) {\n\t\t\t\t\t\t\t\tfilters.push({$or: ors});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tthis.callMethodInternal('reportBuilderBuildTree', report.collection_root, (errCollTree, collectionTree) => {\n\t\t\t\t\t\t\tif (collectionTree) {\n\t\t\t\t\t\t\t\tcollectionTree.layers = [collectionTree];\n\t\t\t\t\n\t\t\t\t\t\t\t\tlet treeLeaves = [];\n\t\t\t\t\t\t\t\tlet allLeaves = [];\n\t\t\t\t\t\t\t\tgetTreeLeaves(collectionTree.children, treeLeaves);\n\t\t\t\t\t\t\t\tgetTreeLeaves(collectionTree.children, allLeaves, true);\n\n\t\t\t\t\t\t\t\tlet filterArrayFields = [];\n\t\t\t\t\t\t\t\tlet filterArrays = [];\n\t\t\t\t\t\t\t\treport.fields_filter.forEach(filterAnd => {\n\t\t\t\t\t\t\t\t\tlet ors = [];\n\t\t\t\t\t\t\t\t\tfilterAnd.ors.filter(a => a.field.includes('.$.')).forEach(filter => {\n\t\t\t\t\t\t\t\t\t\tif (allLeaves.filter(a => a.fieldPath === filter.field)[0]) {\n\t\t\t\t\t\t\t\t\t\t\tfilterArrayFields.push(allLeaves.filter(a => a.fieldPath === filter.field)[0]);\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tif (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {\n\t\t\t\t\t\t\t\t\t\t\tif (filter.condition === 'bw') {\n\t\t\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'Date' && filter.is_rolling) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet startDate = null;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet endDate = null;\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (filter.rolling_interval === 'Q1') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q2') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(2).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q3') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(3).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Q4') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(4).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Today') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Yesterday') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(1, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Week') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Week') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('isoWeek').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Month') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Month') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('month').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last 30 Days') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().subtract(30, 'days').startOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').quarter(moment().quarter()).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Quarter') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('quarter').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Year') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment().startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'Last Year') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = moment(endDate).startOf('year').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (filter.rolling_interval === 'All') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartDate = new Date(2017, 0, 1, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tendDate = moment().endOf('day').toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setHours(23);\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setMinutes(59);\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setSeconds(59);\n\t\t\t\t\t\t\t\t\t\t\t\t\tendDate.setMilliseconds(999);\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: [{[filter.field.replace(/\\.\\$/g, '')]: {'$gte': startDate}}, {[filter.field.replace(/\\.\\$/g, '')]: {'$lte': endDate}}]});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tfilterArrays.push({$and: [{[filter.field.replace(/\\.\\$/g, '')]: {'$gte': filter.value}}, {[filter.field.replace(/\\.\\$/g, '')]: {'$lte': filter.highValue}}]});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.condition === 'nnull') {\n\t\t\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {'$exists': true}});\n\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {'$ne': null}});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tif (filter.fieldType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {'$ne': ''}});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if (filter.condition === 'null') {\n\t\t\t\t\t\t\t\t\t\t\t\tors.push({[filter.field.replace(/\\.\\$/g, '')]: {'$eq': null}});\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\tif (Array.isArray(filter.value)) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (filter.condition === 'ne') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet and = [];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand.push({[filter.field.replace(/\\.\\$/g, '')]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (and.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$and: and});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(and[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet or = [];\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilter.value.forEach(filt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tor.push({[filter.field.replace(/\\.\\$/g, '')]: {['$' + filter.condition]: (Array.isArray(filt) ? filt[0] : filt)}});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (or.length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({$or: or});\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tors.push(or[0]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tors.push({[filter.field.replace(/\\.\\$/g, '')]: {['$' + filter.condition]: filter.value}});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\tif (ors.length) {\n\t\t\t\t\t\t\t\t\t\tfilterArrays.push({$or: ors});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tthis.callMethodInternal('reportBuilderGetResults', report.type, report.collection_root, rootOptions, filters, filterArrays, filterArrayFields, report.fields_selected, report.fields_custom, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type, (err, res) => {\n\t\t\t\t\t\t\t\t\tif (res && res[0]) {\n\t\t\t\t\t\t\t\t\t\tlet results = res[0].results;\n\t\t\t\t\t\t\t\t\t\tlet reportTotals = res[0].totals;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tif (report.type === 'List') {\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\tif ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined ).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id].toLocaleString();\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = (Math.round(result[field.id] * 100) / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' });\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id] === true ? 'True' : 'False';\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id] === true ? 'Yes' : 'No';\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = result[field.id] === true ? 1 : 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('L');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('LT');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('LL');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).format('LLL');\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresults.filter(a => a[field.id] !== null && a[field.id] !== undefined).forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult[field.id] = moment(result[field.id]).toDate().getTime();\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet lines: any = [];\n\n\t\t\t\t\t\t\t\t\t\t\tlet tmpHeaders = {};\n\n\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\ttmpHeaders[group.id] = group.columnName;\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(header => {\n\t\t\t\t\t\t\t\t\t\t\t\ttmpHeaders[header.columnName] = header.columnName;\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet wb = XLSX.utils.book_new();\n\n\t\t\t\t\t\t\t\t\t\t\tresults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmp = {};\n\t\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (Array.isArray(result._id[group.id])) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[group.columnName] = result._id[group.id].join(',');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (group.treeItem.fieldType === 'Number') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[group.columnName] = result._id[group.id] ? (typeof(result._id[group.id]) === 'string' ? parseFloat(result._id[group.id].replace(/,/g, '').replace(/\\$/g, '')) : result._id[group.id]) : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[group.columnName] = result._id[group.id] || '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(header => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (Array.isArray(result[header.id])) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[header.columnName] = result[header.id].join(',');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (header.fieldType === 'Number' || header.leafValueType === 'Count') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[header.columnName] = result[header.id] ? (typeof(result[header.id]) === 'string' ? parseFloat(result[header.id].replace(/,/g, '').replace(/\\$/g, '')) : result[header.id]) : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmp[header.columnName] = result[header.id] || '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tlines.push(tmp);\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet ws = XLSX.utils.json_to_sheet(lines);\n\t\t\t\t\t\t\t\t\t\t\tXLSX.utils.book_append_sheet(wb, ws, 'RB Data');\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tlet wbout = XLSX.write(wb, {bookType: 'xlsx', type: 'base64'});\n\n\t\t\t\t\t\t\t\t\t\t\tdata['emails'].forEach(email => {\n\t\t\t\t\t\t\t\t\t\t\t\tthis.sendEmail(email,\n\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name,\n\t\t\t\t\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t\t\t\t\t<b>` + this.serverConfig['CLIENT_NAME'] + ` Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>` + report.report_name + `<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>` + data['user'] + `<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>`,\n\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: wbout,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tencoding: 'base64'\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['MAIL_FROM_REPORTS'],\n\t\t\t\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if (report.type === 'Group') {\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\tresults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tmodifyDataTypeField(report, result, field, 1);\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tlet wb = new Excel.Workbook();\n\t\t\t\t\t\t\t\t\t\t\tlet ws = wb.addWorksheet('RB_1', {views: [{showGridLines: false}]});\n\t\t\t\t\t\t\t\t\t\t\twb.properties.date1904 = false;\n\t\t\t\t\t\t\t\t\t\t\twb.calcProperties.fullCalcOnLoad = true;\n\n\t\t\t\t\t\t\t\t\t\t\tlet currentRow = 1;\n\t\t\t\t\t\t\t\t\t\t\tlet row = ws.getRow(currentRow);\n\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Report Name:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = report.report_name;\n\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 1;\n\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Run Date:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = moment().format('LLL');\n\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 2;\n\n\t\t\t\t\t\t\t\t\t\t\tlet copy = deepCopy(results);\n\t\t\t\t\t\t\t\t\t\t\tlet widths = [];\n\t\t\t\t\t\t\t\t\t\t\tcopy.forEach(res => {\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentRow = tabGroupExcelRecursive(report, ws, currentRow, 1, res);\n\t\t\t\t\t\t\t\t\t\t\t\ttabGroupExcelWidthRecursive(report, 1, res, widths);\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tfor (let i = 1; i < ws.columns.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\tws.columns[i].width = widths[i - 1];\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tlet now = new Date();\n\n\t\t\t\t\t\t\t\t\t\t\twb.xlsx.writeBuffer().then(buffer => {\n\t\t\t\t\t\t\t\t\t\t\t\tdata['emails'].forEach(email => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.sendEmail(email,\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>` + this.serverConfig['CLIENT_NAME'] + ` Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>` + report.report_name + `<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>` + data['user'] + `<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilename: 'Group_Report_' + report.report_name + '_' + now.getFullYear() + '_' + (now.getMonth() + 1) + '_' + now.getDate() + '.xlsx',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: buffer\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['MAIL_FROM_REPORTS'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t}).catch(err => console.log('Error writing excel export', err));\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse if (report.type === 'Dated') {\n\t\t\t\t\t\t\t\t\t\t\tlet datedUniqueDates = [];\n\t\t\t\t\t\t\t\t\t\t\tlet datedUniqueGroups = [];\n\t\t\t\t\t\t\t\t\t\t\tlet datedData = [];\n\t\t\t\t\t\t\t\t\t\t\tlet reportTotalGroups = [];\n\t\t\t\t\t\t\t\t\t\t\tlet reportTotalDates = [];\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Step 1: Handle quarterly dates if applicable\n\t\t\t\t\t\t\t\t\t\t\tif (report.date_interval === 'Quarterly') {\n\t\t\t\t\t\t\t\t\t\t\t\tresults.forEach(dataPt => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (dataPt._id.month < 4) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (dataPt._id.month < 7) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 2;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (dataPt._id.month < 10) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 3;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdataPt._id.quarter = 4;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tdelete dataPt._id.month;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\t// Deduplicate quarterly data\n\t\t\t\t\t\t\t\t\t\t\t\tfor (let i = results.length - 1; i >= 1; i--) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet dataPt = results[i];\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (results.filter(a => JSON.stringify(a._id) === JSON.stringify(dataPt._id)).length > 1) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet tmpData = results.filter(a => JSON.stringify(a._id) === JSON.stringify(dataPt._id))[0];\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(tmpData)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.filter(a => a !== '_id')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpData[key] += dataPt[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresults.splice(i, 1); // Remove the duplicate entry\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Step 2: Prepare unique groups\n\t\t\t\t\t\t\t\t\t\t\tlet tmpResults = deepCopy(results);\n\t\t\t\t\t\t\t\t\t\t\ttmpResults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.day;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.week;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.month;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.quarter;\n\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id.year;\n\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpGroup = {};\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttmpGroup[key] = result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tif (!datedUniqueGroups.find(a => JSON.stringify(a) === JSON.stringify(tmpGroup))) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueGroups.push(tmpGroup);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t// Step 3: Prepare unique dates\n\t\t\t\t\t\t\t\t\t\t\ttmpResults = deepCopy(results);\n\t\t\t\t\t\t\t\t\t\t\ttmpResults.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t.filter(a => a !== 'second' && a !== 'hour' && a !== 'minute' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year')\n\t\t\t\t\t\t\t\t\t\t\t\t\t.forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdelete result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpDate = {};\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttmpDate[key] = result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\tif (!datedUniqueDates.find(a => JSON.stringify(a) === JSON.stringify(tmpDate))) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.push(tmpDate);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t// Build the date strings\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(result => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (!result.year) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = 'No Date';\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (report.date_interval === 'Seconds') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, result.hour, result.minute, result.second, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY HH:mm:ss');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Minutes') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, result.hour, result.minute, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY HH:mm');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Hours') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, result.hour, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY HH');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Daily') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, result.day, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM DD YYYY');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Weekly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = moment().day('Monday').isoWeekYear(result.year).isoWeek(result.week).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateLast = moment().day('Sunday').isoWeekYear(result.year).isoWeek(result.week).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = 'Week #' + result.week + ' ' + result.year + ' (' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Monthly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year, result.month - 1, 1, 0, 0, 0, 0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = moment(result.date).format('MMM YYYY');\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Quarterly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = moment().quarter(result.quarter).year(result.year).toDate();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = 'Q' + result.quarter + ' ' + result.year;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if (report.date_interval === 'Yearly') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.date = new Date(result.year);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tresult.dateString = result.year.toString();\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates = datedUniqueDates.filter(a => !a.date)\n\t\t\t\t\t\t\t\t\t\t\t\t.concat(datedUniqueDates.filter(a => a.date).sort((a, b) => a.date.getTime() - b.date.getTime()));\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Step 4: Build datedData and reportTotalGroups\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(date => {\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpData = [];\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalDated = {};\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalCnt = {};\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalType = {};\n\n\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueGroups.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet result = results.find(a => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet match = true;\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// Match the group fields\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(group).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (a._id[key] !== group[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmatch = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// Match the date fields\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(date).filter(key => key !== 'date' && key !== 'dateLast' && key !== 'dateString').forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (a._id[key] !== date[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmatch = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn match;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (result) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpData.push(result);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result._id).filter(a => a).forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (report.fields_total.filter(a => a.fields.includes(key)).length) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalDated[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] = result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] += result._id[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalCnt[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] += 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(result).filter(a => a && a !== '_id').forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (report.fields_total.filter(a => a.fields.includes(key)).length) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalDated[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] = result[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[key] += result[key];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!tmpTotalCnt[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalCnt[key] += 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalType[key] = report.fields_total.filter(a => a.fields.includes(key))[0].type;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpData.push(null);\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\t// Handle averaging for totals\n\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(tmpTotalType).forEach(totalKey => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (tmpTotalType[totalKey] === 'avg') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalDated[totalKey] = Math.round(tmpTotalDated[totalKey] * 100) / 100;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\treportTotalDates.push(tmpTotalDated);\n\t\t\t\t\t\t\t\t\t\t\t\tdatedData.push(tmpData);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Calculate group-level totals\n\t\t\t\t\t\t\t\t\t\t\tdatedUniqueGroups.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\tlet tmpTotalGroup = {};\n\t\t\t\t\t\t\t\t\t\t\t\tlet filteredData = results.filter(a => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet match = (!Object.keys(group).length || group._id === null) ? false : true;\n\t\t\t\t\t\t\t\t\t\t\t\t\tObject.keys(group).filter(a => a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'second' && a !== 'minute' && a !== 'hour' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year').forEach(key => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (a._id[key] !== group[key]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmatch = false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn match;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\treport.fields_total.forEach(total => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttotal.fields.forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (filteredData.length) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalGroup[field] = filteredData.filter(a => a && a[field])\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.map(a => a[field])\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t.reduce((a, b) => a + b, 0);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (total.type === 'avg') {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalGroup[field] = Math.round(tmpTotalGroup[field] / filteredData.length * 100) / 100;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttmpTotalGroup[field] = 0;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\treportTotalGroups.push(tmpTotalGroup);\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Step 5: Proceed with Excel generation using datedData and reportTotalGroups\n\t\t\t\t\t\t\t\t\t\t\tlet wb = new Excel.Workbook();\n\t\t\t\t\t\t\t\t\t\t\tlet ws = wb.addWorksheet('Dated_Report', {views: [{showGridLines: true}]});\n\t\t\t\t\t\t\t\t\t\t\twb.properties.date1904 = false;\n\t\t\t\t\t\t\t\t\t\t\twb.calcProperties.fullCalcOnLoad = true;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tlet currentRow = 1;\n\t\t\t\t\t\t\t\t\t\t\tlet currentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\tlet row = ws.getRow(currentRow);\n\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Report Name:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = report.report_name;\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 1;\n\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).font = {\n\t\t\t\t\t\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\t\t\t\t\t\tsize: 14\n\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(2).value = 'Run Date:';\n\t\t\t\t\t\t\t\t\t\t\trow.getCell(4).value = moment().format('LLL');\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 2;\n\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add group column headers\n\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(group => {\n\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = group.columnName;\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add field headers\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(field => {\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add the date interval headers\n\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(() => {\n\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(date => {\n\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = date.dateString;\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add totals headers\n\t\t\t\t\t\t\t\t\t\t\treport.fields_total.forEach(total => {\n\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = 'Totals - ' + toTitleCase(total.type);\n\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tcurrentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\tcurrentRow += 1;\n\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Populate data for each group and field with date intervals\n\t\t\t\t\t\t\t\t\t\t\tfor (let i = 0; i < datedUniqueGroups.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\tlet group = datedUniqueGroups[i];\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\tfor (let j = 0; j < report.fields_selected.filter(a => a.show).length; j++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet field = report.fields_selected.filter(a => a.show)[j];\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Populate group data\n\t\t\t\t\t\t\t\t\t\t\t\t\treport.groups_row.forEach(groupRow => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = (j === 0) ? group[groupRow.id] : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Populate field data\n\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = field.columnName;\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Populate date interval data for each field\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor (let k = 0; k < datedUniqueDates.length; k++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet result = datedData[k];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (result[i]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = result[i][field.id] ? result[i][field.id] : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Add totals for each field in the report\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor (let k = 0; k < report.fields_total.length; k++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet total = report.fields_total[k];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = reportTotalGroups[i][field.id] ? reportTotalGroups[i][field.id] : '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentRow++; // Move to the next row for the next field\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Add report totals at the bottom\n\t\t\t\t\t\t\t\t\t\t\tif (reportTotals) {\n\t\t\t\t\t\t\t\t\t\t\t\tfor (let i = 0; i < report.fields_total.length; i++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet total = report.fields_total[i];\n\t\t\t\t\t\t\t\t\t\t\t\t\trow = ws.getRow(currentRow);\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol = 1;\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = toTitleCase(total.type) + ' Totals';\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol += report.groups_row.length; // Skip group columns\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Skip the date columns for the totals row\n\t\t\t\t\t\t\t\t\t\t\t\t\treport.fields_selected.filter(a => a.show).forEach(() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol += 1;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tdatedUniqueDates.forEach(() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t// Set totals in the correct fields\n\t\t\t\t\t\t\t\t\t\t\t\t\tfor (let j = 0; j < report.fields_selected.filter(a => a.show).length; j++) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tlet field = report.fields_selected.filter(a => a.show)[j];\n\t\t\t\t\t\t\t\t\t\t\t\t\t\trow.getCell(currentCol).value = reportTotals[total.id + '_' + field.id] || '';\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentCol++;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentRow++; // Move to the next row for the next total\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t// Save the Excel file and send it via email\n\t\t\t\t\t\t\t\t\t\t\twb.xlsx.writeBuffer().then(buffer => {\n\t\t\t\t\t\t\t\t\t\t\t\tdata['emails'].forEach(email => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tthis.sendEmail(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\temail,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>${this.serverConfig['CLIENT_NAME']} Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>${report.report_name}<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>${data['user']}<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\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>`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfilename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: buffer\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.serverConfig['MAIL_FROM_REPORTS'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t}).catch(err => console.log('Error writing excel export', err));\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tresolve(true);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\tthis.callMethodInternal('insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [\n\t\t\t\t\t\t\t\t\t\t\terr\n\t\t\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\treject(err);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction getTreeLeaves(items, resArray, allowLookups = false) {\n\titems.forEach(item => {\n\t\tif (item.isLeaf) {\n\t\t\tresArray.push(item);\n\t\t}\n\t\telse {\n\t\t\tif (!item.lookup_collection || allowLookups) {\n\t\t\t\tgetTreeLeaves(item.children, resArray, allowLookups);\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction modifyDataTypeField(report, result, field, index) {\n\tif (index < report.groups_row.length) {\n\t\tresult = result['gr_' + (index + 1)];\n\t\tresult.forEach((tDataRes, tIndex) => {\n\t\t\tmodifyDataTypeField(report, tDataRes, field, index + 1)\n\t\t});\n\t}\n\telse {\n\t\tif (Array.isArray(result[field.id])) {\n\t\t\tresult[field.id].forEach((arr, arrIndex) => {\n\t\t\t\tif ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr.toLocaleString());\n\t\t\t\t}\n\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr.toString());\n\t\t\t\t}\n\t\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, (Math.round(arr * 100) / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' }));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr === true ? 'True' : 'False');\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr === true ? 'Yes' : 'No');\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, arr === true ? 1 : 0);\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('L'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('LT'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('MM/DD/YYYY h:mm A'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('LL'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).format('LLL'));\n\t\t\t\t}\n\t\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {\n\t\t\t\t\tresult[field.id].splice(arrIndex, 1, moment(arr).toDate().getTime());\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tif ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {\n\t\t\t\tresult[field.id] = result[field.id].toLocaleString();\n\t\t\t}\n\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {\n\t\t\t\tresult[field.id] = result[field.id].toString();\n\t\t\t}\n\t\t\telse if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {\n\t\t\t\tresult[field.id] = (Math.round(result[field.id] * 100) / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' });\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {\n\t\t\t\tresult[field.id] = result[field.id] === true ? 'True' : 'False';\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {\n\t\t\t\tresult[field.id] = result[field.id] === true ? 'Yes' : 'No';\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {\n\t\t\t\tresult[field.id] = result[field.id] === true ? 1 : 0;\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('L');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('LT');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('LL');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).format('LLL');\n\t\t\t}\n\t\t\telse if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {\n\t\t\t\tresult[field.id] = moment(result[field.id]).toDate().getTime();\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction tabGroupExcelRecursive(report, ws: Excel.Worksheet, currentRow, level, result) {\n\tlet row = ws.getRow(currentRow);\n\n\tif (level < report.groups_row.length) {\n\t\trow.getCell(2).fill = {\n\t\t\tfgColor: {argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff'},\n\t\t\ttype: 'pattern',\n\t\t\tpattern: 'solid'\n\t\t};\n\t\trow.getCell(2).font = {\n\t\t\tcolor: {argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000'},\n\t\t\tname: 'Arial',\n\t\t\tbold: true,\n\t\t\tsize: 14\n\t\t};\n\n\t\trow.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];\n\t\tws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);\n\t\t\n\t\trow.getCell(2).border = {\n\t\t\ttop: {style:'thick'},\n\t\t\tleft: {style:'thick'},\n\t\t\tright: {style: 'thick'}\n\t\t};\n\n\t\tif (report.fields_total.length) {\n\t\t\treport.fields_total.forEach(total => {\n\t\t\t\tcurrentRow += 1;\n\t\t\t\trow = ws.getRow(currentRow);\n\n\t\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\t\tif (total.fields.includes(field.id)) {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).value = field.columnName;\n\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\t\tsize: 10\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t\t}\n\t\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t\t}\n\n\t\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\t\tleft: {style:'thick'}\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\t\t\n\t\t// Totals\n\t\treport.fields_total.forEach(total => {\n\t\t\tcurrentRow += 1;\n\t\t\trow = ws.getRow(currentRow);\n\n\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\tif (total.fields.includes(field.id)) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];\n\n\t\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\tsize: 10\n\t\t\t\t\t};\n\n\t\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t\t}\n\t\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tleft: {style:'thick'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'},\n\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\t\n\t\tcurrentRow += 1;\n\n\t\tresult = result['gr_' + (level + 1)];\n\t\tresult.forEach((tDataRes, tIndex) => {\n\t\t\tcurrentRow = tabGroupExcelRecursive(report, ws, currentRow, level + 1, tDataRes);\n\t\t});\n\t}\n\telse {\n\t\trow.getCell(2).fill = {\n\t\t\tfgColor: {argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff'},\n\t\t\ttype: 'pattern',\n\t\t\tpattern: 'solid'\n\t\t};\n\t\trow.getCell(2).font = {\n\t\t\tcolor: {argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000'},\n\t\t\tname: 'Arial',\n\t\t\tbold: true,\n\t\t\tsize: 12\n\t\t};\n\n\t\trow.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];\n\t\tws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(a => a.show).length + 1).$col$row);\n\n\t\trow.getCell(2).border = {\n\t\t\ttop: {style:'thick'},\n\t\t\tleft: {style:'thick'},\n\t\t\tright: {style: 'thick'}\n\t\t};\n\n\t\tcurrentRow += 1;\n\t\trow = ws.getRow(currentRow);\n\t\t// Headers\n\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\trow.getCell(fieldIndex + 2).value = field.columnName;\n\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\tname: 'Arial',\n\t\t\t\tbold: true,\n\t\t\t\tsize: 10\n\t\t\t};\n\n\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t}\n\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t}\n\n\t\t\tif (fieldIndex === 0) {\n\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\tleft: {style:'thick'}\n\t\t\t\t};\n\t\t\t}\n\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\n\t\t// Data\n\t\tresult['f_0'].forEach((res, resIndex) => {\n\t\t\tcurrentRow += 1;\n\t\t\trow = ws.getRow(currentRow);\n\n\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\tif (field.fieldType === 'Number' && typeof(result[field.id][resIndex] === 'string') && result[field.id][resIndex]) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = parseFloat(result[field.id][resIndex].replace(new RegExp(/\\,/g), '').replace(new RegExp(/\\$/g), ''));\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = result[field.id][resIndex];\n\t\t\t\t}\n\n\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t}\n\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t}\n\n\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\tname: 'Arial',\n\t\t\t\t\tsize: 10\n\t\t\t\t};\n\n\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\tleft: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\t\n\t\t// Totals\n\t\treport.fields_total.forEach(total => {\n\t\t\tcurrentRow += 1;\n\t\t\trow = ws.getRow(currentRow);\n\n\t\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\t\tif (total.fields.includes(field.id)) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];\n\n\t\t\t\t\trow.getCell(fieldIndex + 2).font = {\n\t\t\t\t\t\tname: 'Arial',\n\t\t\t\t\t\tbold: true,\n\t\t\t\t\t\tsize: 10\n\t\t\t\t\t};\n\n\t\t\t\t\tif (field.leafFormatType === 'Currency') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '\"$\"#,##0.00';\n\t\t\t\t\t}\n\t\t\t\t\telse if (field.leafFormatType === 'Number') {\n\t\t\t\t\t\trow.getCell(fieldIndex + 2).numFmt = '#,##0';\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (fieldIndex === 0) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tleft: {style:'thick'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse if (fieldIndex === report.fields_selected.filter(a => a.show).length - 1) {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'},\n\t\t\t\t\t\tright: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\trow.getCell(fieldIndex + 2).border = {\n\t\t\t\t\t\ttop: {style:'thin'},\n\t\t\t\t\t\tbottom: {style:'thick'}\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\treturn currentRow + 1;\n}\n\nfunction tabGroupExcelWidthRecursive(report, level, result, cols) {\n\tif (level < report.groups_row.length) {\n\t\tresult = result['gr_' + (level + 1)];\n\t\tresult.forEach((tDataRes, tIndex) => {\n\t\t\tcols = tabGroupExcelWidthRecursive(report, level + 1, tDataRes, cols);\n\t\t});\n\t}\n\telse {\n\t\treport.fields_selected.filter(a => a.show).forEach((field, fieldIndex) => {\n\t\t\tif (Array.isArray(result[field.id])) {\n\t\t\t\tresult[field.id].forEach(res => {\n\t\t\t\t\tlet length = 10;\n\n\t\t\t\t\tif (res) {\n\t\t\t\t\t\tlength = res.length + 3;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!cols[fieldIndex]) {\n\t\t\t\t\t\tcols[fieldIndex] = Math.max(10, field.columnName.length);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (length > cols[fieldIndex]) {\n\t\t\t\t\t\tcols[fieldIndex] = length;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet res = result[field.id];\n\n\t\t\t\tif (res) {\n\t\t\t\t\tlength = res.length + 3;\n\t\t\t\t}\n\n\t\t\t\tif (!cols[fieldIndex]) {\n\t\t\t\t\tcols[fieldIndex] = Math.max(10, field.columnName.length);\n\t\t\t\t}\n\n\t\t\t\tif (length > cols[fieldIndex]) {\n\t\t\t\t\tcols[fieldIndex] = length;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\treturn cols;\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "20.2.12",
3
+ "version": "20.2.13",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",