Built motion from commit (unavailable).|2.5.23
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index c983375..cfd4e7a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9c45=['AnalyticCustomReport','rawAttributes','key','model','keys','query','filters','intersection','attributes','fields','limit','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','show','params','length','catch','create','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','find','join','left_join','right_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','GROUP_CONCAT(%s)','SEC_TO_TIME(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','rules','operator','group','condition','getFields','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','select','table','MetricId','metric','field','function','replace','format','groupBy','orderBy','DESC','alias','joins','parse','parentKey','foreignTable','foreignKey','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','SELECT','MAX(%s)','MIN(%s)','AVG(%s)','DATE(%s)','HOUR(%s)','IS\x20NOT\x20EMPTY','value','keyBy','from','%s.%s\x20=\x20%s.%s','Sequelize','No\x20available\x20data','output','fullPath','%s-%s.%s','randomstring','generate','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','fork','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','run','runReport','cross_join','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','html-pdf','eml-format','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','lodash','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../mysqldb','dbH','sendStatus','status','end','json','count','offset','set','Content-Range','reject','destroy','then','CustomReports','UserProfileResource','stack','name','send','index','map'];(function(_0x4687df,_0x12099c){var _0x32eaef=function(_0x2387db){while(--_0x2387db){_0x4687df['push'](_0x4687df['shift']());}};_0x32eaef(++_0x12099c);}(_0x9c45,0x119));var _0x59c4=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x9c45[_0x3dd15e];return _0x231fd0;};'use strict';var pdf=require(_0x59c4('0x0'));var emlformat=require(_0x59c4('0x1'));var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x59c4('0x2'));var rp=require(_0x59c4('0x3'));var moment=require('moment');var BPromise=require(_0x59c4('0x4'));var Mustache=require('mustache');var util=require(_0x59c4('0x5'));var path=require(_0x59c4('0x6'));var sox=require(_0x59c4('0x7'));var csv=require(_0x59c4('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x59c4('0x9'));var squel=require('squel');var crypto=require(_0x59c4('0xa'));var jsforce=require(_0x59c4('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x59c4('0xc'));var Papa=require(_0x59c4('0xd'));var Redis=require('ioredis');var authService=require(_0x59c4('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0x59c4('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x59c4('0x10'))(_0x59c4('0x11'));var utils=require(_0x59c4('0x12'));var config=require('../../config/environment');var db=require(_0x59c4('0x13'))['db'];var dbH=require(_0x59c4('0x13'))[_0x59c4('0x14')];function respondWithStatusCode(_0x4168ce,_0x185836){_0x185836=_0x185836||0xcc;return function(_0x1ab3c7){if(_0x1ab3c7){return _0x4168ce[_0x59c4('0x15')](_0x185836);}return _0x4168ce[_0x59c4('0x16')](_0x185836)[_0x59c4('0x17')]();};}function respondWithResult(_0x521a92,_0x47d88a){_0x47d88a=_0x47d88a||0xc8;return function(_0x3d83f9){if(_0x3d83f9){return _0x521a92[_0x59c4('0x16')](_0x47d88a)[_0x59c4('0x18')](_0x3d83f9);}};}function respondWithFilteredResult(_0x8ec858,_0x5109e5){return function(_0x45bcdb){if(_0x45bcdb){var _0x9dfc1e=_0x45bcdb[_0x59c4('0x19')],_0x161a57=_0x5109e5['offset'],_0x1467ab=_0x5109e5[_0x59c4('0x1a')]+_0x5109e5['limit'],_0x2629ee;if(_0x1467ab>=_0x9dfc1e){_0x1467ab=_0x9dfc1e;_0x2629ee=0xc8;}else{_0x2629ee=0xce;}_0x8ec858[_0x59c4('0x16')](_0x2629ee);return _0x8ec858[_0x59c4('0x1b')](_0x59c4('0x1c'),_0x161a57+'-'+_0x1467ab+'/'+_0x9dfc1e)[_0x59c4('0x18')](_0x45bcdb);}return null;};}function patchUpdates(_0xb57b25){return function(_0x5b0cbd){try{jsonpatch['apply'](_0x5b0cbd,_0xb57b25,!![]);}catch(_0x43fe24){return BPromise[_0x59c4('0x1d')](_0x43fe24);}return _0x5b0cbd['save']();};}function saveUpdates(_0x172797,_0x1b5078){return function(_0x3c0481){if(_0x3c0481){return _0x3c0481['update'](_0x172797)['then'](function(_0x328771){return _0x328771;});}return null;};}function removeEntity(_0x170762,_0x3fb384){return function(_0x3470de){if(_0x3470de){return _0x3470de[_0x59c4('0x1e')]()[_0x59c4('0x1f')](function(){var _0xbb1b1e=_0x3470de['get']({'plain':!![]});var _0x2a89f7=_0x59c4('0x20');return db[_0x59c4('0x21')][_0x59c4('0x1e')]({'where':{'type':_0x2a89f7,'resourceId':_0xbb1b1e['id']}})['then'](function(){return _0x3470de;});})[_0x59c4('0x1f')](function(){_0x170762[_0x59c4('0x16')](0xcc)[_0x59c4('0x17')]();});}};}function handleEntityNotFound(_0xd1ddc6,_0x4cc88b){return function(_0x4e5809){if(!_0x4e5809){_0xd1ddc6['sendStatus'](0x194);}return _0x4e5809;};}function handleError(_0x44a632,_0x18dc80){_0x18dc80=_0x18dc80||0x1f4;return function(_0xfb598d){logger['error'](_0xfb598d[_0x59c4('0x22')]);if(_0xfb598d[_0x59c4('0x23')]){delete _0xfb598d[_0x59c4('0x23')];}_0x44a632[_0x59c4('0x16')](_0x18dc80)[_0x59c4('0x24')](_0xfb598d);};}exports[_0x59c4('0x25')]=function(_0x527731,_0x3edd71){var _0x852c79={},_0xdd30a9={},_0x1290de={'count':0x0,'rows':[]};var _0x5a33c1=_[_0x59c4('0x26')](db[_0x59c4('0x27')][_0x59c4('0x28')],function(_0x114c63){return{'name':_0x114c63['fieldName'],'type':_0x114c63['type'][_0x59c4('0x29')]};});_0xdd30a9[_0x59c4('0x2a')]=_[_0x59c4('0x26')](_0x5a33c1,_0x59c4('0x23'));_0xdd30a9['query']=_[_0x59c4('0x2b')](_0x527731[_0x59c4('0x2c')]);_0xdd30a9[_0x59c4('0x2d')]=_[_0x59c4('0x2e')](_0xdd30a9[_0x59c4('0x2a')],_0xdd30a9['query']);_0x852c79[_0x59c4('0x2f')]=_[_0x59c4('0x2e')](_0xdd30a9[_0x59c4('0x2a')],qs[_0x59c4('0x30')](_0x527731[_0x59c4('0x2c')][_0x59c4('0x30')]));_0x852c79[_0x59c4('0x2f')]=_0x852c79['attributes']['length']?_0x852c79[_0x59c4('0x2f')]:_0xdd30a9[_0x59c4('0x2a')];if(!_0x527731['query']['hasOwnProperty']('nolimit')){_0x852c79[_0x59c4('0x31')]=qs['limit'](_0x527731[_0x59c4('0x2c')][_0x59c4('0x31')]);_0x852c79[_0x59c4('0x1a')]=qs[_0x59c4('0x1a')](_0x527731[_0x59c4('0x2c')][_0x59c4('0x1a')]);}_0x852c79[_0x59c4('0x32')]=qs[_0x59c4('0x33')](_0x527731[_0x59c4('0x2c')][_0x59c4('0x33')]);_0x852c79[_0x59c4('0x34')]=qs[_0x59c4('0x2d')](_[_0x59c4('0x35')](_0x527731[_0x59c4('0x2c')],_0xdd30a9[_0x59c4('0x2d')]));if(_0x527731[_0x59c4('0x2c')][_0x59c4('0x36')]){_0x852c79[_0x59c4('0x34')]=_[_0x59c4('0x37')](_0x852c79[_0x59c4('0x34')],{'$or':_[_0x59c4('0x26')](_0x5a33c1,function(_0x5a4426){if(_0x5a4426[_0x59c4('0x38')]!==_0x59c4('0x39')){var _0x5634f7={};_0x5634f7[_0x5a4426[_0x59c4('0x23')]]={'$like':'%'+_0x527731[_0x59c4('0x2c')][_0x59c4('0x36')]+'%'};return _0x5634f7;}})});}_0x852c79=_[_0x59c4('0x37')]({},_0x852c79,_0x527731[_0x59c4('0x3a')]);var _0x3b7a9f={'where':_0x852c79[_0x59c4('0x34')]};return db['AnalyticCustomReport'][_0x59c4('0x19')](_0x3b7a9f)[_0x59c4('0x1f')](function(_0x1546c5){_0x1290de[_0x59c4('0x19')]=_0x1546c5;if(_0x527731[_0x59c4('0x2c')][_0x59c4('0x3b')]){_0x852c79[_0x59c4('0x3c')]=[{'all':!![]}];}return db[_0x59c4('0x27')][_0x59c4('0x3d')](_0x852c79);})[_0x59c4('0x1f')](function(_0x33f843){_0x1290de[_0x59c4('0x3e')]=_0x33f843;return _0x1290de;})[_0x59c4('0x1f')](respondWithFilteredResult(_0x3edd71,_0x852c79))['catch'](handleError(_0x3edd71,null));};exports[_0x59c4('0x3f')]=function(_0xbf452f,_0x571a35){var _0x11701e={'raw':![],'where':{'id':_0xbf452f[_0x59c4('0x40')]['id']}},_0x3c30f4={};_0x3c30f4['model']=_[_0x59c4('0x2b')](db['AnalyticCustomReport']['rawAttributes']);_0x3c30f4[_0x59c4('0x2c')]=_[_0x59c4('0x2b')](_0xbf452f['query']);_0x3c30f4['filters']=_[_0x59c4('0x2e')](_0x3c30f4[_0x59c4('0x2a')],_0x3c30f4['query']);_0x11701e[_0x59c4('0x2f')]=_[_0x59c4('0x2e')](_0x3c30f4[_0x59c4('0x2a')],qs[_0x59c4('0x30')](_0xbf452f['query'][_0x59c4('0x30')]));_0x11701e[_0x59c4('0x2f')]=_0x11701e['attributes'][_0x59c4('0x41')]?_0x11701e[_0x59c4('0x2f')]:_0x3c30f4[_0x59c4('0x2a')];if(_0xbf452f['query'][_0x59c4('0x3b')]){_0x11701e[_0x59c4('0x3c')]=[{'all':!![]}];}_0x11701e=_[_0x59c4('0x37')]({},_0x11701e,_0xbf452f[_0x59c4('0x3a')]);return db[_0x59c4('0x27')]['find'](_0x11701e)[_0x59c4('0x1f')](handleEntityNotFound(_0x571a35,null))[_0x59c4('0x1f')](respondWithResult(_0x571a35,null))[_0x59c4('0x42')](handleError(_0x571a35,null));};exports[_0x59c4('0x43')]=function(_0xd286f6,_0x72a44a){return db[_0x59c4('0x27')]['create'](_0xd286f6['body'],{})[_0x59c4('0x1f')](function(_0x1d36d9){var _0x5077d4=_0xd286f6['user'][_0x59c4('0x44')]({'plain':!![]});if(!_0x5077d4)throw new Error(_0x59c4('0x45'));if(_0x5077d4[_0x59c4('0x46')]===_0x59c4('0x47')){var _0x59b908=_0x1d36d9[_0x59c4('0x44')]({'plain':!![]});var _0x4ae62f='Reports';return db['UserProfileSection']['find']({'where':{'name':_0x4ae62f,'userProfileId':_0x5077d4['userProfileId']},'raw':!![]})[_0x59c4('0x1f')](function(_0x1f4ab3){if(_0x1f4ab3&&_0x1f4ab3[_0x59c4('0x48')]===0x0){return db[_0x59c4('0x21')][_0x59c4('0x43')]({'name':_0x59b908['name'],'resourceId':_0x59b908['id'],'type':'CustomReports','sectionId':_0x1f4ab3['id']},{})['then'](function(){return _0x1d36d9;});}else{return _0x1d36d9;}})['catch'](function(_0x2c0bbd){logger[_0x59c4('0x49')](_0x59c4('0x4a'),_0x2c0bbd);throw _0x2c0bbd;});}return _0x1d36d9;})['then'](respondWithResult(_0x72a44a,0xc9))[_0x59c4('0x42')](handleError(_0x72a44a,null));};exports['update']=function(_0x36fe81,_0x2fa469){if(_0x36fe81['body']['id']){delete _0x36fe81[_0x59c4('0x4b')]['id'];}return db['AnalyticCustomReport'][_0x59c4('0x4c')]({'where':{'id':_0x36fe81[_0x59c4('0x40')]['id']}})[_0x59c4('0x1f')](handleEntityNotFound(_0x2fa469,null))[_0x59c4('0x1f')](saveUpdates(_0x36fe81[_0x59c4('0x4b')],null))[_0x59c4('0x1f')](respondWithResult(_0x2fa469,null))[_0x59c4('0x42')](handleError(_0x2fa469,null));};exports[_0x59c4('0x1e')]=function(_0x1433a4,_0x1c41cb){return db[_0x59c4('0x27')][_0x59c4('0x4c')]({'where':{'id':_0x1433a4[_0x59c4('0x40')]['id']}})[_0x59c4('0x1f')](handleEntityNotFound(_0x1c41cb,null))[_0x59c4('0x1f')](removeEntity(_0x1c41cb,null))['catch'](handleError(_0x1c41cb,null));};exports['preview']=function(_0x27893a,_0x525145){var _0x42be01=0xa;var _0x3c175b=[_0x59c4('0x4d'),_0x59c4('0x4e'),_0x59c4('0x4f'),'cross_join'];var _0x35a431={'SUM':_0x59c4('0x50'),'COUNT':_0x59c4('0x51'),'COUNT DISTINCT':_0x59c4('0x52'),'MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0x59c4('0x53'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x1f0453={'SEC_TO_TIME':_0x59c4('0x54'),'DATE':'DATE(%s)','HOUR':'HOUR(%s)','ROUND':_0x59c4('0x55'),'UNIX_TIMESTAMP':_0x59c4('0x56')};var _0x159bec=function(_0x12f6e8){return!_[_0x59c4('0x57')]([_0x59c4('0x58'),_0x59c4('0x59'),_0x59c4('0x5a'),'IS\x20NOT\x20EMPTY'],_0x12f6e8);};var _0x5de981=function(_0x18fc53){if(!_0x18fc53||!_0x18fc53[_0x59c4('0x5b')][_0x59c4('0x41')]){return'';}for(var _0x5486f8='(',_0x3e5d0d=0x0;_0x3e5d0d<_0x18fc53[_0x59c4('0x5b')][_0x59c4('0x41')];_0x3e5d0d+=0x1){_0x3e5d0d>0x0&&(_0x5486f8+='\x20'+_0x18fc53[_0x59c4('0x5c')]+'\x20');_0x5486f8+=_0x18fc53[_0x59c4('0x5b')][_0x3e5d0d][_0x59c4('0x5d')]?_0x5de981(_0x18fc53[_0x59c4('0x5b')][_0x3e5d0d][_0x59c4('0x5d')]):_0x18fc53[_0x59c4('0x5b')][_0x3e5d0d]['field']+'\x20'+_0x18fc53[_0x59c4('0x5b')][_0x3e5d0d][_0x59c4('0x5e')]+(_0x159bec(_0x18fc53[_0x59c4('0x5b')][_0x3e5d0d][_0x59c4('0x5e')])?'\x20'+_0x18fc53[_0x59c4('0x5b')][_0x3e5d0d]['value']:'');}return _0x5486f8+')';};var _0x493d48={'where':{'id':_0x27893a[_0x59c4('0x40')]['id']}},_0x4bf3fe,_0x51569e,_0x4e5453,_0x5d156c,_0x592122;_0x493d48=_['merge']({},_0x493d48,_0x27893a[_0x59c4('0x3a')]);return db['AnalyticCustomReport'][_0x59c4('0x4c')](_0x493d48)[_0x59c4('0x1f')](function(_0x527270){if(_0x527270){_0x4bf3fe=_0x527270;return _0x527270[_0x59c4('0x5f')]();}return null;})[_0x59c4('0x1f')](function(_0x4b7948){if(_0x4b7948){if(!_0x4b7948['length']){throw new db['Sequelize'][(_0x59c4('0x60'))](_0x59c4('0x61'),0x193);}_0x51569e=_0x4b7948;return db[_0x59c4('0x62')][_0x59c4('0x3d')]({'raw':!![]});}return null;})['then'](function(_0x4cac80){if(_0x4cac80){_0x4e5453=_['keyBy'](_0x4cac80,'id');var _0x24ec5d;var _0x3440e4=squel[_0x59c4('0x63')]();_0x3440e4['from'](_0x4bf3fe[_0x59c4('0x64')]);for(var _0x44a165=0x0;_0x44a165<_0x51569e[_0x59c4('0x41')];_0x44a165+=0x1){_0x24ec5d=_0x51569e[_0x44a165][_0x59c4('0x65')]?_0x4e5453[_0x51569e[_0x44a165][_0x59c4('0x65')]][_0x59c4('0x66')]:_0x51569e[_0x44a165][_0x59c4('0x67')];_0x24ec5d=_0x51569e[_0x44a165][_0x59c4('0x68')]?_[_0x59c4('0x69')](_0x35a431[_0x51569e[_0x44a165][_0x59c4('0x68')]],'%s',_0x24ec5d):_0x24ec5d;_0x24ec5d=_0x51569e[_0x44a165][_0x59c4('0x6a')]?_['replace'](_0x1f0453[_0x51569e[_0x44a165]['format']],'%s',_0x24ec5d):_0x24ec5d;if(_0x51569e[_0x44a165][_0x59c4('0x6b')]){_0x3440e4[_0x59c4('0x5d')](_0x24ec5d);}_0x51569e[_0x44a165]['orderBy']&&_0x3440e4[_0x59c4('0x32')](_0x24ec5d,_0x51569e[_0x44a165][_0x59c4('0x6c')]===_0x59c4('0x6d')?![]:!![]);_0x3440e4[_0x59c4('0x67')](_0x24ec5d,_0x51569e[_0x44a165][_0x59c4('0x6e')]||_0x24ec5d);}if(_0x4bf3fe[_0x59c4('0x6f')]){_0x4bf3fe[_0x59c4('0x6f')]=JSON[_0x59c4('0x70')](_0x4bf3fe[_0x59c4('0x6f')]);for(var _0x3dde08=0x0;_0x3dde08<_0x4bf3fe['joins'][_0x59c4('0x41')];_0x3dde08+=0x1){if(_0x4bf3fe[_0x59c4('0x6f')][_0x3dde08][_0x59c4('0x38')]&&_[_0x59c4('0x57')](_0x3c175b,_0x4bf3fe['joins'][_0x3dde08]['type'])&&_0x4bf3fe['joins'][_0x3dde08][_0x59c4('0x71')]&&_0x4bf3fe[_0x59c4('0x6f')][_0x3dde08][_0x59c4('0x72')]&&_0x4bf3fe[_0x59c4('0x6f')][_0x3dde08][_0x59c4('0x73')]){_0x3440e4[_0x4bf3fe[_0x59c4('0x6f')][_0x3dde08]['type']](_0x4bf3fe[_0x59c4('0x6f')][_0x3dde08]['foreignTable'],null,util[_0x59c4('0x6a')]('%s.%s\x20=\x20%s.%s',_0x4bf3fe['table'],_0x4bf3fe[_0x59c4('0x6f')][_0x3dde08][_0x59c4('0x71')],_0x4bf3fe[_0x59c4('0x6f')][_0x3dde08]['foreignTable'],_0x4bf3fe['joins'][_0x3dde08][_0x59c4('0x73')]));}}}if(_0x4bf3fe[_0x59c4('0x74')]){_0x4bf3fe[_0x59c4('0x74')]=JSON[_0x59c4('0x70')](_0x4bf3fe[_0x59c4('0x74')]);_0x3440e4['where'](_0x5de981(_0x4bf3fe[_0x59c4('0x74')]['group']));}_0x592122=_0x3440e4[_0x59c4('0x75')]();_0x3440e4[_0x59c4('0x31')](_0x42be01);_0x3440e4[_0x59c4('0x1a')](0x0);logger[_0x59c4('0x76')](_0x59c4('0x77'),_0x3440e4[_0x59c4('0x78')]());return db[_0x59c4('0x79')]['query'](_0x3440e4[_0x59c4('0x78')](),{'type':db[_0x59c4('0x79')][_0x59c4('0x7a')][_0x59c4('0x7b')]});}})[_0x59c4('0x1f')](respondWithResult(_0x525145,null))[_0x59c4('0x42')](handleError(_0x525145,null));};function runReport(_0x8076c9,_0x2a9fb4,_0x45a722){var _0x5e6031=_0x2a9fb4['name'];var _0x5d0826=0xa;var _0x2a8369=[_0x59c4('0x4d'),_0x59c4('0x4e'),'right_join','cross_join'];var _0x4d54f4={'SUM':_0x59c4('0x50'),'COUNT':_0x59c4('0x51'),'COUNT DISTINCT':_0x59c4('0x52'),'MAX':_0x59c4('0x7c'),'MIN':_0x59c4('0x7d'),'AVG':_0x59c4('0x7e'),'GROUP_CONCAT':_0x59c4('0x53'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x7a9884={'SEC_TO_TIME':_0x59c4('0x54'),'DATE':_0x59c4('0x7f'),'HOUR':_0x59c4('0x80'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0xad004e=function(_0x1ca8d5){return!_[_0x59c4('0x57')](['IS\x20NULL',_0x59c4('0x59'),_0x59c4('0x5a'),_0x59c4('0x81')],_0x1ca8d5);};var _0x34fb56=function(_0x2b1086){if(!_0x2b1086||!_0x2b1086[_0x59c4('0x5b')][_0x59c4('0x41')]){return'';}for(var _0x1d1585='(',_0x5b5ed4=0x0;_0x5b5ed4<_0x2b1086[_0x59c4('0x5b')][_0x59c4('0x41')];_0x5b5ed4+=0x1){_0x5b5ed4>0x0&&(_0x1d1585+='\x20'+_0x2b1086[_0x59c4('0x5c')]+'\x20');_0x1d1585+=_0x2b1086['rules'][_0x5b5ed4]['group']?_0x34fb56(_0x2b1086[_0x59c4('0x5b')][_0x5b5ed4]['group']):_0x2b1086['rules'][_0x5b5ed4]['field']+'\x20'+_0x2b1086['rules'][_0x5b5ed4][_0x59c4('0x5e')]+(_0xad004e(_0x2b1086['rules'][_0x5b5ed4][_0x59c4('0x5e')])?'\x20'+_0x2b1086[_0x59c4('0x5b')][_0x5b5ed4][_0x59c4('0x82')]:'');}return _0x1d1585+')';};var _0x509eb1={'where':{'id':_0x8076c9['id']}},_0x52969a,_0x177590,_0x5229f5,_0x496e70,_0x137f6b;_0x509eb1=_['merge']({},_0x509eb1,_0x45a722);return db[_0x59c4('0x27')][_0x59c4('0x4c')](_0x509eb1)['then'](function(_0x1613cd){if(_0x1613cd){_0x52969a=_0x1613cd;return _0x1613cd['getFields']();}return null;})[_0x59c4('0x1f')](function(_0x21753b){if(_0x21753b){if(!_0x21753b[_0x59c4('0x41')]){throw new db['Sequelize'][(_0x59c4('0x60'))](_0x59c4('0x61'),0x193);}_0x177590=_0x21753b;return db['AnalyticMetric'][_0x59c4('0x3d')]({'raw':!![]});}return null;})[_0x59c4('0x1f')](function(_0x594a2f){if(_0x594a2f){_0x5229f5=_[_0x59c4('0x83')](_0x594a2f,'id');var _0x57d241;var _0x3432df=squel[_0x59c4('0x63')]();_0x3432df[_0x59c4('0x84')](_0x52969a[_0x59c4('0x64')]);for(var _0x358f97=0x0;_0x358f97<_0x177590[_0x59c4('0x41')];_0x358f97+=0x1){_0x57d241=_0x177590[_0x358f97][_0x59c4('0x65')]?_0x5229f5[_0x177590[_0x358f97]['MetricId']]['metric']:_0x177590[_0x358f97][_0x59c4('0x67')];_0x57d241=_0x177590[_0x358f97]['function']?_[_0x59c4('0x69')](_0x4d54f4[_0x177590[_0x358f97]['function']],'%s',_0x57d241):_0x57d241;_0x57d241=_0x177590[_0x358f97][_0x59c4('0x6a')]?_['replace'](_0x7a9884[_0x177590[_0x358f97][_0x59c4('0x6a')]],'%s',_0x57d241):_0x57d241;if(_0x177590[_0x358f97][_0x59c4('0x6b')]){_0x3432df['group'](_0x57d241);}_0x177590[_0x358f97]['orderBy']&&_0x3432df[_0x59c4('0x32')](_0x57d241,_0x177590[_0x358f97][_0x59c4('0x6c')]==='DESC'?![]:!![]);_0x3432df['field'](_0x57d241,_0x177590[_0x358f97]['alias']||_0x57d241);}if(_0x52969a[_0x59c4('0x6f')]){_0x52969a[_0x59c4('0x6f')]=JSON['parse'](_0x52969a[_0x59c4('0x6f')]);for(var _0x65b1c0=0x0;_0x65b1c0<_0x52969a[_0x59c4('0x6f')]['length'];_0x65b1c0+=0x1){if(_0x52969a[_0x59c4('0x6f')][_0x65b1c0][_0x59c4('0x38')]&&_[_0x59c4('0x57')](_0x2a8369,_0x52969a[_0x59c4('0x6f')][_0x65b1c0][_0x59c4('0x38')])&&_0x52969a['joins'][_0x65b1c0]['parentKey']&&_0x52969a[_0x59c4('0x6f')][_0x65b1c0][_0x59c4('0x72')]&&_0x52969a[_0x59c4('0x6f')][_0x65b1c0]['foreignKey']){_0x3432df[_0x52969a[_0x59c4('0x6f')][_0x65b1c0]['type']](_0x52969a[_0x59c4('0x6f')][_0x65b1c0][_0x59c4('0x72')],null,util[_0x59c4('0x6a')](_0x59c4('0x85'),_0x52969a['table'],_0x52969a['joins'][_0x65b1c0][_0x59c4('0x71')],_0x52969a[_0x59c4('0x6f')][_0x65b1c0][_0x59c4('0x72')],_0x52969a[_0x59c4('0x6f')][_0x65b1c0][_0x59c4('0x73')]));}}}if(_0x52969a[_0x59c4('0x74')]){_0x52969a[_0x59c4('0x74')]=JSON['parse'](_0x52969a['conditions']);_0x3432df[_0x59c4('0x34')](_0x34fb56(_0x52969a[_0x59c4('0x74')][_0x59c4('0x5d')]));}_0x137f6b=_0x3432df[_0x59c4('0x75')]();_0x3432df[_0x59c4('0x31')](_0x5d0826);_0x3432df[_0x59c4('0x1a')](0x0);logger['debug']('Limited\x20Query:',_0x3432df[_0x59c4('0x78')]());return db[_0x59c4('0x79')][_0x59c4('0x2c')](_0x3432df[_0x59c4('0x78')](),{'type':db[_0x59c4('0x79')][_0x59c4('0x7a')]['SELECT']});}})[_0x59c4('0x1f')](function(_0x3fbeb3){if(!_0x3fbeb3[_0x59c4('0x41')]){throw new db[(_0x59c4('0x86'))][(_0x59c4('0x60'))](_0x59c4('0x87'),0xcc);}if(_0x2a9fb4[_0x59c4('0x88')]==='web'){return null;}var _0x479ef4=_[_0x59c4('0x37')](_0x2a9fb4,{'name':_0x2a9fb4[_0x59c4('0x89')]||_0x2a9fb4['name']||_0x52969a['name'],'basename':_0x5e6031,'savename':util[_0x59c4('0x6a')](_0x59c4('0x8a'),_0x2a9fb4['name']||_0x52969a[_0x59c4('0x23')],require(_0x59c4('0x8b'))[_0x59c4('0x8c')](0x4),_0x2a9fb4['output']||'csv'),'reportId':_0x52969a['id'],'reportType':'custom'});return db[_0x59c4('0x8d')]['create'](_0x479ef4,{'raw':!![]});})[_0x59c4('0x1f')](function(_0x209c2f){if(_0x52969a['table']===_0x59c4('0x8e')){_0x137f6b['where'](_0x52969a['table']+_0x59c4('0x8f'),_0x2a9fb4[_0x59c4('0x90')],_0x2a9fb4[_0x59c4('0x91')]);}else{_0x137f6b[_0x59c4('0x34')](_0x52969a[_0x59c4('0x64')]+_0x59c4('0x92'),_0x2a9fb4['startDate'],_0x2a9fb4[_0x59c4('0x91')]);}if(_0x209c2f){logger[_0x59c4('0x93')](_0x59c4('0x94'),_0x137f6b[_0x59c4('0x78')]());require('child_process')[_0x59c4('0x95')](path['join'](__dirname,_0x59c4('0x96'),_0x209c2f[_0x59c4('0x88')]),[_0x209c2f['id'],_0x137f6b[_0x59c4('0x78')](),path[_0x59c4('0x4d')](__dirname,_0x59c4('0x97'),_0x209c2f[_0x59c4('0x98')]),_0x5e6031]);return _0x209c2f;}else{var _0x249548=squel[_0x59c4('0x63')]();_0x249548['from']('('+_0x137f6b[_0x59c4('0x78')]()+')',_0x59c4('0x99'));_0x249548[_0x59c4('0x67')](_0x59c4('0x9a'),_0x59c4('0x19'));_0x137f6b[_0x59c4('0x31')](_0x2a9fb4[_0x59c4('0x31')]||_0x5d0826);_0x137f6b[_0x59c4('0x1a')](_0x2a9fb4[_0x59c4('0x1a')]||0x0);return dbH[_0x59c4('0x79')]['query'](_0x249548[_0x59c4('0x78')](),{'type':dbH[_0x59c4('0x79')][_0x59c4('0x7a')]['SELECT']})[_0x59c4('0x1f')](function(_0x3b53bf){if(!_0x3b53bf[_0x59c4('0x41')]){_0x496e70=0x0;}else{_0x496e70=_0x3b53bf[0x0][_0x59c4('0x19')]||0x0;}return dbH[_0x59c4('0x79')]['query'](_0x137f6b[_0x59c4('0x78')](),{'type':dbH[_0x59c4('0x79')]['QueryTypes'][_0x59c4('0x7b')]});})['then'](function(_0x14ff87){return{'rows':_0x14ff87||[],'count':_0x496e70};});}});}exports[_0x59c4('0x9b')]=function(_0x57e3a3,_0x4daa84){return runReport(_0x57e3a3[_0x59c4('0x40')],_0x57e3a3[_0x59c4('0x2c')],_0x57e3a3[_0x59c4('0x3a')])['then'](respondWithResult(_0x4daa84,null))[_0x59c4('0x42')](handleError(_0x4daa84,null));};exports[_0x59c4('0x9c')]=runReport;exports[_0x59c4('0x2c')]=function(_0x2985b0,_0x42c767){var _0x5616b5=0xa;var _0x2e1a0a=[_0x59c4('0x4d'),'left_join',_0x59c4('0x4f'),_0x59c4('0x9d')];var _0x56632d={'SUM':'SUM(%s)','COUNT':'COUNT(%s)','COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':_0x59c4('0x7d'),'AVG':_0x59c4('0x7e'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x59c4('0x9e'),'GROUP_CONCAT DESC':_0x59c4('0x9f')};var _0xa42d5a={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x59c4('0x7f'),'HOUR':_0x59c4('0x80'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x59c4('0x56')};var _0x40442f=function(_0x219325){return!_[_0x59c4('0x57')]([_0x59c4('0x58'),'IS\x20NOT\x20NULL',_0x59c4('0x5a'),_0x59c4('0x81')],_0x219325);};var _0x58a915=function(_0xebf105){if(!_0xebf105||!_0xebf105[_0x59c4('0x5b')][_0x59c4('0x41')]){return'';}for(var _0x2aec18='(',_0x146215=0x0;_0x146215<_0xebf105['rules'][_0x59c4('0x41')];_0x146215+=0x1){_0x146215>0x0&&(_0x2aec18+='\x20'+_0xebf105[_0x59c4('0x5c')]+'\x20');_0x2aec18+=_0xebf105[_0x59c4('0x5b')][_0x146215][_0x59c4('0x5d')]?_0x58a915(_0xebf105[_0x59c4('0x5b')][_0x146215][_0x59c4('0x5d')]):_0xebf105[_0x59c4('0x5b')][_0x146215][_0x59c4('0x67')]+'\x20'+_0xebf105[_0x59c4('0x5b')][_0x146215][_0x59c4('0x5e')]+(_0x40442f(_0xebf105[_0x59c4('0x5b')][_0x146215][_0x59c4('0x5e')])?'\x20'+_0xebf105['rules'][_0x146215][_0x59c4('0x82')]:'');}return _0x2aec18+')';};var _0x180f59={'where':{'id':_0x2985b0['params']['id']}},_0x4f9cd8,_0x4b4af2,_0x1a55ba,_0x4aa697,_0x3a03f2;_0x180f59=_[_0x59c4('0x37')]({},_0x180f59,_0x2985b0[_0x59c4('0x3a')]);return db[_0x59c4('0x27')][_0x59c4('0x4c')](_0x180f59)[_0x59c4('0x1f')](function(_0x12a24b){if(_0x12a24b){_0x4f9cd8=_0x12a24b;return _0x12a24b['getFields']();}return null;})[_0x59c4('0x1f')](function(_0x11a1c5){if(_0x11a1c5){if(!_0x11a1c5['length']){throw new db['Sequelize']['ValidationErrorItem'](_0x59c4('0x61'),0x193);}_0x4b4af2=_0x11a1c5;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})[_0x59c4('0x1f')](function(_0x34c874){if(_0x34c874){_0x1a55ba=_[_0x59c4('0x83')](_0x34c874,'id');var _0x1a4884;var _0x1035a0=squel[_0x59c4('0x63')]();_0x1035a0['from'](_0x4f9cd8['table']);for(var _0x4e1802=0x0;_0x4e1802<_0x4b4af2[_0x59c4('0x41')];_0x4e1802+=0x1){_0x1a4884=_0x4b4af2[_0x4e1802]['MetricId']?_0x1a55ba[_0x4b4af2[_0x4e1802][_0x59c4('0x65')]]['metric']:_0x4b4af2[_0x4e1802][_0x59c4('0x67')];_0x1a4884=_0x4b4af2[_0x4e1802][_0x59c4('0x68')]?_[_0x59c4('0x69')](_0x56632d[_0x4b4af2[_0x4e1802][_0x59c4('0x68')]],'%s',_0x1a4884):_0x1a4884;_0x1a4884=_0x4b4af2[_0x4e1802][_0x59c4('0x6a')]?_[_0x59c4('0x69')](_0xa42d5a[_0x4b4af2[_0x4e1802][_0x59c4('0x6a')]],'%s',_0x1a4884):_0x1a4884;if(_0x4b4af2[_0x4e1802][_0x59c4('0x6b')]){_0x1035a0['group'](_0x1a4884);}_0x4b4af2[_0x4e1802][_0x59c4('0x6c')]&&_0x1035a0[_0x59c4('0x32')](_0x1a4884,_0x4b4af2[_0x4e1802]['orderBy']==='DESC'?![]:!![]);_0x1035a0[_0x59c4('0x67')](_0x1a4884,_0x4b4af2[_0x4e1802][_0x59c4('0x6e')]||_0x1a4884);}if(_0x4f9cd8[_0x59c4('0x6f')]){_0x4f9cd8[_0x59c4('0x6f')]=JSON[_0x59c4('0x70')](_0x4f9cd8['joins']);for(var _0x3485d8=0x0;_0x3485d8<_0x4f9cd8[_0x59c4('0x6f')][_0x59c4('0x41')];_0x3485d8+=0x1){if(_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8][_0x59c4('0x38')]&&_[_0x59c4('0x57')](_0x2e1a0a,_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8][_0x59c4('0x38')])&&_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8][_0x59c4('0x71')]&&_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8]['foreignTable']&&_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8][_0x59c4('0x73')]){_0x1035a0[_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8]['type']](_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8][_0x59c4('0x72')],null,util[_0x59c4('0x6a')]('%s.%s\x20=\x20%s.%s',_0x4f9cd8['table'],_0x4f9cd8['joins'][_0x3485d8][_0x59c4('0x71')],_0x4f9cd8[_0x59c4('0x6f')][_0x3485d8][_0x59c4('0x72')],_0x4f9cd8['joins'][_0x3485d8]['foreignKey']));}}}if(_0x4f9cd8['conditions']){_0x4f9cd8[_0x59c4('0x74')]=JSON[_0x59c4('0x70')](_0x4f9cd8[_0x59c4('0x74')]);_0x1035a0[_0x59c4('0x34')](_0x58a915(_0x4f9cd8[_0x59c4('0x74')][_0x59c4('0x5d')]));}_0x3a03f2=_0x1035a0[_0x59c4('0x75')]();_0x1035a0[_0x59c4('0x31')](_0x5616b5);_0x1035a0['offset'](0x0);logger['debug']('Limited\x20Query:',_0x1035a0[_0x59c4('0x78')]());return db[_0x59c4('0x79')]['query'](_0x1035a0[_0x59c4('0x78')](),{'type':db[_0x59c4('0x79')]['QueryTypes'][_0x59c4('0x7b')]});}})[_0x59c4('0x1f')](function(){return{'sql':_0x3a03f2[_0x59c4('0x78')]()};})[_0x59c4('0x1f')](respondWithResult(_0x42c767,null))['catch'](handleError(_0x42c767,null));};
\ No newline at end of file
+var _0x83b9=['endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','fork','../../components/export/','../../files/reports','savename','SELECT','run','runReport','metric','Limited\x20Query:','html-pdf','eml-format','rimraf','zip-dir','request-promise','moment','util','path','sox','to-csv','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','dbH','sendStatus','status','end','offset','set','Content-Range','apply','save','update','then','destroy','UserProfileResource','error','name','send','index','map','AnalyticCustomReport','fieldName','type','key','query','filters','intersection','model','attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','filter','VIRTUAL','merge','options','count','rows','catch','show','params','keys','rawAttributes','fields','includeAll','find','create','body','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','autoAssociation','CustomReports','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','preview','join','left_join','right_join','cross_join','COUNT(%s)','COUNT(DISTINCT\x20%s)','MIN(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','ROUND(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','group','field','condition','value','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','findAll','keyBy','select','MetricId','function','replace','format','groupBy','orderBy','alias','joins','parentKey','foreignTable','%s.%s\x20=\x20%s.%s','table','conditions','debug','toString','sequelize','QueryTypes','SUM(%s)','MAX(%s)','AVG(%s)','UNIX_TIMESTAMP(%s)','getFields','Sequelize','from','DESC','parse','foreignKey','clone','web','%s-%s.%s','output','csv','custom','AnalyticExtractedReport','cdr','startDate'];(function(_0x4b2863,_0x494899){var _0x567d67=function(_0x751f03){while(--_0x751f03){_0x4b2863['push'](_0x4b2863['shift']());}};_0x567d67(++_0x494899);}(_0x83b9,0x155));var _0x983b=function(_0x546328,_0x56dd97){_0x546328=_0x546328-0x0;var _0x1aeddf=_0x83b9[_0x546328];return _0x1aeddf;};'use strict';var pdf=require(_0x983b('0x0'));var emlformat=require(_0x983b('0x1'));var rimraf=require(_0x983b('0x2'));var zipdir=require(_0x983b('0x3'));var jsonpatch=require('fast-json-patch');var rp=require(_0x983b('0x4'));var moment=require(_0x983b('0x5'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x983b('0x6'));var path=require(_0x983b('0x7'));var sox=require(_0x983b('0x8'));var csv=require(_0x983b('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x983b('0xa'));var squel=require(_0x983b('0xb'));var crypto=require(_0x983b('0xc'));var jsforce=require(_0x983b('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x983b('0x9'));var querystring=require(_0x983b('0xe'));var Papa=require(_0x983b('0xf'));var Redis=require('ioredis');var authService=require(_0x983b('0x10'));var qs=require(_0x983b('0x11'));var as=require(_0x983b('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x983b('0x13'))(_0x983b('0x14'));var utils=require(_0x983b('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x983b('0x16'));var db=require('../../mysqldb')['db'];var dbH=require(_0x983b('0x17'))[_0x983b('0x18')];function respondWithStatusCode(_0x58feda,_0x3b2146){_0x3b2146=_0x3b2146||0xcc;return function(_0x53d64c){if(_0x53d64c){return _0x58feda[_0x983b('0x19')](_0x3b2146);}return _0x58feda[_0x983b('0x1a')](_0x3b2146)[_0x983b('0x1b')]();};}function respondWithResult(_0x5a6d56,_0x577691){_0x577691=_0x577691||0xc8;return function(_0x333c4b){if(_0x333c4b){return _0x5a6d56[_0x983b('0x1a')](_0x577691)['json'](_0x333c4b);}};}function respondWithFilteredResult(_0x990cd,_0xefa8f1){return function(_0x3f9ffb){if(_0x3f9ffb){var _0xfc30f5=_0x3f9ffb['count'],_0x327449=_0xefa8f1['offset'],_0x108b7a=_0xefa8f1[_0x983b('0x1c')]+_0xefa8f1['limit'],_0x52e48c;if(_0x108b7a>=_0xfc30f5){_0x108b7a=_0xfc30f5;_0x52e48c=0xc8;}else{_0x52e48c=0xce;}_0x990cd['status'](_0x52e48c);return _0x990cd[_0x983b('0x1d')](_0x983b('0x1e'),_0x327449+'-'+_0x108b7a+'/'+_0xfc30f5)['json'](_0x3f9ffb);}return null;};}function patchUpdates(_0x10fc34){return function(_0x27db4f){try{jsonpatch[_0x983b('0x1f')](_0x27db4f,_0x10fc34,!![]);}catch(_0x30c086){return BPromise['reject'](_0x30c086);}return _0x27db4f[_0x983b('0x20')]();};}function saveUpdates(_0x265fa8,_0x471741){return function(_0x3fa7d1){if(_0x3fa7d1){return _0x3fa7d1[_0x983b('0x21')](_0x265fa8)[_0x983b('0x22')](function(_0x165d53){return _0x165d53;});}return null;};}function removeEntity(_0x1a7bc2,_0x114922){return function(_0x5bff65){if(_0x5bff65){return _0x5bff65[_0x983b('0x23')]()[_0x983b('0x22')](function(){var _0x408a44=_0x5bff65['get']({'plain':!![]});var _0x1337c0='CustomReports';return db[_0x983b('0x24')][_0x983b('0x23')]({'where':{'type':_0x1337c0,'resourceId':_0x408a44['id']}})[_0x983b('0x22')](function(){return _0x5bff65;});})[_0x983b('0x22')](function(){_0x1a7bc2[_0x983b('0x1a')](0xcc)[_0x983b('0x1b')]();});}};}function handleEntityNotFound(_0x22951f,_0x4287da){return function(_0x4c828a){if(!_0x4c828a){_0x22951f[_0x983b('0x19')](0x194);}return _0x4c828a;};}function handleError(_0x2d8912,_0x151e38){_0x151e38=_0x151e38||0x1f4;return function(_0xbeb33d){logger[_0x983b('0x25')](_0xbeb33d['stack']);if(_0xbeb33d['name']){delete _0xbeb33d[_0x983b('0x26')];}_0x2d8912[_0x983b('0x1a')](_0x151e38)[_0x983b('0x27')](_0xbeb33d);};}exports[_0x983b('0x28')]=function(_0x1b2edb,_0x1df3e8){var _0x4150e7={},_0x2bcfd0={},_0x4d984d={'count':0x0,'rows':[]};var _0x42cd56=_[_0x983b('0x29')](db[_0x983b('0x2a')]['rawAttributes'],function(_0x578b5f){return{'name':_0x578b5f[_0x983b('0x2b')],'type':_0x578b5f[_0x983b('0x2c')][_0x983b('0x2d')]};});_0x2bcfd0['model']=_[_0x983b('0x29')](_0x42cd56,'name');_0x2bcfd0['query']=_['keys'](_0x1b2edb[_0x983b('0x2e')]);_0x2bcfd0[_0x983b('0x2f')]=_[_0x983b('0x30')](_0x2bcfd0[_0x983b('0x31')],_0x2bcfd0[_0x983b('0x2e')]);_0x4150e7[_0x983b('0x32')]=_['intersection'](_0x2bcfd0['model'],qs['fields'](_0x1b2edb[_0x983b('0x2e')]['fields']));_0x4150e7['attributes']=_0x4150e7['attributes'][_0x983b('0x33')]?_0x4150e7[_0x983b('0x32')]:_0x2bcfd0[_0x983b('0x31')];if(!_0x1b2edb['query'][_0x983b('0x34')](_0x983b('0x35'))){_0x4150e7[_0x983b('0x36')]=qs[_0x983b('0x36')](_0x1b2edb[_0x983b('0x2e')][_0x983b('0x36')]);_0x4150e7[_0x983b('0x1c')]=qs[_0x983b('0x1c')](_0x1b2edb[_0x983b('0x2e')][_0x983b('0x1c')]);}_0x4150e7[_0x983b('0x37')]=qs[_0x983b('0x38')](_0x1b2edb[_0x983b('0x2e')][_0x983b('0x38')]);_0x4150e7[_0x983b('0x39')]=qs[_0x983b('0x2f')](_['pick'](_0x1b2edb[_0x983b('0x2e')],_0x2bcfd0[_0x983b('0x2f')]),_0x42cd56);if(_0x1b2edb[_0x983b('0x2e')][_0x983b('0x3a')]){_0x4150e7[_0x983b('0x39')]=_['merge'](_0x4150e7['where'],{'$or':_[_0x983b('0x29')](_0x42cd56,function(_0x50fc92){if(_0x50fc92[_0x983b('0x2c')]!==_0x983b('0x3b')){var _0x44e465={};_0x44e465[_0x50fc92['name']]={'$like':'%'+_0x1b2edb[_0x983b('0x2e')][_0x983b('0x3a')]+'%'};return _0x44e465;}})});}_0x4150e7=_[_0x983b('0x3c')]({},_0x4150e7,_0x1b2edb[_0x983b('0x3d')]);var _0x5bfe7f={'where':_0x4150e7[_0x983b('0x39')]};return db[_0x983b('0x2a')][_0x983b('0x3e')](_0x5bfe7f)[_0x983b('0x22')](function(_0x394133){_0x4d984d[_0x983b('0x3e')]=_0x394133;if(_0x1b2edb[_0x983b('0x2e')]['includeAll']){_0x4150e7['include']=[{'all':!![]}];}return db[_0x983b('0x2a')]['findAll'](_0x4150e7);})['then'](function(_0x22bc1b){_0x4d984d[_0x983b('0x3f')]=_0x22bc1b;return _0x4d984d;})[_0x983b('0x22')](respondWithFilteredResult(_0x1df3e8,_0x4150e7))[_0x983b('0x40')](handleError(_0x1df3e8,null));};exports[_0x983b('0x41')]=function(_0x1e40fa,_0x28d42a){var _0x57752d={'raw':![],'where':{'id':_0x1e40fa[_0x983b('0x42')]['id']}},_0x191961={};_0x191961['model']=_[_0x983b('0x43')](db['AnalyticCustomReport'][_0x983b('0x44')]);_0x191961[_0x983b('0x2e')]=_[_0x983b('0x43')](_0x1e40fa['query']);_0x191961[_0x983b('0x2f')]=_[_0x983b('0x30')](_0x191961[_0x983b('0x31')],_0x191961[_0x983b('0x2e')]);_0x57752d[_0x983b('0x32')]=_[_0x983b('0x30')](_0x191961[_0x983b('0x31')],qs['fields'](_0x1e40fa[_0x983b('0x2e')][_0x983b('0x45')]));_0x57752d[_0x983b('0x32')]=_0x57752d[_0x983b('0x32')]['length']?_0x57752d['attributes']:_0x191961['model'];if(_0x1e40fa[_0x983b('0x2e')][_0x983b('0x46')]){_0x57752d['include']=[{'all':!![]}];}_0x57752d=_[_0x983b('0x3c')]({},_0x57752d,_0x1e40fa[_0x983b('0x3d')]);return db[_0x983b('0x2a')][_0x983b('0x47')](_0x57752d)[_0x983b('0x22')](handleEntityNotFound(_0x28d42a,null))['then'](respondWithResult(_0x28d42a,null))[_0x983b('0x40')](handleError(_0x28d42a,null));};exports['create']=function(_0x15bba4,_0x237872){return db[_0x983b('0x2a')][_0x983b('0x48')](_0x15bba4[_0x983b('0x49')],{})['then'](function(_0x49bcbb){var _0x1d439c=_0x15bba4['user'][_0x983b('0x4a')]({'plain':!![]});if(!_0x1d439c)throw new Error(_0x983b('0x4b'));if(_0x1d439c[_0x983b('0x4c')]===_0x983b('0x4d')){var _0xd794c5=_0x49bcbb['get']({'plain':!![]});var _0x32ce04='Reports';return db[_0x983b('0x4e')]['find']({'where':{'name':_0x32ce04,'userProfileId':_0x1d439c[_0x983b('0x4f')]},'raw':!![]})[_0x983b('0x22')](function(_0x12a0d3){if(_0x12a0d3&&_0x12a0d3[_0x983b('0x50')]===0x0){return db[_0x983b('0x24')][_0x983b('0x48')]({'name':_0xd794c5[_0x983b('0x26')],'resourceId':_0xd794c5['id'],'type':_0x983b('0x51'),'sectionId':_0x12a0d3['id']},{})[_0x983b('0x22')](function(){return _0x49bcbb;});}else{return _0x49bcbb;}})[_0x983b('0x40')](function(_0x252fa9){logger['error'](_0x983b('0x52'),_0x252fa9);throw _0x252fa9;});}return _0x49bcbb;})[_0x983b('0x22')](respondWithResult(_0x237872,0xc9))[_0x983b('0x40')](handleError(_0x237872,null));};exports[_0x983b('0x21')]=function(_0x3b786a,_0x2534c0){if(_0x3b786a[_0x983b('0x49')]['id']){delete _0x3b786a[_0x983b('0x49')]['id'];}return db['AnalyticCustomReport'][_0x983b('0x47')]({'where':{'id':_0x3b786a[_0x983b('0x42')]['id']}})[_0x983b('0x22')](handleEntityNotFound(_0x2534c0,null))[_0x983b('0x22')](saveUpdates(_0x3b786a[_0x983b('0x49')],null))[_0x983b('0x22')](respondWithResult(_0x2534c0,null))[_0x983b('0x40')](handleError(_0x2534c0,null));};exports[_0x983b('0x23')]=function(_0x3cc118,_0x2d6ae9){return db['AnalyticCustomReport'][_0x983b('0x47')]({'where':{'id':_0x3cc118['params']['id']}})[_0x983b('0x22')](handleEntityNotFound(_0x2d6ae9,null))[_0x983b('0x22')](removeEntity(_0x2d6ae9,null))['catch'](handleError(_0x2d6ae9,null));};exports[_0x983b('0x53')]=function(_0x3d8c7c,_0xff2299){var _0x421a83=0xa;var _0x5ca6fb=[_0x983b('0x54'),_0x983b('0x55'),_0x983b('0x56'),_0x983b('0x57')];var _0x5b428e={'SUM':'SUM(%s)','COUNT':_0x983b('0x58'),'COUNT DISTINCT':_0x983b('0x59'),'MAX':'MAX(%s)','MIN':_0x983b('0x5a'),'AVG':'AVG(%s)','GROUP_CONCAT':_0x983b('0x5b'),'GROUP_CONCAT ASC':_0x983b('0x5c'),'GROUP_CONCAT DESC':_0x983b('0x5d')};var _0x20cbb0={'SEC_TO_TIME':_0x983b('0x5e'),'DATE':_0x983b('0x5f'),'HOUR':_0x983b('0x60'),'ROUND':_0x983b('0x61'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x52f6f4=function(_0x5f3bdb){return!_[_0x983b('0x62')]([_0x983b('0x63'),_0x983b('0x64'),_0x983b('0x65'),_0x983b('0x66')],_0x5f3bdb);};var _0x1bd55f=function(_0x25ea6b){if(!_0x25ea6b||!_0x25ea6b[_0x983b('0x67')][_0x983b('0x33')]){return'';}for(var _0x38b594='(',_0x12abf4=0x0;_0x12abf4<_0x25ea6b[_0x983b('0x67')][_0x983b('0x33')];_0x12abf4+=0x1){_0x12abf4>0x0&&(_0x38b594+='\x20'+_0x25ea6b[_0x983b('0x68')]+'\x20');_0x38b594+=_0x25ea6b[_0x983b('0x67')][_0x12abf4][_0x983b('0x69')]?_0x1bd55f(_0x25ea6b['rules'][_0x12abf4][_0x983b('0x69')]):_0x25ea6b[_0x983b('0x67')][_0x12abf4][_0x983b('0x6a')]+'\x20'+_0x25ea6b[_0x983b('0x67')][_0x12abf4][_0x983b('0x6b')]+(_0x52f6f4(_0x25ea6b[_0x983b('0x67')][_0x12abf4][_0x983b('0x6b')])?'\x20'+_0x25ea6b[_0x983b('0x67')][_0x12abf4][_0x983b('0x6c')]:'');}return _0x38b594+')';};var _0x1705aa={'where':{'id':_0x3d8c7c[_0x983b('0x42')]['id']}},_0x2b8e07,_0x244b80,_0x35296e,_0x2b0923,_0x1ed5d1;_0x1705aa=_[_0x983b('0x3c')]({},_0x1705aa,_0x3d8c7c[_0x983b('0x3d')]);return db['AnalyticCustomReport']['find'](_0x1705aa)['then'](function(_0x2e400f){if(_0x2e400f){_0x2b8e07=_0x2e400f;return _0x2e400f['getFields']();}return null;})[_0x983b('0x22')](function(_0x5632df){if(_0x5632df){if(!_0x5632df[_0x983b('0x33')]){throw new db['Sequelize'][(_0x983b('0x6d'))](_0x983b('0x6e'),0x193);}_0x244b80=_0x5632df;return db[_0x983b('0x6f')][_0x983b('0x70')]({'raw':!![]});}return null;})[_0x983b('0x22')](function(_0x15fe04){if(_0x15fe04){_0x35296e=_[_0x983b('0x71')](_0x15fe04,'id');var _0x396d82;var _0x14c589=squel[_0x983b('0x72')]();_0x14c589['from'](_0x2b8e07['table']);for(var _0x456dee=0x0;_0x456dee<_0x244b80[_0x983b('0x33')];_0x456dee+=0x1){_0x396d82=_0x244b80[_0x456dee][_0x983b('0x73')]?_0x35296e[_0x244b80[_0x456dee][_0x983b('0x73')]]['metric']:_0x244b80[_0x456dee][_0x983b('0x6a')];_0x396d82=_0x244b80[_0x456dee][_0x983b('0x74')]?_[_0x983b('0x75')](_0x5b428e[_0x244b80[_0x456dee]['function']],'%s',_0x396d82):_0x396d82;_0x396d82=_0x244b80[_0x456dee][_0x983b('0x76')]?_[_0x983b('0x75')](_0x20cbb0[_0x244b80[_0x456dee]['format']],'%s',_0x396d82):_0x396d82;if(_0x244b80[_0x456dee][_0x983b('0x77')]){_0x14c589[_0x983b('0x69')](_0x396d82);}_0x244b80[_0x456dee][_0x983b('0x78')]&&_0x14c589[_0x983b('0x37')](_0x396d82,_0x244b80[_0x456dee][_0x983b('0x78')]==='DESC'?![]:!![]);_0x14c589[_0x983b('0x6a')](_0x396d82,_0x244b80[_0x456dee][_0x983b('0x79')]||_0x396d82);}if(_0x2b8e07[_0x983b('0x7a')]){_0x2b8e07[_0x983b('0x7a')]=JSON['parse'](_0x2b8e07['joins']);for(var _0xfb48d4=0x0;_0xfb48d4<_0x2b8e07[_0x983b('0x7a')][_0x983b('0x33')];_0xfb48d4+=0x1){if(_0x2b8e07[_0x983b('0x7a')][_0xfb48d4]['type']&&_[_0x983b('0x62')](_0x5ca6fb,_0x2b8e07[_0x983b('0x7a')][_0xfb48d4][_0x983b('0x2c')])&&_0x2b8e07[_0x983b('0x7a')][_0xfb48d4][_0x983b('0x7b')]&&_0x2b8e07['joins'][_0xfb48d4][_0x983b('0x7c')]&&_0x2b8e07[_0x983b('0x7a')][_0xfb48d4]['foreignKey']){_0x14c589[_0x2b8e07[_0x983b('0x7a')][_0xfb48d4]['type']](_0x2b8e07[_0x983b('0x7a')][_0xfb48d4]['foreignTable'],null,util[_0x983b('0x76')](_0x983b('0x7d'),_0x2b8e07[_0x983b('0x7e')],_0x2b8e07['joins'][_0xfb48d4]['parentKey'],_0x2b8e07[_0x983b('0x7a')][_0xfb48d4]['foreignTable'],_0x2b8e07[_0x983b('0x7a')][_0xfb48d4]['foreignKey']));}}}if(_0x2b8e07[_0x983b('0x7f')]){_0x2b8e07[_0x983b('0x7f')]=JSON['parse'](_0x2b8e07[_0x983b('0x7f')]);_0x14c589[_0x983b('0x39')](_0x1bd55f(_0x2b8e07[_0x983b('0x7f')][_0x983b('0x69')]));}_0x1ed5d1=_0x14c589['clone']();_0x14c589[_0x983b('0x36')](_0x421a83);_0x14c589[_0x983b('0x1c')](0x0);logger[_0x983b('0x80')]('Limited\x20Query:',_0x14c589[_0x983b('0x81')]());return dbH[_0x983b('0x82')][_0x983b('0x2e')](_0x14c589[_0x983b('0x81')](),{'type':dbH[_0x983b('0x82')][_0x983b('0x83')]['SELECT']});}})['then'](respondWithResult(_0xff2299,null))[_0x983b('0x40')](handleError(_0xff2299,null));};function runReport(_0x2ddd45,_0x65d9b4,_0x401ab3){var _0x410cca=_0x65d9b4[_0x983b('0x26')];var _0x5ebf11=0xa;var _0x990575=[_0x983b('0x54'),'left_join',_0x983b('0x56'),'cross_join'];var _0x14b377={'SUM':_0x983b('0x84'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0x983b('0x59'),'MAX':_0x983b('0x85'),'MIN':_0x983b('0x5a'),'AVG':_0x983b('0x86'),'GROUP_CONCAT':_0x983b('0x5b'),'GROUP_CONCAT ASC':_0x983b('0x5c'),'GROUP_CONCAT DESC':_0x983b('0x5d')};var _0x2d82a7={'SEC_TO_TIME':_0x983b('0x5e'),'DATE':'DATE(%s)','HOUR':'HOUR(%s)','ROUND':_0x983b('0x61'),'UNIX_TIMESTAMP':_0x983b('0x87')};var _0x242055=function(_0x1775d){return!_[_0x983b('0x62')](['IS\x20NULL',_0x983b('0x64'),_0x983b('0x65'),'IS\x20NOT\x20EMPTY'],_0x1775d);};var _0xce852a=function(_0x34445f){if(!_0x34445f||!_0x34445f[_0x983b('0x67')]['length']){return'';}for(var _0x112e08='(',_0x37d192=0x0;_0x37d192<_0x34445f[_0x983b('0x67')][_0x983b('0x33')];_0x37d192+=0x1){_0x37d192>0x0&&(_0x112e08+='\x20'+_0x34445f['operator']+'\x20');_0x112e08+=_0x34445f[_0x983b('0x67')][_0x37d192][_0x983b('0x69')]?_0xce852a(_0x34445f[_0x983b('0x67')][_0x37d192][_0x983b('0x69')]):_0x34445f['rules'][_0x37d192][_0x983b('0x6a')]+'\x20'+_0x34445f[_0x983b('0x67')][_0x37d192][_0x983b('0x6b')]+(_0x242055(_0x34445f[_0x983b('0x67')][_0x37d192][_0x983b('0x6b')])?'\x20'+_0x34445f[_0x983b('0x67')][_0x37d192][_0x983b('0x6c')]:'');}return _0x112e08+')';};var _0x144589={'where':{'id':_0x2ddd45['id']}},_0x49d15b,_0x324e04,_0x1bfbaf,_0x3a37a4,_0x198ea2;_0x144589=_[_0x983b('0x3c')]({},_0x144589,_0x401ab3);return db[_0x983b('0x2a')][_0x983b('0x47')](_0x144589)[_0x983b('0x22')](function(_0x262124){if(_0x262124){_0x49d15b=_0x262124;return _0x262124[_0x983b('0x88')]();}return null;})[_0x983b('0x22')](function(_0x5c470d){if(_0x5c470d){if(!_0x5c470d[_0x983b('0x33')]){throw new db[(_0x983b('0x89'))][(_0x983b('0x6d'))](_0x983b('0x6e'),0x193);}_0x324e04=_0x5c470d;return db[_0x983b('0x6f')]['findAll']({'raw':!![]});}return null;})[_0x983b('0x22')](function(_0x12f0e2){if(_0x12f0e2){_0x1bfbaf=_[_0x983b('0x71')](_0x12f0e2,'id');var _0x368ba6;var _0x44e457=squel[_0x983b('0x72')]();_0x44e457[_0x983b('0x8a')](_0x49d15b[_0x983b('0x7e')]);for(var _0x8ae4b3=0x0;_0x8ae4b3<_0x324e04[_0x983b('0x33')];_0x8ae4b3+=0x1){_0x368ba6=_0x324e04[_0x8ae4b3][_0x983b('0x73')]?_0x1bfbaf[_0x324e04[_0x8ae4b3][_0x983b('0x73')]]['metric']:_0x324e04[_0x8ae4b3][_0x983b('0x6a')];_0x368ba6=_0x324e04[_0x8ae4b3][_0x983b('0x74')]?_['replace'](_0x14b377[_0x324e04[_0x8ae4b3][_0x983b('0x74')]],'%s',_0x368ba6):_0x368ba6;_0x368ba6=_0x324e04[_0x8ae4b3]['format']?_[_0x983b('0x75')](_0x2d82a7[_0x324e04[_0x8ae4b3][_0x983b('0x76')]],'%s',_0x368ba6):_0x368ba6;if(_0x324e04[_0x8ae4b3][_0x983b('0x77')]){_0x44e457[_0x983b('0x69')](_0x368ba6);}_0x324e04[_0x8ae4b3][_0x983b('0x78')]&&_0x44e457[_0x983b('0x37')](_0x368ba6,_0x324e04[_0x8ae4b3][_0x983b('0x78')]===_0x983b('0x8b')?![]:!![]);_0x44e457['field'](_0x368ba6,_0x324e04[_0x8ae4b3][_0x983b('0x79')]||_0x368ba6);}if(_0x49d15b[_0x983b('0x7a')]){_0x49d15b[_0x983b('0x7a')]=JSON[_0x983b('0x8c')](_0x49d15b[_0x983b('0x7a')]);for(var _0x5e2557=0x0;_0x5e2557<_0x49d15b['joins'][_0x983b('0x33')];_0x5e2557+=0x1){if(_0x49d15b[_0x983b('0x7a')][_0x5e2557]['type']&&_[_0x983b('0x62')](_0x990575,_0x49d15b[_0x983b('0x7a')][_0x5e2557]['type'])&&_0x49d15b[_0x983b('0x7a')][_0x5e2557][_0x983b('0x7b')]&&_0x49d15b['joins'][_0x5e2557][_0x983b('0x7c')]&&_0x49d15b['joins'][_0x5e2557]['foreignKey']){_0x44e457[_0x49d15b[_0x983b('0x7a')][_0x5e2557][_0x983b('0x2c')]](_0x49d15b[_0x983b('0x7a')][_0x5e2557][_0x983b('0x7c')],null,util[_0x983b('0x76')](_0x983b('0x7d'),_0x49d15b['table'],_0x49d15b[_0x983b('0x7a')][_0x5e2557]['parentKey'],_0x49d15b['joins'][_0x5e2557][_0x983b('0x7c')],_0x49d15b[_0x983b('0x7a')][_0x5e2557][_0x983b('0x8d')]));}}}if(_0x49d15b[_0x983b('0x7f')]){_0x49d15b[_0x983b('0x7f')]=JSON[_0x983b('0x8c')](_0x49d15b[_0x983b('0x7f')]);_0x44e457[_0x983b('0x39')](_0xce852a(_0x49d15b[_0x983b('0x7f')]['group']));}_0x198ea2=_0x44e457[_0x983b('0x8e')]();_0x44e457[_0x983b('0x36')](_0x5ebf11);_0x44e457[_0x983b('0x1c')](0x0);return;}})[_0x983b('0x22')](function(){if(_0x65d9b4['output']===_0x983b('0x8f')){return null;}var _0x519dfb=_['merge'](_0x65d9b4,{'name':_0x65d9b4['fullPath']||_0x65d9b4[_0x983b('0x26')]||_0x49d15b[_0x983b('0x26')],'basename':_0x410cca,'savename':util['format'](_0x983b('0x90'),_0x65d9b4[_0x983b('0x26')]||_0x49d15b[_0x983b('0x26')],require('randomstring')['generate'](0x4),_0x65d9b4[_0x983b('0x91')]||_0x983b('0x92')),'reportId':_0x49d15b['id'],'reportType':_0x983b('0x93')});return db[_0x983b('0x94')][_0x983b('0x48')](_0x519dfb,{'raw':!![]});})['then'](function(_0x45f508){if(_0x49d15b['table']===_0x983b('0x95')){_0x198ea2[_0x983b('0x39')](_0x49d15b[_0x983b('0x7e')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x65d9b4[_0x983b('0x96')],_0x65d9b4[_0x983b('0x97')]);}else{_0x198ea2[_0x983b('0x39')](_0x49d15b[_0x983b('0x7e')]+_0x983b('0x98'),_0x65d9b4['startDate'],_0x65d9b4[_0x983b('0x97')]);}if(_0x45f508){logger[_0x983b('0x99')](_0x983b('0x9a'),_0x198ea2['toString']());require('child_process')[_0x983b('0x9b')](path['join'](__dirname,_0x983b('0x9c'),_0x45f508['output']),[_0x45f508['id'],_0x198ea2['toString'](),path[_0x983b('0x54')](__dirname,_0x983b('0x9d'),_0x45f508[_0x983b('0x9e')]),_0x410cca]);return _0x45f508;}else{var _0x5d23f7=squel[_0x983b('0x72')]();_0x5d23f7[_0x983b('0x8a')]('('+_0x198ea2[_0x983b('0x81')]()+')','countTable');_0x5d23f7['field']('COUNT(*)',_0x983b('0x3e'));_0x198ea2['limit'](_0x65d9b4[_0x983b('0x36')]||_0x5ebf11);_0x198ea2['offset'](_0x65d9b4['offset']||0x0);return dbH[_0x983b('0x82')][_0x983b('0x2e')](_0x5d23f7['toString'](),{'type':dbH[_0x983b('0x82')]['QueryTypes']['SELECT']})[_0x983b('0x22')](function(_0x2bc8c8){if(!_0x2bc8c8[_0x983b('0x33')]){_0x3a37a4=0x0;}else{_0x3a37a4=_0x2bc8c8[0x0]['count']||0x0;}return dbH[_0x983b('0x82')][_0x983b('0x2e')](_0x198ea2[_0x983b('0x81')](),{'type':dbH[_0x983b('0x82')][_0x983b('0x83')][_0x983b('0x9f')]});})[_0x983b('0x22')](function(_0xd78edf){return{'rows':_0xd78edf||[],'count':_0x3a37a4};});}});}exports[_0x983b('0xa0')]=function(_0x25b25f,_0x49033f){return runReport(_0x25b25f[_0x983b('0x42')],_0x25b25f[_0x983b('0x2e')],_0x25b25f[_0x983b('0x3d')])[_0x983b('0x22')](respondWithResult(_0x49033f,null))[_0x983b('0x40')](handleError(_0x49033f,null));};exports[_0x983b('0xa1')]=runReport;exports['query']=function(_0x459613,_0x5bfe56){var _0x5255ef=0xa;var _0x5ba171=[_0x983b('0x54'),_0x983b('0x55'),_0x983b('0x56'),_0x983b('0x57')];var _0x4033ae={'SUM':_0x983b('0x84'),'COUNT':_0x983b('0x58'),'COUNT DISTINCT':_0x983b('0x59'),'MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0x983b('0x5b'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x983b('0x5d')};var _0x1f3389={'SEC_TO_TIME':_0x983b('0x5e'),'DATE':'DATE(%s)','HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x983b('0x87')};var _0x5b1d3d=function(_0x16cfb5){return!_[_0x983b('0x62')]([_0x983b('0x63'),'IS\x20NOT\x20NULL',_0x983b('0x65'),_0x983b('0x66')],_0x16cfb5);};var _0x3cae8d=function(_0x48b19c){if(!_0x48b19c||!_0x48b19c[_0x983b('0x67')]['length']){return'';}for(var _0x31f4f4='(',_0x4fdd86=0x0;_0x4fdd86<_0x48b19c['rules'][_0x983b('0x33')];_0x4fdd86+=0x1){_0x4fdd86>0x0&&(_0x31f4f4+='\x20'+_0x48b19c[_0x983b('0x68')]+'\x20');_0x31f4f4+=_0x48b19c[_0x983b('0x67')][_0x4fdd86]['group']?_0x3cae8d(_0x48b19c['rules'][_0x4fdd86][_0x983b('0x69')]):_0x48b19c[_0x983b('0x67')][_0x4fdd86][_0x983b('0x6a')]+'\x20'+_0x48b19c[_0x983b('0x67')][_0x4fdd86]['condition']+(_0x5b1d3d(_0x48b19c['rules'][_0x4fdd86][_0x983b('0x6b')])?'\x20'+_0x48b19c[_0x983b('0x67')][_0x4fdd86][_0x983b('0x6c')]:'');}return _0x31f4f4+')';};var _0x1c4614={'where':{'id':_0x459613[_0x983b('0x42')]['id']}},_0x259796,_0x22d1a8,_0x52e050,_0x21eb29,_0x4c0c67;_0x1c4614=_[_0x983b('0x3c')]({},_0x1c4614,_0x459613[_0x983b('0x3d')]);return db[_0x983b('0x2a')][_0x983b('0x47')](_0x1c4614)[_0x983b('0x22')](function(_0x59918c){if(_0x59918c){_0x259796=_0x59918c;return _0x59918c['getFields']();}return null;})[_0x983b('0x22')](function(_0x2f4483){if(_0x2f4483){if(!_0x2f4483[_0x983b('0x33')]){throw new db['Sequelize'][(_0x983b('0x6d'))](_0x983b('0x6e'),0x193);}_0x22d1a8=_0x2f4483;return db[_0x983b('0x6f')][_0x983b('0x70')]({'raw':!![]});}return null;})[_0x983b('0x22')](function(_0x596bb0){if(_0x596bb0){_0x52e050=_[_0x983b('0x71')](_0x596bb0,'id');var _0xc0457d;var _0x3fbc2a=squel[_0x983b('0x72')]();_0x3fbc2a['from'](_0x259796[_0x983b('0x7e')]);for(var _0x1e3e10=0x0;_0x1e3e10<_0x22d1a8[_0x983b('0x33')];_0x1e3e10+=0x1){_0xc0457d=_0x22d1a8[_0x1e3e10]['MetricId']?_0x52e050[_0x22d1a8[_0x1e3e10][_0x983b('0x73')]][_0x983b('0xa2')]:_0x22d1a8[_0x1e3e10]['field'];_0xc0457d=_0x22d1a8[_0x1e3e10][_0x983b('0x74')]?_['replace'](_0x4033ae[_0x22d1a8[_0x1e3e10][_0x983b('0x74')]],'%s',_0xc0457d):_0xc0457d;_0xc0457d=_0x22d1a8[_0x1e3e10][_0x983b('0x76')]?_[_0x983b('0x75')](_0x1f3389[_0x22d1a8[_0x1e3e10][_0x983b('0x76')]],'%s',_0xc0457d):_0xc0457d;if(_0x22d1a8[_0x1e3e10][_0x983b('0x77')]){_0x3fbc2a[_0x983b('0x69')](_0xc0457d);}_0x22d1a8[_0x1e3e10][_0x983b('0x78')]&&_0x3fbc2a[_0x983b('0x37')](_0xc0457d,_0x22d1a8[_0x1e3e10]['orderBy']===_0x983b('0x8b')?![]:!![]);_0x3fbc2a[_0x983b('0x6a')](_0xc0457d,_0x22d1a8[_0x1e3e10]['alias']||_0xc0457d);}if(_0x259796['joins']){_0x259796[_0x983b('0x7a')]=JSON[_0x983b('0x8c')](_0x259796[_0x983b('0x7a')]);for(var _0x3c628f=0x0;_0x3c628f<_0x259796[_0x983b('0x7a')][_0x983b('0x33')];_0x3c628f+=0x1){if(_0x259796[_0x983b('0x7a')][_0x3c628f][_0x983b('0x2c')]&&_[_0x983b('0x62')](_0x5ba171,_0x259796[_0x983b('0x7a')][_0x3c628f][_0x983b('0x2c')])&&_0x259796[_0x983b('0x7a')][_0x3c628f]['parentKey']&&_0x259796[_0x983b('0x7a')][_0x3c628f]['foreignTable']&&_0x259796[_0x983b('0x7a')][_0x3c628f]['foreignKey']){_0x3fbc2a[_0x259796[_0x983b('0x7a')][_0x3c628f][_0x983b('0x2c')]](_0x259796[_0x983b('0x7a')][_0x3c628f][_0x983b('0x7c')],null,util[_0x983b('0x76')](_0x983b('0x7d'),_0x259796[_0x983b('0x7e')],_0x259796[_0x983b('0x7a')][_0x3c628f][_0x983b('0x7b')],_0x259796[_0x983b('0x7a')][_0x3c628f][_0x983b('0x7c')],_0x259796[_0x983b('0x7a')][_0x3c628f][_0x983b('0x8d')]));}}}if(_0x259796[_0x983b('0x7f')]){_0x259796['conditions']=JSON['parse'](_0x259796[_0x983b('0x7f')]);_0x3fbc2a[_0x983b('0x39')](_0x3cae8d(_0x259796['conditions'][_0x983b('0x69')]));}_0x4c0c67=_0x3fbc2a['clone']();_0x3fbc2a['limit'](_0x5255ef);_0x3fbc2a[_0x983b('0x1c')](0x0);logger['debug'](_0x983b('0xa3'),_0x3fbc2a[_0x983b('0x81')]());return dbH['sequelize']['query'](_0x3fbc2a[_0x983b('0x81')](),{'type':dbH[_0x983b('0x82')][_0x983b('0x83')]['SELECT']});}})[_0x983b('0x22')](function(){return{'sql':_0x4c0c67[_0x983b('0x81')]()};})['then'](respondWithResult(_0x5bfe56,null))['catch'](handleError(_0x5bfe56,null));};
\ No newline at end of file