Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 581e1aa..b545fea 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0f49=['status','end','json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','get','CustomReports','UserProfileResource','sendStatus','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','keys','query','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','filter','where','merge','options','AnalyticCustomReport','includeAll','findAll','rows','catch','show','params','include','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','find','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','join','cross_join','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20NOT\x20EMPTY','rules','group','field','condition','value','getFields','ValidationErrorItem','AnalyticMetric','keyBy','from','table','MetricId','metric','function','replace','format','groupBy','orderBy','DESC','alias','joins','parse','foreignTable','parentKey','foreignKey','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','SELECT','left_join','right_join','SUM(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','HOUR(%s)','operator','Sequelize','Please\x20insert\x20at\x20least\x20one\x20field','select','output','web','randomstring','csv','custom','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','endDate','info','Run\x20Query:','child_process','fork','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','run','runReport','MIN(%s)','IS\x20EMPTY','%s.%s\x20=\x20%s.%s','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb'];(function(_0x387583,_0x127b08){var _0x45d2f9=function(_0x1d82ac){while(--_0x1d82ac){_0x387583['push'](_0x387583['shift']());}};_0x45d2f9(++_0x127b08);}(_0x0f49,0x8e));var _0x90f4=function(_0x5f52a4,_0x5706d9){_0x5f52a4=_0x5f52a4-0x0;var _0xde1bce=_0x0f49[_0x5f52a4];return _0xde1bce;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x90f4('0x0'));var rimraf=require(_0x90f4('0x1'));var zipdir=require(_0x90f4('0x2'));var jsonpatch=require(_0x90f4('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x90f4('0x4'));var Mustache=require(_0x90f4('0x5'));var util=require(_0x90f4('0x6'));var path=require(_0x90f4('0x7'));var sox=require(_0x90f4('0x8'));var csv=require(_0x90f4('0x9'));var ejs=require(_0x90f4('0xa'));var fs=require('fs');var _=require(_0x90f4('0xb'));var squel=require(_0x90f4('0xc'));var crypto=require('crypto');var jsforce=require(_0x90f4('0xd'));var deskjs=require(_0x90f4('0xe'));var toCsv=require(_0x90f4('0x9'));var querystring=require(_0x90f4('0xf'));var Papa=require('papaparse');var Redis=require(_0x90f4('0x10'));var authService=require(_0x90f4('0x11'));var qs=require(_0x90f4('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x90f4('0x13'));var logger=require(_0x90f4('0x14'))(_0x90f4('0x15'));var utils=require(_0x90f4('0x16'));var config=require(_0x90f4('0x17'));var licenseUtil=require(_0x90f4('0x18'));var db=require('../../mysqldb')['db'];var dbH=require(_0x90f4('0x19'))['dbH'];function respondWithStatusCode(_0x4f9b64,_0xa947f9){_0xa947f9=_0xa947f9||0xcc;return function(_0xf6dd74){if(_0xf6dd74){return _0x4f9b64['sendStatus'](_0xa947f9);}return _0x4f9b64[_0x90f4('0x1a')](_0xa947f9)[_0x90f4('0x1b')]();};}function respondWithResult(_0x28ca17,_0x34759a){_0x34759a=_0x34759a||0xc8;return function(_0x28c6ad){if(_0x28c6ad){return _0x28ca17[_0x90f4('0x1a')](_0x34759a)[_0x90f4('0x1c')](_0x28c6ad);}};}function respondWithFilteredResult(_0x40dd0d,_0x5dc24e){return function(_0x5d0792){if(_0x5d0792){var _0x9b1067=_0x5d0792[_0x90f4('0x1d')],_0x5e5c6d=_0x5dc24e[_0x90f4('0x1e')],_0x187dd1=_0x5dc24e['offset']+_0x5dc24e[_0x90f4('0x1f')],_0x501b6c;if(_0x187dd1>=_0x9b1067){_0x187dd1=_0x9b1067;_0x501b6c=0xc8;}else{_0x501b6c=0xce;}_0x40dd0d[_0x90f4('0x1a')](_0x501b6c);return _0x40dd0d[_0x90f4('0x20')](_0x90f4('0x21'),_0x5e5c6d+'-'+_0x187dd1+'/'+_0x9b1067)[_0x90f4('0x1c')](_0x5d0792);}return null;};}function patchUpdates(_0x11b730){return function(_0x45ea28){try{jsonpatch[_0x90f4('0x22')](_0x45ea28,_0x11b730,!![]);}catch(_0x376822){return BPromise['reject'](_0x376822);}return _0x45ea28[_0x90f4('0x23')]();};}function saveUpdates(_0x2e16cb,_0x49d9bc){return function(_0x298d80){if(_0x298d80){return _0x298d80[_0x90f4('0x24')](_0x2e16cb)[_0x90f4('0x25')](function(_0x4ea43b){return _0x4ea43b;});}return null;};}function removeEntity(_0x5ae0b2,_0x52c3ad){return function(_0x3d2d4b){if(_0x3d2d4b){return _0x3d2d4b[_0x90f4('0x26')]()[_0x90f4('0x25')](function(){var _0x574935=_0x3d2d4b[_0x90f4('0x27')]({'plain':!![]});var _0x454e28=_0x90f4('0x28');return db[_0x90f4('0x29')]['destroy']({'where':{'type':_0x454e28,'resourceId':_0x574935['id']}})[_0x90f4('0x25')](function(){return _0x3d2d4b;});})[_0x90f4('0x25')](function(){_0x5ae0b2[_0x90f4('0x1a')](0xcc)[_0x90f4('0x1b')]();});}};}function handleEntityNotFound(_0x4a0630,_0x1fa720){return function(_0x175cd6){if(!_0x175cd6){_0x4a0630[_0x90f4('0x2a')](0x194);}return _0x175cd6;};}function handleError(_0x443419,_0xbd26f2){_0xbd26f2=_0xbd26f2||0x1f4;return function(_0x31655d){logger[_0x90f4('0x2b')](_0x31655d[_0x90f4('0x2c')]);if(_0x31655d[_0x90f4('0x2d')]){delete _0x31655d[_0x90f4('0x2d')];}_0x443419[_0x90f4('0x1a')](_0xbd26f2)[_0x90f4('0x2e')](_0x31655d);};}exports[_0x90f4('0x2f')]=function(_0x3aa915,_0xac8cd7){var _0x1809d1={},_0x332ee2={},_0x1009ca={'count':0x0,'rows':[]};var _0x4d8b30=_[_0x90f4('0x30')](db['AnalyticCustomReport'][_0x90f4('0x31')],function(_0x2ebdfe){return{'name':_0x2ebdfe[_0x90f4('0x32')],'type':_0x2ebdfe[_0x90f4('0x33')][_0x90f4('0x34')]};});_0x332ee2['model']=_[_0x90f4('0x30')](_0x4d8b30,'name');_0x332ee2['query']=_[_0x90f4('0x35')](_0x3aa915[_0x90f4('0x36')]);_0x332ee2['filters']=_[_0x90f4('0x37')](_0x332ee2[_0x90f4('0x38')],_0x332ee2[_0x90f4('0x36')]);_0x1809d1[_0x90f4('0x39')]=_['intersection'](_0x332ee2[_0x90f4('0x38')],qs[_0x90f4('0x3a')](_0x3aa915[_0x90f4('0x36')][_0x90f4('0x3a')]));_0x1809d1['attributes']=_0x1809d1[_0x90f4('0x39')][_0x90f4('0x3b')]?_0x1809d1['attributes']:_0x332ee2['model'];if(!_0x3aa915[_0x90f4('0x36')][_0x90f4('0x3c')](_0x90f4('0x3d'))){_0x1809d1[_0x90f4('0x1f')]=qs[_0x90f4('0x1f')](_0x3aa915[_0x90f4('0x36')][_0x90f4('0x1f')]);_0x1809d1[_0x90f4('0x1e')]=qs[_0x90f4('0x1e')](_0x3aa915['query'][_0x90f4('0x1e')]);}_0x1809d1[_0x90f4('0x3e')]=qs[_0x90f4('0x3f')](_0x3aa915[_0x90f4('0x36')][_0x90f4('0x3f')]);_0x1809d1['where']=qs[_0x90f4('0x40')](_['pick'](_0x3aa915[_0x90f4('0x36')],_0x332ee2['filters']),_0x4d8b30);if(_0x3aa915[_0x90f4('0x36')][_0x90f4('0x41')]){_0x1809d1[_0x90f4('0x42')]=_[_0x90f4('0x43')](_0x1809d1['where'],{'$or':_[_0x90f4('0x30')](_0x4d8b30,function(_0x3011b6){if(_0x3011b6[_0x90f4('0x33')]!=='VIRTUAL'){var _0x244ba4={};_0x244ba4[_0x3011b6[_0x90f4('0x2d')]]={'$like':'%'+_0x3aa915[_0x90f4('0x36')]['filter']+'%'};return _0x244ba4;}})});}_0x1809d1=_[_0x90f4('0x43')]({},_0x1809d1,_0x3aa915[_0x90f4('0x44')]);var _0x3d0411={'where':_0x1809d1[_0x90f4('0x42')]};return db[_0x90f4('0x45')][_0x90f4('0x1d')](_0x3d0411)['then'](function(_0x430a30){_0x1009ca['count']=_0x430a30;if(_0x3aa915[_0x90f4('0x36')][_0x90f4('0x46')]){_0x1809d1['include']=[{'all':!![]}];}return db['AnalyticCustomReport'][_0x90f4('0x47')](_0x1809d1);})[_0x90f4('0x25')](function(_0xc847b){_0x1009ca[_0x90f4('0x48')]=_0xc847b;return _0x1009ca;})[_0x90f4('0x25')](respondWithFilteredResult(_0xac8cd7,_0x1809d1))[_0x90f4('0x49')](handleError(_0xac8cd7,null));};exports[_0x90f4('0x4a')]=function(_0x21f743,_0xcb26c6){var _0x19575f={'raw':![],'where':{'id':_0x21f743[_0x90f4('0x4b')]['id']}},_0x2eb786={};_0x2eb786[_0x90f4('0x38')]=_[_0x90f4('0x35')](db[_0x90f4('0x45')][_0x90f4('0x31')]);_0x2eb786[_0x90f4('0x36')]=_[_0x90f4('0x35')](_0x21f743['query']);_0x2eb786[_0x90f4('0x40')]=_[_0x90f4('0x37')](_0x2eb786[_0x90f4('0x38')],_0x2eb786[_0x90f4('0x36')]);_0x19575f[_0x90f4('0x39')]=_['intersection'](_0x2eb786[_0x90f4('0x38')],qs[_0x90f4('0x3a')](_0x21f743[_0x90f4('0x36')][_0x90f4('0x3a')]));_0x19575f[_0x90f4('0x39')]=_0x19575f[_0x90f4('0x39')][_0x90f4('0x3b')]?_0x19575f[_0x90f4('0x39')]:_0x2eb786[_0x90f4('0x38')];if(_0x21f743[_0x90f4('0x36')][_0x90f4('0x46')]){_0x19575f[_0x90f4('0x4c')]=[{'all':!![]}];}_0x19575f=_[_0x90f4('0x43')]({},_0x19575f,_0x21f743[_0x90f4('0x44')]);return db['AnalyticCustomReport']['find'](_0x19575f)[_0x90f4('0x25')](handleEntityNotFound(_0xcb26c6,null))[_0x90f4('0x25')](respondWithResult(_0xcb26c6,null))[_0x90f4('0x49')](handleError(_0xcb26c6,null));};exports[_0x90f4('0x4d')]=function(_0x1fae6d,_0x55e420){return db[_0x90f4('0x45')][_0x90f4('0x4d')](_0x1fae6d[_0x90f4('0x4e')],{})[_0x90f4('0x25')](function(_0x45a404){var _0x1ebdb9=_0x1fae6d[_0x90f4('0x4f')][_0x90f4('0x27')]({'plain':!![]});if(!_0x1ebdb9)throw new Error(_0x90f4('0x50'));if(_0x1ebdb9[_0x90f4('0x51')]===_0x90f4('0x4f')){var _0x50227d=_0x45a404[_0x90f4('0x27')]({'plain':!![]});var _0x287630='Reports';return db[_0x90f4('0x52')][_0x90f4('0x53')]({'where':{'name':_0x287630,'userProfileId':_0x1ebdb9[_0x90f4('0x54')]},'raw':!![]})[_0x90f4('0x25')](function(_0x152836){if(_0x152836&&_0x152836[_0x90f4('0x55')]===0x0){return db['UserProfileResource']['create']({'name':_0x50227d['name'],'resourceId':_0x50227d['id'],'type':_0x90f4('0x28'),'sectionId':_0x152836['id']},{})['then'](function(){return _0x45a404;});}else{return _0x45a404;}})[_0x90f4('0x49')](function(_0xaf0190){logger[_0x90f4('0x2b')](_0x90f4('0x56'),_0xaf0190);throw _0xaf0190;});}return _0x45a404;})[_0x90f4('0x25')](respondWithResult(_0x55e420,0xc9))[_0x90f4('0x49')](handleError(_0x55e420,null));};exports[_0x90f4('0x24')]=function(_0x4378a2,_0x4d0970){if(_0x4378a2[_0x90f4('0x4e')]['id']){delete _0x4378a2[_0x90f4('0x4e')]['id'];}return db['AnalyticCustomReport'][_0x90f4('0x53')]({'where':{'id':_0x4378a2[_0x90f4('0x4b')]['id']}})[_0x90f4('0x25')](handleEntityNotFound(_0x4d0970,null))['then'](saveUpdates(_0x4378a2['body'],null))[_0x90f4('0x25')](respondWithResult(_0x4d0970,null))[_0x90f4('0x49')](handleError(_0x4d0970,null));};exports[_0x90f4('0x26')]=function(_0x2cc16a,_0x230346){return db[_0x90f4('0x45')][_0x90f4('0x53')]({'where':{'id':_0x2cc16a[_0x90f4('0x4b')]['id']}})[_0x90f4('0x25')](handleEntityNotFound(_0x230346,null))[_0x90f4('0x25')](removeEntity(_0x230346,null))[_0x90f4('0x49')](handleError(_0x230346,null));};exports['preview']=function(_0x226573,_0x722433){var _0x552249=0xa;var _0x1a0ce6=[_0x90f4('0x57'),'left_join','right_join',_0x90f4('0x58')];var _0x179b0b={'SUM':'SUM(%s)','COUNT':_0x90f4('0x59'),'COUNT DISTINCT':_0x90f4('0x5a'),'MAX':_0x90f4('0x5b'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x90f4('0x5c')};var _0x238b10={'SEC_TO_TIME':_0x90f4('0x5d'),'DATE':_0x90f4('0x5e'),'HOUR':'HOUR(%s)','ROUND':_0x90f4('0x5f'),'UNIX_TIMESTAMP':_0x90f4('0x60')};var _0x46a5bb=function(_0x431bc2){return!_[_0x90f4('0x61')]([_0x90f4('0x62'),_0x90f4('0x63'),'IS\x20EMPTY',_0x90f4('0x64')],_0x431bc2);};var _0x2106d7=function(_0x167949){if(!_0x167949||!_0x167949[_0x90f4('0x65')][_0x90f4('0x3b')]){return'';}for(var _0x3e4a92='(',_0x3a009b=0x0;_0x3a009b<_0x167949[_0x90f4('0x65')]['length'];_0x3a009b+=0x1){_0x3a009b>0x0&&(_0x3e4a92+='\x20'+_0x167949['operator']+'\x20');_0x3e4a92+=_0x167949[_0x90f4('0x65')][_0x3a009b][_0x90f4('0x66')]?_0x2106d7(_0x167949[_0x90f4('0x65')][_0x3a009b]['group']):_0x167949[_0x90f4('0x65')][_0x3a009b][_0x90f4('0x67')]+'\x20'+_0x167949[_0x90f4('0x65')][_0x3a009b][_0x90f4('0x68')]+(_0x46a5bb(_0x167949['rules'][_0x3a009b][_0x90f4('0x68')])?'\x20'+_0x167949[_0x90f4('0x65')][_0x3a009b][_0x90f4('0x69')]:'');}return _0x3e4a92+')';};var _0x564b1b={'where':{'id':_0x226573[_0x90f4('0x4b')]['id']}},_0x484d83,_0xe2c6ed,_0x3139b5,_0x4adf63,_0x1551b5;_0x564b1b=_['merge']({},_0x564b1b,_0x226573[_0x90f4('0x44')]);return db[_0x90f4('0x45')][_0x90f4('0x53')](_0x564b1b)[_0x90f4('0x25')](function(_0x852769){if(_0x852769){_0x484d83=_0x852769;return _0x852769[_0x90f4('0x6a')]();}return null;})[_0x90f4('0x25')](function(_0x406bff){if(_0x406bff){if(!_0x406bff[_0x90f4('0x3b')]){throw new db['Sequelize'][(_0x90f4('0x6b'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0xe2c6ed=_0x406bff;return db[_0x90f4('0x6c')]['findAll']({'raw':!![]});}return null;})[_0x90f4('0x25')](function(_0x590448){if(_0x590448){_0x3139b5=_[_0x90f4('0x6d')](_0x590448,'id');var _0x4da05c;var _0x553e05=squel['select']();_0x553e05[_0x90f4('0x6e')](_0x484d83[_0x90f4('0x6f')]);for(var _0x2ee9cc=0x0;_0x2ee9cc<_0xe2c6ed[_0x90f4('0x3b')];_0x2ee9cc+=0x1){_0x4da05c=_0xe2c6ed[_0x2ee9cc][_0x90f4('0x70')]?_0x3139b5[_0xe2c6ed[_0x2ee9cc][_0x90f4('0x70')]][_0x90f4('0x71')]:_0xe2c6ed[_0x2ee9cc]['field'];_0x4da05c=_0xe2c6ed[_0x2ee9cc][_0x90f4('0x72')]?_[_0x90f4('0x73')](_0x179b0b[_0xe2c6ed[_0x2ee9cc][_0x90f4('0x72')]],'%s',_0x4da05c):_0x4da05c;_0x4da05c=_0xe2c6ed[_0x2ee9cc][_0x90f4('0x74')]?_[_0x90f4('0x73')](_0x238b10[_0xe2c6ed[_0x2ee9cc][_0x90f4('0x74')]],'%s',_0x4da05c):_0x4da05c;if(_0xe2c6ed[_0x2ee9cc][_0x90f4('0x75')]){_0x553e05[_0x90f4('0x66')](_0x4da05c);}_0xe2c6ed[_0x2ee9cc][_0x90f4('0x76')]&&_0x553e05[_0x90f4('0x3e')](_0x4da05c,_0xe2c6ed[_0x2ee9cc][_0x90f4('0x76')]===_0x90f4('0x77')?![]:!![]);_0x553e05[_0x90f4('0x67')](_0x4da05c,_0xe2c6ed[_0x2ee9cc][_0x90f4('0x78')]||_0x4da05c);}if(_0x484d83[_0x90f4('0x79')]){_0x484d83[_0x90f4('0x79')]=JSON[_0x90f4('0x7a')](_0x484d83[_0x90f4('0x79')]);for(var _0xb02667=0x0;_0xb02667<_0x484d83[_0x90f4('0x79')][_0x90f4('0x3b')];_0xb02667+=0x1){if(_0x484d83[_0x90f4('0x79')][_0xb02667][_0x90f4('0x33')]&&_[_0x90f4('0x61')](_0x1a0ce6,_0x484d83['joins'][_0xb02667][_0x90f4('0x33')])&&_0x484d83[_0x90f4('0x79')][_0xb02667]['parentKey']&&_0x484d83[_0x90f4('0x79')][_0xb02667][_0x90f4('0x7b')]&&_0x484d83[_0x90f4('0x79')][_0xb02667]['foreignKey']){_0x553e05[_0x484d83[_0x90f4('0x79')][_0xb02667][_0x90f4('0x33')]](_0x484d83[_0x90f4('0x79')][_0xb02667][_0x90f4('0x7b')],null,util[_0x90f4('0x74')]('%s.%s\x20=\x20%s.%s',_0x484d83[_0x90f4('0x6f')],_0x484d83[_0x90f4('0x79')][_0xb02667][_0x90f4('0x7c')],_0x484d83[_0x90f4('0x79')][_0xb02667][_0x90f4('0x7b')],_0x484d83[_0x90f4('0x79')][_0xb02667][_0x90f4('0x7d')]));}}}if(_0x484d83[_0x90f4('0x7e')]){_0x484d83[_0x90f4('0x7e')]=JSON['parse'](_0x484d83[_0x90f4('0x7e')]);_0x553e05[_0x90f4('0x42')](_0x2106d7(_0x484d83[_0x90f4('0x7e')][_0x90f4('0x66')]));}_0x1551b5=_0x553e05[_0x90f4('0x7f')]();_0x553e05[_0x90f4('0x1f')](_0x552249);_0x553e05[_0x90f4('0x1e')](0x0);logger[_0x90f4('0x80')](_0x90f4('0x81'),_0x553e05[_0x90f4('0x82')]());return dbH[_0x90f4('0x83')][_0x90f4('0x36')](_0x553e05['toString'](),{'type':dbH[_0x90f4('0x83')][_0x90f4('0x84')][_0x90f4('0x85')]});}})[_0x90f4('0x25')](respondWithResult(_0x722433,null))[_0x90f4('0x49')](handleError(_0x722433,null));};function runReport(_0x352608,_0x332884,_0x497140){var _0x1ddd91=_0x332884[_0x90f4('0x2d')];var _0x887446=0xa;var _0x517bbe=[_0x90f4('0x57'),_0x90f4('0x86'),_0x90f4('0x87'),_0x90f4('0x58')];var _0x1ee737={'SUM':_0x90f4('0x88'),'COUNT':_0x90f4('0x59'),'COUNT DISTINCT':_0x90f4('0x5a'),'MAX':_0x90f4('0x5b'),'MIN':'MIN(%s)','AVG':_0x90f4('0x89'),'GROUP_CONCAT':_0x90f4('0x8a'),'GROUP_CONCAT ASC':_0x90f4('0x8b'),'GROUP_CONCAT DESC':_0x90f4('0x5c')};var _0x4fb487={'SEC_TO_TIME':_0x90f4('0x5d'),'DATE':_0x90f4('0x5e'),'HOUR':_0x90f4('0x8c'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x55b8ad=function(_0x48a344){return!_[_0x90f4('0x61')]([_0x90f4('0x62'),_0x90f4('0x63'),'IS\x20EMPTY',_0x90f4('0x64')],_0x48a344);};var _0x5e0792=function(_0x4a73a8){if(!_0x4a73a8||!_0x4a73a8[_0x90f4('0x65')]['length']){return'';}for(var _0x198d97='(',_0x564435=0x0;_0x564435<_0x4a73a8['rules'][_0x90f4('0x3b')];_0x564435+=0x1){_0x564435>0x0&&(_0x198d97+='\x20'+_0x4a73a8[_0x90f4('0x8d')]+'\x20');_0x198d97+=_0x4a73a8[_0x90f4('0x65')][_0x564435][_0x90f4('0x66')]?_0x5e0792(_0x4a73a8[_0x90f4('0x65')][_0x564435][_0x90f4('0x66')]):_0x4a73a8[_0x90f4('0x65')][_0x564435]['field']+'\x20'+_0x4a73a8['rules'][_0x564435]['condition']+(_0x55b8ad(_0x4a73a8['rules'][_0x564435]['condition'])?'\x20'+_0x4a73a8[_0x90f4('0x65')][_0x564435][_0x90f4('0x69')]:'');}return _0x198d97+')';};var _0xa7017={'where':{'id':_0x352608['id']}},_0x383ecb,_0x73a3bc,_0x5b6b8c,_0x3ad40f,_0x40fc3b;_0xa7017=_[_0x90f4('0x43')]({},_0xa7017,_0x497140);return db[_0x90f4('0x45')][_0x90f4('0x53')](_0xa7017)[_0x90f4('0x25')](function(_0x366004){if(_0x366004){_0x383ecb=_0x366004;return _0x366004[_0x90f4('0x6a')]();}return null;})[_0x90f4('0x25')](function(_0x439674){if(_0x439674){if(!_0x439674[_0x90f4('0x3b')]){throw new db[(_0x90f4('0x8e'))][(_0x90f4('0x6b'))](_0x90f4('0x8f'),0x193);}_0x73a3bc=_0x439674;return db[_0x90f4('0x6c')][_0x90f4('0x47')]({'raw':!![]});}return null;})[_0x90f4('0x25')](function(_0x37c8e2){if(_0x37c8e2){_0x5b6b8c=_[_0x90f4('0x6d')](_0x37c8e2,'id');var _0x4c1fe9;var _0x54ea66=squel[_0x90f4('0x90')]();_0x54ea66[_0x90f4('0x6e')](_0x383ecb[_0x90f4('0x6f')]);for(var _0x2553b4=0x0;_0x2553b4<_0x73a3bc[_0x90f4('0x3b')];_0x2553b4+=0x1){_0x4c1fe9=_0x73a3bc[_0x2553b4][_0x90f4('0x70')]?_0x5b6b8c[_0x73a3bc[_0x2553b4]['MetricId']][_0x90f4('0x71')]:_0x73a3bc[_0x2553b4]['field'];_0x4c1fe9=_0x73a3bc[_0x2553b4][_0x90f4('0x72')]?_[_0x90f4('0x73')](_0x1ee737[_0x73a3bc[_0x2553b4][_0x90f4('0x72')]],'%s',_0x4c1fe9):_0x4c1fe9;_0x4c1fe9=_0x73a3bc[_0x2553b4][_0x90f4('0x74')]?_[_0x90f4('0x73')](_0x4fb487[_0x73a3bc[_0x2553b4]['format']],'%s',_0x4c1fe9):_0x4c1fe9;if(_0x73a3bc[_0x2553b4][_0x90f4('0x75')]){_0x54ea66[_0x90f4('0x66')](_0x4c1fe9);}_0x73a3bc[_0x2553b4]['orderBy']&&_0x54ea66[_0x90f4('0x3e')](_0x4c1fe9,_0x73a3bc[_0x2553b4]['orderBy']===_0x90f4('0x77')?![]:!![]);_0x54ea66[_0x90f4('0x67')](_0x4c1fe9,_0x73a3bc[_0x2553b4][_0x90f4('0x78')]||_0x4c1fe9);}if(_0x383ecb[_0x90f4('0x79')]){_0x383ecb[_0x90f4('0x79')]=JSON[_0x90f4('0x7a')](_0x383ecb[_0x90f4('0x79')]);for(var _0x57186d=0x0;_0x57186d<_0x383ecb[_0x90f4('0x79')][_0x90f4('0x3b')];_0x57186d+=0x1){if(_0x383ecb['joins'][_0x57186d][_0x90f4('0x33')]&&_[_0x90f4('0x61')](_0x517bbe,_0x383ecb[_0x90f4('0x79')][_0x57186d]['type'])&&_0x383ecb[_0x90f4('0x79')][_0x57186d]['parentKey']&&_0x383ecb[_0x90f4('0x79')][_0x57186d][_0x90f4('0x7b')]&&_0x383ecb[_0x90f4('0x79')][_0x57186d][_0x90f4('0x7d')]){_0x54ea66[_0x383ecb['joins'][_0x57186d][_0x90f4('0x33')]](_0x383ecb[_0x90f4('0x79')][_0x57186d]['foreignTable'],null,util[_0x90f4('0x74')]('%s.%s\x20=\x20%s.%s',_0x383ecb[_0x90f4('0x6f')],_0x383ecb[_0x90f4('0x79')][_0x57186d][_0x90f4('0x7c')],_0x383ecb[_0x90f4('0x79')][_0x57186d][_0x90f4('0x7b')],_0x383ecb['joins'][_0x57186d][_0x90f4('0x7d')]));}}}if(_0x383ecb[_0x90f4('0x7e')]){_0x383ecb[_0x90f4('0x7e')]=JSON[_0x90f4('0x7a')](_0x383ecb[_0x90f4('0x7e')]);_0x54ea66[_0x90f4('0x42')](_0x5e0792(_0x383ecb[_0x90f4('0x7e')]['group']));}_0x40fc3b=_0x54ea66[_0x90f4('0x7f')]();_0x54ea66['limit'](_0x887446);_0x54ea66['offset'](0x0);return;}})[_0x90f4('0x25')](function(){if(_0x332884[_0x90f4('0x91')]===_0x90f4('0x92')){return null;}var _0x19de8e=_[_0x90f4('0x43')](_0x332884,{'name':_0x332884['fullPath']||_0x332884[_0x90f4('0x2d')]||_0x383ecb[_0x90f4('0x2d')],'basename':_0x1ddd91,'savename':util[_0x90f4('0x74')]('%s-%s.%s',_0x332884[_0x90f4('0x2d')]||_0x383ecb[_0x90f4('0x2d')],require(_0x90f4('0x93'))['generate'](0x4),_0x332884['output']||_0x90f4('0x94')),'reportId':_0x383ecb['id'],'reportType':_0x90f4('0x95')});return db['AnalyticExtractedReport']['create'](_0x19de8e,{'raw':!![]});})['then'](function(_0x23e324){if(_0x383ecb[_0x90f4('0x6f')]==='cdr'){_0x40fc3b[_0x90f4('0x42')](_0x383ecb[_0x90f4('0x6f')]+_0x90f4('0x96'),_0x332884[_0x90f4('0x97')],_0x332884['endDate']);}else{_0x40fc3b[_0x90f4('0x42')](_0x383ecb[_0x90f4('0x6f')]+_0x90f4('0x98'),_0x332884[_0x90f4('0x97')],_0x332884[_0x90f4('0x99')]);}if(_0x23e324){logger[_0x90f4('0x9a')](_0x90f4('0x9b'),_0x40fc3b[_0x90f4('0x82')]());require(_0x90f4('0x9c'))[_0x90f4('0x9d')](path[_0x90f4('0x57')](__dirname,_0x90f4('0x9e'),_0x23e324['output']),[_0x23e324['id'],_0x40fc3b[_0x90f4('0x82')](),path['join'](__dirname,_0x90f4('0x9f'),_0x23e324[_0x90f4('0xa0')]),_0x1ddd91]);return _0x23e324;}else{var _0x55c0ed=squel[_0x90f4('0x90')]();_0x55c0ed[_0x90f4('0x6e')]('('+_0x40fc3b[_0x90f4('0x82')]()+')',_0x90f4('0xa1'));_0x55c0ed['field'](_0x90f4('0xa2'),'count');_0x40fc3b[_0x90f4('0x1f')](_0x332884[_0x90f4('0x1f')]||_0x887446);_0x40fc3b['offset'](_0x332884['offset']||0x0);return dbH['sequelize'][_0x90f4('0x36')](_0x55c0ed[_0x90f4('0x82')](),{'type':dbH[_0x90f4('0x83')]['QueryTypes'][_0x90f4('0x85')]})[_0x90f4('0x25')](function(_0x1544b8){if(!_0x1544b8[_0x90f4('0x3b')]){_0x3ad40f=0x0;}else{_0x3ad40f=_0x1544b8[0x0][_0x90f4('0x1d')]||0x0;}return dbH[_0x90f4('0x83')][_0x90f4('0x36')](_0x40fc3b[_0x90f4('0x82')](),{'type':dbH[_0x90f4('0x83')][_0x90f4('0x84')]['SELECT']});})[_0x90f4('0x25')](function(_0x11c77f){return{'rows':_0x11c77f||[],'count':_0x3ad40f};});}});}exports[_0x90f4('0xa3')]=function(_0x3a6f52,_0x4937c7){return runReport(_0x3a6f52[_0x90f4('0x4b')],_0x3a6f52[_0x90f4('0x36')],_0x3a6f52[_0x90f4('0x44')])[_0x90f4('0x25')](respondWithResult(_0x4937c7,null))[_0x90f4('0x49')](handleError(_0x4937c7,null));};exports[_0x90f4('0xa4')]=runReport;exports['query']=function(_0x274a06,_0x18f1ef){var _0x13f02e=0xa;var _0x4b2868=[_0x90f4('0x57'),_0x90f4('0x86'),'right_join',_0x90f4('0x58')];var _0x528fb9={'SUM':_0x90f4('0x88'),'COUNT':'COUNT(%s)','COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x90f4('0x5b'),'MIN':_0x90f4('0xa5'),'AVG':_0x90f4('0x89'),'GROUP_CONCAT':_0x90f4('0x8a'),'GROUP_CONCAT ASC':_0x90f4('0x8b'),'GROUP_CONCAT DESC':_0x90f4('0x5c')};var _0x27d653={'SEC_TO_TIME':_0x90f4('0x5d'),'DATE':_0x90f4('0x5e'),'HOUR':_0x90f4('0x8c'),'ROUND':_0x90f4('0x5f'),'UNIX_TIMESTAMP':_0x90f4('0x60')};var _0x311833=function(_0x471c98){return!_[_0x90f4('0x61')]([_0x90f4('0x62'),_0x90f4('0x63'),_0x90f4('0xa6'),_0x90f4('0x64')],_0x471c98);};var _0x4f10d9=function(_0x3abe0e){if(!_0x3abe0e||!_0x3abe0e[_0x90f4('0x65')]['length']){return'';}for(var _0x4e5617='(',_0x71f00c=0x0;_0x71f00c<_0x3abe0e[_0x90f4('0x65')][_0x90f4('0x3b')];_0x71f00c+=0x1){_0x71f00c>0x0&&(_0x4e5617+='\x20'+_0x3abe0e['operator']+'\x20');_0x4e5617+=_0x3abe0e[_0x90f4('0x65')][_0x71f00c][_0x90f4('0x66')]?_0x4f10d9(_0x3abe0e['rules'][_0x71f00c]['group']):_0x3abe0e['rules'][_0x71f00c][_0x90f4('0x67')]+'\x20'+_0x3abe0e['rules'][_0x71f00c][_0x90f4('0x68')]+(_0x311833(_0x3abe0e[_0x90f4('0x65')][_0x71f00c]['condition'])?'\x20'+_0x3abe0e[_0x90f4('0x65')][_0x71f00c][_0x90f4('0x69')]:'');}return _0x4e5617+')';};var _0x2f318b={'where':{'id':_0x274a06['params']['id']}},_0x4a2e6b,_0x5bfb8b,_0x2a3e14,_0x4f6bc3,_0x11bcb0;_0x2f318b=_[_0x90f4('0x43')]({},_0x2f318b,_0x274a06[_0x90f4('0x44')]);return db['AnalyticCustomReport'][_0x90f4('0x53')](_0x2f318b)[_0x90f4('0x25')](function(_0x52c878){if(_0x52c878){_0x4a2e6b=_0x52c878;return _0x52c878[_0x90f4('0x6a')]();}return null;})[_0x90f4('0x25')](function(_0x53effb){if(_0x53effb){if(!_0x53effb[_0x90f4('0x3b')]){throw new db[(_0x90f4('0x8e'))][(_0x90f4('0x6b'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x5bfb8b=_0x53effb;return db[_0x90f4('0x6c')][_0x90f4('0x47')]({'raw':!![]});}return null;})[_0x90f4('0x25')](function(_0x458fce){if(_0x458fce){_0x2a3e14=_['keyBy'](_0x458fce,'id');var _0x3eba2c;var _0x3139fc=squel['select']();_0x3139fc['from'](_0x4a2e6b[_0x90f4('0x6f')]);for(var _0x17e3db=0x0;_0x17e3db<_0x5bfb8b['length'];_0x17e3db+=0x1){_0x3eba2c=_0x5bfb8b[_0x17e3db][_0x90f4('0x70')]?_0x2a3e14[_0x5bfb8b[_0x17e3db][_0x90f4('0x70')]]['metric']:_0x5bfb8b[_0x17e3db][_0x90f4('0x67')];_0x3eba2c=_0x5bfb8b[_0x17e3db][_0x90f4('0x72')]?_[_0x90f4('0x73')](_0x528fb9[_0x5bfb8b[_0x17e3db][_0x90f4('0x72')]],'%s',_0x3eba2c):_0x3eba2c;_0x3eba2c=_0x5bfb8b[_0x17e3db]['format']?_[_0x90f4('0x73')](_0x27d653[_0x5bfb8b[_0x17e3db][_0x90f4('0x74')]],'%s',_0x3eba2c):_0x3eba2c;if(_0x5bfb8b[_0x17e3db][_0x90f4('0x75')]){_0x3139fc[_0x90f4('0x66')](_0x3eba2c);}_0x5bfb8b[_0x17e3db]['orderBy']&&_0x3139fc[_0x90f4('0x3e')](_0x3eba2c,_0x5bfb8b[_0x17e3db][_0x90f4('0x76')]===_0x90f4('0x77')?![]:!![]);_0x3139fc[_0x90f4('0x67')](_0x3eba2c,_0x5bfb8b[_0x17e3db][_0x90f4('0x78')]||_0x3eba2c);}if(_0x4a2e6b[_0x90f4('0x79')]){_0x4a2e6b[_0x90f4('0x79')]=JSON[_0x90f4('0x7a')](_0x4a2e6b['joins']);for(var _0x50d38a=0x0;_0x50d38a<_0x4a2e6b[_0x90f4('0x79')]['length'];_0x50d38a+=0x1){if(_0x4a2e6b[_0x90f4('0x79')][_0x50d38a]['type']&&_['includes'](_0x4b2868,_0x4a2e6b[_0x90f4('0x79')][_0x50d38a]['type'])&&_0x4a2e6b['joins'][_0x50d38a][_0x90f4('0x7c')]&&_0x4a2e6b['joins'][_0x50d38a][_0x90f4('0x7b')]&&_0x4a2e6b[_0x90f4('0x79')][_0x50d38a][_0x90f4('0x7d')]){_0x3139fc[_0x4a2e6b[_0x90f4('0x79')][_0x50d38a]['type']](_0x4a2e6b[_0x90f4('0x79')][_0x50d38a]['foreignTable'],null,util[_0x90f4('0x74')](_0x90f4('0xa7'),_0x4a2e6b[_0x90f4('0x6f')],_0x4a2e6b[_0x90f4('0x79')][_0x50d38a][_0x90f4('0x7c')],_0x4a2e6b['joins'][_0x50d38a][_0x90f4('0x7b')],_0x4a2e6b[_0x90f4('0x79')][_0x50d38a][_0x90f4('0x7d')]));}}}if(_0x4a2e6b[_0x90f4('0x7e')]){_0x4a2e6b[_0x90f4('0x7e')]=JSON[_0x90f4('0x7a')](_0x4a2e6b[_0x90f4('0x7e')]);_0x3139fc[_0x90f4('0x42')](_0x4f10d9(_0x4a2e6b[_0x90f4('0x7e')]['group']));}_0x11bcb0=_0x3139fc[_0x90f4('0x7f')]();_0x3139fc['limit'](_0x13f02e);_0x3139fc[_0x90f4('0x1e')](0x0);logger[_0x90f4('0x80')](_0x90f4('0x81'),_0x3139fc[_0x90f4('0x82')]());return dbH[_0x90f4('0x83')][_0x90f4('0x36')](_0x3139fc[_0x90f4('0x82')](),{'type':dbH['sequelize'][_0x90f4('0x84')][_0x90f4('0x85')]});}})[_0x90f4('0x25')](function(){return{'sql':_0x11bcb0[_0x90f4('0x82')]()};})['then'](respondWithResult(_0x18f1ef,null))[_0x90f4('0x49')](handleError(_0x18f1ef,null));};
\ No newline at end of file
+var _0x4c5a=['filters','intersection','fields','attributes','hasOwnProperty','nolimit','limit','order','sort','where','pick','merge','type','options','AnalyticCustomReport','includeAll','include','findAll','rows','keys','length','find','catch','create','body','user','role','get','Reports','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','preview','join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','DATE(%s)','HOUR(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20NOT\x20EMPTY','rules','group','field','condition','getFields','Sequelize','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','from','MetricId','function','replace','format','groupBy','orderBy','DESC','alias','joins','parse','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','parentKey','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','left_join','SEC_TO_TIME(%s)','ROUND(%s)','IS\x20EMPTY','operator','ValidationErrorItem','select','table','metric','output','fullPath','%s-%s.%s','randomstring','generate','csv','custom','AnalyticExtractedReport','cdr','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','child_process','../../files/reports','savename','countTable','COUNT(*)','SELECT','run','runReport','value','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','json','offset','undefined','count','set','Content-Range','reject','update','destroy','UserProfileResource','then','end','name','send','index','map','rawAttributes','fieldName','key','model','query'];(function(_0x3d2534,_0x4d5dcc){var _0x3f38c0=function(_0x51d1f6){while(--_0x51d1f6){_0x3d2534['push'](_0x3d2534['shift']());}};_0x3f38c0(++_0x4d5dcc);}(_0x4c5a,0x1c0));var _0xa4c5=function(_0x1c2ad4,_0x42b3bb){_0x1c2ad4=_0x1c2ad4-0x0;var _0x129a4e=_0x4c5a[_0x1c2ad4];return _0x129a4e;};'use strict';var emlformat=require(_0xa4c5('0x0'));var rimraf=require(_0xa4c5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xa4c5('0x2'));var rp=require(_0xa4c5('0x3'));var moment=require('moment');var BPromise=require(_0xa4c5('0x4'));var Mustache=require(_0xa4c5('0x5'));var util=require('util');var path=require(_0xa4c5('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xa4c5('0x7'));var fs=require('fs');var fs_extra=require(_0xa4c5('0x8'));var _=require(_0xa4c5('0x9'));var squel=require(_0xa4c5('0xa'));var crypto=require('crypto');var jsforce=require(_0xa4c5('0xb'));var deskjs=require(_0xa4c5('0xc'));var toCsv=require(_0xa4c5('0xd'));var querystring=require(_0xa4c5('0xe'));var Papa=require('papaparse');var Redis=require(_0xa4c5('0xf'));var authService=require(_0xa4c5('0x10'));var qs=require(_0xa4c5('0x11'));var as=require(_0xa4c5('0x12'));var hardwareService=require(_0xa4c5('0x13'));var logger=require(_0xa4c5('0x14'))(_0xa4c5('0x15'));var utils=require(_0xa4c5('0x16'));var config=require(_0xa4c5('0x17'));var licenseUtil=require(_0xa4c5('0x18'));var db=require(_0xa4c5('0x19'))['db'];var dbH=require('../../mysqldb')[_0xa4c5('0x1a')];function respondWithStatusCode(_0x1ee5b6,_0x405327){_0x405327=_0x405327||0xcc;return function(_0x73d01c){if(_0x73d01c){return _0x1ee5b6[_0xa4c5('0x1b')](_0x405327);}return _0x1ee5b6[_0xa4c5('0x1c')](_0x405327)['end']();};}function respondWithResult(_0x44c912,_0x4dcc51){_0x4dcc51=_0x4dcc51||0xc8;return function(_0x29fbf7){if(_0x29fbf7){return _0x44c912['status'](_0x4dcc51)[_0xa4c5('0x1d')](_0x29fbf7);}};}function respondWithFilteredResult(_0x47bc0c,_0x2b4099){return function(_0x2a4950){if(_0x2a4950){var _0xad448f=typeof _0x2b4099[_0xa4c5('0x1e')]===_0xa4c5('0x1f')&&typeof _0x2b4099['limit']===_0xa4c5('0x1f');var _0x3daeab=_0x2a4950[_0xa4c5('0x20')];var _0x5769d8=_0xad448f?0x0:_0x2b4099['offset'];var _0x6c85b2=_0xad448f?_0x2a4950[_0xa4c5('0x20')]:_0x2b4099[_0xa4c5('0x1e')]+_0x2b4099['limit'];var _0x379fc2;if(_0x6c85b2>=_0x3daeab){_0x6c85b2=_0x3daeab;_0x379fc2=0xc8;}else{_0x379fc2=0xce;}_0x47bc0c[_0xa4c5('0x1c')](_0x379fc2);return _0x47bc0c[_0xa4c5('0x21')](_0xa4c5('0x22'),_0x5769d8+'-'+_0x6c85b2+'/'+_0x3daeab)[_0xa4c5('0x1d')](_0x2a4950);}return null;};}function patchUpdates(_0x4890c1){return function(_0x109546){try{jsonpatch['apply'](_0x109546,_0x4890c1,!![]);}catch(_0x547c2a){return BPromise[_0xa4c5('0x23')](_0x547c2a);}return _0x109546['save']();};}function saveUpdates(_0x47fd8e,_0x565c99){return function(_0x15fdd2){if(_0x15fdd2){return _0x15fdd2[_0xa4c5('0x24')](_0x47fd8e)['then'](function(_0x4aa906){return _0x4aa906;});}return null;};}function removeEntity(_0x287d99,_0x5de749){return function(_0x129d79){if(_0x129d79){return _0x129d79[_0xa4c5('0x25')]()['then'](function(){var _0x5acedf=_0x129d79['get']({'plain':!![]});var _0xdcf314='CustomReports';return db[_0xa4c5('0x26')]['destroy']({'where':{'type':_0xdcf314,'resourceId':_0x5acedf['id']}})[_0xa4c5('0x27')](function(){return _0x129d79;});})[_0xa4c5('0x27')](function(){_0x287d99['status'](0xcc)[_0xa4c5('0x28')]();});}};}function handleEntityNotFound(_0x56ab35,_0x8a4c13){return function(_0x1106f1){if(!_0x1106f1){_0x56ab35[_0xa4c5('0x1b')](0x194);}return _0x1106f1;};}function handleError(_0x38a3cc,_0x4b5620){_0x4b5620=_0x4b5620||0x1f4;return function(_0x271706){logger['error'](_0x271706['stack']);if(_0x271706[_0xa4c5('0x29')]){delete _0x271706[_0xa4c5('0x29')];}_0x38a3cc[_0xa4c5('0x1c')](_0x4b5620)[_0xa4c5('0x2a')](_0x271706);};}exports[_0xa4c5('0x2b')]=function(_0x281754,_0x1b57c9){var _0x57abe3={},_0x40c039={},_0xe6993f={'count':0x0,'rows':[]};var _0x21051e=_[_0xa4c5('0x2c')](db['AnalyticCustomReport'][_0xa4c5('0x2d')],function(_0x287257){return{'name':_0x287257[_0xa4c5('0x2e')],'type':_0x287257['type'][_0xa4c5('0x2f')]};});_0x40c039[_0xa4c5('0x30')]=_['map'](_0x21051e,'name');_0x40c039[_0xa4c5('0x31')]=_['keys'](_0x281754[_0xa4c5('0x31')]);_0x40c039[_0xa4c5('0x32')]=_[_0xa4c5('0x33')](_0x40c039['model'],_0x40c039['query']);_0x57abe3['attributes']=_[_0xa4c5('0x33')](_0x40c039[_0xa4c5('0x30')],qs[_0xa4c5('0x34')](_0x281754[_0xa4c5('0x31')][_0xa4c5('0x34')]));_0x57abe3[_0xa4c5('0x35')]=_0x57abe3[_0xa4c5('0x35')]['length']?_0x57abe3[_0xa4c5('0x35')]:_0x40c039[_0xa4c5('0x30')];if(!_0x281754['query'][_0xa4c5('0x36')](_0xa4c5('0x37'))){_0x57abe3[_0xa4c5('0x38')]=qs[_0xa4c5('0x38')](_0x281754[_0xa4c5('0x31')]['limit']);_0x57abe3[_0xa4c5('0x1e')]=qs[_0xa4c5('0x1e')](_0x281754['query']['offset']);}_0x57abe3[_0xa4c5('0x39')]=qs[_0xa4c5('0x3a')](_0x281754[_0xa4c5('0x31')][_0xa4c5('0x3a')]);_0x57abe3[_0xa4c5('0x3b')]=qs[_0xa4c5('0x32')](_[_0xa4c5('0x3c')](_0x281754['query'],_0x40c039[_0xa4c5('0x32')]),_0x21051e);if(_0x281754[_0xa4c5('0x31')]['filter']){_0x57abe3[_0xa4c5('0x3b')]=_[_0xa4c5('0x3d')](_0x57abe3[_0xa4c5('0x3b')],{'$or':_[_0xa4c5('0x2c')](_0x21051e,function(_0x568c4d){if(_0x568c4d[_0xa4c5('0x3e')]!=='VIRTUAL'){var _0x2363fd={};_0x2363fd[_0x568c4d['name']]={'$like':'%'+_0x281754[_0xa4c5('0x31')]['filter']+'%'};return _0x2363fd;}})});}_0x57abe3=_[_0xa4c5('0x3d')]({},_0x57abe3,_0x281754[_0xa4c5('0x3f')]);var _0x1a9bb3={'where':_0x57abe3[_0xa4c5('0x3b')]};return db[_0xa4c5('0x40')]['count'](_0x1a9bb3)[_0xa4c5('0x27')](function(_0x588e84){_0xe6993f[_0xa4c5('0x20')]=_0x588e84;if(_0x281754[_0xa4c5('0x31')][_0xa4c5('0x41')]){_0x57abe3[_0xa4c5('0x42')]=[{'all':!![]}];}return db['AnalyticCustomReport'][_0xa4c5('0x43')](_0x57abe3);})['then'](function(_0x410fde){_0xe6993f[_0xa4c5('0x44')]=_0x410fde;return _0xe6993f;})['then'](respondWithFilteredResult(_0x1b57c9,_0x57abe3))['catch'](handleError(_0x1b57c9,null));};exports['show']=function(_0x448cca,_0x40618f){var _0xadf767={'raw':![],'where':{'id':_0x448cca['params']['id']}},_0xe8ed15={};_0xe8ed15[_0xa4c5('0x30')]=_[_0xa4c5('0x45')](db['AnalyticCustomReport']['rawAttributes']);_0xe8ed15['query']=_[_0xa4c5('0x45')](_0x448cca[_0xa4c5('0x31')]);_0xe8ed15[_0xa4c5('0x32')]=_['intersection'](_0xe8ed15['model'],_0xe8ed15[_0xa4c5('0x31')]);_0xadf767['attributes']=_[_0xa4c5('0x33')](_0xe8ed15['model'],qs[_0xa4c5('0x34')](_0x448cca[_0xa4c5('0x31')][_0xa4c5('0x34')]));_0xadf767[_0xa4c5('0x35')]=_0xadf767[_0xa4c5('0x35')][_0xa4c5('0x46')]?_0xadf767[_0xa4c5('0x35')]:_0xe8ed15['model'];if(_0x448cca[_0xa4c5('0x31')]['includeAll']){_0xadf767['include']=[{'all':!![]}];}_0xadf767=_['merge']({},_0xadf767,_0x448cca[_0xa4c5('0x3f')]);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0xadf767)['then'](handleEntityNotFound(_0x40618f,null))['then'](respondWithResult(_0x40618f,null))[_0xa4c5('0x48')](handleError(_0x40618f,null));};exports[_0xa4c5('0x49')]=function(_0x353496,_0x4e2503){return db[_0xa4c5('0x40')][_0xa4c5('0x49')](_0x353496[_0xa4c5('0x4a')],{})[_0xa4c5('0x27')](function(_0x1dcbcf){var _0x393ef7=_0x353496[_0xa4c5('0x4b')]['get']({'plain':!![]});if(!_0x393ef7)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x393ef7[_0xa4c5('0x4c')]==='user'){var _0x4a084e=_0x1dcbcf[_0xa4c5('0x4d')]({'plain':!![]});var _0x16a54c=_0xa4c5('0x4e');return db[_0xa4c5('0x4f')][_0xa4c5('0x47')]({'where':{'name':_0x16a54c,'userProfileId':_0x393ef7[_0xa4c5('0x50')]},'raw':!![]})[_0xa4c5('0x27')](function(_0x351215){if(_0x351215&&_0x351215[_0xa4c5('0x51')]===0x0){return db[_0xa4c5('0x26')][_0xa4c5('0x49')]({'name':_0x4a084e['name'],'resourceId':_0x4a084e['id'],'type':'CustomReports','sectionId':_0x351215['id']},{})[_0xa4c5('0x27')](function(){return _0x1dcbcf;});}else{return _0x1dcbcf;}})[_0xa4c5('0x48')](function(_0x5a0b2d){logger[_0xa4c5('0x52')](_0xa4c5('0x53'),_0x5a0b2d);throw _0x5a0b2d;});}return _0x1dcbcf;})[_0xa4c5('0x27')](respondWithResult(_0x4e2503,0xc9))[_0xa4c5('0x48')](handleError(_0x4e2503,null));};exports[_0xa4c5('0x24')]=function(_0x47c018,_0x419bb2){if(_0x47c018['body']['id']){delete _0x47c018[_0xa4c5('0x4a')]['id'];}return db[_0xa4c5('0x40')]['find']({'where':{'id':_0x47c018[_0xa4c5('0x54')]['id']}})['then'](handleEntityNotFound(_0x419bb2,null))['then'](saveUpdates(_0x47c018[_0xa4c5('0x4a')],null))[_0xa4c5('0x27')](respondWithResult(_0x419bb2,null))[_0xa4c5('0x48')](handleError(_0x419bb2,null));};exports['destroy']=function(_0x50f370,_0x774ce6){return db[_0xa4c5('0x40')]['find']({'where':{'id':_0x50f370[_0xa4c5('0x54')]['id']}})[_0xa4c5('0x27')](handleEntityNotFound(_0x774ce6,null))[_0xa4c5('0x27')](removeEntity(_0x774ce6,null))[_0xa4c5('0x48')](handleError(_0x774ce6,null));};exports[_0xa4c5('0x55')]=function(_0x274cb4,_0x5c9bdc){var _0x2ff696=0xa;var _0x568766=[_0xa4c5('0x56'),'left_join',_0xa4c5('0x57'),_0xa4c5('0x58')];var _0x31c37a={'SUM':_0xa4c5('0x59'),'COUNT':_0xa4c5('0x5a'),'COUNT DISTINCT':_0xa4c5('0x5b'),'MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':_0xa4c5('0x5d'),'GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':_0xa4c5('0x5f'),'GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0xd2a4f2={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xa4c5('0x63')};var _0x7dd707=function(_0xe85930){return!_[_0xa4c5('0x64')]([_0xa4c5('0x65'),_0xa4c5('0x66'),'IS\x20EMPTY',_0xa4c5('0x67')],_0xe85930);};var _0x135bba=function(_0x27ad75){if(!_0x27ad75||!_0x27ad75[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0xe4b3f4='(',_0x5386b9=0x0;_0x5386b9<_0x27ad75[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x5386b9+=0x1){_0x5386b9>0x0&&(_0xe4b3f4+='\x20'+_0x27ad75['operator']+'\x20');_0xe4b3f4+=_0x27ad75['rules'][_0x5386b9][_0xa4c5('0x69')]?_0x135bba(_0x27ad75[_0xa4c5('0x68')][_0x5386b9][_0xa4c5('0x69')]):_0x27ad75['rules'][_0x5386b9][_0xa4c5('0x6a')]+'\x20'+_0x27ad75[_0xa4c5('0x68')][_0x5386b9]['condition']+(_0x7dd707(_0x27ad75[_0xa4c5('0x68')][_0x5386b9][_0xa4c5('0x6b')])?'\x20'+_0x27ad75['rules'][_0x5386b9]['value']:'');}return _0xe4b3f4+')';};var _0x141a95={'where':{'id':_0x274cb4[_0xa4c5('0x54')]['id']}},_0x1449ae,_0x5ae88e,_0x128805,_0x1e5cf8,_0x54efe4;_0x141a95=_[_0xa4c5('0x3d')]({},_0x141a95,_0x274cb4[_0xa4c5('0x3f')]);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0x141a95)[_0xa4c5('0x27')](function(_0x2ff202){if(_0x2ff202){_0x1449ae=_0x2ff202;return _0x2ff202[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x4d1551){if(_0x4d1551){if(!_0x4d1551[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))]['ValidationErrorItem'](_0xa4c5('0x6e'),0x193);}_0x5ae88e=_0x4d1551;return db[_0xa4c5('0x6f')][_0xa4c5('0x43')]({'raw':!![]});}return null;})[_0xa4c5('0x27')](function(_0x5c19d4){if(_0x5c19d4){_0x128805=_[_0xa4c5('0x70')](_0x5c19d4,'id');var _0x1da8b7;var _0x4c7b6e=squel['select']();_0x4c7b6e[_0xa4c5('0x71')](_0x1449ae['table']);for(var _0xf299ba=0x0;_0xf299ba<_0x5ae88e[_0xa4c5('0x46')];_0xf299ba+=0x1){_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x72')]?_0x128805[_0x5ae88e[_0xf299ba][_0xa4c5('0x72')]]['metric']:_0x5ae88e[_0xf299ba]['field'];_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x31c37a[_0x5ae88e[_0xf299ba][_0xa4c5('0x73')]],'%s',_0x1da8b7):_0x1da8b7;_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0xd2a4f2[_0x5ae88e[_0xf299ba][_0xa4c5('0x75')]],'%s',_0x1da8b7):_0x1da8b7;if(_0x5ae88e[_0xf299ba][_0xa4c5('0x76')]){_0x4c7b6e[_0xa4c5('0x69')](_0x1da8b7);}_0x5ae88e[_0xf299ba][_0xa4c5('0x77')]&&_0x4c7b6e['order'](_0x1da8b7,_0x5ae88e[_0xf299ba][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x4c7b6e[_0xa4c5('0x6a')](_0x1da8b7,_0x5ae88e[_0xf299ba][_0xa4c5('0x79')]||_0x1da8b7);}if(_0x1449ae[_0xa4c5('0x7a')]){_0x1449ae['joins']=JSON[_0xa4c5('0x7b')](_0x1449ae[_0xa4c5('0x7a')]);for(var _0x3d357d=0x0;_0x3d357d<_0x1449ae['joins'][_0xa4c5('0x46')];_0x3d357d+=0x1){if(_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x568766,_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x3e')])&&_0x1449ae[_0xa4c5('0x7a')][_0x3d357d]['parentKey']&&_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7c')]&&_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7d')]){_0x4c7b6e[_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x3e')]](_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')](_0xa4c5('0x7e'),_0x1449ae['table'],_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7f')],_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x7c')],_0x1449ae['joins'][_0x3d357d]['foreignKey']));}}}if(_0x1449ae['conditions']){_0x1449ae[_0xa4c5('0x80')]=JSON['parse'](_0x1449ae[_0xa4c5('0x80')]);_0x4c7b6e[_0xa4c5('0x3b')](_0x135bba(_0x1449ae[_0xa4c5('0x80')]['group']));}_0x54efe4=_0x4c7b6e[_0xa4c5('0x81')]();_0x4c7b6e['limit'](_0x2ff696);_0x4c7b6e[_0xa4c5('0x1e')](0x0);logger[_0xa4c5('0x82')](_0xa4c5('0x83'),_0x4c7b6e[_0xa4c5('0x84')]());return dbH['sequelize'][_0xa4c5('0x31')](_0x4c7b6e['toString'](),{'type':dbH[_0xa4c5('0x85')][_0xa4c5('0x86')]['SELECT']});}})[_0xa4c5('0x27')](respondWithResult(_0x5c9bdc,null))[_0xa4c5('0x48')](handleError(_0x5c9bdc,null));};function runReport(_0x129780,_0x470a0b,_0x7c17d8){var _0x114f35=_0x470a0b[_0xa4c5('0x29')];var _0x40c2af=0xa;var _0x14f818=[_0xa4c5('0x56'),_0xa4c5('0x87'),_0xa4c5('0x57'),'cross_join'];var _0x2264b0={'SUM':_0xa4c5('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0xa4c5('0x5b'),'MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':_0xa4c5('0x5d'),'GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0x15f9f5={'SEC_TO_TIME':_0xa4c5('0x88'),'DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':_0xa4c5('0x89'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x2a5209=function(_0x46318b){return!_['includes'](['IS\x20NULL',_0xa4c5('0x66'),_0xa4c5('0x8a'),_0xa4c5('0x67')],_0x46318b);};var _0x160424=function(_0x33e58b){if(!_0x33e58b||!_0x33e58b[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0x4ee1f7='(',_0x382c64=0x0;_0x382c64<_0x33e58b[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x382c64+=0x1){_0x382c64>0x0&&(_0x4ee1f7+='\x20'+_0x33e58b[_0xa4c5('0x8b')]+'\x20');_0x4ee1f7+=_0x33e58b['rules'][_0x382c64][_0xa4c5('0x69')]?_0x160424(_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x69')]):_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6a')]+'\x20'+_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6b')]+(_0x2a5209(_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6b')])?'\x20'+_0x33e58b[_0xa4c5('0x68')][_0x382c64]['value']:'');}return _0x4ee1f7+')';};var _0x3f7df6={'where':{'id':_0x129780['id']}},_0x5d8983,_0x8de116,_0x4a911f,_0x4fca6b,_0x33212a;_0x3f7df6=_['merge']({},_0x3f7df6,_0x7c17d8);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0x3f7df6)[_0xa4c5('0x27')](function(_0x13b9a0){if(_0x13b9a0){_0x5d8983=_0x13b9a0;return _0x13b9a0[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x3b7847){if(_0x3b7847){if(!_0x3b7847[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))][(_0xa4c5('0x8c'))](_0xa4c5('0x6e'),0x193);}_0x8de116=_0x3b7847;return db[_0xa4c5('0x6f')][_0xa4c5('0x43')]({'raw':!![]});}return null;})['then'](function(_0x3315c6){if(_0x3315c6){_0x4a911f=_[_0xa4c5('0x70')](_0x3315c6,'id');var _0x2ee764;var _0x11735c=squel[_0xa4c5('0x8d')]();_0x11735c['from'](_0x5d8983[_0xa4c5('0x8e')]);for(var _0xe1055=0x0;_0xe1055<_0x8de116[_0xa4c5('0x46')];_0xe1055+=0x1){_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x72')]?_0x4a911f[_0x8de116[_0xe1055][_0xa4c5('0x72')]][_0xa4c5('0x8f')]:_0x8de116[_0xe1055][_0xa4c5('0x6a')];_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x2264b0[_0x8de116[_0xe1055][_0xa4c5('0x73')]],'%s',_0x2ee764):_0x2ee764;_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0x15f9f5[_0x8de116[_0xe1055]['format']],'%s',_0x2ee764):_0x2ee764;if(_0x8de116[_0xe1055][_0xa4c5('0x76')]){_0x11735c[_0xa4c5('0x69')](_0x2ee764);}_0x8de116[_0xe1055][_0xa4c5('0x77')]&&_0x11735c['order'](_0x2ee764,_0x8de116[_0xe1055][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x11735c[_0xa4c5('0x6a')](_0x2ee764,_0x8de116[_0xe1055][_0xa4c5('0x79')]||_0x2ee764);}if(_0x5d8983[_0xa4c5('0x7a')]){_0x5d8983[_0xa4c5('0x7a')]=JSON['parse'](_0x5d8983[_0xa4c5('0x7a')]);for(var _0x512de7=0x0;_0x512de7<_0x5d8983[_0xa4c5('0x7a')][_0xa4c5('0x46')];_0x512de7+=0x1){if(_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x14f818,_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x3e')])&&_0x5d8983['joins'][_0x512de7]['parentKey']&&_0x5d8983['joins'][_0x512de7]['foreignTable']&&_0x5d8983['joins'][_0x512de7][_0xa4c5('0x7d')]){_0x11735c[_0x5d8983[_0xa4c5('0x7a')][_0x512de7]['type']](_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')](_0xa4c5('0x7e'),_0x5d8983[_0xa4c5('0x8e')],_0x5d8983['joins'][_0x512de7]['parentKey'],_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7c')],_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7d')]));}}}if(_0x5d8983[_0xa4c5('0x80')]){_0x5d8983[_0xa4c5('0x80')]=JSON['parse'](_0x5d8983[_0xa4c5('0x80')]);_0x11735c[_0xa4c5('0x3b')](_0x160424(_0x5d8983[_0xa4c5('0x80')][_0xa4c5('0x69')]));}_0x33212a=_0x11735c['clone']();_0x11735c[_0xa4c5('0x38')](_0x40c2af);_0x11735c[_0xa4c5('0x1e')](0x0);return;}})['then'](function(){if(_0x470a0b[_0xa4c5('0x90')]==='web'){return null;}var _0x5a43a3=_[_0xa4c5('0x3d')](_0x470a0b,{'name':_0x470a0b[_0xa4c5('0x91')]||_0x470a0b['name']||_0x5d8983['name'],'basename':_0x114f35,'savename':util[_0xa4c5('0x75')](_0xa4c5('0x92'),_0x470a0b['name']||_0x5d8983['name'],require(_0xa4c5('0x93'))[_0xa4c5('0x94')](0x4),_0x470a0b['output']||_0xa4c5('0x95')),'reportId':_0x5d8983['id'],'reportType':_0xa4c5('0x96')});return db[_0xa4c5('0x97')][_0xa4c5('0x49')](_0x5a43a3,{'raw':!![]});})['then'](function(_0x33d8b2){if(_0x5d8983[_0xa4c5('0x8e')]===_0xa4c5('0x98')){_0x33212a[_0xa4c5('0x3b')](_0x5d8983[_0xa4c5('0x8e')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x470a0b[_0xa4c5('0x99')],_0x470a0b[_0xa4c5('0x9a')]);}else{_0x33212a['where'](_0x5d8983[_0xa4c5('0x8e')]+_0xa4c5('0x9b'),_0x470a0b['startDate'],_0x470a0b[_0xa4c5('0x9a')]);}if(_0x33d8b2){logger[_0xa4c5('0x9c')]('Run\x20Query:',_0x33212a[_0xa4c5('0x84')]());require(_0xa4c5('0x9d'))['fork'](path['join'](__dirname,'../../components/export/',_0x33d8b2[_0xa4c5('0x90')]),[_0x33d8b2['id'],_0x33212a[_0xa4c5('0x84')](),path['join'](__dirname,_0xa4c5('0x9e'),_0x33d8b2[_0xa4c5('0x9f')]),_0x114f35]);return _0x33d8b2;}else{var _0xff61e7=squel[_0xa4c5('0x8d')]();_0xff61e7['from']('('+_0x33212a[_0xa4c5('0x84')]()+')',_0xa4c5('0xa0'));_0xff61e7['field'](_0xa4c5('0xa1'),'count');_0x33212a[_0xa4c5('0x38')](_0x470a0b[_0xa4c5('0x38')]||_0x40c2af);_0x33212a[_0xa4c5('0x1e')](_0x470a0b['offset']||0x0);return dbH[_0xa4c5('0x85')]['query'](_0xff61e7[_0xa4c5('0x84')](),{'type':dbH['sequelize'][_0xa4c5('0x86')][_0xa4c5('0xa2')]})['then'](function(_0x67a6bb){if(!_0x67a6bb[_0xa4c5('0x46')]){_0x4fca6b=0x0;}else{_0x4fca6b=_0x67a6bb[0x0]['count']||0x0;}return dbH[_0xa4c5('0x85')][_0xa4c5('0x31')](_0x33212a[_0xa4c5('0x84')](),{'type':dbH[_0xa4c5('0x85')]['QueryTypes'][_0xa4c5('0xa2')]});})[_0xa4c5('0x27')](function(_0x20c0a4){return{'rows':_0x20c0a4||[],'count':_0x4fca6b};});}});}exports[_0xa4c5('0xa3')]=function(_0x8cfa2e,_0x1339b4){return runReport(_0x8cfa2e[_0xa4c5('0x54')],_0x8cfa2e['query'],_0x8cfa2e[_0xa4c5('0x3f')])['then'](respondWithResult(_0x1339b4,null))[_0xa4c5('0x48')](handleError(_0x1339b4,null));};exports[_0xa4c5('0xa4')]=runReport;exports[_0xa4c5('0x31')]=function(_0x570bfc,_0x23e4ad){var _0x462819=0xa;var _0x41c038=['join','left_join',_0xa4c5('0x57'),_0xa4c5('0x58')];var _0x4b074a={'SUM':_0xa4c5('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':'AVG(%s)','GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0x9f119c={'SEC_TO_TIME':_0xa4c5('0x88'),'DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xa4c5('0x63')};var _0x118a17=function(_0xafc6ce){return!_[_0xa4c5('0x64')]([_0xa4c5('0x65'),'IS\x20NOT\x20NULL',_0xa4c5('0x8a'),_0xa4c5('0x67')],_0xafc6ce);};var _0x1a7cf6=function(_0xab9063){if(!_0xab9063||!_0xab9063[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0x2c5918='(',_0x43ed39=0x0;_0x43ed39<_0xab9063[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x43ed39+=0x1){_0x43ed39>0x0&&(_0x2c5918+='\x20'+_0xab9063['operator']+'\x20');_0x2c5918+=_0xab9063['rules'][_0x43ed39]['group']?_0x1a7cf6(_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x69')]):_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x6a')]+'\x20'+_0xab9063['rules'][_0x43ed39][_0xa4c5('0x6b')]+(_0x118a17(_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x6b')])?'\x20'+_0xab9063['rules'][_0x43ed39][_0xa4c5('0xa5')]:'');}return _0x2c5918+')';};var _0x25425f={'where':{'id':_0x570bfc[_0xa4c5('0x54')]['id']}},_0x55046e,_0x4cd138,_0x1794d6,_0x523163,_0x599026;_0x25425f=_[_0xa4c5('0x3d')]({},_0x25425f,_0x570bfc[_0xa4c5('0x3f')]);return db['AnalyticCustomReport'][_0xa4c5('0x47')](_0x25425f)[_0xa4c5('0x27')](function(_0x95b18c){if(_0x95b18c){_0x55046e=_0x95b18c;return _0x95b18c[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x43bc8b){if(_0x43bc8b){if(!_0x43bc8b[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))][(_0xa4c5('0x8c'))](_0xa4c5('0x6e'),0x193);}_0x4cd138=_0x43bc8b;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})[_0xa4c5('0x27')](function(_0x5b6c3f){if(_0x5b6c3f){_0x1794d6=_['keyBy'](_0x5b6c3f,'id');var _0x4143c4;var _0x99b1da=squel['select']();_0x99b1da[_0xa4c5('0x71')](_0x55046e[_0xa4c5('0x8e')]);for(var _0x124ab1=0x0;_0x124ab1<_0x4cd138[_0xa4c5('0x46')];_0x124ab1+=0x1){_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x72')]?_0x1794d6[_0x4cd138[_0x124ab1]['MetricId']][_0xa4c5('0x8f')]:_0x4cd138[_0x124ab1][_0xa4c5('0x6a')];_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x4b074a[_0x4cd138[_0x124ab1][_0xa4c5('0x73')]],'%s',_0x4143c4):_0x4143c4;_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0x9f119c[_0x4cd138[_0x124ab1][_0xa4c5('0x75')]],'%s',_0x4143c4):_0x4143c4;if(_0x4cd138[_0x124ab1]['groupBy']){_0x99b1da[_0xa4c5('0x69')](_0x4143c4);}_0x4cd138[_0x124ab1][_0xa4c5('0x77')]&&_0x99b1da[_0xa4c5('0x39')](_0x4143c4,_0x4cd138[_0x124ab1][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x99b1da[_0xa4c5('0x6a')](_0x4143c4,_0x4cd138[_0x124ab1]['alias']||_0x4143c4);}if(_0x55046e[_0xa4c5('0x7a')]){_0x55046e['joins']=JSON[_0xa4c5('0x7b')](_0x55046e[_0xa4c5('0x7a')]);for(var _0x260821=0x0;_0x260821<_0x55046e[_0xa4c5('0x7a')][_0xa4c5('0x46')];_0x260821+=0x1){if(_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x41c038,_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')])&&_0x55046e['joins'][_0x260821][_0xa4c5('0x7f')]&&_0x55046e['joins'][_0x260821][_0xa4c5('0x7c')]&&_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7d')]){_0x99b1da[_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')]](_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')]('%s.%s\x20=\x20%s.%s',_0x55046e['table'],_0x55046e['joins'][_0x260821][_0xa4c5('0x7f')],_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7c')],_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7d')]));}}}if(_0x55046e[_0xa4c5('0x80')]){_0x55046e['conditions']=JSON[_0xa4c5('0x7b')](_0x55046e[_0xa4c5('0x80')]);_0x99b1da[_0xa4c5('0x3b')](_0x1a7cf6(_0x55046e[_0xa4c5('0x80')][_0xa4c5('0x69')]));}_0x599026=_0x99b1da[_0xa4c5('0x81')]();_0x99b1da[_0xa4c5('0x38')](_0x462819);_0x99b1da['offset'](0x0);logger[_0xa4c5('0x82')](_0xa4c5('0x83'),_0x99b1da[_0xa4c5('0x84')]());return dbH['sequelize'][_0xa4c5('0x31')](_0x99b1da['toString'](),{'type':dbH[_0xa4c5('0x85')][_0xa4c5('0x86')]['SELECT']});}})[_0xa4c5('0x27')](function(){return{'sql':_0x599026[_0xa4c5('0x84')]()};})['then'](respondWithResult(_0x23e4ad,null))[_0xa4c5('0x48')](handleError(_0x23e4ad,null));};
\ No newline at end of file