Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 581e1aa..dcd928d 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 _0x5522=['type','key','model','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','include','findAll','show','params','keys','rawAttributes','catch','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','Reports','UserProfileSection','find','userProfileId','autoAssociation','CustomReports','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','preview','join','right_join','cross_join','COUNT(DISTINCT\x20%s)','MAX(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','DATE(%s)','HOUR(%s)','ROUND(%s)','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','rules','group','condition','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','select','from','table','MetricId','metric','field','function','replace','format','groupBy','orderBy','DESC','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','Limited\x20Query:','sequelize','toString','QueryTypes','SELECT','SUM(%s)','COUNT(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','SEC_TO_TIME(%s)','UNIX_TIMESTAMP(%s)','IS\x20NOT\x20EMPTY','operator','value','alias','includes','clone','output','web','fullPath','%s-%s.%s','randomstring','generate','csv','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','endDate','startDate','child_process','fork','countTable','COUNT(*)','run','runReport','left_join','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','dbH','sendStatus','end','status','json','limit','offset','count','Content-Range','reject','save','then','destroy','get','UserProfileResource','error','stack','name','send','index','map','AnalyticCustomReport','fieldName'];(function(_0x5326ba,_0x156aca){var _0x6afc=function(_0x42c82d){while(--_0x42c82d){_0x5326ba['push'](_0x5326ba['shift']());}};_0x6afc(++_0x156aca);}(_0x5522,0x1bd));var _0x2552=function(_0x432682,_0x253044){_0x432682=_0x432682-0x0;var _0x463d05=_0x5522[_0x432682];return _0x463d05;};'use strict';var emlformat=require(_0x2552('0x0'));var rimraf=require(_0x2552('0x1'));var zipdir=require(_0x2552('0x2'));var jsonpatch=require(_0x2552('0x3'));var rp=require(_0x2552('0x4'));var moment=require('moment');var BPromise=require(_0x2552('0x5'));var Mustache=require(_0x2552('0x6'));var util=require(_0x2552('0x7'));var path=require('path');var sox=require(_0x2552('0x8'));var csv=require(_0x2552('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x2552('0xa'));var _=require(_0x2552('0xb'));var squel=require(_0x2552('0xc'));var crypto=require(_0x2552('0xd'));var jsforce=require(_0x2552('0xe'));var deskjs=require(_0x2552('0xf'));var toCsv=require(_0x2552('0x9'));var querystring=require(_0x2552('0x10'));var Papa=require(_0x2552('0x11'));var Redis=require(_0x2552('0x12'));var authService=require(_0x2552('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x2552('0x14'));var hardwareService=require(_0x2552('0x15'));var logger=require(_0x2552('0x16'))(_0x2552('0x17'));var utils=require(_0x2552('0x18'));var config=require('../../config/environment');var licenseUtil=require(_0x2552('0x19'));var db=require(_0x2552('0x1a'))['db'];var dbH=require(_0x2552('0x1a'))[_0x2552('0x1b')];function respondWithStatusCode(_0x5fb831,_0x220fdb){_0x220fdb=_0x220fdb||0xcc;return function(_0x3ed7ed){if(_0x3ed7ed){return _0x5fb831[_0x2552('0x1c')](_0x220fdb);}return _0x5fb831['status'](_0x220fdb)[_0x2552('0x1d')]();};}function respondWithResult(_0x260d4a,_0x28db8b){_0x28db8b=_0x28db8b||0xc8;return function(_0x1cbbe7){if(_0x1cbbe7){return _0x260d4a[_0x2552('0x1e')](_0x28db8b)[_0x2552('0x1f')](_0x1cbbe7);}};}function respondWithFilteredResult(_0x2672cc,_0x27fff0){return function(_0x381b91){if(_0x381b91){var _0x217569=typeof _0x27fff0['offset']==='undefined'&&typeof _0x27fff0[_0x2552('0x20')]==='undefined';var _0x45de77=_0x381b91['count'];var _0x5beec8=_0x217569?0x0:_0x27fff0[_0x2552('0x21')];var _0x405986=_0x217569?_0x381b91[_0x2552('0x22')]:_0x27fff0[_0x2552('0x21')]+_0x27fff0[_0x2552('0x20')];var _0x1c1af4;if(_0x405986>=_0x45de77){_0x405986=_0x45de77;_0x1c1af4=0xc8;}else{_0x1c1af4=0xce;}_0x2672cc[_0x2552('0x1e')](_0x1c1af4);return _0x2672cc['set'](_0x2552('0x23'),_0x5beec8+'-'+_0x405986+'/'+_0x45de77)['json'](_0x381b91);}return null;};}function patchUpdates(_0x3489b1){return function(_0x38576d){try{jsonpatch['apply'](_0x38576d,_0x3489b1,!![]);}catch(_0x992b1d){return BPromise[_0x2552('0x24')](_0x992b1d);}return _0x38576d[_0x2552('0x25')]();};}function saveUpdates(_0x4e8a8b,_0x421280){return function(_0x11bd17){if(_0x11bd17){return _0x11bd17['update'](_0x4e8a8b)[_0x2552('0x26')](function(_0x3ea83d){return _0x3ea83d;});}return null;};}function removeEntity(_0x361c0e,_0x5bd7d8){return function(_0x408874){if(_0x408874){return _0x408874[_0x2552('0x27')]()[_0x2552('0x26')](function(){var _0x147c62=_0x408874[_0x2552('0x28')]({'plain':!![]});var _0x4ea485='CustomReports';return db[_0x2552('0x29')][_0x2552('0x27')]({'where':{'type':_0x4ea485,'resourceId':_0x147c62['id']}})[_0x2552('0x26')](function(){return _0x408874;});})[_0x2552('0x26')](function(){_0x361c0e[_0x2552('0x1e')](0xcc)[_0x2552('0x1d')]();});}};}function handleEntityNotFound(_0x27ba54,_0x51a228){return function(_0xd92ab4){if(!_0xd92ab4){_0x27ba54[_0x2552('0x1c')](0x194);}return _0xd92ab4;};}function handleError(_0x5597c2,_0x24a7f3){_0x24a7f3=_0x24a7f3||0x1f4;return function(_0x261b6c){logger[_0x2552('0x2a')](_0x261b6c[_0x2552('0x2b')]);if(_0x261b6c[_0x2552('0x2c')]){delete _0x261b6c[_0x2552('0x2c')];}_0x5597c2[_0x2552('0x1e')](_0x24a7f3)[_0x2552('0x2d')](_0x261b6c);};}exports[_0x2552('0x2e')]=function(_0x1dae94,_0x19772c){var _0xb640f5={},_0x2f7d2c={},_0x4ee39d={'count':0x0,'rows':[]};var _0x575dcd=_[_0x2552('0x2f')](db[_0x2552('0x30')]['rawAttributes'],function(_0x3e5829){return{'name':_0x3e5829[_0x2552('0x31')],'type':_0x3e5829[_0x2552('0x32')][_0x2552('0x33')]};});_0x2f7d2c[_0x2552('0x34')]=_[_0x2552('0x2f')](_0x575dcd,_0x2552('0x2c'));_0x2f7d2c[_0x2552('0x35')]=_['keys'](_0x1dae94['query']);_0x2f7d2c['filters']=_['intersection'](_0x2f7d2c[_0x2552('0x34')],_0x2f7d2c['query']);_0xb640f5[_0x2552('0x36')]=_[_0x2552('0x37')](_0x2f7d2c['model'],qs[_0x2552('0x38')](_0x1dae94[_0x2552('0x35')][_0x2552('0x38')]));_0xb640f5['attributes']=_0xb640f5[_0x2552('0x36')][_0x2552('0x39')]?_0xb640f5[_0x2552('0x36')]:_0x2f7d2c['model'];if(!_0x1dae94[_0x2552('0x35')][_0x2552('0x3a')](_0x2552('0x3b'))){_0xb640f5[_0x2552('0x20')]=qs[_0x2552('0x20')](_0x1dae94[_0x2552('0x35')]['limit']);_0xb640f5['offset']=qs[_0x2552('0x21')](_0x1dae94['query'][_0x2552('0x21')]);}_0xb640f5[_0x2552('0x3c')]=qs[_0x2552('0x3d')](_0x1dae94['query'][_0x2552('0x3d')]);_0xb640f5[_0x2552('0x3e')]=qs[_0x2552('0x3f')](_[_0x2552('0x40')](_0x1dae94[_0x2552('0x35')],_0x2f7d2c[_0x2552('0x3f')]),_0x575dcd);if(_0x1dae94[_0x2552('0x35')][_0x2552('0x41')]){_0xb640f5['where']=_[_0x2552('0x42')](_0xb640f5[_0x2552('0x3e')],{'$or':_[_0x2552('0x2f')](_0x575dcd,function(_0x4fb187){if(_0x4fb187[_0x2552('0x32')]!==_0x2552('0x43')){var _0x2dfd3e={};_0x2dfd3e[_0x4fb187[_0x2552('0x2c')]]={'$like':'%'+_0x1dae94[_0x2552('0x35')][_0x2552('0x41')]+'%'};return _0x2dfd3e;}})});}_0xb640f5=_['merge']({},_0xb640f5,_0x1dae94[_0x2552('0x44')]);var _0x348b8b={'where':_0xb640f5['where']};return db[_0x2552('0x30')]['count'](_0x348b8b)['then'](function(_0x15adac){_0x4ee39d[_0x2552('0x22')]=_0x15adac;if(_0x1dae94[_0x2552('0x35')]['includeAll']){_0xb640f5[_0x2552('0x45')]=[{'all':!![]}];}return db[_0x2552('0x30')][_0x2552('0x46')](_0xb640f5);})[_0x2552('0x26')](function(_0x576124){_0x4ee39d['rows']=_0x576124;return _0x4ee39d;})[_0x2552('0x26')](respondWithFilteredResult(_0x19772c,_0xb640f5))['catch'](handleError(_0x19772c,null));};exports[_0x2552('0x47')]=function(_0x4744e9,_0x43dd04){var _0x46ab1a={'raw':![],'where':{'id':_0x4744e9[_0x2552('0x48')]['id']}},_0xb89c6={};_0xb89c6[_0x2552('0x34')]=_[_0x2552('0x49')](db['AnalyticCustomReport'][_0x2552('0x4a')]);_0xb89c6[_0x2552('0x35')]=_['keys'](_0x4744e9['query']);_0xb89c6[_0x2552('0x3f')]=_[_0x2552('0x37')](_0xb89c6[_0x2552('0x34')],_0xb89c6[_0x2552('0x35')]);_0x46ab1a[_0x2552('0x36')]=_[_0x2552('0x37')](_0xb89c6['model'],qs['fields'](_0x4744e9['query'][_0x2552('0x38')]));_0x46ab1a[_0x2552('0x36')]=_0x46ab1a[_0x2552('0x36')]['length']?_0x46ab1a[_0x2552('0x36')]:_0xb89c6[_0x2552('0x34')];if(_0x4744e9[_0x2552('0x35')]['includeAll']){_0x46ab1a[_0x2552('0x45')]=[{'all':!![]}];}_0x46ab1a=_['merge']({},_0x46ab1a,_0x4744e9[_0x2552('0x44')]);return db['AnalyticCustomReport']['find'](_0x46ab1a)[_0x2552('0x26')](handleEntityNotFound(_0x43dd04,null))['then'](respondWithResult(_0x43dd04,null))[_0x2552('0x4b')](handleError(_0x43dd04,null));};exports[_0x2552('0x4c')]=function(_0x4379df,_0x92e16d){return db['AnalyticCustomReport'][_0x2552('0x4c')](_0x4379df[_0x2552('0x4d')],{})[_0x2552('0x26')](function(_0x5f33f3){var _0x14c63d=_0x4379df[_0x2552('0x4e')][_0x2552('0x28')]({'plain':!![]});if(!_0x14c63d)throw new Error(_0x2552('0x4f'));if(_0x14c63d['role']===_0x2552('0x4e')){var _0x313ea5=_0x5f33f3[_0x2552('0x28')]({'plain':!![]});var _0x137bf1=_0x2552('0x50');return db[_0x2552('0x51')][_0x2552('0x52')]({'where':{'name':_0x137bf1,'userProfileId':_0x14c63d[_0x2552('0x53')]},'raw':!![]})[_0x2552('0x26')](function(_0x49a446){if(_0x49a446&&_0x49a446[_0x2552('0x54')]===0x0){return db[_0x2552('0x29')][_0x2552('0x4c')]({'name':_0x313ea5[_0x2552('0x2c')],'resourceId':_0x313ea5['id'],'type':_0x2552('0x55'),'sectionId':_0x49a446['id']},{})[_0x2552('0x26')](function(){return _0x5f33f3;});}else{return _0x5f33f3;}})[_0x2552('0x4b')](function(_0x4fe312){logger['error'](_0x2552('0x56'),_0x4fe312);throw _0x4fe312;});}return _0x5f33f3;})[_0x2552('0x26')](respondWithResult(_0x92e16d,0xc9))['catch'](handleError(_0x92e16d,null));};exports['update']=function(_0xa06e88,_0x4fc7a0){if(_0xa06e88[_0x2552('0x4d')]['id']){delete _0xa06e88['body']['id'];}return db['AnalyticCustomReport'][_0x2552('0x52')]({'where':{'id':_0xa06e88[_0x2552('0x48')]['id']}})['then'](handleEntityNotFound(_0x4fc7a0,null))[_0x2552('0x26')](saveUpdates(_0xa06e88[_0x2552('0x4d')],null))[_0x2552('0x26')](respondWithResult(_0x4fc7a0,null))['catch'](handleError(_0x4fc7a0,null));};exports[_0x2552('0x27')]=function(_0x5f41a1,_0x503914){return db[_0x2552('0x30')][_0x2552('0x52')]({'where':{'id':_0x5f41a1[_0x2552('0x48')]['id']}})[_0x2552('0x26')](handleEntityNotFound(_0x503914,null))[_0x2552('0x26')](removeEntity(_0x503914,null))['catch'](handleError(_0x503914,null));};exports[_0x2552('0x57')]=function(_0x570faf,_0x4dff3e){var _0x3e9750=0xa;var _0x478b24=[_0x2552('0x58'),'left_join',_0x2552('0x59'),_0x2552('0x5a')];var _0x51be9f={'SUM':'SUM(%s)','COUNT':'COUNT(%s)','COUNT DISTINCT':_0x2552('0x5b'),'MAX':_0x2552('0x5c'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x2552('0x5d'),'GROUP_CONCAT DESC':_0x2552('0x5e')};var _0x41b55c={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x2552('0x5f'),'HOUR':_0x2552('0x60'),'ROUND':_0x2552('0x61'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x1cf315=function(_0x53024){return!_['includes']([_0x2552('0x62'),_0x2552('0x63'),_0x2552('0x64'),'IS\x20NOT\x20EMPTY'],_0x53024);};var _0x5bb69e=function(_0x3b55b2){if(!_0x3b55b2||!_0x3b55b2[_0x2552('0x65')]['length']){return'';}for(var _0x5753f2='(',_0x28171a=0x0;_0x28171a<_0x3b55b2[_0x2552('0x65')][_0x2552('0x39')];_0x28171a+=0x1){_0x28171a>0x0&&(_0x5753f2+='\x20'+_0x3b55b2['operator']+'\x20');_0x5753f2+=_0x3b55b2['rules'][_0x28171a][_0x2552('0x66')]?_0x5bb69e(_0x3b55b2['rules'][_0x28171a][_0x2552('0x66')]):_0x3b55b2['rules'][_0x28171a]['field']+'\x20'+_0x3b55b2[_0x2552('0x65')][_0x28171a][_0x2552('0x67')]+(_0x1cf315(_0x3b55b2[_0x2552('0x65')][_0x28171a][_0x2552('0x67')])?'\x20'+_0x3b55b2[_0x2552('0x65')][_0x28171a]['value']:'');}return _0x5753f2+')';};var _0x9ba1a0={'where':{'id':_0x570faf[_0x2552('0x48')]['id']}},_0x3b4beb,_0x21faa3,_0x96069e,_0x5afd04,_0x343518;_0x9ba1a0=_['merge']({},_0x9ba1a0,_0x570faf[_0x2552('0x44')]);return db[_0x2552('0x30')]['find'](_0x9ba1a0)[_0x2552('0x26')](function(_0x8b4865){if(_0x8b4865){_0x3b4beb=_0x8b4865;return _0x8b4865[_0x2552('0x68')]();}return null;})[_0x2552('0x26')](function(_0x1c689b){if(_0x1c689b){if(!_0x1c689b[_0x2552('0x39')]){throw new db[(_0x2552('0x69'))][(_0x2552('0x6a'))](_0x2552('0x6b'),0x193);}_0x21faa3=_0x1c689b;return db[_0x2552('0x6c')][_0x2552('0x46')]({'raw':!![]});}return null;})['then'](function(_0x3aa7d6){if(_0x3aa7d6){_0x96069e=_[_0x2552('0x6d')](_0x3aa7d6,'id');var _0x5f2227;var _0x48e2d8=squel[_0x2552('0x6e')]();_0x48e2d8[_0x2552('0x6f')](_0x3b4beb[_0x2552('0x70')]);for(var _0x25e99f=0x0;_0x25e99f<_0x21faa3[_0x2552('0x39')];_0x25e99f+=0x1){_0x5f2227=_0x21faa3[_0x25e99f][_0x2552('0x71')]?_0x96069e[_0x21faa3[_0x25e99f]['MetricId']][_0x2552('0x72')]:_0x21faa3[_0x25e99f][_0x2552('0x73')];_0x5f2227=_0x21faa3[_0x25e99f][_0x2552('0x74')]?_[_0x2552('0x75')](_0x51be9f[_0x21faa3[_0x25e99f][_0x2552('0x74')]],'%s',_0x5f2227):_0x5f2227;_0x5f2227=_0x21faa3[_0x25e99f][_0x2552('0x76')]?_[_0x2552('0x75')](_0x41b55c[_0x21faa3[_0x25e99f][_0x2552('0x76')]],'%s',_0x5f2227):_0x5f2227;if(_0x21faa3[_0x25e99f][_0x2552('0x77')]){_0x48e2d8['group'](_0x5f2227);}_0x21faa3[_0x25e99f][_0x2552('0x78')]&&_0x48e2d8['order'](_0x5f2227,_0x21faa3[_0x25e99f][_0x2552('0x78')]===_0x2552('0x79')?![]:!![]);_0x48e2d8['field'](_0x5f2227,_0x21faa3[_0x25e99f]['alias']||_0x5f2227);}if(_0x3b4beb[_0x2552('0x7a')]){_0x3b4beb['joins']=JSON[_0x2552('0x7b')](_0x3b4beb[_0x2552('0x7a')]);for(var _0x1c9685=0x0;_0x1c9685<_0x3b4beb[_0x2552('0x7a')][_0x2552('0x39')];_0x1c9685+=0x1){if(_0x3b4beb[_0x2552('0x7a')][_0x1c9685][_0x2552('0x32')]&&_['includes'](_0x478b24,_0x3b4beb['joins'][_0x1c9685][_0x2552('0x32')])&&_0x3b4beb[_0x2552('0x7a')][_0x1c9685][_0x2552('0x7c')]&&_0x3b4beb[_0x2552('0x7a')][_0x1c9685][_0x2552('0x7d')]&&_0x3b4beb[_0x2552('0x7a')][_0x1c9685][_0x2552('0x7e')]){_0x48e2d8[_0x3b4beb[_0x2552('0x7a')][_0x1c9685]['type']](_0x3b4beb['joins'][_0x1c9685][_0x2552('0x7d')],null,util[_0x2552('0x76')](_0x2552('0x7f'),_0x3b4beb[_0x2552('0x70')],_0x3b4beb[_0x2552('0x7a')][_0x1c9685]['parentKey'],_0x3b4beb['joins'][_0x1c9685][_0x2552('0x7d')],_0x3b4beb[_0x2552('0x7a')][_0x1c9685][_0x2552('0x7e')]));}}}if(_0x3b4beb[_0x2552('0x80')]){_0x3b4beb[_0x2552('0x80')]=JSON[_0x2552('0x7b')](_0x3b4beb[_0x2552('0x80')]);_0x48e2d8['where'](_0x5bb69e(_0x3b4beb[_0x2552('0x80')][_0x2552('0x66')]));}_0x343518=_0x48e2d8['clone']();_0x48e2d8['limit'](_0x3e9750);_0x48e2d8['offset'](0x0);logger['debug'](_0x2552('0x81'),_0x48e2d8['toString']());return dbH[_0x2552('0x82')]['query'](_0x48e2d8[_0x2552('0x83')](),{'type':dbH['sequelize'][_0x2552('0x84')][_0x2552('0x85')]});}})[_0x2552('0x26')](respondWithResult(_0x4dff3e,null))[_0x2552('0x4b')](handleError(_0x4dff3e,null));};function runReport(_0x2ddb58,_0x3a427d,_0x2c7945){var _0x2f0157=_0x3a427d[_0x2552('0x2c')];var _0x11dcb9=0xa;var _0x4a173c=[_0x2552('0x58'),'left_join',_0x2552('0x59'),'cross_join'];var _0x3dfa44={'SUM':_0x2552('0x86'),'COUNT':_0x2552('0x87'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x2552('0x5c'),'MIN':_0x2552('0x88'),'AVG':_0x2552('0x89'),'GROUP_CONCAT':_0x2552('0x8a'),'GROUP_CONCAT ASC':_0x2552('0x5d'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x21224e={'SEC_TO_TIME':_0x2552('0x8b'),'DATE':_0x2552('0x5f'),'HOUR':_0x2552('0x60'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x2552('0x8c')};var _0x5a9882=function(_0x447b40){return!_['includes']([_0x2552('0x62'),_0x2552('0x63'),_0x2552('0x64'),_0x2552('0x8d')],_0x447b40);};var _0x21a12f=function(_0x22b455){if(!_0x22b455||!_0x22b455[_0x2552('0x65')]['length']){return'';}for(var _0x54b8b9='(',_0x26b594=0x0;_0x26b594<_0x22b455[_0x2552('0x65')][_0x2552('0x39')];_0x26b594+=0x1){_0x26b594>0x0&&(_0x54b8b9+='\x20'+_0x22b455[_0x2552('0x8e')]+'\x20');_0x54b8b9+=_0x22b455[_0x2552('0x65')][_0x26b594]['group']?_0x21a12f(_0x22b455[_0x2552('0x65')][_0x26b594][_0x2552('0x66')]):_0x22b455[_0x2552('0x65')][_0x26b594][_0x2552('0x73')]+'\x20'+_0x22b455['rules'][_0x26b594][_0x2552('0x67')]+(_0x5a9882(_0x22b455['rules'][_0x26b594][_0x2552('0x67')])?'\x20'+_0x22b455[_0x2552('0x65')][_0x26b594][_0x2552('0x8f')]:'');}return _0x54b8b9+')';};var _0x4a9c6f={'where':{'id':_0x2ddb58['id']}},_0xf0ed9c,_0x4b7764,_0x3725a0,_0x1deec9,_0x5d6521;_0x4a9c6f=_[_0x2552('0x42')]({},_0x4a9c6f,_0x2c7945);return db[_0x2552('0x30')]['find'](_0x4a9c6f)['then'](function(_0x5304aa){if(_0x5304aa){_0xf0ed9c=_0x5304aa;return _0x5304aa[_0x2552('0x68')]();}return null;})[_0x2552('0x26')](function(_0x406795){if(_0x406795){if(!_0x406795['length']){throw new db[(_0x2552('0x69'))][(_0x2552('0x6a'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x4b7764=_0x406795;return db[_0x2552('0x6c')][_0x2552('0x46')]({'raw':!![]});}return null;})[_0x2552('0x26')](function(_0x302e95){if(_0x302e95){_0x3725a0=_[_0x2552('0x6d')](_0x302e95,'id');var _0x2b211c;var _0x296784=squel['select']();_0x296784[_0x2552('0x6f')](_0xf0ed9c[_0x2552('0x70')]);for(var _0x2ff89c=0x0;_0x2ff89c<_0x4b7764[_0x2552('0x39')];_0x2ff89c+=0x1){_0x2b211c=_0x4b7764[_0x2ff89c][_0x2552('0x71')]?_0x3725a0[_0x4b7764[_0x2ff89c][_0x2552('0x71')]][_0x2552('0x72')]:_0x4b7764[_0x2ff89c][_0x2552('0x73')];_0x2b211c=_0x4b7764[_0x2ff89c]['function']?_[_0x2552('0x75')](_0x3dfa44[_0x4b7764[_0x2ff89c][_0x2552('0x74')]],'%s',_0x2b211c):_0x2b211c;_0x2b211c=_0x4b7764[_0x2ff89c][_0x2552('0x76')]?_[_0x2552('0x75')](_0x21224e[_0x4b7764[_0x2ff89c][_0x2552('0x76')]],'%s',_0x2b211c):_0x2b211c;if(_0x4b7764[_0x2ff89c][_0x2552('0x77')]){_0x296784[_0x2552('0x66')](_0x2b211c);}_0x4b7764[_0x2ff89c][_0x2552('0x78')]&&_0x296784[_0x2552('0x3c')](_0x2b211c,_0x4b7764[_0x2ff89c][_0x2552('0x78')]==='DESC'?![]:!![]);_0x296784[_0x2552('0x73')](_0x2b211c,_0x4b7764[_0x2ff89c][_0x2552('0x90')]||_0x2b211c);}if(_0xf0ed9c['joins']){_0xf0ed9c[_0x2552('0x7a')]=JSON[_0x2552('0x7b')](_0xf0ed9c[_0x2552('0x7a')]);for(var _0x11ff79=0x0;_0x11ff79<_0xf0ed9c['joins'][_0x2552('0x39')];_0x11ff79+=0x1){if(_0xf0ed9c[_0x2552('0x7a')][_0x11ff79][_0x2552('0x32')]&&_[_0x2552('0x91')](_0x4a173c,_0xf0ed9c['joins'][_0x11ff79]['type'])&&_0xf0ed9c['joins'][_0x11ff79][_0x2552('0x7c')]&&_0xf0ed9c[_0x2552('0x7a')][_0x11ff79][_0x2552('0x7d')]&&_0xf0ed9c[_0x2552('0x7a')][_0x11ff79][_0x2552('0x7e')]){_0x296784[_0xf0ed9c['joins'][_0x11ff79][_0x2552('0x32')]](_0xf0ed9c[_0x2552('0x7a')][_0x11ff79][_0x2552('0x7d')],null,util[_0x2552('0x76')]('%s.%s\x20=\x20%s.%s',_0xf0ed9c[_0x2552('0x70')],_0xf0ed9c['joins'][_0x11ff79][_0x2552('0x7c')],_0xf0ed9c['joins'][_0x11ff79][_0x2552('0x7d')],_0xf0ed9c[_0x2552('0x7a')][_0x11ff79][_0x2552('0x7e')]));}}}if(_0xf0ed9c[_0x2552('0x80')]){_0xf0ed9c['conditions']=JSON[_0x2552('0x7b')](_0xf0ed9c[_0x2552('0x80')]);_0x296784[_0x2552('0x3e')](_0x21a12f(_0xf0ed9c[_0x2552('0x80')]['group']));}_0x5d6521=_0x296784[_0x2552('0x92')]();_0x296784['limit'](_0x11dcb9);_0x296784[_0x2552('0x21')](0x0);return;}})[_0x2552('0x26')](function(){if(_0x3a427d[_0x2552('0x93')]===_0x2552('0x94')){return null;}var _0x9b441c=_[_0x2552('0x42')](_0x3a427d,{'name':_0x3a427d[_0x2552('0x95')]||_0x3a427d[_0x2552('0x2c')]||_0xf0ed9c['name'],'basename':_0x2f0157,'savename':util[_0x2552('0x76')](_0x2552('0x96'),_0x3a427d[_0x2552('0x2c')]||_0xf0ed9c['name'],require(_0x2552('0x97'))[_0x2552('0x98')](0x4),_0x3a427d[_0x2552('0x93')]||_0x2552('0x99')),'reportId':_0xf0ed9c['id'],'reportType':'custom'});return db['AnalyticExtractedReport'][_0x2552('0x4c')](_0x9b441c,{'raw':!![]});})[_0x2552('0x26')](function(_0x91782c){if(_0xf0ed9c[_0x2552('0x70')]===_0x2552('0x9a')){_0x5d6521[_0x2552('0x3e')](_0xf0ed9c[_0x2552('0x70')]+_0x2552('0x9b'),_0x3a427d['startDate'],_0x3a427d[_0x2552('0x9c')]);}else{_0x5d6521['where'](_0xf0ed9c[_0x2552('0x70')]+'.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x3a427d[_0x2552('0x9d')],_0x3a427d['endDate']);}if(_0x91782c){logger['info']('Run\x20Query:',_0x5d6521['toString']());require(_0x2552('0x9e'))[_0x2552('0x9f')](path[_0x2552('0x58')](__dirname,'../../components/export/',_0x91782c[_0x2552('0x93')]),[_0x91782c['id'],_0x5d6521['toString'](),path[_0x2552('0x58')](__dirname,'../../files/reports',_0x91782c['savename']),_0x2f0157]);return _0x91782c;}else{var _0x1fdf6a=squel[_0x2552('0x6e')]();_0x1fdf6a['from']('('+_0x5d6521[_0x2552('0x83')]()+')',_0x2552('0xa0'));_0x1fdf6a[_0x2552('0x73')](_0x2552('0xa1'),'count');_0x5d6521[_0x2552('0x20')](_0x3a427d[_0x2552('0x20')]||_0x11dcb9);_0x5d6521[_0x2552('0x21')](_0x3a427d[_0x2552('0x21')]||0x0);return dbH[_0x2552('0x82')][_0x2552('0x35')](_0x1fdf6a[_0x2552('0x83')](),{'type':dbH['sequelize'][_0x2552('0x84')][_0x2552('0x85')]})[_0x2552('0x26')](function(_0x469385){if(!_0x469385['length']){_0x1deec9=0x0;}else{_0x1deec9=_0x469385[0x0][_0x2552('0x22')]||0x0;}return dbH[_0x2552('0x82')][_0x2552('0x35')](_0x5d6521[_0x2552('0x83')](),{'type':dbH[_0x2552('0x82')][_0x2552('0x84')][_0x2552('0x85')]});})[_0x2552('0x26')](function(_0x2e6953){return{'rows':_0x2e6953||[],'count':_0x1deec9};});}});}exports[_0x2552('0xa2')]=function(_0x4cbfbb,_0x4eed14){return runReport(_0x4cbfbb[_0x2552('0x48')],_0x4cbfbb[_0x2552('0x35')],_0x4cbfbb[_0x2552('0x44')])[_0x2552('0x26')](respondWithResult(_0x4eed14,null))[_0x2552('0x4b')](handleError(_0x4eed14,null));};exports[_0x2552('0xa3')]=runReport;exports[_0x2552('0x35')]=function(_0x228083,_0x5dddb4){var _0x31514a=0xa;var _0x1c4fba=['join',_0x2552('0xa4'),_0x2552('0x59'),_0x2552('0x5a')];var _0x23a5b={'SUM':_0x2552('0x86'),'COUNT':_0x2552('0x87'),'COUNT DISTINCT':_0x2552('0x5b'),'MAX':_0x2552('0x5c'),'MIN':_0x2552('0x88'),'AVG':_0x2552('0x89'),'GROUP_CONCAT':_0x2552('0x8a'),'GROUP_CONCAT ASC':_0x2552('0x5d'),'GROUP_CONCAT DESC':_0x2552('0x5e')};var _0x2dfe5f={'SEC_TO_TIME':_0x2552('0x8b'),'DATE':'DATE(%s)','HOUR':_0x2552('0x60'),'ROUND':_0x2552('0x61'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x42e615=function(_0x251c37){return!_[_0x2552('0x91')]([_0x2552('0x62'),_0x2552('0x63'),'IS\x20EMPTY','IS\x20NOT\x20EMPTY'],_0x251c37);};var _0x249a48=function(_0x3d9c22){if(!_0x3d9c22||!_0x3d9c22[_0x2552('0x65')][_0x2552('0x39')]){return'';}for(var _0x4ba2e1='(',_0x31b798=0x0;_0x31b798<_0x3d9c22[_0x2552('0x65')][_0x2552('0x39')];_0x31b798+=0x1){_0x31b798>0x0&&(_0x4ba2e1+='\x20'+_0x3d9c22[_0x2552('0x8e')]+'\x20');_0x4ba2e1+=_0x3d9c22[_0x2552('0x65')][_0x31b798]['group']?_0x249a48(_0x3d9c22[_0x2552('0x65')][_0x31b798][_0x2552('0x66')]):_0x3d9c22[_0x2552('0x65')][_0x31b798][_0x2552('0x73')]+'\x20'+_0x3d9c22[_0x2552('0x65')][_0x31b798]['condition']+(_0x42e615(_0x3d9c22[_0x2552('0x65')][_0x31b798][_0x2552('0x67')])?'\x20'+_0x3d9c22[_0x2552('0x65')][_0x31b798][_0x2552('0x8f')]:'');}return _0x4ba2e1+')';};var _0x1b6e0c={'where':{'id':_0x228083['params']['id']}},_0x5bb3e8,_0x45c9ac,_0x143416,_0x45b36a,_0x4ab55;_0x1b6e0c=_[_0x2552('0x42')]({},_0x1b6e0c,_0x228083[_0x2552('0x44')]);return db[_0x2552('0x30')][_0x2552('0x52')](_0x1b6e0c)[_0x2552('0x26')](function(_0x3cc40a){if(_0x3cc40a){_0x5bb3e8=_0x3cc40a;return _0x3cc40a['getFields']();}return null;})[_0x2552('0x26')](function(_0x173f2a){if(_0x173f2a){if(!_0x173f2a['length']){throw new db[(_0x2552('0x69'))][(_0x2552('0x6a'))](_0x2552('0x6b'),0x193);}_0x45c9ac=_0x173f2a;return db[_0x2552('0x6c')][_0x2552('0x46')]({'raw':!![]});}return null;})['then'](function(_0x365a4a){if(_0x365a4a){_0x143416=_[_0x2552('0x6d')](_0x365a4a,'id');var _0x135108;var _0x3622ba=squel[_0x2552('0x6e')]();_0x3622ba[_0x2552('0x6f')](_0x5bb3e8[_0x2552('0x70')]);for(var _0x96105d=0x0;_0x96105d<_0x45c9ac[_0x2552('0x39')];_0x96105d+=0x1){_0x135108=_0x45c9ac[_0x96105d][_0x2552('0x71')]?_0x143416[_0x45c9ac[_0x96105d][_0x2552('0x71')]]['metric']:_0x45c9ac[_0x96105d]['field'];_0x135108=_0x45c9ac[_0x96105d][_0x2552('0x74')]?_['replace'](_0x23a5b[_0x45c9ac[_0x96105d][_0x2552('0x74')]],'%s',_0x135108):_0x135108;_0x135108=_0x45c9ac[_0x96105d][_0x2552('0x76')]?_['replace'](_0x2dfe5f[_0x45c9ac[_0x96105d][_0x2552('0x76')]],'%s',_0x135108):_0x135108;if(_0x45c9ac[_0x96105d][_0x2552('0x77')]){_0x3622ba[_0x2552('0x66')](_0x135108);}_0x45c9ac[_0x96105d]['orderBy']&&_0x3622ba[_0x2552('0x3c')](_0x135108,_0x45c9ac[_0x96105d][_0x2552('0x78')]===_0x2552('0x79')?![]:!![]);_0x3622ba['field'](_0x135108,_0x45c9ac[_0x96105d][_0x2552('0x90')]||_0x135108);}if(_0x5bb3e8['joins']){_0x5bb3e8[_0x2552('0x7a')]=JSON[_0x2552('0x7b')](_0x5bb3e8[_0x2552('0x7a')]);for(var _0x5aafed=0x0;_0x5aafed<_0x5bb3e8[_0x2552('0x7a')][_0x2552('0x39')];_0x5aafed+=0x1){if(_0x5bb3e8['joins'][_0x5aafed][_0x2552('0x32')]&&_[_0x2552('0x91')](_0x1c4fba,_0x5bb3e8[_0x2552('0x7a')][_0x5aafed][_0x2552('0x32')])&&_0x5bb3e8[_0x2552('0x7a')][_0x5aafed]['parentKey']&&_0x5bb3e8['joins'][_0x5aafed][_0x2552('0x7d')]&&_0x5bb3e8[_0x2552('0x7a')][_0x5aafed]['foreignKey']){_0x3622ba[_0x5bb3e8[_0x2552('0x7a')][_0x5aafed]['type']](_0x5bb3e8[_0x2552('0x7a')][_0x5aafed]['foreignTable'],null,util[_0x2552('0x76')](_0x2552('0x7f'),_0x5bb3e8['table'],_0x5bb3e8[_0x2552('0x7a')][_0x5aafed][_0x2552('0x7c')],_0x5bb3e8[_0x2552('0x7a')][_0x5aafed][_0x2552('0x7d')],_0x5bb3e8[_0x2552('0x7a')][_0x5aafed][_0x2552('0x7e')]));}}}if(_0x5bb3e8[_0x2552('0x80')]){_0x5bb3e8[_0x2552('0x80')]=JSON['parse'](_0x5bb3e8['conditions']);_0x3622ba[_0x2552('0x3e')](_0x249a48(_0x5bb3e8['conditions'][_0x2552('0x66')]));}_0x4ab55=_0x3622ba[_0x2552('0x92')]();_0x3622ba[_0x2552('0x20')](_0x31514a);_0x3622ba[_0x2552('0x21')](0x0);logger['debug'](_0x2552('0x81'),_0x3622ba['toString']());return dbH['sequelize'][_0x2552('0x35')](_0x3622ba[_0x2552('0x83')](),{'type':dbH[_0x2552('0x82')]['QueryTypes'][_0x2552('0x85')]});}})[_0x2552('0x26')](function(){return{'sql':_0x4ab55['toString']()};})[_0x2552('0x26')](respondWithResult(_0x5dddb4,null))[_0x2552('0x4b')](handleError(_0x5dddb4,null));};
\ No newline at end of file