Built motion from commit (unavailable).|2.5.19
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 59d8862..b791d37 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 _0xb519=['path','sox','to-csv','ejs','lodash','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','count','limit','set','apply','reject','save','update','then','get','UserProfileResource','destroy','end','error','name','send','index','map','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','offset','order','sort','where','filter','merge','VIRTUAL','options','AnalyticCustomReport','includeAll','include','catch','show','params','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','CustomReports','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','preview','left_join','right_join','cross_join','COUNT(%s)','COUNT(DISTINCT\x20%s)','MIN(%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)','DATE(%s)','HOUR(%s)','ROUND(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','group','field','value','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','findAll','keyBy','select','from','table','MetricId','metric','function','replace','format','groupBy','DESC','alias','joins','parse','parentKey','foreignTable','foreignKey','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','join','SUM(%s)','MAX(%s)','UNIX_TIMESTAMP(%s)','condition','orderBy','%s.%s\x20=\x20%s.%s','output','fullPath','%s-%s.%s','randomstring','csv','custom','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','Run\x20Query:','fork','../../components/export/','countTable','COUNT(*)','SELECT','runReport','html-pdf','eml-format','zip-dir','request-promise','moment','bluebird','mustache'];(function(_0x582f72,_0x886d8){var _0x4cd5fe=function(_0x4ac1c7){while(--_0x4ac1c7){_0x582f72['push'](_0x582f72['shift']());}};_0x4cd5fe(++_0x886d8);}(_0xb519,0x1df));var _0x9b51=function(_0x2963a4,_0x2e40ca){_0x2963a4=_0x2963a4-0x0;var _0x532e78=_0xb519[_0x2963a4];return _0x532e78;};'use strict';var pdf=require(_0x9b51('0x0'));var emlformat=require(_0x9b51('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x9b51('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9b51('0x3'));var moment=require(_0x9b51('0x4'));var BPromise=require(_0x9b51('0x5'));var Mustache=require(_0x9b51('0x6'));var util=require('util');var path=require(_0x9b51('0x7'));var sox=require(_0x9b51('0x8'));var csv=require(_0x9b51('0x9'));var ejs=require(_0x9b51('0xa'));var fs=require('fs');var _=require(_0x9b51('0xb'));var squel=require('squel');var crypto=require(_0x9b51('0xc'));var jsforce=require(_0x9b51('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x9b51('0x9'));var querystring=require(_0x9b51('0xe'));var Papa=require(_0x9b51('0xf'));var Redis=require(_0x9b51('0x10'));var authService=require(_0x9b51('0x11'));var qs=require(_0x9b51('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x9b51('0x13'));var logger=require(_0x9b51('0x14'))('api');var utils=require(_0x9b51('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x9b51('0x16'));var db=require('../../mysqldb')['db'];var dbH=require(_0x9b51('0x17'))['dbH'];function respondWithStatusCode(_0x6c33d0,_0x4ee0fd){_0x4ee0fd=_0x4ee0fd||0xcc;return function(_0x5812dc){if(_0x5812dc){return _0x6c33d0[_0x9b51('0x18')](_0x4ee0fd);}return _0x6c33d0['status'](_0x4ee0fd)['end']();};}function respondWithResult(_0x347536,_0x10eb96){_0x10eb96=_0x10eb96||0xc8;return function(_0x12ed21){if(_0x12ed21){return _0x347536[_0x9b51('0x19')](_0x10eb96)[_0x9b51('0x1a')](_0x12ed21);}};}function respondWithFilteredResult(_0x2b774d,_0x4c539c){return function(_0x17c1b7){if(_0x17c1b7){var _0xb27e4e=_0x17c1b7[_0x9b51('0x1b')],_0x4f151f=_0x4c539c['offset'],_0x39b952=_0x4c539c['offset']+_0x4c539c[_0x9b51('0x1c')],_0xdc234;if(_0x39b952>=_0xb27e4e){_0x39b952=_0xb27e4e;_0xdc234=0xc8;}else{_0xdc234=0xce;}_0x2b774d[_0x9b51('0x19')](_0xdc234);return _0x2b774d[_0x9b51('0x1d')]('Content-Range',_0x4f151f+'-'+_0x39b952+'/'+_0xb27e4e)[_0x9b51('0x1a')](_0x17c1b7);}return null;};}function patchUpdates(_0x34fb79){return function(_0x2b2099){try{jsonpatch[_0x9b51('0x1e')](_0x2b2099,_0x34fb79,!![]);}catch(_0x3378b8){return BPromise[_0x9b51('0x1f')](_0x3378b8);}return _0x2b2099[_0x9b51('0x20')]();};}function saveUpdates(_0x28c1c8,_0x4a5b75){return function(_0x1b417d){if(_0x1b417d){return _0x1b417d[_0x9b51('0x21')](_0x28c1c8)[_0x9b51('0x22')](function(_0x3a6928){return _0x3a6928;});}return null;};}function removeEntity(_0x22f1fb,_0x4a19d5){return function(_0x21630c){if(_0x21630c){return _0x21630c['destroy']()[_0x9b51('0x22')](function(){var _0x1310fe=_0x21630c[_0x9b51('0x23')]({'plain':!![]});var _0x5880b4='CustomReports';return db[_0x9b51('0x24')][_0x9b51('0x25')]({'where':{'type':_0x5880b4,'resourceId':_0x1310fe['id']}})[_0x9b51('0x22')](function(){return _0x21630c;});})[_0x9b51('0x22')](function(){_0x22f1fb[_0x9b51('0x19')](0xcc)[_0x9b51('0x26')]();});}};}function handleEntityNotFound(_0x5f371d,_0x1d7d88){return function(_0x2ae2ac){if(!_0x2ae2ac){_0x5f371d[_0x9b51('0x18')](0x194);}return _0x2ae2ac;};}function handleError(_0x2cd1fc,_0x3c7fb0){_0x3c7fb0=_0x3c7fb0||0x1f4;return function(_0x3c6c54){logger[_0x9b51('0x27')](_0x3c6c54['stack']);if(_0x3c6c54[_0x9b51('0x28')]){delete _0x3c6c54['name'];}_0x2cd1fc['status'](_0x3c7fb0)[_0x9b51('0x29')](_0x3c6c54);};}exports[_0x9b51('0x2a')]=function(_0x56376e,_0x4fabe0){var _0x778472={},_0x715ab7={},_0x4f8ab2={'count':0x0,'rows':[]};var _0x55d8ee=_[_0x9b51('0x2b')](db['AnalyticCustomReport'][_0x9b51('0x2c')],function(_0x219b75){return{'name':_0x219b75[_0x9b51('0x2d')],'type':_0x219b75[_0x9b51('0x2e')][_0x9b51('0x2f')]};});_0x715ab7[_0x9b51('0x30')]=_[_0x9b51('0x2b')](_0x55d8ee,'name');_0x715ab7['query']=_[_0x9b51('0x31')](_0x56376e[_0x9b51('0x32')]);_0x715ab7[_0x9b51('0x33')]=_[_0x9b51('0x34')](_0x715ab7[_0x9b51('0x30')],_0x715ab7[_0x9b51('0x32')]);_0x778472['attributes']=_[_0x9b51('0x34')](_0x715ab7[_0x9b51('0x30')],qs[_0x9b51('0x35')](_0x56376e[_0x9b51('0x32')][_0x9b51('0x35')]));_0x778472[_0x9b51('0x36')]=_0x778472[_0x9b51('0x36')][_0x9b51('0x37')]?_0x778472['attributes']:_0x715ab7[_0x9b51('0x30')];if(!_0x56376e[_0x9b51('0x32')][_0x9b51('0x38')](_0x9b51('0x39'))){_0x778472[_0x9b51('0x1c')]=qs[_0x9b51('0x1c')](_0x56376e[_0x9b51('0x32')][_0x9b51('0x1c')]);_0x778472[_0x9b51('0x3a')]=qs['offset'](_0x56376e[_0x9b51('0x32')]['offset']);}_0x778472[_0x9b51('0x3b')]=qs[_0x9b51('0x3c')](_0x56376e[_0x9b51('0x32')][_0x9b51('0x3c')]);_0x778472[_0x9b51('0x3d')]=qs[_0x9b51('0x33')](_['pick'](_0x56376e['query'],_0x715ab7[_0x9b51('0x33')]),_0x55d8ee);if(_0x56376e[_0x9b51('0x32')][_0x9b51('0x3e')]){_0x778472[_0x9b51('0x3d')]=_[_0x9b51('0x3f')](_0x778472[_0x9b51('0x3d')],{'$or':_[_0x9b51('0x2b')](_0x55d8ee,function(_0x3c2241){if(_0x3c2241[_0x9b51('0x2e')]!==_0x9b51('0x40')){var _0x413675={};_0x413675[_0x3c2241[_0x9b51('0x28')]]={'$like':'%'+_0x56376e[_0x9b51('0x32')]['filter']+'%'};return _0x413675;}})});}_0x778472=_[_0x9b51('0x3f')]({},_0x778472,_0x56376e[_0x9b51('0x41')]);var _0x487959={'where':_0x778472[_0x9b51('0x3d')]};return db[_0x9b51('0x42')][_0x9b51('0x1b')](_0x487959)[_0x9b51('0x22')](function(_0x453e8b){_0x4f8ab2[_0x9b51('0x1b')]=_0x453e8b;if(_0x56376e[_0x9b51('0x32')][_0x9b51('0x43')]){_0x778472[_0x9b51('0x44')]=[{'all':!![]}];}return db[_0x9b51('0x42')]['findAll'](_0x778472);})[_0x9b51('0x22')](function(_0x52d5c4){_0x4f8ab2['rows']=_0x52d5c4;return _0x4f8ab2;})[_0x9b51('0x22')](respondWithFilteredResult(_0x4fabe0,_0x778472))[_0x9b51('0x45')](handleError(_0x4fabe0,null));};exports[_0x9b51('0x46')]=function(_0x5618a2,_0x2179dd){var _0x4cccfc={'raw':![],'where':{'id':_0x5618a2[_0x9b51('0x47')]['id']}},_0x36691e={};_0x36691e[_0x9b51('0x30')]=_[_0x9b51('0x31')](db[_0x9b51('0x42')]['rawAttributes']);_0x36691e['query']=_[_0x9b51('0x31')](_0x5618a2['query']);_0x36691e[_0x9b51('0x33')]=_['intersection'](_0x36691e[_0x9b51('0x30')],_0x36691e[_0x9b51('0x32')]);_0x4cccfc[_0x9b51('0x36')]=_['intersection'](_0x36691e[_0x9b51('0x30')],qs['fields'](_0x5618a2[_0x9b51('0x32')][_0x9b51('0x35')]));_0x4cccfc[_0x9b51('0x36')]=_0x4cccfc['attributes'][_0x9b51('0x37')]?_0x4cccfc[_0x9b51('0x36')]:_0x36691e[_0x9b51('0x30')];if(_0x5618a2[_0x9b51('0x32')]['includeAll']){_0x4cccfc['include']=[{'all':!![]}];}_0x4cccfc=_[_0x9b51('0x3f')]({},_0x4cccfc,_0x5618a2[_0x9b51('0x41')]);return db[_0x9b51('0x42')][_0x9b51('0x48')](_0x4cccfc)[_0x9b51('0x22')](handleEntityNotFound(_0x2179dd,null))[_0x9b51('0x22')](respondWithResult(_0x2179dd,null))[_0x9b51('0x45')](handleError(_0x2179dd,null));};exports[_0x9b51('0x49')]=function(_0x32910c,_0x1f0625){return db[_0x9b51('0x42')][_0x9b51('0x49')](_0x32910c['body'],{})[_0x9b51('0x22')](function(_0x1e1b46){var _0x4d75db=_0x32910c[_0x9b51('0x4a')][_0x9b51('0x23')]({'plain':!![]});if(!_0x4d75db)throw new Error(_0x9b51('0x4b'));if(_0x4d75db[_0x9b51('0x4c')]===_0x9b51('0x4a')){var _0x160a28=_0x1e1b46[_0x9b51('0x23')]({'plain':!![]});var _0x15d749='Reports';return db['UserProfileSection'][_0x9b51('0x48')]({'where':{'name':_0x15d749,'userProfileId':_0x4d75db[_0x9b51('0x4d')]},'raw':!![]})[_0x9b51('0x22')](function(_0x15e3b7){if(_0x15e3b7&&_0x15e3b7[_0x9b51('0x4e')]===0x0){return db[_0x9b51('0x24')]['create']({'name':_0x160a28[_0x9b51('0x28')],'resourceId':_0x160a28['id'],'type':_0x9b51('0x4f'),'sectionId':_0x15e3b7['id']},{})[_0x9b51('0x22')](function(){return _0x1e1b46;});}else{return _0x1e1b46;}})['catch'](function(_0x1139ea){logger['error'](_0x9b51('0x50'),_0x1139ea);throw _0x1139ea;});}return _0x1e1b46;})[_0x9b51('0x22')](respondWithResult(_0x1f0625,0xc9))['catch'](handleError(_0x1f0625,null));};exports[_0x9b51('0x21')]=function(_0x2307af,_0x4e2465){if(_0x2307af[_0x9b51('0x51')]['id']){delete _0x2307af[_0x9b51('0x51')]['id'];}return db['AnalyticCustomReport'][_0x9b51('0x48')]({'where':{'id':_0x2307af['params']['id']}})[_0x9b51('0x22')](handleEntityNotFound(_0x4e2465,null))[_0x9b51('0x22')](saveUpdates(_0x2307af[_0x9b51('0x51')],null))['then'](respondWithResult(_0x4e2465,null))['catch'](handleError(_0x4e2465,null));};exports[_0x9b51('0x25')]=function(_0x4288e1,_0x30642a){return db[_0x9b51('0x42')][_0x9b51('0x48')]({'where':{'id':_0x4288e1[_0x9b51('0x47')]['id']}})[_0x9b51('0x22')](handleEntityNotFound(_0x30642a,null))['then'](removeEntity(_0x30642a,null))['catch'](handleError(_0x30642a,null));};exports[_0x9b51('0x52')]=function(_0x922e89,_0x36f486){var _0xec020a=0xa;var _0x47e8b9=['join',_0x9b51('0x53'),_0x9b51('0x54'),_0x9b51('0x55')];var _0x85fdf0={'SUM':'SUM(%s)','COUNT':_0x9b51('0x56'),'COUNT DISTINCT':_0x9b51('0x57'),'MAX':'MAX(%s)','MIN':_0x9b51('0x58'),'AVG':_0x9b51('0x59'),'GROUP_CONCAT':_0x9b51('0x5a'),'GROUP_CONCAT ASC':_0x9b51('0x5b'),'GROUP_CONCAT DESC':_0x9b51('0x5c')};var _0x4f24b2={'SEC_TO_TIME':_0x9b51('0x5d'),'DATE':_0x9b51('0x5e'),'HOUR':_0x9b51('0x5f'),'ROUND':_0x9b51('0x60'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x4abe6e=function(_0x3d0d0b){return!_[_0x9b51('0x61')]([_0x9b51('0x62'),_0x9b51('0x63'),_0x9b51('0x64'),_0x9b51('0x65')],_0x3d0d0b);};var _0x278aea=function(_0x3c16d8){if(!_0x3c16d8||!_0x3c16d8[_0x9b51('0x66')][_0x9b51('0x37')]){return'';}for(var _0x201e9f='(',_0x324bf7=0x0;_0x324bf7<_0x3c16d8['rules'][_0x9b51('0x37')];_0x324bf7+=0x1){_0x324bf7>0x0&&(_0x201e9f+='\x20'+_0x3c16d8[_0x9b51('0x67')]+'\x20');_0x201e9f+=_0x3c16d8[_0x9b51('0x66')][_0x324bf7][_0x9b51('0x68')]?_0x278aea(_0x3c16d8[_0x9b51('0x66')][_0x324bf7][_0x9b51('0x68')]):_0x3c16d8[_0x9b51('0x66')][_0x324bf7][_0x9b51('0x69')]+'\x20'+_0x3c16d8['rules'][_0x324bf7]['condition']+(_0x4abe6e(_0x3c16d8[_0x9b51('0x66')][_0x324bf7]['condition'])?'\x20'+_0x3c16d8['rules'][_0x324bf7][_0x9b51('0x6a')]:'');}return _0x201e9f+')';};var _0x15192a={'where':{'id':_0x922e89[_0x9b51('0x47')]['id']}},_0xc8cd7c,_0x45564f,_0x5ab2e7,_0xf85dad,_0x5704a1;_0x15192a=_[_0x9b51('0x3f')]({},_0x15192a,_0x922e89['options']);return db[_0x9b51('0x42')]['find'](_0x15192a)['then'](function(_0x3845b9){if(_0x3845b9){_0xc8cd7c=_0x3845b9;return _0x3845b9[_0x9b51('0x6b')]();}return null;})['then'](function(_0x1e5c79){if(_0x1e5c79){if(!_0x1e5c79['length']){throw new db[(_0x9b51('0x6c'))][(_0x9b51('0x6d'))](_0x9b51('0x6e'),0x193);}_0x45564f=_0x1e5c79;return db[_0x9b51('0x6f')][_0x9b51('0x70')]({'raw':!![]});}return null;})[_0x9b51('0x22')](function(_0x11e950){if(_0x11e950){_0x5ab2e7=_[_0x9b51('0x71')](_0x11e950,'id');var _0x3c426f;var _0x5ca465=squel[_0x9b51('0x72')]();_0x5ca465[_0x9b51('0x73')](_0xc8cd7c[_0x9b51('0x74')]);for(var _0x34083f=0x0;_0x34083f<_0x45564f[_0x9b51('0x37')];_0x34083f+=0x1){_0x3c426f=_0x45564f[_0x34083f][_0x9b51('0x75')]?_0x5ab2e7[_0x45564f[_0x34083f]['MetricId']][_0x9b51('0x76')]:_0x45564f[_0x34083f][_0x9b51('0x69')];_0x3c426f=_0x45564f[_0x34083f][_0x9b51('0x77')]?_[_0x9b51('0x78')](_0x85fdf0[_0x45564f[_0x34083f]['function']],'%s',_0x3c426f):_0x3c426f;_0x3c426f=_0x45564f[_0x34083f]['format']?_[_0x9b51('0x78')](_0x4f24b2[_0x45564f[_0x34083f][_0x9b51('0x79')]],'%s',_0x3c426f):_0x3c426f;if(_0x45564f[_0x34083f][_0x9b51('0x7a')]){_0x5ca465[_0x9b51('0x68')](_0x3c426f);}_0x45564f[_0x34083f]['orderBy']&&_0x5ca465[_0x9b51('0x3b')](_0x3c426f,_0x45564f[_0x34083f]['orderBy']===_0x9b51('0x7b')?![]:!![]);_0x5ca465[_0x9b51('0x69')](_0x3c426f,_0x45564f[_0x34083f][_0x9b51('0x7c')]||_0x3c426f);}if(_0xc8cd7c[_0x9b51('0x7d')]){_0xc8cd7c['joins']=JSON[_0x9b51('0x7e')](_0xc8cd7c['joins']);for(var _0x322380=0x0;_0x322380<_0xc8cd7c[_0x9b51('0x7d')][_0x9b51('0x37')];_0x322380+=0x1){if(_0xc8cd7c[_0x9b51('0x7d')][_0x322380][_0x9b51('0x2e')]&&_['includes'](_0x47e8b9,_0xc8cd7c[_0x9b51('0x7d')][_0x322380][_0x9b51('0x2e')])&&_0xc8cd7c['joins'][_0x322380][_0x9b51('0x7f')]&&_0xc8cd7c[_0x9b51('0x7d')][_0x322380][_0x9b51('0x80')]&&_0xc8cd7c['joins'][_0x322380][_0x9b51('0x81')]){_0x5ca465[_0xc8cd7c['joins'][_0x322380]['type']](_0xc8cd7c[_0x9b51('0x7d')][_0x322380][_0x9b51('0x80')],null,util['format']('%s.%s\x20=\x20%s.%s',_0xc8cd7c[_0x9b51('0x74')],_0xc8cd7c[_0x9b51('0x7d')][_0x322380]['parentKey'],_0xc8cd7c[_0x9b51('0x7d')][_0x322380][_0x9b51('0x80')],_0xc8cd7c['joins'][_0x322380][_0x9b51('0x81')]));}}}if(_0xc8cd7c['conditions']){_0xc8cd7c[_0x9b51('0x82')]=JSON[_0x9b51('0x7e')](_0xc8cd7c['conditions']);_0x5ca465[_0x9b51('0x3d')](_0x278aea(_0xc8cd7c['conditions'][_0x9b51('0x68')]));}_0x5704a1=_0x5ca465[_0x9b51('0x83')]();_0x5ca465[_0x9b51('0x1c')](_0xec020a);_0x5ca465[_0x9b51('0x3a')](0x0);logger[_0x9b51('0x84')](_0x9b51('0x85'),_0x5ca465[_0x9b51('0x86')]());return dbH[_0x9b51('0x87')]['query'](_0x5ca465['toString'](),{'type':dbH['sequelize'][_0x9b51('0x88')]['SELECT']});}})['then'](respondWithResult(_0x36f486,null))[_0x9b51('0x45')](handleError(_0x36f486,null));};function runReport(_0x3b4943,_0x4d92b9,_0x206c78){var _0x299265=_0x4d92b9[_0x9b51('0x28')];var _0x1ea749=0xa;var _0x477147=[_0x9b51('0x89'),_0x9b51('0x53'),'right_join',_0x9b51('0x55')];var _0x2be574={'SUM':_0x9b51('0x8a'),'COUNT':_0x9b51('0x56'),'COUNT DISTINCT':_0x9b51('0x57'),'MAX':_0x9b51('0x8b'),'MIN':'MIN(%s)','AVG':_0x9b51('0x59'),'GROUP_CONCAT':_0x9b51('0x5a'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x29aad8={'SEC_TO_TIME':_0x9b51('0x5d'),'DATE':_0x9b51('0x5e'),'HOUR':_0x9b51('0x5f'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x9b51('0x8c')};var _0x293355=function(_0x9482e6){return!_[_0x9b51('0x61')](['IS\x20NULL',_0x9b51('0x63'),'IS\x20EMPTY','IS\x20NOT\x20EMPTY'],_0x9482e6);};var _0x49f4a=function(_0x2131b5){if(!_0x2131b5||!_0x2131b5[_0x9b51('0x66')]['length']){return'';}for(var _0x3ace74='(',_0x231e11=0x0;_0x231e11<_0x2131b5[_0x9b51('0x66')][_0x9b51('0x37')];_0x231e11+=0x1){_0x231e11>0x0&&(_0x3ace74+='\x20'+_0x2131b5['operator']+'\x20');_0x3ace74+=_0x2131b5[_0x9b51('0x66')][_0x231e11][_0x9b51('0x68')]?_0x49f4a(_0x2131b5[_0x9b51('0x66')][_0x231e11][_0x9b51('0x68')]):_0x2131b5[_0x9b51('0x66')][_0x231e11][_0x9b51('0x69')]+'\x20'+_0x2131b5[_0x9b51('0x66')][_0x231e11][_0x9b51('0x8d')]+(_0x293355(_0x2131b5[_0x9b51('0x66')][_0x231e11]['condition'])?'\x20'+_0x2131b5[_0x9b51('0x66')][_0x231e11][_0x9b51('0x6a')]:'');}return _0x3ace74+')';};var _0x1f6ea7={'where':{'id':_0x3b4943['id']}},_0x54a319,_0x4e800f,_0x48ac33,_0x4125a6,_0x5ac276;_0x1f6ea7=_[_0x9b51('0x3f')]({},_0x1f6ea7,_0x206c78);return db['AnalyticCustomReport'][_0x9b51('0x48')](_0x1f6ea7)[_0x9b51('0x22')](function(_0x3d2005){if(_0x3d2005){_0x54a319=_0x3d2005;return _0x3d2005[_0x9b51('0x6b')]();}return null;})[_0x9b51('0x22')](function(_0x580acd){if(_0x580acd){if(!_0x580acd[_0x9b51('0x37')]){throw new db[(_0x9b51('0x6c'))][(_0x9b51('0x6d'))](_0x9b51('0x6e'),0x193);}_0x4e800f=_0x580acd;return db[_0x9b51('0x6f')][_0x9b51('0x70')]({'raw':!![]});}return null;})[_0x9b51('0x22')](function(_0x15026f){if(_0x15026f){_0x48ac33=_['keyBy'](_0x15026f,'id');var _0x4b497c;var _0x700654=squel[_0x9b51('0x72')]();_0x700654[_0x9b51('0x73')](_0x54a319[_0x9b51('0x74')]);for(var _0x3770c6=0x0;_0x3770c6<_0x4e800f['length'];_0x3770c6+=0x1){_0x4b497c=_0x4e800f[_0x3770c6][_0x9b51('0x75')]?_0x48ac33[_0x4e800f[_0x3770c6][_0x9b51('0x75')]][_0x9b51('0x76')]:_0x4e800f[_0x3770c6][_0x9b51('0x69')];_0x4b497c=_0x4e800f[_0x3770c6][_0x9b51('0x77')]?_[_0x9b51('0x78')](_0x2be574[_0x4e800f[_0x3770c6][_0x9b51('0x77')]],'%s',_0x4b497c):_0x4b497c;_0x4b497c=_0x4e800f[_0x3770c6]['format']?_[_0x9b51('0x78')](_0x29aad8[_0x4e800f[_0x3770c6][_0x9b51('0x79')]],'%s',_0x4b497c):_0x4b497c;if(_0x4e800f[_0x3770c6][_0x9b51('0x7a')]){_0x700654[_0x9b51('0x68')](_0x4b497c);}_0x4e800f[_0x3770c6][_0x9b51('0x8e')]&&_0x700654[_0x9b51('0x3b')](_0x4b497c,_0x4e800f[_0x3770c6][_0x9b51('0x8e')]===_0x9b51('0x7b')?![]:!![]);_0x700654['field'](_0x4b497c,_0x4e800f[_0x3770c6][_0x9b51('0x7c')]||_0x4b497c);}if(_0x54a319[_0x9b51('0x7d')]){_0x54a319[_0x9b51('0x7d')]=JSON[_0x9b51('0x7e')](_0x54a319[_0x9b51('0x7d')]);for(var _0x56d59a=0x0;_0x56d59a<_0x54a319[_0x9b51('0x7d')]['length'];_0x56d59a+=0x1){if(_0x54a319[_0x9b51('0x7d')][_0x56d59a][_0x9b51('0x2e')]&&_[_0x9b51('0x61')](_0x477147,_0x54a319['joins'][_0x56d59a][_0x9b51('0x2e')])&&_0x54a319[_0x9b51('0x7d')][_0x56d59a][_0x9b51('0x7f')]&&_0x54a319[_0x9b51('0x7d')][_0x56d59a]['foreignTable']&&_0x54a319[_0x9b51('0x7d')][_0x56d59a]['foreignKey']){_0x700654[_0x54a319[_0x9b51('0x7d')][_0x56d59a][_0x9b51('0x2e')]](_0x54a319['joins'][_0x56d59a][_0x9b51('0x80')],null,util[_0x9b51('0x79')](_0x9b51('0x8f'),_0x54a319[_0x9b51('0x74')],_0x54a319[_0x9b51('0x7d')][_0x56d59a][_0x9b51('0x7f')],_0x54a319[_0x9b51('0x7d')][_0x56d59a][_0x9b51('0x80')],_0x54a319[_0x9b51('0x7d')][_0x56d59a]['foreignKey']));}}}if(_0x54a319[_0x9b51('0x82')]){_0x54a319['conditions']=JSON[_0x9b51('0x7e')](_0x54a319[_0x9b51('0x82')]);_0x700654['where'](_0x49f4a(_0x54a319[_0x9b51('0x82')][_0x9b51('0x68')]));}_0x5ac276=_0x700654[_0x9b51('0x83')]();_0x700654['limit'](_0x1ea749);_0x700654[_0x9b51('0x3a')](0x0);return;}})[_0x9b51('0x22')](function(){if(_0x4d92b9[_0x9b51('0x90')]==='web'){return null;}var _0x264b1b=_[_0x9b51('0x3f')](_0x4d92b9,{'name':_0x4d92b9[_0x9b51('0x91')]||_0x4d92b9[_0x9b51('0x28')]||_0x54a319[_0x9b51('0x28')],'basename':_0x299265,'savename':util[_0x9b51('0x79')](_0x9b51('0x92'),_0x4d92b9[_0x9b51('0x28')]||_0x54a319[_0x9b51('0x28')],require(_0x9b51('0x93'))['generate'](0x4),_0x4d92b9['output']||_0x9b51('0x94')),'reportId':_0x54a319['id'],'reportType':_0x9b51('0x95')});return db[_0x9b51('0x96')][_0x9b51('0x49')](_0x264b1b,{'raw':!![]});})[_0x9b51('0x22')](function(_0x2034fa){if(_0x54a319[_0x9b51('0x74')]===_0x9b51('0x97')){_0x5ac276['where'](_0x54a319[_0x9b51('0x74')]+_0x9b51('0x98'),_0x4d92b9[_0x9b51('0x99')],_0x4d92b9['endDate']);}else{_0x5ac276[_0x9b51('0x3d')](_0x54a319[_0x9b51('0x74')]+'.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x4d92b9['startDate'],_0x4d92b9[_0x9b51('0x9a')]);}if(_0x2034fa){logger['info'](_0x9b51('0x9b'),_0x5ac276[_0x9b51('0x86')]());require('child_process')[_0x9b51('0x9c')](path[_0x9b51('0x89')](__dirname,_0x9b51('0x9d'),_0x2034fa[_0x9b51('0x90')]),[_0x2034fa['id'],_0x5ac276[_0x9b51('0x86')](),path[_0x9b51('0x89')](__dirname,'../../files/reports',_0x2034fa['savename']),_0x299265]);return _0x2034fa;}else{var _0x3c567c=squel[_0x9b51('0x72')]();_0x3c567c[_0x9b51('0x73')]('('+_0x5ac276[_0x9b51('0x86')]()+')',_0x9b51('0x9e'));_0x3c567c['field'](_0x9b51('0x9f'),_0x9b51('0x1b'));_0x5ac276[_0x9b51('0x1c')](_0x4d92b9[_0x9b51('0x1c')]||_0x1ea749);_0x5ac276[_0x9b51('0x3a')](_0x4d92b9[_0x9b51('0x3a')]||0x0);return dbH[_0x9b51('0x87')][_0x9b51('0x32')](_0x3c567c['toString'](),{'type':dbH['sequelize'][_0x9b51('0x88')][_0x9b51('0xa0')]})[_0x9b51('0x22')](function(_0x1470ca){if(!_0x1470ca[_0x9b51('0x37')]){_0x4125a6=0x0;}else{_0x4125a6=_0x1470ca[0x0][_0x9b51('0x1b')]||0x0;}return dbH[_0x9b51('0x87')][_0x9b51('0x32')](_0x5ac276[_0x9b51('0x86')](),{'type':dbH['sequelize'][_0x9b51('0x88')]['SELECT']});})[_0x9b51('0x22')](function(_0x1ef87c){return{'rows':_0x1ef87c||[],'count':_0x4125a6};});}});}exports['run']=function(_0x5257d1,_0x3e828b){return runReport(_0x5257d1[_0x9b51('0x47')],_0x5257d1[_0x9b51('0x32')],_0x5257d1[_0x9b51('0x41')])[_0x9b51('0x22')](respondWithResult(_0x3e828b,null))[_0x9b51('0x45')](handleError(_0x3e828b,null));};exports[_0x9b51('0xa1')]=runReport;exports['query']=function(_0x3bbddd,_0x4aed47){var _0x51e375=0xa;var _0x814122=['join',_0x9b51('0x53'),_0x9b51('0x54'),_0x9b51('0x55')];var _0x400178={'SUM':_0x9b51('0x8a'),'COUNT':_0x9b51('0x56'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x9b51('0x8b'),'MIN':_0x9b51('0x58'),'AVG':_0x9b51('0x59'),'GROUP_CONCAT':_0x9b51('0x5a'),'GROUP_CONCAT ASC':_0x9b51('0x5b'),'GROUP_CONCAT DESC':_0x9b51('0x5c')};var _0x41fcec={'SEC_TO_TIME':_0x9b51('0x5d'),'DATE':_0x9b51('0x5e'),'HOUR':_0x9b51('0x5f'),'ROUND':_0x9b51('0x60'),'UNIX_TIMESTAMP':_0x9b51('0x8c')};var _0x495289=function(_0x251ca6){return!_[_0x9b51('0x61')](['IS\x20NULL',_0x9b51('0x63'),'IS\x20EMPTY',_0x9b51('0x65')],_0x251ca6);};var _0x47ff76=function(_0x382f8d){if(!_0x382f8d||!_0x382f8d[_0x9b51('0x66')]['length']){return'';}for(var _0x2c3f8e='(',_0x652207=0x0;_0x652207<_0x382f8d[_0x9b51('0x66')][_0x9b51('0x37')];_0x652207+=0x1){_0x652207>0x0&&(_0x2c3f8e+='\x20'+_0x382f8d['operator']+'\x20');_0x2c3f8e+=_0x382f8d[_0x9b51('0x66')][_0x652207][_0x9b51('0x68')]?_0x47ff76(_0x382f8d[_0x9b51('0x66')][_0x652207][_0x9b51('0x68')]):_0x382f8d[_0x9b51('0x66')][_0x652207][_0x9b51('0x69')]+'\x20'+_0x382f8d['rules'][_0x652207][_0x9b51('0x8d')]+(_0x495289(_0x382f8d[_0x9b51('0x66')][_0x652207]['condition'])?'\x20'+_0x382f8d[_0x9b51('0x66')][_0x652207]['value']:'');}return _0x2c3f8e+')';};var _0x145843={'where':{'id':_0x3bbddd[_0x9b51('0x47')]['id']}},_0x27d7ed,_0xaddd08,_0x314e39,_0x464f7c,_0x565146;_0x145843=_[_0x9b51('0x3f')]({},_0x145843,_0x3bbddd['options']);return db[_0x9b51('0x42')][_0x9b51('0x48')](_0x145843)['then'](function(_0x5764ca){if(_0x5764ca){_0x27d7ed=_0x5764ca;return _0x5764ca[_0x9b51('0x6b')]();}return null;})[_0x9b51('0x22')](function(_0x2aff59){if(_0x2aff59){if(!_0x2aff59[_0x9b51('0x37')]){throw new db[(_0x9b51('0x6c'))][(_0x9b51('0x6d'))](_0x9b51('0x6e'),0x193);}_0xaddd08=_0x2aff59;return db[_0x9b51('0x6f')][_0x9b51('0x70')]({'raw':!![]});}return null;})[_0x9b51('0x22')](function(_0x3fd773){if(_0x3fd773){_0x314e39=_['keyBy'](_0x3fd773,'id');var _0x27acba;var _0x3ff798=squel[_0x9b51('0x72')]();_0x3ff798[_0x9b51('0x73')](_0x27d7ed['table']);for(var _0x3f6b52=0x0;_0x3f6b52<_0xaddd08[_0x9b51('0x37')];_0x3f6b52+=0x1){_0x27acba=_0xaddd08[_0x3f6b52][_0x9b51('0x75')]?_0x314e39[_0xaddd08[_0x3f6b52][_0x9b51('0x75')]][_0x9b51('0x76')]:_0xaddd08[_0x3f6b52][_0x9b51('0x69')];_0x27acba=_0xaddd08[_0x3f6b52][_0x9b51('0x77')]?_[_0x9b51('0x78')](_0x400178[_0xaddd08[_0x3f6b52][_0x9b51('0x77')]],'%s',_0x27acba):_0x27acba;_0x27acba=_0xaddd08[_0x3f6b52][_0x9b51('0x79')]?_[_0x9b51('0x78')](_0x41fcec[_0xaddd08[_0x3f6b52][_0x9b51('0x79')]],'%s',_0x27acba):_0x27acba;if(_0xaddd08[_0x3f6b52][_0x9b51('0x7a')]){_0x3ff798['group'](_0x27acba);}_0xaddd08[_0x3f6b52][_0x9b51('0x8e')]&&_0x3ff798[_0x9b51('0x3b')](_0x27acba,_0xaddd08[_0x3f6b52]['orderBy']===_0x9b51('0x7b')?![]:!![]);_0x3ff798['field'](_0x27acba,_0xaddd08[_0x3f6b52]['alias']||_0x27acba);}if(_0x27d7ed[_0x9b51('0x7d')]){_0x27d7ed['joins']=JSON[_0x9b51('0x7e')](_0x27d7ed[_0x9b51('0x7d')]);for(var _0x386515=0x0;_0x386515<_0x27d7ed[_0x9b51('0x7d')][_0x9b51('0x37')];_0x386515+=0x1){if(_0x27d7ed[_0x9b51('0x7d')][_0x386515]['type']&&_[_0x9b51('0x61')](_0x814122,_0x27d7ed[_0x9b51('0x7d')][_0x386515][_0x9b51('0x2e')])&&_0x27d7ed[_0x9b51('0x7d')][_0x386515][_0x9b51('0x7f')]&&_0x27d7ed[_0x9b51('0x7d')][_0x386515][_0x9b51('0x80')]&&_0x27d7ed[_0x9b51('0x7d')][_0x386515]['foreignKey']){_0x3ff798[_0x27d7ed[_0x9b51('0x7d')][_0x386515][_0x9b51('0x2e')]](_0x27d7ed['joins'][_0x386515]['foreignTable'],null,util['format'](_0x9b51('0x8f'),_0x27d7ed[_0x9b51('0x74')],_0x27d7ed[_0x9b51('0x7d')][_0x386515][_0x9b51('0x7f')],_0x27d7ed[_0x9b51('0x7d')][_0x386515][_0x9b51('0x80')],_0x27d7ed[_0x9b51('0x7d')][_0x386515][_0x9b51('0x81')]));}}}if(_0x27d7ed[_0x9b51('0x82')]){_0x27d7ed[_0x9b51('0x82')]=JSON['parse'](_0x27d7ed['conditions']);_0x3ff798[_0x9b51('0x3d')](_0x47ff76(_0x27d7ed[_0x9b51('0x82')][_0x9b51('0x68')]));}_0x565146=_0x3ff798[_0x9b51('0x83')]();_0x3ff798[_0x9b51('0x1c')](_0x51e375);_0x3ff798[_0x9b51('0x3a')](0x0);logger['debug']('Limited\x20Query:',_0x3ff798[_0x9b51('0x86')]());return dbH[_0x9b51('0x87')][_0x9b51('0x32')](_0x3ff798[_0x9b51('0x86')](),{'type':dbH[_0x9b51('0x87')][_0x9b51('0x88')]['SELECT']});}})['then'](function(){return{'sql':_0x565146['toString']()};})[_0x9b51('0x22')](respondWithResult(_0x4aed47,null))[_0x9b51('0x45')](handleError(_0x4aed47,null));};
\ No newline at end of file