Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 59d8862..645135f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xdaae=['status','count','limit','Content-Range','json','apply','reject','then','destroy','get','CustomReports','UserProfileResource','end','error','stack','name','send','index','map','AnalyticCustomReport','rawAttributes','type','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','filter','where','merge','VIRTUAL','options','includeAll','include','rows','catch','find','create','body','user','role','Reports','UserProfileSection','userProfileId','autoAssociation','update','preview','join','SUM(%s)','COUNT(%s)','MAX(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','group','field','condition','value','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','select','from','table','MetricId','function','replace','format','orderBy','DESC','alias','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','clone','debug','Limited\x20Query:','toString','sequelize','SELECT','left_join','right_join','cross_join','COUNT(DISTINCT\x20%s)','MIN(%s)','DATE(%s)','length','metric','groupBy','No\x20available\x20data','output','web','fullPath','generate','csv','custom','AnalyticExtractedReport','.calldate\x20BETWEEN\x20?\x20AND\x20?','endDate','info','fork','countTable','COUNT(*)','QueryTypes','run','params','runReport','findAll','html-pdf','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus'];(function(_0x2a56ad,_0x2b94bf){var _0x425175=function(_0x342f20){while(--_0x342f20){_0x2a56ad['push'](_0x2a56ad['shift']());}};_0x425175(++_0x2b94bf);}(_0xdaae,0x1c1));var _0xedaa=function(_0x15adc6,_0xbc8322){_0x15adc6=_0x15adc6-0x0;var _0x3bb841=_0xdaae[_0x15adc6];return _0x3bb841;};'use strict';var pdf=require(_0xedaa('0x0'));var emlformat=require(_0xedaa('0x1'));var rimraf=require(_0xedaa('0x2'));var zipdir=require(_0xedaa('0x3'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xedaa('0x4'));var BPromise=require(_0xedaa('0x5'));var Mustache=require(_0xedaa('0x6'));var util=require(_0xedaa('0x7'));var path=require(_0xedaa('0x8'));var sox=require('sox');var csv=require(_0xedaa('0x9'));var ejs=require(_0xedaa('0xa'));var fs=require('fs');var _=require(_0xedaa('0xb'));var squel=require(_0xedaa('0xc'));var crypto=require(_0xedaa('0xd'));var jsforce=require(_0xedaa('0xe'));var deskjs=require(_0xedaa('0xf'));var toCsv=require(_0xedaa('0x9'));var querystring=require('querystring');var Papa=require(_0xedaa('0x10'));var Redis=require('ioredis');var authService=require(_0xedaa('0x11'));var qs=require(_0xedaa('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xedaa('0x13'))(_0xedaa('0x14'));var utils=require(_0xedaa('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xedaa('0x16'));var db=require(_0xedaa('0x17'))['db'];var dbH=require('../../mysqldb')['dbH'];function respondWithStatusCode(_0x42ceb0,_0x46beaf){_0x46beaf=_0x46beaf||0xcc;return function(_0x1fc5d0){if(_0x1fc5d0){return _0x42ceb0[_0xedaa('0x18')](_0x46beaf);}return _0x42ceb0[_0xedaa('0x19')](_0x46beaf)['end']();};}function respondWithResult(_0x41d115,_0x1dd096){_0x1dd096=_0x1dd096||0xc8;return function(_0x6c99fa){if(_0x6c99fa){return _0x41d115['status'](_0x1dd096)['json'](_0x6c99fa);}};}function respondWithFilteredResult(_0x1017de,_0x597092){return function(_0x454be3){if(_0x454be3){var _0x18f340=_0x454be3[_0xedaa('0x1a')],_0x8cf030=_0x597092['offset'],_0x2dea2c=_0x597092['offset']+_0x597092[_0xedaa('0x1b')],_0x5bf518;if(_0x2dea2c>=_0x18f340){_0x2dea2c=_0x18f340;_0x5bf518=0xc8;}else{_0x5bf518=0xce;}_0x1017de[_0xedaa('0x19')](_0x5bf518);return _0x1017de['set'](_0xedaa('0x1c'),_0x8cf030+'-'+_0x2dea2c+'/'+_0x18f340)[_0xedaa('0x1d')](_0x454be3);}return null;};}function patchUpdates(_0x25af96){return function(_0x454e5a){try{jsonpatch[_0xedaa('0x1e')](_0x454e5a,_0x25af96,!![]);}catch(_0x29b0f2){return BPromise[_0xedaa('0x1f')](_0x29b0f2);}return _0x454e5a['save']();};}function saveUpdates(_0x25237e,_0x5b3338){return function(_0x4ccb4b){if(_0x4ccb4b){return _0x4ccb4b['update'](_0x25237e)[_0xedaa('0x20')](function(_0x5b9ebe){return _0x5b9ebe;});}return null;};}function removeEntity(_0x3afa02,_0x39c6c9){return function(_0x59cbe9){if(_0x59cbe9){return _0x59cbe9[_0xedaa('0x21')]()[_0xedaa('0x20')](function(){var _0x34892b=_0x59cbe9[_0xedaa('0x22')]({'plain':!![]});var _0x52f7f7=_0xedaa('0x23');return db[_0xedaa('0x24')]['destroy']({'where':{'type':_0x52f7f7,'resourceId':_0x34892b['id']}})[_0xedaa('0x20')](function(){return _0x59cbe9;});})['then'](function(){_0x3afa02['status'](0xcc)[_0xedaa('0x25')]();});}};}function handleEntityNotFound(_0x3fd21f,_0x4f44f0){return function(_0x22bc20){if(!_0x22bc20){_0x3fd21f[_0xedaa('0x18')](0x194);}return _0x22bc20;};}function handleError(_0x1e920e,_0x3bc1ad){_0x3bc1ad=_0x3bc1ad||0x1f4;return function(_0x2ad383){logger[_0xedaa('0x26')](_0x2ad383[_0xedaa('0x27')]);if(_0x2ad383[_0xedaa('0x28')]){delete _0x2ad383[_0xedaa('0x28')];}_0x1e920e[_0xedaa('0x19')](_0x3bc1ad)[_0xedaa('0x29')](_0x2ad383);};}exports[_0xedaa('0x2a')]=function(_0x1e9609,_0x14e99c){var _0x5408bf={},_0x1c88f5={},_0x437ad2={'count':0x0,'rows':[]};var _0x28ee0a=_[_0xedaa('0x2b')](db[_0xedaa('0x2c')][_0xedaa('0x2d')],function(_0x95f21c){return{'name':_0x95f21c['fieldName'],'type':_0x95f21c[_0xedaa('0x2e')]['key']};});_0x1c88f5['model']=_[_0xedaa('0x2b')](_0x28ee0a,_0xedaa('0x28'));_0x1c88f5[_0xedaa('0x2f')]=_[_0xedaa('0x30')](_0x1e9609[_0xedaa('0x2f')]);_0x1c88f5[_0xedaa('0x31')]=_[_0xedaa('0x32')](_0x1c88f5[_0xedaa('0x33')],_0x1c88f5[_0xedaa('0x2f')]);_0x5408bf[_0xedaa('0x34')]=_[_0xedaa('0x32')](_0x1c88f5[_0xedaa('0x33')],qs[_0xedaa('0x35')](_0x1e9609[_0xedaa('0x2f')]['fields']));_0x5408bf[_0xedaa('0x34')]=_0x5408bf[_0xedaa('0x34')]['length']?_0x5408bf[_0xedaa('0x34')]:_0x1c88f5['model'];if(!_0x1e9609[_0xedaa('0x2f')][_0xedaa('0x36')](_0xedaa('0x37'))){_0x5408bf['limit']=qs[_0xedaa('0x1b')](_0x1e9609[_0xedaa('0x2f')][_0xedaa('0x1b')]);_0x5408bf['offset']=qs[_0xedaa('0x38')](_0x1e9609[_0xedaa('0x2f')]['offset']);}_0x5408bf[_0xedaa('0x39')]=qs[_0xedaa('0x3a')](_0x1e9609[_0xedaa('0x2f')][_0xedaa('0x3a')]);_0x5408bf['where']=qs[_0xedaa('0x31')](_['pick'](_0x1e9609[_0xedaa('0x2f')],_0x1c88f5[_0xedaa('0x31')]),_0x28ee0a);if(_0x1e9609[_0xedaa('0x2f')][_0xedaa('0x3b')]){_0x5408bf[_0xedaa('0x3c')]=_[_0xedaa('0x3d')](_0x5408bf[_0xedaa('0x3c')],{'$or':_['map'](_0x28ee0a,function(_0x1a0123){if(_0x1a0123['type']!==_0xedaa('0x3e')){var _0x2b1b13={};_0x2b1b13[_0x1a0123[_0xedaa('0x28')]]={'$like':'%'+_0x1e9609[_0xedaa('0x2f')]['filter']+'%'};return _0x2b1b13;}})});}_0x5408bf=_[_0xedaa('0x3d')]({},_0x5408bf,_0x1e9609[_0xedaa('0x3f')]);var _0x4d4c30={'where':_0x5408bf['where']};return db[_0xedaa('0x2c')]['count'](_0x4d4c30)[_0xedaa('0x20')](function(_0xbc8cb1){_0x437ad2['count']=_0xbc8cb1;if(_0x1e9609[_0xedaa('0x2f')][_0xedaa('0x40')]){_0x5408bf[_0xedaa('0x41')]=[{'all':!![]}];}return db[_0xedaa('0x2c')]['findAll'](_0x5408bf);})[_0xedaa('0x20')](function(_0x407002){_0x437ad2[_0xedaa('0x42')]=_0x407002;return _0x437ad2;})['then'](respondWithFilteredResult(_0x14e99c,_0x5408bf))[_0xedaa('0x43')](handleError(_0x14e99c,null));};exports['show']=function(_0x31d0ac,_0x2092dc){var _0x1a90db={'raw':![],'where':{'id':_0x31d0ac['params']['id']}},_0x43d3a3={};_0x43d3a3[_0xedaa('0x33')]=_['keys'](db[_0xedaa('0x2c')][_0xedaa('0x2d')]);_0x43d3a3[_0xedaa('0x2f')]=_[_0xedaa('0x30')](_0x31d0ac[_0xedaa('0x2f')]);_0x43d3a3[_0xedaa('0x31')]=_[_0xedaa('0x32')](_0x43d3a3[_0xedaa('0x33')],_0x43d3a3[_0xedaa('0x2f')]);_0x1a90db[_0xedaa('0x34')]=_['intersection'](_0x43d3a3[_0xedaa('0x33')],qs[_0xedaa('0x35')](_0x31d0ac['query'][_0xedaa('0x35')]));_0x1a90db[_0xedaa('0x34')]=_0x1a90db[_0xedaa('0x34')]['length']?_0x1a90db[_0xedaa('0x34')]:_0x43d3a3['model'];if(_0x31d0ac['query']['includeAll']){_0x1a90db[_0xedaa('0x41')]=[{'all':!![]}];}_0x1a90db=_[_0xedaa('0x3d')]({},_0x1a90db,_0x31d0ac[_0xedaa('0x3f')]);return db[_0xedaa('0x2c')][_0xedaa('0x44')](_0x1a90db)['then'](handleEntityNotFound(_0x2092dc,null))[_0xedaa('0x20')](respondWithResult(_0x2092dc,null))[_0xedaa('0x43')](handleError(_0x2092dc,null));};exports['create']=function(_0x1929c7,_0x1ae28d){return db[_0xedaa('0x2c')][_0xedaa('0x45')](_0x1929c7[_0xedaa('0x46')],{})[_0xedaa('0x20')](function(_0x58bccf){var _0x50dbcf=_0x1929c7[_0xedaa('0x47')][_0xedaa('0x22')]({'plain':!![]});if(!_0x50dbcf)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x50dbcf[_0xedaa('0x48')]===_0xedaa('0x47')){var _0x29067f=_0x58bccf[_0xedaa('0x22')]({'plain':!![]});var _0x5bebbc=_0xedaa('0x49');return db[_0xedaa('0x4a')][_0xedaa('0x44')]({'where':{'name':_0x5bebbc,'userProfileId':_0x50dbcf[_0xedaa('0x4b')]},'raw':!![]})[_0xedaa('0x20')](function(_0x43bfc3){if(_0x43bfc3&&_0x43bfc3[_0xedaa('0x4c')]===0x0){return db[_0xedaa('0x24')][_0xedaa('0x45')]({'name':_0x29067f['name'],'resourceId':_0x29067f['id'],'type':_0xedaa('0x23'),'sectionId':_0x43bfc3['id']},{})[_0xedaa('0x20')](function(){return _0x58bccf;});}else{return _0x58bccf;}})[_0xedaa('0x43')](function(_0x4ef492){logger[_0xedaa('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4ef492);throw _0x4ef492;});}return _0x58bccf;})[_0xedaa('0x20')](respondWithResult(_0x1ae28d,0xc9))[_0xedaa('0x43')](handleError(_0x1ae28d,null));};exports[_0xedaa('0x4d')]=function(_0x540140,_0x217a48){if(_0x540140['body']['id']){delete _0x540140['body']['id'];}return db[_0xedaa('0x2c')][_0xedaa('0x44')]({'where':{'id':_0x540140['params']['id']}})['then'](handleEntityNotFound(_0x217a48,null))['then'](saveUpdates(_0x540140[_0xedaa('0x46')],null))[_0xedaa('0x20')](respondWithResult(_0x217a48,null))[_0xedaa('0x43')](handleError(_0x217a48,null));};exports['destroy']=function(_0x3cb762,_0x212e83){return db[_0xedaa('0x2c')][_0xedaa('0x44')]({'where':{'id':_0x3cb762['params']['id']}})[_0xedaa('0x20')](handleEntityNotFound(_0x212e83,null))['then'](removeEntity(_0x212e83,null))[_0xedaa('0x43')](handleError(_0x212e83,null));};exports[_0xedaa('0x4e')]=function(_0x4e053e,_0x7a08c1){var _0x29fd60=0xa;var _0x47267a=[_0xedaa('0x4f'),'left_join','right_join','cross_join'];var _0x2d55b7={'SUM':_0xedaa('0x50'),'COUNT':_0xedaa('0x51'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0xedaa('0x52'),'MIN':'MIN(%s)','AVG':_0xedaa('0x53'),'GROUP_CONCAT':_0xedaa('0x54'),'GROUP_CONCAT ASC':_0xedaa('0x55'),'GROUP_CONCAT DESC':_0xedaa('0x56')};var _0x2dcc0f={'SEC_TO_TIME':_0xedaa('0x57'),'DATE':'DATE(%s)','HOUR':'HOUR(%s)','ROUND':_0xedaa('0x58'),'UNIX_TIMESTAMP':_0xedaa('0x59')};var _0x181627=function(_0x5c512d){return!_[_0xedaa('0x5a')]([_0xedaa('0x5b'),_0xedaa('0x5c'),_0xedaa('0x5d'),_0xedaa('0x5e')],_0x5c512d);};var _0x1cf73a=function(_0x2b7909){if(!_0x2b7909||!_0x2b7909[_0xedaa('0x5f')]['length']){return'';}for(var _0xf3b1a4='(',_0xa22bd6=0x0;_0xa22bd6<_0x2b7909[_0xedaa('0x5f')]['length'];_0xa22bd6+=0x1){_0xa22bd6>0x0&&(_0xf3b1a4+='\x20'+_0x2b7909[_0xedaa('0x60')]+'\x20');_0xf3b1a4+=_0x2b7909[_0xedaa('0x5f')][_0xa22bd6][_0xedaa('0x61')]?_0x1cf73a(_0x2b7909[_0xedaa('0x5f')][_0xa22bd6][_0xedaa('0x61')]):_0x2b7909['rules'][_0xa22bd6][_0xedaa('0x62')]+'\x20'+_0x2b7909[_0xedaa('0x5f')][_0xa22bd6][_0xedaa('0x63')]+(_0x181627(_0x2b7909[_0xedaa('0x5f')][_0xa22bd6][_0xedaa('0x63')])?'\x20'+_0x2b7909[_0xedaa('0x5f')][_0xa22bd6][_0xedaa('0x64')]:'');}return _0xf3b1a4+')';};var _0x4588bb={'where':{'id':_0x4e053e['params']['id']}},_0x33642b,_0x23cf4c,_0x2bc87c,_0x43325f,_0x510a0a;_0x4588bb=_[_0xedaa('0x3d')]({},_0x4588bb,_0x4e053e[_0xedaa('0x3f')]);return db['AnalyticCustomReport']['find'](_0x4588bb)[_0xedaa('0x20')](function(_0x81f5fd){if(_0x81f5fd){_0x33642b=_0x81f5fd;return _0x81f5fd[_0xedaa('0x65')]();}return null;})[_0xedaa('0x20')](function(_0x395221){if(_0x395221){if(!_0x395221['length']){throw new db[(_0xedaa('0x66'))][(_0xedaa('0x67'))](_0xedaa('0x68'),0x193);}_0x23cf4c=_0x395221;return db[_0xedaa('0x69')]['findAll']({'raw':!![]});}return null;})[_0xedaa('0x20')](function(_0x4f69c4){if(_0x4f69c4){_0x2bc87c=_[_0xedaa('0x6a')](_0x4f69c4,'id');var _0x3600cd;var _0x2a3d78=squel[_0xedaa('0x6b')]();_0x2a3d78[_0xedaa('0x6c')](_0x33642b[_0xedaa('0x6d')]);for(var _0x319c55=0x0;_0x319c55<_0x23cf4c['length'];_0x319c55+=0x1){_0x3600cd=_0x23cf4c[_0x319c55][_0xedaa('0x6e')]?_0x2bc87c[_0x23cf4c[_0x319c55][_0xedaa('0x6e')]]['metric']:_0x23cf4c[_0x319c55]['field'];_0x3600cd=_0x23cf4c[_0x319c55][_0xedaa('0x6f')]?_[_0xedaa('0x70')](_0x2d55b7[_0x23cf4c[_0x319c55]['function']],'%s',_0x3600cd):_0x3600cd;_0x3600cd=_0x23cf4c[_0x319c55][_0xedaa('0x71')]?_[_0xedaa('0x70')](_0x2dcc0f[_0x23cf4c[_0x319c55][_0xedaa('0x71')]],'%s',_0x3600cd):_0x3600cd;if(_0x23cf4c[_0x319c55]['groupBy']){_0x2a3d78['group'](_0x3600cd);}_0x23cf4c[_0x319c55][_0xedaa('0x72')]&&_0x2a3d78['order'](_0x3600cd,_0x23cf4c[_0x319c55][_0xedaa('0x72')]===_0xedaa('0x73')?![]:!![]);_0x2a3d78[_0xedaa('0x62')](_0x3600cd,_0x23cf4c[_0x319c55][_0xedaa('0x74')]||_0x3600cd);}if(_0x33642b[_0xedaa('0x75')]){_0x33642b[_0xedaa('0x75')]=JSON[_0xedaa('0x76')](_0x33642b['joins']);for(var _0x36e893=0x0;_0x36e893<_0x33642b[_0xedaa('0x75')]['length'];_0x36e893+=0x1){if(_0x33642b[_0xedaa('0x75')][_0x36e893]['type']&&_[_0xedaa('0x5a')](_0x47267a,_0x33642b['joins'][_0x36e893][_0xedaa('0x2e')])&&_0x33642b[_0xedaa('0x75')][_0x36e893][_0xedaa('0x77')]&&_0x33642b[_0xedaa('0x75')][_0x36e893][_0xedaa('0x78')]&&_0x33642b[_0xedaa('0x75')][_0x36e893][_0xedaa('0x79')]){_0x2a3d78[_0x33642b[_0xedaa('0x75')][_0x36e893][_0xedaa('0x2e')]](_0x33642b[_0xedaa('0x75')][_0x36e893][_0xedaa('0x78')],null,util[_0xedaa('0x71')](_0xedaa('0x7a'),_0x33642b['table'],_0x33642b[_0xedaa('0x75')][_0x36e893][_0xedaa('0x77')],_0x33642b[_0xedaa('0x75')][_0x36e893]['foreignTable'],_0x33642b[_0xedaa('0x75')][_0x36e893]['foreignKey']));}}}if(_0x33642b[_0xedaa('0x7b')]){_0x33642b['conditions']=JSON['parse'](_0x33642b['conditions']);_0x2a3d78['where'](_0x1cf73a(_0x33642b[_0xedaa('0x7b')][_0xedaa('0x61')]));}_0x510a0a=_0x2a3d78[_0xedaa('0x7c')]();_0x2a3d78['limit'](_0x29fd60);_0x2a3d78[_0xedaa('0x38')](0x0);logger[_0xedaa('0x7d')](_0xedaa('0x7e'),_0x2a3d78['toString']());return db['sequelize']['query'](_0x2a3d78[_0xedaa('0x7f')](),{'type':db[_0xedaa('0x80')]['QueryTypes'][_0xedaa('0x81')]});}})[_0xedaa('0x20')](respondWithResult(_0x7a08c1,null))[_0xedaa('0x43')](handleError(_0x7a08c1,null));};function runReport(_0x3c0185,_0x12cf17,_0x330b5a){var _0x37d1a4=_0x12cf17[_0xedaa('0x28')];var _0xf8a1dd=0xa;var _0x9e78ba=[_0xedaa('0x4f'),_0xedaa('0x82'),_0xedaa('0x83'),_0xedaa('0x84')];var _0x220910={'SUM':'SUM(%s)','COUNT':_0xedaa('0x51'),'COUNT DISTINCT':_0xedaa('0x85'),'MAX':_0xedaa('0x52'),'MIN':_0xedaa('0x86'),'AVG':_0xedaa('0x53'),'GROUP_CONCAT':_0xedaa('0x54'),'GROUP_CONCAT ASC':_0xedaa('0x55'),'GROUP_CONCAT DESC':_0xedaa('0x56')};var _0x5a7ccc={'SEC_TO_TIME':_0xedaa('0x57'),'DATE':_0xedaa('0x87'),'HOUR':'HOUR(%s)','ROUND':_0xedaa('0x58'),'UNIX_TIMESTAMP':_0xedaa('0x59')};var _0x5c4ff7=function(_0x2c6a21){return!_[_0xedaa('0x5a')]([_0xedaa('0x5b'),_0xedaa('0x5c'),_0xedaa('0x5d'),_0xedaa('0x5e')],_0x2c6a21);};var _0x203446=function(_0x117d48){if(!_0x117d48||!_0x117d48['rules']['length']){return'';}for(var _0x22a2eb='(',_0x188ff1=0x0;_0x188ff1<_0x117d48['rules'][_0xedaa('0x88')];_0x188ff1+=0x1){_0x188ff1>0x0&&(_0x22a2eb+='\x20'+_0x117d48[_0xedaa('0x60')]+'\x20');_0x22a2eb+=_0x117d48[_0xedaa('0x5f')][_0x188ff1][_0xedaa('0x61')]?_0x203446(_0x117d48[_0xedaa('0x5f')][_0x188ff1][_0xedaa('0x61')]):_0x117d48[_0xedaa('0x5f')][_0x188ff1][_0xedaa('0x62')]+'\x20'+_0x117d48[_0xedaa('0x5f')][_0x188ff1]['condition']+(_0x5c4ff7(_0x117d48[_0xedaa('0x5f')][_0x188ff1][_0xedaa('0x63')])?'\x20'+_0x117d48[_0xedaa('0x5f')][_0x188ff1][_0xedaa('0x64')]:'');}return _0x22a2eb+')';};var _0x3c7e38={'where':{'id':_0x3c0185['id']}},_0x1c750a,_0x28fe11,_0x35922e,_0x42d57d,_0x2a613e;_0x3c7e38=_[_0xedaa('0x3d')]({},_0x3c7e38,_0x330b5a);return db['AnalyticCustomReport'][_0xedaa('0x44')](_0x3c7e38)[_0xedaa('0x20')](function(_0x35c040){if(_0x35c040){_0x1c750a=_0x35c040;return _0x35c040[_0xedaa('0x65')]();}return null;})[_0xedaa('0x20')](function(_0x233ee2){if(_0x233ee2){if(!_0x233ee2[_0xedaa('0x88')]){throw new db[(_0xedaa('0x66'))][(_0xedaa('0x67'))](_0xedaa('0x68'),0x193);}_0x28fe11=_0x233ee2;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})[_0xedaa('0x20')](function(_0x1197ff){if(_0x1197ff){_0x35922e=_[_0xedaa('0x6a')](_0x1197ff,'id');var _0x1b60f1;var _0x2bf516=squel['select']();_0x2bf516['from'](_0x1c750a[_0xedaa('0x6d')]);for(var _0x5cdd3b=0x0;_0x5cdd3b<_0x28fe11[_0xedaa('0x88')];_0x5cdd3b+=0x1){_0x1b60f1=_0x28fe11[_0x5cdd3b][_0xedaa('0x6e')]?_0x35922e[_0x28fe11[_0x5cdd3b][_0xedaa('0x6e')]][_0xedaa('0x89')]:_0x28fe11[_0x5cdd3b][_0xedaa('0x62')];_0x1b60f1=_0x28fe11[_0x5cdd3b]['function']?_[_0xedaa('0x70')](_0x220910[_0x28fe11[_0x5cdd3b][_0xedaa('0x6f')]],'%s',_0x1b60f1):_0x1b60f1;_0x1b60f1=_0x28fe11[_0x5cdd3b][_0xedaa('0x71')]?_['replace'](_0x5a7ccc[_0x28fe11[_0x5cdd3b][_0xedaa('0x71')]],'%s',_0x1b60f1):_0x1b60f1;if(_0x28fe11[_0x5cdd3b][_0xedaa('0x8a')]){_0x2bf516[_0xedaa('0x61')](_0x1b60f1);}_0x28fe11[_0x5cdd3b][_0xedaa('0x72')]&&_0x2bf516['order'](_0x1b60f1,_0x28fe11[_0x5cdd3b][_0xedaa('0x72')]===_0xedaa('0x73')?![]:!![]);_0x2bf516[_0xedaa('0x62')](_0x1b60f1,_0x28fe11[_0x5cdd3b][_0xedaa('0x74')]||_0x1b60f1);}if(_0x1c750a['joins']){_0x1c750a[_0xedaa('0x75')]=JSON[_0xedaa('0x76')](_0x1c750a['joins']);for(var _0x3bb784=0x0;_0x3bb784<_0x1c750a[_0xedaa('0x75')][_0xedaa('0x88')];_0x3bb784+=0x1){if(_0x1c750a['joins'][_0x3bb784][_0xedaa('0x2e')]&&_['includes'](_0x9e78ba,_0x1c750a['joins'][_0x3bb784]['type'])&&_0x1c750a[_0xedaa('0x75')][_0x3bb784][_0xedaa('0x77')]&&_0x1c750a[_0xedaa('0x75')][_0x3bb784][_0xedaa('0x78')]&&_0x1c750a[_0xedaa('0x75')][_0x3bb784]['foreignKey']){_0x2bf516[_0x1c750a[_0xedaa('0x75')][_0x3bb784][_0xedaa('0x2e')]](_0x1c750a[_0xedaa('0x75')][_0x3bb784]['foreignTable'],null,util[_0xedaa('0x71')](_0xedaa('0x7a'),_0x1c750a[_0xedaa('0x6d')],_0x1c750a[_0xedaa('0x75')][_0x3bb784][_0xedaa('0x77')],_0x1c750a[_0xedaa('0x75')][_0x3bb784][_0xedaa('0x78')],_0x1c750a[_0xedaa('0x75')][_0x3bb784][_0xedaa('0x79')]));}}}if(_0x1c750a['conditions']){_0x1c750a[_0xedaa('0x7b')]=JSON[_0xedaa('0x76')](_0x1c750a[_0xedaa('0x7b')]);_0x2bf516['where'](_0x203446(_0x1c750a[_0xedaa('0x7b')][_0xedaa('0x61')]));}_0x2a613e=_0x2bf516[_0xedaa('0x7c')]();_0x2bf516['limit'](_0xf8a1dd);_0x2bf516[_0xedaa('0x38')](0x0);logger['debug'](_0xedaa('0x7e'),_0x2bf516[_0xedaa('0x7f')]());return db['sequelize']['query'](_0x2bf516['toString'](),{'type':db[_0xedaa('0x80')]['QueryTypes'][_0xedaa('0x81')]});}})[_0xedaa('0x20')](function(_0x5e6fd9){if(!_0x5e6fd9[_0xedaa('0x88')]){throw new db[(_0xedaa('0x66'))][(_0xedaa('0x67'))](_0xedaa('0x8b'),0xcc);}if(_0x12cf17[_0xedaa('0x8c')]===_0xedaa('0x8d')){return null;}var _0x170587=_[_0xedaa('0x3d')](_0x12cf17,{'name':_0x12cf17[_0xedaa('0x8e')]||_0x12cf17['name']||_0x1c750a[_0xedaa('0x28')],'basename':_0x37d1a4,'savename':util[_0xedaa('0x71')]('%s-%s.%s',_0x12cf17[_0xedaa('0x28')]||_0x1c750a[_0xedaa('0x28')],require('randomstring')[_0xedaa('0x8f')](0x4),_0x12cf17[_0xedaa('0x8c')]||_0xedaa('0x90')),'reportId':_0x1c750a['id'],'reportType':_0xedaa('0x91')});return db[_0xedaa('0x92')]['create'](_0x170587,{'raw':!![]});})['then'](function(_0x3ae9f1){if(_0x1c750a[_0xedaa('0x6d')]==='cdr'){_0x2a613e[_0xedaa('0x3c')](_0x1c750a[_0xedaa('0x6d')]+_0xedaa('0x93'),_0x12cf17['startDate'],_0x12cf17[_0xedaa('0x94')]);}else{_0x2a613e[_0xedaa('0x3c')](_0x1c750a[_0xedaa('0x6d')]+'.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x12cf17['startDate'],_0x12cf17[_0xedaa('0x94')]);}if(_0x3ae9f1){logger[_0xedaa('0x95')]('Run\x20Query:',_0x2a613e[_0xedaa('0x7f')]());require('child_process')[_0xedaa('0x96')](path[_0xedaa('0x4f')](__dirname,'../../components/export/',_0x3ae9f1['output']),[_0x3ae9f1['id'],_0x2a613e[_0xedaa('0x7f')](),path['join'](__dirname,'../../files/reports',_0x3ae9f1['savename']),_0x37d1a4]);return _0x3ae9f1;}else{var _0x5b15e1=squel['select']();_0x5b15e1[_0xedaa('0x6c')]('('+_0x2a613e[_0xedaa('0x7f')]()+')',_0xedaa('0x97'));_0x5b15e1[_0xedaa('0x62')](_0xedaa('0x98'),'count');_0x2a613e[_0xedaa('0x1b')](_0x12cf17[_0xedaa('0x1b')]||_0xf8a1dd);_0x2a613e['offset'](_0x12cf17['offset']||0x0);return dbH[_0xedaa('0x80')][_0xedaa('0x2f')](_0x5b15e1['toString'](),{'type':dbH[_0xedaa('0x80')][_0xedaa('0x99')][_0xedaa('0x81')]})[_0xedaa('0x20')](function(_0x30d98d){if(!_0x30d98d[_0xedaa('0x88')]){_0x42d57d=0x0;}else{_0x42d57d=_0x30d98d[0x0][_0xedaa('0x1a')]||0x0;}return dbH[_0xedaa('0x80')][_0xedaa('0x2f')](_0x2a613e[_0xedaa('0x7f')](),{'type':dbH['sequelize'][_0xedaa('0x99')]['SELECT']});})[_0xedaa('0x20')](function(_0x14ae39){return{'rows':_0x14ae39||[],'count':_0x42d57d};});}});}exports[_0xedaa('0x9a')]=function(_0x2febd8,_0x5e69d2){return runReport(_0x2febd8[_0xedaa('0x9b')],_0x2febd8[_0xedaa('0x2f')],_0x2febd8[_0xedaa('0x3f')])[_0xedaa('0x20')](respondWithResult(_0x5e69d2,null))[_0xedaa('0x43')](handleError(_0x5e69d2,null));};exports[_0xedaa('0x9c')]=runReport;exports[_0xedaa('0x2f')]=function(_0x394f47,_0xbc280b){var _0x1f5cc3=0xa;var _0x216f6c=[_0xedaa('0x4f'),'left_join','right_join',_0xedaa('0x84')];var _0x22f0b3={'SUM':'SUM(%s)','COUNT':_0xedaa('0x51'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0xedaa('0x52'),'MIN':_0xedaa('0x86'),'AVG':_0xedaa('0x53'),'GROUP_CONCAT':_0xedaa('0x54'),'GROUP_CONCAT ASC':_0xedaa('0x55'),'GROUP_CONCAT DESC':_0xedaa('0x56')};var _0x35d3fd={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0xedaa('0x87'),'HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xedaa('0x59')};var _0xf10f9=function(_0xde5d8d){return!_[_0xedaa('0x5a')]([_0xedaa('0x5b'),'IS\x20NOT\x20NULL',_0xedaa('0x5d'),_0xedaa('0x5e')],_0xde5d8d);};var _0x4a15cb=function(_0x119809){if(!_0x119809||!_0x119809[_0xedaa('0x5f')][_0xedaa('0x88')]){return'';}for(var _0x236bf9='(',_0x195098=0x0;_0x195098<_0x119809[_0xedaa('0x5f')][_0xedaa('0x88')];_0x195098+=0x1){_0x195098>0x0&&(_0x236bf9+='\x20'+_0x119809['operator']+'\x20');_0x236bf9+=_0x119809[_0xedaa('0x5f')][_0x195098][_0xedaa('0x61')]?_0x4a15cb(_0x119809[_0xedaa('0x5f')][_0x195098][_0xedaa('0x61')]):_0x119809[_0xedaa('0x5f')][_0x195098]['field']+'\x20'+_0x119809['rules'][_0x195098][_0xedaa('0x63')]+(_0xf10f9(_0x119809[_0xedaa('0x5f')][_0x195098][_0xedaa('0x63')])?'\x20'+_0x119809[_0xedaa('0x5f')][_0x195098][_0xedaa('0x64')]:'');}return _0x236bf9+')';};var _0x3f3174={'where':{'id':_0x394f47[_0xedaa('0x9b')]['id']}},_0x364e54,_0x1d43fb,_0x2354b3,_0x197fd8,_0x26d43f;_0x3f3174=_[_0xedaa('0x3d')]({},_0x3f3174,_0x394f47['options']);return db[_0xedaa('0x2c')]['find'](_0x3f3174)[_0xedaa('0x20')](function(_0x5c43e3){if(_0x5c43e3){_0x364e54=_0x5c43e3;return _0x5c43e3[_0xedaa('0x65')]();}return null;})['then'](function(_0x563720){if(_0x563720){if(!_0x563720['length']){throw new db[(_0xedaa('0x66'))][(_0xedaa('0x67'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x1d43fb=_0x563720;return db[_0xedaa('0x69')][_0xedaa('0x9d')]({'raw':!![]});}return null;})[_0xedaa('0x20')](function(_0x36699c){if(_0x36699c){_0x2354b3=_[_0xedaa('0x6a')](_0x36699c,'id');var _0x3b913c;var _0x190bce=squel['select']();_0x190bce['from'](_0x364e54[_0xedaa('0x6d')]);for(var _0x474fa2=0x0;_0x474fa2<_0x1d43fb[_0xedaa('0x88')];_0x474fa2+=0x1){_0x3b913c=_0x1d43fb[_0x474fa2][_0xedaa('0x6e')]?_0x2354b3[_0x1d43fb[_0x474fa2][_0xedaa('0x6e')]][_0xedaa('0x89')]:_0x1d43fb[_0x474fa2][_0xedaa('0x62')];_0x3b913c=_0x1d43fb[_0x474fa2][_0xedaa('0x6f')]?_[_0xedaa('0x70')](_0x22f0b3[_0x1d43fb[_0x474fa2][_0xedaa('0x6f')]],'%s',_0x3b913c):_0x3b913c;_0x3b913c=_0x1d43fb[_0x474fa2][_0xedaa('0x71')]?_[_0xedaa('0x70')](_0x35d3fd[_0x1d43fb[_0x474fa2][_0xedaa('0x71')]],'%s',_0x3b913c):_0x3b913c;if(_0x1d43fb[_0x474fa2][_0xedaa('0x8a')]){_0x190bce[_0xedaa('0x61')](_0x3b913c);}_0x1d43fb[_0x474fa2][_0xedaa('0x72')]&&_0x190bce[_0xedaa('0x39')](_0x3b913c,_0x1d43fb[_0x474fa2]['orderBy']===_0xedaa('0x73')?![]:!![]);_0x190bce[_0xedaa('0x62')](_0x3b913c,_0x1d43fb[_0x474fa2][_0xedaa('0x74')]||_0x3b913c);}if(_0x364e54[_0xedaa('0x75')]){_0x364e54[_0xedaa('0x75')]=JSON[_0xedaa('0x76')](_0x364e54[_0xedaa('0x75')]);for(var _0x53232a=0x0;_0x53232a<_0x364e54[_0xedaa('0x75')][_0xedaa('0x88')];_0x53232a+=0x1){if(_0x364e54[_0xedaa('0x75')][_0x53232a][_0xedaa('0x2e')]&&_[_0xedaa('0x5a')](_0x216f6c,_0x364e54['joins'][_0x53232a][_0xedaa('0x2e')])&&_0x364e54['joins'][_0x53232a][_0xedaa('0x77')]&&_0x364e54['joins'][_0x53232a]['foreignTable']&&_0x364e54['joins'][_0x53232a][_0xedaa('0x79')]){_0x190bce[_0x364e54['joins'][_0x53232a][_0xedaa('0x2e')]](_0x364e54[_0xedaa('0x75')][_0x53232a][_0xedaa('0x78')],null,util[_0xedaa('0x71')](_0xedaa('0x7a'),_0x364e54[_0xedaa('0x6d')],_0x364e54[_0xedaa('0x75')][_0x53232a][_0xedaa('0x77')],_0x364e54[_0xedaa('0x75')][_0x53232a][_0xedaa('0x78')],_0x364e54[_0xedaa('0x75')][_0x53232a][_0xedaa('0x79')]));}}}if(_0x364e54[_0xedaa('0x7b')]){_0x364e54['conditions']=JSON[_0xedaa('0x76')](_0x364e54[_0xedaa('0x7b')]);_0x190bce[_0xedaa('0x3c')](_0x4a15cb(_0x364e54[_0xedaa('0x7b')]['group']));}_0x26d43f=_0x190bce[_0xedaa('0x7c')]();_0x190bce['limit'](_0x1f5cc3);_0x190bce[_0xedaa('0x38')](0x0);logger[_0xedaa('0x7d')]('Limited\x20Query:',_0x190bce['toString']());return db[_0xedaa('0x80')][_0xedaa('0x2f')](_0x190bce['toString'](),{'type':db[_0xedaa('0x80')][_0xedaa('0x99')][_0xedaa('0x81')]});}})[_0xedaa('0x20')](function(){return{'sql':_0x26d43f[_0xedaa('0x7f')]()};})[_0xedaa('0x20')](respondWithResult(_0xbc280b,null))[_0xedaa('0x43')](handleError(_0xbc280b,null));};
\ No newline at end of file
+var _0x0b0e=['IS\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','field','condition','value','options','getFields','length','Sequelize','AnalyticMetric','findAll','keyBy','select','table','function','format','groupBy','group','orderBy','DESC','joins','parse','parentKey','foreignTable','%s.%s\x20=\x20%s.%s','conditions','clone','debug','toString','sequelize','QueryTypes','SELECT','GROUP_CONCAT(%s)','UNIX_TIMESTAMP(%s)','IS\x20NOT\x20NULL','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','from','MetricId','metric','alias','foreignKey','output','web','fullPath','%s-%s.%s','custom','cdr','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','startDate','info','Run\x20Query:','child_process','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','runReport','replace','Limited\x20Query:','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','dbH','sendStatus','status','end','undefined','limit','count','set','json','apply','update','destroy','UserProfileResource','then','error','stack','name','send','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','filter','merge','VIRTUAL','include','rows','catch','show','includeAll','find','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','CustomReports','body','params','preview','join','left_join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','ROUND(%s)','includes'];(function(_0x278bd7,_0x2b4b52){var _0x56f13b=function(_0x44f3d3){while(--_0x44f3d3){_0x278bd7['push'](_0x278bd7['shift']());}};_0x56f13b(++_0x2b4b52);}(_0x0b0e,0x187));var _0xe0b0=function(_0x3da72b,_0x4fd809){_0x3da72b=_0x3da72b-0x0;var _0xc64ac4=_0x0b0e[_0x3da72b];return _0xc64ac4;};'use strict';var emlformat=require(_0xe0b0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xe0b0('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe0b0('0x2'));var moment=require(_0xe0b0('0x3'));var BPromise=require(_0xe0b0('0x4'));var Mustache=require(_0xe0b0('0x5'));var util=require(_0xe0b0('0x6'));var path=require(_0xe0b0('0x7'));var sox=require(_0xe0b0('0x8'));var csv=require(_0xe0b0('0x9'));var ejs=require(_0xe0b0('0xa'));var fs=require('fs');var fs_extra=require(_0xe0b0('0xb'));var _=require(_0xe0b0('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xe0b0('0xd'));var deskjs=require(_0xe0b0('0xe'));var toCsv=require(_0xe0b0('0x9'));var querystring=require(_0xe0b0('0xf'));var Papa=require('papaparse');var Redis=require(_0xe0b0('0x10'));var authService=require(_0xe0b0('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xe0b0('0x12'));var hardwareService=require(_0xe0b0('0x13'));var logger=require('../../config/logger')(_0xe0b0('0x14'));var utils=require(_0xe0b0('0x15'));var config=require(_0xe0b0('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xe0b0('0x17'))['db'];var dbH=require(_0xe0b0('0x17'))[_0xe0b0('0x18')];function respondWithStatusCode(_0x45f914,_0x34fed4){_0x34fed4=_0x34fed4||0xcc;return function(_0x4d2bf7){if(_0x4d2bf7){return _0x45f914[_0xe0b0('0x19')](_0x34fed4);}return _0x45f914[_0xe0b0('0x1a')](_0x34fed4)[_0xe0b0('0x1b')]();};}function respondWithResult(_0x24babd,_0x177c24){_0x177c24=_0x177c24||0xc8;return function(_0x55d884){if(_0x55d884){return _0x24babd[_0xe0b0('0x1a')](_0x177c24)['json'](_0x55d884);}};}function respondWithFilteredResult(_0x35cb40,_0xadee6e){return function(_0x519ae8){if(_0x519ae8){var _0x11fdca=typeof _0xadee6e['offset']===_0xe0b0('0x1c')&&typeof _0xadee6e[_0xe0b0('0x1d')]==='undefined';var _0x54a3eb=_0x519ae8[_0xe0b0('0x1e')];var _0x50a441=_0x11fdca?0x0:_0xadee6e['offset'];var _0x4bce65=_0x11fdca?_0x519ae8[_0xe0b0('0x1e')]:_0xadee6e['offset']+_0xadee6e['limit'];var _0x10cde1;if(_0x4bce65>=_0x54a3eb){_0x4bce65=_0x54a3eb;_0x10cde1=0xc8;}else{_0x10cde1=0xce;}_0x35cb40['status'](_0x10cde1);return _0x35cb40[_0xe0b0('0x1f')]('Content-Range',_0x50a441+'-'+_0x4bce65+'/'+_0x54a3eb)[_0xe0b0('0x20')](_0x519ae8);}return null;};}function patchUpdates(_0x1cd7c4){return function(_0x3e10b3){try{jsonpatch[_0xe0b0('0x21')](_0x3e10b3,_0x1cd7c4,!![]);}catch(_0x2cf6a1){return BPromise['reject'](_0x2cf6a1);}return _0x3e10b3['save']();};}function saveUpdates(_0x2fa820,_0x5512bb){return function(_0x12b260){if(_0x12b260){return _0x12b260[_0xe0b0('0x22')](_0x2fa820)['then'](function(_0x170ad8){return _0x170ad8;});}return null;};}function removeEntity(_0x503883,_0x2208d0){return function(_0x49a727){if(_0x49a727){return _0x49a727[_0xe0b0('0x23')]()['then'](function(){var _0x3e5c88=_0x49a727['get']({'plain':!![]});var _0x4700cc='CustomReports';return db[_0xe0b0('0x24')]['destroy']({'where':{'type':_0x4700cc,'resourceId':_0x3e5c88['id']}})[_0xe0b0('0x25')](function(){return _0x49a727;});})[_0xe0b0('0x25')](function(){_0x503883[_0xe0b0('0x1a')](0xcc)[_0xe0b0('0x1b')]();});}};}function handleEntityNotFound(_0x3ec2,_0x10745d){return function(_0x5200a6){if(!_0x5200a6){_0x3ec2[_0xe0b0('0x19')](0x194);}return _0x5200a6;};}function handleError(_0x1b8aa8,_0x5b7a64){_0x5b7a64=_0x5b7a64||0x1f4;return function(_0x15e13b){logger[_0xe0b0('0x26')](_0x15e13b[_0xe0b0('0x27')]);if(_0x15e13b[_0xe0b0('0x28')]){delete _0x15e13b[_0xe0b0('0x28')];}_0x1b8aa8[_0xe0b0('0x1a')](_0x5b7a64)[_0xe0b0('0x29')](_0x15e13b);};}exports['index']=function(_0x1854b8,_0x3c0109){var _0x48a9b5={},_0x4fe400={},_0x158b7f={'count':0x0,'rows':[]};var _0x33e672=_[_0xe0b0('0x2a')](db[_0xe0b0('0x2b')][_0xe0b0('0x2c')],function(_0x5866e5){return{'name':_0x5866e5[_0xe0b0('0x2d')],'type':_0x5866e5[_0xe0b0('0x2e')][_0xe0b0('0x2f')]};});_0x4fe400[_0xe0b0('0x30')]=_[_0xe0b0('0x2a')](_0x33e672,'name');_0x4fe400[_0xe0b0('0x31')]=_[_0xe0b0('0x32')](_0x1854b8[_0xe0b0('0x31')]);_0x4fe400[_0xe0b0('0x33')]=_[_0xe0b0('0x34')](_0x4fe400[_0xe0b0('0x30')],_0x4fe400[_0xe0b0('0x31')]);_0x48a9b5[_0xe0b0('0x35')]=_[_0xe0b0('0x34')](_0x4fe400[_0xe0b0('0x30')],qs[_0xe0b0('0x36')](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x36')]));_0x48a9b5[_0xe0b0('0x35')]=_0x48a9b5[_0xe0b0('0x35')]['length']?_0x48a9b5[_0xe0b0('0x35')]:_0x4fe400[_0xe0b0('0x30')];if(!_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x37')](_0xe0b0('0x38'))){_0x48a9b5[_0xe0b0('0x1d')]=qs[_0xe0b0('0x1d')](_0x1854b8['query']['limit']);_0x48a9b5['offset']=qs['offset'](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x39')]);}_0x48a9b5[_0xe0b0('0x3a')]=qs['sort'](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3b')]);_0x48a9b5[_0xe0b0('0x3c')]=qs[_0xe0b0('0x33')](_['pick'](_0x1854b8[_0xe0b0('0x31')],_0x4fe400[_0xe0b0('0x33')]),_0x33e672);if(_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3d')]){_0x48a9b5[_0xe0b0('0x3c')]=_[_0xe0b0('0x3e')](_0x48a9b5[_0xe0b0('0x3c')],{'$or':_[_0xe0b0('0x2a')](_0x33e672,function(_0xeaffbb){if(_0xeaffbb['type']!==_0xe0b0('0x3f')){var _0x54f646={};_0x54f646[_0xeaffbb[_0xe0b0('0x28')]]={'$like':'%'+_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3d')]+'%'};return _0x54f646;}})});}_0x48a9b5=_[_0xe0b0('0x3e')]({},_0x48a9b5,_0x1854b8['options']);var _0x3e1b6b={'where':_0x48a9b5[_0xe0b0('0x3c')]};return db[_0xe0b0('0x2b')][_0xe0b0('0x1e')](_0x3e1b6b)[_0xe0b0('0x25')](function(_0x1c12bd){_0x158b7f[_0xe0b0('0x1e')]=_0x1c12bd;if(_0x1854b8[_0xe0b0('0x31')]['includeAll']){_0x48a9b5[_0xe0b0('0x40')]=[{'all':!![]}];}return db[_0xe0b0('0x2b')]['findAll'](_0x48a9b5);})['then'](function(_0x327fb4){_0x158b7f[_0xe0b0('0x41')]=_0x327fb4;return _0x158b7f;})['then'](respondWithFilteredResult(_0x3c0109,_0x48a9b5))[_0xe0b0('0x42')](handleError(_0x3c0109,null));};exports[_0xe0b0('0x43')]=function(_0x6bca5c,_0x1c869d){var _0x1a8cc7={'raw':![],'where':{'id':_0x6bca5c['params']['id']}},_0x5c31b5={};_0x5c31b5['model']=_[_0xe0b0('0x32')](db[_0xe0b0('0x2b')]['rawAttributes']);_0x5c31b5[_0xe0b0('0x31')]=_[_0xe0b0('0x32')](_0x6bca5c[_0xe0b0('0x31')]);_0x5c31b5[_0xe0b0('0x33')]=_[_0xe0b0('0x34')](_0x5c31b5['model'],_0x5c31b5['query']);_0x1a8cc7[_0xe0b0('0x35')]=_[_0xe0b0('0x34')](_0x5c31b5[_0xe0b0('0x30')],qs[_0xe0b0('0x36')](_0x6bca5c[_0xe0b0('0x31')]['fields']));_0x1a8cc7[_0xe0b0('0x35')]=_0x1a8cc7[_0xe0b0('0x35')]['length']?_0x1a8cc7['attributes']:_0x5c31b5['model'];if(_0x6bca5c[_0xe0b0('0x31')][_0xe0b0('0x44')]){_0x1a8cc7[_0xe0b0('0x40')]=[{'all':!![]}];}_0x1a8cc7=_[_0xe0b0('0x3e')]({},_0x1a8cc7,_0x6bca5c['options']);return db[_0xe0b0('0x2b')][_0xe0b0('0x45')](_0x1a8cc7)['then'](handleEntityNotFound(_0x1c869d,null))['then'](respondWithResult(_0x1c869d,null))[_0xe0b0('0x42')](handleError(_0x1c869d,null));};exports[_0xe0b0('0x46')]=function(_0x497f4f,_0x2b1917){return db[_0xe0b0('0x2b')]['create'](_0x497f4f['body'],{})[_0xe0b0('0x25')](function(_0x511679){var _0x165dc8=_0x497f4f[_0xe0b0('0x47')][_0xe0b0('0x48')]({'plain':!![]});if(!_0x165dc8)throw new Error(_0xe0b0('0x49'));if(_0x165dc8[_0xe0b0('0x4a')]===_0xe0b0('0x47')){var _0x5f5486=_0x511679['get']({'plain':!![]});var _0x2ef908='Reports';return db['UserProfileSection'][_0xe0b0('0x45')]({'where':{'name':_0x2ef908,'userProfileId':_0x165dc8[_0xe0b0('0x4b')]},'raw':!![]})['then'](function(_0x4b65d1){if(_0x4b65d1&&_0x4b65d1[_0xe0b0('0x4c')]===0x0){return db[_0xe0b0('0x24')][_0xe0b0('0x46')]({'name':_0x5f5486[_0xe0b0('0x28')],'resourceId':_0x5f5486['id'],'type':_0xe0b0('0x4d'),'sectionId':_0x4b65d1['id']},{})[_0xe0b0('0x25')](function(){return _0x511679;});}else{return _0x511679;}})[_0xe0b0('0x42')](function(_0x4ebb0f){logger[_0xe0b0('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4ebb0f);throw _0x4ebb0f;});}return _0x511679;})[_0xe0b0('0x25')](respondWithResult(_0x2b1917,0xc9))['catch'](handleError(_0x2b1917,null));};exports['update']=function(_0x33822e,_0x237e8c){if(_0x33822e[_0xe0b0('0x4e')]['id']){delete _0x33822e[_0xe0b0('0x4e')]['id'];}return db[_0xe0b0('0x2b')][_0xe0b0('0x45')]({'where':{'id':_0x33822e[_0xe0b0('0x4f')]['id']}})[_0xe0b0('0x25')](handleEntityNotFound(_0x237e8c,null))[_0xe0b0('0x25')](saveUpdates(_0x33822e['body'],null))[_0xe0b0('0x25')](respondWithResult(_0x237e8c,null))['catch'](handleError(_0x237e8c,null));};exports[_0xe0b0('0x23')]=function(_0x3ae36e,_0x30c4a9){return db[_0xe0b0('0x2b')][_0xe0b0('0x45')]({'where':{'id':_0x3ae36e[_0xe0b0('0x4f')]['id']}})['then'](handleEntityNotFound(_0x30c4a9,null))[_0xe0b0('0x25')](removeEntity(_0x30c4a9,null))[_0xe0b0('0x42')](handleError(_0x30c4a9,null));};exports[_0xe0b0('0x50')]=function(_0x271445,_0x3bb6d6){var _0x3b015e=0xa;var _0x234cb7=[_0xe0b0('0x51'),_0xe0b0('0x52'),_0xe0b0('0x53'),_0xe0b0('0x54')];var _0x18ab99={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':_0xe0b0('0x57'),'MAX':_0xe0b0('0x58'),'MIN':_0xe0b0('0x59'),'AVG':_0xe0b0('0x5a'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x1182dc={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':_0xe0b0('0x5e'),'HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x47dcc4=function(_0x139014){return!_[_0xe0b0('0x61')]([_0xe0b0('0x62'),'IS\x20NOT\x20NULL',_0xe0b0('0x63'),_0xe0b0('0x64')],_0x139014);};var _0x309efb=function(_0x3d820c){if(!_0x3d820c||!_0x3d820c[_0xe0b0('0x65')]['length']){return'';}for(var _0x370f8c='(',_0x242120=0x0;_0x242120<_0x3d820c[_0xe0b0('0x65')]['length'];_0x242120+=0x1){_0x242120>0x0&&(_0x370f8c+='\x20'+_0x3d820c[_0xe0b0('0x66')]+'\x20');_0x370f8c+=_0x3d820c[_0xe0b0('0x65')][_0x242120]['group']?_0x309efb(_0x3d820c[_0xe0b0('0x65')][_0x242120]['group']):_0x3d820c['rules'][_0x242120][_0xe0b0('0x67')]+'\x20'+_0x3d820c['rules'][_0x242120]['condition']+(_0x47dcc4(_0x3d820c[_0xe0b0('0x65')][_0x242120][_0xe0b0('0x68')])?'\x20'+_0x3d820c[_0xe0b0('0x65')][_0x242120][_0xe0b0('0x69')]:'');}return _0x370f8c+')';};var _0x5a7913={'where':{'id':_0x271445[_0xe0b0('0x4f')]['id']}},_0x3679e0,_0x2287a5,_0x3e7fb4,_0x41ec8e,_0x1b29c;_0x5a7913=_[_0xe0b0('0x3e')]({},_0x5a7913,_0x271445[_0xe0b0('0x6a')]);return db['AnalyticCustomReport']['find'](_0x5a7913)[_0xe0b0('0x25')](function(_0x35144f){if(_0x35144f){_0x3679e0=_0x35144f;return _0x35144f[_0xe0b0('0x6b')]();}return null;})['then'](function(_0x49b754){if(_0x49b754){if(!_0x49b754[_0xe0b0('0x6c')]){throw new db[(_0xe0b0('0x6d'))]['ValidationErrorItem']('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x2287a5=_0x49b754;return db[_0xe0b0('0x6e')][_0xe0b0('0x6f')]({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x29175a){if(_0x29175a){_0x3e7fb4=_[_0xe0b0('0x70')](_0x29175a,'id');var _0x15f0f8;var _0x1bc7a6=squel[_0xe0b0('0x71')]();_0x1bc7a6['from'](_0x3679e0[_0xe0b0('0x72')]);for(var _0x12e245=0x0;_0x12e245<_0x2287a5[_0xe0b0('0x6c')];_0x12e245+=0x1){_0x15f0f8=_0x2287a5[_0x12e245]['MetricId']?_0x3e7fb4[_0x2287a5[_0x12e245]['MetricId']]['metric']:_0x2287a5[_0x12e245]['field'];_0x15f0f8=_0x2287a5[_0x12e245]['function']?_['replace'](_0x18ab99[_0x2287a5[_0x12e245][_0xe0b0('0x73')]],'%s',_0x15f0f8):_0x15f0f8;_0x15f0f8=_0x2287a5[_0x12e245]['format']?_['replace'](_0x1182dc[_0x2287a5[_0x12e245][_0xe0b0('0x74')]],'%s',_0x15f0f8):_0x15f0f8;if(_0x2287a5[_0x12e245][_0xe0b0('0x75')]){_0x1bc7a6[_0xe0b0('0x76')](_0x15f0f8);}_0x2287a5[_0x12e245][_0xe0b0('0x77')]&&_0x1bc7a6[_0xe0b0('0x3a')](_0x15f0f8,_0x2287a5[_0x12e245][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x1bc7a6[_0xe0b0('0x67')](_0x15f0f8,_0x2287a5[_0x12e245]['alias']||_0x15f0f8);}if(_0x3679e0[_0xe0b0('0x79')]){_0x3679e0[_0xe0b0('0x79')]=JSON[_0xe0b0('0x7a')](_0x3679e0[_0xe0b0('0x79')]);for(var _0x173ed8=0x0;_0x173ed8<_0x3679e0[_0xe0b0('0x79')][_0xe0b0('0x6c')];_0x173ed8+=0x1){if(_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x2e')]&&_['includes'](_0x234cb7,_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x2e')])&&_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7b')]&&_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x7c')]&&_0x3679e0[_0xe0b0('0x79')][_0x173ed8]['foreignKey']){_0x1bc7a6[_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x2e')]](_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7c')],null,util[_0xe0b0('0x74')](_0xe0b0('0x7d'),_0x3679e0[_0xe0b0('0x72')],_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7b')],_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7c')],_0x3679e0['joins'][_0x173ed8]['foreignKey']));}}}if(_0x3679e0[_0xe0b0('0x7e')]){_0x3679e0['conditions']=JSON['parse'](_0x3679e0['conditions']);_0x1bc7a6['where'](_0x309efb(_0x3679e0[_0xe0b0('0x7e')]['group']));}_0x1b29c=_0x1bc7a6[_0xe0b0('0x7f')]();_0x1bc7a6[_0xe0b0('0x1d')](_0x3b015e);_0x1bc7a6[_0xe0b0('0x39')](0x0);logger[_0xe0b0('0x80')]('Limited\x20Query:',_0x1bc7a6[_0xe0b0('0x81')]());return dbH[_0xe0b0('0x82')]['query'](_0x1bc7a6[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});}})[_0xe0b0('0x25')](respondWithResult(_0x3bb6d6,null))['catch'](handleError(_0x3bb6d6,null));};function runReport(_0x55d3f8,_0x55aef7,_0x545694){var _0x5c258b=_0x55aef7[_0xe0b0('0x28')];var _0x567e1a=0xa;var _0x3c09af=['join',_0xe0b0('0x52'),_0xe0b0('0x53'),_0xe0b0('0x54')];var _0x380b4c={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0xe0b0('0x85'),'GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x4377f7={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':'DATE(%s)','HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':_0xe0b0('0x86')};var _0xc6090e=function(_0x154e6d){return!_[_0xe0b0('0x61')]([_0xe0b0('0x62'),_0xe0b0('0x87'),_0xe0b0('0x63'),'IS\x20NOT\x20EMPTY'],_0x154e6d);};var _0x589c47=function(_0x6e0e9){if(!_0x6e0e9||!_0x6e0e9[_0xe0b0('0x65')]['length']){return'';}for(var _0x7feff4='(',_0x4593f1=0x0;_0x4593f1<_0x6e0e9[_0xe0b0('0x65')][_0xe0b0('0x6c')];_0x4593f1+=0x1){_0x4593f1>0x0&&(_0x7feff4+='\x20'+_0x6e0e9[_0xe0b0('0x66')]+'\x20');_0x7feff4+=_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x76')]?_0x589c47(_0x6e0e9[_0xe0b0('0x65')][_0x4593f1]['group']):_0x6e0e9['rules'][_0x4593f1]['field']+'\x20'+_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x68')]+(_0xc6090e(_0x6e0e9['rules'][_0x4593f1][_0xe0b0('0x68')])?'\x20'+_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x69')]:'');}return _0x7feff4+')';};var _0x328832={'where':{'id':_0x55d3f8['id']}},_0x5c45ae,_0x56c4b9,_0x4e1fb1,_0x22029a,_0x266835;_0x328832=_['merge']({},_0x328832,_0x545694);return db[_0xe0b0('0x2b')][_0xe0b0('0x45')](_0x328832)['then'](function(_0x576482){if(_0x576482){_0x5c45ae=_0x576482;return _0x576482[_0xe0b0('0x6b')]();}return null;})['then'](function(_0x251195){if(_0x251195){if(!_0x251195['length']){throw new db[(_0xe0b0('0x6d'))][(_0xe0b0('0x88'))](_0xe0b0('0x89'),0x193);}_0x56c4b9=_0x251195;return db[_0xe0b0('0x6e')][_0xe0b0('0x6f')]({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x434dfa){if(_0x434dfa){_0x4e1fb1=_[_0xe0b0('0x70')](_0x434dfa,'id');var _0xf76449;var _0x48497e=squel[_0xe0b0('0x71')]();_0x48497e[_0xe0b0('0x8a')](_0x5c45ae[_0xe0b0('0x72')]);for(var _0x4e19f4=0x0;_0x4e19f4<_0x56c4b9[_0xe0b0('0x6c')];_0x4e19f4+=0x1){_0xf76449=_0x56c4b9[_0x4e19f4]['MetricId']?_0x4e1fb1[_0x56c4b9[_0x4e19f4][_0xe0b0('0x8b')]][_0xe0b0('0x8c')]:_0x56c4b9[_0x4e19f4]['field'];_0xf76449=_0x56c4b9[_0x4e19f4][_0xe0b0('0x73')]?_['replace'](_0x380b4c[_0x56c4b9[_0x4e19f4]['function']],'%s',_0xf76449):_0xf76449;_0xf76449=_0x56c4b9[_0x4e19f4][_0xe0b0('0x74')]?_['replace'](_0x4377f7[_0x56c4b9[_0x4e19f4]['format']],'%s',_0xf76449):_0xf76449;if(_0x56c4b9[_0x4e19f4][_0xe0b0('0x75')]){_0x48497e[_0xe0b0('0x76')](_0xf76449);}_0x56c4b9[_0x4e19f4][_0xe0b0('0x77')]&&_0x48497e[_0xe0b0('0x3a')](_0xf76449,_0x56c4b9[_0x4e19f4][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x48497e['field'](_0xf76449,_0x56c4b9[_0x4e19f4][_0xe0b0('0x8d')]||_0xf76449);}if(_0x5c45ae[_0xe0b0('0x79')]){_0x5c45ae[_0xe0b0('0x79')]=JSON['parse'](_0x5c45ae[_0xe0b0('0x79')]);for(var _0x447641=0x0;_0x447641<_0x5c45ae['joins']['length'];_0x447641+=0x1){if(_0x5c45ae[_0xe0b0('0x79')][_0x447641]['type']&&_[_0xe0b0('0x61')](_0x3c09af,_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x2e')])&&_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7b')]&&_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')]&&_0x5c45ae['joins'][_0x447641][_0xe0b0('0x8e')]){_0x48497e[_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x2e')]](_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')],null,util['format']('%s.%s\x20=\x20%s.%s',_0x5c45ae[_0xe0b0('0x72')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7b')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x8e')]));}}}if(_0x5c45ae[_0xe0b0('0x7e')]){_0x5c45ae[_0xe0b0('0x7e')]=JSON[_0xe0b0('0x7a')](_0x5c45ae['conditions']);_0x48497e[_0xe0b0('0x3c')](_0x589c47(_0x5c45ae[_0xe0b0('0x7e')][_0xe0b0('0x76')]));}_0x266835=_0x48497e[_0xe0b0('0x7f')]();_0x48497e['limit'](_0x567e1a);_0x48497e[_0xe0b0('0x39')](0x0);return;}})[_0xe0b0('0x25')](function(){if(_0x55aef7[_0xe0b0('0x8f')]===_0xe0b0('0x90')){return null;}var _0x476763=_['merge'](_0x55aef7,{'name':_0x55aef7[_0xe0b0('0x91')]||_0x55aef7['name']||_0x5c45ae[_0xe0b0('0x28')],'basename':_0x5c258b,'savename':util[_0xe0b0('0x74')](_0xe0b0('0x92'),_0x55aef7[_0xe0b0('0x28')]||_0x5c45ae[_0xe0b0('0x28')],require('randomstring')['generate'](0x4),_0x55aef7[_0xe0b0('0x8f')]||'csv'),'reportId':_0x5c45ae['id'],'reportType':_0xe0b0('0x93')});return db['AnalyticExtractedReport'][_0xe0b0('0x46')](_0x476763,{'raw':!![]});})[_0xe0b0('0x25')](function(_0x205c53){if(_0x5c45ae[_0xe0b0('0x72')]===_0xe0b0('0x94')){_0x266835[_0xe0b0('0x3c')](_0x5c45ae[_0xe0b0('0x72')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x55aef7['startDate'],_0x55aef7[_0xe0b0('0x95')]);}else{_0x266835[_0xe0b0('0x3c')](_0x5c45ae[_0xe0b0('0x72')]+_0xe0b0('0x96'),_0x55aef7[_0xe0b0('0x97')],_0x55aef7[_0xe0b0('0x95')]);}if(_0x205c53){logger[_0xe0b0('0x98')](_0xe0b0('0x99'),_0x266835[_0xe0b0('0x81')]());require(_0xe0b0('0x9a'))['fork'](path['join'](__dirname,_0xe0b0('0x9b'),_0x205c53[_0xe0b0('0x8f')]),[_0x205c53['id'],_0x266835[_0xe0b0('0x81')](),path[_0xe0b0('0x51')](__dirname,_0xe0b0('0x9c'),_0x205c53[_0xe0b0('0x9d')]),_0x5c258b]);return _0x205c53;}else{var _0x33b67a=squel['select']();_0x33b67a['from']('('+_0x266835[_0xe0b0('0x81')]()+')',_0xe0b0('0x9e'));_0x33b67a[_0xe0b0('0x67')](_0xe0b0('0x9f'),_0xe0b0('0x1e'));_0x266835[_0xe0b0('0x1d')](_0x55aef7[_0xe0b0('0x1d')]||_0x567e1a);_0x266835[_0xe0b0('0x39')](_0x55aef7[_0xe0b0('0x39')]||0x0);return dbH[_0xe0b0('0x82')]['query'](_0x33b67a[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')]['QueryTypes'][_0xe0b0('0x84')]})[_0xe0b0('0x25')](function(_0x3615f9){if(!_0x3615f9[_0xe0b0('0x6c')]){_0x22029a=0x0;}else{_0x22029a=_0x3615f9[0x0][_0xe0b0('0x1e')]||0x0;}return dbH['sequelize'][_0xe0b0('0x31')](_0x266835[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});})['then'](function(_0x475404){return{'rows':_0x475404||[],'count':_0x22029a};});}});}exports['run']=function(_0x44e05a,_0x42dfa9){return runReport(_0x44e05a[_0xe0b0('0x4f')],_0x44e05a['query'],_0x44e05a['options'])[_0xe0b0('0x25')](respondWithResult(_0x42dfa9,null))[_0xe0b0('0x42')](handleError(_0x42dfa9,null));};exports[_0xe0b0('0xa0')]=runReport;exports['query']=function(_0x4d372a,_0x5da5eb){var _0x5175e1=0xa;var _0x57694c=['join',_0xe0b0('0x52'),_0xe0b0('0x53'),'cross_join'];var _0x121257={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':_0xe0b0('0x57'),'MAX':_0xe0b0('0x58'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0xe0b0('0x85'),'GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x52dfd8={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':_0xe0b0('0x5e'),'HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':_0xe0b0('0x86')};var _0x1b8d4a=function(_0x51b616){return!_['includes'](['IS\x20NULL',_0xe0b0('0x87'),_0xe0b0('0x63'),_0xe0b0('0x64')],_0x51b616);};var _0x40809f=function(_0x266cb5){if(!_0x266cb5||!_0x266cb5[_0xe0b0('0x65')][_0xe0b0('0x6c')]){return'';}for(var _0x35f081='(',_0x5e4339=0x0;_0x5e4339<_0x266cb5['rules'][_0xe0b0('0x6c')];_0x5e4339+=0x1){_0x5e4339>0x0&&(_0x35f081+='\x20'+_0x266cb5[_0xe0b0('0x66')]+'\x20');_0x35f081+=_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['group']?_0x40809f(_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x76')]):_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['field']+'\x20'+_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['condition']+(_0x1b8d4a(_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x68')])?'\x20'+_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x69')]:'');}return _0x35f081+')';};var _0x3b133a={'where':{'id':_0x4d372a['params']['id']}},_0x26df60,_0x12e46f,_0x55beb2,_0x287af5,_0xb71713;_0x3b133a=_[_0xe0b0('0x3e')]({},_0x3b133a,_0x4d372a[_0xe0b0('0x6a')]);return db[_0xe0b0('0x2b')]['find'](_0x3b133a)[_0xe0b0('0x25')](function(_0x692a95){if(_0x692a95){_0x26df60=_0x692a95;return _0x692a95[_0xe0b0('0x6b')]();}return null;})['then'](function(_0xed8461){if(_0xed8461){if(!_0xed8461[_0xe0b0('0x6c')]){throw new db[(_0xe0b0('0x6d'))][(_0xe0b0('0x88'))](_0xe0b0('0x89'),0x193);}_0x12e46f=_0xed8461;return db[_0xe0b0('0x6e')]['findAll']({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x701ba){if(_0x701ba){_0x55beb2=_[_0xe0b0('0x70')](_0x701ba,'id');var _0x26315d;var _0x11452e=squel[_0xe0b0('0x71')]();_0x11452e[_0xe0b0('0x8a')](_0x26df60[_0xe0b0('0x72')]);for(var _0xf87779=0x0;_0xf87779<_0x12e46f[_0xe0b0('0x6c')];_0xf87779+=0x1){_0x26315d=_0x12e46f[_0xf87779][_0xe0b0('0x8b')]?_0x55beb2[_0x12e46f[_0xf87779]['MetricId']][_0xe0b0('0x8c')]:_0x12e46f[_0xf87779]['field'];_0x26315d=_0x12e46f[_0xf87779]['function']?_[_0xe0b0('0xa1')](_0x121257[_0x12e46f[_0xf87779][_0xe0b0('0x73')]],'%s',_0x26315d):_0x26315d;_0x26315d=_0x12e46f[_0xf87779]['format']?_[_0xe0b0('0xa1')](_0x52dfd8[_0x12e46f[_0xf87779][_0xe0b0('0x74')]],'%s',_0x26315d):_0x26315d;if(_0x12e46f[_0xf87779][_0xe0b0('0x75')]){_0x11452e[_0xe0b0('0x76')](_0x26315d);}_0x12e46f[_0xf87779][_0xe0b0('0x77')]&&_0x11452e[_0xe0b0('0x3a')](_0x26315d,_0x12e46f[_0xf87779][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x11452e[_0xe0b0('0x67')](_0x26315d,_0x12e46f[_0xf87779]['alias']||_0x26315d);}if(_0x26df60[_0xe0b0('0x79')]){_0x26df60[_0xe0b0('0x79')]=JSON[_0xe0b0('0x7a')](_0x26df60[_0xe0b0('0x79')]);for(var _0x48c009=0x0;_0x48c009<_0x26df60['joins'][_0xe0b0('0x6c')];_0x48c009+=0x1){if(_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')]&&_[_0xe0b0('0x61')](_0x57694c,_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')])&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7b')]&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')]&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x8e')]){_0x11452e[_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')]](_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')],null,util[_0xe0b0('0x74')](_0xe0b0('0x7d'),_0x26df60[_0xe0b0('0x72')],_0x26df60['joins'][_0x48c009][_0xe0b0('0x7b')],_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')],_0x26df60['joins'][_0x48c009][_0xe0b0('0x8e')]));}}}if(_0x26df60[_0xe0b0('0x7e')]){_0x26df60[_0xe0b0('0x7e')]=JSON[_0xe0b0('0x7a')](_0x26df60[_0xe0b0('0x7e')]);_0x11452e[_0xe0b0('0x3c')](_0x40809f(_0x26df60[_0xe0b0('0x7e')]['group']));}_0xb71713=_0x11452e[_0xe0b0('0x7f')]();_0x11452e['limit'](_0x5175e1);_0x11452e[_0xe0b0('0x39')](0x0);logger['debug'](_0xe0b0('0xa2'),_0x11452e[_0xe0b0('0x81')]());return dbH['sequelize'][_0xe0b0('0x31')](_0x11452e['toString'](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});}})[_0xe0b0('0x25')](function(){return{'sql':_0xb71713[_0xe0b0('0x81')]()};})[_0xe0b0('0x25')](respondWithResult(_0x5da5eb,null))[_0xe0b0('0x42')](handleError(_0x5da5eb,null));};
\ No newline at end of file