Built motion from commit da617fac.|2.6.6
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 8aec0b6..adc3c6a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd388=['length','hasOwnProperty','nolimit','order','sort','where','pick','filter','VIRTUAL','merge','count','rows','catch','params','include','options','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','preview','join','left_join','right_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','SEC_TO_TIME(%s)','DATE(%s)','includes','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','group','field','condition','getFields','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','findAll','select','from','table','MetricId','metric','replace','function','format','groupBy','orderBy','alias','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','clone','toString','sequelize','SELECT','cross_join','AVG(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','ROUND(%s)','UNIX_TIMESTAMP(%s)','IS\x20NULL','operator','value','keyBy','DESC','web','%s-%s.%s','randomstring','generate','output','csv','custom','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','Run\x20Query:','child_process','fork','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','QueryTypes','run','debug','Limited\x20Query:','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','dbH','end','status','json','offset','undefined','limit','set','Content-Range','apply','reject','save','then','get','UserProfileResource','destroy','sendStatus','error','name','index','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields'];(function(_0x5b5a1a,_0x534424){var _0x20af86=function(_0x2f56d8){while(--_0x2f56d8){_0x5b5a1a['push'](_0x5b5a1a['shift']());}};_0x20af86(++_0x534424);}(_0xd388,0x6c));var _0x8d38=function(_0xef6554,_0x1bf141){_0xef6554=_0xef6554-0x0;var _0x5d17d3=_0xd388[_0xef6554];return _0x5d17d3;};'use strict';var emlformat=require(_0x8d38('0x0'));var rimraf=require(_0x8d38('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x8d38('0x2'));var rp=require(_0x8d38('0x3'));var moment=require(_0x8d38('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x8d38('0x5'));var util=require(_0x8d38('0x6'));var path=require('path');var sox=require(_0x8d38('0x7'));var csv=require(_0x8d38('0x8'));var ejs=require(_0x8d38('0x9'));var fs=require('fs');var fs_extra=require(_0x8d38('0xa'));var _=require('lodash');var squel=require(_0x8d38('0xb'));var crypto=require(_0x8d38('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x8d38('0xd'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x8d38('0xe'));var Redis=require(_0x8d38('0xf'));var authService=require(_0x8d38('0x10'));var qs=require(_0x8d38('0x11'));var as=require(_0x8d38('0x12'));var hardwareService=require(_0x8d38('0x13'));var logger=require(_0x8d38('0x14'))(_0x8d38('0x15'));var utils=require(_0x8d38('0x16'));var config=require(_0x8d38('0x17'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var dbH=require(_0x8d38('0x18'))[_0x8d38('0x19')];function respondWithStatusCode(_0x528eee,_0x4ddbf8){_0x4ddbf8=_0x4ddbf8||0xcc;return function(_0x110b84){if(_0x110b84){return _0x528eee['sendStatus'](_0x4ddbf8);}return _0x528eee['status'](_0x4ddbf8)[_0x8d38('0x1a')]();};}function respondWithResult(_0x4cb3ad,_0x5b37dd){_0x5b37dd=_0x5b37dd||0xc8;return function(_0x444e95){if(_0x444e95){return _0x4cb3ad[_0x8d38('0x1b')](_0x5b37dd)[_0x8d38('0x1c')](_0x444e95);}};}function respondWithFilteredResult(_0x24ef09,_0x2b9651){return function(_0x2ae369){if(_0x2ae369){var _0x5c99fe=typeof _0x2b9651[_0x8d38('0x1d')]===_0x8d38('0x1e')&&typeof _0x2b9651[_0x8d38('0x1f')]==='undefined';var _0xce606b=_0x2ae369['count'];var _0x3c3db7=_0x5c99fe?0x0:_0x2b9651['offset'];var _0x3bd55e=_0x5c99fe?_0x2ae369['count']:_0x2b9651[_0x8d38('0x1d')]+_0x2b9651['limit'];var _0x2f5359;if(_0x3bd55e>=_0xce606b){_0x3bd55e=_0xce606b;_0x2f5359=0xc8;}else{_0x2f5359=0xce;}_0x24ef09[_0x8d38('0x1b')](_0x2f5359);return _0x24ef09[_0x8d38('0x20')](_0x8d38('0x21'),_0x3c3db7+'-'+_0x3bd55e+'/'+_0xce606b)[_0x8d38('0x1c')](_0x2ae369);}return null;};}function patchUpdates(_0xbfaade){return function(_0x4149f6){try{jsonpatch[_0x8d38('0x22')](_0x4149f6,_0xbfaade,!![]);}catch(_0x19e3ce){return BPromise[_0x8d38('0x23')](_0x19e3ce);}return _0x4149f6[_0x8d38('0x24')]();};}function saveUpdates(_0x295b4e,_0x259abb){return function(_0xb26881){if(_0xb26881){return _0xb26881['update'](_0x295b4e)[_0x8d38('0x25')](function(_0x457736){return _0x457736;});}return null;};}function removeEntity(_0x5818ac,_0x30c6ca){return function(_0x18cfaf){if(_0x18cfaf){return _0x18cfaf['destroy']()[_0x8d38('0x25')](function(){var _0xd77b2c=_0x18cfaf[_0x8d38('0x26')]({'plain':!![]});var _0xa43cc2='CustomReports';return db[_0x8d38('0x27')][_0x8d38('0x28')]({'where':{'type':_0xa43cc2,'resourceId':_0xd77b2c['id']}})[_0x8d38('0x25')](function(){return _0x18cfaf;});})['then'](function(){_0x5818ac['status'](0xcc)[_0x8d38('0x1a')]();});}};}function handleEntityNotFound(_0x5950f7,_0x41bdb4){return function(_0x254f1b){if(!_0x254f1b){_0x5950f7[_0x8d38('0x29')](0x194);}return _0x254f1b;};}function handleError(_0x4c767b,_0x1e4086){_0x1e4086=_0x1e4086||0x1f4;return function(_0x40ab18){logger[_0x8d38('0x2a')](_0x40ab18['stack']);if(_0x40ab18[_0x8d38('0x2b')]){delete _0x40ab18[_0x8d38('0x2b')];}_0x4c767b['status'](_0x1e4086)['send'](_0x40ab18);};}exports[_0x8d38('0x2c')]=function(_0xa1b71f,_0x2647a7){var _0x3274dd={},_0x42ab4c={},_0x5f1afd={'count':0x0,'rows':[]};var _0x1bc446=_[_0x8d38('0x2d')](db[_0x8d38('0x2e')][_0x8d38('0x2f')],function(_0x273226){return{'name':_0x273226[_0x8d38('0x30')],'type':_0x273226[_0x8d38('0x31')][_0x8d38('0x32')]};});_0x42ab4c[_0x8d38('0x33')]=_[_0x8d38('0x2d')](_0x1bc446,'name');_0x42ab4c[_0x8d38('0x34')]=_[_0x8d38('0x35')](_0xa1b71f[_0x8d38('0x34')]);_0x42ab4c[_0x8d38('0x36')]=_['intersection'](_0x42ab4c[_0x8d38('0x33')],_0x42ab4c[_0x8d38('0x34')]);_0x3274dd[_0x8d38('0x37')]=_[_0x8d38('0x38')](_0x42ab4c[_0x8d38('0x33')],qs[_0x8d38('0x39')](_0xa1b71f[_0x8d38('0x34')][_0x8d38('0x39')]));_0x3274dd[_0x8d38('0x37')]=_0x3274dd[_0x8d38('0x37')][_0x8d38('0x3a')]?_0x3274dd[_0x8d38('0x37')]:_0x42ab4c['model'];if(!_0xa1b71f['query'][_0x8d38('0x3b')](_0x8d38('0x3c'))){_0x3274dd[_0x8d38('0x1f')]=qs[_0x8d38('0x1f')](_0xa1b71f[_0x8d38('0x34')]['limit']);_0x3274dd[_0x8d38('0x1d')]=qs[_0x8d38('0x1d')](_0xa1b71f['query'][_0x8d38('0x1d')]);}_0x3274dd[_0x8d38('0x3d')]=qs[_0x8d38('0x3e')](_0xa1b71f[_0x8d38('0x34')]['sort']);_0x3274dd[_0x8d38('0x3f')]=qs[_0x8d38('0x36')](_[_0x8d38('0x40')](_0xa1b71f[_0x8d38('0x34')],_0x42ab4c[_0x8d38('0x36')]),_0x1bc446);if(_0xa1b71f[_0x8d38('0x34')][_0x8d38('0x41')]){_0x3274dd[_0x8d38('0x3f')]=_['merge'](_0x3274dd[_0x8d38('0x3f')],{'$or':_[_0x8d38('0x2d')](_0x1bc446,function(_0x3d651c){if(_0x3d651c['type']!==_0x8d38('0x42')){var _0x2d4c18={};_0x2d4c18[_0x3d651c[_0x8d38('0x2b')]]={'$like':'%'+_0xa1b71f['query'][_0x8d38('0x41')]+'%'};return _0x2d4c18;}})});}_0x3274dd=_[_0x8d38('0x43')]({},_0x3274dd,_0xa1b71f['options']);var _0x2ade12={'where':_0x3274dd[_0x8d38('0x3f')]};return db[_0x8d38('0x2e')]['count'](_0x2ade12)['then'](function(_0x1f60b1){_0x5f1afd[_0x8d38('0x44')]=_0x1f60b1;if(_0xa1b71f[_0x8d38('0x34')]['includeAll']){_0x3274dd['include']=[{'all':!![]}];}return db[_0x8d38('0x2e')]['findAll'](_0x3274dd);})[_0x8d38('0x25')](function(_0x319ce1){_0x5f1afd[_0x8d38('0x45')]=_0x319ce1;return _0x5f1afd;})['then'](respondWithFilteredResult(_0x2647a7,_0x3274dd))[_0x8d38('0x46')](handleError(_0x2647a7,null));};exports['show']=function(_0xe12a71,_0xc07e0){var _0xa1003a={'raw':![],'where':{'id':_0xe12a71[_0x8d38('0x47')]['id']}},_0x2ac4f8={};_0x2ac4f8[_0x8d38('0x33')]=_[_0x8d38('0x35')](db[_0x8d38('0x2e')][_0x8d38('0x2f')]);_0x2ac4f8['query']=_[_0x8d38('0x35')](_0xe12a71['query']);_0x2ac4f8[_0x8d38('0x36')]=_['intersection'](_0x2ac4f8['model'],_0x2ac4f8[_0x8d38('0x34')]);_0xa1003a[_0x8d38('0x37')]=_['intersection'](_0x2ac4f8['model'],qs[_0x8d38('0x39')](_0xe12a71[_0x8d38('0x34')][_0x8d38('0x39')]));_0xa1003a[_0x8d38('0x37')]=_0xa1003a[_0x8d38('0x37')][_0x8d38('0x3a')]?_0xa1003a['attributes']:_0x2ac4f8[_0x8d38('0x33')];if(_0xe12a71[_0x8d38('0x34')]['includeAll']){_0xa1003a[_0x8d38('0x48')]=[{'all':!![]}];}_0xa1003a=_[_0x8d38('0x43')]({},_0xa1003a,_0xe12a71[_0x8d38('0x49')]);return db[_0x8d38('0x2e')][_0x8d38('0x4a')](_0xa1003a)['then'](handleEntityNotFound(_0xc07e0,null))[_0x8d38('0x25')](respondWithResult(_0xc07e0,null))['catch'](handleError(_0xc07e0,null));};exports['create']=function(_0xb07b0d,_0x427279){return db['AnalyticCustomReport'][_0x8d38('0x4b')](_0xb07b0d[_0x8d38('0x4c')],{})[_0x8d38('0x25')](function(_0x183816){var _0x41fd13=_0xb07b0d[_0x8d38('0x4d')][_0x8d38('0x26')]({'plain':!![]});if(!_0x41fd13)throw new Error(_0x8d38('0x4e'));if(_0x41fd13[_0x8d38('0x4f')]==='user'){var _0xc3675c=_0x183816['get']({'plain':!![]});var _0x3d36de='Reports';return db[_0x8d38('0x50')][_0x8d38('0x4a')]({'where':{'name':_0x3d36de,'userProfileId':_0x41fd13[_0x8d38('0x51')]},'raw':!![]})[_0x8d38('0x25')](function(_0x481433){if(_0x481433&&_0x481433[_0x8d38('0x52')]===0x0){return db[_0x8d38('0x27')][_0x8d38('0x4b')]({'name':_0xc3675c['name'],'resourceId':_0xc3675c['id'],'type':'CustomReports','sectionId':_0x481433['id']},{})[_0x8d38('0x25')](function(){return _0x183816;});}else{return _0x183816;}})[_0x8d38('0x46')](function(_0x29aef7){logger[_0x8d38('0x2a')](_0x8d38('0x53'),_0x29aef7);throw _0x29aef7;});}return _0x183816;})['then'](respondWithResult(_0x427279,0xc9))[_0x8d38('0x46')](handleError(_0x427279,null));};exports[_0x8d38('0x54')]=function(_0x3cf15b,_0x3e4615){if(_0x3cf15b[_0x8d38('0x4c')]['id']){delete _0x3cf15b[_0x8d38('0x4c')]['id'];}return db[_0x8d38('0x2e')][_0x8d38('0x4a')]({'where':{'id':_0x3cf15b[_0x8d38('0x47')]['id']}})['then'](handleEntityNotFound(_0x3e4615,null))['then'](saveUpdates(_0x3cf15b[_0x8d38('0x4c')],null))[_0x8d38('0x25')](respondWithResult(_0x3e4615,null))[_0x8d38('0x46')](handleError(_0x3e4615,null));};exports[_0x8d38('0x28')]=function(_0x83010,_0x4fb6e9){return db['AnalyticCustomReport']['find']({'where':{'id':_0x83010['params']['id']}})[_0x8d38('0x25')](handleEntityNotFound(_0x4fb6e9,null))[_0x8d38('0x25')](removeEntity(_0x4fb6e9,null))[_0x8d38('0x46')](handleError(_0x4fb6e9,null));};exports[_0x8d38('0x55')]=function(_0x1cc440,_0x29aee4){var _0x8a6fdd=0xa;var _0x329cd2=[_0x8d38('0x56'),_0x8d38('0x57'),_0x8d38('0x58'),'cross_join'];var _0x47a6b2={'SUM':_0x8d38('0x59'),'COUNT':_0x8d38('0x5a'),'COUNT DISTINCT':_0x8d38('0x5b'),'MAX':_0x8d38('0x5c'),'MIN':_0x8d38('0x5d'),'AVG':'AVG(%s)','GROUP_CONCAT':_0x8d38('0x5e'),'GROUP_CONCAT ASC':_0x8d38('0x5f'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x434198={'SEC_TO_TIME':_0x8d38('0x60'),'DATE':_0x8d38('0x61'),'HOUR':'HOUR(%s)','ROUND':'ROUND(%s)','UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x5e64aa=function(_0x441508){return!_[_0x8d38('0x62')](['IS\x20NULL',_0x8d38('0x63'),_0x8d38('0x64'),_0x8d38('0x65')],_0x441508);};var _0x4e1863=function(_0x43ab96){if(!_0x43ab96||!_0x43ab96['rules']['length']){return'';}for(var _0x3fba3c='(',_0x576aaf=0x0;_0x576aaf<_0x43ab96[_0x8d38('0x66')]['length'];_0x576aaf+=0x1){_0x576aaf>0x0&&(_0x3fba3c+='\x20'+_0x43ab96['operator']+'\x20');_0x3fba3c+=_0x43ab96[_0x8d38('0x66')][_0x576aaf][_0x8d38('0x67')]?_0x4e1863(_0x43ab96['rules'][_0x576aaf][_0x8d38('0x67')]):_0x43ab96['rules'][_0x576aaf][_0x8d38('0x68')]+'\x20'+_0x43ab96[_0x8d38('0x66')][_0x576aaf]['condition']+(_0x5e64aa(_0x43ab96[_0x8d38('0x66')][_0x576aaf][_0x8d38('0x69')])?'\x20'+_0x43ab96['rules'][_0x576aaf]['value']:'');}return _0x3fba3c+')';};var _0x4646e1={'where':{'id':_0x1cc440['params']['id']}},_0x488b63,_0x8952b0,_0x5b6f11,_0x19d985,_0x579050;_0x4646e1=_[_0x8d38('0x43')]({},_0x4646e1,_0x1cc440[_0x8d38('0x49')]);return db['AnalyticCustomReport'][_0x8d38('0x4a')](_0x4646e1)[_0x8d38('0x25')](function(_0x1746e9){if(_0x1746e9){_0x488b63=_0x1746e9;return _0x1746e9[_0x8d38('0x6a')]();}return null;})[_0x8d38('0x25')](function(_0x149e93){if(_0x149e93){if(!_0x149e93[_0x8d38('0x3a')]){throw new db['Sequelize'][(_0x8d38('0x6b'))](_0x8d38('0x6c'),0x193);}_0x8952b0=_0x149e93;return db[_0x8d38('0x6d')][_0x8d38('0x6e')]({'raw':!![]});}return null;})[_0x8d38('0x25')](function(_0x33d942){if(_0x33d942){_0x5b6f11=_['keyBy'](_0x33d942,'id');var _0x546d5d;var _0x29c1ae=squel[_0x8d38('0x6f')]();_0x29c1ae[_0x8d38('0x70')](_0x488b63[_0x8d38('0x71')]);for(var _0x3a3c02=0x0;_0x3a3c02<_0x8952b0['length'];_0x3a3c02+=0x1){_0x546d5d=_0x8952b0[_0x3a3c02][_0x8d38('0x72')]?_0x5b6f11[_0x8952b0[_0x3a3c02]['MetricId']][_0x8d38('0x73')]:_0x8952b0[_0x3a3c02][_0x8d38('0x68')];_0x546d5d=_0x8952b0[_0x3a3c02]['function']?_[_0x8d38('0x74')](_0x47a6b2[_0x8952b0[_0x3a3c02][_0x8d38('0x75')]],'%s',_0x546d5d):_0x546d5d;_0x546d5d=_0x8952b0[_0x3a3c02][_0x8d38('0x76')]?_[_0x8d38('0x74')](_0x434198[_0x8952b0[_0x3a3c02][_0x8d38('0x76')]],'%s',_0x546d5d):_0x546d5d;if(_0x8952b0[_0x3a3c02][_0x8d38('0x77')]){_0x29c1ae[_0x8d38('0x67')](_0x546d5d);}_0x8952b0[_0x3a3c02][_0x8d38('0x78')]&&_0x29c1ae[_0x8d38('0x3d')](_0x546d5d,_0x8952b0[_0x3a3c02][_0x8d38('0x78')]==='DESC'?![]:!![]);_0x29c1ae['field'](_0x546d5d,_0x8952b0[_0x3a3c02][_0x8d38('0x79')]||_0x546d5d);}if(_0x488b63[_0x8d38('0x7a')]){_0x488b63['joins']=JSON[_0x8d38('0x7b')](_0x488b63[_0x8d38('0x7a')]);for(var _0x37c1a6=0x0;_0x37c1a6<_0x488b63[_0x8d38('0x7a')][_0x8d38('0x3a')];_0x37c1a6+=0x1){if(_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x31')]&&_['includes'](_0x329cd2,_0x488b63[_0x8d38('0x7a')][_0x37c1a6]['type'])&&_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7c')]&&_0x488b63['joins'][_0x37c1a6][_0x8d38('0x7d')]&&_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7e')]){_0x29c1ae[_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x31')]](_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7d')],null,util[_0x8d38('0x76')](_0x8d38('0x7f'),_0x488b63[_0x8d38('0x71')],_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7c')],_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7d')],_0x488b63[_0x8d38('0x7a')][_0x37c1a6][_0x8d38('0x7e')]));}}}if(_0x488b63['conditions']){_0x488b63[_0x8d38('0x80')]=JSON[_0x8d38('0x7b')](_0x488b63[_0x8d38('0x80')]);_0x29c1ae[_0x8d38('0x3f')](_0x4e1863(_0x488b63[_0x8d38('0x80')]['group']));}_0x579050=_0x29c1ae[_0x8d38('0x81')]();_0x29c1ae[_0x8d38('0x1f')](_0x8a6fdd);_0x29c1ae[_0x8d38('0x1d')](0x0);logger['debug']('Limited\x20Query:',_0x29c1ae[_0x8d38('0x82')]());return dbH[_0x8d38('0x83')][_0x8d38('0x34')](_0x29c1ae[_0x8d38('0x82')](),{'type':dbH['sequelize']['QueryTypes'][_0x8d38('0x84')]});}})[_0x8d38('0x25')](respondWithResult(_0x29aee4,null))[_0x8d38('0x46')](handleError(_0x29aee4,null));};function runReport(_0x5eae48,_0x5d9654,_0x17f15d){var _0x429711=_0x5d9654[_0x8d38('0x2b')];var _0x24efbe=0xa;var _0x438b4f=[_0x8d38('0x56'),_0x8d38('0x57'),_0x8d38('0x58'),_0x8d38('0x85')];var _0x4419bb={'SUM':'SUM(%s)','COUNT':_0x8d38('0x5a'),'COUNT DISTINCT':_0x8d38('0x5b'),'MAX':_0x8d38('0x5c'),'MIN':'MIN(%s)','AVG':_0x8d38('0x86'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x8d38('0x5f'),'GROUP_CONCAT DESC':_0x8d38('0x87')};var _0x25b323={'SEC_TO_TIME':_0x8d38('0x60'),'DATE':_0x8d38('0x61'),'HOUR':'HOUR(%s)','ROUND':_0x8d38('0x88'),'UNIX_TIMESTAMP':_0x8d38('0x89')};var _0x3d924e=function(_0x42ed60){return!_[_0x8d38('0x62')]([_0x8d38('0x8a'),'IS\x20NOT\x20NULL',_0x8d38('0x64'),_0x8d38('0x65')],_0x42ed60);};var _0x3a50bd=function(_0x5a12b5){if(!_0x5a12b5||!_0x5a12b5[_0x8d38('0x66')]['length']){return'';}for(var _0x5f1c36='(',_0x14307a=0x0;_0x14307a<_0x5a12b5[_0x8d38('0x66')][_0x8d38('0x3a')];_0x14307a+=0x1){_0x14307a>0x0&&(_0x5f1c36+='\x20'+_0x5a12b5[_0x8d38('0x8b')]+'\x20');_0x5f1c36+=_0x5a12b5[_0x8d38('0x66')][_0x14307a][_0x8d38('0x67')]?_0x3a50bd(_0x5a12b5['rules'][_0x14307a][_0x8d38('0x67')]):_0x5a12b5[_0x8d38('0x66')][_0x14307a]['field']+'\x20'+_0x5a12b5[_0x8d38('0x66')][_0x14307a]['condition']+(_0x3d924e(_0x5a12b5['rules'][_0x14307a][_0x8d38('0x69')])?'\x20'+_0x5a12b5[_0x8d38('0x66')][_0x14307a][_0x8d38('0x8c')]:'');}return _0x5f1c36+')';};var _0x51aa93={'where':{'id':_0x5eae48['id']}},_0xd2018d,_0x4f7a00,_0xc423e0,_0xc5f183,_0x356efa;_0x51aa93=_[_0x8d38('0x43')]({},_0x51aa93,_0x17f15d);return db[_0x8d38('0x2e')]['find'](_0x51aa93)[_0x8d38('0x25')](function(_0x571ef7){if(_0x571ef7){_0xd2018d=_0x571ef7;return _0x571ef7[_0x8d38('0x6a')]();}return null;})['then'](function(_0x15ec44){if(_0x15ec44){if(!_0x15ec44[_0x8d38('0x3a')]){throw new db['Sequelize'][(_0x8d38('0x6b'))](_0x8d38('0x6c'),0x193);}_0x4f7a00=_0x15ec44;return db[_0x8d38('0x6d')][_0x8d38('0x6e')]({'raw':!![]});}return null;})['then'](function(_0x3d653c){if(_0x3d653c){_0xc423e0=_[_0x8d38('0x8d')](_0x3d653c,'id');var _0x30c291;var _0x5e7b07=squel[_0x8d38('0x6f')]();_0x5e7b07[_0x8d38('0x70')](_0xd2018d[_0x8d38('0x71')]);for(var _0x36a7be=0x0;_0x36a7be<_0x4f7a00[_0x8d38('0x3a')];_0x36a7be+=0x1){_0x30c291=_0x4f7a00[_0x36a7be]['MetricId']?_0xc423e0[_0x4f7a00[_0x36a7be][_0x8d38('0x72')]]['metric']:_0x4f7a00[_0x36a7be][_0x8d38('0x68')];_0x30c291=_0x4f7a00[_0x36a7be]['function']?_[_0x8d38('0x74')](_0x4419bb[_0x4f7a00[_0x36a7be][_0x8d38('0x75')]],'%s',_0x30c291):_0x30c291;_0x30c291=_0x4f7a00[_0x36a7be]['format']?_[_0x8d38('0x74')](_0x25b323[_0x4f7a00[_0x36a7be][_0x8d38('0x76')]],'%s',_0x30c291):_0x30c291;if(_0x4f7a00[_0x36a7be][_0x8d38('0x77')]){_0x5e7b07[_0x8d38('0x67')](_0x30c291);}_0x4f7a00[_0x36a7be][_0x8d38('0x78')]&&_0x5e7b07['order'](_0x30c291,_0x4f7a00[_0x36a7be]['orderBy']===_0x8d38('0x8e')?![]:!![]);_0x5e7b07[_0x8d38('0x68')](_0x30c291,_0x4f7a00[_0x36a7be][_0x8d38('0x79')]||_0x30c291);}if(_0xd2018d['joins']){_0xd2018d[_0x8d38('0x7a')]=JSON[_0x8d38('0x7b')](_0xd2018d[_0x8d38('0x7a')]);for(var _0x43765e=0x0;_0x43765e<_0xd2018d[_0x8d38('0x7a')]['length'];_0x43765e+=0x1){if(_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x31')]&&_[_0x8d38('0x62')](_0x438b4f,_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x31')])&&_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7c')]&&_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7d')]&&_0xd2018d[_0x8d38('0x7a')][_0x43765e]['foreignKey']){_0x5e7b07[_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x31')]](_0xd2018d[_0x8d38('0x7a')][_0x43765e]['foreignTable'],null,util[_0x8d38('0x76')]('%s.%s\x20=\x20%s.%s',_0xd2018d[_0x8d38('0x71')],_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7c')],_0xd2018d[_0x8d38('0x7a')][_0x43765e]['foreignTable'],_0xd2018d[_0x8d38('0x7a')][_0x43765e][_0x8d38('0x7e')]));}}}if(_0xd2018d[_0x8d38('0x80')]){_0xd2018d[_0x8d38('0x80')]=JSON[_0x8d38('0x7b')](_0xd2018d[_0x8d38('0x80')]);_0x5e7b07[_0x8d38('0x3f')](_0x3a50bd(_0xd2018d['conditions'][_0x8d38('0x67')]));}_0x356efa=_0x5e7b07[_0x8d38('0x81')]();_0x5e7b07['limit'](_0x24efbe);_0x5e7b07[_0x8d38('0x1d')](0x0);return;}})[_0x8d38('0x25')](function(){if(_0x5d9654['output']===_0x8d38('0x8f')){return null;}var _0xd59734=_[_0x8d38('0x43')](_0x5d9654,{'name':_0x5d9654['fullPath']||_0x5d9654[_0x8d38('0x2b')]||_0xd2018d[_0x8d38('0x2b')],'basename':_0x429711,'savename':util[_0x8d38('0x76')](_0x8d38('0x90'),_0x5d9654['name']||_0xd2018d[_0x8d38('0x2b')],require(_0x8d38('0x91'))[_0x8d38('0x92')](0x4),_0x5d9654[_0x8d38('0x93')]||_0x8d38('0x94')),'reportId':_0xd2018d['id'],'reportType':_0x8d38('0x95')});return db['AnalyticExtractedReport'][_0x8d38('0x4b')](_0xd59734,{'raw':!![]});})['then'](function(_0x178f52){if(_0xd2018d[_0x8d38('0x71')]===_0x8d38('0x96')){_0x356efa[_0x8d38('0x3f')](_0xd2018d[_0x8d38('0x71')]+_0x8d38('0x97'),_0x5d9654[_0x8d38('0x98')],_0x5d9654[_0x8d38('0x99')]);}else{_0x356efa['where'](_0xd2018d['table']+'.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x5d9654[_0x8d38('0x98')],_0x5d9654[_0x8d38('0x99')]);}if(_0x178f52){logger['info'](_0x8d38('0x9a'),_0x356efa[_0x8d38('0x82')]());require(_0x8d38('0x9b'))[_0x8d38('0x9c')](path[_0x8d38('0x56')](__dirname,_0x8d38('0x9d'),_0x178f52[_0x8d38('0x93')]),[_0x178f52['id'],_0x356efa[_0x8d38('0x82')](),path[_0x8d38('0x56')](__dirname,_0x8d38('0x9e'),_0x178f52[_0x8d38('0x9f')]),_0x429711]);return _0x178f52;}else{var _0x1429de=squel[_0x8d38('0x6f')]();_0x1429de[_0x8d38('0x70')]('('+_0x356efa['toString']()+')',_0x8d38('0xa0'));_0x1429de[_0x8d38('0x68')](_0x8d38('0xa1'),'count');_0x356efa['limit'](_0x5d9654[_0x8d38('0x1f')]||_0x24efbe);_0x356efa[_0x8d38('0x1d')](_0x5d9654[_0x8d38('0x1d')]||0x0);return dbH['sequelize'][_0x8d38('0x34')](_0x1429de[_0x8d38('0x82')](),{'type':dbH[_0x8d38('0x83')][_0x8d38('0xa2')][_0x8d38('0x84')]})[_0x8d38('0x25')](function(_0x27cca0){if(!_0x27cca0[_0x8d38('0x3a')]){_0xc5f183=0x0;}else{_0xc5f183=_0x27cca0[0x0][_0x8d38('0x44')]||0x0;}return dbH['sequelize'][_0x8d38('0x34')](_0x356efa[_0x8d38('0x82')](),{'type':dbH[_0x8d38('0x83')]['QueryTypes'][_0x8d38('0x84')]});})[_0x8d38('0x25')](function(_0x3c02b1){return{'rows':_0x3c02b1||[],'count':_0xc5f183};});}});}exports[_0x8d38('0xa3')]=function(_0x514fec,_0x2ef97c){return runReport(_0x514fec['params'],_0x514fec['query'],_0x514fec[_0x8d38('0x49')])['then'](respondWithResult(_0x2ef97c,null))[_0x8d38('0x46')](handleError(_0x2ef97c,null));};exports['runReport']=runReport;exports['query']=function(_0x52a82d,_0x2d54ea){var _0x1cbd07=0xa;var _0x128b4a=[_0x8d38('0x56'),_0x8d38('0x57'),_0x8d38('0x58'),'cross_join'];var _0x3547b8={'SUM':_0x8d38('0x59'),'COUNT':_0x8d38('0x5a'),'COUNT DISTINCT':_0x8d38('0x5b'),'MAX':_0x8d38('0x5c'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0x8d38('0x5e'),'GROUP_CONCAT ASC':_0x8d38('0x5f'),'GROUP_CONCAT DESC':_0x8d38('0x87')};var _0x6d91b0={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x8d38('0x61'),'HOUR':'HOUR(%s)','ROUND':_0x8d38('0x88'),'UNIX_TIMESTAMP':_0x8d38('0x89')};var _0x5a9bc5=function(_0x40beab){return!_[_0x8d38('0x62')](['IS\x20NULL',_0x8d38('0x63'),_0x8d38('0x64'),'IS\x20NOT\x20EMPTY'],_0x40beab);};var _0x1b734c=function(_0x33b04e){if(!_0x33b04e||!_0x33b04e[_0x8d38('0x66')][_0x8d38('0x3a')]){return'';}for(var _0x3bfd5e='(',_0x45ce56=0x0;_0x45ce56<_0x33b04e[_0x8d38('0x66')]['length'];_0x45ce56+=0x1){_0x45ce56>0x0&&(_0x3bfd5e+='\x20'+_0x33b04e[_0x8d38('0x8b')]+'\x20');_0x3bfd5e+=_0x33b04e[_0x8d38('0x66')][_0x45ce56]['group']?_0x1b734c(_0x33b04e['rules'][_0x45ce56][_0x8d38('0x67')]):_0x33b04e['rules'][_0x45ce56][_0x8d38('0x68')]+'\x20'+_0x33b04e[_0x8d38('0x66')][_0x45ce56][_0x8d38('0x69')]+(_0x5a9bc5(_0x33b04e[_0x8d38('0x66')][_0x45ce56][_0x8d38('0x69')])?'\x20'+_0x33b04e[_0x8d38('0x66')][_0x45ce56][_0x8d38('0x8c')]:'');}return _0x3bfd5e+')';};var _0x186bfd={'where':{'id':_0x52a82d['params']['id']}},_0x35d334,_0x134290,_0x517d40,_0x3adeee,_0x51f5ec;_0x186bfd=_[_0x8d38('0x43')]({},_0x186bfd,_0x52a82d['options']);return db[_0x8d38('0x2e')][_0x8d38('0x4a')](_0x186bfd)[_0x8d38('0x25')](function(_0x3b904e){if(_0x3b904e){_0x35d334=_0x3b904e;return _0x3b904e[_0x8d38('0x6a')]();}return null;})[_0x8d38('0x25')](function(_0x3a0aa6){if(_0x3a0aa6){if(!_0x3a0aa6[_0x8d38('0x3a')]){throw new db['Sequelize'][(_0x8d38('0x6b'))](_0x8d38('0x6c'),0x193);}_0x134290=_0x3a0aa6;return db[_0x8d38('0x6d')]['findAll']({'raw':!![]});}return null;})[_0x8d38('0x25')](function(_0x4fbe3f){if(_0x4fbe3f){_0x517d40=_[_0x8d38('0x8d')](_0x4fbe3f,'id');var _0x8c51cd;var _0x1b4268=squel['select']();_0x1b4268['from'](_0x35d334[_0x8d38('0x71')]);for(var _0x5e5977=0x0;_0x5e5977<_0x134290[_0x8d38('0x3a')];_0x5e5977+=0x1){_0x8c51cd=_0x134290[_0x5e5977][_0x8d38('0x72')]?_0x517d40[_0x134290[_0x5e5977][_0x8d38('0x72')]][_0x8d38('0x73')]:_0x134290[_0x5e5977][_0x8d38('0x68')];_0x8c51cd=_0x134290[_0x5e5977][_0x8d38('0x75')]?_[_0x8d38('0x74')](_0x3547b8[_0x134290[_0x5e5977][_0x8d38('0x75')]],'%s',_0x8c51cd):_0x8c51cd;_0x8c51cd=_0x134290[_0x5e5977][_0x8d38('0x76')]?_['replace'](_0x6d91b0[_0x134290[_0x5e5977][_0x8d38('0x76')]],'%s',_0x8c51cd):_0x8c51cd;if(_0x134290[_0x5e5977][_0x8d38('0x77')]){_0x1b4268[_0x8d38('0x67')](_0x8c51cd);}_0x134290[_0x5e5977][_0x8d38('0x78')]&&_0x1b4268['order'](_0x8c51cd,_0x134290[_0x5e5977][_0x8d38('0x78')]===_0x8d38('0x8e')?![]:!![]);_0x1b4268[_0x8d38('0x68')](_0x8c51cd,_0x134290[_0x5e5977][_0x8d38('0x79')]||_0x8c51cd);}if(_0x35d334[_0x8d38('0x7a')]){_0x35d334['joins']=JSON[_0x8d38('0x7b')](_0x35d334[_0x8d38('0x7a')]);for(var _0x76491b=0x0;_0x76491b<_0x35d334[_0x8d38('0x7a')][_0x8d38('0x3a')];_0x76491b+=0x1){if(_0x35d334['joins'][_0x76491b][_0x8d38('0x31')]&&_['includes'](_0x128b4a,_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x31')])&&_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7c')]&&_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7d')]&&_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7e')]){_0x1b4268[_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x31')]](_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7d')],null,util[_0x8d38('0x76')](_0x8d38('0x7f'),_0x35d334[_0x8d38('0x71')],_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7c')],_0x35d334[_0x8d38('0x7a')][_0x76491b][_0x8d38('0x7d')],_0x35d334['joins'][_0x76491b][_0x8d38('0x7e')]));}}}if(_0x35d334[_0x8d38('0x80')]){_0x35d334['conditions']=JSON[_0x8d38('0x7b')](_0x35d334['conditions']);_0x1b4268['where'](_0x1b734c(_0x35d334['conditions'][_0x8d38('0x67')]));}_0x51f5ec=_0x1b4268[_0x8d38('0x81')]();_0x1b4268[_0x8d38('0x1f')](_0x1cbd07);_0x1b4268['offset'](0x0);logger[_0x8d38('0xa4')](_0x8d38('0xa5'),_0x1b4268[_0x8d38('0x82')]());return dbH[_0x8d38('0x83')]['query'](_0x1b4268['toString'](),{'type':dbH[_0x8d38('0x83')]['QueryTypes'][_0x8d38('0x84')]});}})[_0x8d38('0x25')](function(){return{'sql':_0x51f5ec[_0x8d38('0x82')]()};})[_0x8d38('0x25')](respondWithResult(_0x2d54ea,null))[_0x8d38('0x46')](handleError(_0x2d54ea,null));};
\ No newline at end of file
+var _0x29ae=['rules','operator','group','field','condition','value','getFields','Sequelize','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','findAll','keyBy','select','from','table','MetricId','metric','function','replace','format','groupBy','orderBy','alias','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','debug','Limited\x20Query:','toString','sequelize','SELECT','SUM(%s)','ROUND(%s)','ValidationErrorItem','output','web','fullPath','%s-%s.%s','randomstring','generate','csv','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','../../components/export/','countTable','COUNT(*)','QueryTypes','run','runReport','left_join','MAX(%s)','DESC','clone','rimraf','moment','bluebird','mustache','util','path','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/license/util','../../mysqldb','dbH','sendStatus','status','end','undefined','limit','count','offset','set','Content-Range','json','apply','reject','then','destroy','get','CustomReports','stack','name','send','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','keys','filters','intersection','model','query','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','rows','catch','show','params','include','options','find','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Reports','userProfileId','autoAssociation','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','preview','join','right_join','cross_join','COUNT(%s)','COUNT(DISTINCT\x20%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY'];(function(_0x5d6456,_0x58ecc7){var _0x4d66c1=function(_0x4335e3){while(--_0x4335e3){_0x5d6456['push'](_0x5d6456['shift']());}};_0x4d66c1(++_0x58ecc7);}(_0x29ae,0x17e));var _0xe29a=function(_0x2da9fb,_0x3af2d0){_0x2da9fb=_0x2da9fb-0x0;var _0x5345a5=_0x29ae[_0x2da9fb];return _0x5345a5;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xe29a('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xe29a('0x1'));var BPromise=require(_0xe29a('0x2'));var Mustache=require(_0xe29a('0x3'));var util=require(_0xe29a('0x4'));var path=require(_0xe29a('0x5'));var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xe29a('0x6'));var squel=require(_0xe29a('0x7'));var crypto=require(_0xe29a('0x8'));var jsforce=require(_0xe29a('0x9'));var deskjs=require(_0xe29a('0xa'));var toCsv=require(_0xe29a('0xb'));var querystring=require(_0xe29a('0xc'));var Papa=require(_0xe29a('0xd'));var Redis=require(_0xe29a('0xe'));var authService=require(_0xe29a('0xf'));var qs=require(_0xe29a('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xe29a('0x11'));var logger=require('../../config/logger')(_0xe29a('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0xe29a('0x13'));var db=require(_0xe29a('0x14'))['db'];var dbH=require('../../mysqldb')[_0xe29a('0x15')];function respondWithStatusCode(_0x356e36,_0x599402){_0x599402=_0x599402||0xcc;return function(_0x5993de){if(_0x5993de){return _0x356e36[_0xe29a('0x16')](_0x599402);}return _0x356e36[_0xe29a('0x17')](_0x599402)[_0xe29a('0x18')]();};}function respondWithResult(_0x4d7a36,_0x2d609a){_0x2d609a=_0x2d609a||0xc8;return function(_0xbb8ab2){if(_0xbb8ab2){return _0x4d7a36[_0xe29a('0x17')](_0x2d609a)['json'](_0xbb8ab2);}};}function respondWithFilteredResult(_0x4599c2,_0x89a241){return function(_0x1a527d){if(_0x1a527d){var _0x3d178f=typeof _0x89a241['offset']===_0xe29a('0x19')&&typeof _0x89a241[_0xe29a('0x1a')]===_0xe29a('0x19');var _0x3fb2fe=_0x1a527d[_0xe29a('0x1b')];var _0x3a8d25=_0x3d178f?0x0:_0x89a241[_0xe29a('0x1c')];var _0x2ef75a=_0x3d178f?_0x1a527d['count']:_0x89a241['offset']+_0x89a241[_0xe29a('0x1a')];var _0xfa844e;if(_0x2ef75a>=_0x3fb2fe){_0x2ef75a=_0x3fb2fe;_0xfa844e=0xc8;}else{_0xfa844e=0xce;}_0x4599c2[_0xe29a('0x17')](_0xfa844e);return _0x4599c2[_0xe29a('0x1d')](_0xe29a('0x1e'),_0x3a8d25+'-'+_0x2ef75a+'/'+_0x3fb2fe)[_0xe29a('0x1f')](_0x1a527d);}return null;};}function patchUpdates(_0x23b056){return function(_0x2a9b7a){try{jsonpatch[_0xe29a('0x20')](_0x2a9b7a,_0x23b056,!![]);}catch(_0x5288ce){return BPromise[_0xe29a('0x21')](_0x5288ce);}return _0x2a9b7a['save']();};}function saveUpdates(_0xeedbe1,_0x3d7571){return function(_0x31f5b6){if(_0x31f5b6){return _0x31f5b6['update'](_0xeedbe1)[_0xe29a('0x22')](function(_0x2a583b){return _0x2a583b;});}return null;};}function removeEntity(_0x47d4c8,_0x47cc5c){return function(_0x5201db){if(_0x5201db){return _0x5201db[_0xe29a('0x23')]()[_0xe29a('0x22')](function(){var _0x53649b=_0x5201db[_0xe29a('0x24')]({'plain':!![]});var _0x3b20bb=_0xe29a('0x25');return db['UserProfileResource'][_0xe29a('0x23')]({'where':{'type':_0x3b20bb,'resourceId':_0x53649b['id']}})[_0xe29a('0x22')](function(){return _0x5201db;});})[_0xe29a('0x22')](function(){_0x47d4c8[_0xe29a('0x17')](0xcc)[_0xe29a('0x18')]();});}};}function handleEntityNotFound(_0x5d1293,_0x28e550){return function(_0x5ec50f){if(!_0x5ec50f){_0x5d1293[_0xe29a('0x16')](0x194);}return _0x5ec50f;};}function handleError(_0x13a72f,_0x45a93d){_0x45a93d=_0x45a93d||0x1f4;return function(_0xeb7880){logger['error'](_0xeb7880[_0xe29a('0x26')]);if(_0xeb7880[_0xe29a('0x27')]){delete _0xeb7880['name'];}_0x13a72f[_0xe29a('0x17')](_0x45a93d)[_0xe29a('0x28')](_0xeb7880);};}exports['index']=function(_0x4fbfa1,_0x413ab7){var _0x39b30e={},_0x4c823c={},_0x28a740={'count':0x0,'rows':[]};var _0x3528c3=_[_0xe29a('0x29')](db[_0xe29a('0x2a')][_0xe29a('0x2b')],function(_0x299f4c){return{'name':_0x299f4c[_0xe29a('0x2c')],'type':_0x299f4c[_0xe29a('0x2d')][_0xe29a('0x2e')]};});_0x4c823c['model']=_[_0xe29a('0x29')](_0x3528c3,'name');_0x4c823c['query']=_[_0xe29a('0x2f')](_0x4fbfa1['query']);_0x4c823c[_0xe29a('0x30')]=_[_0xe29a('0x31')](_0x4c823c[_0xe29a('0x32')],_0x4c823c[_0xe29a('0x33')]);_0x39b30e[_0xe29a('0x34')]=_[_0xe29a('0x31')](_0x4c823c[_0xe29a('0x32')],qs[_0xe29a('0x35')](_0x4fbfa1['query']['fields']));_0x39b30e[_0xe29a('0x34')]=_0x39b30e[_0xe29a('0x34')][_0xe29a('0x36')]?_0x39b30e[_0xe29a('0x34')]:_0x4c823c[_0xe29a('0x32')];if(!_0x4fbfa1[_0xe29a('0x33')][_0xe29a('0x37')]('nolimit')){_0x39b30e[_0xe29a('0x1a')]=qs['limit'](_0x4fbfa1[_0xe29a('0x33')]['limit']);_0x39b30e[_0xe29a('0x1c')]=qs[_0xe29a('0x1c')](_0x4fbfa1[_0xe29a('0x33')][_0xe29a('0x1c')]);}_0x39b30e[_0xe29a('0x38')]=qs[_0xe29a('0x39')](_0x4fbfa1[_0xe29a('0x33')][_0xe29a('0x39')]);_0x39b30e[_0xe29a('0x3a')]=qs[_0xe29a('0x30')](_[_0xe29a('0x3b')](_0x4fbfa1[_0xe29a('0x33')],_0x4c823c[_0xe29a('0x30')]),_0x3528c3);if(_0x4fbfa1[_0xe29a('0x33')][_0xe29a('0x3c')]){_0x39b30e[_0xe29a('0x3a')]=_[_0xe29a('0x3d')](_0x39b30e[_0xe29a('0x3a')],{'$or':_[_0xe29a('0x29')](_0x3528c3,function(_0x2a68bc){if(_0x2a68bc[_0xe29a('0x2d')]!==_0xe29a('0x3e')){var _0xb8d229={};_0xb8d229[_0x2a68bc[_0xe29a('0x27')]]={'$like':'%'+_0x4fbfa1[_0xe29a('0x33')]['filter']+'%'};return _0xb8d229;}})});}_0x39b30e=_[_0xe29a('0x3d')]({},_0x39b30e,_0x4fbfa1['options']);var _0x5c8e86={'where':_0x39b30e[_0xe29a('0x3a')]};return db[_0xe29a('0x2a')]['count'](_0x5c8e86)[_0xe29a('0x22')](function(_0x47798e){_0x28a740[_0xe29a('0x1b')]=_0x47798e;if(_0x4fbfa1[_0xe29a('0x33')][_0xe29a('0x3f')]){_0x39b30e['include']=[{'all':!![]}];}return db[_0xe29a('0x2a')]['findAll'](_0x39b30e);})[_0xe29a('0x22')](function(_0x5bcfc0){_0x28a740[_0xe29a('0x40')]=_0x5bcfc0;return _0x28a740;})['then'](respondWithFilteredResult(_0x413ab7,_0x39b30e))[_0xe29a('0x41')](handleError(_0x413ab7,null));};exports[_0xe29a('0x42')]=function(_0x571664,_0x5e40d4){var _0x978afd={'raw':![],'where':{'id':_0x571664[_0xe29a('0x43')]['id']}},_0x460765={};_0x460765[_0xe29a('0x32')]=_[_0xe29a('0x2f')](db[_0xe29a('0x2a')][_0xe29a('0x2b')]);_0x460765[_0xe29a('0x33')]=_[_0xe29a('0x2f')](_0x571664[_0xe29a('0x33')]);_0x460765[_0xe29a('0x30')]=_[_0xe29a('0x31')](_0x460765['model'],_0x460765[_0xe29a('0x33')]);_0x978afd[_0xe29a('0x34')]=_[_0xe29a('0x31')](_0x460765[_0xe29a('0x32')],qs['fields'](_0x571664['query'][_0xe29a('0x35')]));_0x978afd[_0xe29a('0x34')]=_0x978afd[_0xe29a('0x34')][_0xe29a('0x36')]?_0x978afd['attributes']:_0x460765[_0xe29a('0x32')];if(_0x571664[_0xe29a('0x33')][_0xe29a('0x3f')]){_0x978afd[_0xe29a('0x44')]=[{'all':!![]}];}_0x978afd=_[_0xe29a('0x3d')]({},_0x978afd,_0x571664[_0xe29a('0x45')]);return db['AnalyticCustomReport'][_0xe29a('0x46')](_0x978afd)[_0xe29a('0x22')](handleEntityNotFound(_0x5e40d4,null))[_0xe29a('0x22')](respondWithResult(_0x5e40d4,null))[_0xe29a('0x41')](handleError(_0x5e40d4,null));};exports['create']=function(_0x502611,_0x2296c0){return db[_0xe29a('0x2a')]['create'](_0x502611[_0xe29a('0x47')],{})[_0xe29a('0x22')](function(_0x334233){var _0x35be4a=_0x502611[_0xe29a('0x48')][_0xe29a('0x24')]({'plain':!![]});if(!_0x35be4a)throw new Error(_0xe29a('0x49'));if(_0x35be4a[_0xe29a('0x4a')]===_0xe29a('0x48')){var _0xee339e=_0x334233['get']({'plain':!![]});var _0x49660f=_0xe29a('0x4b');return db['UserProfileSection'][_0xe29a('0x46')]({'where':{'name':_0x49660f,'userProfileId':_0x35be4a[_0xe29a('0x4c')]},'raw':!![]})[_0xe29a('0x22')](function(_0x4c2383){if(_0x4c2383&&_0x4c2383[_0xe29a('0x4d')]===0x0){return db['UserProfileResource'][_0xe29a('0x4e')]({'name':_0xee339e[_0xe29a('0x27')],'resourceId':_0xee339e['id'],'type':_0xe29a('0x25'),'sectionId':_0x4c2383['id']},{})['then'](function(){return _0x334233;});}else{return _0x334233;}})[_0xe29a('0x41')](function(_0x1f5c78){logger['error'](_0xe29a('0x4f'),_0x1f5c78);throw _0x1f5c78;});}return _0x334233;})[_0xe29a('0x22')](respondWithResult(_0x2296c0,0xc9))[_0xe29a('0x41')](handleError(_0x2296c0,null));};exports[_0xe29a('0x50')]=function(_0x2329ba,_0x41614a){if(_0x2329ba['body']['id']){delete _0x2329ba['body']['id'];}return db['AnalyticCustomReport'][_0xe29a('0x46')]({'where':{'id':_0x2329ba[_0xe29a('0x43')]['id']}})[_0xe29a('0x22')](handleEntityNotFound(_0x41614a,null))[_0xe29a('0x22')](saveUpdates(_0x2329ba[_0xe29a('0x47')],null))[_0xe29a('0x22')](respondWithResult(_0x41614a,null))[_0xe29a('0x41')](handleError(_0x41614a,null));};exports[_0xe29a('0x23')]=function(_0x7d988f,_0x42e894){return db[_0xe29a('0x2a')][_0xe29a('0x46')]({'where':{'id':_0x7d988f[_0xe29a('0x43')]['id']}})[_0xe29a('0x22')](handleEntityNotFound(_0x42e894,null))[_0xe29a('0x22')](removeEntity(_0x42e894,null))[_0xe29a('0x41')](handleError(_0x42e894,null));};exports[_0xe29a('0x51')]=function(_0x554e0b,_0x2a6921){var _0xf96d6d=0xa;var _0x26603c=[_0xe29a('0x52'),'left_join',_0xe29a('0x53'),_0xe29a('0x54')];var _0x203e07={'SUM':'SUM(%s)','COUNT':_0xe29a('0x55'),'COUNT DISTINCT':_0xe29a('0x56'),'MAX':'MAX(%s)','MIN':_0xe29a('0x57'),'AVG':_0xe29a('0x58'),'GROUP_CONCAT':_0xe29a('0x59'),'GROUP_CONCAT ASC':_0xe29a('0x5a'),'GROUP_CONCAT DESC':_0xe29a('0x5b')};var _0x29baad={'SEC_TO_TIME':_0xe29a('0x5c'),'DATE':_0xe29a('0x5d'),'HOUR':_0xe29a('0x5e'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xe29a('0x5f')};var _0x2e3554=function(_0x2e6a6e){return!_[_0xe29a('0x60')]([_0xe29a('0x61'),_0xe29a('0x62'),_0xe29a('0x63'),_0xe29a('0x64')],_0x2e6a6e);};var _0x4e881f=function(_0x2aa3dc){if(!_0x2aa3dc||!_0x2aa3dc['rules'][_0xe29a('0x36')]){return'';}for(var _0x565e9a='(',_0x2a3c53=0x0;_0x2a3c53<_0x2aa3dc[_0xe29a('0x65')][_0xe29a('0x36')];_0x2a3c53+=0x1){_0x2a3c53>0x0&&(_0x565e9a+='\x20'+_0x2aa3dc[_0xe29a('0x66')]+'\x20');_0x565e9a+=_0x2aa3dc[_0xe29a('0x65')][_0x2a3c53][_0xe29a('0x67')]?_0x4e881f(_0x2aa3dc[_0xe29a('0x65')][_0x2a3c53][_0xe29a('0x67')]):_0x2aa3dc[_0xe29a('0x65')][_0x2a3c53][_0xe29a('0x68')]+'\x20'+_0x2aa3dc[_0xe29a('0x65')][_0x2a3c53][_0xe29a('0x69')]+(_0x2e3554(_0x2aa3dc[_0xe29a('0x65')][_0x2a3c53][_0xe29a('0x69')])?'\x20'+_0x2aa3dc[_0xe29a('0x65')][_0x2a3c53][_0xe29a('0x6a')]:'');}return _0x565e9a+')';};var _0x5daca2={'where':{'id':_0x554e0b[_0xe29a('0x43')]['id']}},_0x378b8b,_0x89fe8d,_0x5b8229,_0x3fc891,_0xdc7a87;_0x5daca2=_['merge']({},_0x5daca2,_0x554e0b[_0xe29a('0x45')]);return db[_0xe29a('0x2a')]['find'](_0x5daca2)[_0xe29a('0x22')](function(_0x570ea1){if(_0x570ea1){_0x378b8b=_0x570ea1;return _0x570ea1[_0xe29a('0x6b')]();}return null;})[_0xe29a('0x22')](function(_0x569c4e){if(_0x569c4e){if(!_0x569c4e['length']){throw new db[(_0xe29a('0x6c'))]['ValidationErrorItem'](_0xe29a('0x6d'),0x193);}_0x89fe8d=_0x569c4e;return db[_0xe29a('0x6e')][_0xe29a('0x6f')]({'raw':!![]});}return null;})['then'](function(_0x5bf39f){if(_0x5bf39f){_0x5b8229=_[_0xe29a('0x70')](_0x5bf39f,'id');var _0x43f363;var _0x4e65df=squel[_0xe29a('0x71')]();_0x4e65df[_0xe29a('0x72')](_0x378b8b[_0xe29a('0x73')]);for(var _0xe126c8=0x0;_0xe126c8<_0x89fe8d['length'];_0xe126c8+=0x1){_0x43f363=_0x89fe8d[_0xe126c8]['MetricId']?_0x5b8229[_0x89fe8d[_0xe126c8][_0xe29a('0x74')]][_0xe29a('0x75')]:_0x89fe8d[_0xe126c8][_0xe29a('0x68')];_0x43f363=_0x89fe8d[_0xe126c8][_0xe29a('0x76')]?_[_0xe29a('0x77')](_0x203e07[_0x89fe8d[_0xe126c8][_0xe29a('0x76')]],'%s',_0x43f363):_0x43f363;_0x43f363=_0x89fe8d[_0xe126c8][_0xe29a('0x78')]?_[_0xe29a('0x77')](_0x29baad[_0x89fe8d[_0xe126c8]['format']],'%s',_0x43f363):_0x43f363;if(_0x89fe8d[_0xe126c8][_0xe29a('0x79')]){_0x4e65df[_0xe29a('0x67')](_0x43f363);}_0x89fe8d[_0xe126c8][_0xe29a('0x7a')]&&_0x4e65df[_0xe29a('0x38')](_0x43f363,_0x89fe8d[_0xe126c8][_0xe29a('0x7a')]==='DESC'?![]:!![]);_0x4e65df[_0xe29a('0x68')](_0x43f363,_0x89fe8d[_0xe126c8][_0xe29a('0x7b')]||_0x43f363);}if(_0x378b8b['joins']){_0x378b8b[_0xe29a('0x7c')]=JSON[_0xe29a('0x7d')](_0x378b8b[_0xe29a('0x7c')]);for(var _0x55b00a=0x0;_0x55b00a<_0x378b8b['joins'][_0xe29a('0x36')];_0x55b00a+=0x1){if(_0x378b8b[_0xe29a('0x7c')][_0x55b00a][_0xe29a('0x2d')]&&_['includes'](_0x26603c,_0x378b8b[_0xe29a('0x7c')][_0x55b00a][_0xe29a('0x2d')])&&_0x378b8b['joins'][_0x55b00a][_0xe29a('0x7e')]&&_0x378b8b['joins'][_0x55b00a][_0xe29a('0x7f')]&&_0x378b8b['joins'][_0x55b00a][_0xe29a('0x80')]){_0x4e65df[_0x378b8b['joins'][_0x55b00a]['type']](_0x378b8b[_0xe29a('0x7c')][_0x55b00a][_0xe29a('0x7f')],null,util['format'](_0xe29a('0x81'),_0x378b8b[_0xe29a('0x73')],_0x378b8b[_0xe29a('0x7c')][_0x55b00a][_0xe29a('0x7e')],_0x378b8b[_0xe29a('0x7c')][_0x55b00a]['foreignTable'],_0x378b8b[_0xe29a('0x7c')][_0x55b00a][_0xe29a('0x80')]));}}}if(_0x378b8b[_0xe29a('0x82')]){_0x378b8b[_0xe29a('0x82')]=JSON[_0xe29a('0x7d')](_0x378b8b['conditions']);_0x4e65df['where'](_0x4e881f(_0x378b8b[_0xe29a('0x82')][_0xe29a('0x67')]));}_0xdc7a87=_0x4e65df['clone']();_0x4e65df[_0xe29a('0x1a')](_0xf96d6d);_0x4e65df['offset'](0x0);logger[_0xe29a('0x83')](_0xe29a('0x84'),_0x4e65df[_0xe29a('0x85')]());return dbH['sequelize']['query'](_0x4e65df[_0xe29a('0x85')](),{'type':dbH[_0xe29a('0x86')]['QueryTypes'][_0xe29a('0x87')]});}})[_0xe29a('0x22')](respondWithResult(_0x2a6921,null))['catch'](handleError(_0x2a6921,null));};function runReport(_0x4b3503,_0x574507,_0x35a20e){var _0xe6433e=_0x574507[_0xe29a('0x27')];var _0x51fa3f=0xa;var _0xa45fbb=[_0xe29a('0x52'),'left_join',_0xe29a('0x53'),_0xe29a('0x54')];var _0x2a66e1={'SUM':_0xe29a('0x88'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0xe29a('0x56'),'MAX':'MAX(%s)','MIN':_0xe29a('0x57'),'AVG':_0xe29a('0x58'),'GROUP_CONCAT':_0xe29a('0x59'),'GROUP_CONCAT ASC':_0xe29a('0x5a'),'GROUP_CONCAT DESC':_0xe29a('0x5b')};var _0x11d293={'SEC_TO_TIME':_0xe29a('0x5c'),'DATE':_0xe29a('0x5d'),'HOUR':'HOUR(%s)','ROUND':_0xe29a('0x89'),'UNIX_TIMESTAMP':_0xe29a('0x5f')};var _0xf82449=function(_0x59902f){return!_['includes']([_0xe29a('0x61'),_0xe29a('0x62'),_0xe29a('0x63'),_0xe29a('0x64')],_0x59902f);};var _0x482671=function(_0x49632d){if(!_0x49632d||!_0x49632d[_0xe29a('0x65')][_0xe29a('0x36')]){return'';}for(var _0x5b41d9='(',_0x25cc9d=0x0;_0x25cc9d<_0x49632d[_0xe29a('0x65')][_0xe29a('0x36')];_0x25cc9d+=0x1){_0x25cc9d>0x0&&(_0x5b41d9+='\x20'+_0x49632d[_0xe29a('0x66')]+'\x20');_0x5b41d9+=_0x49632d[_0xe29a('0x65')][_0x25cc9d][_0xe29a('0x67')]?_0x482671(_0x49632d[_0xe29a('0x65')][_0x25cc9d]['group']):_0x49632d['rules'][_0x25cc9d][_0xe29a('0x68')]+'\x20'+_0x49632d['rules'][_0x25cc9d][_0xe29a('0x69')]+(_0xf82449(_0x49632d[_0xe29a('0x65')][_0x25cc9d][_0xe29a('0x69')])?'\x20'+_0x49632d[_0xe29a('0x65')][_0x25cc9d][_0xe29a('0x6a')]:'');}return _0x5b41d9+')';};var _0xb96b61={'where':{'id':_0x4b3503['id']}},_0x3ce1c9,_0x4a0c31,_0x10eb44,_0x3be73b,_0x4ca52f;_0xb96b61=_[_0xe29a('0x3d')]({},_0xb96b61,_0x35a20e);return db['AnalyticCustomReport'][_0xe29a('0x46')](_0xb96b61)['then'](function(_0xf1adf5){if(_0xf1adf5){_0x3ce1c9=_0xf1adf5;return _0xf1adf5[_0xe29a('0x6b')]();}return null;})[_0xe29a('0x22')](function(_0x40df2e){if(_0x40df2e){if(!_0x40df2e[_0xe29a('0x36')]){throw new db[(_0xe29a('0x6c'))][(_0xe29a('0x8a'))](_0xe29a('0x6d'),0x193);}_0x4a0c31=_0x40df2e;return db[_0xe29a('0x6e')][_0xe29a('0x6f')]({'raw':!![]});}return null;})['then'](function(_0x3500ea){if(_0x3500ea){_0x10eb44=_[_0xe29a('0x70')](_0x3500ea,'id');var _0x25c688;var _0x4df4ef=squel[_0xe29a('0x71')]();_0x4df4ef['from'](_0x3ce1c9[_0xe29a('0x73')]);for(var _0x31034c=0x0;_0x31034c<_0x4a0c31[_0xe29a('0x36')];_0x31034c+=0x1){_0x25c688=_0x4a0c31[_0x31034c]['MetricId']?_0x10eb44[_0x4a0c31[_0x31034c][_0xe29a('0x74')]][_0xe29a('0x75')]:_0x4a0c31[_0x31034c][_0xe29a('0x68')];_0x25c688=_0x4a0c31[_0x31034c][_0xe29a('0x76')]?_[_0xe29a('0x77')](_0x2a66e1[_0x4a0c31[_0x31034c]['function']],'%s',_0x25c688):_0x25c688;_0x25c688=_0x4a0c31[_0x31034c][_0xe29a('0x78')]?_[_0xe29a('0x77')](_0x11d293[_0x4a0c31[_0x31034c][_0xe29a('0x78')]],'%s',_0x25c688):_0x25c688;if(_0x4a0c31[_0x31034c][_0xe29a('0x79')]){_0x4df4ef[_0xe29a('0x67')](_0x25c688);}_0x4a0c31[_0x31034c][_0xe29a('0x7a')]&&_0x4df4ef[_0xe29a('0x38')](_0x25c688,_0x4a0c31[_0x31034c][_0xe29a('0x7a')]==='DESC'?![]:!![]);_0x4df4ef[_0xe29a('0x68')](_0x25c688,_0x4a0c31[_0x31034c][_0xe29a('0x7b')]||_0x25c688);}if(_0x3ce1c9[_0xe29a('0x7c')]){_0x3ce1c9[_0xe29a('0x7c')]=JSON['parse'](_0x3ce1c9['joins']);for(var _0x40ca4d=0x0;_0x40ca4d<_0x3ce1c9['joins'][_0xe29a('0x36')];_0x40ca4d+=0x1){if(_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d][_0xe29a('0x2d')]&&_['includes'](_0xa45fbb,_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d][_0xe29a('0x2d')])&&_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d]['parentKey']&&_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d][_0xe29a('0x7f')]&&_0x3ce1c9['joins'][_0x40ca4d][_0xe29a('0x80')]){_0x4df4ef[_0x3ce1c9['joins'][_0x40ca4d]['type']](_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d][_0xe29a('0x7f')],null,util[_0xe29a('0x78')](_0xe29a('0x81'),_0x3ce1c9[_0xe29a('0x73')],_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d]['parentKey'],_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d]['foreignTable'],_0x3ce1c9[_0xe29a('0x7c')][_0x40ca4d][_0xe29a('0x80')]));}}}if(_0x3ce1c9[_0xe29a('0x82')]){_0x3ce1c9[_0xe29a('0x82')]=JSON[_0xe29a('0x7d')](_0x3ce1c9[_0xe29a('0x82')]);_0x4df4ef[_0xe29a('0x3a')](_0x482671(_0x3ce1c9[_0xe29a('0x82')][_0xe29a('0x67')]));}_0x4ca52f=_0x4df4ef['clone']();_0x4df4ef[_0xe29a('0x1a')](_0x51fa3f);_0x4df4ef[_0xe29a('0x1c')](0x0);return;}})[_0xe29a('0x22')](function(){if(_0x574507[_0xe29a('0x8b')]===_0xe29a('0x8c')){return null;}var _0x32e3d3=_[_0xe29a('0x3d')](_0x574507,{'name':_0x574507[_0xe29a('0x8d')]||_0x574507['name']||_0x3ce1c9['name'],'basename':_0xe6433e,'savename':util[_0xe29a('0x78')](_0xe29a('0x8e'),_0x574507['name']||_0x3ce1c9[_0xe29a('0x27')],require(_0xe29a('0x8f'))[_0xe29a('0x90')](0x4),_0x574507['output']||_0xe29a('0x91')),'reportId':_0x3ce1c9['id'],'reportType':'custom'});return db[_0xe29a('0x92')][_0xe29a('0x4e')](_0x32e3d3,{'raw':!![]});})[_0xe29a('0x22')](function(_0x5aece1){if(_0x3ce1c9[_0xe29a('0x73')]===_0xe29a('0x93')){_0x4ca52f['where'](_0x3ce1c9[_0xe29a('0x73')]+_0xe29a('0x94'),_0x574507[_0xe29a('0x95')],_0x574507[_0xe29a('0x96')]);}else{_0x4ca52f[_0xe29a('0x3a')](_0x3ce1c9[_0xe29a('0x73')]+'.createdAt\x20BETWEEN\x20?\x20AND\x20?',_0x574507['startDate'],_0x574507[_0xe29a('0x96')]);}if(_0x5aece1){logger['info']('Run\x20Query:',_0x4ca52f['toString']());require('child_process')['fork'](path[_0xe29a('0x52')](__dirname,_0xe29a('0x97'),_0x5aece1['output']),[_0x5aece1['id'],_0x4ca52f['toString'](),path[_0xe29a('0x52')](__dirname,'../../files/reports',_0x5aece1['savename']),_0xe6433e]);return _0x5aece1;}else{var _0x410f64=squel[_0xe29a('0x71')]();_0x410f64['from']('('+_0x4ca52f[_0xe29a('0x85')]()+')',_0xe29a('0x98'));_0x410f64['field'](_0xe29a('0x99'),_0xe29a('0x1b'));_0x4ca52f[_0xe29a('0x1a')](_0x574507[_0xe29a('0x1a')]||_0x51fa3f);_0x4ca52f['offset'](_0x574507[_0xe29a('0x1c')]||0x0);return dbH['sequelize']['query'](_0x410f64[_0xe29a('0x85')](),{'type':dbH[_0xe29a('0x86')][_0xe29a('0x9a')][_0xe29a('0x87')]})[_0xe29a('0x22')](function(_0x36a2e7){if(!_0x36a2e7[_0xe29a('0x36')]){_0x3be73b=0x0;}else{_0x3be73b=_0x36a2e7[0x0]['count']||0x0;}return dbH[_0xe29a('0x86')][_0xe29a('0x33')](_0x4ca52f[_0xe29a('0x85')](),{'type':dbH['sequelize']['QueryTypes'][_0xe29a('0x87')]});})[_0xe29a('0x22')](function(_0x5a588c){return{'rows':_0x5a588c||[],'count':_0x3be73b};});}});}exports[_0xe29a('0x9b')]=function(_0x486fbd,_0x59e054){return runReport(_0x486fbd[_0xe29a('0x43')],_0x486fbd[_0xe29a('0x33')],_0x486fbd['options'])['then'](respondWithResult(_0x59e054,null))['catch'](handleError(_0x59e054,null));};exports[_0xe29a('0x9c')]=runReport;exports['query']=function(_0x52f969,_0x11f407){var _0x269cfa=0xa;var _0x4a0943=['join',_0xe29a('0x9d'),'right_join','cross_join'];var _0x1f9546={'SUM':_0xe29a('0x88'),'COUNT':_0xe29a('0x55'),'COUNT DISTINCT':_0xe29a('0x56'),'MAX':_0xe29a('0x9e'),'MIN':'MIN(%s)','AVG':_0xe29a('0x58'),'GROUP_CONCAT':_0xe29a('0x59'),'GROUP_CONCAT ASC':_0xe29a('0x5a'),'GROUP_CONCAT DESC':_0xe29a('0x5b')};var _0x305f3a={'SEC_TO_TIME':_0xe29a('0x5c'),'DATE':_0xe29a('0x5d'),'HOUR':'HOUR(%s)','ROUND':_0xe29a('0x89'),'UNIX_TIMESTAMP':_0xe29a('0x5f')};var _0x3a0f33=function(_0x5ee41f){return!_[_0xe29a('0x60')]([_0xe29a('0x61'),_0xe29a('0x62'),_0xe29a('0x63'),_0xe29a('0x64')],_0x5ee41f);};var _0x19a9d1=function(_0x4d8ad4){if(!_0x4d8ad4||!_0x4d8ad4[_0xe29a('0x65')]['length']){return'';}for(var _0x4a92d7='(',_0x47d125=0x0;_0x47d125<_0x4d8ad4[_0xe29a('0x65')][_0xe29a('0x36')];_0x47d125+=0x1){_0x47d125>0x0&&(_0x4a92d7+='\x20'+_0x4d8ad4[_0xe29a('0x66')]+'\x20');_0x4a92d7+=_0x4d8ad4[_0xe29a('0x65')][_0x47d125][_0xe29a('0x67')]?_0x19a9d1(_0x4d8ad4[_0xe29a('0x65')][_0x47d125][_0xe29a('0x67')]):_0x4d8ad4['rules'][_0x47d125][_0xe29a('0x68')]+'\x20'+_0x4d8ad4['rules'][_0x47d125]['condition']+(_0x3a0f33(_0x4d8ad4[_0xe29a('0x65')][_0x47d125]['condition'])?'\x20'+_0x4d8ad4[_0xe29a('0x65')][_0x47d125][_0xe29a('0x6a')]:'');}return _0x4a92d7+')';};var _0x2ffbf2={'where':{'id':_0x52f969[_0xe29a('0x43')]['id']}},_0x21ab8e,_0xc18bc3,_0x496afd,_0x172aad,_0x30dfb0;_0x2ffbf2=_[_0xe29a('0x3d')]({},_0x2ffbf2,_0x52f969[_0xe29a('0x45')]);return db[_0xe29a('0x2a')]['find'](_0x2ffbf2)[_0xe29a('0x22')](function(_0x5cd893){if(_0x5cd893){_0x21ab8e=_0x5cd893;return _0x5cd893['getFields']();}return null;})[_0xe29a('0x22')](function(_0x13ffc7){if(_0x13ffc7){if(!_0x13ffc7[_0xe29a('0x36')]){throw new db['Sequelize']['ValidationErrorItem'](_0xe29a('0x6d'),0x193);}_0xc18bc3=_0x13ffc7;return db[_0xe29a('0x6e')][_0xe29a('0x6f')]({'raw':!![]});}return null;})[_0xe29a('0x22')](function(_0x4017d0){if(_0x4017d0){_0x496afd=_[_0xe29a('0x70')](_0x4017d0,'id');var _0x3969e9;var _0x3d66f1=squel[_0xe29a('0x71')]();_0x3d66f1[_0xe29a('0x72')](_0x21ab8e[_0xe29a('0x73')]);for(var _0x3ef721=0x0;_0x3ef721<_0xc18bc3[_0xe29a('0x36')];_0x3ef721+=0x1){_0x3969e9=_0xc18bc3[_0x3ef721][_0xe29a('0x74')]?_0x496afd[_0xc18bc3[_0x3ef721][_0xe29a('0x74')]][_0xe29a('0x75')]:_0xc18bc3[_0x3ef721][_0xe29a('0x68')];_0x3969e9=_0xc18bc3[_0x3ef721][_0xe29a('0x76')]?_[_0xe29a('0x77')](_0x1f9546[_0xc18bc3[_0x3ef721][_0xe29a('0x76')]],'%s',_0x3969e9):_0x3969e9;_0x3969e9=_0xc18bc3[_0x3ef721]['format']?_['replace'](_0x305f3a[_0xc18bc3[_0x3ef721][_0xe29a('0x78')]],'%s',_0x3969e9):_0x3969e9;if(_0xc18bc3[_0x3ef721][_0xe29a('0x79')]){_0x3d66f1[_0xe29a('0x67')](_0x3969e9);}_0xc18bc3[_0x3ef721][_0xe29a('0x7a')]&&_0x3d66f1[_0xe29a('0x38')](_0x3969e9,_0xc18bc3[_0x3ef721]['orderBy']===_0xe29a('0x9f')?![]:!![]);_0x3d66f1[_0xe29a('0x68')](_0x3969e9,_0xc18bc3[_0x3ef721][_0xe29a('0x7b')]||_0x3969e9);}if(_0x21ab8e[_0xe29a('0x7c')]){_0x21ab8e['joins']=JSON[_0xe29a('0x7d')](_0x21ab8e['joins']);for(var _0xf06b6a=0x0;_0xf06b6a<_0x21ab8e[_0xe29a('0x7c')][_0xe29a('0x36')];_0xf06b6a+=0x1){if(_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a][_0xe29a('0x2d')]&&_[_0xe29a('0x60')](_0x4a0943,_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a]['type'])&&_0x21ab8e['joins'][_0xf06b6a][_0xe29a('0x7e')]&&_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a][_0xe29a('0x7f')]&&_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a][_0xe29a('0x80')]){_0x3d66f1[_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a][_0xe29a('0x2d')]](_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a][_0xe29a('0x7f')],null,util[_0xe29a('0x78')]('%s.%s\x20=\x20%s.%s',_0x21ab8e[_0xe29a('0x73')],_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a][_0xe29a('0x7e')],_0x21ab8e[_0xe29a('0x7c')][_0xf06b6a][_0xe29a('0x7f')],_0x21ab8e['joins'][_0xf06b6a][_0xe29a('0x80')]));}}}if(_0x21ab8e[_0xe29a('0x82')]){_0x21ab8e[_0xe29a('0x82')]=JSON[_0xe29a('0x7d')](_0x21ab8e[_0xe29a('0x82')]);_0x3d66f1[_0xe29a('0x3a')](_0x19a9d1(_0x21ab8e[_0xe29a('0x82')][_0xe29a('0x67')]));}_0x30dfb0=_0x3d66f1[_0xe29a('0xa0')]();_0x3d66f1['limit'](_0x269cfa);_0x3d66f1[_0xe29a('0x1c')](0x0);logger[_0xe29a('0x83')](_0xe29a('0x84'),_0x3d66f1[_0xe29a('0x85')]());return dbH[_0xe29a('0x86')][_0xe29a('0x33')](_0x3d66f1[_0xe29a('0x85')](),{'type':dbH[_0xe29a('0x86')][_0xe29a('0x9a')][_0xe29a('0x87')]});}})['then'](function(){return{'sql':_0x30dfb0[_0xe29a('0x85')]()};})[_0xe29a('0x22')](respondWithResult(_0x11f407,null))['catch'](handleError(_0x11f407,null));};
\ No newline at end of file