Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index ff18f5e..b545fea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8f9f=['rimraf','fast-json-patch','request-promise','moment','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','end','json','undefined','limit','count','offset','Content-Range','reject','save','update','then','destroy','get','CustomReports','UserProfileResource','stack','name','map','AnalyticCustomReport','rawAttributes','type','key','query','filters','model','attributes','intersection','fields','hasOwnProperty','nolimit','where','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','keys','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','preview','join','left_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%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\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','length','rules','group','field','condition','value','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','from','table','MetricId','metric','function','replace','format','groupBy','orderBy','order','DESC','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','clone','debug','Limited\x20Query:','toString','sequelize','SELECT','right_join','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','HOUR(%s)','operator','alias','fullPath','%s-%s.%s','randomstring','output','csv','custom','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','endDate','Run\x20Query:','child_process','fork','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','QueryTypes','run','IS\x20NULL','eml-format'];(function(_0x52d40c,_0x5159ec){var _0x2b070a=function(_0x25e5b7){while(--_0x25e5b7){_0x52d40c['push'](_0x52d40c['shift']());}};_0x2b070a(++_0x5159ec);}(_0x8f9f,0x1ee));var _0xf8f9=function(_0x580647,_0x43d2c3){_0x580647=_0x580647-0x0;var _0x5f0792=_0x8f9f[_0x580647];return _0x5f0792;};'use strict';var emlformat=require(_0xf8f9('0x0'));var rimraf=require(_0xf8f9('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf8f9('0x2'));var rp=require(_0xf8f9('0x3'));var moment=require(_0xf8f9('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf8f9('0x5'));var path=require(_0xf8f9('0x6'));var sox=require(_0xf8f9('0x7'));var csv=require(_0xf8f9('0x8'));var ejs=require(_0xf8f9('0x9'));var fs=require('fs');var fs_extra=require(_0xf8f9('0xa'));var _=require(_0xf8f9('0xb'));var squel=require(_0xf8f9('0xc'));var crypto=require('crypto');var jsforce=require(_0xf8f9('0xd'));var deskjs=require(_0xf8f9('0xe'));var toCsv=require(_0xf8f9('0x8'));var querystring=require(_0xf8f9('0xf'));var Papa=require(_0xf8f9('0x10'));var Redis=require('ioredis');var authService=require(_0xf8f9('0x11'));var qs=require(_0xf8f9('0x12'));var as=require(_0xf8f9('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf8f9('0x14'))('api');var utils=require(_0xf8f9('0x15'));var config=require(_0xf8f9('0x16'));var licenseUtil=require(_0xf8f9('0x17'));var db=require('../../mysqldb')['db'];var dbH=require(_0xf8f9('0x18'))[_0xf8f9('0x19')];function respondWithStatusCode(_0x53583c,_0x2fd5ba){_0x2fd5ba=_0x2fd5ba||0xcc;return function(_0x3efe27){if(_0x3efe27){return _0x53583c[_0xf8f9('0x1a')](_0x2fd5ba);}return _0x53583c[_0xf8f9('0x1b')](_0x2fd5ba)[_0xf8f9('0x1c')]();};}function respondWithResult(_0x2e810f,_0x42abdd){_0x42abdd=_0x42abdd||0xc8;return function(_0xd0507b){if(_0xd0507b){return _0x2e810f['status'](_0x42abdd)[_0xf8f9('0x1d')](_0xd0507b);}};}function respondWithFilteredResult(_0x3a07f0,_0xd2d3cb){return function(_0x2f0a7d){if(_0x2f0a7d){var _0x8b6346=typeof _0xd2d3cb['offset']===_0xf8f9('0x1e')&&typeof _0xd2d3cb[_0xf8f9('0x1f')]===_0xf8f9('0x1e');var _0x3ce72b=_0x2f0a7d[_0xf8f9('0x20')];var _0x1d969c=_0x8b6346?0x0:_0xd2d3cb['offset'];var _0x3cef0c=_0x8b6346?_0x2f0a7d['count']:_0xd2d3cb[_0xf8f9('0x21')]+_0xd2d3cb['limit'];var _0x25aa52;if(_0x3cef0c>=_0x3ce72b){_0x3cef0c=_0x3ce72b;_0x25aa52=0xc8;}else{_0x25aa52=0xce;}_0x3a07f0[_0xf8f9('0x1b')](_0x25aa52);return _0x3a07f0['set'](_0xf8f9('0x22'),_0x1d969c+'-'+_0x3cef0c+'/'+_0x3ce72b)[_0xf8f9('0x1d')](_0x2f0a7d);}return null;};}function patchUpdates(_0x1e048c){return function(_0x1d6c60){try{jsonpatch['apply'](_0x1d6c60,_0x1e048c,!![]);}catch(_0x3213e8){return BPromise[_0xf8f9('0x23')](_0x3213e8);}return _0x1d6c60[_0xf8f9('0x24')]();};}function saveUpdates(_0x2208dc,_0x2f77e1){return function(_0x5004eb){if(_0x5004eb){return _0x5004eb[_0xf8f9('0x25')](_0x2208dc)[_0xf8f9('0x26')](function(_0x481266){return _0x481266;});}return null;};}function removeEntity(_0x46db24,_0x113710){return function(_0x4ca05a){if(_0x4ca05a){return _0x4ca05a[_0xf8f9('0x27')]()['then'](function(){var _0x77061f=_0x4ca05a[_0xf8f9('0x28')]({'plain':!![]});var _0x512208=_0xf8f9('0x29');return db[_0xf8f9('0x2a')]['destroy']({'where':{'type':_0x512208,'resourceId':_0x77061f['id']}})[_0xf8f9('0x26')](function(){return _0x4ca05a;});})[_0xf8f9('0x26')](function(){_0x46db24[_0xf8f9('0x1b')](0xcc)[_0xf8f9('0x1c')]();});}};}function handleEntityNotFound(_0x5b121d,_0x262ce5){return function(_0xc85710){if(!_0xc85710){_0x5b121d[_0xf8f9('0x1a')](0x194);}return _0xc85710;};}function handleError(_0x3fe7bc,_0x4f972f){_0x4f972f=_0x4f972f||0x1f4;return function(_0x24e0ac){logger['error'](_0x24e0ac[_0xf8f9('0x2b')]);if(_0x24e0ac['name']){delete _0x24e0ac[_0xf8f9('0x2c')];}_0x3fe7bc[_0xf8f9('0x1b')](_0x4f972f)['send'](_0x24e0ac);};}exports['index']=function(_0x41ffad,_0x2cb24a){var _0x3c95ed={},_0x4c963a={},_0x342c06={'count':0x0,'rows':[]};var _0x5b8cf6=_[_0xf8f9('0x2d')](db[_0xf8f9('0x2e')][_0xf8f9('0x2f')],function(_0x1a937b){return{'name':_0x1a937b['fieldName'],'type':_0x1a937b[_0xf8f9('0x30')][_0xf8f9('0x31')]};});_0x4c963a['model']=_[_0xf8f9('0x2d')](_0x5b8cf6,'name');_0x4c963a[_0xf8f9('0x32')]=_['keys'](_0x41ffad[_0xf8f9('0x32')]);_0x4c963a[_0xf8f9('0x33')]=_['intersection'](_0x4c963a[_0xf8f9('0x34')],_0x4c963a[_0xf8f9('0x32')]);_0x3c95ed[_0xf8f9('0x35')]=_[_0xf8f9('0x36')](_0x4c963a[_0xf8f9('0x34')],qs[_0xf8f9('0x37')](_0x41ffad[_0xf8f9('0x32')][_0xf8f9('0x37')]));_0x3c95ed[_0xf8f9('0x35')]=_0x3c95ed[_0xf8f9('0x35')]['length']?_0x3c95ed[_0xf8f9('0x35')]:_0x4c963a[_0xf8f9('0x34')];if(!_0x41ffad[_0xf8f9('0x32')][_0xf8f9('0x38')](_0xf8f9('0x39'))){_0x3c95ed[_0xf8f9('0x1f')]=qs[_0xf8f9('0x1f')](_0x41ffad['query'][_0xf8f9('0x1f')]);_0x3c95ed[_0xf8f9('0x21')]=qs[_0xf8f9('0x21')](_0x41ffad[_0xf8f9('0x32')][_0xf8f9('0x21')]);}_0x3c95ed['order']=qs['sort'](_0x41ffad[_0xf8f9('0x32')]['sort']);_0x3c95ed[_0xf8f9('0x3a')]=qs['filters'](_['pick'](_0x41ffad['query'],_0x4c963a[_0xf8f9('0x33')]),_0x5b8cf6);if(_0x41ffad['query'][_0xf8f9('0x3b')]){_0x3c95ed[_0xf8f9('0x3a')]=_[_0xf8f9('0x3c')](_0x3c95ed['where'],{'$or':_[_0xf8f9('0x2d')](_0x5b8cf6,function(_0x452024){if(_0x452024[_0xf8f9('0x30')]!==_0xf8f9('0x3d')){var _0x1990a3={};_0x1990a3[_0x452024['name']]={'$like':'%'+_0x41ffad[_0xf8f9('0x32')]['filter']+'%'};return _0x1990a3;}})});}_0x3c95ed=_['merge']({},_0x3c95ed,_0x41ffad[_0xf8f9('0x3e')]);var _0x56c739={'where':_0x3c95ed[_0xf8f9('0x3a')]};return db[_0xf8f9('0x2e')][_0xf8f9('0x20')](_0x56c739)['then'](function(_0x599160){_0x342c06[_0xf8f9('0x20')]=_0x599160;if(_0x41ffad['query'][_0xf8f9('0x3f')]){_0x3c95ed[_0xf8f9('0x40')]=[{'all':!![]}];}return db[_0xf8f9('0x2e')][_0xf8f9('0x41')](_0x3c95ed);})[_0xf8f9('0x26')](function(_0x71dfa0){_0x342c06[_0xf8f9('0x42')]=_0x71dfa0;return _0x342c06;})[_0xf8f9('0x26')](respondWithFilteredResult(_0x2cb24a,_0x3c95ed))[_0xf8f9('0x43')](handleError(_0x2cb24a,null));};exports[_0xf8f9('0x44')]=function(_0x5829f8,_0x351c66){var _0x28eb23={'raw':![],'where':{'id':_0x5829f8[_0xf8f9('0x45')]['id']}},_0x232167={};_0x232167[_0xf8f9('0x34')]=_['keys'](db['AnalyticCustomReport'][_0xf8f9('0x2f')]);_0x232167[_0xf8f9('0x32')]=_[_0xf8f9('0x46')](_0x5829f8[_0xf8f9('0x32')]);_0x232167[_0xf8f9('0x33')]=_[_0xf8f9('0x36')](_0x232167[_0xf8f9('0x34')],_0x232167[_0xf8f9('0x32')]);_0x28eb23[_0xf8f9('0x35')]=_[_0xf8f9('0x36')](_0x232167[_0xf8f9('0x34')],qs[_0xf8f9('0x37')](_0x5829f8[_0xf8f9('0x32')][_0xf8f9('0x37')]));_0x28eb23['attributes']=_0x28eb23[_0xf8f9('0x35')]['length']?_0x28eb23[_0xf8f9('0x35')]:_0x232167[_0xf8f9('0x34')];if(_0x5829f8['query'][_0xf8f9('0x3f')]){_0x28eb23[_0xf8f9('0x40')]=[{'all':!![]}];}_0x28eb23=_[_0xf8f9('0x3c')]({},_0x28eb23,_0x5829f8['options']);return db[_0xf8f9('0x2e')][_0xf8f9('0x47')](_0x28eb23)[_0xf8f9('0x26')](handleEntityNotFound(_0x351c66,null))[_0xf8f9('0x26')](respondWithResult(_0x351c66,null))[_0xf8f9('0x43')](handleError(_0x351c66,null));};exports[_0xf8f9('0x48')]=function(_0x251db7,_0x2061f4){return db[_0xf8f9('0x2e')][_0xf8f9('0x48')](_0x251db7[_0xf8f9('0x49')],{})[_0xf8f9('0x26')](function(_0x1fd901){var _0x5f418c=_0x251db7[_0xf8f9('0x4a')][_0xf8f9('0x28')]({'plain':!![]});if(!_0x5f418c)throw new Error(_0xf8f9('0x4b'));if(_0x5f418c[_0xf8f9('0x4c')]===_0xf8f9('0x4a')){var _0x290b0d=_0x1fd901[_0xf8f9('0x28')]({'plain':!![]});var _0x4407d0='Reports';return db[_0xf8f9('0x4d')]['find']({'where':{'name':_0x4407d0,'userProfileId':_0x5f418c['userProfileId']},'raw':!![]})[_0xf8f9('0x26')](function(_0x193900){if(_0x193900&&_0x193900[_0xf8f9('0x4e')]===0x0){return db['UserProfileResource'][_0xf8f9('0x48')]({'name':_0x290b0d[_0xf8f9('0x2c')],'resourceId':_0x290b0d['id'],'type':'CustomReports','sectionId':_0x193900['id']},{})[_0xf8f9('0x26')](function(){return _0x1fd901;});}else{return _0x1fd901;}})[_0xf8f9('0x43')](function(_0x37da45){logger[_0xf8f9('0x4f')](_0xf8f9('0x50'),_0x37da45);throw _0x37da45;});}return _0x1fd901;})[_0xf8f9('0x26')](respondWithResult(_0x2061f4,0xc9))[_0xf8f9('0x43')](handleError(_0x2061f4,null));};exports[_0xf8f9('0x25')]=function(_0x270b8f,_0x5c194e){if(_0x270b8f['body']['id']){delete _0x270b8f['body']['id'];}return db['AnalyticCustomReport'][_0xf8f9('0x47')]({'where':{'id':_0x270b8f[_0xf8f9('0x45')]['id']}})[_0xf8f9('0x26')](handleEntityNotFound(_0x5c194e,null))[_0xf8f9('0x26')](saveUpdates(_0x270b8f['body'],null))['then'](respondWithResult(_0x5c194e,null))[_0xf8f9('0x43')](handleError(_0x5c194e,null));};exports['destroy']=function(_0x185ec3,_0x42a48a){return db[_0xf8f9('0x2e')]['find']({'where':{'id':_0x185ec3[_0xf8f9('0x45')]['id']}})[_0xf8f9('0x26')](handleEntityNotFound(_0x42a48a,null))['then'](removeEntity(_0x42a48a,null))['catch'](handleError(_0x42a48a,null));};exports[_0xf8f9('0x51')]=function(_0x1ca21c,_0x59f784){var _0x119ef0=0xa;var _0x20f5f4=[_0xf8f9('0x52'),_0xf8f9('0x53'),'right_join',_0xf8f9('0x54')];var _0x3acbe2={'SUM':_0xf8f9('0x55'),'COUNT':_0xf8f9('0x56'),'COUNT DISTINCT':_0xf8f9('0x57'),'MAX':_0xf8f9('0x58'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0xf8f9('0x59'),'GROUP_CONCAT DESC':_0xf8f9('0x5a')};var _0x23e8f5={'SEC_TO_TIME':_0xf8f9('0x5b'),'DATE':_0xf8f9('0x5c'),'HOUR':'HOUR(%s)','ROUND':_0xf8f9('0x5d'),'UNIX_TIMESTAMP':_0xf8f9('0x5e')};var _0x5e519d=function(_0x1ac445){return!_[_0xf8f9('0x5f')](['IS\x20NULL',_0xf8f9('0x60'),_0xf8f9('0x61'),_0xf8f9('0x62')],_0x1ac445);};var _0x43cb3c=function(_0x20abef){if(!_0x20abef||!_0x20abef['rules'][_0xf8f9('0x63')]){return'';}for(var _0x21cca0='(',_0x3c147b=0x0;_0x3c147b<_0x20abef[_0xf8f9('0x64')]['length'];_0x3c147b+=0x1){_0x3c147b>0x0&&(_0x21cca0+='\x20'+_0x20abef['operator']+'\x20');_0x21cca0+=_0x20abef['rules'][_0x3c147b][_0xf8f9('0x65')]?_0x43cb3c(_0x20abef['rules'][_0x3c147b][_0xf8f9('0x65')]):_0x20abef[_0xf8f9('0x64')][_0x3c147b][_0xf8f9('0x66')]+'\x20'+_0x20abef[_0xf8f9('0x64')][_0x3c147b]['condition']+(_0x5e519d(_0x20abef['rules'][_0x3c147b][_0xf8f9('0x67')])?'\x20'+_0x20abef[_0xf8f9('0x64')][_0x3c147b][_0xf8f9('0x68')]:'');}return _0x21cca0+')';};var _0x50f89d={'where':{'id':_0x1ca21c['params']['id']}},_0x2056fb,_0x17f514,_0x4e833c,_0xab9150,_0xf2b36a;_0x50f89d=_[_0xf8f9('0x3c')]({},_0x50f89d,_0x1ca21c[_0xf8f9('0x3e')]);return db[_0xf8f9('0x2e')][_0xf8f9('0x47')](_0x50f89d)[_0xf8f9('0x26')](function(_0x31670e){if(_0x31670e){_0x2056fb=_0x31670e;return _0x31670e[_0xf8f9('0x69')]();}return null;})['then'](function(_0x337b65){if(_0x337b65){if(!_0x337b65[_0xf8f9('0x63')]){throw new db[(_0xf8f9('0x6a'))][(_0xf8f9('0x6b'))](_0xf8f9('0x6c'),0x193);}_0x17f514=_0x337b65;return db[_0xf8f9('0x6d')]['findAll']({'raw':!![]});}return null;})[_0xf8f9('0x26')](function(_0xdee894){if(_0xdee894){_0x4e833c=_[_0xf8f9('0x6e')](_0xdee894,'id');var _0x453f06;var _0x1870e1=squel['select']();_0x1870e1[_0xf8f9('0x6f')](_0x2056fb[_0xf8f9('0x70')]);for(var _0x3fb2ef=0x0;_0x3fb2ef<_0x17f514['length'];_0x3fb2ef+=0x1){_0x453f06=_0x17f514[_0x3fb2ef][_0xf8f9('0x71')]?_0x4e833c[_0x17f514[_0x3fb2ef][_0xf8f9('0x71')]][_0xf8f9('0x72')]:_0x17f514[_0x3fb2ef][_0xf8f9('0x66')];_0x453f06=_0x17f514[_0x3fb2ef][_0xf8f9('0x73')]?_[_0xf8f9('0x74')](_0x3acbe2[_0x17f514[_0x3fb2ef][_0xf8f9('0x73')]],'%s',_0x453f06):_0x453f06;_0x453f06=_0x17f514[_0x3fb2ef]['format']?_[_0xf8f9('0x74')](_0x23e8f5[_0x17f514[_0x3fb2ef][_0xf8f9('0x75')]],'%s',_0x453f06):_0x453f06;if(_0x17f514[_0x3fb2ef][_0xf8f9('0x76')]){_0x1870e1['group'](_0x453f06);}_0x17f514[_0x3fb2ef][_0xf8f9('0x77')]&&_0x1870e1[_0xf8f9('0x78')](_0x453f06,_0x17f514[_0x3fb2ef][_0xf8f9('0x77')]===_0xf8f9('0x79')?![]:!![]);_0x1870e1[_0xf8f9('0x66')](_0x453f06,_0x17f514[_0x3fb2ef]['alias']||_0x453f06);}if(_0x2056fb[_0xf8f9('0x7a')]){_0x2056fb[_0xf8f9('0x7a')]=JSON[_0xf8f9('0x7b')](_0x2056fb[_0xf8f9('0x7a')]);for(var _0x1ff154=0x0;_0x1ff154<_0x2056fb[_0xf8f9('0x7a')]['length'];_0x1ff154+=0x1){if(_0x2056fb[_0xf8f9('0x7a')][_0x1ff154][_0xf8f9('0x30')]&&_['includes'](_0x20f5f4,_0x2056fb[_0xf8f9('0x7a')][_0x1ff154][_0xf8f9('0x30')])&&_0x2056fb['joins'][_0x1ff154][_0xf8f9('0x7c')]&&_0x2056fb[_0xf8f9('0x7a')][_0x1ff154][_0xf8f9('0x7d')]&&_0x2056fb[_0xf8f9('0x7a')][_0x1ff154][_0xf8f9('0x7e')]){_0x1870e1[_0x2056fb[_0xf8f9('0x7a')][_0x1ff154]['type']](_0x2056fb[_0xf8f9('0x7a')][_0x1ff154][_0xf8f9('0x7d')],null,util[_0xf8f9('0x75')](_0xf8f9('0x7f'),_0x2056fb[_0xf8f9('0x70')],_0x2056fb['joins'][_0x1ff154][_0xf8f9('0x7c')],_0x2056fb[_0xf8f9('0x7a')][_0x1ff154][_0xf8f9('0x7d')],_0x2056fb[_0xf8f9('0x7a')][_0x1ff154][_0xf8f9('0x7e')]));}}}if(_0x2056fb[_0xf8f9('0x80')]){_0x2056fb[_0xf8f9('0x80')]=JSON[_0xf8f9('0x7b')](_0x2056fb[_0xf8f9('0x80')]);_0x1870e1[_0xf8f9('0x3a')](_0x43cb3c(_0x2056fb[_0xf8f9('0x80')][_0xf8f9('0x65')]));}_0xf2b36a=_0x1870e1[_0xf8f9('0x81')]();_0x1870e1[_0xf8f9('0x1f')](_0x119ef0);_0x1870e1['offset'](0x0);logger[_0xf8f9('0x82')](_0xf8f9('0x83'),_0x1870e1[_0xf8f9('0x84')]());return dbH[_0xf8f9('0x85')]['query'](_0x1870e1[_0xf8f9('0x84')](),{'type':dbH[_0xf8f9('0x85')]['QueryTypes'][_0xf8f9('0x86')]});}})[_0xf8f9('0x26')](respondWithResult(_0x59f784,null))[_0xf8f9('0x43')](handleError(_0x59f784,null));};function runReport(_0x3863e8,_0x1cdf63,_0x1d4dfb){var _0x2a54bd=_0x1cdf63[_0xf8f9('0x2c')];var _0x2a6077=0xa;var _0x429195=[_0xf8f9('0x52'),_0xf8f9('0x53'),_0xf8f9('0x87'),'cross_join'];var _0xa487e2={'SUM':_0xf8f9('0x55'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0xf8f9('0x57'),'MAX':_0xf8f9('0x58'),'MIN':_0xf8f9('0x88'),'AVG':_0xf8f9('0x89'),'GROUP_CONCAT':_0xf8f9('0x8a'),'GROUP_CONCAT ASC':_0xf8f9('0x59'),'GROUP_CONCAT DESC':_0xf8f9('0x5a')};var _0x577de6={'SEC_TO_TIME':_0xf8f9('0x5b'),'DATE':_0xf8f9('0x5c'),'HOUR':_0xf8f9('0x8b'),'ROUND':_0xf8f9('0x5d'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x2b5030=function(_0x2aa620){return!_['includes'](['IS\x20NULL',_0xf8f9('0x60'),'IS\x20EMPTY',_0xf8f9('0x62')],_0x2aa620);};var _0x1d6348=function(_0x41c11d){if(!_0x41c11d||!_0x41c11d['rules'][_0xf8f9('0x63')]){return'';}for(var _0x196a86='(',_0x53c32b=0x0;_0x53c32b<_0x41c11d[_0xf8f9('0x64')]['length'];_0x53c32b+=0x1){_0x53c32b>0x0&&(_0x196a86+='\x20'+_0x41c11d[_0xf8f9('0x8c')]+'\x20');_0x196a86+=_0x41c11d[_0xf8f9('0x64')][_0x53c32b][_0xf8f9('0x65')]?_0x1d6348(_0x41c11d['rules'][_0x53c32b][_0xf8f9('0x65')]):_0x41c11d['rules'][_0x53c32b][_0xf8f9('0x66')]+'\x20'+_0x41c11d[_0xf8f9('0x64')][_0x53c32b][_0xf8f9('0x67')]+(_0x2b5030(_0x41c11d[_0xf8f9('0x64')][_0x53c32b][_0xf8f9('0x67')])?'\x20'+_0x41c11d[_0xf8f9('0x64')][_0x53c32b][_0xf8f9('0x68')]:'');}return _0x196a86+')';};var _0x38f1fb={'where':{'id':_0x3863e8['id']}},_0x395ef1,_0x33252e,_0x46ffe4,_0x20ef5a,_0x108988;_0x38f1fb=_[_0xf8f9('0x3c')]({},_0x38f1fb,_0x1d4dfb);return db[_0xf8f9('0x2e')][_0xf8f9('0x47')](_0x38f1fb)['then'](function(_0x562719){if(_0x562719){_0x395ef1=_0x562719;return _0x562719[_0xf8f9('0x69')]();}return null;})['then'](function(_0x32af64){if(_0x32af64){if(!_0x32af64[_0xf8f9('0x63')]){throw new db['Sequelize']['ValidationErrorItem'](_0xf8f9('0x6c'),0x193);}_0x33252e=_0x32af64;return db[_0xf8f9('0x6d')][_0xf8f9('0x41')]({'raw':!![]});}return null;})[_0xf8f9('0x26')](function(_0x117c94){if(_0x117c94){_0x46ffe4=_[_0xf8f9('0x6e')](_0x117c94,'id');var _0x5588c9;var _0x43cf3b=squel['select']();_0x43cf3b['from'](_0x395ef1['table']);for(var _0x49e0dd=0x0;_0x49e0dd<_0x33252e[_0xf8f9('0x63')];_0x49e0dd+=0x1){_0x5588c9=_0x33252e[_0x49e0dd][_0xf8f9('0x71')]?_0x46ffe4[_0x33252e[_0x49e0dd]['MetricId']]['metric']:_0x33252e[_0x49e0dd][_0xf8f9('0x66')];_0x5588c9=_0x33252e[_0x49e0dd][_0xf8f9('0x73')]?_['replace'](_0xa487e2[_0x33252e[_0x49e0dd][_0xf8f9('0x73')]],'%s',_0x5588c9):_0x5588c9;_0x5588c9=_0x33252e[_0x49e0dd][_0xf8f9('0x75')]?_[_0xf8f9('0x74')](_0x577de6[_0x33252e[_0x49e0dd][_0xf8f9('0x75')]],'%s',_0x5588c9):_0x5588c9;if(_0x33252e[_0x49e0dd][_0xf8f9('0x76')]){_0x43cf3b[_0xf8f9('0x65')](_0x5588c9);}_0x33252e[_0x49e0dd]['orderBy']&&_0x43cf3b[_0xf8f9('0x78')](_0x5588c9,_0x33252e[_0x49e0dd][_0xf8f9('0x77')]===_0xf8f9('0x79')?![]:!![]);_0x43cf3b[_0xf8f9('0x66')](_0x5588c9,_0x33252e[_0x49e0dd][_0xf8f9('0x8d')]||_0x5588c9);}if(_0x395ef1[_0xf8f9('0x7a')]){_0x395ef1[_0xf8f9('0x7a')]=JSON[_0xf8f9('0x7b')](_0x395ef1['joins']);for(var _0x255cdb=0x0;_0x255cdb<_0x395ef1[_0xf8f9('0x7a')][_0xf8f9('0x63')];_0x255cdb+=0x1){if(_0x395ef1[_0xf8f9('0x7a')][_0x255cdb][_0xf8f9('0x30')]&&_['includes'](_0x429195,_0x395ef1[_0xf8f9('0x7a')][_0x255cdb][_0xf8f9('0x30')])&&_0x395ef1[_0xf8f9('0x7a')][_0x255cdb][_0xf8f9('0x7c')]&&_0x395ef1[_0xf8f9('0x7a')][_0x255cdb][_0xf8f9('0x7d')]&&_0x395ef1['joins'][_0x255cdb][_0xf8f9('0x7e')]){_0x43cf3b[_0x395ef1['joins'][_0x255cdb]['type']](_0x395ef1[_0xf8f9('0x7a')][_0x255cdb][_0xf8f9('0x7d')],null,util[_0xf8f9('0x75')](_0xf8f9('0x7f'),_0x395ef1[_0xf8f9('0x70')],_0x395ef1[_0xf8f9('0x7a')][_0x255cdb][_0xf8f9('0x7c')],_0x395ef1[_0xf8f9('0x7a')][_0x255cdb]['foreignTable'],_0x395ef1[_0xf8f9('0x7a')][_0x255cdb][_0xf8f9('0x7e')]));}}}if(_0x395ef1['conditions']){_0x395ef1[_0xf8f9('0x80')]=JSON[_0xf8f9('0x7b')](_0x395ef1[_0xf8f9('0x80')]);_0x43cf3b[_0xf8f9('0x3a')](_0x1d6348(_0x395ef1[_0xf8f9('0x80')][_0xf8f9('0x65')]));}_0x108988=_0x43cf3b[_0xf8f9('0x81')]();_0x43cf3b['limit'](_0x2a6077);_0x43cf3b['offset'](0x0);return;}})[_0xf8f9('0x26')](function(){if(_0x1cdf63['output']==='web'){return null;}var _0x6d23=_[_0xf8f9('0x3c')](_0x1cdf63,{'name':_0x1cdf63[_0xf8f9('0x8e')]||_0x1cdf63[_0xf8f9('0x2c')]||_0x395ef1['name'],'basename':_0x2a54bd,'savename':util[_0xf8f9('0x75')](_0xf8f9('0x8f'),_0x1cdf63['name']||_0x395ef1[_0xf8f9('0x2c')],require(_0xf8f9('0x90'))['generate'](0x4),_0x1cdf63[_0xf8f9('0x91')]||_0xf8f9('0x92')),'reportId':_0x395ef1['id'],'reportType':_0xf8f9('0x93')});return db[_0xf8f9('0x94')][_0xf8f9('0x48')](_0x6d23,{'raw':!![]});})[_0xf8f9('0x26')](function(_0x57b2d5){if(_0x395ef1[_0xf8f9('0x70')]===_0xf8f9('0x95')){_0x108988[_0xf8f9('0x3a')](_0x395ef1[_0xf8f9('0x70')]+_0xf8f9('0x96'),_0x1cdf63[_0xf8f9('0x97')],_0x1cdf63['endDate']);}else{_0x108988[_0xf8f9('0x3a')](_0x395ef1[_0xf8f9('0x70')]+_0xf8f9('0x98'),_0x1cdf63[_0xf8f9('0x97')],_0x1cdf63[_0xf8f9('0x99')]);}if(_0x57b2d5){logger['info'](_0xf8f9('0x9a'),_0x108988[_0xf8f9('0x84')]());require(_0xf8f9('0x9b'))[_0xf8f9('0x9c')](path['join'](__dirname,_0xf8f9('0x9d'),_0x57b2d5[_0xf8f9('0x91')]),[_0x57b2d5['id'],_0x108988[_0xf8f9('0x84')](),path['join'](__dirname,_0xf8f9('0x9e'),_0x57b2d5[_0xf8f9('0x9f')]),_0x2a54bd]);return _0x57b2d5;}else{var _0x4e7bd9=squel['select']();_0x4e7bd9['from']('('+_0x108988[_0xf8f9('0x84')]()+')',_0xf8f9('0xa0'));_0x4e7bd9[_0xf8f9('0x66')](_0xf8f9('0xa1'),_0xf8f9('0x20'));_0x108988[_0xf8f9('0x1f')](_0x1cdf63['limit']||_0x2a6077);_0x108988[_0xf8f9('0x21')](_0x1cdf63[_0xf8f9('0x21')]||0x0);return dbH[_0xf8f9('0x85')][_0xf8f9('0x32')](_0x4e7bd9['toString'](),{'type':dbH[_0xf8f9('0x85')][_0xf8f9('0xa2')][_0xf8f9('0x86')]})['then'](function(_0x4d201d){if(!_0x4d201d[_0xf8f9('0x63')]){_0x20ef5a=0x0;}else{_0x20ef5a=_0x4d201d[0x0]['count']||0x0;}return dbH[_0xf8f9('0x85')][_0xf8f9('0x32')](_0x108988[_0xf8f9('0x84')](),{'type':dbH[_0xf8f9('0x85')][_0xf8f9('0xa2')][_0xf8f9('0x86')]});})[_0xf8f9('0x26')](function(_0x26fe44){return{'rows':_0x26fe44||[],'count':_0x20ef5a};});}});}exports[_0xf8f9('0xa3')]=function(_0x22cf7d,_0x132505){return runReport(_0x22cf7d[_0xf8f9('0x45')],_0x22cf7d['query'],_0x22cf7d[_0xf8f9('0x3e')])['then'](respondWithResult(_0x132505,null))[_0xf8f9('0x43')](handleError(_0x132505,null));};exports['runReport']=runReport;exports['query']=function(_0x527cef,_0x5aee0e){var _0x32e5f2=0xa;var _0x19fede=['join',_0xf8f9('0x53'),_0xf8f9('0x87'),'cross_join'];var _0x1c7a4c={'SUM':_0xf8f9('0x55'),'COUNT':_0xf8f9('0x56'),'COUNT DISTINCT':_0xf8f9('0x57'),'MAX':_0xf8f9('0x58'),'MIN':_0xf8f9('0x88'),'AVG':_0xf8f9('0x89'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0xf8f9('0x59'),'GROUP_CONCAT DESC':_0xf8f9('0x5a')};var _0x1c7d26={'SEC_TO_TIME':_0xf8f9('0x5b'),'DATE':'DATE(%s)','HOUR':_0xf8f9('0x8b'),'ROUND':_0xf8f9('0x5d'),'UNIX_TIMESTAMP':_0xf8f9('0x5e')};var _0xcbceae=function(_0x47f5eb){return!_[_0xf8f9('0x5f')]([_0xf8f9('0xa4'),_0xf8f9('0x60'),'IS\x20EMPTY','IS\x20NOT\x20EMPTY'],_0x47f5eb);};var _0x1b4b8a=function(_0x1204c5){if(!_0x1204c5||!_0x1204c5['rules'][_0xf8f9('0x63')]){return'';}for(var _0x5b89ab='(',_0x1004d1=0x0;_0x1004d1<_0x1204c5[_0xf8f9('0x64')][_0xf8f9('0x63')];_0x1004d1+=0x1){_0x1004d1>0x0&&(_0x5b89ab+='\x20'+_0x1204c5[_0xf8f9('0x8c')]+'\x20');_0x5b89ab+=_0x1204c5[_0xf8f9('0x64')][_0x1004d1][_0xf8f9('0x65')]?_0x1b4b8a(_0x1204c5[_0xf8f9('0x64')][_0x1004d1]['group']):_0x1204c5['rules'][_0x1004d1]['field']+'\x20'+_0x1204c5[_0xf8f9('0x64')][_0x1004d1][_0xf8f9('0x67')]+(_0xcbceae(_0x1204c5['rules'][_0x1004d1][_0xf8f9('0x67')])?'\x20'+_0x1204c5[_0xf8f9('0x64')][_0x1004d1][_0xf8f9('0x68')]:'');}return _0x5b89ab+')';};var _0x5a931f={'where':{'id':_0x527cef['params']['id']}},_0xbb8bff,_0x399567,_0x154544,_0x24e36d,_0xde61b8;_0x5a931f=_[_0xf8f9('0x3c')]({},_0x5a931f,_0x527cef[_0xf8f9('0x3e')]);return db[_0xf8f9('0x2e')]['find'](_0x5a931f)[_0xf8f9('0x26')](function(_0x1d4392){if(_0x1d4392){_0xbb8bff=_0x1d4392;return _0x1d4392[_0xf8f9('0x69')]();}return null;})[_0xf8f9('0x26')](function(_0x7b6c8b){if(_0x7b6c8b){if(!_0x7b6c8b[_0xf8f9('0x63')]){throw new db[(_0xf8f9('0x6a'))][(_0xf8f9('0x6b'))](_0xf8f9('0x6c'),0x193);}_0x399567=_0x7b6c8b;return db[_0xf8f9('0x6d')][_0xf8f9('0x41')]({'raw':!![]});}return null;})[_0xf8f9('0x26')](function(_0x4a251a){if(_0x4a251a){_0x154544=_['keyBy'](_0x4a251a,'id');var _0x3f75ca;var _0x295623=squel['select']();_0x295623[_0xf8f9('0x6f')](_0xbb8bff['table']);for(var _0xe0e087=0x0;_0xe0e087<_0x399567[_0xf8f9('0x63')];_0xe0e087+=0x1){_0x3f75ca=_0x399567[_0xe0e087][_0xf8f9('0x71')]?_0x154544[_0x399567[_0xe0e087][_0xf8f9('0x71')]][_0xf8f9('0x72')]:_0x399567[_0xe0e087][_0xf8f9('0x66')];_0x3f75ca=_0x399567[_0xe0e087][_0xf8f9('0x73')]?_[_0xf8f9('0x74')](_0x1c7a4c[_0x399567[_0xe0e087][_0xf8f9('0x73')]],'%s',_0x3f75ca):_0x3f75ca;_0x3f75ca=_0x399567[_0xe0e087][_0xf8f9('0x75')]?_[_0xf8f9('0x74')](_0x1c7d26[_0x399567[_0xe0e087]['format']],'%s',_0x3f75ca):_0x3f75ca;if(_0x399567[_0xe0e087][_0xf8f9('0x76')]){_0x295623[_0xf8f9('0x65')](_0x3f75ca);}_0x399567[_0xe0e087]['orderBy']&&_0x295623[_0xf8f9('0x78')](_0x3f75ca,_0x399567[_0xe0e087][_0xf8f9('0x77')]===_0xf8f9('0x79')?![]:!![]);_0x295623[_0xf8f9('0x66')](_0x3f75ca,_0x399567[_0xe0e087][_0xf8f9('0x8d')]||_0x3f75ca);}if(_0xbb8bff[_0xf8f9('0x7a')]){_0xbb8bff[_0xf8f9('0x7a')]=JSON[_0xf8f9('0x7b')](_0xbb8bff[_0xf8f9('0x7a')]);for(var _0x535c7e=0x0;_0x535c7e<_0xbb8bff[_0xf8f9('0x7a')]['length'];_0x535c7e+=0x1){if(_0xbb8bff[_0xf8f9('0x7a')][_0x535c7e]['type']&&_['includes'](_0x19fede,_0xbb8bff[_0xf8f9('0x7a')][_0x535c7e][_0xf8f9('0x30')])&&_0xbb8bff[_0xf8f9('0x7a')][_0x535c7e][_0xf8f9('0x7c')]&&_0xbb8bff['joins'][_0x535c7e][_0xf8f9('0x7d')]&&_0xbb8bff[_0xf8f9('0x7a')][_0x535c7e][_0xf8f9('0x7e')]){_0x295623[_0xbb8bff[_0xf8f9('0x7a')][_0x535c7e][_0xf8f9('0x30')]](_0xbb8bff[_0xf8f9('0x7a')][_0x535c7e][_0xf8f9('0x7d')],null,util[_0xf8f9('0x75')](_0xf8f9('0x7f'),_0xbb8bff['table'],_0xbb8bff['joins'][_0x535c7e]['parentKey'],_0xbb8bff[_0xf8f9('0x7a')][_0x535c7e][_0xf8f9('0x7d')],_0xbb8bff['joins'][_0x535c7e][_0xf8f9('0x7e')]));}}}if(_0xbb8bff[_0xf8f9('0x80')]){_0xbb8bff[_0xf8f9('0x80')]=JSON[_0xf8f9('0x7b')](_0xbb8bff[_0xf8f9('0x80')]);_0x295623[_0xf8f9('0x3a')](_0x1b4b8a(_0xbb8bff[_0xf8f9('0x80')][_0xf8f9('0x65')]));}_0xde61b8=_0x295623[_0xf8f9('0x81')]();_0x295623[_0xf8f9('0x1f')](_0x32e5f2);_0x295623[_0xf8f9('0x21')](0x0);logger[_0xf8f9('0x82')](_0xf8f9('0x83'),_0x295623[_0xf8f9('0x84')]());return dbH['sequelize']['query'](_0x295623[_0xf8f9('0x84')](),{'type':dbH[_0xf8f9('0x85')][_0xf8f9('0xa2')][_0xf8f9('0x86')]});}})[_0xf8f9('0x26')](function(){return{'sql':_0xde61b8[_0xf8f9('0x84')]()};})[_0xf8f9('0x26')](respondWithResult(_0x5aee0e,null))[_0xf8f9('0x43')](handleError(_0x5aee0e,null));};
\ No newline at end of file
+var _0x4c5a=['filters','intersection','fields','attributes','hasOwnProperty','nolimit','limit','order','sort','where','pick','merge','type','options','AnalyticCustomReport','includeAll','include','findAll','rows','keys','length','find','catch','create','body','user','role','get','Reports','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','preview','join','right_join','cross_join','SUM(%s)','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)','DATE(%s)','HOUR(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20NOT\x20EMPTY','rules','group','field','condition','getFields','Sequelize','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','from','MetricId','function','replace','format','groupBy','orderBy','DESC','alias','joins','parse','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','parentKey','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','left_join','SEC_TO_TIME(%s)','ROUND(%s)','IS\x20EMPTY','operator','ValidationErrorItem','select','table','metric','output','fullPath','%s-%s.%s','randomstring','generate','csv','custom','AnalyticExtractedReport','cdr','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','child_process','../../files/reports','savename','countTable','COUNT(*)','SELECT','run','runReport','value','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','json','offset','undefined','count','set','Content-Range','reject','update','destroy','UserProfileResource','then','end','name','send','index','map','rawAttributes','fieldName','key','model','query'];(function(_0x3d2534,_0x4d5dcc){var _0x3f38c0=function(_0x51d1f6){while(--_0x51d1f6){_0x3d2534['push'](_0x3d2534['shift']());}};_0x3f38c0(++_0x4d5dcc);}(_0x4c5a,0x1c0));var _0xa4c5=function(_0x1c2ad4,_0x42b3bb){_0x1c2ad4=_0x1c2ad4-0x0;var _0x129a4e=_0x4c5a[_0x1c2ad4];return _0x129a4e;};'use strict';var emlformat=require(_0xa4c5('0x0'));var rimraf=require(_0xa4c5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xa4c5('0x2'));var rp=require(_0xa4c5('0x3'));var moment=require('moment');var BPromise=require(_0xa4c5('0x4'));var Mustache=require(_0xa4c5('0x5'));var util=require('util');var path=require(_0xa4c5('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xa4c5('0x7'));var fs=require('fs');var fs_extra=require(_0xa4c5('0x8'));var _=require(_0xa4c5('0x9'));var squel=require(_0xa4c5('0xa'));var crypto=require('crypto');var jsforce=require(_0xa4c5('0xb'));var deskjs=require(_0xa4c5('0xc'));var toCsv=require(_0xa4c5('0xd'));var querystring=require(_0xa4c5('0xe'));var Papa=require('papaparse');var Redis=require(_0xa4c5('0xf'));var authService=require(_0xa4c5('0x10'));var qs=require(_0xa4c5('0x11'));var as=require(_0xa4c5('0x12'));var hardwareService=require(_0xa4c5('0x13'));var logger=require(_0xa4c5('0x14'))(_0xa4c5('0x15'));var utils=require(_0xa4c5('0x16'));var config=require(_0xa4c5('0x17'));var licenseUtil=require(_0xa4c5('0x18'));var db=require(_0xa4c5('0x19'))['db'];var dbH=require('../../mysqldb')[_0xa4c5('0x1a')];function respondWithStatusCode(_0x1ee5b6,_0x405327){_0x405327=_0x405327||0xcc;return function(_0x73d01c){if(_0x73d01c){return _0x1ee5b6[_0xa4c5('0x1b')](_0x405327);}return _0x1ee5b6[_0xa4c5('0x1c')](_0x405327)['end']();};}function respondWithResult(_0x44c912,_0x4dcc51){_0x4dcc51=_0x4dcc51||0xc8;return function(_0x29fbf7){if(_0x29fbf7){return _0x44c912['status'](_0x4dcc51)[_0xa4c5('0x1d')](_0x29fbf7);}};}function respondWithFilteredResult(_0x47bc0c,_0x2b4099){return function(_0x2a4950){if(_0x2a4950){var _0xad448f=typeof _0x2b4099[_0xa4c5('0x1e')]===_0xa4c5('0x1f')&&typeof _0x2b4099['limit']===_0xa4c5('0x1f');var _0x3daeab=_0x2a4950[_0xa4c5('0x20')];var _0x5769d8=_0xad448f?0x0:_0x2b4099['offset'];var _0x6c85b2=_0xad448f?_0x2a4950[_0xa4c5('0x20')]:_0x2b4099[_0xa4c5('0x1e')]+_0x2b4099['limit'];var _0x379fc2;if(_0x6c85b2>=_0x3daeab){_0x6c85b2=_0x3daeab;_0x379fc2=0xc8;}else{_0x379fc2=0xce;}_0x47bc0c[_0xa4c5('0x1c')](_0x379fc2);return _0x47bc0c[_0xa4c5('0x21')](_0xa4c5('0x22'),_0x5769d8+'-'+_0x6c85b2+'/'+_0x3daeab)[_0xa4c5('0x1d')](_0x2a4950);}return null;};}function patchUpdates(_0x4890c1){return function(_0x109546){try{jsonpatch['apply'](_0x109546,_0x4890c1,!![]);}catch(_0x547c2a){return BPromise[_0xa4c5('0x23')](_0x547c2a);}return _0x109546['save']();};}function saveUpdates(_0x47fd8e,_0x565c99){return function(_0x15fdd2){if(_0x15fdd2){return _0x15fdd2[_0xa4c5('0x24')](_0x47fd8e)['then'](function(_0x4aa906){return _0x4aa906;});}return null;};}function removeEntity(_0x287d99,_0x5de749){return function(_0x129d79){if(_0x129d79){return _0x129d79[_0xa4c5('0x25')]()['then'](function(){var _0x5acedf=_0x129d79['get']({'plain':!![]});var _0xdcf314='CustomReports';return db[_0xa4c5('0x26')]['destroy']({'where':{'type':_0xdcf314,'resourceId':_0x5acedf['id']}})[_0xa4c5('0x27')](function(){return _0x129d79;});})[_0xa4c5('0x27')](function(){_0x287d99['status'](0xcc)[_0xa4c5('0x28')]();});}};}function handleEntityNotFound(_0x56ab35,_0x8a4c13){return function(_0x1106f1){if(!_0x1106f1){_0x56ab35[_0xa4c5('0x1b')](0x194);}return _0x1106f1;};}function handleError(_0x38a3cc,_0x4b5620){_0x4b5620=_0x4b5620||0x1f4;return function(_0x271706){logger['error'](_0x271706['stack']);if(_0x271706[_0xa4c5('0x29')]){delete _0x271706[_0xa4c5('0x29')];}_0x38a3cc[_0xa4c5('0x1c')](_0x4b5620)[_0xa4c5('0x2a')](_0x271706);};}exports[_0xa4c5('0x2b')]=function(_0x281754,_0x1b57c9){var _0x57abe3={},_0x40c039={},_0xe6993f={'count':0x0,'rows':[]};var _0x21051e=_[_0xa4c5('0x2c')](db['AnalyticCustomReport'][_0xa4c5('0x2d')],function(_0x287257){return{'name':_0x287257[_0xa4c5('0x2e')],'type':_0x287257['type'][_0xa4c5('0x2f')]};});_0x40c039[_0xa4c5('0x30')]=_['map'](_0x21051e,'name');_0x40c039[_0xa4c5('0x31')]=_['keys'](_0x281754[_0xa4c5('0x31')]);_0x40c039[_0xa4c5('0x32')]=_[_0xa4c5('0x33')](_0x40c039['model'],_0x40c039['query']);_0x57abe3['attributes']=_[_0xa4c5('0x33')](_0x40c039[_0xa4c5('0x30')],qs[_0xa4c5('0x34')](_0x281754[_0xa4c5('0x31')][_0xa4c5('0x34')]));_0x57abe3[_0xa4c5('0x35')]=_0x57abe3[_0xa4c5('0x35')]['length']?_0x57abe3[_0xa4c5('0x35')]:_0x40c039[_0xa4c5('0x30')];if(!_0x281754['query'][_0xa4c5('0x36')](_0xa4c5('0x37'))){_0x57abe3[_0xa4c5('0x38')]=qs[_0xa4c5('0x38')](_0x281754[_0xa4c5('0x31')]['limit']);_0x57abe3[_0xa4c5('0x1e')]=qs[_0xa4c5('0x1e')](_0x281754['query']['offset']);}_0x57abe3[_0xa4c5('0x39')]=qs[_0xa4c5('0x3a')](_0x281754[_0xa4c5('0x31')][_0xa4c5('0x3a')]);_0x57abe3[_0xa4c5('0x3b')]=qs[_0xa4c5('0x32')](_[_0xa4c5('0x3c')](_0x281754['query'],_0x40c039[_0xa4c5('0x32')]),_0x21051e);if(_0x281754[_0xa4c5('0x31')]['filter']){_0x57abe3[_0xa4c5('0x3b')]=_[_0xa4c5('0x3d')](_0x57abe3[_0xa4c5('0x3b')],{'$or':_[_0xa4c5('0x2c')](_0x21051e,function(_0x568c4d){if(_0x568c4d[_0xa4c5('0x3e')]!=='VIRTUAL'){var _0x2363fd={};_0x2363fd[_0x568c4d['name']]={'$like':'%'+_0x281754[_0xa4c5('0x31')]['filter']+'%'};return _0x2363fd;}})});}_0x57abe3=_[_0xa4c5('0x3d')]({},_0x57abe3,_0x281754[_0xa4c5('0x3f')]);var _0x1a9bb3={'where':_0x57abe3[_0xa4c5('0x3b')]};return db[_0xa4c5('0x40')]['count'](_0x1a9bb3)[_0xa4c5('0x27')](function(_0x588e84){_0xe6993f[_0xa4c5('0x20')]=_0x588e84;if(_0x281754[_0xa4c5('0x31')][_0xa4c5('0x41')]){_0x57abe3[_0xa4c5('0x42')]=[{'all':!![]}];}return db['AnalyticCustomReport'][_0xa4c5('0x43')](_0x57abe3);})['then'](function(_0x410fde){_0xe6993f[_0xa4c5('0x44')]=_0x410fde;return _0xe6993f;})['then'](respondWithFilteredResult(_0x1b57c9,_0x57abe3))['catch'](handleError(_0x1b57c9,null));};exports['show']=function(_0x448cca,_0x40618f){var _0xadf767={'raw':![],'where':{'id':_0x448cca['params']['id']}},_0xe8ed15={};_0xe8ed15[_0xa4c5('0x30')]=_[_0xa4c5('0x45')](db['AnalyticCustomReport']['rawAttributes']);_0xe8ed15['query']=_[_0xa4c5('0x45')](_0x448cca[_0xa4c5('0x31')]);_0xe8ed15[_0xa4c5('0x32')]=_['intersection'](_0xe8ed15['model'],_0xe8ed15[_0xa4c5('0x31')]);_0xadf767['attributes']=_[_0xa4c5('0x33')](_0xe8ed15['model'],qs[_0xa4c5('0x34')](_0x448cca[_0xa4c5('0x31')][_0xa4c5('0x34')]));_0xadf767[_0xa4c5('0x35')]=_0xadf767[_0xa4c5('0x35')][_0xa4c5('0x46')]?_0xadf767[_0xa4c5('0x35')]:_0xe8ed15['model'];if(_0x448cca[_0xa4c5('0x31')]['includeAll']){_0xadf767['include']=[{'all':!![]}];}_0xadf767=_['merge']({},_0xadf767,_0x448cca[_0xa4c5('0x3f')]);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0xadf767)['then'](handleEntityNotFound(_0x40618f,null))['then'](respondWithResult(_0x40618f,null))[_0xa4c5('0x48')](handleError(_0x40618f,null));};exports[_0xa4c5('0x49')]=function(_0x353496,_0x4e2503){return db[_0xa4c5('0x40')][_0xa4c5('0x49')](_0x353496[_0xa4c5('0x4a')],{})[_0xa4c5('0x27')](function(_0x1dcbcf){var _0x393ef7=_0x353496[_0xa4c5('0x4b')]['get']({'plain':!![]});if(!_0x393ef7)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x393ef7[_0xa4c5('0x4c')]==='user'){var _0x4a084e=_0x1dcbcf[_0xa4c5('0x4d')]({'plain':!![]});var _0x16a54c=_0xa4c5('0x4e');return db[_0xa4c5('0x4f')][_0xa4c5('0x47')]({'where':{'name':_0x16a54c,'userProfileId':_0x393ef7[_0xa4c5('0x50')]},'raw':!![]})[_0xa4c5('0x27')](function(_0x351215){if(_0x351215&&_0x351215[_0xa4c5('0x51')]===0x0){return db[_0xa4c5('0x26')][_0xa4c5('0x49')]({'name':_0x4a084e['name'],'resourceId':_0x4a084e['id'],'type':'CustomReports','sectionId':_0x351215['id']},{})[_0xa4c5('0x27')](function(){return _0x1dcbcf;});}else{return _0x1dcbcf;}})[_0xa4c5('0x48')](function(_0x5a0b2d){logger[_0xa4c5('0x52')](_0xa4c5('0x53'),_0x5a0b2d);throw _0x5a0b2d;});}return _0x1dcbcf;})[_0xa4c5('0x27')](respondWithResult(_0x4e2503,0xc9))[_0xa4c5('0x48')](handleError(_0x4e2503,null));};exports[_0xa4c5('0x24')]=function(_0x47c018,_0x419bb2){if(_0x47c018['body']['id']){delete _0x47c018[_0xa4c5('0x4a')]['id'];}return db[_0xa4c5('0x40')]['find']({'where':{'id':_0x47c018[_0xa4c5('0x54')]['id']}})['then'](handleEntityNotFound(_0x419bb2,null))['then'](saveUpdates(_0x47c018[_0xa4c5('0x4a')],null))[_0xa4c5('0x27')](respondWithResult(_0x419bb2,null))[_0xa4c5('0x48')](handleError(_0x419bb2,null));};exports['destroy']=function(_0x50f370,_0x774ce6){return db[_0xa4c5('0x40')]['find']({'where':{'id':_0x50f370[_0xa4c5('0x54')]['id']}})[_0xa4c5('0x27')](handleEntityNotFound(_0x774ce6,null))[_0xa4c5('0x27')](removeEntity(_0x774ce6,null))[_0xa4c5('0x48')](handleError(_0x774ce6,null));};exports[_0xa4c5('0x55')]=function(_0x274cb4,_0x5c9bdc){var _0x2ff696=0xa;var _0x568766=[_0xa4c5('0x56'),'left_join',_0xa4c5('0x57'),_0xa4c5('0x58')];var _0x31c37a={'SUM':_0xa4c5('0x59'),'COUNT':_0xa4c5('0x5a'),'COUNT DISTINCT':_0xa4c5('0x5b'),'MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':_0xa4c5('0x5d'),'GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':_0xa4c5('0x5f'),'GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0xd2a4f2={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xa4c5('0x63')};var _0x7dd707=function(_0xe85930){return!_[_0xa4c5('0x64')]([_0xa4c5('0x65'),_0xa4c5('0x66'),'IS\x20EMPTY',_0xa4c5('0x67')],_0xe85930);};var _0x135bba=function(_0x27ad75){if(!_0x27ad75||!_0x27ad75[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0xe4b3f4='(',_0x5386b9=0x0;_0x5386b9<_0x27ad75[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x5386b9+=0x1){_0x5386b9>0x0&&(_0xe4b3f4+='\x20'+_0x27ad75['operator']+'\x20');_0xe4b3f4+=_0x27ad75['rules'][_0x5386b9][_0xa4c5('0x69')]?_0x135bba(_0x27ad75[_0xa4c5('0x68')][_0x5386b9][_0xa4c5('0x69')]):_0x27ad75['rules'][_0x5386b9][_0xa4c5('0x6a')]+'\x20'+_0x27ad75[_0xa4c5('0x68')][_0x5386b9]['condition']+(_0x7dd707(_0x27ad75[_0xa4c5('0x68')][_0x5386b9][_0xa4c5('0x6b')])?'\x20'+_0x27ad75['rules'][_0x5386b9]['value']:'');}return _0xe4b3f4+')';};var _0x141a95={'where':{'id':_0x274cb4[_0xa4c5('0x54')]['id']}},_0x1449ae,_0x5ae88e,_0x128805,_0x1e5cf8,_0x54efe4;_0x141a95=_[_0xa4c5('0x3d')]({},_0x141a95,_0x274cb4[_0xa4c5('0x3f')]);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0x141a95)[_0xa4c5('0x27')](function(_0x2ff202){if(_0x2ff202){_0x1449ae=_0x2ff202;return _0x2ff202[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x4d1551){if(_0x4d1551){if(!_0x4d1551[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))]['ValidationErrorItem'](_0xa4c5('0x6e'),0x193);}_0x5ae88e=_0x4d1551;return db[_0xa4c5('0x6f')][_0xa4c5('0x43')]({'raw':!![]});}return null;})[_0xa4c5('0x27')](function(_0x5c19d4){if(_0x5c19d4){_0x128805=_[_0xa4c5('0x70')](_0x5c19d4,'id');var _0x1da8b7;var _0x4c7b6e=squel['select']();_0x4c7b6e[_0xa4c5('0x71')](_0x1449ae['table']);for(var _0xf299ba=0x0;_0xf299ba<_0x5ae88e[_0xa4c5('0x46')];_0xf299ba+=0x1){_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x72')]?_0x128805[_0x5ae88e[_0xf299ba][_0xa4c5('0x72')]]['metric']:_0x5ae88e[_0xf299ba]['field'];_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x31c37a[_0x5ae88e[_0xf299ba][_0xa4c5('0x73')]],'%s',_0x1da8b7):_0x1da8b7;_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0xd2a4f2[_0x5ae88e[_0xf299ba][_0xa4c5('0x75')]],'%s',_0x1da8b7):_0x1da8b7;if(_0x5ae88e[_0xf299ba][_0xa4c5('0x76')]){_0x4c7b6e[_0xa4c5('0x69')](_0x1da8b7);}_0x5ae88e[_0xf299ba][_0xa4c5('0x77')]&&_0x4c7b6e['order'](_0x1da8b7,_0x5ae88e[_0xf299ba][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x4c7b6e[_0xa4c5('0x6a')](_0x1da8b7,_0x5ae88e[_0xf299ba][_0xa4c5('0x79')]||_0x1da8b7);}if(_0x1449ae[_0xa4c5('0x7a')]){_0x1449ae['joins']=JSON[_0xa4c5('0x7b')](_0x1449ae[_0xa4c5('0x7a')]);for(var _0x3d357d=0x0;_0x3d357d<_0x1449ae['joins'][_0xa4c5('0x46')];_0x3d357d+=0x1){if(_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x568766,_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x3e')])&&_0x1449ae[_0xa4c5('0x7a')][_0x3d357d]['parentKey']&&_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7c')]&&_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7d')]){_0x4c7b6e[_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x3e')]](_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')](_0xa4c5('0x7e'),_0x1449ae['table'],_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7f')],_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x7c')],_0x1449ae['joins'][_0x3d357d]['foreignKey']));}}}if(_0x1449ae['conditions']){_0x1449ae[_0xa4c5('0x80')]=JSON['parse'](_0x1449ae[_0xa4c5('0x80')]);_0x4c7b6e[_0xa4c5('0x3b')](_0x135bba(_0x1449ae[_0xa4c5('0x80')]['group']));}_0x54efe4=_0x4c7b6e[_0xa4c5('0x81')]();_0x4c7b6e['limit'](_0x2ff696);_0x4c7b6e[_0xa4c5('0x1e')](0x0);logger[_0xa4c5('0x82')](_0xa4c5('0x83'),_0x4c7b6e[_0xa4c5('0x84')]());return dbH['sequelize'][_0xa4c5('0x31')](_0x4c7b6e['toString'](),{'type':dbH[_0xa4c5('0x85')][_0xa4c5('0x86')]['SELECT']});}})[_0xa4c5('0x27')](respondWithResult(_0x5c9bdc,null))[_0xa4c5('0x48')](handleError(_0x5c9bdc,null));};function runReport(_0x129780,_0x470a0b,_0x7c17d8){var _0x114f35=_0x470a0b[_0xa4c5('0x29')];var _0x40c2af=0xa;var _0x14f818=[_0xa4c5('0x56'),_0xa4c5('0x87'),_0xa4c5('0x57'),'cross_join'];var _0x2264b0={'SUM':_0xa4c5('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0xa4c5('0x5b'),'MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':_0xa4c5('0x5d'),'GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0x15f9f5={'SEC_TO_TIME':_0xa4c5('0x88'),'DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':_0xa4c5('0x89'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x2a5209=function(_0x46318b){return!_['includes'](['IS\x20NULL',_0xa4c5('0x66'),_0xa4c5('0x8a'),_0xa4c5('0x67')],_0x46318b);};var _0x160424=function(_0x33e58b){if(!_0x33e58b||!_0x33e58b[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0x4ee1f7='(',_0x382c64=0x0;_0x382c64<_0x33e58b[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x382c64+=0x1){_0x382c64>0x0&&(_0x4ee1f7+='\x20'+_0x33e58b[_0xa4c5('0x8b')]+'\x20');_0x4ee1f7+=_0x33e58b['rules'][_0x382c64][_0xa4c5('0x69')]?_0x160424(_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x69')]):_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6a')]+'\x20'+_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6b')]+(_0x2a5209(_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6b')])?'\x20'+_0x33e58b[_0xa4c5('0x68')][_0x382c64]['value']:'');}return _0x4ee1f7+')';};var _0x3f7df6={'where':{'id':_0x129780['id']}},_0x5d8983,_0x8de116,_0x4a911f,_0x4fca6b,_0x33212a;_0x3f7df6=_['merge']({},_0x3f7df6,_0x7c17d8);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0x3f7df6)[_0xa4c5('0x27')](function(_0x13b9a0){if(_0x13b9a0){_0x5d8983=_0x13b9a0;return _0x13b9a0[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x3b7847){if(_0x3b7847){if(!_0x3b7847[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))][(_0xa4c5('0x8c'))](_0xa4c5('0x6e'),0x193);}_0x8de116=_0x3b7847;return db[_0xa4c5('0x6f')][_0xa4c5('0x43')]({'raw':!![]});}return null;})['then'](function(_0x3315c6){if(_0x3315c6){_0x4a911f=_[_0xa4c5('0x70')](_0x3315c6,'id');var _0x2ee764;var _0x11735c=squel[_0xa4c5('0x8d')]();_0x11735c['from'](_0x5d8983[_0xa4c5('0x8e')]);for(var _0xe1055=0x0;_0xe1055<_0x8de116[_0xa4c5('0x46')];_0xe1055+=0x1){_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x72')]?_0x4a911f[_0x8de116[_0xe1055][_0xa4c5('0x72')]][_0xa4c5('0x8f')]:_0x8de116[_0xe1055][_0xa4c5('0x6a')];_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x2264b0[_0x8de116[_0xe1055][_0xa4c5('0x73')]],'%s',_0x2ee764):_0x2ee764;_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0x15f9f5[_0x8de116[_0xe1055]['format']],'%s',_0x2ee764):_0x2ee764;if(_0x8de116[_0xe1055][_0xa4c5('0x76')]){_0x11735c[_0xa4c5('0x69')](_0x2ee764);}_0x8de116[_0xe1055][_0xa4c5('0x77')]&&_0x11735c['order'](_0x2ee764,_0x8de116[_0xe1055][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x11735c[_0xa4c5('0x6a')](_0x2ee764,_0x8de116[_0xe1055][_0xa4c5('0x79')]||_0x2ee764);}if(_0x5d8983[_0xa4c5('0x7a')]){_0x5d8983[_0xa4c5('0x7a')]=JSON['parse'](_0x5d8983[_0xa4c5('0x7a')]);for(var _0x512de7=0x0;_0x512de7<_0x5d8983[_0xa4c5('0x7a')][_0xa4c5('0x46')];_0x512de7+=0x1){if(_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x14f818,_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x3e')])&&_0x5d8983['joins'][_0x512de7]['parentKey']&&_0x5d8983['joins'][_0x512de7]['foreignTable']&&_0x5d8983['joins'][_0x512de7][_0xa4c5('0x7d')]){_0x11735c[_0x5d8983[_0xa4c5('0x7a')][_0x512de7]['type']](_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')](_0xa4c5('0x7e'),_0x5d8983[_0xa4c5('0x8e')],_0x5d8983['joins'][_0x512de7]['parentKey'],_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7c')],_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7d')]));}}}if(_0x5d8983[_0xa4c5('0x80')]){_0x5d8983[_0xa4c5('0x80')]=JSON['parse'](_0x5d8983[_0xa4c5('0x80')]);_0x11735c[_0xa4c5('0x3b')](_0x160424(_0x5d8983[_0xa4c5('0x80')][_0xa4c5('0x69')]));}_0x33212a=_0x11735c['clone']();_0x11735c[_0xa4c5('0x38')](_0x40c2af);_0x11735c[_0xa4c5('0x1e')](0x0);return;}})['then'](function(){if(_0x470a0b[_0xa4c5('0x90')]==='web'){return null;}var _0x5a43a3=_[_0xa4c5('0x3d')](_0x470a0b,{'name':_0x470a0b[_0xa4c5('0x91')]||_0x470a0b['name']||_0x5d8983['name'],'basename':_0x114f35,'savename':util[_0xa4c5('0x75')](_0xa4c5('0x92'),_0x470a0b['name']||_0x5d8983['name'],require(_0xa4c5('0x93'))[_0xa4c5('0x94')](0x4),_0x470a0b['output']||_0xa4c5('0x95')),'reportId':_0x5d8983['id'],'reportType':_0xa4c5('0x96')});return db[_0xa4c5('0x97')][_0xa4c5('0x49')](_0x5a43a3,{'raw':!![]});})['then'](function(_0x33d8b2){if(_0x5d8983[_0xa4c5('0x8e')]===_0xa4c5('0x98')){_0x33212a[_0xa4c5('0x3b')](_0x5d8983[_0xa4c5('0x8e')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x470a0b[_0xa4c5('0x99')],_0x470a0b[_0xa4c5('0x9a')]);}else{_0x33212a['where'](_0x5d8983[_0xa4c5('0x8e')]+_0xa4c5('0x9b'),_0x470a0b['startDate'],_0x470a0b[_0xa4c5('0x9a')]);}if(_0x33d8b2){logger[_0xa4c5('0x9c')]('Run\x20Query:',_0x33212a[_0xa4c5('0x84')]());require(_0xa4c5('0x9d'))['fork'](path['join'](__dirname,'../../components/export/',_0x33d8b2[_0xa4c5('0x90')]),[_0x33d8b2['id'],_0x33212a[_0xa4c5('0x84')](),path['join'](__dirname,_0xa4c5('0x9e'),_0x33d8b2[_0xa4c5('0x9f')]),_0x114f35]);return _0x33d8b2;}else{var _0xff61e7=squel[_0xa4c5('0x8d')]();_0xff61e7['from']('('+_0x33212a[_0xa4c5('0x84')]()+')',_0xa4c5('0xa0'));_0xff61e7['field'](_0xa4c5('0xa1'),'count');_0x33212a[_0xa4c5('0x38')](_0x470a0b[_0xa4c5('0x38')]||_0x40c2af);_0x33212a[_0xa4c5('0x1e')](_0x470a0b['offset']||0x0);return dbH[_0xa4c5('0x85')]['query'](_0xff61e7[_0xa4c5('0x84')](),{'type':dbH['sequelize'][_0xa4c5('0x86')][_0xa4c5('0xa2')]})['then'](function(_0x67a6bb){if(!_0x67a6bb[_0xa4c5('0x46')]){_0x4fca6b=0x0;}else{_0x4fca6b=_0x67a6bb[0x0]['count']||0x0;}return dbH[_0xa4c5('0x85')][_0xa4c5('0x31')](_0x33212a[_0xa4c5('0x84')](),{'type':dbH[_0xa4c5('0x85')]['QueryTypes'][_0xa4c5('0xa2')]});})[_0xa4c5('0x27')](function(_0x20c0a4){return{'rows':_0x20c0a4||[],'count':_0x4fca6b};});}});}exports[_0xa4c5('0xa3')]=function(_0x8cfa2e,_0x1339b4){return runReport(_0x8cfa2e[_0xa4c5('0x54')],_0x8cfa2e['query'],_0x8cfa2e[_0xa4c5('0x3f')])['then'](respondWithResult(_0x1339b4,null))[_0xa4c5('0x48')](handleError(_0x1339b4,null));};exports[_0xa4c5('0xa4')]=runReport;exports[_0xa4c5('0x31')]=function(_0x570bfc,_0x23e4ad){var _0x462819=0xa;var _0x41c038=['join','left_join',_0xa4c5('0x57'),_0xa4c5('0x58')];var _0x4b074a={'SUM':_0xa4c5('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':'AVG(%s)','GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0x9f119c={'SEC_TO_TIME':_0xa4c5('0x88'),'DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xa4c5('0x63')};var _0x118a17=function(_0xafc6ce){return!_[_0xa4c5('0x64')]([_0xa4c5('0x65'),'IS\x20NOT\x20NULL',_0xa4c5('0x8a'),_0xa4c5('0x67')],_0xafc6ce);};var _0x1a7cf6=function(_0xab9063){if(!_0xab9063||!_0xab9063[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0x2c5918='(',_0x43ed39=0x0;_0x43ed39<_0xab9063[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x43ed39+=0x1){_0x43ed39>0x0&&(_0x2c5918+='\x20'+_0xab9063['operator']+'\x20');_0x2c5918+=_0xab9063['rules'][_0x43ed39]['group']?_0x1a7cf6(_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x69')]):_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x6a')]+'\x20'+_0xab9063['rules'][_0x43ed39][_0xa4c5('0x6b')]+(_0x118a17(_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x6b')])?'\x20'+_0xab9063['rules'][_0x43ed39][_0xa4c5('0xa5')]:'');}return _0x2c5918+')';};var _0x25425f={'where':{'id':_0x570bfc[_0xa4c5('0x54')]['id']}},_0x55046e,_0x4cd138,_0x1794d6,_0x523163,_0x599026;_0x25425f=_[_0xa4c5('0x3d')]({},_0x25425f,_0x570bfc[_0xa4c5('0x3f')]);return db['AnalyticCustomReport'][_0xa4c5('0x47')](_0x25425f)[_0xa4c5('0x27')](function(_0x95b18c){if(_0x95b18c){_0x55046e=_0x95b18c;return _0x95b18c[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x43bc8b){if(_0x43bc8b){if(!_0x43bc8b[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))][(_0xa4c5('0x8c'))](_0xa4c5('0x6e'),0x193);}_0x4cd138=_0x43bc8b;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})[_0xa4c5('0x27')](function(_0x5b6c3f){if(_0x5b6c3f){_0x1794d6=_['keyBy'](_0x5b6c3f,'id');var _0x4143c4;var _0x99b1da=squel['select']();_0x99b1da[_0xa4c5('0x71')](_0x55046e[_0xa4c5('0x8e')]);for(var _0x124ab1=0x0;_0x124ab1<_0x4cd138[_0xa4c5('0x46')];_0x124ab1+=0x1){_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x72')]?_0x1794d6[_0x4cd138[_0x124ab1]['MetricId']][_0xa4c5('0x8f')]:_0x4cd138[_0x124ab1][_0xa4c5('0x6a')];_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x4b074a[_0x4cd138[_0x124ab1][_0xa4c5('0x73')]],'%s',_0x4143c4):_0x4143c4;_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0x9f119c[_0x4cd138[_0x124ab1][_0xa4c5('0x75')]],'%s',_0x4143c4):_0x4143c4;if(_0x4cd138[_0x124ab1]['groupBy']){_0x99b1da[_0xa4c5('0x69')](_0x4143c4);}_0x4cd138[_0x124ab1][_0xa4c5('0x77')]&&_0x99b1da[_0xa4c5('0x39')](_0x4143c4,_0x4cd138[_0x124ab1][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x99b1da[_0xa4c5('0x6a')](_0x4143c4,_0x4cd138[_0x124ab1]['alias']||_0x4143c4);}if(_0x55046e[_0xa4c5('0x7a')]){_0x55046e['joins']=JSON[_0xa4c5('0x7b')](_0x55046e[_0xa4c5('0x7a')]);for(var _0x260821=0x0;_0x260821<_0x55046e[_0xa4c5('0x7a')][_0xa4c5('0x46')];_0x260821+=0x1){if(_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x41c038,_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')])&&_0x55046e['joins'][_0x260821][_0xa4c5('0x7f')]&&_0x55046e['joins'][_0x260821][_0xa4c5('0x7c')]&&_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7d')]){_0x99b1da[_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')]](_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')]('%s.%s\x20=\x20%s.%s',_0x55046e['table'],_0x55046e['joins'][_0x260821][_0xa4c5('0x7f')],_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7c')],_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7d')]));}}}if(_0x55046e[_0xa4c5('0x80')]){_0x55046e['conditions']=JSON[_0xa4c5('0x7b')](_0x55046e[_0xa4c5('0x80')]);_0x99b1da[_0xa4c5('0x3b')](_0x1a7cf6(_0x55046e[_0xa4c5('0x80')][_0xa4c5('0x69')]));}_0x599026=_0x99b1da[_0xa4c5('0x81')]();_0x99b1da[_0xa4c5('0x38')](_0x462819);_0x99b1da['offset'](0x0);logger[_0xa4c5('0x82')](_0xa4c5('0x83'),_0x99b1da[_0xa4c5('0x84')]());return dbH['sequelize'][_0xa4c5('0x31')](_0x99b1da['toString'](),{'type':dbH[_0xa4c5('0x85')][_0xa4c5('0x86')]['SELECT']});}})[_0xa4c5('0x27')](function(){return{'sql':_0x599026[_0xa4c5('0x84')]()};})['then'](respondWithResult(_0x23e4ad,null))[_0xa4c5('0x48')](handleError(_0x23e4ad,null));};
\ No newline at end of file