Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 59d8862..f0b157e 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 _0x60b1=['runReport','SUM(%s)','MIN(%s)','HOUR(%s)','IS\x20NOT\x20EMPTY','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','lodash','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','destroy','then','get','UserProfileResource','stack','name','send','index','map','AnalyticCustomReport','type','key','query','keys','filters','intersection','model','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','merge','where','VIRTUAL','filter','options','includeAll','include','findAll','rows','catch','show','params','rawAttributes','length','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','error','preview','left_join','right_join','cross_join','COUNT(%s)','COUNT(DISTINCT\x20%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','DATE(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20EMPTY','rules','operator','group','field','condition','value','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','from','table','MetricId','replace','function','format','orderBy','DESC','alias','joins','parse','parentKey','foreignTable','%s.%s\x20=\x20%s.%s','foreignKey','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','SELECT','MAX(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','IS\x20NOT\x20NULL','select','metric','No\x20available\x20data','output','web','fullPath','randomstring','generate','csv','custom','AnalyticExtractedReport','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','child_process','../../components/export/','join','../../files/reports','COUNT(*)'];(function(_0x4ccf96,_0x34978e){var _0xd103b7=function(_0x55736b){while(--_0x55736b){_0x4ccf96['push'](_0x4ccf96['shift']());}};_0xd103b7(++_0x34978e);}(_0x60b1,0xaa));var _0x160b=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0x60b1[_0x14add3];return _0x4a174f;};'use strict';var pdf=require(_0x160b('0x0'));var emlformat=require(_0x160b('0x1'));var rimraf=require(_0x160b('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x160b('0x3'));var rp=require(_0x160b('0x4'));var moment=require(_0x160b('0x5'));var BPromise=require(_0x160b('0x6'));var Mustache=require(_0x160b('0x7'));var util=require('util');var path=require(_0x160b('0x8'));var sox=require(_0x160b('0x9'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0x160b('0xa'));var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x160b('0xb'));var toCsv=require(_0x160b('0xc'));var querystring=require(_0x160b('0xd'));var Papa=require(_0x160b('0xe'));var Redis=require(_0x160b('0xf'));var authService=require(_0x160b('0x10'));var qs=require(_0x160b('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x160b('0x12'))(_0x160b('0x13'));var utils=require(_0x160b('0x14'));var config=require(_0x160b('0x15'));var licenseUtil=require(_0x160b('0x16'));var db=require(_0x160b('0x17'))['db'];var dbH=require(_0x160b('0x17'))[_0x160b('0x18')];function respondWithStatusCode(_0x26ae1a,_0xae63ba){_0xae63ba=_0xae63ba||0xcc;return function(_0x232b17){if(_0x232b17){return _0x26ae1a[_0x160b('0x19')](_0xae63ba);}return _0x26ae1a[_0x160b('0x1a')](_0xae63ba)[_0x160b('0x1b')]();};}function respondWithResult(_0x4dce24,_0x971f4f){_0x971f4f=_0x971f4f||0xc8;return function(_0x583a92){if(_0x583a92){return _0x4dce24['status'](_0x971f4f)[_0x160b('0x1c')](_0x583a92);}};}function respondWithFilteredResult(_0x15e364,_0x1ee81c){return function(_0x1d8acf){if(_0x1d8acf){var _0x5d970b=_0x1d8acf[_0x160b('0x1d')],_0x522a38=_0x1ee81c[_0x160b('0x1e')],_0x4874b9=_0x1ee81c[_0x160b('0x1e')]+_0x1ee81c[_0x160b('0x1f')],_0x46a494;if(_0x4874b9>=_0x5d970b){_0x4874b9=_0x5d970b;_0x46a494=0xc8;}else{_0x46a494=0xce;}_0x15e364[_0x160b('0x1a')](_0x46a494);return _0x15e364[_0x160b('0x20')](_0x160b('0x21'),_0x522a38+'-'+_0x4874b9+'/'+_0x5d970b)[_0x160b('0x1c')](_0x1d8acf);}return null;};}function patchUpdates(_0x74728e){return function(_0x1540d9){try{jsonpatch[_0x160b('0x22')](_0x1540d9,_0x74728e,!![]);}catch(_0x3318ab){return BPromise[_0x160b('0x23')](_0x3318ab);}return _0x1540d9[_0x160b('0x24')]();};}function saveUpdates(_0x1d8397,_0x5ea3d2){return function(_0x3fd70d){if(_0x3fd70d){return _0x3fd70d[_0x160b('0x25')](_0x1d8397)['then'](function(_0x29a3b8){return _0x29a3b8;});}return null;};}function removeEntity(_0x323db1,_0x5b56b1){return function(_0x5262e9){if(_0x5262e9){return _0x5262e9[_0x160b('0x26')]()[_0x160b('0x27')](function(){var _0x2ae4c4=_0x5262e9[_0x160b('0x28')]({'plain':!![]});var _0x3e56e6='CustomReports';return db[_0x160b('0x29')][_0x160b('0x26')]({'where':{'type':_0x3e56e6,'resourceId':_0x2ae4c4['id']}})['then'](function(){return _0x5262e9;});})[_0x160b('0x27')](function(){_0x323db1['status'](0xcc)[_0x160b('0x1b')]();});}};}function handleEntityNotFound(_0xcf3adb,_0x2a1818){return function(_0x5936b4){if(!_0x5936b4){_0xcf3adb[_0x160b('0x19')](0x194);}return _0x5936b4;};}function handleError(_0x171b01,_0x533c8a){_0x533c8a=_0x533c8a||0x1f4;return function(_0x491c9f){logger['error'](_0x491c9f[_0x160b('0x2a')]);if(_0x491c9f[_0x160b('0x2b')]){delete _0x491c9f[_0x160b('0x2b')];}_0x171b01[_0x160b('0x1a')](_0x533c8a)[_0x160b('0x2c')](_0x491c9f);};}exports[_0x160b('0x2d')]=function(_0x18bf01,_0x56e9ea){var _0x3846c5={},_0x5ec501={},_0x5115de={'count':0x0,'rows':[]};var _0xf2da8a=_[_0x160b('0x2e')](db[_0x160b('0x2f')]['rawAttributes'],function(_0x3e8677){return{'name':_0x3e8677['fieldName'],'type':_0x3e8677[_0x160b('0x30')][_0x160b('0x31')]};});_0x5ec501['model']=_[_0x160b('0x2e')](_0xf2da8a,_0x160b('0x2b'));_0x5ec501[_0x160b('0x32')]=_[_0x160b('0x33')](_0x18bf01[_0x160b('0x32')]);_0x5ec501[_0x160b('0x34')]=_[_0x160b('0x35')](_0x5ec501[_0x160b('0x36')],_0x5ec501[_0x160b('0x32')]);_0x3846c5[_0x160b('0x37')]=_[_0x160b('0x35')](_0x5ec501[_0x160b('0x36')],qs[_0x160b('0x38')](_0x18bf01[_0x160b('0x32')][_0x160b('0x38')]));_0x3846c5[_0x160b('0x37')]=_0x3846c5[_0x160b('0x37')]['length']?_0x3846c5[_0x160b('0x37')]:_0x5ec501[_0x160b('0x36')];if(!_0x18bf01['query'][_0x160b('0x39')](_0x160b('0x3a'))){_0x3846c5['limit']=qs['limit'](_0x18bf01[_0x160b('0x32')][_0x160b('0x1f')]);_0x3846c5[_0x160b('0x1e')]=qs[_0x160b('0x1e')](_0x18bf01[_0x160b('0x32')]['offset']);}_0x3846c5[_0x160b('0x3b')]=qs['sort'](_0x18bf01['query'][_0x160b('0x3c')]);_0x3846c5['where']=qs['filters'](_[_0x160b('0x3d')](_0x18bf01[_0x160b('0x32')],_0x5ec501[_0x160b('0x34')]),_0xf2da8a);if(_0x18bf01[_0x160b('0x32')]['filter']){_0x3846c5['where']=_[_0x160b('0x3e')](_0x3846c5[_0x160b('0x3f')],{'$or':_['map'](_0xf2da8a,function(_0x25589f){if(_0x25589f[_0x160b('0x30')]!==_0x160b('0x40')){var _0x2c9868={};_0x2c9868[_0x25589f['name']]={'$like':'%'+_0x18bf01[_0x160b('0x32')][_0x160b('0x41')]+'%'};return _0x2c9868;}})});}_0x3846c5=_[_0x160b('0x3e')]({},_0x3846c5,_0x18bf01[_0x160b('0x42')]);var _0x1c7baf={'where':_0x3846c5[_0x160b('0x3f')]};return db[_0x160b('0x2f')]['count'](_0x1c7baf)['then'](function(_0x87265c){_0x5115de[_0x160b('0x1d')]=_0x87265c;if(_0x18bf01[_0x160b('0x32')][_0x160b('0x43')]){_0x3846c5[_0x160b('0x44')]=[{'all':!![]}];}return db[_0x160b('0x2f')][_0x160b('0x45')](_0x3846c5);})[_0x160b('0x27')](function(_0x48a69a){_0x5115de[_0x160b('0x46')]=_0x48a69a;return _0x5115de;})['then'](respondWithFilteredResult(_0x56e9ea,_0x3846c5))[_0x160b('0x47')](handleError(_0x56e9ea,null));};exports[_0x160b('0x48')]=function(_0x3da478,_0x2a22fb){var _0x153fd2={'raw':![],'where':{'id':_0x3da478[_0x160b('0x49')]['id']}},_0x58e2b1={};_0x58e2b1[_0x160b('0x36')]=_[_0x160b('0x33')](db['AnalyticCustomReport'][_0x160b('0x4a')]);_0x58e2b1[_0x160b('0x32')]=_[_0x160b('0x33')](_0x3da478['query']);_0x58e2b1['filters']=_[_0x160b('0x35')](_0x58e2b1['model'],_0x58e2b1[_0x160b('0x32')]);_0x153fd2[_0x160b('0x37')]=_[_0x160b('0x35')](_0x58e2b1['model'],qs[_0x160b('0x38')](_0x3da478['query'][_0x160b('0x38')]));_0x153fd2[_0x160b('0x37')]=_0x153fd2['attributes'][_0x160b('0x4b')]?_0x153fd2[_0x160b('0x37')]:_0x58e2b1['model'];if(_0x3da478['query'][_0x160b('0x43')]){_0x153fd2[_0x160b('0x44')]=[{'all':!![]}];}_0x153fd2=_[_0x160b('0x3e')]({},_0x153fd2,_0x3da478[_0x160b('0x42')]);return db['AnalyticCustomReport'][_0x160b('0x4c')](_0x153fd2)['then'](handleEntityNotFound(_0x2a22fb,null))[_0x160b('0x27')](respondWithResult(_0x2a22fb,null))['catch'](handleError(_0x2a22fb,null));};exports[_0x160b('0x4d')]=function(_0x3349ec,_0x16e0e2){return db[_0x160b('0x2f')][_0x160b('0x4d')](_0x3349ec[_0x160b('0x4e')],{})[_0x160b('0x27')](function(_0x596d77){var _0x320044=_0x3349ec[_0x160b('0x4f')][_0x160b('0x28')]({'plain':!![]});if(!_0x320044)throw new Error(_0x160b('0x50'));if(_0x320044[_0x160b('0x51')]===_0x160b('0x4f')){var _0x281aa0=_0x596d77[_0x160b('0x28')]({'plain':!![]});var _0x1e1077='Reports';return db[_0x160b('0x52')][_0x160b('0x4c')]({'where':{'name':_0x1e1077,'userProfileId':_0x320044['userProfileId']},'raw':!![]})[_0x160b('0x27')](function(_0x2fe8a0){if(_0x2fe8a0&&_0x2fe8a0[_0x160b('0x53')]===0x0){return db[_0x160b('0x29')][_0x160b('0x4d')]({'name':_0x281aa0[_0x160b('0x2b')],'resourceId':_0x281aa0['id'],'type':'CustomReports','sectionId':_0x2fe8a0['id']},{})[_0x160b('0x27')](function(){return _0x596d77;});}else{return _0x596d77;}})[_0x160b('0x47')](function(_0x47f478){logger[_0x160b('0x54')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x47f478);throw _0x47f478;});}return _0x596d77;})['then'](respondWithResult(_0x16e0e2,0xc9))['catch'](handleError(_0x16e0e2,null));};exports['update']=function(_0x1041d0,_0x536402){if(_0x1041d0[_0x160b('0x4e')]['id']){delete _0x1041d0['body']['id'];}return db[_0x160b('0x2f')][_0x160b('0x4c')]({'where':{'id':_0x1041d0[_0x160b('0x49')]['id']}})[_0x160b('0x27')](handleEntityNotFound(_0x536402,null))[_0x160b('0x27')](saveUpdates(_0x1041d0[_0x160b('0x4e')],null))[_0x160b('0x27')](respondWithResult(_0x536402,null))[_0x160b('0x47')](handleError(_0x536402,null));};exports['destroy']=function(_0x3276ad,_0x45c3ef){return db['AnalyticCustomReport'][_0x160b('0x4c')]({'where':{'id':_0x3276ad[_0x160b('0x49')]['id']}})[_0x160b('0x27')](handleEntityNotFound(_0x45c3ef,null))[_0x160b('0x27')](removeEntity(_0x45c3ef,null))[_0x160b('0x47')](handleError(_0x45c3ef,null));};exports[_0x160b('0x55')]=function(_0x38a667,_0x2a20cf){var _0x371b3c=0xa;var _0x5235fe=['join',_0x160b('0x56'),_0x160b('0x57'),_0x160b('0x58')];var _0x10210a={'SUM':'SUM(%s)','COUNT':_0x160b('0x59'),'COUNT DISTINCT':_0x160b('0x5a'),'MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':_0x160b('0x5b'),'GROUP_CONCAT':_0x160b('0x5c'),'GROUP_CONCAT ASC':_0x160b('0x5d'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x306a49={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x160b('0x5e'),'HOUR':'HOUR(%s)','ROUND':_0x160b('0x5f'),'UNIX_TIMESTAMP':_0x160b('0x60')};var _0x3fc9b0=function(_0x257060){return!_[_0x160b('0x61')]([_0x160b('0x62'),'IS\x20NOT\x20NULL',_0x160b('0x63'),'IS\x20NOT\x20EMPTY'],_0x257060);};var _0x4fd794=function(_0x265f4f){if(!_0x265f4f||!_0x265f4f['rules'][_0x160b('0x4b')]){return'';}for(var _0x1a8661='(',_0x100940=0x0;_0x100940<_0x265f4f[_0x160b('0x64')][_0x160b('0x4b')];_0x100940+=0x1){_0x100940>0x0&&(_0x1a8661+='\x20'+_0x265f4f[_0x160b('0x65')]+'\x20');_0x1a8661+=_0x265f4f['rules'][_0x100940][_0x160b('0x66')]?_0x4fd794(_0x265f4f[_0x160b('0x64')][_0x100940][_0x160b('0x66')]):_0x265f4f[_0x160b('0x64')][_0x100940][_0x160b('0x67')]+'\x20'+_0x265f4f['rules'][_0x100940]['condition']+(_0x3fc9b0(_0x265f4f[_0x160b('0x64')][_0x100940][_0x160b('0x68')])?'\x20'+_0x265f4f[_0x160b('0x64')][_0x100940][_0x160b('0x69')]:'');}return _0x1a8661+')';};var _0x3ecc95={'where':{'id':_0x38a667[_0x160b('0x49')]['id']}},_0x53c233,_0x293e2f,_0xd9705a,_0x3adc73,_0x45fb20;_0x3ecc95=_[_0x160b('0x3e')]({},_0x3ecc95,_0x38a667[_0x160b('0x42')]);return db['AnalyticCustomReport'][_0x160b('0x4c')](_0x3ecc95)[_0x160b('0x27')](function(_0x31fb79){if(_0x31fb79){_0x53c233=_0x31fb79;return _0x31fb79[_0x160b('0x6a')]();}return null;})[_0x160b('0x27')](function(_0x23cd66){if(_0x23cd66){if(!_0x23cd66['length']){throw new db[(_0x160b('0x6b'))][(_0x160b('0x6c'))](_0x160b('0x6d'),0x193);}_0x293e2f=_0x23cd66;return db[_0x160b('0x6e')][_0x160b('0x45')]({'raw':!![]});}return null;})['then'](function(_0x10bf59){if(_0x10bf59){_0xd9705a=_[_0x160b('0x6f')](_0x10bf59,'id');var _0x3c645b;var _0x145e54=squel['select']();_0x145e54[_0x160b('0x70')](_0x53c233[_0x160b('0x71')]);for(var _0x494ea9=0x0;_0x494ea9<_0x293e2f[_0x160b('0x4b')];_0x494ea9+=0x1){_0x3c645b=_0x293e2f[_0x494ea9][_0x160b('0x72')]?_0xd9705a[_0x293e2f[_0x494ea9][_0x160b('0x72')]]['metric']:_0x293e2f[_0x494ea9]['field'];_0x3c645b=_0x293e2f[_0x494ea9]['function']?_[_0x160b('0x73')](_0x10210a[_0x293e2f[_0x494ea9][_0x160b('0x74')]],'%s',_0x3c645b):_0x3c645b;_0x3c645b=_0x293e2f[_0x494ea9][_0x160b('0x75')]?_[_0x160b('0x73')](_0x306a49[_0x293e2f[_0x494ea9][_0x160b('0x75')]],'%s',_0x3c645b):_0x3c645b;if(_0x293e2f[_0x494ea9]['groupBy']){_0x145e54[_0x160b('0x66')](_0x3c645b);}_0x293e2f[_0x494ea9]['orderBy']&&_0x145e54['order'](_0x3c645b,_0x293e2f[_0x494ea9][_0x160b('0x76')]===_0x160b('0x77')?![]:!![]);_0x145e54['field'](_0x3c645b,_0x293e2f[_0x494ea9][_0x160b('0x78')]||_0x3c645b);}if(_0x53c233[_0x160b('0x79')]){_0x53c233['joins']=JSON[_0x160b('0x7a')](_0x53c233[_0x160b('0x79')]);for(var _0x435b71=0x0;_0x435b71<_0x53c233[_0x160b('0x79')]['length'];_0x435b71+=0x1){if(_0x53c233[_0x160b('0x79')][_0x435b71][_0x160b('0x30')]&&_[_0x160b('0x61')](_0x5235fe,_0x53c233['joins'][_0x435b71]['type'])&&_0x53c233[_0x160b('0x79')][_0x435b71][_0x160b('0x7b')]&&_0x53c233['joins'][_0x435b71][_0x160b('0x7c')]&&_0x53c233[_0x160b('0x79')][_0x435b71]['foreignKey']){_0x145e54[_0x53c233['joins'][_0x435b71][_0x160b('0x30')]](_0x53c233['joins'][_0x435b71][_0x160b('0x7c')],null,util[_0x160b('0x75')](_0x160b('0x7d'),_0x53c233[_0x160b('0x71')],_0x53c233[_0x160b('0x79')][_0x435b71][_0x160b('0x7b')],_0x53c233[_0x160b('0x79')][_0x435b71][_0x160b('0x7c')],_0x53c233[_0x160b('0x79')][_0x435b71][_0x160b('0x7e')]));}}}if(_0x53c233[_0x160b('0x7f')]){_0x53c233[_0x160b('0x7f')]=JSON[_0x160b('0x7a')](_0x53c233[_0x160b('0x7f')]);_0x145e54[_0x160b('0x3f')](_0x4fd794(_0x53c233[_0x160b('0x7f')][_0x160b('0x66')]));}_0x45fb20=_0x145e54[_0x160b('0x80')]();_0x145e54[_0x160b('0x1f')](_0x371b3c);_0x145e54[_0x160b('0x1e')](0x0);logger[_0x160b('0x81')](_0x160b('0x82'),_0x145e54[_0x160b('0x83')]());return db[_0x160b('0x84')][_0x160b('0x32')](_0x145e54[_0x160b('0x83')](),{'type':db['sequelize'][_0x160b('0x85')][_0x160b('0x86')]});}})[_0x160b('0x27')](respondWithResult(_0x2a20cf,null))[_0x160b('0x47')](handleError(_0x2a20cf,null));};function runReport(_0x5e14d1,_0x3b4838,_0x1288c6){var _0x24a32b=_0x3b4838[_0x160b('0x2b')];var _0x35e8be=0xa;var _0x4d26ad=['join',_0x160b('0x56'),'right_join',_0x160b('0x58')];var _0xa28a27={'SUM':'SUM(%s)','COUNT':_0x160b('0x59'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x160b('0x87'),'MIN':'MIN(%s)','AVG':_0x160b('0x5b'),'GROUP_CONCAT':_0x160b('0x5c'),'GROUP_CONCAT ASC':_0x160b('0x5d'),'GROUP_CONCAT DESC':_0x160b('0x88')};var _0x961bc5={'SEC_TO_TIME':_0x160b('0x89'),'DATE':_0x160b('0x5e'),'HOUR':'HOUR(%s)','ROUND':_0x160b('0x5f'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x30a09d=function(_0x271cba){return!_[_0x160b('0x61')]([_0x160b('0x62'),_0x160b('0x8a'),_0x160b('0x63'),'IS\x20NOT\x20EMPTY'],_0x271cba);};var _0x24adfb=function(_0x2164ce){if(!_0x2164ce||!_0x2164ce[_0x160b('0x64')]['length']){return'';}for(var _0x54c86f='(',_0x1c3da1=0x0;_0x1c3da1<_0x2164ce[_0x160b('0x64')]['length'];_0x1c3da1+=0x1){_0x1c3da1>0x0&&(_0x54c86f+='\x20'+_0x2164ce[_0x160b('0x65')]+'\x20');_0x54c86f+=_0x2164ce[_0x160b('0x64')][_0x1c3da1][_0x160b('0x66')]?_0x24adfb(_0x2164ce[_0x160b('0x64')][_0x1c3da1][_0x160b('0x66')]):_0x2164ce[_0x160b('0x64')][_0x1c3da1][_0x160b('0x67')]+'\x20'+_0x2164ce[_0x160b('0x64')][_0x1c3da1][_0x160b('0x68')]+(_0x30a09d(_0x2164ce[_0x160b('0x64')][_0x1c3da1]['condition'])?'\x20'+_0x2164ce[_0x160b('0x64')][_0x1c3da1][_0x160b('0x69')]:'');}return _0x54c86f+')';};var _0x20f145={'where':{'id':_0x5e14d1['id']}},_0x24a72d,_0x94f903,_0x1c52c6,_0x449b70,_0x19c2a;_0x20f145=_[_0x160b('0x3e')]({},_0x20f145,_0x1288c6);return db[_0x160b('0x2f')][_0x160b('0x4c')](_0x20f145)['then'](function(_0x3b8869){if(_0x3b8869){_0x24a72d=_0x3b8869;return _0x3b8869[_0x160b('0x6a')]();}return null;})['then'](function(_0xda38f8){if(_0xda38f8){if(!_0xda38f8[_0x160b('0x4b')]){throw new db['Sequelize'][(_0x160b('0x6c'))](_0x160b('0x6d'),0x193);}_0x94f903=_0xda38f8;return db[_0x160b('0x6e')][_0x160b('0x45')]({'raw':!![]});}return null;})[_0x160b('0x27')](function(_0x4c11b4){if(_0x4c11b4){_0x1c52c6=_['keyBy'](_0x4c11b4,'id');var _0x52f8b6;var _0x2be722=squel[_0x160b('0x8b')]();_0x2be722[_0x160b('0x70')](_0x24a72d[_0x160b('0x71')]);for(var _0x386ccf=0x0;_0x386ccf<_0x94f903['length'];_0x386ccf+=0x1){_0x52f8b6=_0x94f903[_0x386ccf][_0x160b('0x72')]?_0x1c52c6[_0x94f903[_0x386ccf]['MetricId']][_0x160b('0x8c')]:_0x94f903[_0x386ccf][_0x160b('0x67')];_0x52f8b6=_0x94f903[_0x386ccf][_0x160b('0x74')]?_['replace'](_0xa28a27[_0x94f903[_0x386ccf]['function']],'%s',_0x52f8b6):_0x52f8b6;_0x52f8b6=_0x94f903[_0x386ccf][_0x160b('0x75')]?_[_0x160b('0x73')](_0x961bc5[_0x94f903[_0x386ccf][_0x160b('0x75')]],'%s',_0x52f8b6):_0x52f8b6;if(_0x94f903[_0x386ccf]['groupBy']){_0x2be722[_0x160b('0x66')](_0x52f8b6);}_0x94f903[_0x386ccf][_0x160b('0x76')]&&_0x2be722[_0x160b('0x3b')](_0x52f8b6,_0x94f903[_0x386ccf]['orderBy']==='DESC'?![]:!![]);_0x2be722['field'](_0x52f8b6,_0x94f903[_0x386ccf][_0x160b('0x78')]||_0x52f8b6);}if(_0x24a72d[_0x160b('0x79')]){_0x24a72d['joins']=JSON[_0x160b('0x7a')](_0x24a72d['joins']);for(var _0x589d6c=0x0;_0x589d6c<_0x24a72d[_0x160b('0x79')][_0x160b('0x4b')];_0x589d6c+=0x1){if(_0x24a72d[_0x160b('0x79')][_0x589d6c]['type']&&_[_0x160b('0x61')](_0x4d26ad,_0x24a72d[_0x160b('0x79')][_0x589d6c][_0x160b('0x30')])&&_0x24a72d[_0x160b('0x79')][_0x589d6c][_0x160b('0x7b')]&&_0x24a72d['joins'][_0x589d6c][_0x160b('0x7c')]&&_0x24a72d[_0x160b('0x79')][_0x589d6c]['foreignKey']){_0x2be722[_0x24a72d[_0x160b('0x79')][_0x589d6c][_0x160b('0x30')]](_0x24a72d['joins'][_0x589d6c][_0x160b('0x7c')],null,util['format'](_0x160b('0x7d'),_0x24a72d[_0x160b('0x71')],_0x24a72d['joins'][_0x589d6c]['parentKey'],_0x24a72d[_0x160b('0x79')][_0x589d6c][_0x160b('0x7c')],_0x24a72d[_0x160b('0x79')][_0x589d6c][_0x160b('0x7e')]));}}}if(_0x24a72d[_0x160b('0x7f')]){_0x24a72d['conditions']=JSON[_0x160b('0x7a')](_0x24a72d[_0x160b('0x7f')]);_0x2be722[_0x160b('0x3f')](_0x24adfb(_0x24a72d[_0x160b('0x7f')][_0x160b('0x66')]));}_0x19c2a=_0x2be722[_0x160b('0x80')]();_0x2be722['limit'](_0x35e8be);_0x2be722[_0x160b('0x1e')](0x0);logger[_0x160b('0x81')]('Limited\x20Query:',_0x2be722['toString']());return db[_0x160b('0x84')][_0x160b('0x32')](_0x2be722[_0x160b('0x83')](),{'type':db['sequelize'][_0x160b('0x85')][_0x160b('0x86')]});}})[_0x160b('0x27')](function(_0x26c2d6){if(!_0x26c2d6[_0x160b('0x4b')]){throw new db[(_0x160b('0x6b'))][(_0x160b('0x6c'))](_0x160b('0x8d'),0xcc);}if(_0x3b4838[_0x160b('0x8e')]===_0x160b('0x8f')){return null;}var _0x450608=_[_0x160b('0x3e')](_0x3b4838,{'name':_0x3b4838[_0x160b('0x90')]||_0x3b4838[_0x160b('0x2b')]||_0x24a72d[_0x160b('0x2b')],'basename':_0x24a32b,'savename':util[_0x160b('0x75')]('%s-%s.%s',_0x3b4838[_0x160b('0x2b')]||_0x24a72d['name'],require(_0x160b('0x91'))[_0x160b('0x92')](0x4),_0x3b4838[_0x160b('0x8e')]||_0x160b('0x93')),'reportId':_0x24a72d['id'],'reportType':_0x160b('0x94')});return db[_0x160b('0x95')]['create'](_0x450608,{'raw':!![]});})[_0x160b('0x27')](function(_0x5ad007){if(_0x24a72d['table']==='cdr'){_0x19c2a[_0x160b('0x3f')](_0x24a72d[_0x160b('0x71')]+_0x160b('0x96'),_0x3b4838[_0x160b('0x97')],_0x3b4838[_0x160b('0x98')]);}else{_0x19c2a[_0x160b('0x3f')](_0x24a72d[_0x160b('0x71')]+_0x160b('0x99'),_0x3b4838[_0x160b('0x97')],_0x3b4838['endDate']);}if(_0x5ad007){logger[_0x160b('0x9a')]('Run\x20Query:',_0x19c2a[_0x160b('0x83')]());require(_0x160b('0x9b'))['fork'](path['join'](__dirname,_0x160b('0x9c'),_0x5ad007[_0x160b('0x8e')]),[_0x5ad007['id'],_0x19c2a[_0x160b('0x83')](),path[_0x160b('0x9d')](__dirname,_0x160b('0x9e'),_0x5ad007['savename']),_0x24a32b]);return _0x5ad007;}else{var _0x50430e=squel[_0x160b('0x8b')]();_0x50430e[_0x160b('0x70')]('('+_0x19c2a['toString']()+')','countTable');_0x50430e[_0x160b('0x67')](_0x160b('0x9f'),_0x160b('0x1d'));_0x19c2a[_0x160b('0x1f')](_0x3b4838[_0x160b('0x1f')]||_0x35e8be);_0x19c2a[_0x160b('0x1e')](_0x3b4838[_0x160b('0x1e')]||0x0);return dbH[_0x160b('0x84')][_0x160b('0x32')](_0x50430e[_0x160b('0x83')](),{'type':dbH[_0x160b('0x84')][_0x160b('0x85')][_0x160b('0x86')]})[_0x160b('0x27')](function(_0x4dced8){if(!_0x4dced8[_0x160b('0x4b')]){_0x449b70=0x0;}else{_0x449b70=_0x4dced8[0x0][_0x160b('0x1d')]||0x0;}return dbH[_0x160b('0x84')]['query'](_0x19c2a[_0x160b('0x83')](),{'type':dbH[_0x160b('0x84')][_0x160b('0x85')][_0x160b('0x86')]});})[_0x160b('0x27')](function(_0x4dc944){return{'rows':_0x4dc944||[],'count':_0x449b70};});}});}exports['run']=function(_0x4712b2,_0x1711cc){return runReport(_0x4712b2[_0x160b('0x49')],_0x4712b2['query'],_0x4712b2[_0x160b('0x42')])[_0x160b('0x27')](respondWithResult(_0x1711cc,null))['catch'](handleError(_0x1711cc,null));};exports[_0x160b('0xa0')]=runReport;exports[_0x160b('0x32')]=function(_0x226326,_0x49a35f){var _0x2a8539=0xa;var _0xe588ad=[_0x160b('0x9d'),_0x160b('0x56'),_0x160b('0x57'),_0x160b('0x58')];var _0x1c94ef={'SUM':_0x160b('0xa1'),'COUNT':_0x160b('0x59'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x160b('0x87'),'MIN':_0x160b('0xa2'),'AVG':'AVG(%s)','GROUP_CONCAT':_0x160b('0x5c'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x160b('0x88')};var _0x3a1132={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x160b('0x5e'),'HOUR':_0x160b('0xa3'),'ROUND':_0x160b('0x5f'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x3e800b=function(_0x8126af){return!_['includes']([_0x160b('0x62'),_0x160b('0x8a'),_0x160b('0x63'),_0x160b('0xa4')],_0x8126af);};var _0x240777=function(_0x47e9ba){if(!_0x47e9ba||!_0x47e9ba[_0x160b('0x64')][_0x160b('0x4b')]){return'';}for(var _0x105a64='(',_0x2fb1c9=0x0;_0x2fb1c9<_0x47e9ba[_0x160b('0x64')][_0x160b('0x4b')];_0x2fb1c9+=0x1){_0x2fb1c9>0x0&&(_0x105a64+='\x20'+_0x47e9ba[_0x160b('0x65')]+'\x20');_0x105a64+=_0x47e9ba['rules'][_0x2fb1c9]['group']?_0x240777(_0x47e9ba[_0x160b('0x64')][_0x2fb1c9][_0x160b('0x66')]):_0x47e9ba[_0x160b('0x64')][_0x2fb1c9][_0x160b('0x67')]+'\x20'+_0x47e9ba[_0x160b('0x64')][_0x2fb1c9]['condition']+(_0x3e800b(_0x47e9ba['rules'][_0x2fb1c9][_0x160b('0x68')])?'\x20'+_0x47e9ba[_0x160b('0x64')][_0x2fb1c9]['value']:'');}return _0x105a64+')';};var _0x203d9e={'where':{'id':_0x226326['params']['id']}},_0xb2b0e5,_0x3fd896,_0x483ad6,_0x1ea959,_0x6df375;_0x203d9e=_[_0x160b('0x3e')]({},_0x203d9e,_0x226326['options']);return db[_0x160b('0x2f')][_0x160b('0x4c')](_0x203d9e)[_0x160b('0x27')](function(_0x5d2c3c){if(_0x5d2c3c){_0xb2b0e5=_0x5d2c3c;return _0x5d2c3c[_0x160b('0x6a')]();}return null;})['then'](function(_0x7e1249){if(_0x7e1249){if(!_0x7e1249[_0x160b('0x4b')]){throw new db['Sequelize'][(_0x160b('0x6c'))](_0x160b('0x6d'),0x193);}_0x3fd896=_0x7e1249;return db['AnalyticMetric'][_0x160b('0x45')]({'raw':!![]});}return null;})[_0x160b('0x27')](function(_0x4b47e3){if(_0x4b47e3){_0x483ad6=_[_0x160b('0x6f')](_0x4b47e3,'id');var _0x2d2d9a;var _0x3a4005=squel['select']();_0x3a4005[_0x160b('0x70')](_0xb2b0e5[_0x160b('0x71')]);for(var _0x592fc4=0x0;_0x592fc4<_0x3fd896[_0x160b('0x4b')];_0x592fc4+=0x1){_0x2d2d9a=_0x3fd896[_0x592fc4][_0x160b('0x72')]?_0x483ad6[_0x3fd896[_0x592fc4]['MetricId']][_0x160b('0x8c')]:_0x3fd896[_0x592fc4]['field'];_0x2d2d9a=_0x3fd896[_0x592fc4]['function']?_['replace'](_0x1c94ef[_0x3fd896[_0x592fc4]['function']],'%s',_0x2d2d9a):_0x2d2d9a;_0x2d2d9a=_0x3fd896[_0x592fc4][_0x160b('0x75')]?_[_0x160b('0x73')](_0x3a1132[_0x3fd896[_0x592fc4][_0x160b('0x75')]],'%s',_0x2d2d9a):_0x2d2d9a;if(_0x3fd896[_0x592fc4]['groupBy']){_0x3a4005[_0x160b('0x66')](_0x2d2d9a);}_0x3fd896[_0x592fc4][_0x160b('0x76')]&&_0x3a4005[_0x160b('0x3b')](_0x2d2d9a,_0x3fd896[_0x592fc4][_0x160b('0x76')]===_0x160b('0x77')?![]:!![]);_0x3a4005[_0x160b('0x67')](_0x2d2d9a,_0x3fd896[_0x592fc4]['alias']||_0x2d2d9a);}if(_0xb2b0e5[_0x160b('0x79')]){_0xb2b0e5[_0x160b('0x79')]=JSON['parse'](_0xb2b0e5[_0x160b('0x79')]);for(var _0xdebccd=0x0;_0xdebccd<_0xb2b0e5[_0x160b('0x79')][_0x160b('0x4b')];_0xdebccd+=0x1){if(_0xb2b0e5[_0x160b('0x79')][_0xdebccd][_0x160b('0x30')]&&_['includes'](_0xe588ad,_0xb2b0e5[_0x160b('0x79')][_0xdebccd][_0x160b('0x30')])&&_0xb2b0e5[_0x160b('0x79')][_0xdebccd][_0x160b('0x7b')]&&_0xb2b0e5[_0x160b('0x79')][_0xdebccd]['foreignTable']&&_0xb2b0e5[_0x160b('0x79')][_0xdebccd]['foreignKey']){_0x3a4005[_0xb2b0e5[_0x160b('0x79')][_0xdebccd]['type']](_0xb2b0e5[_0x160b('0x79')][_0xdebccd][_0x160b('0x7c')],null,util[_0x160b('0x75')](_0x160b('0x7d'),_0xb2b0e5[_0x160b('0x71')],_0xb2b0e5[_0x160b('0x79')][_0xdebccd][_0x160b('0x7b')],_0xb2b0e5[_0x160b('0x79')][_0xdebccd][_0x160b('0x7c')],_0xb2b0e5[_0x160b('0x79')][_0xdebccd][_0x160b('0x7e')]));}}}if(_0xb2b0e5[_0x160b('0x7f')]){_0xb2b0e5[_0x160b('0x7f')]=JSON['parse'](_0xb2b0e5[_0x160b('0x7f')]);_0x3a4005[_0x160b('0x3f')](_0x240777(_0xb2b0e5['conditions']['group']));}_0x6df375=_0x3a4005[_0x160b('0x80')]();_0x3a4005[_0x160b('0x1f')](_0x2a8539);_0x3a4005[_0x160b('0x1e')](0x0);logger['debug'](_0x160b('0x82'),_0x3a4005[_0x160b('0x83')]());return db[_0x160b('0x84')][_0x160b('0x32')](_0x3a4005['toString'](),{'type':db[_0x160b('0x84')]['QueryTypes'][_0x160b('0x86')]});}})[_0x160b('0x27')](function(){return{'sql':_0x6df375[_0x160b('0x83')]()};})[_0x160b('0x27')](respondWithResult(_0x49a35f,null))[_0x160b('0x47')](handleError(_0x49a35f,null));};
\ No newline at end of file