Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 6a0d4cf..4b91569 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xff11=['format','orderBy','DESC','alias','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','clone','debug','toString','sequelize','QueryTypes','SELECT','join','right_join','SUM(%s)','GROUP_CONCAT(%s)','operator','keyBy','select','groupBy','output','web','fullPath','%s-%s.%s','generate','csv','custom','AnalyticExtractedReport','cdr','startDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','endDate','info','Run\x20Query:','child_process','../../components/export/','../../files/reports','savename','run','runReport','AVG(%s)','IS\x20NOT\x20EMPTY','Limited\x20Query:','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','UserProfileResource','error','stack','name','send','index','AnalyticCustomReport','rawAttributes','fieldName','key','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','pick','filter','merge','where','type','VIRTUAL','options','include','findAll','rows','catch','show','params','includeAll','find','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','create','CustomReports','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','preview','left_join','cross_join','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%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)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','rules','group','field','condition','value','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','from','table','MetricId','metric','function','replace'];(function(_0x4d0427,_0x2d9d15){var _0x3164b4=function(_0x57903f){while(--_0x57903f){_0x4d0427['push'](_0x4d0427['shift']());}};_0x3164b4(++_0x2d9d15);}(_0xff11,0x186));var _0x1ff1=function(_0x3b94ec,_0x570c33){_0x3b94ec=_0x3b94ec-0x0;var _0x7bde3d=_0xff11[_0x3b94ec];return _0x7bde3d;};'use strict';var emlformat=require(_0x1ff1('0x0'));var rimraf=require(_0x1ff1('0x1'));var zipdir=require(_0x1ff1('0x2'));var jsonpatch=require(_0x1ff1('0x3'));var rp=require(_0x1ff1('0x4'));var moment=require(_0x1ff1('0x5'));var BPromise=require(_0x1ff1('0x6'));var Mustache=require(_0x1ff1('0x7'));var util=require(_0x1ff1('0x8'));var path=require(_0x1ff1('0x9'));var sox=require(_0x1ff1('0xa'));var csv=require(_0x1ff1('0xb'));var ejs=require(_0x1ff1('0xc'));var fs=require('fs');var fs_extra=require(_0x1ff1('0xd'));var _=require(_0x1ff1('0xe'));var squel=require('squel');var crypto=require(_0x1ff1('0xf'));var jsforce=require(_0x1ff1('0x10'));var deskjs=require(_0x1ff1('0x11'));var toCsv=require(_0x1ff1('0xb'));var querystring=require(_0x1ff1('0x12'));var Papa=require('papaparse');var Redis=require(_0x1ff1('0x13'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x1ff1('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x1ff1('0x15'))('api');var utils=require(_0x1ff1('0x16'));var config=require(_0x1ff1('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x1ff1('0x18'))['db'];var dbH=require('../../mysqldb')['dbH'];function respondWithStatusCode(_0xb7eab5,_0x382d5a){_0x382d5a=_0x382d5a||0xcc;return function(_0x3494ec){if(_0x3494ec){return _0xb7eab5[_0x1ff1('0x19')](_0x382d5a);}return _0xb7eab5[_0x1ff1('0x1a')](_0x382d5a)[_0x1ff1('0x1b')]();};}function respondWithResult(_0x4d9188,_0x232340){_0x232340=_0x232340||0xc8;return function(_0x17f3b3){if(_0x17f3b3){return _0x4d9188[_0x1ff1('0x1a')](_0x232340)[_0x1ff1('0x1c')](_0x17f3b3);}};}function respondWithFilteredResult(_0x2bbf0e,_0x4fa5a2){return function(_0xfb23f3){if(_0xfb23f3){var _0x430569=typeof _0x4fa5a2[_0x1ff1('0x1d')]===_0x1ff1('0x1e')&&typeof _0x4fa5a2['limit']===_0x1ff1('0x1e');var _0x2d4bdd=_0xfb23f3[_0x1ff1('0x1f')];var _0x40091d=_0x430569?0x0:_0x4fa5a2[_0x1ff1('0x1d')];var _0x51469b=_0x430569?_0xfb23f3[_0x1ff1('0x1f')]:_0x4fa5a2['offset']+_0x4fa5a2[_0x1ff1('0x20')];var _0x4a4314;if(_0x51469b>=_0x2d4bdd){_0x51469b=_0x2d4bdd;_0x4a4314=0xc8;}else{_0x4a4314=0xce;}_0x2bbf0e['status'](_0x4a4314);return _0x2bbf0e[_0x1ff1('0x21')](_0x1ff1('0x22'),_0x40091d+'-'+_0x51469b+'/'+_0x2d4bdd)[_0x1ff1('0x1c')](_0xfb23f3);}return null;};}function patchUpdates(_0x1e2ab3){return function(_0x8db772){try{jsonpatch[_0x1ff1('0x23')](_0x8db772,_0x1e2ab3,!![]);}catch(_0x2edbd7){return BPromise[_0x1ff1('0x24')](_0x2edbd7);}return _0x8db772[_0x1ff1('0x25')]();};}function saveUpdates(_0x1ce430,_0x2e85cb){return function(_0x354875){if(_0x354875){return _0x354875[_0x1ff1('0x26')](_0x1ce430)[_0x1ff1('0x27')](function(_0x4899b2){return _0x4899b2;});}return null;};}function removeEntity(_0x2e354a,_0x464483){return function(_0x50e518){if(_0x50e518){return _0x50e518[_0x1ff1('0x28')]()[_0x1ff1('0x27')](function(){var _0x5b3887=_0x50e518[_0x1ff1('0x29')]({'plain':!![]});var _0x19b507='CustomReports';return db[_0x1ff1('0x2a')][_0x1ff1('0x28')]({'where':{'type':_0x19b507,'resourceId':_0x5b3887['id']}})[_0x1ff1('0x27')](function(){return _0x50e518;});})['then'](function(){_0x2e354a[_0x1ff1('0x1a')](0xcc)[_0x1ff1('0x1b')]();});}};}function handleEntityNotFound(_0x4cf4f5,_0xcecae9){return function(_0x1579f5){if(!_0x1579f5){_0x4cf4f5[_0x1ff1('0x19')](0x194);}return _0x1579f5;};}function handleError(_0x436611,_0x5b73da){_0x5b73da=_0x5b73da||0x1f4;return function(_0x50a76e){logger[_0x1ff1('0x2b')](_0x50a76e[_0x1ff1('0x2c')]);if(_0x50a76e['name']){delete _0x50a76e[_0x1ff1('0x2d')];}_0x436611['status'](_0x5b73da)[_0x1ff1('0x2e')](_0x50a76e);};}exports[_0x1ff1('0x2f')]=function(_0x33701e,_0x458c57){var _0x45a011={},_0x12eb73={},_0x5ca35a={'count':0x0,'rows':[]};var _0x3b1c79=_['map'](db[_0x1ff1('0x30')][_0x1ff1('0x31')],function(_0x42b983){return{'name':_0x42b983[_0x1ff1('0x32')],'type':_0x42b983['type'][_0x1ff1('0x33')]};});_0x12eb73[_0x1ff1('0x34')]=_[_0x1ff1('0x35')](_0x3b1c79,'name');_0x12eb73[_0x1ff1('0x36')]=_[_0x1ff1('0x37')](_0x33701e[_0x1ff1('0x36')]);_0x12eb73[_0x1ff1('0x38')]=_[_0x1ff1('0x39')](_0x12eb73[_0x1ff1('0x34')],_0x12eb73[_0x1ff1('0x36')]);_0x45a011[_0x1ff1('0x3a')]=_['intersection'](_0x12eb73[_0x1ff1('0x34')],qs[_0x1ff1('0x3b')](_0x33701e[_0x1ff1('0x36')][_0x1ff1('0x3b')]));_0x45a011[_0x1ff1('0x3a')]=_0x45a011[_0x1ff1('0x3a')][_0x1ff1('0x3c')]?_0x45a011[_0x1ff1('0x3a')]:_0x12eb73[_0x1ff1('0x34')];if(!_0x33701e['query'][_0x1ff1('0x3d')]('nolimit')){_0x45a011['limit']=qs[_0x1ff1('0x20')](_0x33701e[_0x1ff1('0x36')][_0x1ff1('0x20')]);_0x45a011['offset']=qs[_0x1ff1('0x1d')](_0x33701e[_0x1ff1('0x36')]['offset']);}_0x45a011[_0x1ff1('0x3e')]=qs[_0x1ff1('0x3f')](_0x33701e['query'][_0x1ff1('0x3f')]);_0x45a011['where']=qs[_0x1ff1('0x38')](_[_0x1ff1('0x40')](_0x33701e[_0x1ff1('0x36')],_0x12eb73[_0x1ff1('0x38')]),_0x3b1c79);if(_0x33701e[_0x1ff1('0x36')][_0x1ff1('0x41')]){_0x45a011['where']=_[_0x1ff1('0x42')](_0x45a011[_0x1ff1('0x43')],{'$or':_[_0x1ff1('0x35')](_0x3b1c79,function(_0x3ea0a6){if(_0x3ea0a6[_0x1ff1('0x44')]!==_0x1ff1('0x45')){var _0x35495c={};_0x35495c[_0x3ea0a6['name']]={'$like':'%'+_0x33701e[_0x1ff1('0x36')][_0x1ff1('0x41')]+'%'};return _0x35495c;}})});}_0x45a011=_[_0x1ff1('0x42')]({},_0x45a011,_0x33701e[_0x1ff1('0x46')]);var _0x58aece={'where':_0x45a011[_0x1ff1('0x43')]};return db[_0x1ff1('0x30')][_0x1ff1('0x1f')](_0x58aece)[_0x1ff1('0x27')](function(_0x811b94){_0x5ca35a['count']=_0x811b94;if(_0x33701e['query']['includeAll']){_0x45a011[_0x1ff1('0x47')]=[{'all':!![]}];}return db[_0x1ff1('0x30')][_0x1ff1('0x48')](_0x45a011);})[_0x1ff1('0x27')](function(_0x30be9e){_0x5ca35a[_0x1ff1('0x49')]=_0x30be9e;return _0x5ca35a;})[_0x1ff1('0x27')](respondWithFilteredResult(_0x458c57,_0x45a011))[_0x1ff1('0x4a')](handleError(_0x458c57,null));};exports[_0x1ff1('0x4b')]=function(_0x476cc0,_0x360e7f){var _0x49abf2={'raw':![],'where':{'id':_0x476cc0[_0x1ff1('0x4c')]['id']}},_0x174a50={};_0x174a50[_0x1ff1('0x34')]=_[_0x1ff1('0x37')](db[_0x1ff1('0x30')]['rawAttributes']);_0x174a50[_0x1ff1('0x36')]=_[_0x1ff1('0x37')](_0x476cc0[_0x1ff1('0x36')]);_0x174a50[_0x1ff1('0x38')]=_['intersection'](_0x174a50[_0x1ff1('0x34')],_0x174a50[_0x1ff1('0x36')]);_0x49abf2[_0x1ff1('0x3a')]=_['intersection'](_0x174a50['model'],qs['fields'](_0x476cc0['query'][_0x1ff1('0x3b')]));_0x49abf2[_0x1ff1('0x3a')]=_0x49abf2['attributes'][_0x1ff1('0x3c')]?_0x49abf2[_0x1ff1('0x3a')]:_0x174a50['model'];if(_0x476cc0[_0x1ff1('0x36')][_0x1ff1('0x4d')]){_0x49abf2[_0x1ff1('0x47')]=[{'all':!![]}];}_0x49abf2=_['merge']({},_0x49abf2,_0x476cc0[_0x1ff1('0x46')]);return db['AnalyticCustomReport'][_0x1ff1('0x4e')](_0x49abf2)[_0x1ff1('0x27')](handleEntityNotFound(_0x360e7f,null))[_0x1ff1('0x27')](respondWithResult(_0x360e7f,null))[_0x1ff1('0x4a')](handleError(_0x360e7f,null));};exports['create']=function(_0x125355,_0xc73bc9){return db[_0x1ff1('0x30')]['create'](_0x125355[_0x1ff1('0x4f')],{})[_0x1ff1('0x27')](function(_0x2164b8){var _0x515e68=_0x125355['user'][_0x1ff1('0x29')]({'plain':!![]});if(!_0x515e68)throw new Error(_0x1ff1('0x50'));if(_0x515e68[_0x1ff1('0x51')]===_0x1ff1('0x52')){var _0x83a8a7=_0x2164b8[_0x1ff1('0x29')]({'plain':!![]});var _0x210b17='Reports';return db[_0x1ff1('0x53')][_0x1ff1('0x4e')]({'where':{'name':_0x210b17,'userProfileId':_0x515e68[_0x1ff1('0x54')]},'raw':!![]})[_0x1ff1('0x27')](function(_0x5b007c){if(_0x5b007c&&_0x5b007c[_0x1ff1('0x55')]===0x0){return db[_0x1ff1('0x2a')][_0x1ff1('0x56')]({'name':_0x83a8a7[_0x1ff1('0x2d')],'resourceId':_0x83a8a7['id'],'type':_0x1ff1('0x57'),'sectionId':_0x5b007c['id']},{})[_0x1ff1('0x27')](function(){return _0x2164b8;});}else{return _0x2164b8;}})[_0x1ff1('0x4a')](function(_0x3992ee){logger[_0x1ff1('0x2b')](_0x1ff1('0x58'),_0x3992ee);throw _0x3992ee;});}return _0x2164b8;})[_0x1ff1('0x27')](respondWithResult(_0xc73bc9,0xc9))['catch'](handleError(_0xc73bc9,null));};exports[_0x1ff1('0x26')]=function(_0x4c3a68,_0x32b8f4){if(_0x4c3a68[_0x1ff1('0x4f')]['id']){delete _0x4c3a68[_0x1ff1('0x4f')]['id'];}return db[_0x1ff1('0x30')][_0x1ff1('0x4e')]({'where':{'id':_0x4c3a68[_0x1ff1('0x4c')]['id']}})[_0x1ff1('0x27')](handleEntityNotFound(_0x32b8f4,null))[_0x1ff1('0x27')](saveUpdates(_0x4c3a68[_0x1ff1('0x4f')],null))[_0x1ff1('0x27')](respondWithResult(_0x32b8f4,null))['catch'](handleError(_0x32b8f4,null));};exports['destroy']=function(_0x4410a3,_0x4c8791){return db[_0x1ff1('0x30')][_0x1ff1('0x4e')]({'where':{'id':_0x4410a3[_0x1ff1('0x4c')]['id']}})[_0x1ff1('0x27')](handleEntityNotFound(_0x4c8791,null))[_0x1ff1('0x27')](removeEntity(_0x4c8791,null))['catch'](handleError(_0x4c8791,null));};exports[_0x1ff1('0x59')]=function(_0x2de2a9,_0x5e7585){var _0x53e9fe=0xa;var _0xd8769c=['join',_0x1ff1('0x5a'),'right_join',_0x1ff1('0x5b')];var _0x2ce6e5={'SUM':'SUM(%s)','COUNT':_0x1ff1('0x5c'),'COUNT DISTINCT':_0x1ff1('0x5d'),'MAX':_0x1ff1('0x5e'),'MIN':_0x1ff1('0x5f'),'AVG':'AVG(%s)','GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x1ff1('0x60'),'GROUP_CONCAT DESC':_0x1ff1('0x61')};var _0x28c72c={'SEC_TO_TIME':_0x1ff1('0x62'),'DATE':_0x1ff1('0x63'),'HOUR':_0x1ff1('0x64'),'ROUND':_0x1ff1('0x65'),'UNIX_TIMESTAMP':_0x1ff1('0x66')};var _0x57e5cd=function(_0x351eff){return!_[_0x1ff1('0x67')]([_0x1ff1('0x68'),_0x1ff1('0x69'),_0x1ff1('0x6a'),'IS\x20NOT\x20EMPTY'],_0x351eff);};var _0x193d43=function(_0x245f5f){if(!_0x245f5f||!_0x245f5f[_0x1ff1('0x6b')][_0x1ff1('0x3c')]){return'';}for(var _0x48e8f8='(',_0x28339b=0x0;_0x28339b<_0x245f5f[_0x1ff1('0x6b')]['length'];_0x28339b+=0x1){_0x28339b>0x0&&(_0x48e8f8+='\x20'+_0x245f5f['operator']+'\x20');_0x48e8f8+=_0x245f5f[_0x1ff1('0x6b')][_0x28339b][_0x1ff1('0x6c')]?_0x193d43(_0x245f5f[_0x1ff1('0x6b')][_0x28339b][_0x1ff1('0x6c')]):_0x245f5f['rules'][_0x28339b][_0x1ff1('0x6d')]+'\x20'+_0x245f5f['rules'][_0x28339b][_0x1ff1('0x6e')]+(_0x57e5cd(_0x245f5f[_0x1ff1('0x6b')][_0x28339b][_0x1ff1('0x6e')])?'\x20'+_0x245f5f[_0x1ff1('0x6b')][_0x28339b][_0x1ff1('0x6f')]:'');}return _0x48e8f8+')';};var _0x2ee3f0={'where':{'id':_0x2de2a9[_0x1ff1('0x4c')]['id']}},_0x1524ab,_0x395f48,_0x1183fa,_0x33ceff,_0x39a73d;_0x2ee3f0=_[_0x1ff1('0x42')]({},_0x2ee3f0,_0x2de2a9[_0x1ff1('0x46')]);return db['AnalyticCustomReport'][_0x1ff1('0x4e')](_0x2ee3f0)[_0x1ff1('0x27')](function(_0x179f8b){if(_0x179f8b){_0x1524ab=_0x179f8b;return _0x179f8b[_0x1ff1('0x70')]();}return null;})[_0x1ff1('0x27')](function(_0x4bbfc0){if(_0x4bbfc0){if(!_0x4bbfc0[_0x1ff1('0x3c')]){throw new db[(_0x1ff1('0x71'))][(_0x1ff1('0x72'))](_0x1ff1('0x73'),0x193);}_0x395f48=_0x4bbfc0;return db[_0x1ff1('0x74')][_0x1ff1('0x48')]({'raw':!![]});}return null;})['then'](function(_0x588964){if(_0x588964){_0x1183fa=_['keyBy'](_0x588964,'id');var _0x1a4ae1;var _0x29e48f=squel['select']();_0x29e48f[_0x1ff1('0x75')](_0x1524ab[_0x1ff1('0x76')]);for(var _0x3cbef2=0x0;_0x3cbef2<_0x395f48[_0x1ff1('0x3c')];_0x3cbef2+=0x1){_0x1a4ae1=_0x395f48[_0x3cbef2][_0x1ff1('0x77')]?_0x1183fa[_0x395f48[_0x3cbef2][_0x1ff1('0x77')]][_0x1ff1('0x78')]:_0x395f48[_0x3cbef2]['field'];_0x1a4ae1=_0x395f48[_0x3cbef2][_0x1ff1('0x79')]?_[_0x1ff1('0x7a')](_0x2ce6e5[_0x395f48[_0x3cbef2][_0x1ff1('0x79')]],'%s',_0x1a4ae1):_0x1a4ae1;_0x1a4ae1=_0x395f48[_0x3cbef2]['format']?_[_0x1ff1('0x7a')](_0x28c72c[_0x395f48[_0x3cbef2][_0x1ff1('0x7b')]],'%s',_0x1a4ae1):_0x1a4ae1;if(_0x395f48[_0x3cbef2]['groupBy']){_0x29e48f[_0x1ff1('0x6c')](_0x1a4ae1);}_0x395f48[_0x3cbef2][_0x1ff1('0x7c')]&&_0x29e48f[_0x1ff1('0x3e')](_0x1a4ae1,_0x395f48[_0x3cbef2][_0x1ff1('0x7c')]===_0x1ff1('0x7d')?![]:!![]);_0x29e48f['field'](_0x1a4ae1,_0x395f48[_0x3cbef2][_0x1ff1('0x7e')]||_0x1a4ae1);}if(_0x1524ab['joins']){_0x1524ab[_0x1ff1('0x7f')]=JSON[_0x1ff1('0x80')](_0x1524ab[_0x1ff1('0x7f')]);for(var _0x483079=0x0;_0x483079<_0x1524ab[_0x1ff1('0x7f')][_0x1ff1('0x3c')];_0x483079+=0x1){if(_0x1524ab[_0x1ff1('0x7f')][_0x483079][_0x1ff1('0x44')]&&_[_0x1ff1('0x67')](_0xd8769c,_0x1524ab[_0x1ff1('0x7f')][_0x483079][_0x1ff1('0x44')])&&_0x1524ab[_0x1ff1('0x7f')][_0x483079][_0x1ff1('0x81')]&&_0x1524ab[_0x1ff1('0x7f')][_0x483079][_0x1ff1('0x82')]&&_0x1524ab[_0x1ff1('0x7f')][_0x483079][_0x1ff1('0x83')]){_0x29e48f[_0x1524ab['joins'][_0x483079]['type']](_0x1524ab['joins'][_0x483079]['foreignTable'],null,util[_0x1ff1('0x7b')](_0x1ff1('0x84'),_0x1524ab[_0x1ff1('0x76')],_0x1524ab[_0x1ff1('0x7f')][_0x483079][_0x1ff1('0x81')],_0x1524ab['joins'][_0x483079][_0x1ff1('0x82')],_0x1524ab[_0x1ff1('0x7f')][_0x483079][_0x1ff1('0x83')]));}}}if(_0x1524ab[_0x1ff1('0x85')]){_0x1524ab['conditions']=JSON['parse'](_0x1524ab[_0x1ff1('0x85')]);_0x29e48f[_0x1ff1('0x43')](_0x193d43(_0x1524ab['conditions'][_0x1ff1('0x6c')]));}_0x39a73d=_0x29e48f[_0x1ff1('0x86')]();_0x29e48f['limit'](_0x53e9fe);_0x29e48f[_0x1ff1('0x1d')](0x0);logger[_0x1ff1('0x87')]('Limited\x20Query:',_0x29e48f[_0x1ff1('0x88')]());return dbH['sequelize'][_0x1ff1('0x36')](_0x29e48f[_0x1ff1('0x88')](),{'type':dbH[_0x1ff1('0x89')][_0x1ff1('0x8a')][_0x1ff1('0x8b')]});}})[_0x1ff1('0x27')](respondWithResult(_0x5e7585,null))[_0x1ff1('0x4a')](handleError(_0x5e7585,null));};function runReport(_0x6c809b,_0x315ad6,_0x301686){var _0x31a077=_0x315ad6[_0x1ff1('0x2d')];var _0x2159a7=0xa;var _0x584f24=[_0x1ff1('0x8c'),'left_join',_0x1ff1('0x8d'),'cross_join'];var _0x4fd2f5={'SUM':_0x1ff1('0x8e'),'COUNT':_0x1ff1('0x5c'),'COUNT DISTINCT':_0x1ff1('0x5d'),'MAX':_0x1ff1('0x5e'),'MIN':_0x1ff1('0x5f'),'AVG':'AVG(%s)','GROUP_CONCAT':_0x1ff1('0x8f'),'GROUP_CONCAT ASC':_0x1ff1('0x60'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x57998b={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':'DATE(%s)','HOUR':_0x1ff1('0x64'),'ROUND':_0x1ff1('0x65'),'UNIX_TIMESTAMP':_0x1ff1('0x66')};var _0x197df8=function(_0xe06ff3){return!_[_0x1ff1('0x67')]([_0x1ff1('0x68'),_0x1ff1('0x69'),_0x1ff1('0x6a'),'IS\x20NOT\x20EMPTY'],_0xe06ff3);};var _0x4ab08b=function(_0x4c90d0){if(!_0x4c90d0||!_0x4c90d0[_0x1ff1('0x6b')]['length']){return'';}for(var _0x16fbb7='(',_0x5b4211=0x0;_0x5b4211<_0x4c90d0['rules'][_0x1ff1('0x3c')];_0x5b4211+=0x1){_0x5b4211>0x0&&(_0x16fbb7+='\x20'+_0x4c90d0[_0x1ff1('0x90')]+'\x20');_0x16fbb7+=_0x4c90d0['rules'][_0x5b4211]['group']?_0x4ab08b(_0x4c90d0[_0x1ff1('0x6b')][_0x5b4211][_0x1ff1('0x6c')]):_0x4c90d0['rules'][_0x5b4211][_0x1ff1('0x6d')]+'\x20'+_0x4c90d0['rules'][_0x5b4211][_0x1ff1('0x6e')]+(_0x197df8(_0x4c90d0[_0x1ff1('0x6b')][_0x5b4211][_0x1ff1('0x6e')])?'\x20'+_0x4c90d0[_0x1ff1('0x6b')][_0x5b4211][_0x1ff1('0x6f')]:'');}return _0x16fbb7+')';};var _0x133e2e={'where':{'id':_0x6c809b['id']}},_0x5bc779,_0x5cb868,_0x341153,_0x2ef405,_0x30d84e;_0x133e2e=_[_0x1ff1('0x42')]({},_0x133e2e,_0x301686);return db[_0x1ff1('0x30')][_0x1ff1('0x4e')](_0x133e2e)['then'](function(_0x88f781){if(_0x88f781){_0x5bc779=_0x88f781;return _0x88f781['getFields']();}return null;})[_0x1ff1('0x27')](function(_0x2160a7){if(_0x2160a7){if(!_0x2160a7['length']){throw new db[(_0x1ff1('0x71'))]['ValidationErrorItem'](_0x1ff1('0x73'),0x193);}_0x5cb868=_0x2160a7;return db['AnalyticMetric'][_0x1ff1('0x48')]({'raw':!![]});}return null;})[_0x1ff1('0x27')](function(_0x3cbe76){if(_0x3cbe76){_0x341153=_[_0x1ff1('0x91')](_0x3cbe76,'id');var _0x13fd31;var _0x5aab9c=squel[_0x1ff1('0x92')]();_0x5aab9c[_0x1ff1('0x75')](_0x5bc779[_0x1ff1('0x76')]);for(var _0x5484fb=0x0;_0x5484fb<_0x5cb868[_0x1ff1('0x3c')];_0x5484fb+=0x1){_0x13fd31=_0x5cb868[_0x5484fb][_0x1ff1('0x77')]?_0x341153[_0x5cb868[_0x5484fb]['MetricId']]['metric']:_0x5cb868[_0x5484fb]['field'];_0x13fd31=_0x5cb868[_0x5484fb]['function']?_[_0x1ff1('0x7a')](_0x4fd2f5[_0x5cb868[_0x5484fb][_0x1ff1('0x79')]],'%s',_0x13fd31):_0x13fd31;_0x13fd31=_0x5cb868[_0x5484fb][_0x1ff1('0x7b')]?_[_0x1ff1('0x7a')](_0x57998b[_0x5cb868[_0x5484fb][_0x1ff1('0x7b')]],'%s',_0x13fd31):_0x13fd31;if(_0x5cb868[_0x5484fb][_0x1ff1('0x93')]){_0x5aab9c[_0x1ff1('0x6c')](_0x13fd31);}_0x5cb868[_0x5484fb][_0x1ff1('0x7c')]&&_0x5aab9c[_0x1ff1('0x3e')](_0x13fd31,_0x5cb868[_0x5484fb][_0x1ff1('0x7c')]===_0x1ff1('0x7d')?![]:!![]);_0x5aab9c['field'](_0x13fd31,_0x5cb868[_0x5484fb][_0x1ff1('0x7e')]||_0x13fd31);}if(_0x5bc779['joins']){_0x5bc779[_0x1ff1('0x7f')]=JSON[_0x1ff1('0x80')](_0x5bc779[_0x1ff1('0x7f')]);for(var _0x55ce74=0x0;_0x55ce74<_0x5bc779[_0x1ff1('0x7f')][_0x1ff1('0x3c')];_0x55ce74+=0x1){if(_0x5bc779[_0x1ff1('0x7f')][_0x55ce74]['type']&&_['includes'](_0x584f24,_0x5bc779[_0x1ff1('0x7f')][_0x55ce74][_0x1ff1('0x44')])&&_0x5bc779[_0x1ff1('0x7f')][_0x55ce74][_0x1ff1('0x81')]&&_0x5bc779['joins'][_0x55ce74][_0x1ff1('0x82')]&&_0x5bc779['joins'][_0x55ce74]['foreignKey']){_0x5aab9c[_0x5bc779[_0x1ff1('0x7f')][_0x55ce74]['type']](_0x5bc779['joins'][_0x55ce74][_0x1ff1('0x82')],null,util[_0x1ff1('0x7b')](_0x1ff1('0x84'),_0x5bc779[_0x1ff1('0x76')],_0x5bc779['joins'][_0x55ce74][_0x1ff1('0x81')],_0x5bc779[_0x1ff1('0x7f')][_0x55ce74][_0x1ff1('0x82')],_0x5bc779[_0x1ff1('0x7f')][_0x55ce74][_0x1ff1('0x83')]));}}}if(_0x5bc779[_0x1ff1('0x85')]){_0x5bc779[_0x1ff1('0x85')]=JSON[_0x1ff1('0x80')](_0x5bc779[_0x1ff1('0x85')]);_0x5aab9c[_0x1ff1('0x43')](_0x4ab08b(_0x5bc779[_0x1ff1('0x85')][_0x1ff1('0x6c')]));}_0x30d84e=_0x5aab9c['clone']();_0x5aab9c[_0x1ff1('0x20')](_0x2159a7);_0x5aab9c['offset'](0x0);return;}})['then'](function(){if(_0x315ad6[_0x1ff1('0x94')]===_0x1ff1('0x95')){return null;}var _0x41a789=_[_0x1ff1('0x42')](_0x315ad6,{'name':_0x315ad6[_0x1ff1('0x96')]||_0x315ad6[_0x1ff1('0x2d')]||_0x5bc779[_0x1ff1('0x2d')],'basename':_0x31a077,'savename':util['format'](_0x1ff1('0x97'),_0x315ad6[_0x1ff1('0x2d')]||_0x5bc779[_0x1ff1('0x2d')],require('randomstring')[_0x1ff1('0x98')](0x4),_0x315ad6[_0x1ff1('0x94')]||_0x1ff1('0x99')),'reportId':_0x5bc779['id'],'reportType':_0x1ff1('0x9a')});return db[_0x1ff1('0x9b')][_0x1ff1('0x56')](_0x41a789,{'raw':!![]});})[_0x1ff1('0x27')](function(_0xa50046){if(_0x5bc779[_0x1ff1('0x76')]===_0x1ff1('0x9c')){_0x30d84e[_0x1ff1('0x43')](_0x5bc779[_0x1ff1('0x76')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x315ad6[_0x1ff1('0x9d')],_0x315ad6['endDate']);}else{_0x30d84e[_0x1ff1('0x43')](_0x5bc779[_0x1ff1('0x76')]+_0x1ff1('0x9e'),_0x315ad6[_0x1ff1('0x9d')],_0x315ad6[_0x1ff1('0x9f')]);}if(_0xa50046){logger[_0x1ff1('0xa0')](_0x1ff1('0xa1'),_0x30d84e[_0x1ff1('0x88')]());require(_0x1ff1('0xa2'))['fork'](path['join'](__dirname,_0x1ff1('0xa3'),_0xa50046[_0x1ff1('0x94')]),[_0xa50046['id'],_0x30d84e['toString'](),path[_0x1ff1('0x8c')](__dirname,_0x1ff1('0xa4'),_0xa50046[_0x1ff1('0xa5')]),_0x31a077]);return _0xa50046;}else{var _0x62c109=squel[_0x1ff1('0x92')]();_0x62c109['from']('('+_0x30d84e[_0x1ff1('0x88')]()+')','countTable');_0x62c109[_0x1ff1('0x6d')]('COUNT(*)',_0x1ff1('0x1f'));_0x30d84e['limit'](_0x315ad6[_0x1ff1('0x20')]||_0x2159a7);_0x30d84e[_0x1ff1('0x1d')](_0x315ad6[_0x1ff1('0x1d')]||0x0);return dbH['sequelize'][_0x1ff1('0x36')](_0x62c109[_0x1ff1('0x88')](),{'type':dbH[_0x1ff1('0x89')][_0x1ff1('0x8a')][_0x1ff1('0x8b')]})[_0x1ff1('0x27')](function(_0x5be215){if(!_0x5be215[_0x1ff1('0x3c')]){_0x2ef405=0x0;}else{_0x2ef405=_0x5be215[0x0]['count']||0x0;}return dbH[_0x1ff1('0x89')]['query'](_0x30d84e[_0x1ff1('0x88')](),{'type':dbH[_0x1ff1('0x89')][_0x1ff1('0x8a')][_0x1ff1('0x8b')]});})[_0x1ff1('0x27')](function(_0x4a113d){return{'rows':_0x4a113d||[],'count':_0x2ef405};});}});}exports[_0x1ff1('0xa6')]=function(_0x235d71,_0x1e8683){return runReport(_0x235d71[_0x1ff1('0x4c')],_0x235d71[_0x1ff1('0x36')],_0x235d71[_0x1ff1('0x46')])['then'](respondWithResult(_0x1e8683,null))['catch'](handleError(_0x1e8683,null));};exports[_0x1ff1('0xa7')]=runReport;exports[_0x1ff1('0x36')]=function(_0x5a6896,_0x1d7db5){var _0x58aaea=0xa;var _0x3de320=['join',_0x1ff1('0x5a'),_0x1ff1('0x8d'),_0x1ff1('0x5b')];var _0xbc08a2={'SUM':_0x1ff1('0x8e'),'COUNT':_0x1ff1('0x5c'),'COUNT DISTINCT':_0x1ff1('0x5d'),'MAX':_0x1ff1('0x5e'),'MIN':_0x1ff1('0x5f'),'AVG':_0x1ff1('0xa8'),'GROUP_CONCAT':_0x1ff1('0x8f'),'GROUP_CONCAT ASC':_0x1ff1('0x60'),'GROUP_CONCAT DESC':_0x1ff1('0x61')};var _0x1c14db={'SEC_TO_TIME':_0x1ff1('0x62'),'DATE':'DATE(%s)','HOUR':_0x1ff1('0x64'),'ROUND':_0x1ff1('0x65'),'UNIX_TIMESTAMP':_0x1ff1('0x66')};var _0x1e888e=function(_0x10c05c){return!_[_0x1ff1('0x67')](['IS\x20NULL',_0x1ff1('0x69'),_0x1ff1('0x6a'),_0x1ff1('0xa9')],_0x10c05c);};var _0x502f51=function(_0x4d3d29){if(!_0x4d3d29||!_0x4d3d29['rules'][_0x1ff1('0x3c')]){return'';}for(var _0x54f8e7='(',_0x429028=0x0;_0x429028<_0x4d3d29[_0x1ff1('0x6b')][_0x1ff1('0x3c')];_0x429028+=0x1){_0x429028>0x0&&(_0x54f8e7+='\x20'+_0x4d3d29[_0x1ff1('0x90')]+'\x20');_0x54f8e7+=_0x4d3d29[_0x1ff1('0x6b')][_0x429028][_0x1ff1('0x6c')]?_0x502f51(_0x4d3d29['rules'][_0x429028][_0x1ff1('0x6c')]):_0x4d3d29[_0x1ff1('0x6b')][_0x429028]['field']+'\x20'+_0x4d3d29[_0x1ff1('0x6b')][_0x429028][_0x1ff1('0x6e')]+(_0x1e888e(_0x4d3d29[_0x1ff1('0x6b')][_0x429028][_0x1ff1('0x6e')])?'\x20'+_0x4d3d29[_0x1ff1('0x6b')][_0x429028]['value']:'');}return _0x54f8e7+')';};var _0x160d61={'where':{'id':_0x5a6896[_0x1ff1('0x4c')]['id']}},_0x340bcf,_0x53fe83,_0x4ef8f7,_0x1735e4,_0x9970b6;_0x160d61=_['merge']({},_0x160d61,_0x5a6896[_0x1ff1('0x46')]);return db[_0x1ff1('0x30')][_0x1ff1('0x4e')](_0x160d61)[_0x1ff1('0x27')](function(_0x587079){if(_0x587079){_0x340bcf=_0x587079;return _0x587079['getFields']();}return null;})['then'](function(_0xb60172){if(_0xb60172){if(!_0xb60172[_0x1ff1('0x3c')]){throw new db[(_0x1ff1('0x71'))][(_0x1ff1('0x72'))](_0x1ff1('0x73'),0x193);}_0x53fe83=_0xb60172;return db[_0x1ff1('0x74')]['findAll']({'raw':!![]});}return null;})[_0x1ff1('0x27')](function(_0x4e2a0d){if(_0x4e2a0d){_0x4ef8f7=_[_0x1ff1('0x91')](_0x4e2a0d,'id');var _0x319e1e;var _0x2c8781=squel[_0x1ff1('0x92')]();_0x2c8781[_0x1ff1('0x75')](_0x340bcf['table']);for(var _0x20f038=0x0;_0x20f038<_0x53fe83[_0x1ff1('0x3c')];_0x20f038+=0x1){_0x319e1e=_0x53fe83[_0x20f038][_0x1ff1('0x77')]?_0x4ef8f7[_0x53fe83[_0x20f038][_0x1ff1('0x77')]][_0x1ff1('0x78')]:_0x53fe83[_0x20f038]['field'];_0x319e1e=_0x53fe83[_0x20f038]['function']?_[_0x1ff1('0x7a')](_0xbc08a2[_0x53fe83[_0x20f038][_0x1ff1('0x79')]],'%s',_0x319e1e):_0x319e1e;_0x319e1e=_0x53fe83[_0x20f038][_0x1ff1('0x7b')]?_[_0x1ff1('0x7a')](_0x1c14db[_0x53fe83[_0x20f038][_0x1ff1('0x7b')]],'%s',_0x319e1e):_0x319e1e;if(_0x53fe83[_0x20f038]['groupBy']){_0x2c8781[_0x1ff1('0x6c')](_0x319e1e);}_0x53fe83[_0x20f038]['orderBy']&&_0x2c8781[_0x1ff1('0x3e')](_0x319e1e,_0x53fe83[_0x20f038]['orderBy']===_0x1ff1('0x7d')?![]:!![]);_0x2c8781[_0x1ff1('0x6d')](_0x319e1e,_0x53fe83[_0x20f038]['alias']||_0x319e1e);}if(_0x340bcf[_0x1ff1('0x7f')]){_0x340bcf[_0x1ff1('0x7f')]=JSON[_0x1ff1('0x80')](_0x340bcf[_0x1ff1('0x7f')]);for(var _0x52e32e=0x0;_0x52e32e<_0x340bcf[_0x1ff1('0x7f')][_0x1ff1('0x3c')];_0x52e32e+=0x1){if(_0x340bcf[_0x1ff1('0x7f')][_0x52e32e]['type']&&_[_0x1ff1('0x67')](_0x3de320,_0x340bcf[_0x1ff1('0x7f')][_0x52e32e]['type'])&&_0x340bcf['joins'][_0x52e32e][_0x1ff1('0x81')]&&_0x340bcf[_0x1ff1('0x7f')][_0x52e32e][_0x1ff1('0x82')]&&_0x340bcf[_0x1ff1('0x7f')][_0x52e32e][_0x1ff1('0x83')]){_0x2c8781[_0x340bcf[_0x1ff1('0x7f')][_0x52e32e][_0x1ff1('0x44')]](_0x340bcf['joins'][_0x52e32e][_0x1ff1('0x82')],null,util[_0x1ff1('0x7b')]('%s.%s\x20=\x20%s.%s',_0x340bcf[_0x1ff1('0x76')],_0x340bcf[_0x1ff1('0x7f')][_0x52e32e][_0x1ff1('0x81')],_0x340bcf[_0x1ff1('0x7f')][_0x52e32e]['foreignTable'],_0x340bcf[_0x1ff1('0x7f')][_0x52e32e][_0x1ff1('0x83')]));}}}if(_0x340bcf[_0x1ff1('0x85')]){_0x340bcf[_0x1ff1('0x85')]=JSON['parse'](_0x340bcf[_0x1ff1('0x85')]);_0x2c8781['where'](_0x502f51(_0x340bcf[_0x1ff1('0x85')]['group']));}_0x9970b6=_0x2c8781[_0x1ff1('0x86')]();_0x2c8781[_0x1ff1('0x20')](_0x58aaea);_0x2c8781[_0x1ff1('0x1d')](0x0);logger[_0x1ff1('0x87')](_0x1ff1('0xaa'),_0x2c8781[_0x1ff1('0x88')]());return dbH[_0x1ff1('0x89')]['query'](_0x2c8781[_0x1ff1('0x88')](),{'type':dbH[_0x1ff1('0x89')][_0x1ff1('0x8a')][_0x1ff1('0x8b')]});}})[_0x1ff1('0x27')](function(){return{'sql':_0x9970b6[_0x1ff1('0x88')]()};})[_0x1ff1('0x27')](respondWithResult(_0x1d7db5,null))['catch'](handleError(_0x1d7db5,null));};
\ No newline at end of file
+var _0x36ae=['AnalyticExtractedReport','cdr','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','child_process','fork','../../components/export/','../../files/reports','countTable','COUNT(*)','left_join','AnalyticMetric','debug','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','json','offset','undefined','count','limit','status','set','Content-Range','apply','reject','save','update','then','destroy','CustomReports','UserProfileResource','error','stack','name','send','AnalyticCustomReport','rawAttributes','type','model','map','query','filters','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','keys','intersection','length','include','find','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','preview','join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%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)','DATE(%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','from','table','metric','function','replace','format','groupBy','orderBy','DESC','alias','joins','parse','parentKey','foreignTable','foreignKey','conditions','clone','Limited\x20Query:','toString','sequelize','QueryTypes','SELECT','right_join','MIN(%s)','HOUR(%s)','Please\x20insert\x20at\x20least\x20one\x20field','keyBy','select','MetricId','%s.%s\x20=\x20%s.%s','web','fullPath','%s-%s.%s','randomstring','generate','output','custom'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x36ae,0xb3));var _0xe36a=function(_0x5ae8f7,_0x330d91){_0x5ae8f7=_0x5ae8f7-0x0;var _0x54c636=_0x36ae[_0x5ae8f7];return _0x54c636;};'use strict';var emlformat=require(_0xe36a('0x0'));var rimraf=require(_0xe36a('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xe36a('0x2'));var rp=require(_0xe36a('0x3'));var moment=require('moment');var BPromise=require(_0xe36a('0x4'));var Mustache=require(_0xe36a('0x5'));var util=require(_0xe36a('0x6'));var path=require(_0xe36a('0x7'));var sox=require(_0xe36a('0x8'));var csv=require(_0xe36a('0x9'));var ejs=require(_0xe36a('0xa'));var fs=require('fs');var fs_extra=require(_0xe36a('0xb'));var _=require(_0xe36a('0xc'));var squel=require(_0xe36a('0xd'));var crypto=require('crypto');var jsforce=require(_0xe36a('0xe'));var deskjs=require(_0xe36a('0xf'));var toCsv=require(_0xe36a('0x9'));var querystring=require(_0xe36a('0x10'));var Papa=require(_0xe36a('0x11'));var Redis=require(_0xe36a('0x12'));var authService=require(_0xe36a('0x13'));var qs=require(_0xe36a('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0xe36a('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xe36a('0x16'));var db=require('../../mysqldb')['db'];var dbH=require(_0xe36a('0x17'))['dbH'];function respondWithStatusCode(_0x273a4f,_0x42c8ee){_0x42c8ee=_0x42c8ee||0xcc;return function(_0x2865c7){if(_0x2865c7){return _0x273a4f[_0xe36a('0x18')](_0x42c8ee);}return _0x273a4f['status'](_0x42c8ee)[_0xe36a('0x19')]();};}function respondWithResult(_0x6492c5,_0x4d6887){_0x4d6887=_0x4d6887||0xc8;return function(_0x3ea0a6){if(_0x3ea0a6){return _0x6492c5['status'](_0x4d6887)[_0xe36a('0x1a')](_0x3ea0a6);}};}function respondWithFilteredResult(_0x57ecdf,_0x2517a6){return function(_0x703f42){if(_0x703f42){var _0xca4ac0=typeof _0x2517a6[_0xe36a('0x1b')]===_0xe36a('0x1c')&&typeof _0x2517a6['limit']===_0xe36a('0x1c');var _0x2a713b=_0x703f42[_0xe36a('0x1d')];var _0x652a6=_0xca4ac0?0x0:_0x2517a6[_0xe36a('0x1b')];var _0x155066=_0xca4ac0?_0x703f42[_0xe36a('0x1d')]:_0x2517a6[_0xe36a('0x1b')]+_0x2517a6[_0xe36a('0x1e')];var _0x55eecf;if(_0x155066>=_0x2a713b){_0x155066=_0x2a713b;_0x55eecf=0xc8;}else{_0x55eecf=0xce;}_0x57ecdf[_0xe36a('0x1f')](_0x55eecf);return _0x57ecdf[_0xe36a('0x20')](_0xe36a('0x21'),_0x652a6+'-'+_0x155066+'/'+_0x2a713b)[_0xe36a('0x1a')](_0x703f42);}return null;};}function patchUpdates(_0x37cafd){return function(_0xb654de){try{jsonpatch[_0xe36a('0x22')](_0xb654de,_0x37cafd,!![]);}catch(_0x189d71){return BPromise[_0xe36a('0x23')](_0x189d71);}return _0xb654de[_0xe36a('0x24')]();};}function saveUpdates(_0x35cc00,_0x5ed791){return function(_0x477066){if(_0x477066){return _0x477066[_0xe36a('0x25')](_0x35cc00)[_0xe36a('0x26')](function(_0x1522e5){return _0x1522e5;});}return null;};}function removeEntity(_0x47033e,_0x4cdb18){return function(_0x56a305){if(_0x56a305){return _0x56a305[_0xe36a('0x27')]()['then'](function(){var _0x102dd0=_0x56a305['get']({'plain':!![]});var _0x4bcb3a=_0xe36a('0x28');return db[_0xe36a('0x29')][_0xe36a('0x27')]({'where':{'type':_0x4bcb3a,'resourceId':_0x102dd0['id']}})['then'](function(){return _0x56a305;});})[_0xe36a('0x26')](function(){_0x47033e['status'](0xcc)[_0xe36a('0x19')]();});}};}function handleEntityNotFound(_0x217736,_0xc69655){return function(_0x894ca){if(!_0x894ca){_0x217736[_0xe36a('0x18')](0x194);}return _0x894ca;};}function handleError(_0x4ddab1,_0x2d7976){_0x2d7976=_0x2d7976||0x1f4;return function(_0x1a18b2){logger[_0xe36a('0x2a')](_0x1a18b2[_0xe36a('0x2b')]);if(_0x1a18b2[_0xe36a('0x2c')]){delete _0x1a18b2[_0xe36a('0x2c')];}_0x4ddab1[_0xe36a('0x1f')](_0x2d7976)[_0xe36a('0x2d')](_0x1a18b2);};}exports['index']=function(_0x2017d1,_0x43d155){var _0x3a7214={},_0x26a7a6={},_0x1a19eb={'count':0x0,'rows':[]};var _0x3056bc=_['map'](db[_0xe36a('0x2e')][_0xe36a('0x2f')],function(_0x208e8d){return{'name':_0x208e8d['fieldName'],'type':_0x208e8d[_0xe36a('0x30')]['key']};});_0x26a7a6[_0xe36a('0x31')]=_[_0xe36a('0x32')](_0x3056bc,_0xe36a('0x2c'));_0x26a7a6[_0xe36a('0x33')]=_['keys'](_0x2017d1['query']);_0x26a7a6[_0xe36a('0x34')]=_['intersection'](_0x26a7a6[_0xe36a('0x31')],_0x26a7a6[_0xe36a('0x33')]);_0x3a7214[_0xe36a('0x35')]=_['intersection'](_0x26a7a6[_0xe36a('0x31')],qs[_0xe36a('0x36')](_0x2017d1[_0xe36a('0x33')][_0xe36a('0x36')]));_0x3a7214[_0xe36a('0x35')]=_0x3a7214['attributes']['length']?_0x3a7214[_0xe36a('0x35')]:_0x26a7a6[_0xe36a('0x31')];if(!_0x2017d1[_0xe36a('0x33')][_0xe36a('0x37')](_0xe36a('0x38'))){_0x3a7214[_0xe36a('0x1e')]=qs[_0xe36a('0x1e')](_0x2017d1['query'][_0xe36a('0x1e')]);_0x3a7214['offset']=qs['offset'](_0x2017d1[_0xe36a('0x33')][_0xe36a('0x1b')]);}_0x3a7214[_0xe36a('0x39')]=qs[_0xe36a('0x3a')](_0x2017d1[_0xe36a('0x33')][_0xe36a('0x3a')]);_0x3a7214['where']=qs['filters'](_[_0xe36a('0x3b')](_0x2017d1[_0xe36a('0x33')],_0x26a7a6[_0xe36a('0x34')]),_0x3056bc);if(_0x2017d1[_0xe36a('0x33')][_0xe36a('0x3c')]){_0x3a7214[_0xe36a('0x3d')]=_[_0xe36a('0x3e')](_0x3a7214[_0xe36a('0x3d')],{'$or':_[_0xe36a('0x32')](_0x3056bc,function(_0x36169e){if(_0x36169e[_0xe36a('0x30')]!==_0xe36a('0x3f')){var _0x541181={};_0x541181[_0x36169e[_0xe36a('0x2c')]]={'$like':'%'+_0x2017d1['query']['filter']+'%'};return _0x541181;}})});}_0x3a7214=_[_0xe36a('0x3e')]({},_0x3a7214,_0x2017d1[_0xe36a('0x40')]);var _0xd5c9e4={'where':_0x3a7214[_0xe36a('0x3d')]};return db[_0xe36a('0x2e')][_0xe36a('0x1d')](_0xd5c9e4)['then'](function(_0x127cba){_0x1a19eb[_0xe36a('0x1d')]=_0x127cba;if(_0x2017d1[_0xe36a('0x33')][_0xe36a('0x41')]){_0x3a7214['include']=[{'all':!![]}];}return db[_0xe36a('0x2e')][_0xe36a('0x42')](_0x3a7214);})[_0xe36a('0x26')](function(_0x5cb4b9){_0x1a19eb[_0xe36a('0x43')]=_0x5cb4b9;return _0x1a19eb;})[_0xe36a('0x26')](respondWithFilteredResult(_0x43d155,_0x3a7214))[_0xe36a('0x44')](handleError(_0x43d155,null));};exports[_0xe36a('0x45')]=function(_0x12750a,_0xe0343d){var _0x38a38d={'raw':![],'where':{'id':_0x12750a[_0xe36a('0x46')]['id']}},_0x1cec8d={};_0x1cec8d[_0xe36a('0x31')]=_[_0xe36a('0x47')](db[_0xe36a('0x2e')][_0xe36a('0x2f')]);_0x1cec8d[_0xe36a('0x33')]=_[_0xe36a('0x47')](_0x12750a[_0xe36a('0x33')]);_0x1cec8d['filters']=_[_0xe36a('0x48')](_0x1cec8d[_0xe36a('0x31')],_0x1cec8d[_0xe36a('0x33')]);_0x38a38d[_0xe36a('0x35')]=_[_0xe36a('0x48')](_0x1cec8d[_0xe36a('0x31')],qs[_0xe36a('0x36')](_0x12750a['query'][_0xe36a('0x36')]));_0x38a38d[_0xe36a('0x35')]=_0x38a38d['attributes'][_0xe36a('0x49')]?_0x38a38d[_0xe36a('0x35')]:_0x1cec8d['model'];if(_0x12750a[_0xe36a('0x33')][_0xe36a('0x41')]){_0x38a38d[_0xe36a('0x4a')]=[{'all':!![]}];}_0x38a38d=_[_0xe36a('0x3e')]({},_0x38a38d,_0x12750a[_0xe36a('0x40')]);return db['AnalyticCustomReport'][_0xe36a('0x4b')](_0x38a38d)[_0xe36a('0x26')](handleEntityNotFound(_0xe0343d,null))[_0xe36a('0x26')](respondWithResult(_0xe0343d,null))[_0xe36a('0x44')](handleError(_0xe0343d,null));};exports[_0xe36a('0x4c')]=function(_0x5d1953,_0x1084c7){return db[_0xe36a('0x2e')][_0xe36a('0x4c')](_0x5d1953[_0xe36a('0x4d')],{})['then'](function(_0x6e84d){var _0x1d7a68=_0x5d1953[_0xe36a('0x4e')][_0xe36a('0x4f')]({'plain':!![]});if(!_0x1d7a68)throw new Error(_0xe36a('0x50'));if(_0x1d7a68[_0xe36a('0x51')]===_0xe36a('0x4e')){var _0x1a7c3d=_0x6e84d[_0xe36a('0x4f')]({'plain':!![]});var _0x22fab2='Reports';return db[_0xe36a('0x52')]['find']({'where':{'name':_0x22fab2,'userProfileId':_0x1d7a68['userProfileId']},'raw':!![]})[_0xe36a('0x26')](function(_0x10e7a6){if(_0x10e7a6&&_0x10e7a6[_0xe36a('0x53')]===0x0){return db[_0xe36a('0x29')][_0xe36a('0x4c')]({'name':_0x1a7c3d['name'],'resourceId':_0x1a7c3d['id'],'type':_0xe36a('0x28'),'sectionId':_0x10e7a6['id']},{})[_0xe36a('0x26')](function(){return _0x6e84d;});}else{return _0x6e84d;}})[_0xe36a('0x44')](function(_0x2eb2a7){logger['error'](_0xe36a('0x54'),_0x2eb2a7);throw _0x2eb2a7;});}return _0x6e84d;})[_0xe36a('0x26')](respondWithResult(_0x1084c7,0xc9))[_0xe36a('0x44')](handleError(_0x1084c7,null));};exports[_0xe36a('0x25')]=function(_0x506944,_0x38a23e){if(_0x506944['body']['id']){delete _0x506944[_0xe36a('0x4d')]['id'];}return db['AnalyticCustomReport'][_0xe36a('0x4b')]({'where':{'id':_0x506944[_0xe36a('0x46')]['id']}})[_0xe36a('0x26')](handleEntityNotFound(_0x38a23e,null))[_0xe36a('0x26')](saveUpdates(_0x506944[_0xe36a('0x4d')],null))['then'](respondWithResult(_0x38a23e,null))[_0xe36a('0x44')](handleError(_0x38a23e,null));};exports[_0xe36a('0x27')]=function(_0x186ee3,_0x36f4ba){return db[_0xe36a('0x2e')][_0xe36a('0x4b')]({'where':{'id':_0x186ee3[_0xe36a('0x46')]['id']}})[_0xe36a('0x26')](handleEntityNotFound(_0x36f4ba,null))[_0xe36a('0x26')](removeEntity(_0x36f4ba,null))[_0xe36a('0x44')](handleError(_0x36f4ba,null));};exports[_0xe36a('0x55')]=function(_0x376e2d,_0x4f0fb1){var _0x2dde62=0xa;var _0x147457=[_0xe36a('0x56'),'left_join','right_join',_0xe36a('0x57')];var _0xd07bd0={'SUM':_0xe36a('0x58'),'COUNT':_0xe36a('0x59'),'COUNT DISTINCT':_0xe36a('0x5a'),'MAX':_0xe36a('0x5b'),'MIN':'MIN(%s)','AVG':_0xe36a('0x5c'),'GROUP_CONCAT':_0xe36a('0x5d'),'GROUP_CONCAT ASC':_0xe36a('0x5e'),'GROUP_CONCAT DESC':_0xe36a('0x5f')};var _0x40f5f3={'SEC_TO_TIME':_0xe36a('0x60'),'DATE':_0xe36a('0x61'),'HOUR':'HOUR(%s)','ROUND':_0xe36a('0x62'),'UNIX_TIMESTAMP':_0xe36a('0x63')};var _0x8368b7=function(_0x51ac1e){return!_[_0xe36a('0x64')]([_0xe36a('0x65'),_0xe36a('0x66'),_0xe36a('0x67'),_0xe36a('0x68')],_0x51ac1e);};var _0x223fa4=function(_0x4528ee){if(!_0x4528ee||!_0x4528ee[_0xe36a('0x69')]['length']){return'';}for(var _0x5163b2='(',_0x191195=0x0;_0x191195<_0x4528ee[_0xe36a('0x69')][_0xe36a('0x49')];_0x191195+=0x1){_0x191195>0x0&&(_0x5163b2+='\x20'+_0x4528ee[_0xe36a('0x6a')]+'\x20');_0x5163b2+=_0x4528ee[_0xe36a('0x69')][_0x191195][_0xe36a('0x6b')]?_0x223fa4(_0x4528ee[_0xe36a('0x69')][_0x191195][_0xe36a('0x6b')]):_0x4528ee['rules'][_0x191195][_0xe36a('0x6c')]+'\x20'+_0x4528ee[_0xe36a('0x69')][_0x191195][_0xe36a('0x6d')]+(_0x8368b7(_0x4528ee['rules'][_0x191195][_0xe36a('0x6d')])?'\x20'+_0x4528ee[_0xe36a('0x69')][_0x191195][_0xe36a('0x6e')]:'');}return _0x5163b2+')';};var _0x2c859d={'where':{'id':_0x376e2d[_0xe36a('0x46')]['id']}},_0x5ea26b,_0x3cbe67,_0x14e1c9,_0x597a79,_0x550097;_0x2c859d=_[_0xe36a('0x3e')]({},_0x2c859d,_0x376e2d[_0xe36a('0x40')]);return db[_0xe36a('0x2e')][_0xe36a('0x4b')](_0x2c859d)[_0xe36a('0x26')](function(_0xf71330){if(_0xf71330){_0x5ea26b=_0xf71330;return _0xf71330[_0xe36a('0x6f')]();}return null;})[_0xe36a('0x26')](function(_0x153d36){if(_0x153d36){if(!_0x153d36[_0xe36a('0x49')]){throw new db[(_0xe36a('0x70'))][(_0xe36a('0x71'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x3cbe67=_0x153d36;return db['AnalyticMetric'][_0xe36a('0x42')]({'raw':!![]});}return null;})[_0xe36a('0x26')](function(_0x1888c6){if(_0x1888c6){_0x14e1c9=_['keyBy'](_0x1888c6,'id');var _0x5bf30b;var _0x5843bb=squel['select']();_0x5843bb[_0xe36a('0x72')](_0x5ea26b[_0xe36a('0x73')]);for(var _0x639ed8=0x0;_0x639ed8<_0x3cbe67[_0xe36a('0x49')];_0x639ed8+=0x1){_0x5bf30b=_0x3cbe67[_0x639ed8]['MetricId']?_0x14e1c9[_0x3cbe67[_0x639ed8]['MetricId']][_0xe36a('0x74')]:_0x3cbe67[_0x639ed8][_0xe36a('0x6c')];_0x5bf30b=_0x3cbe67[_0x639ed8][_0xe36a('0x75')]?_[_0xe36a('0x76')](_0xd07bd0[_0x3cbe67[_0x639ed8][_0xe36a('0x75')]],'%s',_0x5bf30b):_0x5bf30b;_0x5bf30b=_0x3cbe67[_0x639ed8][_0xe36a('0x77')]?_[_0xe36a('0x76')](_0x40f5f3[_0x3cbe67[_0x639ed8][_0xe36a('0x77')]],'%s',_0x5bf30b):_0x5bf30b;if(_0x3cbe67[_0x639ed8][_0xe36a('0x78')]){_0x5843bb[_0xe36a('0x6b')](_0x5bf30b);}_0x3cbe67[_0x639ed8][_0xe36a('0x79')]&&_0x5843bb[_0xe36a('0x39')](_0x5bf30b,_0x3cbe67[_0x639ed8]['orderBy']===_0xe36a('0x7a')?![]:!![]);_0x5843bb[_0xe36a('0x6c')](_0x5bf30b,_0x3cbe67[_0x639ed8][_0xe36a('0x7b')]||_0x5bf30b);}if(_0x5ea26b[_0xe36a('0x7c')]){_0x5ea26b[_0xe36a('0x7c')]=JSON[_0xe36a('0x7d')](_0x5ea26b[_0xe36a('0x7c')]);for(var _0x2f5d4f=0x0;_0x2f5d4f<_0x5ea26b[_0xe36a('0x7c')]['length'];_0x2f5d4f+=0x1){if(_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f][_0xe36a('0x30')]&&_[_0xe36a('0x64')](_0x147457,_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f][_0xe36a('0x30')])&&_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f][_0xe36a('0x7e')]&&_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f][_0xe36a('0x7f')]&&_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f]['foreignKey']){_0x5843bb[_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f]['type']](_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f]['foreignTable'],null,util[_0xe36a('0x77')]('%s.%s\x20=\x20%s.%s',_0x5ea26b[_0xe36a('0x73')],_0x5ea26b['joins'][_0x2f5d4f][_0xe36a('0x7e')],_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f][_0xe36a('0x7f')],_0x5ea26b[_0xe36a('0x7c')][_0x2f5d4f][_0xe36a('0x80')]));}}}if(_0x5ea26b[_0xe36a('0x81')]){_0x5ea26b[_0xe36a('0x81')]=JSON[_0xe36a('0x7d')](_0x5ea26b['conditions']);_0x5843bb['where'](_0x223fa4(_0x5ea26b['conditions']['group']));}_0x550097=_0x5843bb[_0xe36a('0x82')]();_0x5843bb[_0xe36a('0x1e')](_0x2dde62);_0x5843bb['offset'](0x0);logger['debug'](_0xe36a('0x83'),_0x5843bb[_0xe36a('0x84')]());return dbH[_0xe36a('0x85')][_0xe36a('0x33')](_0x5843bb['toString'](),{'type':dbH['sequelize'][_0xe36a('0x86')][_0xe36a('0x87')]});}})[_0xe36a('0x26')](respondWithResult(_0x4f0fb1,null))[_0xe36a('0x44')](handleError(_0x4f0fb1,null));};function runReport(_0x2e4d73,_0x5b114a,_0x51c207){var _0x24e5fd=_0x5b114a[_0xe36a('0x2c')];var _0x35cde8=0xa;var _0xffa2e8=[_0xe36a('0x56'),'left_join',_0xe36a('0x88'),_0xe36a('0x57')];var _0x2c6581={'SUM':_0xe36a('0x58'),'COUNT':_0xe36a('0x59'),'COUNT DISTINCT':_0xe36a('0x5a'),'MAX':_0xe36a('0x5b'),'MIN':_0xe36a('0x89'),'AVG':_0xe36a('0x5c'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0xe36a('0x5e'),'GROUP_CONCAT DESC':_0xe36a('0x5f')};var _0x5d2b5b={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0xe36a('0x61'),'HOUR':_0xe36a('0x8a'),'ROUND':_0xe36a('0x62'),'UNIX_TIMESTAMP':_0xe36a('0x63')};var _0x4633a9=function(_0xab4c5d){return!_['includes']([_0xe36a('0x65'),_0xe36a('0x66'),_0xe36a('0x67'),_0xe36a('0x68')],_0xab4c5d);};var _0x1386e9=function(_0x3af19a){if(!_0x3af19a||!_0x3af19a[_0xe36a('0x69')][_0xe36a('0x49')]){return'';}for(var _0xc0b5df='(',_0x1863f3=0x0;_0x1863f3<_0x3af19a[_0xe36a('0x69')][_0xe36a('0x49')];_0x1863f3+=0x1){_0x1863f3>0x0&&(_0xc0b5df+='\x20'+_0x3af19a[_0xe36a('0x6a')]+'\x20');_0xc0b5df+=_0x3af19a[_0xe36a('0x69')][_0x1863f3]['group']?_0x1386e9(_0x3af19a[_0xe36a('0x69')][_0x1863f3][_0xe36a('0x6b')]):_0x3af19a[_0xe36a('0x69')][_0x1863f3][_0xe36a('0x6c')]+'\x20'+_0x3af19a['rules'][_0x1863f3][_0xe36a('0x6d')]+(_0x4633a9(_0x3af19a[_0xe36a('0x69')][_0x1863f3]['condition'])?'\x20'+_0x3af19a[_0xe36a('0x69')][_0x1863f3][_0xe36a('0x6e')]:'');}return _0xc0b5df+')';};var _0x3468a6={'where':{'id':_0x2e4d73['id']}},_0x3c0337,_0x4a5d97,_0x5cda2d,_0x55596f,_0x52e0ca;_0x3468a6=_[_0xe36a('0x3e')]({},_0x3468a6,_0x51c207);return db['AnalyticCustomReport'][_0xe36a('0x4b')](_0x3468a6)[_0xe36a('0x26')](function(_0x30e3b5){if(_0x30e3b5){_0x3c0337=_0x30e3b5;return _0x30e3b5['getFields']();}return null;})['then'](function(_0x1e7ad9){if(_0x1e7ad9){if(!_0x1e7ad9[_0xe36a('0x49')]){throw new db['Sequelize']['ValidationErrorItem'](_0xe36a('0x8b'),0x193);}_0x4a5d97=_0x1e7ad9;return db['AnalyticMetric'][_0xe36a('0x42')]({'raw':!![]});}return null;})['then'](function(_0x536c21){if(_0x536c21){_0x5cda2d=_[_0xe36a('0x8c')](_0x536c21,'id');var _0x2fbdbf;var _0x28b978=squel[_0xe36a('0x8d')]();_0x28b978[_0xe36a('0x72')](_0x3c0337[_0xe36a('0x73')]);for(var _0x5738b0=0x0;_0x5738b0<_0x4a5d97[_0xe36a('0x49')];_0x5738b0+=0x1){_0x2fbdbf=_0x4a5d97[_0x5738b0][_0xe36a('0x8e')]?_0x5cda2d[_0x4a5d97[_0x5738b0][_0xe36a('0x8e')]][_0xe36a('0x74')]:_0x4a5d97[_0x5738b0][_0xe36a('0x6c')];_0x2fbdbf=_0x4a5d97[_0x5738b0][_0xe36a('0x75')]?_['replace'](_0x2c6581[_0x4a5d97[_0x5738b0][_0xe36a('0x75')]],'%s',_0x2fbdbf):_0x2fbdbf;_0x2fbdbf=_0x4a5d97[_0x5738b0][_0xe36a('0x77')]?_['replace'](_0x5d2b5b[_0x4a5d97[_0x5738b0][_0xe36a('0x77')]],'%s',_0x2fbdbf):_0x2fbdbf;if(_0x4a5d97[_0x5738b0][_0xe36a('0x78')]){_0x28b978[_0xe36a('0x6b')](_0x2fbdbf);}_0x4a5d97[_0x5738b0]['orderBy']&&_0x28b978['order'](_0x2fbdbf,_0x4a5d97[_0x5738b0][_0xe36a('0x79')]===_0xe36a('0x7a')?![]:!![]);_0x28b978[_0xe36a('0x6c')](_0x2fbdbf,_0x4a5d97[_0x5738b0][_0xe36a('0x7b')]||_0x2fbdbf);}if(_0x3c0337[_0xe36a('0x7c')]){_0x3c0337[_0xe36a('0x7c')]=JSON[_0xe36a('0x7d')](_0x3c0337[_0xe36a('0x7c')]);for(var _0x11b16b=0x0;_0x11b16b<_0x3c0337[_0xe36a('0x7c')][_0xe36a('0x49')];_0x11b16b+=0x1){if(_0x3c0337[_0xe36a('0x7c')][_0x11b16b][_0xe36a('0x30')]&&_['includes'](_0xffa2e8,_0x3c0337['joins'][_0x11b16b]['type'])&&_0x3c0337[_0xe36a('0x7c')][_0x11b16b][_0xe36a('0x7e')]&&_0x3c0337[_0xe36a('0x7c')][_0x11b16b][_0xe36a('0x7f')]&&_0x3c0337[_0xe36a('0x7c')][_0x11b16b]['foreignKey']){_0x28b978[_0x3c0337['joins'][_0x11b16b][_0xe36a('0x30')]](_0x3c0337[_0xe36a('0x7c')][_0x11b16b][_0xe36a('0x7f')],null,util[_0xe36a('0x77')](_0xe36a('0x8f'),_0x3c0337['table'],_0x3c0337['joins'][_0x11b16b][_0xe36a('0x7e')],_0x3c0337['joins'][_0x11b16b][_0xe36a('0x7f')],_0x3c0337[_0xe36a('0x7c')][_0x11b16b][_0xe36a('0x80')]));}}}if(_0x3c0337[_0xe36a('0x81')]){_0x3c0337['conditions']=JSON[_0xe36a('0x7d')](_0x3c0337[_0xe36a('0x81')]);_0x28b978['where'](_0x1386e9(_0x3c0337[_0xe36a('0x81')]['group']));}_0x52e0ca=_0x28b978['clone']();_0x28b978['limit'](_0x35cde8);_0x28b978[_0xe36a('0x1b')](0x0);return;}})[_0xe36a('0x26')](function(){if(_0x5b114a['output']===_0xe36a('0x90')){return null;}var _0x49296a=_[_0xe36a('0x3e')](_0x5b114a,{'name':_0x5b114a[_0xe36a('0x91')]||_0x5b114a[_0xe36a('0x2c')]||_0x3c0337[_0xe36a('0x2c')],'basename':_0x24e5fd,'savename':util[_0xe36a('0x77')](_0xe36a('0x92'),_0x5b114a[_0xe36a('0x2c')]||_0x3c0337[_0xe36a('0x2c')],require(_0xe36a('0x93'))[_0xe36a('0x94')](0x4),_0x5b114a[_0xe36a('0x95')]||'csv'),'reportId':_0x3c0337['id'],'reportType':_0xe36a('0x96')});return db[_0xe36a('0x97')]['create'](_0x49296a,{'raw':!![]});})['then'](function(_0x222dcc){if(_0x3c0337['table']===_0xe36a('0x98')){_0x52e0ca[_0xe36a('0x3d')](_0x3c0337[_0xe36a('0x73')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x5b114a[_0xe36a('0x99')],_0x5b114a[_0xe36a('0x9a')]);}else{_0x52e0ca[_0xe36a('0x3d')](_0x3c0337['table']+_0xe36a('0x9b'),_0x5b114a[_0xe36a('0x99')],_0x5b114a[_0xe36a('0x9a')]);}if(_0x222dcc){logger['info']('Run\x20Query:',_0x52e0ca[_0xe36a('0x84')]());require(_0xe36a('0x9c'))[_0xe36a('0x9d')](path[_0xe36a('0x56')](__dirname,_0xe36a('0x9e'),_0x222dcc[_0xe36a('0x95')]),[_0x222dcc['id'],_0x52e0ca[_0xe36a('0x84')](),path[_0xe36a('0x56')](__dirname,_0xe36a('0x9f'),_0x222dcc['savename']),_0x24e5fd]);return _0x222dcc;}else{var _0x3106b7=squel['select']();_0x3106b7['from']('('+_0x52e0ca[_0xe36a('0x84')]()+')',_0xe36a('0xa0'));_0x3106b7[_0xe36a('0x6c')](_0xe36a('0xa1'),'count');_0x52e0ca[_0xe36a('0x1e')](_0x5b114a[_0xe36a('0x1e')]||_0x35cde8);_0x52e0ca[_0xe36a('0x1b')](_0x5b114a['offset']||0x0);return dbH['sequelize'][_0xe36a('0x33')](_0x3106b7[_0xe36a('0x84')](),{'type':dbH['sequelize']['QueryTypes'][_0xe36a('0x87')]})[_0xe36a('0x26')](function(_0x2d4d06){if(!_0x2d4d06[_0xe36a('0x49')]){_0x55596f=0x0;}else{_0x55596f=_0x2d4d06[0x0][_0xe36a('0x1d')]||0x0;}return dbH['sequelize'][_0xe36a('0x33')](_0x52e0ca[_0xe36a('0x84')](),{'type':dbH['sequelize'][_0xe36a('0x86')]['SELECT']});})[_0xe36a('0x26')](function(_0x15b9a5){return{'rows':_0x15b9a5||[],'count':_0x55596f};});}});}exports['run']=function(_0x4a08b2,_0x538af5){return runReport(_0x4a08b2[_0xe36a('0x46')],_0x4a08b2[_0xe36a('0x33')],_0x4a08b2['options'])[_0xe36a('0x26')](respondWithResult(_0x538af5,null))['catch'](handleError(_0x538af5,null));};exports['runReport']=runReport;exports['query']=function(_0x655b66,_0x49e7ed){var _0x531ec8=0xa;var _0x5cb8c9=['join',_0xe36a('0xa2'),_0xe36a('0x88'),'cross_join'];var _0x43019a={'SUM':'SUM(%s)','COUNT':_0xe36a('0x59'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0xe36a('0x5b'),'MIN':_0xe36a('0x89'),'AVG':_0xe36a('0x5c'),'GROUP_CONCAT':_0xe36a('0x5d'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x5dad02={'SEC_TO_TIME':_0xe36a('0x60'),'DATE':_0xe36a('0x61'),'HOUR':'HOUR(%s)','ROUND':_0xe36a('0x62'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x2be918=function(_0xdef831){return!_[_0xe36a('0x64')]([_0xe36a('0x65'),_0xe36a('0x66'),_0xe36a('0x67'),_0xe36a('0x68')],_0xdef831);};var _0x68cc21=function(_0x3e6193){if(!_0x3e6193||!_0x3e6193['rules'][_0xe36a('0x49')]){return'';}for(var _0x13afa3='(',_0x50e357=0x0;_0x50e357<_0x3e6193[_0xe36a('0x69')][_0xe36a('0x49')];_0x50e357+=0x1){_0x50e357>0x0&&(_0x13afa3+='\x20'+_0x3e6193['operator']+'\x20');_0x13afa3+=_0x3e6193[_0xe36a('0x69')][_0x50e357][_0xe36a('0x6b')]?_0x68cc21(_0x3e6193[_0xe36a('0x69')][_0x50e357][_0xe36a('0x6b')]):_0x3e6193[_0xe36a('0x69')][_0x50e357][_0xe36a('0x6c')]+'\x20'+_0x3e6193[_0xe36a('0x69')][_0x50e357][_0xe36a('0x6d')]+(_0x2be918(_0x3e6193['rules'][_0x50e357][_0xe36a('0x6d')])?'\x20'+_0x3e6193[_0xe36a('0x69')][_0x50e357]['value']:'');}return _0x13afa3+')';};var _0x5d27f2={'where':{'id':_0x655b66[_0xe36a('0x46')]['id']}},_0x4a3f99,_0x3f4439,_0x5f1b29,_0x3d68be,_0x41e68a;_0x5d27f2=_['merge']({},_0x5d27f2,_0x655b66['options']);return db[_0xe36a('0x2e')][_0xe36a('0x4b')](_0x5d27f2)['then'](function(_0x2920a6){if(_0x2920a6){_0x4a3f99=_0x2920a6;return _0x2920a6[_0xe36a('0x6f')]();}return null;})[_0xe36a('0x26')](function(_0x6ed048){if(_0x6ed048){if(!_0x6ed048[_0xe36a('0x49')]){throw new db[(_0xe36a('0x70'))][(_0xe36a('0x71'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x3f4439=_0x6ed048;return db[_0xe36a('0xa3')][_0xe36a('0x42')]({'raw':!![]});}return null;})['then'](function(_0x2f89f1){if(_0x2f89f1){_0x5f1b29=_[_0xe36a('0x8c')](_0x2f89f1,'id');var _0x18876b;var _0x27fad1=squel[_0xe36a('0x8d')]();_0x27fad1[_0xe36a('0x72')](_0x4a3f99['table']);for(var _0x385676=0x0;_0x385676<_0x3f4439[_0xe36a('0x49')];_0x385676+=0x1){_0x18876b=_0x3f4439[_0x385676][_0xe36a('0x8e')]?_0x5f1b29[_0x3f4439[_0x385676][_0xe36a('0x8e')]][_0xe36a('0x74')]:_0x3f4439[_0x385676]['field'];_0x18876b=_0x3f4439[_0x385676]['function']?_[_0xe36a('0x76')](_0x43019a[_0x3f4439[_0x385676][_0xe36a('0x75')]],'%s',_0x18876b):_0x18876b;_0x18876b=_0x3f4439[_0x385676]['format']?_[_0xe36a('0x76')](_0x5dad02[_0x3f4439[_0x385676][_0xe36a('0x77')]],'%s',_0x18876b):_0x18876b;if(_0x3f4439[_0x385676][_0xe36a('0x78')]){_0x27fad1[_0xe36a('0x6b')](_0x18876b);}_0x3f4439[_0x385676]['orderBy']&&_0x27fad1['order'](_0x18876b,_0x3f4439[_0x385676][_0xe36a('0x79')]===_0xe36a('0x7a')?![]:!![]);_0x27fad1[_0xe36a('0x6c')](_0x18876b,_0x3f4439[_0x385676][_0xe36a('0x7b')]||_0x18876b);}if(_0x4a3f99['joins']){_0x4a3f99['joins']=JSON[_0xe36a('0x7d')](_0x4a3f99[_0xe36a('0x7c')]);for(var _0x25d704=0x0;_0x25d704<_0x4a3f99[_0xe36a('0x7c')]['length'];_0x25d704+=0x1){if(_0x4a3f99['joins'][_0x25d704][_0xe36a('0x30')]&&_[_0xe36a('0x64')](_0x5cb8c9,_0x4a3f99[_0xe36a('0x7c')][_0x25d704][_0xe36a('0x30')])&&_0x4a3f99[_0xe36a('0x7c')][_0x25d704][_0xe36a('0x7e')]&&_0x4a3f99[_0xe36a('0x7c')][_0x25d704][_0xe36a('0x7f')]&&_0x4a3f99[_0xe36a('0x7c')][_0x25d704][_0xe36a('0x80')]){_0x27fad1[_0x4a3f99[_0xe36a('0x7c')][_0x25d704][_0xe36a('0x30')]](_0x4a3f99[_0xe36a('0x7c')][_0x25d704][_0xe36a('0x7f')],null,util[_0xe36a('0x77')](_0xe36a('0x8f'),_0x4a3f99['table'],_0x4a3f99[_0xe36a('0x7c')][_0x25d704]['parentKey'],_0x4a3f99['joins'][_0x25d704]['foreignTable'],_0x4a3f99[_0xe36a('0x7c')][_0x25d704][_0xe36a('0x80')]));}}}if(_0x4a3f99[_0xe36a('0x81')]){_0x4a3f99[_0xe36a('0x81')]=JSON[_0xe36a('0x7d')](_0x4a3f99[_0xe36a('0x81')]);_0x27fad1[_0xe36a('0x3d')](_0x68cc21(_0x4a3f99['conditions'][_0xe36a('0x6b')]));}_0x41e68a=_0x27fad1[_0xe36a('0x82')]();_0x27fad1[_0xe36a('0x1e')](_0x531ec8);_0x27fad1[_0xe36a('0x1b')](0x0);logger[_0xe36a('0xa4')](_0xe36a('0x83'),_0x27fad1['toString']());return dbH[_0xe36a('0x85')][_0xe36a('0x33')](_0x27fad1[_0xe36a('0x84')](),{'type':dbH[_0xe36a('0x85')]['QueryTypes'][_0xe36a('0x87')]});}})[_0xe36a('0x26')](function(){return{'sql':_0x41e68a['toString']()};})[_0xe36a('0x26')](respondWithResult(_0x49e7ed,null))[_0xe36a('0x44')](handleError(_0x49e7ed,null));};
\ No newline at end of file