Built motion from commit 5b761a7b.|2.5.36
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 581e1aa..01c79e6 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 _0x31a3=['%s.%s\x20=\x20%s.%s','conditions','parse','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','SELECT','left_join','MAX(%s)','IS\x20NOT\x20NULL','IS\x20NOT\x20EMPTY','Sequelize','ValidationErrorItem','output','web','fullPath','%s-%s.%s','randomstring','generate','csv','custom','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','child_process','fork','../../components/export/','countTable','run','runReport','operator','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','end','json','offset','undefined','limit','count','status','set','Content-Range','apply','reject','save','update','then','destroy','get','CustomReports','UserProfileResource','error','stack','name','send','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','merge','VIRTUAL','includeAll','findAll','rows','catch','params','options','find','create','user','Reports','UserProfileSection','userProfileId','autoAssociation','body','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)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20EMPTY','rules','group','field','condition','value','getFields','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','select','from','table','MetricId','metric','function','replace','format','groupBy','order','orderBy','DESC','alias','joins','parentKey','foreignKey','foreignTable'];(function(_0x248f6b,_0x401324){var _0x54b829=function(_0x51ad90){while(--_0x51ad90){_0x248f6b['push'](_0x248f6b['shift']());}};_0x54b829(++_0x401324);}(_0x31a3,0x183));var _0x331a=function(_0x46ef1d,_0x24926){_0x46ef1d=_0x46ef1d-0x0;var _0x49ce69=_0x31a3[_0x46ef1d];return _0x49ce69;};'use strict';var emlformat=require(_0x331a('0x0'));var rimraf=require(_0x331a('0x1'));var zipdir=require(_0x331a('0x2'));var jsonpatch=require(_0x331a('0x3'));var rp=require(_0x331a('0x4'));var moment=require(_0x331a('0x5'));var BPromise=require(_0x331a('0x6'));var Mustache=require(_0x331a('0x7'));var util=require(_0x331a('0x8'));var path=require(_0x331a('0x9'));var sox=require(_0x331a('0xa'));var csv=require(_0x331a('0xb'));var ejs=require(_0x331a('0xc'));var fs=require('fs');var fs_extra=require(_0x331a('0xd'));var _=require(_0x331a('0xe'));var squel=require(_0x331a('0xf'));var crypto=require(_0x331a('0x10'));var jsforce=require(_0x331a('0x11'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x331a('0x12'));var Papa=require(_0x331a('0x13'));var Redis=require(_0x331a('0x14'));var authService=require(_0x331a('0x15'));var qs=require(_0x331a('0x16'));var as=require(_0x331a('0x17'));var hardwareService=require(_0x331a('0x18'));var logger=require(_0x331a('0x19'))('api');var utils=require(_0x331a('0x1a'));var config=require(_0x331a('0x1b'));var licenseUtil=require(_0x331a('0x1c'));var db=require(_0x331a('0x1d'))['db'];var dbH=require(_0x331a('0x1d'))[_0x331a('0x1e')];function respondWithStatusCode(_0x32d387,_0x19d690){_0x19d690=_0x19d690||0xcc;return function(_0x899366){if(_0x899366){return _0x32d387[_0x331a('0x1f')](_0x19d690);}return _0x32d387['status'](_0x19d690)[_0x331a('0x20')]();};}function respondWithResult(_0x15a44a,_0x529527){_0x529527=_0x529527||0xc8;return function(_0x8076fb){if(_0x8076fb){return _0x15a44a['status'](_0x529527)[_0x331a('0x21')](_0x8076fb);}};}function respondWithFilteredResult(_0x29d851,_0x1c385b){return function(_0x12ab11){if(_0x12ab11){var _0x43fde0=typeof _0x1c385b[_0x331a('0x22')]===_0x331a('0x23')&&typeof _0x1c385b[_0x331a('0x24')]===_0x331a('0x23');var _0x12e44f=_0x12ab11['count'];var _0x471e66=_0x43fde0?0x0:_0x1c385b[_0x331a('0x22')];var _0x22b25f=_0x43fde0?_0x12ab11[_0x331a('0x25')]:_0x1c385b[_0x331a('0x22')]+_0x1c385b['limit'];var _0x96469f;if(_0x22b25f>=_0x12e44f){_0x22b25f=_0x12e44f;_0x96469f=0xc8;}else{_0x96469f=0xce;}_0x29d851[_0x331a('0x26')](_0x96469f);return _0x29d851[_0x331a('0x27')](_0x331a('0x28'),_0x471e66+'-'+_0x22b25f+'/'+_0x12e44f)[_0x331a('0x21')](_0x12ab11);}return null;};}function patchUpdates(_0x40562a){return function(_0x2ee678){try{jsonpatch[_0x331a('0x29')](_0x2ee678,_0x40562a,!![]);}catch(_0x17b2d5){return BPromise[_0x331a('0x2a')](_0x17b2d5);}return _0x2ee678[_0x331a('0x2b')]();};}function saveUpdates(_0x4639d1,_0x3558ca){return function(_0x142111){if(_0x142111){return _0x142111[_0x331a('0x2c')](_0x4639d1)[_0x331a('0x2d')](function(_0xe8134f){return _0xe8134f;});}return null;};}function removeEntity(_0x651d19,_0x1714ab){return function(_0x23a8de){if(_0x23a8de){return _0x23a8de[_0x331a('0x2e')]()[_0x331a('0x2d')](function(){var _0x31b196=_0x23a8de[_0x331a('0x2f')]({'plain':!![]});var _0x27c68f=_0x331a('0x30');return db[_0x331a('0x31')][_0x331a('0x2e')]({'where':{'type':_0x27c68f,'resourceId':_0x31b196['id']}})[_0x331a('0x2d')](function(){return _0x23a8de;});})[_0x331a('0x2d')](function(){_0x651d19['status'](0xcc)[_0x331a('0x20')]();});}};}function handleEntityNotFound(_0x119a98,_0x309b3c){return function(_0x3119ad){if(!_0x3119ad){_0x119a98[_0x331a('0x1f')](0x194);}return _0x3119ad;};}function handleError(_0x3abaee,_0x53869f){_0x53869f=_0x53869f||0x1f4;return function(_0x36fe92){logger[_0x331a('0x32')](_0x36fe92[_0x331a('0x33')]);if(_0x36fe92[_0x331a('0x34')]){delete _0x36fe92[_0x331a('0x34')];}_0x3abaee[_0x331a('0x26')](_0x53869f)[_0x331a('0x35')](_0x36fe92);};}exports['index']=function(_0x1cbd3c,_0x437786){var _0x506f38={},_0x136dec={},_0x1e8c17={'count':0x0,'rows':[]};var _0x18fd4f=_[_0x331a('0x36')](db[_0x331a('0x37')][_0x331a('0x38')],function(_0x1ede19){return{'name':_0x1ede19[_0x331a('0x39')],'type':_0x1ede19[_0x331a('0x3a')][_0x331a('0x3b')]};});_0x136dec[_0x331a('0x3c')]=_[_0x331a('0x36')](_0x18fd4f,_0x331a('0x34'));_0x136dec['query']=_[_0x331a('0x3d')](_0x1cbd3c[_0x331a('0x3e')]);_0x136dec[_0x331a('0x3f')]=_[_0x331a('0x40')](_0x136dec[_0x331a('0x3c')],_0x136dec[_0x331a('0x3e')]);_0x506f38[_0x331a('0x41')]=_[_0x331a('0x40')](_0x136dec[_0x331a('0x3c')],qs['fields'](_0x1cbd3c['query'][_0x331a('0x42')]));_0x506f38[_0x331a('0x41')]=_0x506f38[_0x331a('0x41')][_0x331a('0x43')]?_0x506f38[_0x331a('0x41')]:_0x136dec[_0x331a('0x3c')];if(!_0x1cbd3c[_0x331a('0x3e')][_0x331a('0x44')](_0x331a('0x45'))){_0x506f38[_0x331a('0x24')]=qs[_0x331a('0x24')](_0x1cbd3c['query']['limit']);_0x506f38[_0x331a('0x22')]=qs[_0x331a('0x22')](_0x1cbd3c[_0x331a('0x3e')][_0x331a('0x22')]);}_0x506f38['order']=qs['sort'](_0x1cbd3c[_0x331a('0x3e')][_0x331a('0x46')]);_0x506f38[_0x331a('0x47')]=qs[_0x331a('0x3f')](_[_0x331a('0x48')](_0x1cbd3c[_0x331a('0x3e')],_0x136dec[_0x331a('0x3f')]),_0x18fd4f);if(_0x1cbd3c['query'][_0x331a('0x49')]){_0x506f38[_0x331a('0x47')]=_[_0x331a('0x4a')](_0x506f38[_0x331a('0x47')],{'$or':_[_0x331a('0x36')](_0x18fd4f,function(_0x678f3b){if(_0x678f3b['type']!==_0x331a('0x4b')){var _0x141bfd={};_0x141bfd[_0x678f3b[_0x331a('0x34')]]={'$like':'%'+_0x1cbd3c[_0x331a('0x3e')]['filter']+'%'};return _0x141bfd;}})});}_0x506f38=_[_0x331a('0x4a')]({},_0x506f38,_0x1cbd3c['options']);var _0x1967d7={'where':_0x506f38[_0x331a('0x47')]};return db[_0x331a('0x37')]['count'](_0x1967d7)[_0x331a('0x2d')](function(_0x524736){_0x1e8c17[_0x331a('0x25')]=_0x524736;if(_0x1cbd3c[_0x331a('0x3e')][_0x331a('0x4c')]){_0x506f38['include']=[{'all':!![]}];}return db[_0x331a('0x37')][_0x331a('0x4d')](_0x506f38);})[_0x331a('0x2d')](function(_0x2e1ea3){_0x1e8c17[_0x331a('0x4e')]=_0x2e1ea3;return _0x1e8c17;})[_0x331a('0x2d')](respondWithFilteredResult(_0x437786,_0x506f38))[_0x331a('0x4f')](handleError(_0x437786,null));};exports['show']=function(_0x1f1956,_0x12a090){var _0x14bb74={'raw':![],'where':{'id':_0x1f1956[_0x331a('0x50')]['id']}},_0x26613f={};_0x26613f[_0x331a('0x3c')]=_[_0x331a('0x3d')](db['AnalyticCustomReport'][_0x331a('0x38')]);_0x26613f[_0x331a('0x3e')]=_[_0x331a('0x3d')](_0x1f1956[_0x331a('0x3e')]);_0x26613f[_0x331a('0x3f')]=_['intersection'](_0x26613f['model'],_0x26613f[_0x331a('0x3e')]);_0x14bb74['attributes']=_[_0x331a('0x40')](_0x26613f[_0x331a('0x3c')],qs[_0x331a('0x42')](_0x1f1956[_0x331a('0x3e')][_0x331a('0x42')]));_0x14bb74[_0x331a('0x41')]=_0x14bb74[_0x331a('0x41')][_0x331a('0x43')]?_0x14bb74[_0x331a('0x41')]:_0x26613f[_0x331a('0x3c')];if(_0x1f1956[_0x331a('0x3e')][_0x331a('0x4c')]){_0x14bb74['include']=[{'all':!![]}];}_0x14bb74=_[_0x331a('0x4a')]({},_0x14bb74,_0x1f1956[_0x331a('0x51')]);return db[_0x331a('0x37')][_0x331a('0x52')](_0x14bb74)['then'](handleEntityNotFound(_0x12a090,null))[_0x331a('0x2d')](respondWithResult(_0x12a090,null))[_0x331a('0x4f')](handleError(_0x12a090,null));};exports['create']=function(_0x35c905,_0x1a4841){return db[_0x331a('0x37')][_0x331a('0x53')](_0x35c905['body'],{})[_0x331a('0x2d')](function(_0x33af38){var _0x2c846c=_0x35c905[_0x331a('0x54')][_0x331a('0x2f')]({'plain':!![]});if(!_0x2c846c)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2c846c['role']===_0x331a('0x54')){var _0x64c29=_0x33af38[_0x331a('0x2f')]({'plain':!![]});var _0x58ab52=_0x331a('0x55');return db[_0x331a('0x56')]['find']({'where':{'name':_0x58ab52,'userProfileId':_0x2c846c[_0x331a('0x57')]},'raw':!![]})[_0x331a('0x2d')](function(_0x4be25f){if(_0x4be25f&&_0x4be25f[_0x331a('0x58')]===0x0){return db[_0x331a('0x31')]['create']({'name':_0x64c29[_0x331a('0x34')],'resourceId':_0x64c29['id'],'type':_0x331a('0x30'),'sectionId':_0x4be25f['id']},{})['then'](function(){return _0x33af38;});}else{return _0x33af38;}})[_0x331a('0x4f')](function(_0x74f6e){logger[_0x331a('0x32')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x74f6e);throw _0x74f6e;});}return _0x33af38;})[_0x331a('0x2d')](respondWithResult(_0x1a4841,0xc9))[_0x331a('0x4f')](handleError(_0x1a4841,null));};exports[_0x331a('0x2c')]=function(_0x207360,_0x3a0e1c){if(_0x207360[_0x331a('0x59')]['id']){delete _0x207360[_0x331a('0x59')]['id'];}return db['AnalyticCustomReport'][_0x331a('0x52')]({'where':{'id':_0x207360[_0x331a('0x50')]['id']}})[_0x331a('0x2d')](handleEntityNotFound(_0x3a0e1c,null))['then'](saveUpdates(_0x207360[_0x331a('0x59')],null))[_0x331a('0x2d')](respondWithResult(_0x3a0e1c,null))[_0x331a('0x4f')](handleError(_0x3a0e1c,null));};exports[_0x331a('0x2e')]=function(_0x27efbb,_0x5cf183){return db[_0x331a('0x37')][_0x331a('0x52')]({'where':{'id':_0x27efbb[_0x331a('0x50')]['id']}})[_0x331a('0x2d')](handleEntityNotFound(_0x5cf183,null))[_0x331a('0x2d')](removeEntity(_0x5cf183,null))[_0x331a('0x4f')](handleError(_0x5cf183,null));};exports['preview']=function(_0x371ea6,_0x26dada){var _0x3495ef=0xa;var _0x4121e7=[_0x331a('0x5a'),'left_join',_0x331a('0x5b'),_0x331a('0x5c')];var _0x56cd7b={'SUM':_0x331a('0x5d'),'COUNT':_0x331a('0x5e'),'COUNT DISTINCT':_0x331a('0x5f'),'MAX':'MAX(%s)','MIN':_0x331a('0x60'),'AVG':_0x331a('0x61'),'GROUP_CONCAT':_0x331a('0x62'),'GROUP_CONCAT ASC':_0x331a('0x63'),'GROUP_CONCAT DESC':_0x331a('0x64')};var _0x3ec6f4={'SEC_TO_TIME':_0x331a('0x65'),'DATE':_0x331a('0x66'),'HOUR':_0x331a('0x67'),'ROUND':_0x331a('0x68'),'UNIX_TIMESTAMP':_0x331a('0x69')};var _0x110a86=function(_0x496f11){return!_[_0x331a('0x6a')]([_0x331a('0x6b'),'IS\x20NOT\x20NULL',_0x331a('0x6c'),'IS\x20NOT\x20EMPTY'],_0x496f11);};var _0x4502f6=function(_0xbb611){if(!_0xbb611||!_0xbb611[_0x331a('0x6d')][_0x331a('0x43')]){return'';}for(var _0x56dfb1='(',_0x4cd452=0x0;_0x4cd452<_0xbb611[_0x331a('0x6d')][_0x331a('0x43')];_0x4cd452+=0x1){_0x4cd452>0x0&&(_0x56dfb1+='\x20'+_0xbb611['operator']+'\x20');_0x56dfb1+=_0xbb611['rules'][_0x4cd452][_0x331a('0x6e')]?_0x4502f6(_0xbb611['rules'][_0x4cd452][_0x331a('0x6e')]):_0xbb611[_0x331a('0x6d')][_0x4cd452][_0x331a('0x6f')]+'\x20'+_0xbb611[_0x331a('0x6d')][_0x4cd452][_0x331a('0x70')]+(_0x110a86(_0xbb611[_0x331a('0x6d')][_0x4cd452][_0x331a('0x70')])?'\x20'+_0xbb611[_0x331a('0x6d')][_0x4cd452][_0x331a('0x71')]:'');}return _0x56dfb1+')';};var _0x1839ed={'where':{'id':_0x371ea6[_0x331a('0x50')]['id']}},_0x3a69db,_0x1df8a9,_0x4a4549,_0x54fb65,_0xe73504;_0x1839ed=_[_0x331a('0x4a')]({},_0x1839ed,_0x371ea6[_0x331a('0x51')]);return db[_0x331a('0x37')][_0x331a('0x52')](_0x1839ed)[_0x331a('0x2d')](function(_0x41da2f){if(_0x41da2f){_0x3a69db=_0x41da2f;return _0x41da2f[_0x331a('0x72')]();}return null;})['then'](function(_0x56c429){if(_0x56c429){if(!_0x56c429['length']){throw new db['Sequelize']['ValidationErrorItem'](_0x331a('0x73'),0x193);}_0x1df8a9=_0x56c429;return db[_0x331a('0x74')][_0x331a('0x4d')]({'raw':!![]});}return null;})[_0x331a('0x2d')](function(_0x5db1ce){if(_0x5db1ce){_0x4a4549=_[_0x331a('0x75')](_0x5db1ce,'id');var _0x39c11a;var _0x2b4458=squel[_0x331a('0x76')]();_0x2b4458[_0x331a('0x77')](_0x3a69db[_0x331a('0x78')]);for(var _0x2a2fac=0x0;_0x2a2fac<_0x1df8a9[_0x331a('0x43')];_0x2a2fac+=0x1){_0x39c11a=_0x1df8a9[_0x2a2fac][_0x331a('0x79')]?_0x4a4549[_0x1df8a9[_0x2a2fac]['MetricId']][_0x331a('0x7a')]:_0x1df8a9[_0x2a2fac][_0x331a('0x6f')];_0x39c11a=_0x1df8a9[_0x2a2fac][_0x331a('0x7b')]?_[_0x331a('0x7c')](_0x56cd7b[_0x1df8a9[_0x2a2fac][_0x331a('0x7b')]],'%s',_0x39c11a):_0x39c11a;_0x39c11a=_0x1df8a9[_0x2a2fac]['format']?_[_0x331a('0x7c')](_0x3ec6f4[_0x1df8a9[_0x2a2fac][_0x331a('0x7d')]],'%s',_0x39c11a):_0x39c11a;if(_0x1df8a9[_0x2a2fac][_0x331a('0x7e')]){_0x2b4458['group'](_0x39c11a);}_0x1df8a9[_0x2a2fac]['orderBy']&&_0x2b4458[_0x331a('0x7f')](_0x39c11a,_0x1df8a9[_0x2a2fac][_0x331a('0x80')]===_0x331a('0x81')?![]:!![]);_0x2b4458[_0x331a('0x6f')](_0x39c11a,_0x1df8a9[_0x2a2fac][_0x331a('0x82')]||_0x39c11a);}if(_0x3a69db[_0x331a('0x83')]){_0x3a69db[_0x331a('0x83')]=JSON['parse'](_0x3a69db[_0x331a('0x83')]);for(var _0x164a4f=0x0;_0x164a4f<_0x3a69db[_0x331a('0x83')][_0x331a('0x43')];_0x164a4f+=0x1){if(_0x3a69db['joins'][_0x164a4f][_0x331a('0x3a')]&&_['includes'](_0x4121e7,_0x3a69db['joins'][_0x164a4f][_0x331a('0x3a')])&&_0x3a69db['joins'][_0x164a4f][_0x331a('0x84')]&&_0x3a69db[_0x331a('0x83')][_0x164a4f]['foreignTable']&&_0x3a69db[_0x331a('0x83')][_0x164a4f][_0x331a('0x85')]){_0x2b4458[_0x3a69db[_0x331a('0x83')][_0x164a4f][_0x331a('0x3a')]](_0x3a69db[_0x331a('0x83')][_0x164a4f][_0x331a('0x86')],null,util['format'](_0x331a('0x87'),_0x3a69db[_0x331a('0x78')],_0x3a69db[_0x331a('0x83')][_0x164a4f][_0x331a('0x84')],_0x3a69db[_0x331a('0x83')][_0x164a4f][_0x331a('0x86')],_0x3a69db[_0x331a('0x83')][_0x164a4f][_0x331a('0x85')]));}}}if(_0x3a69db[_0x331a('0x88')]){_0x3a69db[_0x331a('0x88')]=JSON[_0x331a('0x89')](_0x3a69db[_0x331a('0x88')]);_0x2b4458[_0x331a('0x47')](_0x4502f6(_0x3a69db[_0x331a('0x88')][_0x331a('0x6e')]));}_0xe73504=_0x2b4458[_0x331a('0x8a')]();_0x2b4458[_0x331a('0x24')](_0x3495ef);_0x2b4458[_0x331a('0x22')](0x0);logger[_0x331a('0x8b')](_0x331a('0x8c'),_0x2b4458[_0x331a('0x8d')]());return dbH['sequelize']['query'](_0x2b4458[_0x331a('0x8d')](),{'type':dbH[_0x331a('0x8e')][_0x331a('0x8f')][_0x331a('0x90')]});}})['then'](respondWithResult(_0x26dada,null))[_0x331a('0x4f')](handleError(_0x26dada,null));};function runReport(_0x50dcac,_0x1cff1a,_0x1cfc58){var _0x2a4f24=_0x1cff1a[_0x331a('0x34')];var _0x3cd8ab=0xa;var _0xc04b7=[_0x331a('0x5a'),_0x331a('0x91'),'right_join',_0x331a('0x5c')];var _0x14ff5b={'SUM':_0x331a('0x5d'),'COUNT':_0x331a('0x5e'),'COUNT DISTINCT':_0x331a('0x5f'),'MAX':_0x331a('0x92'),'MIN':_0x331a('0x60'),'AVG':'AVG(%s)','GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x331a('0x63'),'GROUP_CONCAT DESC':_0x331a('0x64')};var _0x24e6cb={'SEC_TO_TIME':_0x331a('0x65'),'DATE':'DATE(%s)','HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x331a('0x69')};var _0x589cbd=function(_0x5f2a01){return!_[_0x331a('0x6a')]([_0x331a('0x6b'),_0x331a('0x93'),_0x331a('0x6c'),_0x331a('0x94')],_0x5f2a01);};var _0x957c4f=function(_0x2936d8){if(!_0x2936d8||!_0x2936d8[_0x331a('0x6d')]['length']){return'';}for(var _0x13c476='(',_0x373df5=0x0;_0x373df5<_0x2936d8[_0x331a('0x6d')][_0x331a('0x43')];_0x373df5+=0x1){_0x373df5>0x0&&(_0x13c476+='\x20'+_0x2936d8['operator']+'\x20');_0x13c476+=_0x2936d8[_0x331a('0x6d')][_0x373df5][_0x331a('0x6e')]?_0x957c4f(_0x2936d8[_0x331a('0x6d')][_0x373df5][_0x331a('0x6e')]):_0x2936d8[_0x331a('0x6d')][_0x373df5][_0x331a('0x6f')]+'\x20'+_0x2936d8['rules'][_0x373df5][_0x331a('0x70')]+(_0x589cbd(_0x2936d8[_0x331a('0x6d')][_0x373df5]['condition'])?'\x20'+_0x2936d8['rules'][_0x373df5]['value']:'');}return _0x13c476+')';};var _0xb14d9d={'where':{'id':_0x50dcac['id']}},_0x4bef3e,_0x4546a2,_0x300ba0,_0x3484f2,_0x5a84b9;_0xb14d9d=_[_0x331a('0x4a')]({},_0xb14d9d,_0x1cfc58);return db[_0x331a('0x37')][_0x331a('0x52')](_0xb14d9d)['then'](function(_0x31125b){if(_0x31125b){_0x4bef3e=_0x31125b;return _0x31125b['getFields']();}return null;})[_0x331a('0x2d')](function(_0x564c75){if(_0x564c75){if(!_0x564c75['length']){throw new db[(_0x331a('0x95'))][(_0x331a('0x96'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x4546a2=_0x564c75;return db[_0x331a('0x74')][_0x331a('0x4d')]({'raw':!![]});}return null;})[_0x331a('0x2d')](function(_0x1f26ab){if(_0x1f26ab){_0x300ba0=_[_0x331a('0x75')](_0x1f26ab,'id');var _0x40e1fe;var _0x118834=squel['select']();_0x118834[_0x331a('0x77')](_0x4bef3e[_0x331a('0x78')]);for(var _0x576815=0x0;_0x576815<_0x4546a2[_0x331a('0x43')];_0x576815+=0x1){_0x40e1fe=_0x4546a2[_0x576815][_0x331a('0x79')]?_0x300ba0[_0x4546a2[_0x576815]['MetricId']][_0x331a('0x7a')]:_0x4546a2[_0x576815][_0x331a('0x6f')];_0x40e1fe=_0x4546a2[_0x576815][_0x331a('0x7b')]?_[_0x331a('0x7c')](_0x14ff5b[_0x4546a2[_0x576815][_0x331a('0x7b')]],'%s',_0x40e1fe):_0x40e1fe;_0x40e1fe=_0x4546a2[_0x576815][_0x331a('0x7d')]?_[_0x331a('0x7c')](_0x24e6cb[_0x4546a2[_0x576815]['format']],'%s',_0x40e1fe):_0x40e1fe;if(_0x4546a2[_0x576815]['groupBy']){_0x118834[_0x331a('0x6e')](_0x40e1fe);}_0x4546a2[_0x576815][_0x331a('0x80')]&&_0x118834[_0x331a('0x7f')](_0x40e1fe,_0x4546a2[_0x576815][_0x331a('0x80')]===_0x331a('0x81')?![]:!![]);_0x118834[_0x331a('0x6f')](_0x40e1fe,_0x4546a2[_0x576815]['alias']||_0x40e1fe);}if(_0x4bef3e[_0x331a('0x83')]){_0x4bef3e[_0x331a('0x83')]=JSON['parse'](_0x4bef3e[_0x331a('0x83')]);for(var _0x350007=0x0;_0x350007<_0x4bef3e[_0x331a('0x83')][_0x331a('0x43')];_0x350007+=0x1){if(_0x4bef3e[_0x331a('0x83')][_0x350007][_0x331a('0x3a')]&&_[_0x331a('0x6a')](_0xc04b7,_0x4bef3e['joins'][_0x350007][_0x331a('0x3a')])&&_0x4bef3e[_0x331a('0x83')][_0x350007]['parentKey']&&_0x4bef3e[_0x331a('0x83')][_0x350007][_0x331a('0x86')]&&_0x4bef3e[_0x331a('0x83')][_0x350007][_0x331a('0x85')]){_0x118834[_0x4bef3e[_0x331a('0x83')][_0x350007][_0x331a('0x3a')]](_0x4bef3e[_0x331a('0x83')][_0x350007][_0x331a('0x86')],null,util[_0x331a('0x7d')](_0x331a('0x87'),_0x4bef3e[_0x331a('0x78')],_0x4bef3e[_0x331a('0x83')][_0x350007]['parentKey'],_0x4bef3e[_0x331a('0x83')][_0x350007][_0x331a('0x86')],_0x4bef3e[_0x331a('0x83')][_0x350007][_0x331a('0x85')]));}}}if(_0x4bef3e[_0x331a('0x88')]){_0x4bef3e['conditions']=JSON[_0x331a('0x89')](_0x4bef3e[_0x331a('0x88')]);_0x118834[_0x331a('0x47')](_0x957c4f(_0x4bef3e['conditions'][_0x331a('0x6e')]));}_0x5a84b9=_0x118834[_0x331a('0x8a')]();_0x118834[_0x331a('0x24')](_0x3cd8ab);_0x118834[_0x331a('0x22')](0x0);return;}})['then'](function(){if(_0x1cff1a[_0x331a('0x97')]===_0x331a('0x98')){return null;}var _0x3fd23f=_['merge'](_0x1cff1a,{'name':_0x1cff1a[_0x331a('0x99')]||_0x1cff1a[_0x331a('0x34')]||_0x4bef3e[_0x331a('0x34')],'basename':_0x2a4f24,'savename':util[_0x331a('0x7d')](_0x331a('0x9a'),_0x1cff1a[_0x331a('0x34')]||_0x4bef3e[_0x331a('0x34')],require(_0x331a('0x9b'))[_0x331a('0x9c')](0x4),_0x1cff1a['output']||_0x331a('0x9d')),'reportId':_0x4bef3e['id'],'reportType':_0x331a('0x9e')});return db[_0x331a('0x9f')][_0x331a('0x53')](_0x3fd23f,{'raw':!![]});})[_0x331a('0x2d')](function(_0x317df1){if(_0x4bef3e[_0x331a('0x78')]===_0x331a('0xa0')){_0x5a84b9['where'](_0x4bef3e[_0x331a('0x78')]+_0x331a('0xa1'),_0x1cff1a[_0x331a('0xa2')],_0x1cff1a[_0x331a('0xa3')]);}else{_0x5a84b9[_0x331a('0x47')](_0x4bef3e[_0x331a('0x78')]+_0x331a('0xa4'),_0x1cff1a['startDate'],_0x1cff1a[_0x331a('0xa3')]);}if(_0x317df1){logger[_0x331a('0xa5')](_0x331a('0xa6'),_0x5a84b9[_0x331a('0x8d')]());require(_0x331a('0xa7'))[_0x331a('0xa8')](path[_0x331a('0x5a')](__dirname,_0x331a('0xa9'),_0x317df1[_0x331a('0x97')]),[_0x317df1['id'],_0x5a84b9[_0x331a('0x8d')](),path[_0x331a('0x5a')](__dirname,'../../files/reports',_0x317df1['savename']),_0x2a4f24]);return _0x317df1;}else{var _0x24fc5b=squel[_0x331a('0x76')]();_0x24fc5b['from']('('+_0x5a84b9[_0x331a('0x8d')]()+')',_0x331a('0xaa'));_0x24fc5b[_0x331a('0x6f')]('COUNT(*)',_0x331a('0x25'));_0x5a84b9[_0x331a('0x24')](_0x1cff1a['limit']||_0x3cd8ab);_0x5a84b9['offset'](_0x1cff1a[_0x331a('0x22')]||0x0);return dbH[_0x331a('0x8e')][_0x331a('0x3e')](_0x24fc5b[_0x331a('0x8d')](),{'type':dbH['sequelize'][_0x331a('0x8f')][_0x331a('0x90')]})[_0x331a('0x2d')](function(_0x3347c8){if(!_0x3347c8[_0x331a('0x43')]){_0x3484f2=0x0;}else{_0x3484f2=_0x3347c8[0x0][_0x331a('0x25')]||0x0;}return dbH[_0x331a('0x8e')][_0x331a('0x3e')](_0x5a84b9[_0x331a('0x8d')](),{'type':dbH[_0x331a('0x8e')][_0x331a('0x8f')][_0x331a('0x90')]});})[_0x331a('0x2d')](function(_0x142025){return{'rows':_0x142025||[],'count':_0x3484f2};});}});}exports[_0x331a('0xab')]=function(_0x56cad9,_0x140d7e){return runReport(_0x56cad9[_0x331a('0x50')],_0x56cad9[_0x331a('0x3e')],_0x56cad9[_0x331a('0x51')])[_0x331a('0x2d')](respondWithResult(_0x140d7e,null))[_0x331a('0x4f')](handleError(_0x140d7e,null));};exports[_0x331a('0xac')]=runReport;exports[_0x331a('0x3e')]=function(_0x4160b5,_0x2a144d){var _0x336ba5=0xa;var _0x30f773=['join',_0x331a('0x91'),_0x331a('0x5b'),_0x331a('0x5c')];var _0x242fbc={'SUM':_0x331a('0x5d'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0x331a('0x5f'),'MAX':_0x331a('0x92'),'MIN':_0x331a('0x60'),'AVG':_0x331a('0x61'),'GROUP_CONCAT':_0x331a('0x62'),'GROUP_CONCAT ASC':_0x331a('0x63'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x429525={'SEC_TO_TIME':_0x331a('0x65'),'DATE':_0x331a('0x66'),'HOUR':_0x331a('0x67'),'ROUND':_0x331a('0x68'),'UNIX_TIMESTAMP':_0x331a('0x69')};var _0x2188e5=function(_0x4fec80){return!_['includes'](['IS\x20NULL','IS\x20NOT\x20NULL',_0x331a('0x6c'),_0x331a('0x94')],_0x4fec80);};var _0x27b0c6=function(_0x50231f){if(!_0x50231f||!_0x50231f['rules'][_0x331a('0x43')]){return'';}for(var _0x396660='(',_0x390ce7=0x0;_0x390ce7<_0x50231f['rules'][_0x331a('0x43')];_0x390ce7+=0x1){_0x390ce7>0x0&&(_0x396660+='\x20'+_0x50231f[_0x331a('0xad')]+'\x20');_0x396660+=_0x50231f[_0x331a('0x6d')][_0x390ce7]['group']?_0x27b0c6(_0x50231f[_0x331a('0x6d')][_0x390ce7][_0x331a('0x6e')]):_0x50231f[_0x331a('0x6d')][_0x390ce7][_0x331a('0x6f')]+'\x20'+_0x50231f[_0x331a('0x6d')][_0x390ce7]['condition']+(_0x2188e5(_0x50231f['rules'][_0x390ce7][_0x331a('0x70')])?'\x20'+_0x50231f[_0x331a('0x6d')][_0x390ce7][_0x331a('0x71')]:'');}return _0x396660+')';};var _0x35e51={'where':{'id':_0x4160b5[_0x331a('0x50')]['id']}},_0x1a1a0f,_0x18dac5,_0x3946d9,_0x3ff22c,_0x37236f;_0x35e51=_['merge']({},_0x35e51,_0x4160b5[_0x331a('0x51')]);return db[_0x331a('0x37')][_0x331a('0x52')](_0x35e51)[_0x331a('0x2d')](function(_0x2cb26){if(_0x2cb26){_0x1a1a0f=_0x2cb26;return _0x2cb26[_0x331a('0x72')]();}return null;})[_0x331a('0x2d')](function(_0x77dea8){if(_0x77dea8){if(!_0x77dea8[_0x331a('0x43')]){throw new db[(_0x331a('0x95'))][(_0x331a('0x96'))](_0x331a('0x73'),0x193);}_0x18dac5=_0x77dea8;return db[_0x331a('0x74')]['findAll']({'raw':!![]});}return null;})[_0x331a('0x2d')](function(_0x1181cc){if(_0x1181cc){_0x3946d9=_[_0x331a('0x75')](_0x1181cc,'id');var _0x10df41;var _0x1ec707=squel['select']();_0x1ec707[_0x331a('0x77')](_0x1a1a0f[_0x331a('0x78')]);for(var _0x219efd=0x0;_0x219efd<_0x18dac5['length'];_0x219efd+=0x1){_0x10df41=_0x18dac5[_0x219efd]['MetricId']?_0x3946d9[_0x18dac5[_0x219efd][_0x331a('0x79')]][_0x331a('0x7a')]:_0x18dac5[_0x219efd]['field'];_0x10df41=_0x18dac5[_0x219efd][_0x331a('0x7b')]?_[_0x331a('0x7c')](_0x242fbc[_0x18dac5[_0x219efd]['function']],'%s',_0x10df41):_0x10df41;_0x10df41=_0x18dac5[_0x219efd][_0x331a('0x7d')]?_[_0x331a('0x7c')](_0x429525[_0x18dac5[_0x219efd][_0x331a('0x7d')]],'%s',_0x10df41):_0x10df41;if(_0x18dac5[_0x219efd][_0x331a('0x7e')]){_0x1ec707[_0x331a('0x6e')](_0x10df41);}_0x18dac5[_0x219efd][_0x331a('0x80')]&&_0x1ec707[_0x331a('0x7f')](_0x10df41,_0x18dac5[_0x219efd]['orderBy']===_0x331a('0x81')?![]:!![]);_0x1ec707['field'](_0x10df41,_0x18dac5[_0x219efd]['alias']||_0x10df41);}if(_0x1a1a0f[_0x331a('0x83')]){_0x1a1a0f[_0x331a('0x83')]=JSON['parse'](_0x1a1a0f[_0x331a('0x83')]);for(var _0x696fe2=0x0;_0x696fe2<_0x1a1a0f[_0x331a('0x83')][_0x331a('0x43')];_0x696fe2+=0x1){if(_0x1a1a0f['joins'][_0x696fe2]['type']&&_[_0x331a('0x6a')](_0x30f773,_0x1a1a0f[_0x331a('0x83')][_0x696fe2][_0x331a('0x3a')])&&_0x1a1a0f[_0x331a('0x83')][_0x696fe2][_0x331a('0x84')]&&_0x1a1a0f[_0x331a('0x83')][_0x696fe2][_0x331a('0x86')]&&_0x1a1a0f[_0x331a('0x83')][_0x696fe2]['foreignKey']){_0x1ec707[_0x1a1a0f[_0x331a('0x83')][_0x696fe2][_0x331a('0x3a')]](_0x1a1a0f['joins'][_0x696fe2][_0x331a('0x86')],null,util[_0x331a('0x7d')]('%s.%s\x20=\x20%s.%s',_0x1a1a0f['table'],_0x1a1a0f['joins'][_0x696fe2]['parentKey'],_0x1a1a0f[_0x331a('0x83')][_0x696fe2][_0x331a('0x86')],_0x1a1a0f['joins'][_0x696fe2][_0x331a('0x85')]));}}}if(_0x1a1a0f[_0x331a('0x88')]){_0x1a1a0f[_0x331a('0x88')]=JSON['parse'](_0x1a1a0f[_0x331a('0x88')]);_0x1ec707[_0x331a('0x47')](_0x27b0c6(_0x1a1a0f[_0x331a('0x88')][_0x331a('0x6e')]));}_0x37236f=_0x1ec707[_0x331a('0x8a')]();_0x1ec707['limit'](_0x336ba5);_0x1ec707[_0x331a('0x22')](0x0);logger[_0x331a('0x8b')](_0x331a('0x8c'),_0x1ec707['toString']());return dbH[_0x331a('0x8e')][_0x331a('0x3e')](_0x1ec707['toString'](),{'type':dbH[_0x331a('0x8e')][_0x331a('0x8f')]['SELECT']});}})['then'](function(){return{'sql':_0x37236f[_0x331a('0x8d')]()};})[_0x331a('0x2d')](respondWithResult(_0x2a144d,null))[_0x331a('0x4f')](handleError(_0x2a144d,null));};
\ No newline at end of file