Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index aeb540f..645135f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb749=['child_process','fork','../../components/export/','../../files/reports','savename','run','runReport','IS\x20NOT\x20EMPTY','Limited\x20Query:','html-pdf','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','lodash','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','set','Content-Range','apply','update','destroy','get','CustomReports','UserProfileResource','then','stack','send','index','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','name','intersection','query','fields','attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','show','params','keys','find','catch','create','body','user','Reports','UserProfileSection','autoAssociation','error','preview','join','left_join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','UNIX_TIMESTAMP(%s)','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','rules','operator','group','field','condition','value','Sequelize','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','select','from','table','MetricId','metric','function','replace','format','orderBy','alias','parse','joins','includes','parentKey','foreignTable','foreignKey','conditions','clone','debug','sequelize','toString','QueryTypes','SELECT','HOUR(%s)','ROUND(%s)','getFields','ValidationErrorItem','groupBy','DESC','%s.%s\x20=\x20%s.%s','fullPath','%s-%s.%s','generate','output','csv','custom','AnalyticExtractedReport','cdr','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','Run\x20Query:'];(function(_0x4854d6,_0x2f1264){var _0x3885c0=function(_0x4d564d){while(--_0x4d564d){_0x4854d6['push'](_0x4854d6['shift']());}};_0x3885c0(++_0x2f1264);}(_0xb749,0xac));var _0x9b74=function(_0x40c760,_0x156f78){_0x40c760=_0x40c760-0x0;var _0x3fa39a=_0xb749[_0x40c760];return _0x3fa39a;};'use strict';var pdf=require(_0x9b74('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x9b74('0x1'));var zipdir=require(_0x9b74('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x9b74('0x3'));var moment=require('moment');var BPromise=require(_0x9b74('0x4'));var Mustache=require(_0x9b74('0x5'));var util=require(_0x9b74('0x6'));var path=require(_0x9b74('0x7'));var sox=require(_0x9b74('0x8'));var csv=require(_0x9b74('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x9b74('0xa'));var squel=require('squel');var crypto=require(_0x9b74('0xb'));var jsforce=require(_0x9b74('0xc'));var deskjs=require(_0x9b74('0xd'));var toCsv=require(_0x9b74('0x9'));var querystring=require(_0x9b74('0xe'));var Papa=require('papaparse');var Redis=require(_0x9b74('0xf'));var authService=require(_0x9b74('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x9b74('0x11'));var hardwareService=require(_0x9b74('0x12'));var logger=require(_0x9b74('0x13'))('api');var utils=require(_0x9b74('0x14'));var config=require(_0x9b74('0x15'));var licenseUtil=require(_0x9b74('0x16'));var db=require(_0x9b74('0x17'))['db'];var dbH=require('../../mysqldb')['dbH'];function respondWithStatusCode(_0xc104c0,_0x203fda){_0x203fda=_0x203fda||0xcc;return function(_0x1027da){if(_0x1027da){return _0xc104c0[_0x9b74('0x18')](_0x203fda);}return _0xc104c0['status'](_0x203fda)[_0x9b74('0x19')]();};}function respondWithResult(_0x440027,_0x260532){_0x260532=_0x260532||0xc8;return function(_0x31c30d){if(_0x31c30d){return _0x440027[_0x9b74('0x1a')](_0x260532)[_0x9b74('0x1b')](_0x31c30d);}};}function respondWithFilteredResult(_0x5270d8,_0x4d5105){return function(_0x6d921a){if(_0x6d921a){var _0x29a86d=_0x6d921a['count'],_0x307a85=_0x4d5105[_0x9b74('0x1c')],_0x193be3=_0x4d5105[_0x9b74('0x1c')]+_0x4d5105['limit'],_0x4cb6d7;if(_0x193be3>=_0x29a86d){_0x193be3=_0x29a86d;_0x4cb6d7=0xc8;}else{_0x4cb6d7=0xce;}_0x5270d8[_0x9b74('0x1a')](_0x4cb6d7);return _0x5270d8[_0x9b74('0x1d')](_0x9b74('0x1e'),_0x307a85+'-'+_0x193be3+'/'+_0x29a86d)['json'](_0x6d921a);}return null;};}function patchUpdates(_0x18901d){return function(_0x2a3498){try{jsonpatch[_0x9b74('0x1f')](_0x2a3498,_0x18901d,!![]);}catch(_0x2f2464){return BPromise['reject'](_0x2f2464);}return _0x2a3498['save']();};}function saveUpdates(_0x49afcd,_0x1a743f){return function(_0x523ba6){if(_0x523ba6){return _0x523ba6[_0x9b74('0x20')](_0x49afcd)['then'](function(_0x3c0777){return _0x3c0777;});}return null;};}function removeEntity(_0x1ff224,_0x3897a2){return function(_0xddac13){if(_0xddac13){return _0xddac13[_0x9b74('0x21')]()['then'](function(){var _0xbc2be4=_0xddac13[_0x9b74('0x22')]({'plain':!![]});var _0x548655=_0x9b74('0x23');return db[_0x9b74('0x24')]['destroy']({'where':{'type':_0x548655,'resourceId':_0xbc2be4['id']}})['then'](function(){return _0xddac13;});})[_0x9b74('0x25')](function(){_0x1ff224[_0x9b74('0x1a')](0xcc)[_0x9b74('0x19')]();});}};}function handleEntityNotFound(_0x464ceb,_0x13f392){return function(_0x4f9cd7){if(!_0x4f9cd7){_0x464ceb[_0x9b74('0x18')](0x194);}return _0x4f9cd7;};}function handleError(_0x35d202,_0x49da20){_0x49da20=_0x49da20||0x1f4;return function(_0x2fca21){logger['error'](_0x2fca21[_0x9b74('0x26')]);if(_0x2fca21['name']){delete _0x2fca21['name'];}_0x35d202[_0x9b74('0x1a')](_0x49da20)[_0x9b74('0x27')](_0x2fca21);};}exports[_0x9b74('0x28')]=function(_0x5a0319,_0x5c5b0e){var _0x19ccf0={},_0xe5e961={},_0x25960a={'count':0x0,'rows':[]};var _0x49a9ed=_[_0x9b74('0x29')](db[_0x9b74('0x2a')][_0x9b74('0x2b')],function(_0x97e30a){return{'name':_0x97e30a[_0x9b74('0x2c')],'type':_0x97e30a[_0x9b74('0x2d')][_0x9b74('0x2e')]};});_0xe5e961[_0x9b74('0x2f')]=_[_0x9b74('0x29')](_0x49a9ed,_0x9b74('0x30'));_0xe5e961['query']=_['keys'](_0x5a0319['query']);_0xe5e961['filters']=_[_0x9b74('0x31')](_0xe5e961[_0x9b74('0x2f')],_0xe5e961[_0x9b74('0x32')]);_0x19ccf0['attributes']=_[_0x9b74('0x31')](_0xe5e961[_0x9b74('0x2f')],qs['fields'](_0x5a0319['query'][_0x9b74('0x33')]));_0x19ccf0[_0x9b74('0x34')]=_0x19ccf0[_0x9b74('0x34')][_0x9b74('0x35')]?_0x19ccf0[_0x9b74('0x34')]:_0xe5e961['model'];if(!_0x5a0319[_0x9b74('0x32')][_0x9b74('0x36')](_0x9b74('0x37'))){_0x19ccf0[_0x9b74('0x38')]=qs['limit'](_0x5a0319[_0x9b74('0x32')][_0x9b74('0x38')]);_0x19ccf0[_0x9b74('0x1c')]=qs[_0x9b74('0x1c')](_0x5a0319[_0x9b74('0x32')][_0x9b74('0x1c')]);}_0x19ccf0[_0x9b74('0x39')]=qs[_0x9b74('0x3a')](_0x5a0319[_0x9b74('0x32')][_0x9b74('0x3a')]);_0x19ccf0[_0x9b74('0x3b')]=qs[_0x9b74('0x3c')](_[_0x9b74('0x3d')](_0x5a0319[_0x9b74('0x32')],_0xe5e961[_0x9b74('0x3c')]),_0x49a9ed);if(_0x5a0319[_0x9b74('0x32')][_0x9b74('0x3e')]){_0x19ccf0[_0x9b74('0x3b')]=_[_0x9b74('0x3f')](_0x19ccf0['where'],{'$or':_[_0x9b74('0x29')](_0x49a9ed,function(_0x4b11c4){if(_0x4b11c4[_0x9b74('0x2d')]!==_0x9b74('0x40')){var _0x88c44a={};_0x88c44a[_0x4b11c4[_0x9b74('0x30')]]={'$like':'%'+_0x5a0319[_0x9b74('0x32')][_0x9b74('0x3e')]+'%'};return _0x88c44a;}})});}_0x19ccf0=_[_0x9b74('0x3f')]({},_0x19ccf0,_0x5a0319[_0x9b74('0x41')]);var _0x4d97ac={'where':_0x19ccf0[_0x9b74('0x3b')]};return db['AnalyticCustomReport']['count'](_0x4d97ac)[_0x9b74('0x25')](function(_0x35ad26){_0x25960a[_0x9b74('0x42')]=_0x35ad26;if(_0x5a0319[_0x9b74('0x32')][_0x9b74('0x43')]){_0x19ccf0[_0x9b74('0x44')]=[{'all':!![]}];}return db[_0x9b74('0x2a')][_0x9b74('0x45')](_0x19ccf0);})[_0x9b74('0x25')](function(_0x3f0322){_0x25960a[_0x9b74('0x46')]=_0x3f0322;return _0x25960a;})['then'](respondWithFilteredResult(_0x5c5b0e,_0x19ccf0))['catch'](handleError(_0x5c5b0e,null));};exports[_0x9b74('0x47')]=function(_0x4aec47,_0xc4694){var _0x57a3e0={'raw':![],'where':{'id':_0x4aec47[_0x9b74('0x48')]['id']}},_0x24a5d7={};_0x24a5d7[_0x9b74('0x2f')]=_[_0x9b74('0x49')](db[_0x9b74('0x2a')][_0x9b74('0x2b')]);_0x24a5d7[_0x9b74('0x32')]=_[_0x9b74('0x49')](_0x4aec47[_0x9b74('0x32')]);_0x24a5d7[_0x9b74('0x3c')]=_[_0x9b74('0x31')](_0x24a5d7[_0x9b74('0x2f')],_0x24a5d7[_0x9b74('0x32')]);_0x57a3e0['attributes']=_[_0x9b74('0x31')](_0x24a5d7[_0x9b74('0x2f')],qs[_0x9b74('0x33')](_0x4aec47[_0x9b74('0x32')][_0x9b74('0x33')]));_0x57a3e0['attributes']=_0x57a3e0[_0x9b74('0x34')][_0x9b74('0x35')]?_0x57a3e0['attributes']:_0x24a5d7[_0x9b74('0x2f')];if(_0x4aec47[_0x9b74('0x32')]['includeAll']){_0x57a3e0[_0x9b74('0x44')]=[{'all':!![]}];}_0x57a3e0=_['merge']({},_0x57a3e0,_0x4aec47[_0x9b74('0x41')]);return db[_0x9b74('0x2a')][_0x9b74('0x4a')](_0x57a3e0)[_0x9b74('0x25')](handleEntityNotFound(_0xc4694,null))['then'](respondWithResult(_0xc4694,null))[_0x9b74('0x4b')](handleError(_0xc4694,null));};exports[_0x9b74('0x4c')]=function(_0x686ca5,_0xb806ec){return db[_0x9b74('0x2a')][_0x9b74('0x4c')](_0x686ca5[_0x9b74('0x4d')],{})[_0x9b74('0x25')](function(_0x3c4c28){var _0x3727d8=_0x686ca5[_0x9b74('0x4e')]['get']({'plain':!![]});if(!_0x3727d8)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x3727d8['role']===_0x9b74('0x4e')){var _0x597382=_0x3c4c28[_0x9b74('0x22')]({'plain':!![]});var _0x39c017=_0x9b74('0x4f');return db[_0x9b74('0x50')][_0x9b74('0x4a')]({'where':{'name':_0x39c017,'userProfileId':_0x3727d8['userProfileId']},'raw':!![]})['then'](function(_0x1e9c9a){if(_0x1e9c9a&&_0x1e9c9a[_0x9b74('0x51')]===0x0){return db[_0x9b74('0x24')][_0x9b74('0x4c')]({'name':_0x597382['name'],'resourceId':_0x597382['id'],'type':_0x9b74('0x23'),'sectionId':_0x1e9c9a['id']},{})[_0x9b74('0x25')](function(){return _0x3c4c28;});}else{return _0x3c4c28;}})['catch'](function(_0x7bf8be){logger[_0x9b74('0x52')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x7bf8be);throw _0x7bf8be;});}return _0x3c4c28;})[_0x9b74('0x25')](respondWithResult(_0xb806ec,0xc9))[_0x9b74('0x4b')](handleError(_0xb806ec,null));};exports['update']=function(_0x2483ec,_0x1c543c){if(_0x2483ec[_0x9b74('0x4d')]['id']){delete _0x2483ec[_0x9b74('0x4d')]['id'];}return db['AnalyticCustomReport'][_0x9b74('0x4a')]({'where':{'id':_0x2483ec[_0x9b74('0x48')]['id']}})[_0x9b74('0x25')](handleEntityNotFound(_0x1c543c,null))['then'](saveUpdates(_0x2483ec[_0x9b74('0x4d')],null))[_0x9b74('0x25')](respondWithResult(_0x1c543c,null))[_0x9b74('0x4b')](handleError(_0x1c543c,null));};exports['destroy']=function(_0x1a0754,_0xec0887){return db[_0x9b74('0x2a')][_0x9b74('0x4a')]({'where':{'id':_0x1a0754[_0x9b74('0x48')]['id']}})[_0x9b74('0x25')](handleEntityNotFound(_0xec0887,null))[_0x9b74('0x25')](removeEntity(_0xec0887,null))[_0x9b74('0x4b')](handleError(_0xec0887,null));};exports[_0x9b74('0x53')]=function(_0x4392f6,_0x3da0b6){var _0xd4d6=0xa;var _0x5b8ec1=[_0x9b74('0x54'),_0x9b74('0x55'),_0x9b74('0x56'),_0x9b74('0x57')];var _0x1f1938={'SUM':_0x9b74('0x58'),'COUNT':_0x9b74('0x59'),'COUNT DISTINCT':_0x9b74('0x5a'),'MAX':_0x9b74('0x5b'),'MIN':_0x9b74('0x5c'),'AVG':_0x9b74('0x5d'),'GROUP_CONCAT':_0x9b74('0x5e'),'GROUP_CONCAT ASC':_0x9b74('0x5f'),'GROUP_CONCAT DESC':_0x9b74('0x60')};var _0x1d64df={'SEC_TO_TIME':_0x9b74('0x61'),'DATE':_0x9b74('0x62'),'HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x9b74('0x63')};var _0x5a1ee1=function(_0x473dc3){return!_['includes']([_0x9b74('0x64'),_0x9b74('0x65'),_0x9b74('0x66'),'IS\x20NOT\x20EMPTY'],_0x473dc3);};var _0x4fe8bc=function(_0x43cfbd){if(!_0x43cfbd||!_0x43cfbd[_0x9b74('0x67')][_0x9b74('0x35')]){return'';}for(var _0x531d66='(',_0x1b4297=0x0;_0x1b4297<_0x43cfbd[_0x9b74('0x67')]['length'];_0x1b4297+=0x1){_0x1b4297>0x0&&(_0x531d66+='\x20'+_0x43cfbd[_0x9b74('0x68')]+'\x20');_0x531d66+=_0x43cfbd['rules'][_0x1b4297][_0x9b74('0x69')]?_0x4fe8bc(_0x43cfbd['rules'][_0x1b4297][_0x9b74('0x69')]):_0x43cfbd[_0x9b74('0x67')][_0x1b4297][_0x9b74('0x6a')]+'\x20'+_0x43cfbd[_0x9b74('0x67')][_0x1b4297][_0x9b74('0x6b')]+(_0x5a1ee1(_0x43cfbd[_0x9b74('0x67')][_0x1b4297]['condition'])?'\x20'+_0x43cfbd['rules'][_0x1b4297][_0x9b74('0x6c')]:'');}return _0x531d66+')';};var _0x47cd93={'where':{'id':_0x4392f6['params']['id']}},_0x538217,_0x6ef798,_0x535496,_0x585aba,_0x35aabe;_0x47cd93=_[_0x9b74('0x3f')]({},_0x47cd93,_0x4392f6['options']);return db['AnalyticCustomReport'][_0x9b74('0x4a')](_0x47cd93)[_0x9b74('0x25')](function(_0x331648){if(_0x331648){_0x538217=_0x331648;return _0x331648['getFields']();}return null;})[_0x9b74('0x25')](function(_0x444a78){if(_0x444a78){if(!_0x444a78['length']){throw new db[(_0x9b74('0x6d'))]['ValidationErrorItem'](_0x9b74('0x6e'),0x193);}_0x6ef798=_0x444a78;return db[_0x9b74('0x6f')][_0x9b74('0x45')]({'raw':!![]});}return null;})['then'](function(_0x3a8d39){if(_0x3a8d39){_0x535496=_[_0x9b74('0x70')](_0x3a8d39,'id');var _0x365584;var _0x5ad84e=squel[_0x9b74('0x71')]();_0x5ad84e[_0x9b74('0x72')](_0x538217[_0x9b74('0x73')]);for(var _0x5e4781=0x0;_0x5e4781<_0x6ef798[_0x9b74('0x35')];_0x5e4781+=0x1){_0x365584=_0x6ef798[_0x5e4781][_0x9b74('0x74')]?_0x535496[_0x6ef798[_0x5e4781][_0x9b74('0x74')]][_0x9b74('0x75')]:_0x6ef798[_0x5e4781][_0x9b74('0x6a')];_0x365584=_0x6ef798[_0x5e4781][_0x9b74('0x76')]?_[_0x9b74('0x77')](_0x1f1938[_0x6ef798[_0x5e4781]['function']],'%s',_0x365584):_0x365584;_0x365584=_0x6ef798[_0x5e4781][_0x9b74('0x78')]?_['replace'](_0x1d64df[_0x6ef798[_0x5e4781]['format']],'%s',_0x365584):_0x365584;if(_0x6ef798[_0x5e4781]['groupBy']){_0x5ad84e[_0x9b74('0x69')](_0x365584);}_0x6ef798[_0x5e4781][_0x9b74('0x79')]&&_0x5ad84e[_0x9b74('0x39')](_0x365584,_0x6ef798[_0x5e4781][_0x9b74('0x79')]==='DESC'?![]:!![]);_0x5ad84e[_0x9b74('0x6a')](_0x365584,_0x6ef798[_0x5e4781][_0x9b74('0x7a')]||_0x365584);}if(_0x538217['joins']){_0x538217['joins']=JSON[_0x9b74('0x7b')](_0x538217[_0x9b74('0x7c')]);for(var _0x388726=0x0;_0x388726<_0x538217[_0x9b74('0x7c')][_0x9b74('0x35')];_0x388726+=0x1){if(_0x538217[_0x9b74('0x7c')][_0x388726][_0x9b74('0x2d')]&&_[_0x9b74('0x7d')](_0x5b8ec1,_0x538217['joins'][_0x388726][_0x9b74('0x2d')])&&_0x538217[_0x9b74('0x7c')][_0x388726][_0x9b74('0x7e')]&&_0x538217[_0x9b74('0x7c')][_0x388726][_0x9b74('0x7f')]&&_0x538217[_0x9b74('0x7c')][_0x388726][_0x9b74('0x80')]){_0x5ad84e[_0x538217[_0x9b74('0x7c')][_0x388726]['type']](_0x538217[_0x9b74('0x7c')][_0x388726]['foreignTable'],null,util[_0x9b74('0x78')]('%s.%s\x20=\x20%s.%s',_0x538217[_0x9b74('0x73')],_0x538217[_0x9b74('0x7c')][_0x388726]['parentKey'],_0x538217[_0x9b74('0x7c')][_0x388726][_0x9b74('0x7f')],_0x538217[_0x9b74('0x7c')][_0x388726][_0x9b74('0x80')]));}}}if(_0x538217[_0x9b74('0x81')]){_0x538217[_0x9b74('0x81')]=JSON[_0x9b74('0x7b')](_0x538217['conditions']);_0x5ad84e['where'](_0x4fe8bc(_0x538217['conditions'][_0x9b74('0x69')]));}_0x35aabe=_0x5ad84e[_0x9b74('0x82')]();_0x5ad84e[_0x9b74('0x38')](_0xd4d6);_0x5ad84e[_0x9b74('0x1c')](0x0);logger[_0x9b74('0x83')]('Limited\x20Query:',_0x5ad84e['toString']());return dbH[_0x9b74('0x84')][_0x9b74('0x32')](_0x5ad84e[_0x9b74('0x85')](),{'type':dbH[_0x9b74('0x84')][_0x9b74('0x86')][_0x9b74('0x87')]});}})[_0x9b74('0x25')](respondWithResult(_0x3da0b6,null))['catch'](handleError(_0x3da0b6,null));};function runReport(_0x6550b1,_0x4917e3,_0x3e581f){var _0x19fe47=_0x4917e3[_0x9b74('0x30')];var _0x3f118f=0xa;var _0x372510=[_0x9b74('0x54'),_0x9b74('0x55'),_0x9b74('0x56'),_0x9b74('0x57')];var _0x4cbba4={'SUM':_0x9b74('0x58'),'COUNT':_0x9b74('0x59'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x9b74('0x5b'),'MIN':_0x9b74('0x5c'),'AVG':_0x9b74('0x5d'),'GROUP_CONCAT':_0x9b74('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x9b74('0x60')};var _0x2f98fe={'SEC_TO_TIME':_0x9b74('0x61'),'DATE':_0x9b74('0x62'),'HOUR':_0x9b74('0x88'),'ROUND':_0x9b74('0x89'),'UNIX_TIMESTAMP':_0x9b74('0x63')};var _0x48a8bc=function(_0x451063){return!_[_0x9b74('0x7d')]([_0x9b74('0x64'),_0x9b74('0x65'),_0x9b74('0x66'),'IS\x20NOT\x20EMPTY'],_0x451063);};var _0x187321=function(_0x2ef4da){if(!_0x2ef4da||!_0x2ef4da[_0x9b74('0x67')][_0x9b74('0x35')]){return'';}for(var _0x402dd4='(',_0x5c24dc=0x0;_0x5c24dc<_0x2ef4da[_0x9b74('0x67')][_0x9b74('0x35')];_0x5c24dc+=0x1){_0x5c24dc>0x0&&(_0x402dd4+='\x20'+_0x2ef4da[_0x9b74('0x68')]+'\x20');_0x402dd4+=_0x2ef4da[_0x9b74('0x67')][_0x5c24dc][_0x9b74('0x69')]?_0x187321(_0x2ef4da['rules'][_0x5c24dc]['group']):_0x2ef4da[_0x9b74('0x67')][_0x5c24dc]['field']+'\x20'+_0x2ef4da[_0x9b74('0x67')][_0x5c24dc][_0x9b74('0x6b')]+(_0x48a8bc(_0x2ef4da[_0x9b74('0x67')][_0x5c24dc][_0x9b74('0x6b')])?'\x20'+_0x2ef4da[_0x9b74('0x67')][_0x5c24dc][_0x9b74('0x6c')]:'');}return _0x402dd4+')';};var _0x73f66f={'where':{'id':_0x6550b1['id']}},_0x7b3c75,_0x5330e0,_0x3c1c3e,_0x51743b,_0x4b8d05;_0x73f66f=_['merge']({},_0x73f66f,_0x3e581f);return db['AnalyticCustomReport'][_0x9b74('0x4a')](_0x73f66f)['then'](function(_0x341c5b){if(_0x341c5b){_0x7b3c75=_0x341c5b;return _0x341c5b[_0x9b74('0x8a')]();}return null;})[_0x9b74('0x25')](function(_0x25f6ad){if(_0x25f6ad){if(!_0x25f6ad[_0x9b74('0x35')]){throw new db[(_0x9b74('0x6d'))][(_0x9b74('0x8b'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x5330e0=_0x25f6ad;return db[_0x9b74('0x6f')][_0x9b74('0x45')]({'raw':!![]});}return null;})[_0x9b74('0x25')](function(_0x10e9eb){if(_0x10e9eb){_0x3c1c3e=_['keyBy'](_0x10e9eb,'id');var _0x91861b;var _0x48a6ca=squel[_0x9b74('0x71')]();_0x48a6ca['from'](_0x7b3c75['table']);for(var _0x33cdd3=0x0;_0x33cdd3<_0x5330e0[_0x9b74('0x35')];_0x33cdd3+=0x1){_0x91861b=_0x5330e0[_0x33cdd3][_0x9b74('0x74')]?_0x3c1c3e[_0x5330e0[_0x33cdd3][_0x9b74('0x74')]][_0x9b74('0x75')]:_0x5330e0[_0x33cdd3]['field'];_0x91861b=_0x5330e0[_0x33cdd3]['function']?_[_0x9b74('0x77')](_0x4cbba4[_0x5330e0[_0x33cdd3][_0x9b74('0x76')]],'%s',_0x91861b):_0x91861b;_0x91861b=_0x5330e0[_0x33cdd3]['format']?_['replace'](_0x2f98fe[_0x5330e0[_0x33cdd3][_0x9b74('0x78')]],'%s',_0x91861b):_0x91861b;if(_0x5330e0[_0x33cdd3][_0x9b74('0x8c')]){_0x48a6ca[_0x9b74('0x69')](_0x91861b);}_0x5330e0[_0x33cdd3][_0x9b74('0x79')]&&_0x48a6ca['order'](_0x91861b,_0x5330e0[_0x33cdd3]['orderBy']===_0x9b74('0x8d')?![]:!![]);_0x48a6ca['field'](_0x91861b,_0x5330e0[_0x33cdd3]['alias']||_0x91861b);}if(_0x7b3c75['joins']){_0x7b3c75['joins']=JSON[_0x9b74('0x7b')](_0x7b3c75[_0x9b74('0x7c')]);for(var _0x257c4a=0x0;_0x257c4a<_0x7b3c75['joins'][_0x9b74('0x35')];_0x257c4a+=0x1){if(_0x7b3c75[_0x9b74('0x7c')][_0x257c4a][_0x9b74('0x2d')]&&_['includes'](_0x372510,_0x7b3c75['joins'][_0x257c4a]['type'])&&_0x7b3c75[_0x9b74('0x7c')][_0x257c4a][_0x9b74('0x7e')]&&_0x7b3c75['joins'][_0x257c4a][_0x9b74('0x7f')]&&_0x7b3c75[_0x9b74('0x7c')][_0x257c4a][_0x9b74('0x80')]){_0x48a6ca[_0x7b3c75[_0x9b74('0x7c')][_0x257c4a]['type']](_0x7b3c75[_0x9b74('0x7c')][_0x257c4a][_0x9b74('0x7f')],null,util[_0x9b74('0x78')](_0x9b74('0x8e'),_0x7b3c75[_0x9b74('0x73')],_0x7b3c75['joins'][_0x257c4a]['parentKey'],_0x7b3c75[_0x9b74('0x7c')][_0x257c4a][_0x9b74('0x7f')],_0x7b3c75['joins'][_0x257c4a][_0x9b74('0x80')]));}}}if(_0x7b3c75[_0x9b74('0x81')]){_0x7b3c75[_0x9b74('0x81')]=JSON[_0x9b74('0x7b')](_0x7b3c75['conditions']);_0x48a6ca[_0x9b74('0x3b')](_0x187321(_0x7b3c75['conditions']['group']));}_0x4b8d05=_0x48a6ca[_0x9b74('0x82')]();_0x48a6ca[_0x9b74('0x38')](_0x3f118f);_0x48a6ca['offset'](0x0);return;}})[_0x9b74('0x25')](function(){if(_0x4917e3['output']==='web'){return null;}var _0x3cf838=_['merge'](_0x4917e3,{'name':_0x4917e3[_0x9b74('0x8f')]||_0x4917e3[_0x9b74('0x30')]||_0x7b3c75[_0x9b74('0x30')],'basename':_0x19fe47,'savename':util[_0x9b74('0x78')](_0x9b74('0x90'),_0x4917e3['name']||_0x7b3c75[_0x9b74('0x30')],require('randomstring')[_0x9b74('0x91')](0x4),_0x4917e3[_0x9b74('0x92')]||_0x9b74('0x93')),'reportId':_0x7b3c75['id'],'reportType':_0x9b74('0x94')});return db[_0x9b74('0x95')][_0x9b74('0x4c')](_0x3cf838,{'raw':!![]});})[_0x9b74('0x25')](function(_0x150b60){if(_0x7b3c75[_0x9b74('0x73')]===_0x9b74('0x96')){_0x4b8d05[_0x9b74('0x3b')](_0x7b3c75[_0x9b74('0x73')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x4917e3['startDate'],_0x4917e3[_0x9b74('0x97')]);}else{_0x4b8d05[_0x9b74('0x3b')](_0x7b3c75[_0x9b74('0x73')]+_0x9b74('0x98'),_0x4917e3['startDate'],_0x4917e3[_0x9b74('0x97')]);}if(_0x150b60){logger['info'](_0x9b74('0x99'),_0x4b8d05[_0x9b74('0x85')]());require(_0x9b74('0x9a'))[_0x9b74('0x9b')](path[_0x9b74('0x54')](__dirname,_0x9b74('0x9c'),_0x150b60[_0x9b74('0x92')]),[_0x150b60['id'],_0x4b8d05[_0x9b74('0x85')](),path[_0x9b74('0x54')](__dirname,_0x9b74('0x9d'),_0x150b60[_0x9b74('0x9e')]),_0x19fe47]);return _0x150b60;}else{var _0x4a8262=squel[_0x9b74('0x71')]();_0x4a8262[_0x9b74('0x72')]('('+_0x4b8d05[_0x9b74('0x85')]()+')','countTable');_0x4a8262['field']('COUNT(*)',_0x9b74('0x42'));_0x4b8d05[_0x9b74('0x38')](_0x4917e3[_0x9b74('0x38')]||_0x3f118f);_0x4b8d05[_0x9b74('0x1c')](_0x4917e3[_0x9b74('0x1c')]||0x0);return dbH[_0x9b74('0x84')][_0x9b74('0x32')](_0x4a8262[_0x9b74('0x85')](),{'type':dbH[_0x9b74('0x84')][_0x9b74('0x86')][_0x9b74('0x87')]})['then'](function(_0x33c4d9){if(!_0x33c4d9[_0x9b74('0x35')]){_0x51743b=0x0;}else{_0x51743b=_0x33c4d9[0x0][_0x9b74('0x42')]||0x0;}return dbH['sequelize'][_0x9b74('0x32')](_0x4b8d05[_0x9b74('0x85')](),{'type':dbH[_0x9b74('0x84')][_0x9b74('0x86')][_0x9b74('0x87')]});})[_0x9b74('0x25')](function(_0x42fbc7){return{'rows':_0x42fbc7||[],'count':_0x51743b};});}});}exports[_0x9b74('0x9f')]=function(_0x39e39d,_0xd2860f){return runReport(_0x39e39d[_0x9b74('0x48')],_0x39e39d[_0x9b74('0x32')],_0x39e39d[_0x9b74('0x41')])[_0x9b74('0x25')](respondWithResult(_0xd2860f,null))[_0x9b74('0x4b')](handleError(_0xd2860f,null));};exports[_0x9b74('0xa0')]=runReport;exports[_0x9b74('0x32')]=function(_0x110e9e,_0x335230){var _0x64dca=0xa;var _0x5d71f8=[_0x9b74('0x54'),_0x9b74('0x55'),_0x9b74('0x56'),_0x9b74('0x57')];var _0x6247fa={'SUM':_0x9b74('0x58'),'COUNT':_0x9b74('0x59'),'COUNT DISTINCT':_0x9b74('0x5a'),'MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':_0x9b74('0x5d'),'GROUP_CONCAT':_0x9b74('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x9b74('0x60')};var _0x51fe77={'SEC_TO_TIME':_0x9b74('0x61'),'DATE':_0x9b74('0x62'),'HOUR':_0x9b74('0x88'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x9b74('0x63')};var _0xb5a7c=function(_0x2e9fed){return!_[_0x9b74('0x7d')]([_0x9b74('0x64'),_0x9b74('0x65'),_0x9b74('0x66'),_0x9b74('0xa1')],_0x2e9fed);};var _0x134418=function(_0x540ff3){if(!_0x540ff3||!_0x540ff3[_0x9b74('0x67')][_0x9b74('0x35')]){return'';}for(var _0x13ea9a='(',_0x17bf80=0x0;_0x17bf80<_0x540ff3[_0x9b74('0x67')]['length'];_0x17bf80+=0x1){_0x17bf80>0x0&&(_0x13ea9a+='\x20'+_0x540ff3[_0x9b74('0x68')]+'\x20');_0x13ea9a+=_0x540ff3[_0x9b74('0x67')][_0x17bf80][_0x9b74('0x69')]?_0x134418(_0x540ff3[_0x9b74('0x67')][_0x17bf80][_0x9b74('0x69')]):_0x540ff3[_0x9b74('0x67')][_0x17bf80][_0x9b74('0x6a')]+'\x20'+_0x540ff3[_0x9b74('0x67')][_0x17bf80][_0x9b74('0x6b')]+(_0xb5a7c(_0x540ff3[_0x9b74('0x67')][_0x17bf80][_0x9b74('0x6b')])?'\x20'+_0x540ff3[_0x9b74('0x67')][_0x17bf80][_0x9b74('0x6c')]:'');}return _0x13ea9a+')';};var _0xbca6b8={'where':{'id':_0x110e9e['params']['id']}},_0x35c693,_0x248c28,_0x4b559b,_0x55789a,_0x26be27;_0xbca6b8=_['merge']({},_0xbca6b8,_0x110e9e[_0x9b74('0x41')]);return db[_0x9b74('0x2a')][_0x9b74('0x4a')](_0xbca6b8)['then'](function(_0x5f502d){if(_0x5f502d){_0x35c693=_0x5f502d;return _0x5f502d[_0x9b74('0x8a')]();}return null;})['then'](function(_0x217067){if(_0x217067){if(!_0x217067[_0x9b74('0x35')]){throw new db[(_0x9b74('0x6d'))][(_0x9b74('0x8b'))](_0x9b74('0x6e'),0x193);}_0x248c28=_0x217067;return db[_0x9b74('0x6f')][_0x9b74('0x45')]({'raw':!![]});}return null;})[_0x9b74('0x25')](function(_0xbc73ec){if(_0xbc73ec){_0x4b559b=_[_0x9b74('0x70')](_0xbc73ec,'id');var _0x490f04;var _0x4e30cd=squel[_0x9b74('0x71')]();_0x4e30cd['from'](_0x35c693['table']);for(var _0x49ffc=0x0;_0x49ffc<_0x248c28[_0x9b74('0x35')];_0x49ffc+=0x1){_0x490f04=_0x248c28[_0x49ffc][_0x9b74('0x74')]?_0x4b559b[_0x248c28[_0x49ffc][_0x9b74('0x74')]][_0x9b74('0x75')]:_0x248c28[_0x49ffc][_0x9b74('0x6a')];_0x490f04=_0x248c28[_0x49ffc][_0x9b74('0x76')]?_[_0x9b74('0x77')](_0x6247fa[_0x248c28[_0x49ffc][_0x9b74('0x76')]],'%s',_0x490f04):_0x490f04;_0x490f04=_0x248c28[_0x49ffc][_0x9b74('0x78')]?_['replace'](_0x51fe77[_0x248c28[_0x49ffc][_0x9b74('0x78')]],'%s',_0x490f04):_0x490f04;if(_0x248c28[_0x49ffc][_0x9b74('0x8c')]){_0x4e30cd[_0x9b74('0x69')](_0x490f04);}_0x248c28[_0x49ffc]['orderBy']&&_0x4e30cd[_0x9b74('0x39')](_0x490f04,_0x248c28[_0x49ffc]['orderBy']===_0x9b74('0x8d')?![]:!![]);_0x4e30cd[_0x9b74('0x6a')](_0x490f04,_0x248c28[_0x49ffc]['alias']||_0x490f04);}if(_0x35c693[_0x9b74('0x7c')]){_0x35c693[_0x9b74('0x7c')]=JSON[_0x9b74('0x7b')](_0x35c693[_0x9b74('0x7c')]);for(var _0x5436a9=0x0;_0x5436a9<_0x35c693[_0x9b74('0x7c')][_0x9b74('0x35')];_0x5436a9+=0x1){if(_0x35c693[_0x9b74('0x7c')][_0x5436a9][_0x9b74('0x2d')]&&_[_0x9b74('0x7d')](_0x5d71f8,_0x35c693[_0x9b74('0x7c')][_0x5436a9][_0x9b74('0x2d')])&&_0x35c693[_0x9b74('0x7c')][_0x5436a9][_0x9b74('0x7e')]&&_0x35c693[_0x9b74('0x7c')][_0x5436a9]['foreignTable']&&_0x35c693['joins'][_0x5436a9][_0x9b74('0x80')]){_0x4e30cd[_0x35c693[_0x9b74('0x7c')][_0x5436a9][_0x9b74('0x2d')]](_0x35c693[_0x9b74('0x7c')][_0x5436a9]['foreignTable'],null,util[_0x9b74('0x78')](_0x9b74('0x8e'),_0x35c693['table'],_0x35c693[_0x9b74('0x7c')][_0x5436a9][_0x9b74('0x7e')],_0x35c693[_0x9b74('0x7c')][_0x5436a9]['foreignTable'],_0x35c693[_0x9b74('0x7c')][_0x5436a9][_0x9b74('0x80')]));}}}if(_0x35c693[_0x9b74('0x81')]){_0x35c693[_0x9b74('0x81')]=JSON['parse'](_0x35c693[_0x9b74('0x81')]);_0x4e30cd[_0x9b74('0x3b')](_0x134418(_0x35c693[_0x9b74('0x81')]['group']));}_0x26be27=_0x4e30cd[_0x9b74('0x82')]();_0x4e30cd[_0x9b74('0x38')](_0x64dca);_0x4e30cd['offset'](0x0);logger[_0x9b74('0x83')](_0x9b74('0xa2'),_0x4e30cd['toString']());return dbH[_0x9b74('0x84')]['query'](_0x4e30cd['toString'](),{'type':dbH[_0x9b74('0x84')][_0x9b74('0x86')][_0x9b74('0x87')]});}})[_0x9b74('0x25')](function(){return{'sql':_0x26be27[_0x9b74('0x85')]()};})[_0x9b74('0x25')](respondWithResult(_0x335230,null))[_0x9b74('0x4b')](handleError(_0x335230,null));};
\ No newline at end of file
+var _0x0b0e=['IS\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','field','condition','value','options','getFields','length','Sequelize','AnalyticMetric','findAll','keyBy','select','table','function','format','groupBy','group','orderBy','DESC','joins','parse','parentKey','foreignTable','%s.%s\x20=\x20%s.%s','conditions','clone','debug','toString','sequelize','QueryTypes','SELECT','GROUP_CONCAT(%s)','UNIX_TIMESTAMP(%s)','IS\x20NOT\x20NULL','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','from','MetricId','metric','alias','foreignKey','output','web','fullPath','%s-%s.%s','custom','cdr','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','startDate','info','Run\x20Query:','child_process','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','runReport','replace','Limited\x20Query:','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','dbH','sendStatus','status','end','undefined','limit','count','set','json','apply','update','destroy','UserProfileResource','then','error','stack','name','send','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','filter','merge','VIRTUAL','include','rows','catch','show','includeAll','find','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','CustomReports','body','params','preview','join','left_join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','ROUND(%s)','includes'];(function(_0x278bd7,_0x2b4b52){var _0x56f13b=function(_0x44f3d3){while(--_0x44f3d3){_0x278bd7['push'](_0x278bd7['shift']());}};_0x56f13b(++_0x2b4b52);}(_0x0b0e,0x187));var _0xe0b0=function(_0x3da72b,_0x4fd809){_0x3da72b=_0x3da72b-0x0;var _0xc64ac4=_0x0b0e[_0x3da72b];return _0xc64ac4;};'use strict';var emlformat=require(_0xe0b0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xe0b0('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe0b0('0x2'));var moment=require(_0xe0b0('0x3'));var BPromise=require(_0xe0b0('0x4'));var Mustache=require(_0xe0b0('0x5'));var util=require(_0xe0b0('0x6'));var path=require(_0xe0b0('0x7'));var sox=require(_0xe0b0('0x8'));var csv=require(_0xe0b0('0x9'));var ejs=require(_0xe0b0('0xa'));var fs=require('fs');var fs_extra=require(_0xe0b0('0xb'));var _=require(_0xe0b0('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xe0b0('0xd'));var deskjs=require(_0xe0b0('0xe'));var toCsv=require(_0xe0b0('0x9'));var querystring=require(_0xe0b0('0xf'));var Papa=require('papaparse');var Redis=require(_0xe0b0('0x10'));var authService=require(_0xe0b0('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xe0b0('0x12'));var hardwareService=require(_0xe0b0('0x13'));var logger=require('../../config/logger')(_0xe0b0('0x14'));var utils=require(_0xe0b0('0x15'));var config=require(_0xe0b0('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xe0b0('0x17'))['db'];var dbH=require(_0xe0b0('0x17'))[_0xe0b0('0x18')];function respondWithStatusCode(_0x45f914,_0x34fed4){_0x34fed4=_0x34fed4||0xcc;return function(_0x4d2bf7){if(_0x4d2bf7){return _0x45f914[_0xe0b0('0x19')](_0x34fed4);}return _0x45f914[_0xe0b0('0x1a')](_0x34fed4)[_0xe0b0('0x1b')]();};}function respondWithResult(_0x24babd,_0x177c24){_0x177c24=_0x177c24||0xc8;return function(_0x55d884){if(_0x55d884){return _0x24babd[_0xe0b0('0x1a')](_0x177c24)['json'](_0x55d884);}};}function respondWithFilteredResult(_0x35cb40,_0xadee6e){return function(_0x519ae8){if(_0x519ae8){var _0x11fdca=typeof _0xadee6e['offset']===_0xe0b0('0x1c')&&typeof _0xadee6e[_0xe0b0('0x1d')]==='undefined';var _0x54a3eb=_0x519ae8[_0xe0b0('0x1e')];var _0x50a441=_0x11fdca?0x0:_0xadee6e['offset'];var _0x4bce65=_0x11fdca?_0x519ae8[_0xe0b0('0x1e')]:_0xadee6e['offset']+_0xadee6e['limit'];var _0x10cde1;if(_0x4bce65>=_0x54a3eb){_0x4bce65=_0x54a3eb;_0x10cde1=0xc8;}else{_0x10cde1=0xce;}_0x35cb40['status'](_0x10cde1);return _0x35cb40[_0xe0b0('0x1f')]('Content-Range',_0x50a441+'-'+_0x4bce65+'/'+_0x54a3eb)[_0xe0b0('0x20')](_0x519ae8);}return null;};}function patchUpdates(_0x1cd7c4){return function(_0x3e10b3){try{jsonpatch[_0xe0b0('0x21')](_0x3e10b3,_0x1cd7c4,!![]);}catch(_0x2cf6a1){return BPromise['reject'](_0x2cf6a1);}return _0x3e10b3['save']();};}function saveUpdates(_0x2fa820,_0x5512bb){return function(_0x12b260){if(_0x12b260){return _0x12b260[_0xe0b0('0x22')](_0x2fa820)['then'](function(_0x170ad8){return _0x170ad8;});}return null;};}function removeEntity(_0x503883,_0x2208d0){return function(_0x49a727){if(_0x49a727){return _0x49a727[_0xe0b0('0x23')]()['then'](function(){var _0x3e5c88=_0x49a727['get']({'plain':!![]});var _0x4700cc='CustomReports';return db[_0xe0b0('0x24')]['destroy']({'where':{'type':_0x4700cc,'resourceId':_0x3e5c88['id']}})[_0xe0b0('0x25')](function(){return _0x49a727;});})[_0xe0b0('0x25')](function(){_0x503883[_0xe0b0('0x1a')](0xcc)[_0xe0b0('0x1b')]();});}};}function handleEntityNotFound(_0x3ec2,_0x10745d){return function(_0x5200a6){if(!_0x5200a6){_0x3ec2[_0xe0b0('0x19')](0x194);}return _0x5200a6;};}function handleError(_0x1b8aa8,_0x5b7a64){_0x5b7a64=_0x5b7a64||0x1f4;return function(_0x15e13b){logger[_0xe0b0('0x26')](_0x15e13b[_0xe0b0('0x27')]);if(_0x15e13b[_0xe0b0('0x28')]){delete _0x15e13b[_0xe0b0('0x28')];}_0x1b8aa8[_0xe0b0('0x1a')](_0x5b7a64)[_0xe0b0('0x29')](_0x15e13b);};}exports['index']=function(_0x1854b8,_0x3c0109){var _0x48a9b5={},_0x4fe400={},_0x158b7f={'count':0x0,'rows':[]};var _0x33e672=_[_0xe0b0('0x2a')](db[_0xe0b0('0x2b')][_0xe0b0('0x2c')],function(_0x5866e5){return{'name':_0x5866e5[_0xe0b0('0x2d')],'type':_0x5866e5[_0xe0b0('0x2e')][_0xe0b0('0x2f')]};});_0x4fe400[_0xe0b0('0x30')]=_[_0xe0b0('0x2a')](_0x33e672,'name');_0x4fe400[_0xe0b0('0x31')]=_[_0xe0b0('0x32')](_0x1854b8[_0xe0b0('0x31')]);_0x4fe400[_0xe0b0('0x33')]=_[_0xe0b0('0x34')](_0x4fe400[_0xe0b0('0x30')],_0x4fe400[_0xe0b0('0x31')]);_0x48a9b5[_0xe0b0('0x35')]=_[_0xe0b0('0x34')](_0x4fe400[_0xe0b0('0x30')],qs[_0xe0b0('0x36')](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x36')]));_0x48a9b5[_0xe0b0('0x35')]=_0x48a9b5[_0xe0b0('0x35')]['length']?_0x48a9b5[_0xe0b0('0x35')]:_0x4fe400[_0xe0b0('0x30')];if(!_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x37')](_0xe0b0('0x38'))){_0x48a9b5[_0xe0b0('0x1d')]=qs[_0xe0b0('0x1d')](_0x1854b8['query']['limit']);_0x48a9b5['offset']=qs['offset'](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x39')]);}_0x48a9b5[_0xe0b0('0x3a')]=qs['sort'](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3b')]);_0x48a9b5[_0xe0b0('0x3c')]=qs[_0xe0b0('0x33')](_['pick'](_0x1854b8[_0xe0b0('0x31')],_0x4fe400[_0xe0b0('0x33')]),_0x33e672);if(_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3d')]){_0x48a9b5[_0xe0b0('0x3c')]=_[_0xe0b0('0x3e')](_0x48a9b5[_0xe0b0('0x3c')],{'$or':_[_0xe0b0('0x2a')](_0x33e672,function(_0xeaffbb){if(_0xeaffbb['type']!==_0xe0b0('0x3f')){var _0x54f646={};_0x54f646[_0xeaffbb[_0xe0b0('0x28')]]={'$like':'%'+_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3d')]+'%'};return _0x54f646;}})});}_0x48a9b5=_[_0xe0b0('0x3e')]({},_0x48a9b5,_0x1854b8['options']);var _0x3e1b6b={'where':_0x48a9b5[_0xe0b0('0x3c')]};return db[_0xe0b0('0x2b')][_0xe0b0('0x1e')](_0x3e1b6b)[_0xe0b0('0x25')](function(_0x1c12bd){_0x158b7f[_0xe0b0('0x1e')]=_0x1c12bd;if(_0x1854b8[_0xe0b0('0x31')]['includeAll']){_0x48a9b5[_0xe0b0('0x40')]=[{'all':!![]}];}return db[_0xe0b0('0x2b')]['findAll'](_0x48a9b5);})['then'](function(_0x327fb4){_0x158b7f[_0xe0b0('0x41')]=_0x327fb4;return _0x158b7f;})['then'](respondWithFilteredResult(_0x3c0109,_0x48a9b5))[_0xe0b0('0x42')](handleError(_0x3c0109,null));};exports[_0xe0b0('0x43')]=function(_0x6bca5c,_0x1c869d){var _0x1a8cc7={'raw':![],'where':{'id':_0x6bca5c['params']['id']}},_0x5c31b5={};_0x5c31b5['model']=_[_0xe0b0('0x32')](db[_0xe0b0('0x2b')]['rawAttributes']);_0x5c31b5[_0xe0b0('0x31')]=_[_0xe0b0('0x32')](_0x6bca5c[_0xe0b0('0x31')]);_0x5c31b5[_0xe0b0('0x33')]=_[_0xe0b0('0x34')](_0x5c31b5['model'],_0x5c31b5['query']);_0x1a8cc7[_0xe0b0('0x35')]=_[_0xe0b0('0x34')](_0x5c31b5[_0xe0b0('0x30')],qs[_0xe0b0('0x36')](_0x6bca5c[_0xe0b0('0x31')]['fields']));_0x1a8cc7[_0xe0b0('0x35')]=_0x1a8cc7[_0xe0b0('0x35')]['length']?_0x1a8cc7['attributes']:_0x5c31b5['model'];if(_0x6bca5c[_0xe0b0('0x31')][_0xe0b0('0x44')]){_0x1a8cc7[_0xe0b0('0x40')]=[{'all':!![]}];}_0x1a8cc7=_[_0xe0b0('0x3e')]({},_0x1a8cc7,_0x6bca5c['options']);return db[_0xe0b0('0x2b')][_0xe0b0('0x45')](_0x1a8cc7)['then'](handleEntityNotFound(_0x1c869d,null))['then'](respondWithResult(_0x1c869d,null))[_0xe0b0('0x42')](handleError(_0x1c869d,null));};exports[_0xe0b0('0x46')]=function(_0x497f4f,_0x2b1917){return db[_0xe0b0('0x2b')]['create'](_0x497f4f['body'],{})[_0xe0b0('0x25')](function(_0x511679){var _0x165dc8=_0x497f4f[_0xe0b0('0x47')][_0xe0b0('0x48')]({'plain':!![]});if(!_0x165dc8)throw new Error(_0xe0b0('0x49'));if(_0x165dc8[_0xe0b0('0x4a')]===_0xe0b0('0x47')){var _0x5f5486=_0x511679['get']({'plain':!![]});var _0x2ef908='Reports';return db['UserProfileSection'][_0xe0b0('0x45')]({'where':{'name':_0x2ef908,'userProfileId':_0x165dc8[_0xe0b0('0x4b')]},'raw':!![]})['then'](function(_0x4b65d1){if(_0x4b65d1&&_0x4b65d1[_0xe0b0('0x4c')]===0x0){return db[_0xe0b0('0x24')][_0xe0b0('0x46')]({'name':_0x5f5486[_0xe0b0('0x28')],'resourceId':_0x5f5486['id'],'type':_0xe0b0('0x4d'),'sectionId':_0x4b65d1['id']},{})[_0xe0b0('0x25')](function(){return _0x511679;});}else{return _0x511679;}})[_0xe0b0('0x42')](function(_0x4ebb0f){logger[_0xe0b0('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4ebb0f);throw _0x4ebb0f;});}return _0x511679;})[_0xe0b0('0x25')](respondWithResult(_0x2b1917,0xc9))['catch'](handleError(_0x2b1917,null));};exports['update']=function(_0x33822e,_0x237e8c){if(_0x33822e[_0xe0b0('0x4e')]['id']){delete _0x33822e[_0xe0b0('0x4e')]['id'];}return db[_0xe0b0('0x2b')][_0xe0b0('0x45')]({'where':{'id':_0x33822e[_0xe0b0('0x4f')]['id']}})[_0xe0b0('0x25')](handleEntityNotFound(_0x237e8c,null))[_0xe0b0('0x25')](saveUpdates(_0x33822e['body'],null))[_0xe0b0('0x25')](respondWithResult(_0x237e8c,null))['catch'](handleError(_0x237e8c,null));};exports[_0xe0b0('0x23')]=function(_0x3ae36e,_0x30c4a9){return db[_0xe0b0('0x2b')][_0xe0b0('0x45')]({'where':{'id':_0x3ae36e[_0xe0b0('0x4f')]['id']}})['then'](handleEntityNotFound(_0x30c4a9,null))[_0xe0b0('0x25')](removeEntity(_0x30c4a9,null))[_0xe0b0('0x42')](handleError(_0x30c4a9,null));};exports[_0xe0b0('0x50')]=function(_0x271445,_0x3bb6d6){var _0x3b015e=0xa;var _0x234cb7=[_0xe0b0('0x51'),_0xe0b0('0x52'),_0xe0b0('0x53'),_0xe0b0('0x54')];var _0x18ab99={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':_0xe0b0('0x57'),'MAX':_0xe0b0('0x58'),'MIN':_0xe0b0('0x59'),'AVG':_0xe0b0('0x5a'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x1182dc={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':_0xe0b0('0x5e'),'HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x47dcc4=function(_0x139014){return!_[_0xe0b0('0x61')]([_0xe0b0('0x62'),'IS\x20NOT\x20NULL',_0xe0b0('0x63'),_0xe0b0('0x64')],_0x139014);};var _0x309efb=function(_0x3d820c){if(!_0x3d820c||!_0x3d820c[_0xe0b0('0x65')]['length']){return'';}for(var _0x370f8c='(',_0x242120=0x0;_0x242120<_0x3d820c[_0xe0b0('0x65')]['length'];_0x242120+=0x1){_0x242120>0x0&&(_0x370f8c+='\x20'+_0x3d820c[_0xe0b0('0x66')]+'\x20');_0x370f8c+=_0x3d820c[_0xe0b0('0x65')][_0x242120]['group']?_0x309efb(_0x3d820c[_0xe0b0('0x65')][_0x242120]['group']):_0x3d820c['rules'][_0x242120][_0xe0b0('0x67')]+'\x20'+_0x3d820c['rules'][_0x242120]['condition']+(_0x47dcc4(_0x3d820c[_0xe0b0('0x65')][_0x242120][_0xe0b0('0x68')])?'\x20'+_0x3d820c[_0xe0b0('0x65')][_0x242120][_0xe0b0('0x69')]:'');}return _0x370f8c+')';};var _0x5a7913={'where':{'id':_0x271445[_0xe0b0('0x4f')]['id']}},_0x3679e0,_0x2287a5,_0x3e7fb4,_0x41ec8e,_0x1b29c;_0x5a7913=_[_0xe0b0('0x3e')]({},_0x5a7913,_0x271445[_0xe0b0('0x6a')]);return db['AnalyticCustomReport']['find'](_0x5a7913)[_0xe0b0('0x25')](function(_0x35144f){if(_0x35144f){_0x3679e0=_0x35144f;return _0x35144f[_0xe0b0('0x6b')]();}return null;})['then'](function(_0x49b754){if(_0x49b754){if(!_0x49b754[_0xe0b0('0x6c')]){throw new db[(_0xe0b0('0x6d'))]['ValidationErrorItem']('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x2287a5=_0x49b754;return db[_0xe0b0('0x6e')][_0xe0b0('0x6f')]({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x29175a){if(_0x29175a){_0x3e7fb4=_[_0xe0b0('0x70')](_0x29175a,'id');var _0x15f0f8;var _0x1bc7a6=squel[_0xe0b0('0x71')]();_0x1bc7a6['from'](_0x3679e0[_0xe0b0('0x72')]);for(var _0x12e245=0x0;_0x12e245<_0x2287a5[_0xe0b0('0x6c')];_0x12e245+=0x1){_0x15f0f8=_0x2287a5[_0x12e245]['MetricId']?_0x3e7fb4[_0x2287a5[_0x12e245]['MetricId']]['metric']:_0x2287a5[_0x12e245]['field'];_0x15f0f8=_0x2287a5[_0x12e245]['function']?_['replace'](_0x18ab99[_0x2287a5[_0x12e245][_0xe0b0('0x73')]],'%s',_0x15f0f8):_0x15f0f8;_0x15f0f8=_0x2287a5[_0x12e245]['format']?_['replace'](_0x1182dc[_0x2287a5[_0x12e245][_0xe0b0('0x74')]],'%s',_0x15f0f8):_0x15f0f8;if(_0x2287a5[_0x12e245][_0xe0b0('0x75')]){_0x1bc7a6[_0xe0b0('0x76')](_0x15f0f8);}_0x2287a5[_0x12e245][_0xe0b0('0x77')]&&_0x1bc7a6[_0xe0b0('0x3a')](_0x15f0f8,_0x2287a5[_0x12e245][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x1bc7a6[_0xe0b0('0x67')](_0x15f0f8,_0x2287a5[_0x12e245]['alias']||_0x15f0f8);}if(_0x3679e0[_0xe0b0('0x79')]){_0x3679e0[_0xe0b0('0x79')]=JSON[_0xe0b0('0x7a')](_0x3679e0[_0xe0b0('0x79')]);for(var _0x173ed8=0x0;_0x173ed8<_0x3679e0[_0xe0b0('0x79')][_0xe0b0('0x6c')];_0x173ed8+=0x1){if(_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x2e')]&&_['includes'](_0x234cb7,_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x2e')])&&_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7b')]&&_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x7c')]&&_0x3679e0[_0xe0b0('0x79')][_0x173ed8]['foreignKey']){_0x1bc7a6[_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x2e')]](_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7c')],null,util[_0xe0b0('0x74')](_0xe0b0('0x7d'),_0x3679e0[_0xe0b0('0x72')],_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7b')],_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7c')],_0x3679e0['joins'][_0x173ed8]['foreignKey']));}}}if(_0x3679e0[_0xe0b0('0x7e')]){_0x3679e0['conditions']=JSON['parse'](_0x3679e0['conditions']);_0x1bc7a6['where'](_0x309efb(_0x3679e0[_0xe0b0('0x7e')]['group']));}_0x1b29c=_0x1bc7a6[_0xe0b0('0x7f')]();_0x1bc7a6[_0xe0b0('0x1d')](_0x3b015e);_0x1bc7a6[_0xe0b0('0x39')](0x0);logger[_0xe0b0('0x80')]('Limited\x20Query:',_0x1bc7a6[_0xe0b0('0x81')]());return dbH[_0xe0b0('0x82')]['query'](_0x1bc7a6[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});}})[_0xe0b0('0x25')](respondWithResult(_0x3bb6d6,null))['catch'](handleError(_0x3bb6d6,null));};function runReport(_0x55d3f8,_0x55aef7,_0x545694){var _0x5c258b=_0x55aef7[_0xe0b0('0x28')];var _0x567e1a=0xa;var _0x3c09af=['join',_0xe0b0('0x52'),_0xe0b0('0x53'),_0xe0b0('0x54')];var _0x380b4c={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0xe0b0('0x85'),'GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x4377f7={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':'DATE(%s)','HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':_0xe0b0('0x86')};var _0xc6090e=function(_0x154e6d){return!_[_0xe0b0('0x61')]([_0xe0b0('0x62'),_0xe0b0('0x87'),_0xe0b0('0x63'),'IS\x20NOT\x20EMPTY'],_0x154e6d);};var _0x589c47=function(_0x6e0e9){if(!_0x6e0e9||!_0x6e0e9[_0xe0b0('0x65')]['length']){return'';}for(var _0x7feff4='(',_0x4593f1=0x0;_0x4593f1<_0x6e0e9[_0xe0b0('0x65')][_0xe0b0('0x6c')];_0x4593f1+=0x1){_0x4593f1>0x0&&(_0x7feff4+='\x20'+_0x6e0e9[_0xe0b0('0x66')]+'\x20');_0x7feff4+=_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x76')]?_0x589c47(_0x6e0e9[_0xe0b0('0x65')][_0x4593f1]['group']):_0x6e0e9['rules'][_0x4593f1]['field']+'\x20'+_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x68')]+(_0xc6090e(_0x6e0e9['rules'][_0x4593f1][_0xe0b0('0x68')])?'\x20'+_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x69')]:'');}return _0x7feff4+')';};var _0x328832={'where':{'id':_0x55d3f8['id']}},_0x5c45ae,_0x56c4b9,_0x4e1fb1,_0x22029a,_0x266835;_0x328832=_['merge']({},_0x328832,_0x545694);return db[_0xe0b0('0x2b')][_0xe0b0('0x45')](_0x328832)['then'](function(_0x576482){if(_0x576482){_0x5c45ae=_0x576482;return _0x576482[_0xe0b0('0x6b')]();}return null;})['then'](function(_0x251195){if(_0x251195){if(!_0x251195['length']){throw new db[(_0xe0b0('0x6d'))][(_0xe0b0('0x88'))](_0xe0b0('0x89'),0x193);}_0x56c4b9=_0x251195;return db[_0xe0b0('0x6e')][_0xe0b0('0x6f')]({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x434dfa){if(_0x434dfa){_0x4e1fb1=_[_0xe0b0('0x70')](_0x434dfa,'id');var _0xf76449;var _0x48497e=squel[_0xe0b0('0x71')]();_0x48497e[_0xe0b0('0x8a')](_0x5c45ae[_0xe0b0('0x72')]);for(var _0x4e19f4=0x0;_0x4e19f4<_0x56c4b9[_0xe0b0('0x6c')];_0x4e19f4+=0x1){_0xf76449=_0x56c4b9[_0x4e19f4]['MetricId']?_0x4e1fb1[_0x56c4b9[_0x4e19f4][_0xe0b0('0x8b')]][_0xe0b0('0x8c')]:_0x56c4b9[_0x4e19f4]['field'];_0xf76449=_0x56c4b9[_0x4e19f4][_0xe0b0('0x73')]?_['replace'](_0x380b4c[_0x56c4b9[_0x4e19f4]['function']],'%s',_0xf76449):_0xf76449;_0xf76449=_0x56c4b9[_0x4e19f4][_0xe0b0('0x74')]?_['replace'](_0x4377f7[_0x56c4b9[_0x4e19f4]['format']],'%s',_0xf76449):_0xf76449;if(_0x56c4b9[_0x4e19f4][_0xe0b0('0x75')]){_0x48497e[_0xe0b0('0x76')](_0xf76449);}_0x56c4b9[_0x4e19f4][_0xe0b0('0x77')]&&_0x48497e[_0xe0b0('0x3a')](_0xf76449,_0x56c4b9[_0x4e19f4][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x48497e['field'](_0xf76449,_0x56c4b9[_0x4e19f4][_0xe0b0('0x8d')]||_0xf76449);}if(_0x5c45ae[_0xe0b0('0x79')]){_0x5c45ae[_0xe0b0('0x79')]=JSON['parse'](_0x5c45ae[_0xe0b0('0x79')]);for(var _0x447641=0x0;_0x447641<_0x5c45ae['joins']['length'];_0x447641+=0x1){if(_0x5c45ae[_0xe0b0('0x79')][_0x447641]['type']&&_[_0xe0b0('0x61')](_0x3c09af,_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x2e')])&&_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7b')]&&_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')]&&_0x5c45ae['joins'][_0x447641][_0xe0b0('0x8e')]){_0x48497e[_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x2e')]](_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')],null,util['format']('%s.%s\x20=\x20%s.%s',_0x5c45ae[_0xe0b0('0x72')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7b')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x8e')]));}}}if(_0x5c45ae[_0xe0b0('0x7e')]){_0x5c45ae[_0xe0b0('0x7e')]=JSON[_0xe0b0('0x7a')](_0x5c45ae['conditions']);_0x48497e[_0xe0b0('0x3c')](_0x589c47(_0x5c45ae[_0xe0b0('0x7e')][_0xe0b0('0x76')]));}_0x266835=_0x48497e[_0xe0b0('0x7f')]();_0x48497e['limit'](_0x567e1a);_0x48497e[_0xe0b0('0x39')](0x0);return;}})[_0xe0b0('0x25')](function(){if(_0x55aef7[_0xe0b0('0x8f')]===_0xe0b0('0x90')){return null;}var _0x476763=_['merge'](_0x55aef7,{'name':_0x55aef7[_0xe0b0('0x91')]||_0x55aef7['name']||_0x5c45ae[_0xe0b0('0x28')],'basename':_0x5c258b,'savename':util[_0xe0b0('0x74')](_0xe0b0('0x92'),_0x55aef7[_0xe0b0('0x28')]||_0x5c45ae[_0xe0b0('0x28')],require('randomstring')['generate'](0x4),_0x55aef7[_0xe0b0('0x8f')]||'csv'),'reportId':_0x5c45ae['id'],'reportType':_0xe0b0('0x93')});return db['AnalyticExtractedReport'][_0xe0b0('0x46')](_0x476763,{'raw':!![]});})[_0xe0b0('0x25')](function(_0x205c53){if(_0x5c45ae[_0xe0b0('0x72')]===_0xe0b0('0x94')){_0x266835[_0xe0b0('0x3c')](_0x5c45ae[_0xe0b0('0x72')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x55aef7['startDate'],_0x55aef7[_0xe0b0('0x95')]);}else{_0x266835[_0xe0b0('0x3c')](_0x5c45ae[_0xe0b0('0x72')]+_0xe0b0('0x96'),_0x55aef7[_0xe0b0('0x97')],_0x55aef7[_0xe0b0('0x95')]);}if(_0x205c53){logger[_0xe0b0('0x98')](_0xe0b0('0x99'),_0x266835[_0xe0b0('0x81')]());require(_0xe0b0('0x9a'))['fork'](path['join'](__dirname,_0xe0b0('0x9b'),_0x205c53[_0xe0b0('0x8f')]),[_0x205c53['id'],_0x266835[_0xe0b0('0x81')](),path[_0xe0b0('0x51')](__dirname,_0xe0b0('0x9c'),_0x205c53[_0xe0b0('0x9d')]),_0x5c258b]);return _0x205c53;}else{var _0x33b67a=squel['select']();_0x33b67a['from']('('+_0x266835[_0xe0b0('0x81')]()+')',_0xe0b0('0x9e'));_0x33b67a[_0xe0b0('0x67')](_0xe0b0('0x9f'),_0xe0b0('0x1e'));_0x266835[_0xe0b0('0x1d')](_0x55aef7[_0xe0b0('0x1d')]||_0x567e1a);_0x266835[_0xe0b0('0x39')](_0x55aef7[_0xe0b0('0x39')]||0x0);return dbH[_0xe0b0('0x82')]['query'](_0x33b67a[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')]['QueryTypes'][_0xe0b0('0x84')]})[_0xe0b0('0x25')](function(_0x3615f9){if(!_0x3615f9[_0xe0b0('0x6c')]){_0x22029a=0x0;}else{_0x22029a=_0x3615f9[0x0][_0xe0b0('0x1e')]||0x0;}return dbH['sequelize'][_0xe0b0('0x31')](_0x266835[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});})['then'](function(_0x475404){return{'rows':_0x475404||[],'count':_0x22029a};});}});}exports['run']=function(_0x44e05a,_0x42dfa9){return runReport(_0x44e05a[_0xe0b0('0x4f')],_0x44e05a['query'],_0x44e05a['options'])[_0xe0b0('0x25')](respondWithResult(_0x42dfa9,null))[_0xe0b0('0x42')](handleError(_0x42dfa9,null));};exports[_0xe0b0('0xa0')]=runReport;exports['query']=function(_0x4d372a,_0x5da5eb){var _0x5175e1=0xa;var _0x57694c=['join',_0xe0b0('0x52'),_0xe0b0('0x53'),'cross_join'];var _0x121257={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':_0xe0b0('0x57'),'MAX':_0xe0b0('0x58'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0xe0b0('0x85'),'GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x52dfd8={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':_0xe0b0('0x5e'),'HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':_0xe0b0('0x86')};var _0x1b8d4a=function(_0x51b616){return!_['includes'](['IS\x20NULL',_0xe0b0('0x87'),_0xe0b0('0x63'),_0xe0b0('0x64')],_0x51b616);};var _0x40809f=function(_0x266cb5){if(!_0x266cb5||!_0x266cb5[_0xe0b0('0x65')][_0xe0b0('0x6c')]){return'';}for(var _0x35f081='(',_0x5e4339=0x0;_0x5e4339<_0x266cb5['rules'][_0xe0b0('0x6c')];_0x5e4339+=0x1){_0x5e4339>0x0&&(_0x35f081+='\x20'+_0x266cb5[_0xe0b0('0x66')]+'\x20');_0x35f081+=_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['group']?_0x40809f(_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x76')]):_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['field']+'\x20'+_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['condition']+(_0x1b8d4a(_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x68')])?'\x20'+_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x69')]:'');}return _0x35f081+')';};var _0x3b133a={'where':{'id':_0x4d372a['params']['id']}},_0x26df60,_0x12e46f,_0x55beb2,_0x287af5,_0xb71713;_0x3b133a=_[_0xe0b0('0x3e')]({},_0x3b133a,_0x4d372a[_0xe0b0('0x6a')]);return db[_0xe0b0('0x2b')]['find'](_0x3b133a)[_0xe0b0('0x25')](function(_0x692a95){if(_0x692a95){_0x26df60=_0x692a95;return _0x692a95[_0xe0b0('0x6b')]();}return null;})['then'](function(_0xed8461){if(_0xed8461){if(!_0xed8461[_0xe0b0('0x6c')]){throw new db[(_0xe0b0('0x6d'))][(_0xe0b0('0x88'))](_0xe0b0('0x89'),0x193);}_0x12e46f=_0xed8461;return db[_0xe0b0('0x6e')]['findAll']({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x701ba){if(_0x701ba){_0x55beb2=_[_0xe0b0('0x70')](_0x701ba,'id');var _0x26315d;var _0x11452e=squel[_0xe0b0('0x71')]();_0x11452e[_0xe0b0('0x8a')](_0x26df60[_0xe0b0('0x72')]);for(var _0xf87779=0x0;_0xf87779<_0x12e46f[_0xe0b0('0x6c')];_0xf87779+=0x1){_0x26315d=_0x12e46f[_0xf87779][_0xe0b0('0x8b')]?_0x55beb2[_0x12e46f[_0xf87779]['MetricId']][_0xe0b0('0x8c')]:_0x12e46f[_0xf87779]['field'];_0x26315d=_0x12e46f[_0xf87779]['function']?_[_0xe0b0('0xa1')](_0x121257[_0x12e46f[_0xf87779][_0xe0b0('0x73')]],'%s',_0x26315d):_0x26315d;_0x26315d=_0x12e46f[_0xf87779]['format']?_[_0xe0b0('0xa1')](_0x52dfd8[_0x12e46f[_0xf87779][_0xe0b0('0x74')]],'%s',_0x26315d):_0x26315d;if(_0x12e46f[_0xf87779][_0xe0b0('0x75')]){_0x11452e[_0xe0b0('0x76')](_0x26315d);}_0x12e46f[_0xf87779][_0xe0b0('0x77')]&&_0x11452e[_0xe0b0('0x3a')](_0x26315d,_0x12e46f[_0xf87779][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x11452e[_0xe0b0('0x67')](_0x26315d,_0x12e46f[_0xf87779]['alias']||_0x26315d);}if(_0x26df60[_0xe0b0('0x79')]){_0x26df60[_0xe0b0('0x79')]=JSON[_0xe0b0('0x7a')](_0x26df60[_0xe0b0('0x79')]);for(var _0x48c009=0x0;_0x48c009<_0x26df60['joins'][_0xe0b0('0x6c')];_0x48c009+=0x1){if(_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')]&&_[_0xe0b0('0x61')](_0x57694c,_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')])&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7b')]&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')]&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x8e')]){_0x11452e[_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')]](_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')],null,util[_0xe0b0('0x74')](_0xe0b0('0x7d'),_0x26df60[_0xe0b0('0x72')],_0x26df60['joins'][_0x48c009][_0xe0b0('0x7b')],_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')],_0x26df60['joins'][_0x48c009][_0xe0b0('0x8e')]));}}}if(_0x26df60[_0xe0b0('0x7e')]){_0x26df60[_0xe0b0('0x7e')]=JSON[_0xe0b0('0x7a')](_0x26df60[_0xe0b0('0x7e')]);_0x11452e[_0xe0b0('0x3c')](_0x40809f(_0x26df60[_0xe0b0('0x7e')]['group']));}_0xb71713=_0x11452e[_0xe0b0('0x7f')]();_0x11452e['limit'](_0x5175e1);_0x11452e[_0xe0b0('0x39')](0x0);logger['debug'](_0xe0b0('0xa2'),_0x11452e[_0xe0b0('0x81')]());return dbH['sequelize'][_0xe0b0('0x31')](_0x11452e['toString'](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});}})[_0xe0b0('0x25')](function(){return{'sql':_0xb71713[_0xe0b0('0x81')]()};})[_0xe0b0('0x25')](respondWithResult(_0x5da5eb,null))[_0xe0b0('0x42')](handleError(_0x5da5eb,null));};
\ No newline at end of file