Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index c6c177f..645135f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x54bb=['stack','name','send','map','rawAttributes','fieldName','type','key','query','filters','intersection','attributes','fields','length','model','hasOwnProperty','nolimit','order','sort','filter','where','VIRTUAL','merge','AnalyticCustomReport','includeAll','include','catch','params','keys','options','find','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Reports','userProfileId','autoAssociation','CustomReports','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','body','preview','join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','DATE(%s)','HOUR(%s)','UNIX_TIMESTAMP(%s)','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','group','condition','value','getFields','Sequelize','ValidationErrorItem','findAll','keyBy','from','table','MetricId','metric','field','function','replace','format','orderBy','alias','joins','parse','includes','parentKey','foreignKey','foreignTable','%s.%s\x20=\x20%s.%s','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','SELECT','left_join','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','SEC_TO_TIME(%s)','ROUND(%s)','AnalyticMetric','select','No\x20available\x20data','web','fullPath','%s-%s.%s','randomstring','generate','csv','custom','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','../../components/export/','output','../../files/reports','savename','COUNT(*)','run','Please\x20insert\x20at\x20least\x20one\x20field','html-pdf','rimraf','fast-json-patch','request-promise','moment','mustache','util','sox','ejs','squel','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','end','status','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','UserProfileResource','sendStatus'];(function(_0x4e90e3,_0x570a1d){var _0x295e5b=function(_0x754043){while(--_0x754043){_0x4e90e3['push'](_0x4e90e3['shift']());}};_0x295e5b(++_0x570a1d);}(_0x54bb,0x7c));var _0xb54b=function(_0x11963b,_0x5d2da7){_0x11963b=_0x11963b-0x0;var _0x5d451e=_0x54bb[_0x11963b];return _0x5d451e;};'use strict';var pdf=require(_0xb54b('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xb54b('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xb54b('0x2'));var rp=require(_0xb54b('0x3'));var moment=require(_0xb54b('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xb54b('0x5'));var util=require(_0xb54b('0x6'));var path=require('path');var sox=require(_0xb54b('0x7'));var csv=require('to-csv');var ejs=require(_0xb54b('0x8'));var fs=require('fs');var _=require('lodash');var squel=require(_0xb54b('0x9'));var crypto=require('crypto');var jsforce=require(_0xb54b('0xa'));var deskjs=require(_0xb54b('0xb'));var toCsv=require(_0xb54b('0xc'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xb54b('0xd'));var authService=require(_0xb54b('0xe'));var qs=require(_0xb54b('0xf'));var as=require(_0xb54b('0x10'));var hardwareService=require(_0xb54b('0x11'));var logger=require(_0xb54b('0x12'))(_0xb54b('0x13'));var utils=require(_0xb54b('0x14'));var config=require('../../config/environment');var db=require(_0xb54b('0x15'))['db'];function respondWithStatusCode(_0x4165ff,_0x36bd92){_0x36bd92=_0x36bd92||0xcc;return function(_0x4afee3){if(_0x4afee3){return _0x4165ff['sendStatus'](_0x36bd92);}return _0x4165ff['status'](_0x36bd92)[_0xb54b('0x16')]();};}function respondWithResult(_0xfd7437,_0x52cef2){_0x52cef2=_0x52cef2||0xc8;return function(_0x511a2d){if(_0x511a2d){return _0xfd7437[_0xb54b('0x17')](_0x52cef2)['json'](_0x511a2d);}};}function respondWithFilteredResult(_0x3a72a7,_0x5b4831){return function(_0x502d31){if(_0x502d31){var _0x32660b=_0x502d31[_0xb54b('0x18')],_0x3ace3c=_0x5b4831['offset'],_0x379d8f=_0x5b4831[_0xb54b('0x19')]+_0x5b4831[_0xb54b('0x1a')],_0x17861b;if(_0x379d8f>=_0x32660b){_0x379d8f=_0x32660b;_0x17861b=0xc8;}else{_0x17861b=0xce;}_0x3a72a7[_0xb54b('0x17')](_0x17861b);return _0x3a72a7[_0xb54b('0x1b')](_0xb54b('0x1c'),_0x3ace3c+'-'+_0x379d8f+'/'+_0x32660b)['json'](_0x502d31);}return null;};}function patchUpdates(_0x2e176d){return function(_0x4b5bc8){try{jsonpatch[_0xb54b('0x1d')](_0x4b5bc8,_0x2e176d,!![]);}catch(_0x49c964){return BPromise[_0xb54b('0x1e')](_0x49c964);}return _0x4b5bc8[_0xb54b('0x1f')]();};}function saveUpdates(_0x4c8dda,_0x2c8e95){return function(_0x52727e){if(_0x52727e){return _0x52727e[_0xb54b('0x20')](_0x4c8dda)[_0xb54b('0x21')](function(_0x3bd987){return _0x3bd987;});}return null;};}function removeEntity(_0x5be84b,_0x3e1a1e){return function(_0x48cc4c){if(_0x48cc4c){return _0x48cc4c[_0xb54b('0x22')]()[_0xb54b('0x21')](function(){var _0x4f8506=_0x48cc4c[_0xb54b('0x23')]({'plain':!![]});var _0xe60bc3='CustomReports';return db[_0xb54b('0x24')][_0xb54b('0x22')]({'where':{'type':_0xe60bc3,'resourceId':_0x4f8506['id']}})[_0xb54b('0x21')](function(){return _0x48cc4c;});})[_0xb54b('0x21')](function(){_0x5be84b[_0xb54b('0x17')](0xcc)[_0xb54b('0x16')]();});}};}function handleEntityNotFound(_0x3cf25a,_0x386c8e){return function(_0x230c54){if(!_0x230c54){_0x3cf25a[_0xb54b('0x25')](0x194);}return _0x230c54;};}function handleError(_0x5bbf60,_0x5f1f10){_0x5f1f10=_0x5f1f10||0x1f4;return function(_0x3781af){logger['error'](_0x3781af[_0xb54b('0x26')]);if(_0x3781af[_0xb54b('0x27')]){delete _0x3781af['name'];}_0x5bbf60['status'](_0x5f1f10)[_0xb54b('0x28')](_0x3781af);};}exports['index']=function(_0x45c514,_0x3c9669){var _0x2300df={},_0x3b0964={},_0x312f7e={'count':0x0,'rows':[]};var _0x414cdd=_[_0xb54b('0x29')](db['AnalyticCustomReport'][_0xb54b('0x2a')],function(_0x215ac5){return{'name':_0x215ac5[_0xb54b('0x2b')],'type':_0x215ac5[_0xb54b('0x2c')][_0xb54b('0x2d')]};});_0x3b0964['model']=_['map'](_0x414cdd,'name');_0x3b0964['query']=_['keys'](_0x45c514[_0xb54b('0x2e')]);_0x3b0964[_0xb54b('0x2f')]=_[_0xb54b('0x30')](_0x3b0964['model'],_0x3b0964[_0xb54b('0x2e')]);_0x2300df[_0xb54b('0x31')]=_[_0xb54b('0x30')](_0x3b0964['model'],qs[_0xb54b('0x32')](_0x45c514['query'][_0xb54b('0x32')]));_0x2300df[_0xb54b('0x31')]=_0x2300df[_0xb54b('0x31')][_0xb54b('0x33')]?_0x2300df[_0xb54b('0x31')]:_0x3b0964[_0xb54b('0x34')];if(!_0x45c514[_0xb54b('0x2e')][_0xb54b('0x35')](_0xb54b('0x36'))){_0x2300df['limit']=qs[_0xb54b('0x1a')](_0x45c514[_0xb54b('0x2e')]['limit']);_0x2300df[_0xb54b('0x19')]=qs[_0xb54b('0x19')](_0x45c514[_0xb54b('0x2e')][_0xb54b('0x19')]);}_0x2300df[_0xb54b('0x37')]=qs['sort'](_0x45c514['query'][_0xb54b('0x38')]);_0x2300df['where']=qs[_0xb54b('0x2f')](_['pick'](_0x45c514[_0xb54b('0x2e')],_0x3b0964['filters']));if(_0x45c514[_0xb54b('0x2e')][_0xb54b('0x39')]){_0x2300df[_0xb54b('0x3a')]=_['merge'](_0x2300df['where'],{'$or':_[_0xb54b('0x29')](_0x414cdd,function(_0x48404e){if(_0x48404e['type']!==_0xb54b('0x3b')){var _0x1f4e4a={};_0x1f4e4a[_0x48404e[_0xb54b('0x27')]]={'$like':'%'+_0x45c514[_0xb54b('0x2e')][_0xb54b('0x39')]+'%'};return _0x1f4e4a;}})});}_0x2300df=_[_0xb54b('0x3c')]({},_0x2300df,_0x45c514['options']);var _0x75d064={'where':_0x2300df['where']};return db[_0xb54b('0x3d')]['count'](_0x75d064)[_0xb54b('0x21')](function(_0x431e95){_0x312f7e[_0xb54b('0x18')]=_0x431e95;if(_0x45c514[_0xb54b('0x2e')][_0xb54b('0x3e')]){_0x2300df[_0xb54b('0x3f')]=[{'all':!![]}];}return db['AnalyticCustomReport']['findAll'](_0x2300df);})[_0xb54b('0x21')](function(_0x4ef66d){_0x312f7e['rows']=_0x4ef66d;return _0x312f7e;})[_0xb54b('0x21')](respondWithFilteredResult(_0x3c9669,_0x2300df))[_0xb54b('0x40')](handleError(_0x3c9669,null));};exports['show']=function(_0x11b52a,_0x22efea){var _0x43e92c={'raw':![],'where':{'id':_0x11b52a[_0xb54b('0x41')]['id']}},_0x48abe1={};_0x48abe1['model']=_[_0xb54b('0x42')](db[_0xb54b('0x3d')][_0xb54b('0x2a')]);_0x48abe1['query']=_['keys'](_0x11b52a['query']);_0x48abe1[_0xb54b('0x2f')]=_[_0xb54b('0x30')](_0x48abe1['model'],_0x48abe1[_0xb54b('0x2e')]);_0x43e92c[_0xb54b('0x31')]=_[_0xb54b('0x30')](_0x48abe1['model'],qs[_0xb54b('0x32')](_0x11b52a[_0xb54b('0x2e')][_0xb54b('0x32')]));_0x43e92c[_0xb54b('0x31')]=_0x43e92c['attributes'][_0xb54b('0x33')]?_0x43e92c[_0xb54b('0x31')]:_0x48abe1['model'];if(_0x11b52a[_0xb54b('0x2e')][_0xb54b('0x3e')]){_0x43e92c[_0xb54b('0x3f')]=[{'all':!![]}];}_0x43e92c=_[_0xb54b('0x3c')]({},_0x43e92c,_0x11b52a[_0xb54b('0x43')]);return db[_0xb54b('0x3d')][_0xb54b('0x44')](_0x43e92c)[_0xb54b('0x21')](handleEntityNotFound(_0x22efea,null))[_0xb54b('0x21')](respondWithResult(_0x22efea,null))[_0xb54b('0x40')](handleError(_0x22efea,null));};exports['create']=function(_0x5be37a,_0x7cbe37){return db['AnalyticCustomReport'][_0xb54b('0x45')](_0x5be37a['body'],{})[_0xb54b('0x21')](function(_0x37200d){var _0xe87dc7=_0x5be37a[_0xb54b('0x46')][_0xb54b('0x23')]({'plain':!![]});if(!_0xe87dc7)throw new Error(_0xb54b('0x47'));if(_0xe87dc7[_0xb54b('0x48')]==='user'){var _0x570f26=_0x37200d[_0xb54b('0x23')]({'plain':!![]});var _0x4d1b5a=_0xb54b('0x49');return db['UserProfileSection'][_0xb54b('0x44')]({'where':{'name':_0x4d1b5a,'userProfileId':_0xe87dc7[_0xb54b('0x4a')]},'raw':!![]})[_0xb54b('0x21')](function(_0x1653d0){if(_0x1653d0&&_0x1653d0[_0xb54b('0x4b')]===0x0){return db[_0xb54b('0x24')]['create']({'name':_0x570f26['name'],'resourceId':_0x570f26['id'],'type':_0xb54b('0x4c'),'sectionId':_0x1653d0['id']},{})['then'](function(){return _0x37200d;});}else{return _0x37200d;}})[_0xb54b('0x40')](function(_0x131993){logger[_0xb54b('0x4d')](_0xb54b('0x4e'),_0x131993);throw _0x131993;});}return _0x37200d;})['then'](respondWithResult(_0x7cbe37,0xc9))['catch'](handleError(_0x7cbe37,null));};exports[_0xb54b('0x20')]=function(_0xde9348,_0x55a99f){if(_0xde9348['body']['id']){delete _0xde9348['body']['id'];}return db[_0xb54b('0x3d')][_0xb54b('0x44')]({'where':{'id':_0xde9348[_0xb54b('0x41')]['id']}})['then'](handleEntityNotFound(_0x55a99f,null))[_0xb54b('0x21')](saveUpdates(_0xde9348[_0xb54b('0x4f')],null))[_0xb54b('0x21')](respondWithResult(_0x55a99f,null))[_0xb54b('0x40')](handleError(_0x55a99f,null));};exports[_0xb54b('0x22')]=function(_0x4d2ccf,_0x1caa95){return db['AnalyticCustomReport'][_0xb54b('0x44')]({'where':{'id':_0x4d2ccf[_0xb54b('0x41')]['id']}})[_0xb54b('0x21')](handleEntityNotFound(_0x1caa95,null))['then'](removeEntity(_0x1caa95,null))[_0xb54b('0x40')](handleError(_0x1caa95,null));};exports[_0xb54b('0x50')]=function(_0x26690e,_0xb67bd9){var _0x56485f=0xa;var _0x1e086b=[_0xb54b('0x51'),'left_join',_0xb54b('0x52'),_0xb54b('0x53')];var _0x1d055a={'SUM':_0xb54b('0x54'),'COUNT':_0xb54b('0x55'),'COUNT DISTINCT':_0xb54b('0x56'),'MAX':_0xb54b('0x57'),'MIN':_0xb54b('0x58'),'AVG':_0xb54b('0x59'),'GROUP_CONCAT':_0xb54b('0x5a'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0xb54b('0x5b')};var _0x1a8b6b={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0xb54b('0x5c'),'HOUR':_0xb54b('0x5d'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xb54b('0x5e')};var _0x13eb55=function(_0x510e5c){return!_['includes']([_0xb54b('0x5f'),_0xb54b('0x60'),_0xb54b('0x61'),_0xb54b('0x62')],_0x510e5c);};var _0x15ca3d=function(_0x5ce3ce){if(!_0x5ce3ce||!_0x5ce3ce['rules'][_0xb54b('0x33')]){return'';}for(var _0x34abdd='(',_0x52de06=0x0;_0x52de06<_0x5ce3ce[_0xb54b('0x63')][_0xb54b('0x33')];_0x52de06+=0x1){_0x52de06>0x0&&(_0x34abdd+='\x20'+_0x5ce3ce[_0xb54b('0x64')]+'\x20');_0x34abdd+=_0x5ce3ce[_0xb54b('0x63')][_0x52de06][_0xb54b('0x65')]?_0x15ca3d(_0x5ce3ce['rules'][_0x52de06][_0xb54b('0x65')]):_0x5ce3ce[_0xb54b('0x63')][_0x52de06]['field']+'\x20'+_0x5ce3ce[_0xb54b('0x63')][_0x52de06][_0xb54b('0x66')]+(_0x13eb55(_0x5ce3ce['rules'][_0x52de06][_0xb54b('0x66')])?'\x20'+_0x5ce3ce[_0xb54b('0x63')][_0x52de06][_0xb54b('0x67')]:'');}return _0x34abdd+')';};var _0x2248dd={'where':{'id':_0x26690e[_0xb54b('0x41')]['id']}},_0x51dd5d,_0xb761d5,_0x5f191d,_0xaa2a7e,_0x4dc513;_0x2248dd=_[_0xb54b('0x3c')]({},_0x2248dd,_0x26690e[_0xb54b('0x43')]);return db[_0xb54b('0x3d')][_0xb54b('0x44')](_0x2248dd)['then'](function(_0x46fd76){if(_0x46fd76){_0x51dd5d=_0x46fd76;return _0x46fd76[_0xb54b('0x68')]();}return null;})['then'](function(_0x2af366){if(_0x2af366){if(!_0x2af366[_0xb54b('0x33')]){throw new db[(_0xb54b('0x69'))][(_0xb54b('0x6a'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0xb761d5=_0x2af366;return db['AnalyticMetric'][_0xb54b('0x6b')]({'raw':!![]});}return null;})[_0xb54b('0x21')](function(_0x127d66){if(_0x127d66){_0x5f191d=_[_0xb54b('0x6c')](_0x127d66,'id');var _0x430b7d;var _0x54ad90=squel['select']();_0x54ad90[_0xb54b('0x6d')](_0x51dd5d[_0xb54b('0x6e')]);for(var _0x59acf1=0x0;_0x59acf1<_0xb761d5[_0xb54b('0x33')];_0x59acf1+=0x1){_0x430b7d=_0xb761d5[_0x59acf1][_0xb54b('0x6f')]?_0x5f191d[_0xb761d5[_0x59acf1]['MetricId']][_0xb54b('0x70')]:_0xb761d5[_0x59acf1][_0xb54b('0x71')];_0x430b7d=_0xb761d5[_0x59acf1][_0xb54b('0x72')]?_[_0xb54b('0x73')](_0x1d055a[_0xb761d5[_0x59acf1][_0xb54b('0x72')]],'%s',_0x430b7d):_0x430b7d;_0x430b7d=_0xb761d5[_0x59acf1]['format']?_[_0xb54b('0x73')](_0x1a8b6b[_0xb761d5[_0x59acf1][_0xb54b('0x74')]],'%s',_0x430b7d):_0x430b7d;if(_0xb761d5[_0x59acf1]['groupBy']){_0x54ad90[_0xb54b('0x65')](_0x430b7d);}_0xb761d5[_0x59acf1][_0xb54b('0x75')]&&_0x54ad90[_0xb54b('0x37')](_0x430b7d,_0xb761d5[_0x59acf1]['orderBy']==='DESC'?![]:!![]);_0x54ad90[_0xb54b('0x71')](_0x430b7d,_0xb761d5[_0x59acf1][_0xb54b('0x76')]||_0x430b7d);}if(_0x51dd5d['joins']){_0x51dd5d[_0xb54b('0x77')]=JSON[_0xb54b('0x78')](_0x51dd5d[_0xb54b('0x77')]);for(var _0x504af1=0x0;_0x504af1<_0x51dd5d[_0xb54b('0x77')][_0xb54b('0x33')];_0x504af1+=0x1){if(_0x51dd5d[_0xb54b('0x77')][_0x504af1][_0xb54b('0x2c')]&&_[_0xb54b('0x79')](_0x1e086b,_0x51dd5d[_0xb54b('0x77')][_0x504af1][_0xb54b('0x2c')])&&_0x51dd5d[_0xb54b('0x77')][_0x504af1][_0xb54b('0x7a')]&&_0x51dd5d[_0xb54b('0x77')][_0x504af1]['foreignTable']&&_0x51dd5d[_0xb54b('0x77')][_0x504af1][_0xb54b('0x7b')]){_0x54ad90[_0x51dd5d[_0xb54b('0x77')][_0x504af1]['type']](_0x51dd5d['joins'][_0x504af1][_0xb54b('0x7c')],null,util[_0xb54b('0x74')](_0xb54b('0x7d'),_0x51dd5d[_0xb54b('0x6e')],_0x51dd5d['joins'][_0x504af1]['parentKey'],_0x51dd5d['joins'][_0x504af1][_0xb54b('0x7c')],_0x51dd5d[_0xb54b('0x77')][_0x504af1][_0xb54b('0x7b')]));}}}if(_0x51dd5d[_0xb54b('0x7e')]){_0x51dd5d[_0xb54b('0x7e')]=JSON['parse'](_0x51dd5d[_0xb54b('0x7e')]);_0x54ad90[_0xb54b('0x3a')](_0x15ca3d(_0x51dd5d[_0xb54b('0x7e')][_0xb54b('0x65')]));}_0x4dc513=_0x54ad90[_0xb54b('0x7f')]();_0x54ad90[_0xb54b('0x1a')](_0x56485f);_0x54ad90['offset'](0x0);logger[_0xb54b('0x80')](_0xb54b('0x81'),_0x54ad90[_0xb54b('0x82')]());return db[_0xb54b('0x83')][_0xb54b('0x2e')](_0x54ad90[_0xb54b('0x82')](),{'type':db[_0xb54b('0x83')][_0xb54b('0x84')][_0xb54b('0x85')]});}})[_0xb54b('0x21')](respondWithResult(_0xb67bd9,null))[_0xb54b('0x40')](handleError(_0xb67bd9,null));};function runReport(_0x27c31e,_0x3b32dc,_0x1005b3){var _0x326dba=_0x3b32dc[_0xb54b('0x27')];var _0x138faf=0xa;var _0x42338b=['join',_0xb54b('0x86'),_0xb54b('0x52'),_0xb54b('0x53')];var _0x37e226={'SUM':_0xb54b('0x54'),'COUNT':_0xb54b('0x55'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0xb54b('0x57'),'MIN':_0xb54b('0x58'),'AVG':_0xb54b('0x59'),'GROUP_CONCAT':_0xb54b('0x5a'),'GROUP_CONCAT ASC':_0xb54b('0x87'),'GROUP_CONCAT DESC':_0xb54b('0x5b')};var _0x57beb8={'SEC_TO_TIME':_0xb54b('0x88'),'DATE':_0xb54b('0x5c'),'HOUR':_0xb54b('0x5d'),'ROUND':_0xb54b('0x89'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0xc504be=function(_0x2dc0c3){return!_[_0xb54b('0x79')]([_0xb54b('0x5f'),'IS\x20NOT\x20NULL',_0xb54b('0x61'),_0xb54b('0x62')],_0x2dc0c3);};var _0x1a5000=function(_0x248b20){if(!_0x248b20||!_0x248b20[_0xb54b('0x63')][_0xb54b('0x33')]){return'';}for(var _0x33fd70='(',_0x49c78c=0x0;_0x49c78c<_0x248b20[_0xb54b('0x63')]['length'];_0x49c78c+=0x1){_0x49c78c>0x0&&(_0x33fd70+='\x20'+_0x248b20[_0xb54b('0x64')]+'\x20');_0x33fd70+=_0x248b20[_0xb54b('0x63')][_0x49c78c][_0xb54b('0x65')]?_0x1a5000(_0x248b20[_0xb54b('0x63')][_0x49c78c][_0xb54b('0x65')]):_0x248b20[_0xb54b('0x63')][_0x49c78c]['field']+'\x20'+_0x248b20[_0xb54b('0x63')][_0x49c78c][_0xb54b('0x66')]+(_0xc504be(_0x248b20[_0xb54b('0x63')][_0x49c78c][_0xb54b('0x66')])?'\x20'+_0x248b20['rules'][_0x49c78c][_0xb54b('0x67')]:'');}return _0x33fd70+')';};var _0x5f013a={'where':{'id':_0x27c31e['id']}},_0x1bbd1b,_0x557713,_0x1e091f,_0x119584,_0xf41b8e;_0x5f013a=_[_0xb54b('0x3c')]({},_0x5f013a,_0x1005b3);return db['AnalyticCustomReport'][_0xb54b('0x44')](_0x5f013a)[_0xb54b('0x21')](function(_0x1e584e){if(_0x1e584e){_0x1bbd1b=_0x1e584e;return _0x1e584e[_0xb54b('0x68')]();}return null;})[_0xb54b('0x21')](function(_0x46d099){if(_0x46d099){if(!_0x46d099[_0xb54b('0x33')]){throw new db[(_0xb54b('0x69'))][(_0xb54b('0x6a'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x557713=_0x46d099;return db[_0xb54b('0x8a')]['findAll']({'raw':!![]});}return null;})[_0xb54b('0x21')](function(_0x3ec49f){if(_0x3ec49f){_0x1e091f=_[_0xb54b('0x6c')](_0x3ec49f,'id');var _0x325ae2;var _0x30a6ff=squel[_0xb54b('0x8b')]();_0x30a6ff[_0xb54b('0x6d')](_0x1bbd1b['table']);for(var _0x1868c2=0x0;_0x1868c2<_0x557713[_0xb54b('0x33')];_0x1868c2+=0x1){_0x325ae2=_0x557713[_0x1868c2][_0xb54b('0x6f')]?_0x1e091f[_0x557713[_0x1868c2][_0xb54b('0x6f')]][_0xb54b('0x70')]:_0x557713[_0x1868c2][_0xb54b('0x71')];_0x325ae2=_0x557713[_0x1868c2]['function']?_[_0xb54b('0x73')](_0x37e226[_0x557713[_0x1868c2][_0xb54b('0x72')]],'%s',_0x325ae2):_0x325ae2;_0x325ae2=_0x557713[_0x1868c2][_0xb54b('0x74')]?_[_0xb54b('0x73')](_0x57beb8[_0x557713[_0x1868c2]['format']],'%s',_0x325ae2):_0x325ae2;if(_0x557713[_0x1868c2]['groupBy']){_0x30a6ff[_0xb54b('0x65')](_0x325ae2);}_0x557713[_0x1868c2]['orderBy']&&_0x30a6ff[_0xb54b('0x37')](_0x325ae2,_0x557713[_0x1868c2][_0xb54b('0x75')]==='DESC'?![]:!![]);_0x30a6ff[_0xb54b('0x71')](_0x325ae2,_0x557713[_0x1868c2][_0xb54b('0x76')]||_0x325ae2);}if(_0x1bbd1b[_0xb54b('0x77')]){_0x1bbd1b[_0xb54b('0x77')]=JSON[_0xb54b('0x78')](_0x1bbd1b['joins']);for(var _0x2d61b9=0x0;_0x2d61b9<_0x1bbd1b[_0xb54b('0x77')][_0xb54b('0x33')];_0x2d61b9+=0x1){if(_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9]['type']&&_[_0xb54b('0x79')](_0x42338b,_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9][_0xb54b('0x2c')])&&_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9][_0xb54b('0x7a')]&&_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9][_0xb54b('0x7c')]&&_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9][_0xb54b('0x7b')]){_0x30a6ff[_0x1bbd1b['joins'][_0x2d61b9][_0xb54b('0x2c')]](_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9][_0xb54b('0x7c')],null,util[_0xb54b('0x74')](_0xb54b('0x7d'),_0x1bbd1b[_0xb54b('0x6e')],_0x1bbd1b['joins'][_0x2d61b9][_0xb54b('0x7a')],_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9]['foreignTable'],_0x1bbd1b[_0xb54b('0x77')][_0x2d61b9][_0xb54b('0x7b')]));}}}if(_0x1bbd1b[_0xb54b('0x7e')]){_0x1bbd1b[_0xb54b('0x7e')]=JSON[_0xb54b('0x78')](_0x1bbd1b['conditions']);_0x30a6ff[_0xb54b('0x3a')](_0x1a5000(_0x1bbd1b[_0xb54b('0x7e')][_0xb54b('0x65')]));}_0xf41b8e=_0x30a6ff[_0xb54b('0x7f')]();_0x30a6ff[_0xb54b('0x1a')](_0x138faf);_0x30a6ff[_0xb54b('0x19')](0x0);logger[_0xb54b('0x80')](_0xb54b('0x81'),_0x30a6ff[_0xb54b('0x82')]());return db[_0xb54b('0x83')][_0xb54b('0x2e')](_0x30a6ff[_0xb54b('0x82')](),{'type':db[_0xb54b('0x83')][_0xb54b('0x84')][_0xb54b('0x85')]});}})[_0xb54b('0x21')](function(_0x307512){if(!_0x307512['length']){throw new db[(_0xb54b('0x69'))][(_0xb54b('0x6a'))](_0xb54b('0x8c'),0xcc);}if(_0x3b32dc['output']===_0xb54b('0x8d')){return null;}var _0xb5267a=_['merge'](_0x3b32dc,{'name':_0x3b32dc[_0xb54b('0x8e')]||_0x3b32dc[_0xb54b('0x27')]||_0x1bbd1b['name'],'basename':_0x326dba,'savename':util[_0xb54b('0x74')](_0xb54b('0x8f'),_0x3b32dc[_0xb54b('0x27')]||_0x1bbd1b[_0xb54b('0x27')],require(_0xb54b('0x90'))[_0xb54b('0x91')](0x4),_0x3b32dc['output']||_0xb54b('0x92')),'reportId':_0x1bbd1b['id'],'reportType':_0xb54b('0x93')});return db['AnalyticExtractedReport'][_0xb54b('0x45')](_0xb5267a,{'raw':!![]});})[_0xb54b('0x21')](function(_0x1c678a){if(_0x1bbd1b[_0xb54b('0x6e')]===_0xb54b('0x94')){_0xf41b8e[_0xb54b('0x3a')](_0x1bbd1b[_0xb54b('0x6e')]+_0xb54b('0x95'),_0x3b32dc[_0xb54b('0x96')],_0x3b32dc[_0xb54b('0x97')]);}else{_0xf41b8e[_0xb54b('0x3a')](_0x1bbd1b[_0xb54b('0x6e')]+_0xb54b('0x98'),_0x3b32dc['startDate'],_0x3b32dc['endDate']);}if(_0x1c678a){logger[_0xb54b('0x99')](_0xb54b('0x9a'),_0xf41b8e['toString']());require('child_process')['fork'](path[_0xb54b('0x51')](__dirname,_0xb54b('0x9b'),_0x1c678a[_0xb54b('0x9c')]),[_0x1c678a['id'],_0xf41b8e[_0xb54b('0x82')](),path[_0xb54b('0x51')](__dirname,_0xb54b('0x9d'),_0x1c678a[_0xb54b('0x9e')]),_0x326dba]);return _0x1c678a;}else{var _0x58ac8b=squel['select']();_0x58ac8b[_0xb54b('0x6d')]('('+_0xf41b8e[_0xb54b('0x82')]()+')','countTable');_0x58ac8b[_0xb54b('0x71')](_0xb54b('0x9f'),'count');_0xf41b8e['limit'](_0x3b32dc[_0xb54b('0x1a')]||_0x138faf);_0xf41b8e['offset'](_0x3b32dc[_0xb54b('0x19')]||0x0);return db[_0xb54b('0x83')][_0xb54b('0x2e')](_0x58ac8b[_0xb54b('0x82')](),{'type':db[_0xb54b('0x83')][_0xb54b('0x84')]['SELECT']})[_0xb54b('0x21')](function(_0x2bca00){if(!_0x2bca00[_0xb54b('0x33')]){_0x119584=0x0;}else{_0x119584=_0x2bca00[0x0]['count']||0x0;}return db['sequelize'][_0xb54b('0x2e')](_0xf41b8e[_0xb54b('0x82')](),{'type':db[_0xb54b('0x83')][_0xb54b('0x84')][_0xb54b('0x85')]});})[_0xb54b('0x21')](function(_0x4ac86c){return{'rows':_0x4ac86c||[],'count':_0x119584};});}});}exports[_0xb54b('0xa0')]=function(_0x269eba,_0x51909e){return runReport(_0x269eba[_0xb54b('0x41')],_0x269eba[_0xb54b('0x2e')],_0x269eba[_0xb54b('0x43')])[_0xb54b('0x21')](respondWithResult(_0x51909e,null))[_0xb54b('0x40')](handleError(_0x51909e,null));};exports['runReport']=runReport;exports[_0xb54b('0x2e')]=function(_0x3307d1,_0x3c7ef5){var _0x11bd34=0xa;var _0xf01f59=[_0xb54b('0x51'),_0xb54b('0x86'),_0xb54b('0x52'),_0xb54b('0x53')];var _0x54485d={'SUM':_0xb54b('0x54'),'COUNT':_0xb54b('0x55'),'COUNT DISTINCT':_0xb54b('0x56'),'MAX':_0xb54b('0x57'),'MIN':_0xb54b('0x58'),'AVG':'AVG(%s)','GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0xb54b('0x87'),'GROUP_CONCAT DESC':_0xb54b('0x5b')};var _0x39ff73={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':'DATE(%s)','HOUR':_0xb54b('0x5d'),'ROUND':_0xb54b('0x89'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x2f20c3=function(_0x74aa89){return!_[_0xb54b('0x79')]([_0xb54b('0x5f'),_0xb54b('0x60'),_0xb54b('0x61'),_0xb54b('0x62')],_0x74aa89);};var _0x1b0961=function(_0x1f9c86){if(!_0x1f9c86||!_0x1f9c86[_0xb54b('0x63')][_0xb54b('0x33')]){return'';}for(var _0xf50939='(',_0x4085ce=0x0;_0x4085ce<_0x1f9c86[_0xb54b('0x63')][_0xb54b('0x33')];_0x4085ce+=0x1){_0x4085ce>0x0&&(_0xf50939+='\x20'+_0x1f9c86['operator']+'\x20');_0xf50939+=_0x1f9c86[_0xb54b('0x63')][_0x4085ce][_0xb54b('0x65')]?_0x1b0961(_0x1f9c86[_0xb54b('0x63')][_0x4085ce][_0xb54b('0x65')]):_0x1f9c86[_0xb54b('0x63')][_0x4085ce]['field']+'\x20'+_0x1f9c86[_0xb54b('0x63')][_0x4085ce][_0xb54b('0x66')]+(_0x2f20c3(_0x1f9c86[_0xb54b('0x63')][_0x4085ce][_0xb54b('0x66')])?'\x20'+_0x1f9c86[_0xb54b('0x63')][_0x4085ce][_0xb54b('0x67')]:'');}return _0xf50939+')';};var _0x2b0134={'where':{'id':_0x3307d1[_0xb54b('0x41')]['id']}},_0x53fcec,_0x3c9a21,_0x27290c,_0x4e2daf,_0x28b91f;_0x2b0134=_[_0xb54b('0x3c')]({},_0x2b0134,_0x3307d1[_0xb54b('0x43')]);return db[_0xb54b('0x3d')][_0xb54b('0x44')](_0x2b0134)[_0xb54b('0x21')](function(_0x36b978){if(_0x36b978){_0x53fcec=_0x36b978;return _0x36b978['getFields']();}return null;})[_0xb54b('0x21')](function(_0xfb16c3){if(_0xfb16c3){if(!_0xfb16c3['length']){throw new db[(_0xb54b('0x69'))][(_0xb54b('0x6a'))](_0xb54b('0xa1'),0x193);}_0x3c9a21=_0xfb16c3;return db[_0xb54b('0x8a')][_0xb54b('0x6b')]({'raw':!![]});}return null;})[_0xb54b('0x21')](function(_0x3fa762){if(_0x3fa762){_0x27290c=_[_0xb54b('0x6c')](_0x3fa762,'id');var _0x200b0e;var _0x43c454=squel[_0xb54b('0x8b')]();_0x43c454[_0xb54b('0x6d')](_0x53fcec['table']);for(var _0x5b2452=0x0;_0x5b2452<_0x3c9a21[_0xb54b('0x33')];_0x5b2452+=0x1){_0x200b0e=_0x3c9a21[_0x5b2452][_0xb54b('0x6f')]?_0x27290c[_0x3c9a21[_0x5b2452]['MetricId']][_0xb54b('0x70')]:_0x3c9a21[_0x5b2452][_0xb54b('0x71')];_0x200b0e=_0x3c9a21[_0x5b2452][_0xb54b('0x72')]?_['replace'](_0x54485d[_0x3c9a21[_0x5b2452][_0xb54b('0x72')]],'%s',_0x200b0e):_0x200b0e;_0x200b0e=_0x3c9a21[_0x5b2452][_0xb54b('0x74')]?_['replace'](_0x39ff73[_0x3c9a21[_0x5b2452][_0xb54b('0x74')]],'%s',_0x200b0e):_0x200b0e;if(_0x3c9a21[_0x5b2452]['groupBy']){_0x43c454[_0xb54b('0x65')](_0x200b0e);}_0x3c9a21[_0x5b2452][_0xb54b('0x75')]&&_0x43c454[_0xb54b('0x37')](_0x200b0e,_0x3c9a21[_0x5b2452][_0xb54b('0x75')]==='DESC'?![]:!![]);_0x43c454[_0xb54b('0x71')](_0x200b0e,_0x3c9a21[_0x5b2452][_0xb54b('0x76')]||_0x200b0e);}if(_0x53fcec[_0xb54b('0x77')]){_0x53fcec[_0xb54b('0x77')]=JSON[_0xb54b('0x78')](_0x53fcec[_0xb54b('0x77')]);for(var _0x3e5ee4=0x0;_0x3e5ee4<_0x53fcec[_0xb54b('0x77')][_0xb54b('0x33')];_0x3e5ee4+=0x1){if(_0x53fcec[_0xb54b('0x77')][_0x3e5ee4][_0xb54b('0x2c')]&&_[_0xb54b('0x79')](_0xf01f59,_0x53fcec[_0xb54b('0x77')][_0x3e5ee4]['type'])&&_0x53fcec[_0xb54b('0x77')][_0x3e5ee4][_0xb54b('0x7a')]&&_0x53fcec[_0xb54b('0x77')][_0x3e5ee4][_0xb54b('0x7c')]&&_0x53fcec[_0xb54b('0x77')][_0x3e5ee4][_0xb54b('0x7b')]){_0x43c454[_0x53fcec[_0xb54b('0x77')][_0x3e5ee4]['type']](_0x53fcec[_0xb54b('0x77')][_0x3e5ee4]['foreignTable'],null,util[_0xb54b('0x74')](_0xb54b('0x7d'),_0x53fcec[_0xb54b('0x6e')],_0x53fcec['joins'][_0x3e5ee4][_0xb54b('0x7a')],_0x53fcec[_0xb54b('0x77')][_0x3e5ee4]['foreignTable'],_0x53fcec['joins'][_0x3e5ee4][_0xb54b('0x7b')]));}}}if(_0x53fcec[_0xb54b('0x7e')]){_0x53fcec[_0xb54b('0x7e')]=JSON[_0xb54b('0x78')](_0x53fcec[_0xb54b('0x7e')]);_0x43c454[_0xb54b('0x3a')](_0x1b0961(_0x53fcec[_0xb54b('0x7e')][_0xb54b('0x65')]));}_0x28b91f=_0x43c454[_0xb54b('0x7f')]();_0x43c454[_0xb54b('0x1a')](_0x11bd34);_0x43c454['offset'](0x0);logger['debug'](_0xb54b('0x81'),_0x43c454[_0xb54b('0x82')]());return db[_0xb54b('0x83')]['query'](_0x43c454[_0xb54b('0x82')](),{'type':db[_0xb54b('0x83')][_0xb54b('0x84')]['SELECT']});}})[_0xb54b('0x21')](function(){return{'sql':_0x28b91f[_0xb54b('0x82')]()};})[_0xb54b('0x21')](respondWithResult(_0x3c7ef5,null))['catch'](handleError(_0x3c7ef5,null));};
\ No newline at end of file
+var _0x0b0e=['IS\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','field','condition','value','options','getFields','length','Sequelize','AnalyticMetric','findAll','keyBy','select','table','function','format','groupBy','group','orderBy','DESC','joins','parse','parentKey','foreignTable','%s.%s\x20=\x20%s.%s','conditions','clone','debug','toString','sequelize','QueryTypes','SELECT','GROUP_CONCAT(%s)','UNIX_TIMESTAMP(%s)','IS\x20NOT\x20NULL','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','from','MetricId','metric','alias','foreignKey','output','web','fullPath','%s-%s.%s','custom','cdr','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','startDate','info','Run\x20Query:','child_process','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','runReport','replace','Limited\x20Query:','eml-format','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','dbH','sendStatus','status','end','undefined','limit','count','set','json','apply','update','destroy','UserProfileResource','then','error','stack','name','send','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','nolimit','offset','order','sort','where','filter','merge','VIRTUAL','include','rows','catch','show','includeAll','find','create','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','autoAssociation','CustomReports','body','params','preview','join','left_join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','ROUND(%s)','includes'];(function(_0x278bd7,_0x2b4b52){var _0x56f13b=function(_0x44f3d3){while(--_0x44f3d3){_0x278bd7['push'](_0x278bd7['shift']());}};_0x56f13b(++_0x2b4b52);}(_0x0b0e,0x187));var _0xe0b0=function(_0x3da72b,_0x4fd809){_0x3da72b=_0x3da72b-0x0;var _0xc64ac4=_0x0b0e[_0x3da72b];return _0xc64ac4;};'use strict';var emlformat=require(_0xe0b0('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xe0b0('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xe0b0('0x2'));var moment=require(_0xe0b0('0x3'));var BPromise=require(_0xe0b0('0x4'));var Mustache=require(_0xe0b0('0x5'));var util=require(_0xe0b0('0x6'));var path=require(_0xe0b0('0x7'));var sox=require(_0xe0b0('0x8'));var csv=require(_0xe0b0('0x9'));var ejs=require(_0xe0b0('0xa'));var fs=require('fs');var fs_extra=require(_0xe0b0('0xb'));var _=require(_0xe0b0('0xc'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xe0b0('0xd'));var deskjs=require(_0xe0b0('0xe'));var toCsv=require(_0xe0b0('0x9'));var querystring=require(_0xe0b0('0xf'));var Papa=require('papaparse');var Redis=require(_0xe0b0('0x10'));var authService=require(_0xe0b0('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xe0b0('0x12'));var hardwareService=require(_0xe0b0('0x13'));var logger=require('../../config/logger')(_0xe0b0('0x14'));var utils=require(_0xe0b0('0x15'));var config=require(_0xe0b0('0x16'));var licenseUtil=require('../../config/license/util');var db=require(_0xe0b0('0x17'))['db'];var dbH=require(_0xe0b0('0x17'))[_0xe0b0('0x18')];function respondWithStatusCode(_0x45f914,_0x34fed4){_0x34fed4=_0x34fed4||0xcc;return function(_0x4d2bf7){if(_0x4d2bf7){return _0x45f914[_0xe0b0('0x19')](_0x34fed4);}return _0x45f914[_0xe0b0('0x1a')](_0x34fed4)[_0xe0b0('0x1b')]();};}function respondWithResult(_0x24babd,_0x177c24){_0x177c24=_0x177c24||0xc8;return function(_0x55d884){if(_0x55d884){return _0x24babd[_0xe0b0('0x1a')](_0x177c24)['json'](_0x55d884);}};}function respondWithFilteredResult(_0x35cb40,_0xadee6e){return function(_0x519ae8){if(_0x519ae8){var _0x11fdca=typeof _0xadee6e['offset']===_0xe0b0('0x1c')&&typeof _0xadee6e[_0xe0b0('0x1d')]==='undefined';var _0x54a3eb=_0x519ae8[_0xe0b0('0x1e')];var _0x50a441=_0x11fdca?0x0:_0xadee6e['offset'];var _0x4bce65=_0x11fdca?_0x519ae8[_0xe0b0('0x1e')]:_0xadee6e['offset']+_0xadee6e['limit'];var _0x10cde1;if(_0x4bce65>=_0x54a3eb){_0x4bce65=_0x54a3eb;_0x10cde1=0xc8;}else{_0x10cde1=0xce;}_0x35cb40['status'](_0x10cde1);return _0x35cb40[_0xe0b0('0x1f')]('Content-Range',_0x50a441+'-'+_0x4bce65+'/'+_0x54a3eb)[_0xe0b0('0x20')](_0x519ae8);}return null;};}function patchUpdates(_0x1cd7c4){return function(_0x3e10b3){try{jsonpatch[_0xe0b0('0x21')](_0x3e10b3,_0x1cd7c4,!![]);}catch(_0x2cf6a1){return BPromise['reject'](_0x2cf6a1);}return _0x3e10b3['save']();};}function saveUpdates(_0x2fa820,_0x5512bb){return function(_0x12b260){if(_0x12b260){return _0x12b260[_0xe0b0('0x22')](_0x2fa820)['then'](function(_0x170ad8){return _0x170ad8;});}return null;};}function removeEntity(_0x503883,_0x2208d0){return function(_0x49a727){if(_0x49a727){return _0x49a727[_0xe0b0('0x23')]()['then'](function(){var _0x3e5c88=_0x49a727['get']({'plain':!![]});var _0x4700cc='CustomReports';return db[_0xe0b0('0x24')]['destroy']({'where':{'type':_0x4700cc,'resourceId':_0x3e5c88['id']}})[_0xe0b0('0x25')](function(){return _0x49a727;});})[_0xe0b0('0x25')](function(){_0x503883[_0xe0b0('0x1a')](0xcc)[_0xe0b0('0x1b')]();});}};}function handleEntityNotFound(_0x3ec2,_0x10745d){return function(_0x5200a6){if(!_0x5200a6){_0x3ec2[_0xe0b0('0x19')](0x194);}return _0x5200a6;};}function handleError(_0x1b8aa8,_0x5b7a64){_0x5b7a64=_0x5b7a64||0x1f4;return function(_0x15e13b){logger[_0xe0b0('0x26')](_0x15e13b[_0xe0b0('0x27')]);if(_0x15e13b[_0xe0b0('0x28')]){delete _0x15e13b[_0xe0b0('0x28')];}_0x1b8aa8[_0xe0b0('0x1a')](_0x5b7a64)[_0xe0b0('0x29')](_0x15e13b);};}exports['index']=function(_0x1854b8,_0x3c0109){var _0x48a9b5={},_0x4fe400={},_0x158b7f={'count':0x0,'rows':[]};var _0x33e672=_[_0xe0b0('0x2a')](db[_0xe0b0('0x2b')][_0xe0b0('0x2c')],function(_0x5866e5){return{'name':_0x5866e5[_0xe0b0('0x2d')],'type':_0x5866e5[_0xe0b0('0x2e')][_0xe0b0('0x2f')]};});_0x4fe400[_0xe0b0('0x30')]=_[_0xe0b0('0x2a')](_0x33e672,'name');_0x4fe400[_0xe0b0('0x31')]=_[_0xe0b0('0x32')](_0x1854b8[_0xe0b0('0x31')]);_0x4fe400[_0xe0b0('0x33')]=_[_0xe0b0('0x34')](_0x4fe400[_0xe0b0('0x30')],_0x4fe400[_0xe0b0('0x31')]);_0x48a9b5[_0xe0b0('0x35')]=_[_0xe0b0('0x34')](_0x4fe400[_0xe0b0('0x30')],qs[_0xe0b0('0x36')](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x36')]));_0x48a9b5[_0xe0b0('0x35')]=_0x48a9b5[_0xe0b0('0x35')]['length']?_0x48a9b5[_0xe0b0('0x35')]:_0x4fe400[_0xe0b0('0x30')];if(!_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x37')](_0xe0b0('0x38'))){_0x48a9b5[_0xe0b0('0x1d')]=qs[_0xe0b0('0x1d')](_0x1854b8['query']['limit']);_0x48a9b5['offset']=qs['offset'](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x39')]);}_0x48a9b5[_0xe0b0('0x3a')]=qs['sort'](_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3b')]);_0x48a9b5[_0xe0b0('0x3c')]=qs[_0xe0b0('0x33')](_['pick'](_0x1854b8[_0xe0b0('0x31')],_0x4fe400[_0xe0b0('0x33')]),_0x33e672);if(_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3d')]){_0x48a9b5[_0xe0b0('0x3c')]=_[_0xe0b0('0x3e')](_0x48a9b5[_0xe0b0('0x3c')],{'$or':_[_0xe0b0('0x2a')](_0x33e672,function(_0xeaffbb){if(_0xeaffbb['type']!==_0xe0b0('0x3f')){var _0x54f646={};_0x54f646[_0xeaffbb[_0xe0b0('0x28')]]={'$like':'%'+_0x1854b8[_0xe0b0('0x31')][_0xe0b0('0x3d')]+'%'};return _0x54f646;}})});}_0x48a9b5=_[_0xe0b0('0x3e')]({},_0x48a9b5,_0x1854b8['options']);var _0x3e1b6b={'where':_0x48a9b5[_0xe0b0('0x3c')]};return db[_0xe0b0('0x2b')][_0xe0b0('0x1e')](_0x3e1b6b)[_0xe0b0('0x25')](function(_0x1c12bd){_0x158b7f[_0xe0b0('0x1e')]=_0x1c12bd;if(_0x1854b8[_0xe0b0('0x31')]['includeAll']){_0x48a9b5[_0xe0b0('0x40')]=[{'all':!![]}];}return db[_0xe0b0('0x2b')]['findAll'](_0x48a9b5);})['then'](function(_0x327fb4){_0x158b7f[_0xe0b0('0x41')]=_0x327fb4;return _0x158b7f;})['then'](respondWithFilteredResult(_0x3c0109,_0x48a9b5))[_0xe0b0('0x42')](handleError(_0x3c0109,null));};exports[_0xe0b0('0x43')]=function(_0x6bca5c,_0x1c869d){var _0x1a8cc7={'raw':![],'where':{'id':_0x6bca5c['params']['id']}},_0x5c31b5={};_0x5c31b5['model']=_[_0xe0b0('0x32')](db[_0xe0b0('0x2b')]['rawAttributes']);_0x5c31b5[_0xe0b0('0x31')]=_[_0xe0b0('0x32')](_0x6bca5c[_0xe0b0('0x31')]);_0x5c31b5[_0xe0b0('0x33')]=_[_0xe0b0('0x34')](_0x5c31b5['model'],_0x5c31b5['query']);_0x1a8cc7[_0xe0b0('0x35')]=_[_0xe0b0('0x34')](_0x5c31b5[_0xe0b0('0x30')],qs[_0xe0b0('0x36')](_0x6bca5c[_0xe0b0('0x31')]['fields']));_0x1a8cc7[_0xe0b0('0x35')]=_0x1a8cc7[_0xe0b0('0x35')]['length']?_0x1a8cc7['attributes']:_0x5c31b5['model'];if(_0x6bca5c[_0xe0b0('0x31')][_0xe0b0('0x44')]){_0x1a8cc7[_0xe0b0('0x40')]=[{'all':!![]}];}_0x1a8cc7=_[_0xe0b0('0x3e')]({},_0x1a8cc7,_0x6bca5c['options']);return db[_0xe0b0('0x2b')][_0xe0b0('0x45')](_0x1a8cc7)['then'](handleEntityNotFound(_0x1c869d,null))['then'](respondWithResult(_0x1c869d,null))[_0xe0b0('0x42')](handleError(_0x1c869d,null));};exports[_0xe0b0('0x46')]=function(_0x497f4f,_0x2b1917){return db[_0xe0b0('0x2b')]['create'](_0x497f4f['body'],{})[_0xe0b0('0x25')](function(_0x511679){var _0x165dc8=_0x497f4f[_0xe0b0('0x47')][_0xe0b0('0x48')]({'plain':!![]});if(!_0x165dc8)throw new Error(_0xe0b0('0x49'));if(_0x165dc8[_0xe0b0('0x4a')]===_0xe0b0('0x47')){var _0x5f5486=_0x511679['get']({'plain':!![]});var _0x2ef908='Reports';return db['UserProfileSection'][_0xe0b0('0x45')]({'where':{'name':_0x2ef908,'userProfileId':_0x165dc8[_0xe0b0('0x4b')]},'raw':!![]})['then'](function(_0x4b65d1){if(_0x4b65d1&&_0x4b65d1[_0xe0b0('0x4c')]===0x0){return db[_0xe0b0('0x24')][_0xe0b0('0x46')]({'name':_0x5f5486[_0xe0b0('0x28')],'resourceId':_0x5f5486['id'],'type':_0xe0b0('0x4d'),'sectionId':_0x4b65d1['id']},{})[_0xe0b0('0x25')](function(){return _0x511679;});}else{return _0x511679;}})[_0xe0b0('0x42')](function(_0x4ebb0f){logger[_0xe0b0('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x4ebb0f);throw _0x4ebb0f;});}return _0x511679;})[_0xe0b0('0x25')](respondWithResult(_0x2b1917,0xc9))['catch'](handleError(_0x2b1917,null));};exports['update']=function(_0x33822e,_0x237e8c){if(_0x33822e[_0xe0b0('0x4e')]['id']){delete _0x33822e[_0xe0b0('0x4e')]['id'];}return db[_0xe0b0('0x2b')][_0xe0b0('0x45')]({'where':{'id':_0x33822e[_0xe0b0('0x4f')]['id']}})[_0xe0b0('0x25')](handleEntityNotFound(_0x237e8c,null))[_0xe0b0('0x25')](saveUpdates(_0x33822e['body'],null))[_0xe0b0('0x25')](respondWithResult(_0x237e8c,null))['catch'](handleError(_0x237e8c,null));};exports[_0xe0b0('0x23')]=function(_0x3ae36e,_0x30c4a9){return db[_0xe0b0('0x2b')][_0xe0b0('0x45')]({'where':{'id':_0x3ae36e[_0xe0b0('0x4f')]['id']}})['then'](handleEntityNotFound(_0x30c4a9,null))[_0xe0b0('0x25')](removeEntity(_0x30c4a9,null))[_0xe0b0('0x42')](handleError(_0x30c4a9,null));};exports[_0xe0b0('0x50')]=function(_0x271445,_0x3bb6d6){var _0x3b015e=0xa;var _0x234cb7=[_0xe0b0('0x51'),_0xe0b0('0x52'),_0xe0b0('0x53'),_0xe0b0('0x54')];var _0x18ab99={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':_0xe0b0('0x57'),'MAX':_0xe0b0('0x58'),'MIN':_0xe0b0('0x59'),'AVG':_0xe0b0('0x5a'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x1182dc={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':_0xe0b0('0x5e'),'HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x47dcc4=function(_0x139014){return!_[_0xe0b0('0x61')]([_0xe0b0('0x62'),'IS\x20NOT\x20NULL',_0xe0b0('0x63'),_0xe0b0('0x64')],_0x139014);};var _0x309efb=function(_0x3d820c){if(!_0x3d820c||!_0x3d820c[_0xe0b0('0x65')]['length']){return'';}for(var _0x370f8c='(',_0x242120=0x0;_0x242120<_0x3d820c[_0xe0b0('0x65')]['length'];_0x242120+=0x1){_0x242120>0x0&&(_0x370f8c+='\x20'+_0x3d820c[_0xe0b0('0x66')]+'\x20');_0x370f8c+=_0x3d820c[_0xe0b0('0x65')][_0x242120]['group']?_0x309efb(_0x3d820c[_0xe0b0('0x65')][_0x242120]['group']):_0x3d820c['rules'][_0x242120][_0xe0b0('0x67')]+'\x20'+_0x3d820c['rules'][_0x242120]['condition']+(_0x47dcc4(_0x3d820c[_0xe0b0('0x65')][_0x242120][_0xe0b0('0x68')])?'\x20'+_0x3d820c[_0xe0b0('0x65')][_0x242120][_0xe0b0('0x69')]:'');}return _0x370f8c+')';};var _0x5a7913={'where':{'id':_0x271445[_0xe0b0('0x4f')]['id']}},_0x3679e0,_0x2287a5,_0x3e7fb4,_0x41ec8e,_0x1b29c;_0x5a7913=_[_0xe0b0('0x3e')]({},_0x5a7913,_0x271445[_0xe0b0('0x6a')]);return db['AnalyticCustomReport']['find'](_0x5a7913)[_0xe0b0('0x25')](function(_0x35144f){if(_0x35144f){_0x3679e0=_0x35144f;return _0x35144f[_0xe0b0('0x6b')]();}return null;})['then'](function(_0x49b754){if(_0x49b754){if(!_0x49b754[_0xe0b0('0x6c')]){throw new db[(_0xe0b0('0x6d'))]['ValidationErrorItem']('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x2287a5=_0x49b754;return db[_0xe0b0('0x6e')][_0xe0b0('0x6f')]({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x29175a){if(_0x29175a){_0x3e7fb4=_[_0xe0b0('0x70')](_0x29175a,'id');var _0x15f0f8;var _0x1bc7a6=squel[_0xe0b0('0x71')]();_0x1bc7a6['from'](_0x3679e0[_0xe0b0('0x72')]);for(var _0x12e245=0x0;_0x12e245<_0x2287a5[_0xe0b0('0x6c')];_0x12e245+=0x1){_0x15f0f8=_0x2287a5[_0x12e245]['MetricId']?_0x3e7fb4[_0x2287a5[_0x12e245]['MetricId']]['metric']:_0x2287a5[_0x12e245]['field'];_0x15f0f8=_0x2287a5[_0x12e245]['function']?_['replace'](_0x18ab99[_0x2287a5[_0x12e245][_0xe0b0('0x73')]],'%s',_0x15f0f8):_0x15f0f8;_0x15f0f8=_0x2287a5[_0x12e245]['format']?_['replace'](_0x1182dc[_0x2287a5[_0x12e245][_0xe0b0('0x74')]],'%s',_0x15f0f8):_0x15f0f8;if(_0x2287a5[_0x12e245][_0xe0b0('0x75')]){_0x1bc7a6[_0xe0b0('0x76')](_0x15f0f8);}_0x2287a5[_0x12e245][_0xe0b0('0x77')]&&_0x1bc7a6[_0xe0b0('0x3a')](_0x15f0f8,_0x2287a5[_0x12e245][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x1bc7a6[_0xe0b0('0x67')](_0x15f0f8,_0x2287a5[_0x12e245]['alias']||_0x15f0f8);}if(_0x3679e0[_0xe0b0('0x79')]){_0x3679e0[_0xe0b0('0x79')]=JSON[_0xe0b0('0x7a')](_0x3679e0[_0xe0b0('0x79')]);for(var _0x173ed8=0x0;_0x173ed8<_0x3679e0[_0xe0b0('0x79')][_0xe0b0('0x6c')];_0x173ed8+=0x1){if(_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x2e')]&&_['includes'](_0x234cb7,_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x2e')])&&_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7b')]&&_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x7c')]&&_0x3679e0[_0xe0b0('0x79')][_0x173ed8]['foreignKey']){_0x1bc7a6[_0x3679e0['joins'][_0x173ed8][_0xe0b0('0x2e')]](_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7c')],null,util[_0xe0b0('0x74')](_0xe0b0('0x7d'),_0x3679e0[_0xe0b0('0x72')],_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7b')],_0x3679e0[_0xe0b0('0x79')][_0x173ed8][_0xe0b0('0x7c')],_0x3679e0['joins'][_0x173ed8]['foreignKey']));}}}if(_0x3679e0[_0xe0b0('0x7e')]){_0x3679e0['conditions']=JSON['parse'](_0x3679e0['conditions']);_0x1bc7a6['where'](_0x309efb(_0x3679e0[_0xe0b0('0x7e')]['group']));}_0x1b29c=_0x1bc7a6[_0xe0b0('0x7f')]();_0x1bc7a6[_0xe0b0('0x1d')](_0x3b015e);_0x1bc7a6[_0xe0b0('0x39')](0x0);logger[_0xe0b0('0x80')]('Limited\x20Query:',_0x1bc7a6[_0xe0b0('0x81')]());return dbH[_0xe0b0('0x82')]['query'](_0x1bc7a6[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});}})[_0xe0b0('0x25')](respondWithResult(_0x3bb6d6,null))['catch'](handleError(_0x3bb6d6,null));};function runReport(_0x55d3f8,_0x55aef7,_0x545694){var _0x5c258b=_0x55aef7[_0xe0b0('0x28')];var _0x567e1a=0xa;var _0x3c09af=['join',_0xe0b0('0x52'),_0xe0b0('0x53'),_0xe0b0('0x54')];var _0x380b4c={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0xe0b0('0x85'),'GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x4377f7={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':'DATE(%s)','HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':_0xe0b0('0x86')};var _0xc6090e=function(_0x154e6d){return!_[_0xe0b0('0x61')]([_0xe0b0('0x62'),_0xe0b0('0x87'),_0xe0b0('0x63'),'IS\x20NOT\x20EMPTY'],_0x154e6d);};var _0x589c47=function(_0x6e0e9){if(!_0x6e0e9||!_0x6e0e9[_0xe0b0('0x65')]['length']){return'';}for(var _0x7feff4='(',_0x4593f1=0x0;_0x4593f1<_0x6e0e9[_0xe0b0('0x65')][_0xe0b0('0x6c')];_0x4593f1+=0x1){_0x4593f1>0x0&&(_0x7feff4+='\x20'+_0x6e0e9[_0xe0b0('0x66')]+'\x20');_0x7feff4+=_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x76')]?_0x589c47(_0x6e0e9[_0xe0b0('0x65')][_0x4593f1]['group']):_0x6e0e9['rules'][_0x4593f1]['field']+'\x20'+_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x68')]+(_0xc6090e(_0x6e0e9['rules'][_0x4593f1][_0xe0b0('0x68')])?'\x20'+_0x6e0e9[_0xe0b0('0x65')][_0x4593f1][_0xe0b0('0x69')]:'');}return _0x7feff4+')';};var _0x328832={'where':{'id':_0x55d3f8['id']}},_0x5c45ae,_0x56c4b9,_0x4e1fb1,_0x22029a,_0x266835;_0x328832=_['merge']({},_0x328832,_0x545694);return db[_0xe0b0('0x2b')][_0xe0b0('0x45')](_0x328832)['then'](function(_0x576482){if(_0x576482){_0x5c45ae=_0x576482;return _0x576482[_0xe0b0('0x6b')]();}return null;})['then'](function(_0x251195){if(_0x251195){if(!_0x251195['length']){throw new db[(_0xe0b0('0x6d'))][(_0xe0b0('0x88'))](_0xe0b0('0x89'),0x193);}_0x56c4b9=_0x251195;return db[_0xe0b0('0x6e')][_0xe0b0('0x6f')]({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x434dfa){if(_0x434dfa){_0x4e1fb1=_[_0xe0b0('0x70')](_0x434dfa,'id');var _0xf76449;var _0x48497e=squel[_0xe0b0('0x71')]();_0x48497e[_0xe0b0('0x8a')](_0x5c45ae[_0xe0b0('0x72')]);for(var _0x4e19f4=0x0;_0x4e19f4<_0x56c4b9[_0xe0b0('0x6c')];_0x4e19f4+=0x1){_0xf76449=_0x56c4b9[_0x4e19f4]['MetricId']?_0x4e1fb1[_0x56c4b9[_0x4e19f4][_0xe0b0('0x8b')]][_0xe0b0('0x8c')]:_0x56c4b9[_0x4e19f4]['field'];_0xf76449=_0x56c4b9[_0x4e19f4][_0xe0b0('0x73')]?_['replace'](_0x380b4c[_0x56c4b9[_0x4e19f4]['function']],'%s',_0xf76449):_0xf76449;_0xf76449=_0x56c4b9[_0x4e19f4][_0xe0b0('0x74')]?_['replace'](_0x4377f7[_0x56c4b9[_0x4e19f4]['format']],'%s',_0xf76449):_0xf76449;if(_0x56c4b9[_0x4e19f4][_0xe0b0('0x75')]){_0x48497e[_0xe0b0('0x76')](_0xf76449);}_0x56c4b9[_0x4e19f4][_0xe0b0('0x77')]&&_0x48497e[_0xe0b0('0x3a')](_0xf76449,_0x56c4b9[_0x4e19f4][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x48497e['field'](_0xf76449,_0x56c4b9[_0x4e19f4][_0xe0b0('0x8d')]||_0xf76449);}if(_0x5c45ae[_0xe0b0('0x79')]){_0x5c45ae[_0xe0b0('0x79')]=JSON['parse'](_0x5c45ae[_0xe0b0('0x79')]);for(var _0x447641=0x0;_0x447641<_0x5c45ae['joins']['length'];_0x447641+=0x1){if(_0x5c45ae[_0xe0b0('0x79')][_0x447641]['type']&&_[_0xe0b0('0x61')](_0x3c09af,_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x2e')])&&_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7b')]&&_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')]&&_0x5c45ae['joins'][_0x447641][_0xe0b0('0x8e')]){_0x48497e[_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x2e')]](_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')],null,util['format']('%s.%s\x20=\x20%s.%s',_0x5c45ae[_0xe0b0('0x72')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7b')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x7c')],_0x5c45ae[_0xe0b0('0x79')][_0x447641][_0xe0b0('0x8e')]));}}}if(_0x5c45ae[_0xe0b0('0x7e')]){_0x5c45ae[_0xe0b0('0x7e')]=JSON[_0xe0b0('0x7a')](_0x5c45ae['conditions']);_0x48497e[_0xe0b0('0x3c')](_0x589c47(_0x5c45ae[_0xe0b0('0x7e')][_0xe0b0('0x76')]));}_0x266835=_0x48497e[_0xe0b0('0x7f')]();_0x48497e['limit'](_0x567e1a);_0x48497e[_0xe0b0('0x39')](0x0);return;}})[_0xe0b0('0x25')](function(){if(_0x55aef7[_0xe0b0('0x8f')]===_0xe0b0('0x90')){return null;}var _0x476763=_['merge'](_0x55aef7,{'name':_0x55aef7[_0xe0b0('0x91')]||_0x55aef7['name']||_0x5c45ae[_0xe0b0('0x28')],'basename':_0x5c258b,'savename':util[_0xe0b0('0x74')](_0xe0b0('0x92'),_0x55aef7[_0xe0b0('0x28')]||_0x5c45ae[_0xe0b0('0x28')],require('randomstring')['generate'](0x4),_0x55aef7[_0xe0b0('0x8f')]||'csv'),'reportId':_0x5c45ae['id'],'reportType':_0xe0b0('0x93')});return db['AnalyticExtractedReport'][_0xe0b0('0x46')](_0x476763,{'raw':!![]});})[_0xe0b0('0x25')](function(_0x205c53){if(_0x5c45ae[_0xe0b0('0x72')]===_0xe0b0('0x94')){_0x266835[_0xe0b0('0x3c')](_0x5c45ae[_0xe0b0('0x72')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x55aef7['startDate'],_0x55aef7[_0xe0b0('0x95')]);}else{_0x266835[_0xe0b0('0x3c')](_0x5c45ae[_0xe0b0('0x72')]+_0xe0b0('0x96'),_0x55aef7[_0xe0b0('0x97')],_0x55aef7[_0xe0b0('0x95')]);}if(_0x205c53){logger[_0xe0b0('0x98')](_0xe0b0('0x99'),_0x266835[_0xe0b0('0x81')]());require(_0xe0b0('0x9a'))['fork'](path['join'](__dirname,_0xe0b0('0x9b'),_0x205c53[_0xe0b0('0x8f')]),[_0x205c53['id'],_0x266835[_0xe0b0('0x81')](),path[_0xe0b0('0x51')](__dirname,_0xe0b0('0x9c'),_0x205c53[_0xe0b0('0x9d')]),_0x5c258b]);return _0x205c53;}else{var _0x33b67a=squel['select']();_0x33b67a['from']('('+_0x266835[_0xe0b0('0x81')]()+')',_0xe0b0('0x9e'));_0x33b67a[_0xe0b0('0x67')](_0xe0b0('0x9f'),_0xe0b0('0x1e'));_0x266835[_0xe0b0('0x1d')](_0x55aef7[_0xe0b0('0x1d')]||_0x567e1a);_0x266835[_0xe0b0('0x39')](_0x55aef7[_0xe0b0('0x39')]||0x0);return dbH[_0xe0b0('0x82')]['query'](_0x33b67a[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')]['QueryTypes'][_0xe0b0('0x84')]})[_0xe0b0('0x25')](function(_0x3615f9){if(!_0x3615f9[_0xe0b0('0x6c')]){_0x22029a=0x0;}else{_0x22029a=_0x3615f9[0x0][_0xe0b0('0x1e')]||0x0;}return dbH['sequelize'][_0xe0b0('0x31')](_0x266835[_0xe0b0('0x81')](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});})['then'](function(_0x475404){return{'rows':_0x475404||[],'count':_0x22029a};});}});}exports['run']=function(_0x44e05a,_0x42dfa9){return runReport(_0x44e05a[_0xe0b0('0x4f')],_0x44e05a['query'],_0x44e05a['options'])[_0xe0b0('0x25')](respondWithResult(_0x42dfa9,null))[_0xe0b0('0x42')](handleError(_0x42dfa9,null));};exports[_0xe0b0('0xa0')]=runReport;exports['query']=function(_0x4d372a,_0x5da5eb){var _0x5175e1=0xa;var _0x57694c=['join',_0xe0b0('0x52'),_0xe0b0('0x53'),'cross_join'];var _0x121257={'SUM':_0xe0b0('0x55'),'COUNT':_0xe0b0('0x56'),'COUNT DISTINCT':_0xe0b0('0x57'),'MAX':_0xe0b0('0x58'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0xe0b0('0x85'),'GROUP_CONCAT ASC':_0xe0b0('0x5b'),'GROUP_CONCAT DESC':_0xe0b0('0x5c')};var _0x52dfd8={'SEC_TO_TIME':_0xe0b0('0x5d'),'DATE':_0xe0b0('0x5e'),'HOUR':_0xe0b0('0x5f'),'ROUND':_0xe0b0('0x60'),'UNIX_TIMESTAMP':_0xe0b0('0x86')};var _0x1b8d4a=function(_0x51b616){return!_['includes'](['IS\x20NULL',_0xe0b0('0x87'),_0xe0b0('0x63'),_0xe0b0('0x64')],_0x51b616);};var _0x40809f=function(_0x266cb5){if(!_0x266cb5||!_0x266cb5[_0xe0b0('0x65')][_0xe0b0('0x6c')]){return'';}for(var _0x35f081='(',_0x5e4339=0x0;_0x5e4339<_0x266cb5['rules'][_0xe0b0('0x6c')];_0x5e4339+=0x1){_0x5e4339>0x0&&(_0x35f081+='\x20'+_0x266cb5[_0xe0b0('0x66')]+'\x20');_0x35f081+=_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['group']?_0x40809f(_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x76')]):_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['field']+'\x20'+_0x266cb5[_0xe0b0('0x65')][_0x5e4339]['condition']+(_0x1b8d4a(_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x68')])?'\x20'+_0x266cb5[_0xe0b0('0x65')][_0x5e4339][_0xe0b0('0x69')]:'');}return _0x35f081+')';};var _0x3b133a={'where':{'id':_0x4d372a['params']['id']}},_0x26df60,_0x12e46f,_0x55beb2,_0x287af5,_0xb71713;_0x3b133a=_[_0xe0b0('0x3e')]({},_0x3b133a,_0x4d372a[_0xe0b0('0x6a')]);return db[_0xe0b0('0x2b')]['find'](_0x3b133a)[_0xe0b0('0x25')](function(_0x692a95){if(_0x692a95){_0x26df60=_0x692a95;return _0x692a95[_0xe0b0('0x6b')]();}return null;})['then'](function(_0xed8461){if(_0xed8461){if(!_0xed8461[_0xe0b0('0x6c')]){throw new db[(_0xe0b0('0x6d'))][(_0xe0b0('0x88'))](_0xe0b0('0x89'),0x193);}_0x12e46f=_0xed8461;return db[_0xe0b0('0x6e')]['findAll']({'raw':!![]});}return null;})[_0xe0b0('0x25')](function(_0x701ba){if(_0x701ba){_0x55beb2=_[_0xe0b0('0x70')](_0x701ba,'id');var _0x26315d;var _0x11452e=squel[_0xe0b0('0x71')]();_0x11452e[_0xe0b0('0x8a')](_0x26df60[_0xe0b0('0x72')]);for(var _0xf87779=0x0;_0xf87779<_0x12e46f[_0xe0b0('0x6c')];_0xf87779+=0x1){_0x26315d=_0x12e46f[_0xf87779][_0xe0b0('0x8b')]?_0x55beb2[_0x12e46f[_0xf87779]['MetricId']][_0xe0b0('0x8c')]:_0x12e46f[_0xf87779]['field'];_0x26315d=_0x12e46f[_0xf87779]['function']?_[_0xe0b0('0xa1')](_0x121257[_0x12e46f[_0xf87779][_0xe0b0('0x73')]],'%s',_0x26315d):_0x26315d;_0x26315d=_0x12e46f[_0xf87779]['format']?_[_0xe0b0('0xa1')](_0x52dfd8[_0x12e46f[_0xf87779][_0xe0b0('0x74')]],'%s',_0x26315d):_0x26315d;if(_0x12e46f[_0xf87779][_0xe0b0('0x75')]){_0x11452e[_0xe0b0('0x76')](_0x26315d);}_0x12e46f[_0xf87779][_0xe0b0('0x77')]&&_0x11452e[_0xe0b0('0x3a')](_0x26315d,_0x12e46f[_0xf87779][_0xe0b0('0x77')]===_0xe0b0('0x78')?![]:!![]);_0x11452e[_0xe0b0('0x67')](_0x26315d,_0x12e46f[_0xf87779]['alias']||_0x26315d);}if(_0x26df60[_0xe0b0('0x79')]){_0x26df60[_0xe0b0('0x79')]=JSON[_0xe0b0('0x7a')](_0x26df60[_0xe0b0('0x79')]);for(var _0x48c009=0x0;_0x48c009<_0x26df60['joins'][_0xe0b0('0x6c')];_0x48c009+=0x1){if(_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')]&&_[_0xe0b0('0x61')](_0x57694c,_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')])&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7b')]&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')]&&_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x8e')]){_0x11452e[_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x2e')]](_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')],null,util[_0xe0b0('0x74')](_0xe0b0('0x7d'),_0x26df60[_0xe0b0('0x72')],_0x26df60['joins'][_0x48c009][_0xe0b0('0x7b')],_0x26df60[_0xe0b0('0x79')][_0x48c009][_0xe0b0('0x7c')],_0x26df60['joins'][_0x48c009][_0xe0b0('0x8e')]));}}}if(_0x26df60[_0xe0b0('0x7e')]){_0x26df60[_0xe0b0('0x7e')]=JSON[_0xe0b0('0x7a')](_0x26df60[_0xe0b0('0x7e')]);_0x11452e[_0xe0b0('0x3c')](_0x40809f(_0x26df60[_0xe0b0('0x7e')]['group']));}_0xb71713=_0x11452e[_0xe0b0('0x7f')]();_0x11452e['limit'](_0x5175e1);_0x11452e[_0xe0b0('0x39')](0x0);logger['debug'](_0xe0b0('0xa2'),_0x11452e[_0xe0b0('0x81')]());return dbH['sequelize'][_0xe0b0('0x31')](_0x11452e['toString'](),{'type':dbH[_0xe0b0('0x82')][_0xe0b0('0x83')][_0xe0b0('0x84')]});}})[_0xe0b0('0x25')](function(){return{'sql':_0xb71713[_0xe0b0('0x81')]()};})[_0xe0b0('0x25')](respondWithResult(_0x5da5eb,null))[_0xe0b0('0x42')](handleError(_0x5da5eb,null));};
\ No newline at end of file