Built motion from commit (unavailable).|2.5.13
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 59d8862..b4000f3 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 _0x43d1=['show','params','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Reports','UserProfileSection','userProfileId','autoAssociation','body','join','left_join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','HOUR(%s)','ROUND(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','group','field','condition','value','find','getFields','Sequelize','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','select','from','table','MetricId','metric','function','replace','format','groupBy','orderBy','alias','joins','parentKey','foreignTable','%s.%s\x20=\x20%s.%s','foreignKey','conditions','clone','toString','sequelize','SELECT','MAX(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','DATE(%s)','ValidationErrorItem','DESC','parse','Limited\x20Query:','No\x20available\x20data','web','fullPath','randomstring','generate','output','custom','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','child_process','fork','../../components/export/','../../files/reports','savename','QueryTypes','run','runReport','UNIX_TIMESTAMP(%s)','operator','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','json','count','offset','limit','set','apply','reject','save','update','then','destroy','get','UserProfileResource','end','error','stack','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','AnalyticCustomReport','includeAll','include','findAll','rows','catch'];(function(_0xd0b415,_0x149675){var _0x2bdf2c=function(_0x59fbfa){while(--_0x59fbfa){_0xd0b415['push'](_0xd0b415['shift']());}};_0x2bdf2c(++_0x149675);}(_0x43d1,0x10c));var _0x143d=function(_0x5b7e31,_0xc752b1){_0x5b7e31=_0x5b7e31-0x0;var _0x441d28=_0x43d1[_0x5b7e31];return _0x441d28;};'use strict';var pdf=require(_0x143d('0x0'));var emlformat=require(_0x143d('0x1'));var rimraf=require(_0x143d('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x143d('0x3'));var rp=require(_0x143d('0x4'));var moment=require(_0x143d('0x5'));var BPromise=require(_0x143d('0x6'));var Mustache=require(_0x143d('0x7'));var util=require(_0x143d('0x8'));var path=require(_0x143d('0x9'));var sox=require(_0x143d('0xa'));var csv=require(_0x143d('0xb'));var ejs=require(_0x143d('0xc'));var fs=require('fs');var _=require(_0x143d('0xd'));var squel=require(_0x143d('0xe'));var crypto=require(_0x143d('0xf'));var jsforce=require(_0x143d('0x10'));var deskjs=require(_0x143d('0x11'));var toCsv=require('to-csv');var querystring=require(_0x143d('0x12'));var Papa=require('papaparse');var Redis=require(_0x143d('0x13'));var authService=require(_0x143d('0x14'));var qs=require(_0x143d('0x15'));var as=require(_0x143d('0x16'));var hardwareService=require(_0x143d('0x17'));var logger=require(_0x143d('0x18'))(_0x143d('0x19'));var utils=require(_0x143d('0x1a'));var config=require(_0x143d('0x1b'));var licenseUtil=require(_0x143d('0x1c'));var db=require(_0x143d('0x1d'))['db'];var dbH=require(_0x143d('0x1d'))[_0x143d('0x1e')];function respondWithStatusCode(_0x1657c4,_0x57383f){_0x57383f=_0x57383f||0xcc;return function(_0x5d9e06){if(_0x5d9e06){return _0x1657c4[_0x143d('0x1f')](_0x57383f);}return _0x1657c4['status'](_0x57383f)['end']();};}function respondWithResult(_0x4f5031,_0x238c89){_0x238c89=_0x238c89||0xc8;return function(_0x23ea0c){if(_0x23ea0c){return _0x4f5031[_0x143d('0x20')](_0x238c89)[_0x143d('0x21')](_0x23ea0c);}};}function respondWithFilteredResult(_0xc5f756,_0x5a5fbb){return function(_0x19a850){if(_0x19a850){var _0x2798b7=_0x19a850[_0x143d('0x22')],_0x7d1769=_0x5a5fbb[_0x143d('0x23')],_0x5cd31b=_0x5a5fbb[_0x143d('0x23')]+_0x5a5fbb[_0x143d('0x24')],_0x7954d;if(_0x5cd31b>=_0x2798b7){_0x5cd31b=_0x2798b7;_0x7954d=0xc8;}else{_0x7954d=0xce;}_0xc5f756[_0x143d('0x20')](_0x7954d);return _0xc5f756[_0x143d('0x25')]('Content-Range',_0x7d1769+'-'+_0x5cd31b+'/'+_0x2798b7)['json'](_0x19a850);}return null;};}function patchUpdates(_0x2cc7d4){return function(_0x299b20){try{jsonpatch[_0x143d('0x26')](_0x299b20,_0x2cc7d4,!![]);}catch(_0x4831e5){return BPromise[_0x143d('0x27')](_0x4831e5);}return _0x299b20[_0x143d('0x28')]();};}function saveUpdates(_0x545d26,_0x3b6082){return function(_0x30fa83){if(_0x30fa83){return _0x30fa83[_0x143d('0x29')](_0x545d26)[_0x143d('0x2a')](function(_0x4c7ecc){return _0x4c7ecc;});}return null;};}function removeEntity(_0x687d0d,_0x1bcf6a){return function(_0x2a6249){if(_0x2a6249){return _0x2a6249[_0x143d('0x2b')]()[_0x143d('0x2a')](function(){var _0x24105d=_0x2a6249[_0x143d('0x2c')]({'plain':!![]});var _0x183b60='CustomReports';return db[_0x143d('0x2d')][_0x143d('0x2b')]({'where':{'type':_0x183b60,'resourceId':_0x24105d['id']}})[_0x143d('0x2a')](function(){return _0x2a6249;});})['then'](function(){_0x687d0d[_0x143d('0x20')](0xcc)[_0x143d('0x2e')]();});}};}function handleEntityNotFound(_0x25965f,_0x3188fe){return function(_0x989a4){if(!_0x989a4){_0x25965f['sendStatus'](0x194);}return _0x989a4;};}function handleError(_0x406aa4,_0x43390a){_0x43390a=_0x43390a||0x1f4;return function(_0x327b38){logger[_0x143d('0x2f')](_0x327b38[_0x143d('0x30')]);if(_0x327b38[_0x143d('0x31')]){delete _0x327b38[_0x143d('0x31')];}_0x406aa4['status'](_0x43390a)['send'](_0x327b38);};}exports[_0x143d('0x32')]=function(_0x1426f4,_0x49c73a){var _0xddc20c={},_0x51fb1f={},_0x58fe28={'count':0x0,'rows':[]};var _0x3dc1cc=_[_0x143d('0x33')](db['AnalyticCustomReport'][_0x143d('0x34')],function(_0x4ba2c5){return{'name':_0x4ba2c5[_0x143d('0x35')],'type':_0x4ba2c5[_0x143d('0x36')][_0x143d('0x37')]};});_0x51fb1f[_0x143d('0x38')]=_[_0x143d('0x33')](_0x3dc1cc,'name');_0x51fb1f[_0x143d('0x39')]=_[_0x143d('0x3a')](_0x1426f4[_0x143d('0x39')]);_0x51fb1f[_0x143d('0x3b')]=_[_0x143d('0x3c')](_0x51fb1f[_0x143d('0x38')],_0x51fb1f[_0x143d('0x39')]);_0xddc20c['attributes']=_[_0x143d('0x3c')](_0x51fb1f[_0x143d('0x38')],qs[_0x143d('0x3d')](_0x1426f4[_0x143d('0x39')][_0x143d('0x3d')]));_0xddc20c['attributes']=_0xddc20c[_0x143d('0x3e')][_0x143d('0x3f')]?_0xddc20c[_0x143d('0x3e')]:_0x51fb1f[_0x143d('0x38')];if(!_0x1426f4['query'][_0x143d('0x40')](_0x143d('0x41'))){_0xddc20c[_0x143d('0x24')]=qs['limit'](_0x1426f4['query'][_0x143d('0x24')]);_0xddc20c[_0x143d('0x23')]=qs[_0x143d('0x23')](_0x1426f4[_0x143d('0x39')][_0x143d('0x23')]);}_0xddc20c[_0x143d('0x42')]=qs[_0x143d('0x43')](_0x1426f4[_0x143d('0x39')]['sort']);_0xddc20c[_0x143d('0x44')]=qs[_0x143d('0x3b')](_[_0x143d('0x45')](_0x1426f4['query'],_0x51fb1f[_0x143d('0x3b')]),_0x3dc1cc);if(_0x1426f4[_0x143d('0x39')][_0x143d('0x46')]){_0xddc20c[_0x143d('0x44')]=_[_0x143d('0x47')](_0xddc20c[_0x143d('0x44')],{'$or':_['map'](_0x3dc1cc,function(_0x24002a){if(_0x24002a[_0x143d('0x36')]!==_0x143d('0x48')){var _0x415de6={};_0x415de6[_0x24002a[_0x143d('0x31')]]={'$like':'%'+_0x1426f4[_0x143d('0x39')][_0x143d('0x46')]+'%'};return _0x415de6;}})});}_0xddc20c=_[_0x143d('0x47')]({},_0xddc20c,_0x1426f4[_0x143d('0x49')]);var _0x3734f1={'where':_0xddc20c['where']};return db[_0x143d('0x4a')][_0x143d('0x22')](_0x3734f1)[_0x143d('0x2a')](function(_0x27d485){_0x58fe28[_0x143d('0x22')]=_0x27d485;if(_0x1426f4['query'][_0x143d('0x4b')]){_0xddc20c[_0x143d('0x4c')]=[{'all':!![]}];}return db[_0x143d('0x4a')][_0x143d('0x4d')](_0xddc20c);})[_0x143d('0x2a')](function(_0x3d2838){_0x58fe28[_0x143d('0x4e')]=_0x3d2838;return _0x58fe28;})['then'](respondWithFilteredResult(_0x49c73a,_0xddc20c))[_0x143d('0x4f')](handleError(_0x49c73a,null));};exports[_0x143d('0x50')]=function(_0x4b0741,_0x5e74a7){var _0x5e1283={'raw':![],'where':{'id':_0x4b0741[_0x143d('0x51')]['id']}},_0x25fb54={};_0x25fb54[_0x143d('0x38')]=_[_0x143d('0x3a')](db[_0x143d('0x4a')][_0x143d('0x34')]);_0x25fb54[_0x143d('0x39')]=_[_0x143d('0x3a')](_0x4b0741['query']);_0x25fb54[_0x143d('0x3b')]=_['intersection'](_0x25fb54['model'],_0x25fb54[_0x143d('0x39')]);_0x5e1283[_0x143d('0x3e')]=_[_0x143d('0x3c')](_0x25fb54[_0x143d('0x38')],qs['fields'](_0x4b0741['query'][_0x143d('0x3d')]));_0x5e1283[_0x143d('0x3e')]=_0x5e1283[_0x143d('0x3e')][_0x143d('0x3f')]?_0x5e1283[_0x143d('0x3e')]:_0x25fb54[_0x143d('0x38')];if(_0x4b0741[_0x143d('0x39')][_0x143d('0x4b')]){_0x5e1283[_0x143d('0x4c')]=[{'all':!![]}];}_0x5e1283=_['merge']({},_0x5e1283,_0x4b0741[_0x143d('0x49')]);return db['AnalyticCustomReport']['find'](_0x5e1283)[_0x143d('0x2a')](handleEntityNotFound(_0x5e74a7,null))[_0x143d('0x2a')](respondWithResult(_0x5e74a7,null))['catch'](handleError(_0x5e74a7,null));};exports[_0x143d('0x52')]=function(_0x2e747a,_0x59f8f7){return db[_0x143d('0x4a')][_0x143d('0x52')](_0x2e747a['body'],{})[_0x143d('0x2a')](function(_0x2b47d2){var _0x3a1e32=_0x2e747a[_0x143d('0x53')][_0x143d('0x2c')]({'plain':!![]});if(!_0x3a1e32)throw new Error(_0x143d('0x54'));if(_0x3a1e32[_0x143d('0x55')]===_0x143d('0x53')){var _0x58188e=_0x2b47d2['get']({'plain':!![]});var _0x9b3154=_0x143d('0x56');return db[_0x143d('0x57')]['find']({'where':{'name':_0x9b3154,'userProfileId':_0x3a1e32[_0x143d('0x58')]},'raw':!![]})[_0x143d('0x2a')](function(_0x534a61){if(_0x534a61&&_0x534a61[_0x143d('0x59')]===0x0){return db[_0x143d('0x2d')][_0x143d('0x52')]({'name':_0x58188e[_0x143d('0x31')],'resourceId':_0x58188e['id'],'type':'CustomReports','sectionId':_0x534a61['id']},{})[_0x143d('0x2a')](function(){return _0x2b47d2;});}else{return _0x2b47d2;}})[_0x143d('0x4f')](function(_0x31b3ce){logger[_0x143d('0x2f')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x31b3ce);throw _0x31b3ce;});}return _0x2b47d2;})[_0x143d('0x2a')](respondWithResult(_0x59f8f7,0xc9))[_0x143d('0x4f')](handleError(_0x59f8f7,null));};exports[_0x143d('0x29')]=function(_0x312ade,_0x4e98c0){if(_0x312ade[_0x143d('0x5a')]['id']){delete _0x312ade['body']['id'];}return db['AnalyticCustomReport']['find']({'where':{'id':_0x312ade[_0x143d('0x51')]['id']}})[_0x143d('0x2a')](handleEntityNotFound(_0x4e98c0,null))[_0x143d('0x2a')](saveUpdates(_0x312ade[_0x143d('0x5a')],null))[_0x143d('0x2a')](respondWithResult(_0x4e98c0,null))[_0x143d('0x4f')](handleError(_0x4e98c0,null));};exports[_0x143d('0x2b')]=function(_0x155d65,_0x5bf09d){return db[_0x143d('0x4a')]['find']({'where':{'id':_0x155d65[_0x143d('0x51')]['id']}})[_0x143d('0x2a')](handleEntityNotFound(_0x5bf09d,null))[_0x143d('0x2a')](removeEntity(_0x5bf09d,null))[_0x143d('0x4f')](handleError(_0x5bf09d,null));};exports['preview']=function(_0x22d898,_0x56e52e){var _0x34766f=0xa;var _0x1ab612=[_0x143d('0x5b'),_0x143d('0x5c'),_0x143d('0x5d'),_0x143d('0x5e')];var _0x67d632={'SUM':_0x143d('0x5f'),'COUNT':_0x143d('0x60'),'COUNT DISTINCT':_0x143d('0x61'),'MAX':'MAX(%s)','MIN':_0x143d('0x62'),'AVG':_0x143d('0x63'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x143d('0x64')};var _0x343f0d={'SEC_TO_TIME':_0x143d('0x65'),'DATE':'DATE(%s)','HOUR':_0x143d('0x66'),'ROUND':_0x143d('0x67'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x132d5f=function(_0x1790a1){return!_[_0x143d('0x68')]([_0x143d('0x69'),_0x143d('0x6a'),_0x143d('0x6b'),_0x143d('0x6c')],_0x1790a1);};var _0x1c89d=function(_0x51cf9d){if(!_0x51cf9d||!_0x51cf9d[_0x143d('0x6d')]['length']){return'';}for(var _0x354014='(',_0x2061bd=0x0;_0x2061bd<_0x51cf9d['rules']['length'];_0x2061bd+=0x1){_0x2061bd>0x0&&(_0x354014+='\x20'+_0x51cf9d['operator']+'\x20');_0x354014+=_0x51cf9d[_0x143d('0x6d')][_0x2061bd][_0x143d('0x6e')]?_0x1c89d(_0x51cf9d[_0x143d('0x6d')][_0x2061bd][_0x143d('0x6e')]):_0x51cf9d[_0x143d('0x6d')][_0x2061bd][_0x143d('0x6f')]+'\x20'+_0x51cf9d['rules'][_0x2061bd]['condition']+(_0x132d5f(_0x51cf9d['rules'][_0x2061bd][_0x143d('0x70')])?'\x20'+_0x51cf9d['rules'][_0x2061bd][_0x143d('0x71')]:'');}return _0x354014+')';};var _0x18a3a0={'where':{'id':_0x22d898['params']['id']}},_0x26f694,_0x1da6e0,_0x55aed2,_0x2c9313,_0x15989a;_0x18a3a0=_['merge']({},_0x18a3a0,_0x22d898['options']);return db[_0x143d('0x4a')][_0x143d('0x72')](_0x18a3a0)[_0x143d('0x2a')](function(_0x1239a8){if(_0x1239a8){_0x26f694=_0x1239a8;return _0x1239a8[_0x143d('0x73')]();}return null;})['then'](function(_0x316bd7){if(_0x316bd7){if(!_0x316bd7[_0x143d('0x3f')]){throw new db[(_0x143d('0x74'))]['ValidationErrorItem'](_0x143d('0x75'),0x193);}_0x1da6e0=_0x316bd7;return db[_0x143d('0x76')][_0x143d('0x4d')]({'raw':!![]});}return null;})['then'](function(_0x175cbd){if(_0x175cbd){_0x55aed2=_[_0x143d('0x77')](_0x175cbd,'id');var _0xfd2e5b;var _0x42fe3e=squel[_0x143d('0x78')]();_0x42fe3e[_0x143d('0x79')](_0x26f694[_0x143d('0x7a')]);for(var _0x1c832b=0x0;_0x1c832b<_0x1da6e0[_0x143d('0x3f')];_0x1c832b+=0x1){_0xfd2e5b=_0x1da6e0[_0x1c832b][_0x143d('0x7b')]?_0x55aed2[_0x1da6e0[_0x1c832b][_0x143d('0x7b')]][_0x143d('0x7c')]:_0x1da6e0[_0x1c832b][_0x143d('0x6f')];_0xfd2e5b=_0x1da6e0[_0x1c832b][_0x143d('0x7d')]?_[_0x143d('0x7e')](_0x67d632[_0x1da6e0[_0x1c832b][_0x143d('0x7d')]],'%s',_0xfd2e5b):_0xfd2e5b;_0xfd2e5b=_0x1da6e0[_0x1c832b][_0x143d('0x7f')]?_['replace'](_0x343f0d[_0x1da6e0[_0x1c832b][_0x143d('0x7f')]],'%s',_0xfd2e5b):_0xfd2e5b;if(_0x1da6e0[_0x1c832b][_0x143d('0x80')]){_0x42fe3e[_0x143d('0x6e')](_0xfd2e5b);}_0x1da6e0[_0x1c832b]['orderBy']&&_0x42fe3e[_0x143d('0x42')](_0xfd2e5b,_0x1da6e0[_0x1c832b][_0x143d('0x81')]==='DESC'?![]:!![]);_0x42fe3e['field'](_0xfd2e5b,_0x1da6e0[_0x1c832b][_0x143d('0x82')]||_0xfd2e5b);}if(_0x26f694[_0x143d('0x83')]){_0x26f694['joins']=JSON['parse'](_0x26f694[_0x143d('0x83')]);for(var _0x357158=0x0;_0x357158<_0x26f694[_0x143d('0x83')][_0x143d('0x3f')];_0x357158+=0x1){if(_0x26f694[_0x143d('0x83')][_0x357158][_0x143d('0x36')]&&_[_0x143d('0x68')](_0x1ab612,_0x26f694[_0x143d('0x83')][_0x357158][_0x143d('0x36')])&&_0x26f694[_0x143d('0x83')][_0x357158][_0x143d('0x84')]&&_0x26f694[_0x143d('0x83')][_0x357158][_0x143d('0x85')]&&_0x26f694[_0x143d('0x83')][_0x357158]['foreignKey']){_0x42fe3e[_0x26f694[_0x143d('0x83')][_0x357158][_0x143d('0x36')]](_0x26f694[_0x143d('0x83')][_0x357158][_0x143d('0x85')],null,util[_0x143d('0x7f')](_0x143d('0x86'),_0x26f694[_0x143d('0x7a')],_0x26f694[_0x143d('0x83')][_0x357158]['parentKey'],_0x26f694['joins'][_0x357158][_0x143d('0x85')],_0x26f694[_0x143d('0x83')][_0x357158][_0x143d('0x87')]));}}}if(_0x26f694[_0x143d('0x88')]){_0x26f694['conditions']=JSON['parse'](_0x26f694[_0x143d('0x88')]);_0x42fe3e['where'](_0x1c89d(_0x26f694[_0x143d('0x88')][_0x143d('0x6e')]));}_0x15989a=_0x42fe3e[_0x143d('0x89')]();_0x42fe3e[_0x143d('0x24')](_0x34766f);_0x42fe3e[_0x143d('0x23')](0x0);logger['debug']('Limited\x20Query:',_0x42fe3e[_0x143d('0x8a')]());return db[_0x143d('0x8b')][_0x143d('0x39')](_0x42fe3e[_0x143d('0x8a')](),{'type':db[_0x143d('0x8b')]['QueryTypes'][_0x143d('0x8c')]});}})[_0x143d('0x2a')](respondWithResult(_0x56e52e,null))[_0x143d('0x4f')](handleError(_0x56e52e,null));};function runReport(_0xc4a919,_0x543365,_0x3a9ca2){var _0x2da9f0=_0x543365['name'];var _0x53c17a=0xa;var _0x14098a=['join',_0x143d('0x5c'),_0x143d('0x5d'),_0x143d('0x5e')];var _0x326fed={'SUM':_0x143d('0x5f'),'COUNT':_0x143d('0x60'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x143d('0x8d'),'MIN':_0x143d('0x62'),'AVG':'AVG(%s)','GROUP_CONCAT':_0x143d('0x8e'),'GROUP_CONCAT ASC':_0x143d('0x8f'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x966549={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x143d('0x90'),'HOUR':_0x143d('0x66'),'ROUND':_0x143d('0x67'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x18d9bf=function(_0x5c62da){return!_[_0x143d('0x68')](['IS\x20NULL','IS\x20NOT\x20NULL',_0x143d('0x6b'),_0x143d('0x6c')],_0x5c62da);};var _0x50bf53=function(_0x326510){if(!_0x326510||!_0x326510['rules'][_0x143d('0x3f')]){return'';}for(var _0x1dd0b7='(',_0x2862e0=0x0;_0x2862e0<_0x326510['rules'][_0x143d('0x3f')];_0x2862e0+=0x1){_0x2862e0>0x0&&(_0x1dd0b7+='\x20'+_0x326510['operator']+'\x20');_0x1dd0b7+=_0x326510[_0x143d('0x6d')][_0x2862e0][_0x143d('0x6e')]?_0x50bf53(_0x326510['rules'][_0x2862e0][_0x143d('0x6e')]):_0x326510[_0x143d('0x6d')][_0x2862e0][_0x143d('0x6f')]+'\x20'+_0x326510[_0x143d('0x6d')][_0x2862e0][_0x143d('0x70')]+(_0x18d9bf(_0x326510[_0x143d('0x6d')][_0x2862e0][_0x143d('0x70')])?'\x20'+_0x326510[_0x143d('0x6d')][_0x2862e0][_0x143d('0x71')]:'');}return _0x1dd0b7+')';};var _0x519dba={'where':{'id':_0xc4a919['id']}},_0x1da0af,_0x2c777e,_0x4cb602,_0x5b7539,_0x203d82;_0x519dba=_['merge']({},_0x519dba,_0x3a9ca2);return db[_0x143d('0x4a')][_0x143d('0x72')](_0x519dba)[_0x143d('0x2a')](function(_0xadd1d4){if(_0xadd1d4){_0x1da0af=_0xadd1d4;return _0xadd1d4['getFields']();}return null;})['then'](function(_0x7e1a99){if(_0x7e1a99){if(!_0x7e1a99[_0x143d('0x3f')]){throw new db[(_0x143d('0x74'))][(_0x143d('0x91'))](_0x143d('0x75'),0x193);}_0x2c777e=_0x7e1a99;return db[_0x143d('0x76')][_0x143d('0x4d')]({'raw':!![]});}return null;})[_0x143d('0x2a')](function(_0x35e4bd){if(_0x35e4bd){_0x4cb602=_[_0x143d('0x77')](_0x35e4bd,'id');var _0x453a8e;var _0xb70efa=squel['select']();_0xb70efa[_0x143d('0x79')](_0x1da0af[_0x143d('0x7a')]);for(var _0x1d5943=0x0;_0x1d5943<_0x2c777e[_0x143d('0x3f')];_0x1d5943+=0x1){_0x453a8e=_0x2c777e[_0x1d5943]['MetricId']?_0x4cb602[_0x2c777e[_0x1d5943]['MetricId']][_0x143d('0x7c')]:_0x2c777e[_0x1d5943]['field'];_0x453a8e=_0x2c777e[_0x1d5943][_0x143d('0x7d')]?_[_0x143d('0x7e')](_0x326fed[_0x2c777e[_0x1d5943][_0x143d('0x7d')]],'%s',_0x453a8e):_0x453a8e;_0x453a8e=_0x2c777e[_0x1d5943][_0x143d('0x7f')]?_['replace'](_0x966549[_0x2c777e[_0x1d5943][_0x143d('0x7f')]],'%s',_0x453a8e):_0x453a8e;if(_0x2c777e[_0x1d5943]['groupBy']){_0xb70efa[_0x143d('0x6e')](_0x453a8e);}_0x2c777e[_0x1d5943][_0x143d('0x81')]&&_0xb70efa['order'](_0x453a8e,_0x2c777e[_0x1d5943][_0x143d('0x81')]===_0x143d('0x92')?![]:!![]);_0xb70efa[_0x143d('0x6f')](_0x453a8e,_0x2c777e[_0x1d5943][_0x143d('0x82')]||_0x453a8e);}if(_0x1da0af[_0x143d('0x83')]){_0x1da0af['joins']=JSON[_0x143d('0x93')](_0x1da0af[_0x143d('0x83')]);for(var _0x48b410=0x0;_0x48b410<_0x1da0af[_0x143d('0x83')][_0x143d('0x3f')];_0x48b410+=0x1){if(_0x1da0af['joins'][_0x48b410]['type']&&_['includes'](_0x14098a,_0x1da0af[_0x143d('0x83')][_0x48b410][_0x143d('0x36')])&&_0x1da0af['joins'][_0x48b410][_0x143d('0x84')]&&_0x1da0af[_0x143d('0x83')][_0x48b410]['foreignTable']&&_0x1da0af[_0x143d('0x83')][_0x48b410]['foreignKey']){_0xb70efa[_0x1da0af['joins'][_0x48b410][_0x143d('0x36')]](_0x1da0af[_0x143d('0x83')][_0x48b410][_0x143d('0x85')],null,util[_0x143d('0x7f')](_0x143d('0x86'),_0x1da0af[_0x143d('0x7a')],_0x1da0af[_0x143d('0x83')][_0x48b410][_0x143d('0x84')],_0x1da0af['joins'][_0x48b410][_0x143d('0x85')],_0x1da0af[_0x143d('0x83')][_0x48b410][_0x143d('0x87')]));}}}if(_0x1da0af[_0x143d('0x88')]){_0x1da0af[_0x143d('0x88')]=JSON[_0x143d('0x93')](_0x1da0af['conditions']);_0xb70efa[_0x143d('0x44')](_0x50bf53(_0x1da0af[_0x143d('0x88')][_0x143d('0x6e')]));}_0x203d82=_0xb70efa['clone']();_0xb70efa[_0x143d('0x24')](_0x53c17a);_0xb70efa[_0x143d('0x23')](0x0);logger['debug'](_0x143d('0x94'),_0xb70efa[_0x143d('0x8a')]());return db['sequelize'][_0x143d('0x39')](_0xb70efa[_0x143d('0x8a')](),{'type':db['sequelize']['QueryTypes']['SELECT']});}})['then'](function(_0xc2d999){if(!_0xc2d999['length']){throw new db[(_0x143d('0x74'))]['ValidationErrorItem'](_0x143d('0x95'),0xcc);}if(_0x543365['output']===_0x143d('0x96')){return null;}var _0x4ed53c=_[_0x143d('0x47')](_0x543365,{'name':_0x543365[_0x143d('0x97')]||_0x543365[_0x143d('0x31')]||_0x1da0af[_0x143d('0x31')],'basename':_0x2da9f0,'savename':util[_0x143d('0x7f')]('%s-%s.%s',_0x543365[_0x143d('0x31')]||_0x1da0af['name'],require(_0x143d('0x98'))[_0x143d('0x99')](0x4),_0x543365[_0x143d('0x9a')]||'csv'),'reportId':_0x1da0af['id'],'reportType':_0x143d('0x9b')});return db[_0x143d('0x9c')][_0x143d('0x52')](_0x4ed53c,{'raw':!![]});})['then'](function(_0x4924ae){if(_0x1da0af[_0x143d('0x7a')]===_0x143d('0x9d')){_0x203d82[_0x143d('0x44')](_0x1da0af['table']+_0x143d('0x9e'),_0x543365[_0x143d('0x9f')],_0x543365[_0x143d('0xa0')]);}else{_0x203d82[_0x143d('0x44')](_0x1da0af['table']+_0x143d('0xa1'),_0x543365[_0x143d('0x9f')],_0x543365[_0x143d('0xa0')]);}if(_0x4924ae){logger[_0x143d('0xa2')](_0x143d('0xa3'),_0x203d82['toString']());require(_0x143d('0xa4'))[_0x143d('0xa5')](path['join'](__dirname,_0x143d('0xa6'),_0x4924ae[_0x143d('0x9a')]),[_0x4924ae['id'],_0x203d82['toString'](),path['join'](__dirname,_0x143d('0xa7'),_0x4924ae[_0x143d('0xa8')]),_0x2da9f0]);return _0x4924ae;}else{var _0x105aeb=squel[_0x143d('0x78')]();_0x105aeb[_0x143d('0x79')]('('+_0x203d82[_0x143d('0x8a')]()+')','countTable');_0x105aeb[_0x143d('0x6f')]('COUNT(*)',_0x143d('0x22'));_0x203d82['limit'](_0x543365[_0x143d('0x24')]||_0x53c17a);_0x203d82[_0x143d('0x23')](_0x543365[_0x143d('0x23')]||0x0);return dbH[_0x143d('0x8b')][_0x143d('0x39')](_0x105aeb[_0x143d('0x8a')](),{'type':dbH[_0x143d('0x8b')][_0x143d('0xa9')]['SELECT']})['then'](function(_0xbe69ed){if(!_0xbe69ed[_0x143d('0x3f')]){_0x5b7539=0x0;}else{_0x5b7539=_0xbe69ed[0x0]['count']||0x0;}return dbH[_0x143d('0x8b')][_0x143d('0x39')](_0x203d82[_0x143d('0x8a')](),{'type':dbH[_0x143d('0x8b')][_0x143d('0xa9')]['SELECT']});})['then'](function(_0x965d3d){return{'rows':_0x965d3d||[],'count':_0x5b7539};});}});}exports[_0x143d('0xaa')]=function(_0x1089c7,_0x106453){return runReport(_0x1089c7[_0x143d('0x51')],_0x1089c7[_0x143d('0x39')],_0x1089c7[_0x143d('0x49')])['then'](respondWithResult(_0x106453,null))['catch'](handleError(_0x106453,null));};exports[_0x143d('0xab')]=runReport;exports[_0x143d('0x39')]=function(_0x530a25,_0x533778){var _0x3c00c6=0xa;var _0x1e32b9=[_0x143d('0x5b'),_0x143d('0x5c'),'right_join','cross_join'];var _0x309e85={'SUM':_0x143d('0x5f'),'COUNT':_0x143d('0x60'),'COUNT DISTINCT':_0x143d('0x61'),'MAX':'MAX(%s)','MIN':_0x143d('0x62'),'AVG':'AVG(%s)','GROUP_CONCAT':_0x143d('0x8e'),'GROUP_CONCAT ASC':_0x143d('0x8f'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0xfbcc99={'SEC_TO_TIME':_0x143d('0x65'),'DATE':_0x143d('0x90'),'HOUR':_0x143d('0x66'),'ROUND':_0x143d('0x67'),'UNIX_TIMESTAMP':_0x143d('0xac')};var _0x59d3e8=function(_0x50396c){return!_[_0x143d('0x68')](['IS\x20NULL',_0x143d('0x6a'),_0x143d('0x6b'),_0x143d('0x6c')],_0x50396c);};var _0x1f3e96=function(_0x3af356){if(!_0x3af356||!_0x3af356[_0x143d('0x6d')][_0x143d('0x3f')]){return'';}for(var _0x3d5982='(',_0x415963=0x0;_0x415963<_0x3af356[_0x143d('0x6d')][_0x143d('0x3f')];_0x415963+=0x1){_0x415963>0x0&&(_0x3d5982+='\x20'+_0x3af356[_0x143d('0xad')]+'\x20');_0x3d5982+=_0x3af356['rules'][_0x415963][_0x143d('0x6e')]?_0x1f3e96(_0x3af356['rules'][_0x415963][_0x143d('0x6e')]):_0x3af356[_0x143d('0x6d')][_0x415963]['field']+'\x20'+_0x3af356['rules'][_0x415963][_0x143d('0x70')]+(_0x59d3e8(_0x3af356[_0x143d('0x6d')][_0x415963]['condition'])?'\x20'+_0x3af356[_0x143d('0x6d')][_0x415963]['value']:'');}return _0x3d5982+')';};var _0x10b13e={'where':{'id':_0x530a25[_0x143d('0x51')]['id']}},_0x420ef9,_0x33d018,_0x5d1b7c,_0x5585a9,_0x19a876;_0x10b13e=_[_0x143d('0x47')]({},_0x10b13e,_0x530a25[_0x143d('0x49')]);return db[_0x143d('0x4a')]['find'](_0x10b13e)[_0x143d('0x2a')](function(_0xffdbbf){if(_0xffdbbf){_0x420ef9=_0xffdbbf;return _0xffdbbf['getFields']();}return null;})[_0x143d('0x2a')](function(_0x54f495){if(_0x54f495){if(!_0x54f495[_0x143d('0x3f')]){throw new db[(_0x143d('0x74'))][(_0x143d('0x91'))](_0x143d('0x75'),0x193);}_0x33d018=_0x54f495;return db[_0x143d('0x76')][_0x143d('0x4d')]({'raw':!![]});}return null;})[_0x143d('0x2a')](function(_0x34a374){if(_0x34a374){_0x5d1b7c=_[_0x143d('0x77')](_0x34a374,'id');var _0x275c4d;var _0x5c9c4b=squel[_0x143d('0x78')]();_0x5c9c4b['from'](_0x420ef9[_0x143d('0x7a')]);for(var _0x7af3b5=0x0;_0x7af3b5<_0x33d018['length'];_0x7af3b5+=0x1){_0x275c4d=_0x33d018[_0x7af3b5][_0x143d('0x7b')]?_0x5d1b7c[_0x33d018[_0x7af3b5][_0x143d('0x7b')]]['metric']:_0x33d018[_0x7af3b5][_0x143d('0x6f')];_0x275c4d=_0x33d018[_0x7af3b5][_0x143d('0x7d')]?_['replace'](_0x309e85[_0x33d018[_0x7af3b5]['function']],'%s',_0x275c4d):_0x275c4d;_0x275c4d=_0x33d018[_0x7af3b5][_0x143d('0x7f')]?_[_0x143d('0x7e')](_0xfbcc99[_0x33d018[_0x7af3b5]['format']],'%s',_0x275c4d):_0x275c4d;if(_0x33d018[_0x7af3b5][_0x143d('0x80')]){_0x5c9c4b['group'](_0x275c4d);}_0x33d018[_0x7af3b5][_0x143d('0x81')]&&_0x5c9c4b[_0x143d('0x42')](_0x275c4d,_0x33d018[_0x7af3b5]['orderBy']===_0x143d('0x92')?![]:!![]);_0x5c9c4b[_0x143d('0x6f')](_0x275c4d,_0x33d018[_0x7af3b5][_0x143d('0x82')]||_0x275c4d);}if(_0x420ef9[_0x143d('0x83')]){_0x420ef9[_0x143d('0x83')]=JSON[_0x143d('0x93')](_0x420ef9[_0x143d('0x83')]);for(var _0x1f8266=0x0;_0x1f8266<_0x420ef9[_0x143d('0x83')][_0x143d('0x3f')];_0x1f8266+=0x1){if(_0x420ef9['joins'][_0x1f8266][_0x143d('0x36')]&&_[_0x143d('0x68')](_0x1e32b9,_0x420ef9[_0x143d('0x83')][_0x1f8266][_0x143d('0x36')])&&_0x420ef9['joins'][_0x1f8266][_0x143d('0x84')]&&_0x420ef9[_0x143d('0x83')][_0x1f8266]['foreignTable']&&_0x420ef9[_0x143d('0x83')][_0x1f8266][_0x143d('0x87')]){_0x5c9c4b[_0x420ef9['joins'][_0x1f8266]['type']](_0x420ef9[_0x143d('0x83')][_0x1f8266][_0x143d('0x85')],null,util['format'](_0x143d('0x86'),_0x420ef9['table'],_0x420ef9['joins'][_0x1f8266]['parentKey'],_0x420ef9[_0x143d('0x83')][_0x1f8266][_0x143d('0x85')],_0x420ef9[_0x143d('0x83')][_0x1f8266][_0x143d('0x87')]));}}}if(_0x420ef9[_0x143d('0x88')]){_0x420ef9[_0x143d('0x88')]=JSON[_0x143d('0x93')](_0x420ef9[_0x143d('0x88')]);_0x5c9c4b[_0x143d('0x44')](_0x1f3e96(_0x420ef9[_0x143d('0x88')]['group']));}_0x19a876=_0x5c9c4b[_0x143d('0x89')]();_0x5c9c4b['limit'](_0x3c00c6);_0x5c9c4b[_0x143d('0x23')](0x0);logger['debug'](_0x143d('0x94'),_0x5c9c4b[_0x143d('0x8a')]());return db[_0x143d('0x8b')][_0x143d('0x39')](_0x5c9c4b[_0x143d('0x8a')](),{'type':db[_0x143d('0x8b')]['QueryTypes'][_0x143d('0x8c')]});}})[_0x143d('0x2a')](function(){return{'sql':_0x19a876[_0x143d('0x8a')]()};})[_0x143d('0x2a')](respondWithResult(_0x533778,null))[_0x143d('0x4f')](handleError(_0x533778,null));};
\ No newline at end of file