Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 039f3b1..ec40e8d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf249=['../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/utils','../../mysqldb','dbH','sendStatus','status','end','json','count','offset','limit','set','Content-Range','save','update','then','destroy','CustomReports','UserProfileResource','error','stack','name','send','index','AnalyticCustomReport','fieldName','type','model','map','query','keys','filters','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','catch','show','params','rawAttributes','intersection','create','body','user','get','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Reports','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','find','preview','join','left_join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','DATE(%s)','HOUR(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NOT\x20NULL','IS\x20EMPTY','rules','operator','group','field','condition','value','getFields','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','keyBy','select','from','table','MetricId','metric','function','replace','format','groupBy','orderBy','DESC','alias','joins','parse','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','conditions','debug','toString','sequelize','QueryTypes','SELECT','MIN(%s)','IS\x20NULL','IS\x20NOT\x20EMPTY','Sequelize','output','web','generate','AnalyticExtractedReport','.calldate\x20BETWEEN\x20?\x20AND\x20?','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','fork','../../components/export/','savename','countTable','COUNT(*)','run','runReport','SEC_TO_TIME(%s)','AnalyticMetric','clone','Limited\x20Query:','html-pdf','zip-dir','fast-json-patch','moment','mustache','util','path','sox','to-csv','lodash','crypto','desk.js','papaparse','../../components/auth/service'];(function(_0x5c6994,_0x19ad9a){var _0x1d5c84=function(_0x4a385a){while(--_0x4a385a){_0x5c6994['push'](_0x5c6994['shift']());}};_0x1d5c84(++_0x19ad9a);}(_0xf249,0x8c));var _0x9f24=function(_0x4cdfa4,_0x128419){_0x4cdfa4=_0x4cdfa4-0x0;var _0x44475e=_0xf249[_0x4cdfa4];return _0x44475e;};'use strict';var pdf=require(_0x9f24('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x9f24('0x1'));var jsonpatch=require(_0x9f24('0x2'));var rp=require('request-promise');var moment=require(_0x9f24('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x9f24('0x4'));var util=require(_0x9f24('0x5'));var path=require(_0x9f24('0x6'));var sox=require(_0x9f24('0x7'));var csv=require(_0x9f24('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x9f24('0x9'));var squel=require('squel');var crypto=require(_0x9f24('0xa'));var jsforce=require('jsforce');var deskjs=require(_0x9f24('0xb'));var toCsv=require(_0x9f24('0x8'));var querystring=require('querystring');var Papa=require(_0x9f24('0xc'));var Redis=require('ioredis');var authService=require(_0x9f24('0xd'));var qs=require(_0x9f24('0xe'));var as=require(_0x9f24('0xf'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require(_0x9f24('0x10'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x9f24('0x11'))['db'];var dbH=require(_0x9f24('0x11'))[_0x9f24('0x12')];function respondWithStatusCode(_0x738349,_0xdfe2ed){_0xdfe2ed=_0xdfe2ed||0xcc;return function(_0x2479ae){if(_0x2479ae){return _0x738349[_0x9f24('0x13')](_0xdfe2ed);}return _0x738349[_0x9f24('0x14')](_0xdfe2ed)[_0x9f24('0x15')]();};}function respondWithResult(_0x57b824,_0x38722e){_0x38722e=_0x38722e||0xc8;return function(_0x36b44b){if(_0x36b44b){return _0x57b824[_0x9f24('0x14')](_0x38722e)[_0x9f24('0x16')](_0x36b44b);}};}function respondWithFilteredResult(_0x5b96c8,_0x387bad){return function(_0x4bc11f){if(_0x4bc11f){var _0x2a54c4=_0x4bc11f[_0x9f24('0x17')],_0x192e97=_0x387bad[_0x9f24('0x18')],_0x346fa2=_0x387bad[_0x9f24('0x18')]+_0x387bad[_0x9f24('0x19')],_0x2a4c8c;if(_0x346fa2>=_0x2a54c4){_0x346fa2=_0x2a54c4;_0x2a4c8c=0xc8;}else{_0x2a4c8c=0xce;}_0x5b96c8['status'](_0x2a4c8c);return _0x5b96c8[_0x9f24('0x1a')](_0x9f24('0x1b'),_0x192e97+'-'+_0x346fa2+'/'+_0x2a54c4)[_0x9f24('0x16')](_0x4bc11f);}return null;};}function patchUpdates(_0x49f54e){return function(_0x65081b){try{jsonpatch['apply'](_0x65081b,_0x49f54e,!![]);}catch(_0x39ac22){return BPromise['reject'](_0x39ac22);}return _0x65081b[_0x9f24('0x1c')]();};}function saveUpdates(_0x5a5ec5,_0x57e1ac){return function(_0x4f987b){if(_0x4f987b){return _0x4f987b[_0x9f24('0x1d')](_0x5a5ec5)[_0x9f24('0x1e')](function(_0x2423d0){return _0x2423d0;});}return null;};}function removeEntity(_0x41a4f9,_0x5a1adc){return function(_0x3ca26b){if(_0x3ca26b){return _0x3ca26b[_0x9f24('0x1f')]()[_0x9f24('0x1e')](function(){var _0x4dd29b=_0x3ca26b['get']({'plain':!![]});var _0x55d9a4=_0x9f24('0x20');return db[_0x9f24('0x21')][_0x9f24('0x1f')]({'where':{'type':_0x55d9a4,'resourceId':_0x4dd29b['id']}})[_0x9f24('0x1e')](function(){return _0x3ca26b;});})['then'](function(){_0x41a4f9[_0x9f24('0x14')](0xcc)[_0x9f24('0x15')]();});}};}function handleEntityNotFound(_0x13887f,_0x130534){return function(_0x4b0c51){if(!_0x4b0c51){_0x13887f[_0x9f24('0x13')](0x194);}return _0x4b0c51;};}function handleError(_0x55634d,_0x35987a){_0x35987a=_0x35987a||0x1f4;return function(_0x10f25e){logger[_0x9f24('0x22')](_0x10f25e[_0x9f24('0x23')]);if(_0x10f25e[_0x9f24('0x24')]){delete _0x10f25e['name'];}_0x55634d[_0x9f24('0x14')](_0x35987a)[_0x9f24('0x25')](_0x10f25e);};}exports[_0x9f24('0x26')]=function(_0x2a3269,_0x1f08f3){var _0x55e7e0={},_0x416925={},_0x1a58e0={'count':0x0,'rows':[]};var _0x175cc9=_['map'](db[_0x9f24('0x27')]['rawAttributes'],function(_0x4926e6){return{'name':_0x4926e6[_0x9f24('0x28')],'type':_0x4926e6[_0x9f24('0x29')]['key']};});_0x416925[_0x9f24('0x2a')]=_[_0x9f24('0x2b')](_0x175cc9,_0x9f24('0x24'));_0x416925[_0x9f24('0x2c')]=_[_0x9f24('0x2d')](_0x2a3269[_0x9f24('0x2c')]);_0x416925[_0x9f24('0x2e')]=_['intersection'](_0x416925[_0x9f24('0x2a')],_0x416925['query']);_0x55e7e0[_0x9f24('0x2f')]=_['intersection'](_0x416925[_0x9f24('0x2a')],qs[_0x9f24('0x30')](_0x2a3269[_0x9f24('0x2c')][_0x9f24('0x30')]));_0x55e7e0[_0x9f24('0x2f')]=_0x55e7e0[_0x9f24('0x2f')][_0x9f24('0x31')]?_0x55e7e0[_0x9f24('0x2f')]:_0x416925[_0x9f24('0x2a')];if(!_0x2a3269[_0x9f24('0x2c')]['hasOwnProperty'](_0x9f24('0x32'))){_0x55e7e0['limit']=qs[_0x9f24('0x19')](_0x2a3269[_0x9f24('0x2c')]['limit']);_0x55e7e0[_0x9f24('0x18')]=qs[_0x9f24('0x18')](_0x2a3269['query'][_0x9f24('0x18')]);}_0x55e7e0[_0x9f24('0x33')]=qs[_0x9f24('0x34')](_0x2a3269[_0x9f24('0x2c')]['sort']);_0x55e7e0[_0x9f24('0x35')]=qs[_0x9f24('0x2e')](_[_0x9f24('0x36')](_0x2a3269['query'],_0x416925[_0x9f24('0x2e')]),_0x175cc9);if(_0x2a3269[_0x9f24('0x2c')][_0x9f24('0x37')]){_0x55e7e0[_0x9f24('0x35')]=_[_0x9f24('0x38')](_0x55e7e0['where'],{'$or':_['map'](_0x175cc9,function(_0x435e11){if(_0x435e11[_0x9f24('0x29')]!=='VIRTUAL'){var _0x569d82={};_0x569d82[_0x435e11[_0x9f24('0x24')]]={'$like':'%'+_0x2a3269[_0x9f24('0x2c')][_0x9f24('0x37')]+'%'};return _0x569d82;}})});}_0x55e7e0=_[_0x9f24('0x38')]({},_0x55e7e0,_0x2a3269[_0x9f24('0x39')]);var _0x1c81d2={'where':_0x55e7e0['where']};return db[_0x9f24('0x27')][_0x9f24('0x17')](_0x1c81d2)[_0x9f24('0x1e')](function(_0x2df9b0){_0x1a58e0[_0x9f24('0x17')]=_0x2df9b0;if(_0x2a3269[_0x9f24('0x2c')][_0x9f24('0x3a')]){_0x55e7e0[_0x9f24('0x3b')]=[{'all':!![]}];}return db[_0x9f24('0x27')][_0x9f24('0x3c')](_0x55e7e0);})['then'](function(_0x524bf3){_0x1a58e0['rows']=_0x524bf3;return _0x1a58e0;})[_0x9f24('0x1e')](respondWithFilteredResult(_0x1f08f3,_0x55e7e0))[_0x9f24('0x3d')](handleError(_0x1f08f3,null));};exports[_0x9f24('0x3e')]=function(_0x2b8584,_0x5d7901){var _0x5ae558={'raw':![],'where':{'id':_0x2b8584[_0x9f24('0x3f')]['id']}},_0x2dc30a={};_0x2dc30a['model']=_['keys'](db[_0x9f24('0x27')][_0x9f24('0x40')]);_0x2dc30a[_0x9f24('0x2c')]=_[_0x9f24('0x2d')](_0x2b8584[_0x9f24('0x2c')]);_0x2dc30a['filters']=_[_0x9f24('0x41')](_0x2dc30a[_0x9f24('0x2a')],_0x2dc30a['query']);_0x5ae558[_0x9f24('0x2f')]=_['intersection'](_0x2dc30a[_0x9f24('0x2a')],qs[_0x9f24('0x30')](_0x2b8584[_0x9f24('0x2c')][_0x9f24('0x30')]));_0x5ae558['attributes']=_0x5ae558[_0x9f24('0x2f')][_0x9f24('0x31')]?_0x5ae558[_0x9f24('0x2f')]:_0x2dc30a[_0x9f24('0x2a')];if(_0x2b8584['query'][_0x9f24('0x3a')]){_0x5ae558[_0x9f24('0x3b')]=[{'all':!![]}];}_0x5ae558=_[_0x9f24('0x38')]({},_0x5ae558,_0x2b8584[_0x9f24('0x39')]);return db[_0x9f24('0x27')]['find'](_0x5ae558)[_0x9f24('0x1e')](handleEntityNotFound(_0x5d7901,null))[_0x9f24('0x1e')](respondWithResult(_0x5d7901,null))[_0x9f24('0x3d')](handleError(_0x5d7901,null));};exports['create']=function(_0x267cd8,_0x4ba1ce){return db['AnalyticCustomReport'][_0x9f24('0x42')](_0x267cd8[_0x9f24('0x43')],{})['then'](function(_0x4c4b1a){var _0x59b6a6=_0x267cd8[_0x9f24('0x44')][_0x9f24('0x45')]({'plain':!![]});if(!_0x59b6a6)throw new Error(_0x9f24('0x46'));if(_0x59b6a6[_0x9f24('0x47')]===_0x9f24('0x44')){var _0x38599b=_0x4c4b1a[_0x9f24('0x45')]({'plain':!![]});var _0x2d7dbb=_0x9f24('0x48');return db['UserProfileSection']['find']({'where':{'name':_0x2d7dbb,'userProfileId':_0x59b6a6['userProfileId']},'raw':!![]})[_0x9f24('0x1e')](function(_0x327edc){if(_0x327edc&&_0x327edc[_0x9f24('0x49')]===0x0){return db['UserProfileResource'][_0x9f24('0x42')]({'name':_0x38599b[_0x9f24('0x24')],'resourceId':_0x38599b['id'],'type':_0x9f24('0x20'),'sectionId':_0x327edc['id']},{})[_0x9f24('0x1e')](function(){return _0x4c4b1a;});}else{return _0x4c4b1a;}})[_0x9f24('0x3d')](function(_0x55555f){logger[_0x9f24('0x22')](_0x9f24('0x4a'),_0x55555f);throw _0x55555f;});}return _0x4c4b1a;})[_0x9f24('0x1e')](respondWithResult(_0x4ba1ce,0xc9))['catch'](handleError(_0x4ba1ce,null));};exports[_0x9f24('0x1d')]=function(_0x31810a,_0x7a1c4f){if(_0x31810a[_0x9f24('0x43')]['id']){delete _0x31810a[_0x9f24('0x43')]['id'];}return db[_0x9f24('0x27')]['find']({'where':{'id':_0x31810a[_0x9f24('0x3f')]['id']}})['then'](handleEntityNotFound(_0x7a1c4f,null))[_0x9f24('0x1e')](saveUpdates(_0x31810a[_0x9f24('0x43')],null))[_0x9f24('0x1e')](respondWithResult(_0x7a1c4f,null))['catch'](handleError(_0x7a1c4f,null));};exports[_0x9f24('0x1f')]=function(_0x517093,_0x27fb94){return db[_0x9f24('0x27')][_0x9f24('0x4b')]({'where':{'id':_0x517093[_0x9f24('0x3f')]['id']}})[_0x9f24('0x1e')](handleEntityNotFound(_0x27fb94,null))[_0x9f24('0x1e')](removeEntity(_0x27fb94,null))[_0x9f24('0x3d')](handleError(_0x27fb94,null));};exports[_0x9f24('0x4c')]=function(_0x415624,_0xaef109){var _0x5b2f20=0xa;var _0x46ddfe=[_0x9f24('0x4d'),_0x9f24('0x4e'),_0x9f24('0x4f'),_0x9f24('0x50')];var _0x52c16b={'SUM':_0x9f24('0x51'),'COUNT':_0x9f24('0x52'),'COUNT DISTINCT':_0x9f24('0x53'),'MAX':_0x9f24('0x54'),'MIN':'MIN(%s)','AVG':_0x9f24('0x55'),'GROUP_CONCAT':_0x9f24('0x56'),'GROUP_CONCAT ASC':_0x9f24('0x57'),'GROUP_CONCAT DESC':_0x9f24('0x58')};var _0x4e9b3c={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x9f24('0x59'),'HOUR':_0x9f24('0x5a'),'ROUND':_0x9f24('0x5b'),'UNIX_TIMESTAMP':_0x9f24('0x5c')};var _0xff97e7=function(_0x57710a){return!_[_0x9f24('0x5d')](['IS\x20NULL',_0x9f24('0x5e'),_0x9f24('0x5f'),'IS\x20NOT\x20EMPTY'],_0x57710a);};var _0x593e5e=function(_0x1c228e){if(!_0x1c228e||!_0x1c228e[_0x9f24('0x60')][_0x9f24('0x31')]){return'';}for(var _0x400707='(',_0x2a206b=0x0;_0x2a206b<_0x1c228e[_0x9f24('0x60')][_0x9f24('0x31')];_0x2a206b+=0x1){_0x2a206b>0x0&&(_0x400707+='\x20'+_0x1c228e[_0x9f24('0x61')]+'\x20');_0x400707+=_0x1c228e[_0x9f24('0x60')][_0x2a206b][_0x9f24('0x62')]?_0x593e5e(_0x1c228e[_0x9f24('0x60')][_0x2a206b][_0x9f24('0x62')]):_0x1c228e[_0x9f24('0x60')][_0x2a206b][_0x9f24('0x63')]+'\x20'+_0x1c228e[_0x9f24('0x60')][_0x2a206b][_0x9f24('0x64')]+(_0xff97e7(_0x1c228e['rules'][_0x2a206b]['condition'])?'\x20'+_0x1c228e[_0x9f24('0x60')][_0x2a206b][_0x9f24('0x65')]:'');}return _0x400707+')';};var _0x2ca870={'where':{'id':_0x415624[_0x9f24('0x3f')]['id']}},_0x2fb4fd,_0x9d15e,_0x2a3b03,_0x493779,_0x5a8714;_0x2ca870=_[_0x9f24('0x38')]({},_0x2ca870,_0x415624[_0x9f24('0x39')]);return db[_0x9f24('0x27')][_0x9f24('0x4b')](_0x2ca870)[_0x9f24('0x1e')](function(_0x2d7734){if(_0x2d7734){_0x2fb4fd=_0x2d7734;return _0x2d7734[_0x9f24('0x66')]();}return null;})[_0x9f24('0x1e')](function(_0x39e8ce){if(_0x39e8ce){if(!_0x39e8ce[_0x9f24('0x31')]){throw new db['Sequelize'][(_0x9f24('0x67'))](_0x9f24('0x68'),0x193);}_0x9d15e=_0x39e8ce;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})[_0x9f24('0x1e')](function(_0x285f8c){if(_0x285f8c){_0x2a3b03=_[_0x9f24('0x69')](_0x285f8c,'id');var _0x7be9d8;var _0x56a022=squel[_0x9f24('0x6a')]();_0x56a022[_0x9f24('0x6b')](_0x2fb4fd[_0x9f24('0x6c')]);for(var _0x5645af=0x0;_0x5645af<_0x9d15e[_0x9f24('0x31')];_0x5645af+=0x1){_0x7be9d8=_0x9d15e[_0x5645af][_0x9f24('0x6d')]?_0x2a3b03[_0x9d15e[_0x5645af][_0x9f24('0x6d')]][_0x9f24('0x6e')]:_0x9d15e[_0x5645af][_0x9f24('0x63')];_0x7be9d8=_0x9d15e[_0x5645af][_0x9f24('0x6f')]?_[_0x9f24('0x70')](_0x52c16b[_0x9d15e[_0x5645af]['function']],'%s',_0x7be9d8):_0x7be9d8;_0x7be9d8=_0x9d15e[_0x5645af][_0x9f24('0x71')]?_[_0x9f24('0x70')](_0x4e9b3c[_0x9d15e[_0x5645af][_0x9f24('0x71')]],'%s',_0x7be9d8):_0x7be9d8;if(_0x9d15e[_0x5645af][_0x9f24('0x72')]){_0x56a022[_0x9f24('0x62')](_0x7be9d8);}_0x9d15e[_0x5645af]['orderBy']&&_0x56a022[_0x9f24('0x33')](_0x7be9d8,_0x9d15e[_0x5645af][_0x9f24('0x73')]===_0x9f24('0x74')?![]:!![]);_0x56a022[_0x9f24('0x63')](_0x7be9d8,_0x9d15e[_0x5645af][_0x9f24('0x75')]||_0x7be9d8);}if(_0x2fb4fd[_0x9f24('0x76')]){_0x2fb4fd['joins']=JSON[_0x9f24('0x77')](_0x2fb4fd[_0x9f24('0x76')]);for(var _0x1aba72=0x0;_0x1aba72<_0x2fb4fd['joins'][_0x9f24('0x31')];_0x1aba72+=0x1){if(_0x2fb4fd[_0x9f24('0x76')][_0x1aba72][_0x9f24('0x29')]&&_['includes'](_0x46ddfe,_0x2fb4fd[_0x9f24('0x76')][_0x1aba72]['type'])&&_0x2fb4fd['joins'][_0x1aba72][_0x9f24('0x78')]&&_0x2fb4fd[_0x9f24('0x76')][_0x1aba72][_0x9f24('0x79')]&&_0x2fb4fd[_0x9f24('0x76')][_0x1aba72][_0x9f24('0x7a')]){_0x56a022[_0x2fb4fd['joins'][_0x1aba72][_0x9f24('0x29')]](_0x2fb4fd[_0x9f24('0x76')][_0x1aba72][_0x9f24('0x79')],null,util[_0x9f24('0x71')](_0x9f24('0x7b'),_0x2fb4fd[_0x9f24('0x6c')],_0x2fb4fd[_0x9f24('0x76')][_0x1aba72]['parentKey'],_0x2fb4fd[_0x9f24('0x76')][_0x1aba72]['foreignTable'],_0x2fb4fd[_0x9f24('0x76')][_0x1aba72]['foreignKey']));}}}if(_0x2fb4fd['conditions']){_0x2fb4fd[_0x9f24('0x7c')]=JSON['parse'](_0x2fb4fd[_0x9f24('0x7c')]);_0x56a022[_0x9f24('0x35')](_0x593e5e(_0x2fb4fd[_0x9f24('0x7c')][_0x9f24('0x62')]));}_0x5a8714=_0x56a022['clone']();_0x56a022['limit'](_0x5b2f20);_0x56a022[_0x9f24('0x18')](0x0);logger[_0x9f24('0x7d')]('Limited\x20Query:',_0x56a022[_0x9f24('0x7e')]());return dbH[_0x9f24('0x7f')][_0x9f24('0x2c')](_0x56a022[_0x9f24('0x7e')](),{'type':dbH['sequelize'][_0x9f24('0x80')][_0x9f24('0x81')]});}})['then'](respondWithResult(_0xaef109,null))['catch'](handleError(_0xaef109,null));};function runReport(_0x464c27,_0x237c6b,_0x16cd66){var _0xf3f2c3=_0x237c6b[_0x9f24('0x24')];var _0x467582=0xa;var _0x232672=[_0x9f24('0x4d'),_0x9f24('0x4e'),'right_join',_0x9f24('0x50')];var _0x19977a={'SUM':_0x9f24('0x51'),'COUNT':_0x9f24('0x52'),'COUNT DISTINCT':_0x9f24('0x53'),'MAX':_0x9f24('0x54'),'MIN':_0x9f24('0x82'),'AVG':_0x9f24('0x55'),'GROUP_CONCAT':_0x9f24('0x56'),'GROUP_CONCAT ASC':_0x9f24('0x57'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x8d9580={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x9f24('0x59'),'HOUR':_0x9f24('0x5a'),'ROUND':_0x9f24('0x5b'),'UNIX_TIMESTAMP':_0x9f24('0x5c')};var _0x48978a=function(_0xdefddd){return!_[_0x9f24('0x5d')]([_0x9f24('0x83'),_0x9f24('0x5e'),_0x9f24('0x5f'),_0x9f24('0x84')],_0xdefddd);};var _0x53927a=function(_0x4bef35){if(!_0x4bef35||!_0x4bef35[_0x9f24('0x60')][_0x9f24('0x31')]){return'';}for(var _0x3091fa='(',_0x1c23ac=0x0;_0x1c23ac<_0x4bef35['rules'][_0x9f24('0x31')];_0x1c23ac+=0x1){_0x1c23ac>0x0&&(_0x3091fa+='\x20'+_0x4bef35[_0x9f24('0x61')]+'\x20');_0x3091fa+=_0x4bef35['rules'][_0x1c23ac][_0x9f24('0x62')]?_0x53927a(_0x4bef35[_0x9f24('0x60')][_0x1c23ac][_0x9f24('0x62')]):_0x4bef35[_0x9f24('0x60')][_0x1c23ac]['field']+'\x20'+_0x4bef35[_0x9f24('0x60')][_0x1c23ac]['condition']+(_0x48978a(_0x4bef35[_0x9f24('0x60')][_0x1c23ac][_0x9f24('0x64')])?'\x20'+_0x4bef35[_0x9f24('0x60')][_0x1c23ac][_0x9f24('0x65')]:'');}return _0x3091fa+')';};var _0x3cdc5c={'where':{'id':_0x464c27['id']}},_0x87c730,_0x215765,_0x347a85,_0x29fb22,_0x3e3cfe;_0x3cdc5c=_['merge']({},_0x3cdc5c,_0x16cd66);return db[_0x9f24('0x27')][_0x9f24('0x4b')](_0x3cdc5c)[_0x9f24('0x1e')](function(_0x56962f){if(_0x56962f){_0x87c730=_0x56962f;return _0x56962f['getFields']();}return null;})[_0x9f24('0x1e')](function(_0x203830){if(_0x203830){if(!_0x203830['length']){throw new db[(_0x9f24('0x85'))][(_0x9f24('0x67'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x215765=_0x203830;return db['AnalyticMetric'][_0x9f24('0x3c')]({'raw':!![]});}return null;})[_0x9f24('0x1e')](function(_0x2eab3e){if(_0x2eab3e){_0x347a85=_[_0x9f24('0x69')](_0x2eab3e,'id');var _0xa3e491;var _0x251067=squel[_0x9f24('0x6a')]();_0x251067[_0x9f24('0x6b')](_0x87c730['table']);for(var _0x3f5f54=0x0;_0x3f5f54<_0x215765['length'];_0x3f5f54+=0x1){_0xa3e491=_0x215765[_0x3f5f54][_0x9f24('0x6d')]?_0x347a85[_0x215765[_0x3f5f54]['MetricId']][_0x9f24('0x6e')]:_0x215765[_0x3f5f54][_0x9f24('0x63')];_0xa3e491=_0x215765[_0x3f5f54][_0x9f24('0x6f')]?_[_0x9f24('0x70')](_0x19977a[_0x215765[_0x3f5f54][_0x9f24('0x6f')]],'%s',_0xa3e491):_0xa3e491;_0xa3e491=_0x215765[_0x3f5f54]['format']?_[_0x9f24('0x70')](_0x8d9580[_0x215765[_0x3f5f54]['format']],'%s',_0xa3e491):_0xa3e491;if(_0x215765[_0x3f5f54]['groupBy']){_0x251067[_0x9f24('0x62')](_0xa3e491);}_0x215765[_0x3f5f54][_0x9f24('0x73')]&&_0x251067['order'](_0xa3e491,_0x215765[_0x3f5f54][_0x9f24('0x73')]===_0x9f24('0x74')?![]:!![]);_0x251067[_0x9f24('0x63')](_0xa3e491,_0x215765[_0x3f5f54]['alias']||_0xa3e491);}if(_0x87c730['joins']){_0x87c730[_0x9f24('0x76')]=JSON[_0x9f24('0x77')](_0x87c730[_0x9f24('0x76')]);for(var _0x5a9e4b=0x0;_0x5a9e4b<_0x87c730[_0x9f24('0x76')][_0x9f24('0x31')];_0x5a9e4b+=0x1){if(_0x87c730['joins'][_0x5a9e4b][_0x9f24('0x29')]&&_[_0x9f24('0x5d')](_0x232672,_0x87c730[_0x9f24('0x76')][_0x5a9e4b][_0x9f24('0x29')])&&_0x87c730[_0x9f24('0x76')][_0x5a9e4b][_0x9f24('0x78')]&&_0x87c730['joins'][_0x5a9e4b]['foreignTable']&&_0x87c730[_0x9f24('0x76')][_0x5a9e4b]['foreignKey']){_0x251067[_0x87c730[_0x9f24('0x76')][_0x5a9e4b][_0x9f24('0x29')]](_0x87c730[_0x9f24('0x76')][_0x5a9e4b]['foreignTable'],null,util[_0x9f24('0x71')](_0x9f24('0x7b'),_0x87c730[_0x9f24('0x6c')],_0x87c730[_0x9f24('0x76')][_0x5a9e4b]['parentKey'],_0x87c730[_0x9f24('0x76')][_0x5a9e4b][_0x9f24('0x79')],_0x87c730[_0x9f24('0x76')][_0x5a9e4b][_0x9f24('0x7a')]));}}}if(_0x87c730['conditions']){_0x87c730['conditions']=JSON[_0x9f24('0x77')](_0x87c730[_0x9f24('0x7c')]);_0x251067['where'](_0x53927a(_0x87c730['conditions'][_0x9f24('0x62')]));}_0x3e3cfe=_0x251067['clone']();_0x251067[_0x9f24('0x19')](_0x467582);_0x251067[_0x9f24('0x18')](0x0);return;}})['then'](function(){if(_0x237c6b[_0x9f24('0x86')]===_0x9f24('0x87')){return null;}var _0x351491=_[_0x9f24('0x38')](_0x237c6b,{'name':_0x237c6b['fullPath']||_0x237c6b['name']||_0x87c730['name'],'basename':_0xf3f2c3,'savename':util[_0x9f24('0x71')]('%s-%s.%s',_0x237c6b[_0x9f24('0x24')]||_0x87c730[_0x9f24('0x24')],require('randomstring')[_0x9f24('0x88')](0x4),_0x237c6b[_0x9f24('0x86')]||'csv'),'reportId':_0x87c730['id'],'reportType':'custom'});return db[_0x9f24('0x89')][_0x9f24('0x42')](_0x351491,{'raw':!![]});})[_0x9f24('0x1e')](function(_0x5ebcfb){if(_0x87c730['table']==='cdr'){_0x3e3cfe['where'](_0x87c730[_0x9f24('0x6c')]+_0x9f24('0x8a'),_0x237c6b['startDate'],_0x237c6b[_0x9f24('0x8b')]);}else{_0x3e3cfe['where'](_0x87c730[_0x9f24('0x6c')]+_0x9f24('0x8c'),_0x237c6b['startDate'],_0x237c6b['endDate']);}if(_0x5ebcfb){logger[_0x9f24('0x8d')](_0x9f24('0x8e'),_0x3e3cfe[_0x9f24('0x7e')]());require('child_process')[_0x9f24('0x8f')](path[_0x9f24('0x4d')](__dirname,_0x9f24('0x90'),_0x5ebcfb[_0x9f24('0x86')]),[_0x5ebcfb['id'],_0x3e3cfe[_0x9f24('0x7e')](),path[_0x9f24('0x4d')](__dirname,'../../files/reports',_0x5ebcfb[_0x9f24('0x91')]),_0xf3f2c3]);return _0x5ebcfb;}else{var _0x55d00f=squel[_0x9f24('0x6a')]();_0x55d00f[_0x9f24('0x6b')]('('+_0x3e3cfe[_0x9f24('0x7e')]()+')',_0x9f24('0x92'));_0x55d00f[_0x9f24('0x63')](_0x9f24('0x93'),_0x9f24('0x17'));_0x3e3cfe[_0x9f24('0x19')](_0x237c6b[_0x9f24('0x19')]||_0x467582);_0x3e3cfe[_0x9f24('0x18')](_0x237c6b[_0x9f24('0x18')]||0x0);return dbH['sequelize'][_0x9f24('0x2c')](_0x55d00f[_0x9f24('0x7e')](),{'type':dbH['sequelize'][_0x9f24('0x80')]['SELECT']})[_0x9f24('0x1e')](function(_0x3c7090){if(!_0x3c7090['length']){_0x29fb22=0x0;}else{_0x29fb22=_0x3c7090[0x0]['count']||0x0;}return dbH[_0x9f24('0x7f')][_0x9f24('0x2c')](_0x3e3cfe[_0x9f24('0x7e')](),{'type':dbH['sequelize'][_0x9f24('0x80')][_0x9f24('0x81')]});})[_0x9f24('0x1e')](function(_0x3dacdc){return{'rows':_0x3dacdc||[],'count':_0x29fb22};});}});}exports[_0x9f24('0x94')]=function(_0x147c3d,_0x5118c0){return runReport(_0x147c3d[_0x9f24('0x3f')],_0x147c3d[_0x9f24('0x2c')],_0x147c3d[_0x9f24('0x39')])[_0x9f24('0x1e')](respondWithResult(_0x5118c0,null))[_0x9f24('0x3d')](handleError(_0x5118c0,null));};exports[_0x9f24('0x95')]=runReport;exports[_0x9f24('0x2c')]=function(_0x4066b9,_0x42ce88){var _0x4dd9d8=0xa;var _0x4cf8bd=[_0x9f24('0x4d'),_0x9f24('0x4e'),_0x9f24('0x4f'),'cross_join'];var _0x46ce03={'SUM':'SUM(%s)','COUNT':_0x9f24('0x52'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x9f24('0x54'),'MIN':_0x9f24('0x82'),'AVG':_0x9f24('0x55'),'GROUP_CONCAT':_0x9f24('0x56'),'GROUP_CONCAT ASC':_0x9f24('0x57'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x313759={'SEC_TO_TIME':_0x9f24('0x96'),'DATE':_0x9f24('0x59'),'HOUR':_0x9f24('0x5a'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x50328f=function(_0x40aa72){return!_[_0x9f24('0x5d')]([_0x9f24('0x83'),'IS\x20NOT\x20NULL',_0x9f24('0x5f'),_0x9f24('0x84')],_0x40aa72);};var _0x599d73=function(_0xf9a8ba){if(!_0xf9a8ba||!_0xf9a8ba[_0x9f24('0x60')][_0x9f24('0x31')]){return'';}for(var _0x26fb00='(',_0x2a85dd=0x0;_0x2a85dd<_0xf9a8ba[_0x9f24('0x60')]['length'];_0x2a85dd+=0x1){_0x2a85dd>0x0&&(_0x26fb00+='\x20'+_0xf9a8ba['operator']+'\x20');_0x26fb00+=_0xf9a8ba[_0x9f24('0x60')][_0x2a85dd][_0x9f24('0x62')]?_0x599d73(_0xf9a8ba[_0x9f24('0x60')][_0x2a85dd][_0x9f24('0x62')]):_0xf9a8ba['rules'][_0x2a85dd][_0x9f24('0x63')]+'\x20'+_0xf9a8ba[_0x9f24('0x60')][_0x2a85dd][_0x9f24('0x64')]+(_0x50328f(_0xf9a8ba[_0x9f24('0x60')][_0x2a85dd]['condition'])?'\x20'+_0xf9a8ba[_0x9f24('0x60')][_0x2a85dd][_0x9f24('0x65')]:'');}return _0x26fb00+')';};var _0x24eb56={'where':{'id':_0x4066b9[_0x9f24('0x3f')]['id']}},_0x39cfe6,_0x337c24,_0x52ea89,_0x4d74c6,_0x1f48e2;_0x24eb56=_[_0x9f24('0x38')]({},_0x24eb56,_0x4066b9[_0x9f24('0x39')]);return db['AnalyticCustomReport']['find'](_0x24eb56)[_0x9f24('0x1e')](function(_0x501ab0){if(_0x501ab0){_0x39cfe6=_0x501ab0;return _0x501ab0[_0x9f24('0x66')]();}return null;})[_0x9f24('0x1e')](function(_0x5ba582){if(_0x5ba582){if(!_0x5ba582[_0x9f24('0x31')]){throw new db[(_0x9f24('0x85'))][(_0x9f24('0x67'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x337c24=_0x5ba582;return db[_0x9f24('0x97')][_0x9f24('0x3c')]({'raw':!![]});}return null;})[_0x9f24('0x1e')](function(_0xabab1b){if(_0xabab1b){_0x52ea89=_['keyBy'](_0xabab1b,'id');var _0x4365d9;var _0x5e9678=squel[_0x9f24('0x6a')]();_0x5e9678[_0x9f24('0x6b')](_0x39cfe6[_0x9f24('0x6c')]);for(var _0x4d5be9=0x0;_0x4d5be9<_0x337c24[_0x9f24('0x31')];_0x4d5be9+=0x1){_0x4365d9=_0x337c24[_0x4d5be9][_0x9f24('0x6d')]?_0x52ea89[_0x337c24[_0x4d5be9][_0x9f24('0x6d')]][_0x9f24('0x6e')]:_0x337c24[_0x4d5be9][_0x9f24('0x63')];_0x4365d9=_0x337c24[_0x4d5be9][_0x9f24('0x6f')]?_[_0x9f24('0x70')](_0x46ce03[_0x337c24[_0x4d5be9][_0x9f24('0x6f')]],'%s',_0x4365d9):_0x4365d9;_0x4365d9=_0x337c24[_0x4d5be9]['format']?_[_0x9f24('0x70')](_0x313759[_0x337c24[_0x4d5be9]['format']],'%s',_0x4365d9):_0x4365d9;if(_0x337c24[_0x4d5be9][_0x9f24('0x72')]){_0x5e9678[_0x9f24('0x62')](_0x4365d9);}_0x337c24[_0x4d5be9][_0x9f24('0x73')]&&_0x5e9678[_0x9f24('0x33')](_0x4365d9,_0x337c24[_0x4d5be9][_0x9f24('0x73')]==='DESC'?![]:!![]);_0x5e9678[_0x9f24('0x63')](_0x4365d9,_0x337c24[_0x4d5be9][_0x9f24('0x75')]||_0x4365d9);}if(_0x39cfe6[_0x9f24('0x76')]){_0x39cfe6['joins']=JSON[_0x9f24('0x77')](_0x39cfe6[_0x9f24('0x76')]);for(var _0x1301f3=0x0;_0x1301f3<_0x39cfe6[_0x9f24('0x76')]['length'];_0x1301f3+=0x1){if(_0x39cfe6[_0x9f24('0x76')][_0x1301f3]['type']&&_[_0x9f24('0x5d')](_0x4cf8bd,_0x39cfe6[_0x9f24('0x76')][_0x1301f3][_0x9f24('0x29')])&&_0x39cfe6[_0x9f24('0x76')][_0x1301f3][_0x9f24('0x78')]&&_0x39cfe6[_0x9f24('0x76')][_0x1301f3][_0x9f24('0x79')]&&_0x39cfe6[_0x9f24('0x76')][_0x1301f3][_0x9f24('0x7a')]){_0x5e9678[_0x39cfe6[_0x9f24('0x76')][_0x1301f3][_0x9f24('0x29')]](_0x39cfe6['joins'][_0x1301f3][_0x9f24('0x79')],null,util[_0x9f24('0x71')](_0x9f24('0x7b'),_0x39cfe6[_0x9f24('0x6c')],_0x39cfe6['joins'][_0x1301f3]['parentKey'],_0x39cfe6[_0x9f24('0x76')][_0x1301f3][_0x9f24('0x79')],_0x39cfe6[_0x9f24('0x76')][_0x1301f3]['foreignKey']));}}}if(_0x39cfe6['conditions']){_0x39cfe6['conditions']=JSON[_0x9f24('0x77')](_0x39cfe6[_0x9f24('0x7c')]);_0x5e9678[_0x9f24('0x35')](_0x599d73(_0x39cfe6['conditions'][_0x9f24('0x62')]));}_0x1f48e2=_0x5e9678[_0x9f24('0x98')]();_0x5e9678[_0x9f24('0x19')](_0x4dd9d8);_0x5e9678['offset'](0x0);logger[_0x9f24('0x7d')](_0x9f24('0x99'),_0x5e9678[_0x9f24('0x7e')]());return dbH[_0x9f24('0x7f')][_0x9f24('0x2c')](_0x5e9678[_0x9f24('0x7e')](),{'type':dbH['sequelize'][_0x9f24('0x80')][_0x9f24('0x81')]});}})[_0x9f24('0x1e')](function(){return{'sql':_0x1f48e2[_0x9f24('0x7e')]()};})[_0x9f24('0x1e')](respondWithResult(_0x42ce88,null))[_0x9f24('0x3d')](handleError(_0x42ce88,null));};
\ No newline at end of file
+var _0x12b8=['includeAll','include','findAll','params','rawAttributes','find','catch','create','body','user','role','Reports','UserProfileSection','userProfileId','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','preview','join','left_join','right_join','cross_join','SUM(%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','rules','group','field','condition','value','getFields','Sequelize','ValidationErrorItem','AnalyticMetric','keyBy','from','table','MetricId','function','replace','format','groupBy','orderBy','DESC','alias','joins','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','parentKey','conditions','parse','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','SELECT','COUNT(%s)','COUNT(DISTINCT\x20%s)','IS\x20NOT\x20EMPTY','operator','Please\x20insert\x20at\x20least\x20one\x20field','select','metric','output','web','fullPath','%s-%s.%s','generate','csv','custom','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','.createdAt\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','info','child_process','../../components/export/','savename','countTable','COUNT(*)','run','runReport','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','squel','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','end','json','undefined','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','get','CustomReports','error','stack','send','index','map','AnalyticCustomReport','fieldName','type','key','keys','intersection','model','query','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','name','merge','options'];(function(_0x4906c8,_0x41119e){var _0x1a0b9d=function(_0x124f3e){while(--_0x124f3e){_0x4906c8['push'](_0x4906c8['shift']());}};_0x1a0b9d(++_0x41119e);}(_0x12b8,0x1b5));var _0x812b=function(_0x15fe68,_0xddc145){_0x15fe68=_0x15fe68-0x0;var _0x1d144c=_0x12b8[_0x15fe68];return _0x1d144c;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x812b('0x0'));var jsonpatch=require(_0x812b('0x1'));var rp=require(_0x812b('0x2'));var moment=require(_0x812b('0x3'));var BPromise=require(_0x812b('0x4'));var Mustache=require(_0x812b('0x5'));var util=require(_0x812b('0x6'));var path=require(_0x812b('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x812b('0x8'));var fs=require('fs');var fs_extra=require(_0x812b('0x9'));var _=require(_0x812b('0xa'));var squel=require(_0x812b('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x812b('0xc'));var querystring=require(_0x812b('0xd'));var Papa=require(_0x812b('0xe'));var Redis=require(_0x812b('0xf'));var authService=require(_0x812b('0x10'));var qs=require(_0x812b('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x812b('0x12'));var logger=require(_0x812b('0x13'))(_0x812b('0x14'));var utils=require(_0x812b('0x15'));var config=require(_0x812b('0x16'));var licenseUtil=require(_0x812b('0x17'));var db=require(_0x812b('0x18'))['db'];var dbH=require(_0x812b('0x18'))[_0x812b('0x19')];function respondWithStatusCode(_0x4708d7,_0x3a893e){_0x3a893e=_0x3a893e||0xcc;return function(_0xc4d62){if(_0xc4d62){return _0x4708d7[_0x812b('0x1a')](_0x3a893e);}return _0x4708d7[_0x812b('0x1b')](_0x3a893e)[_0x812b('0x1c')]();};}function respondWithResult(_0x3d3eff,_0x18ba01){_0x18ba01=_0x18ba01||0xc8;return function(_0x592a83){if(_0x592a83){return _0x3d3eff[_0x812b('0x1b')](_0x18ba01)[_0x812b('0x1d')](_0x592a83);}};}function respondWithFilteredResult(_0x161f62,_0x3303b2){return function(_0xef9f3f){if(_0xef9f3f){var _0x13faf9=typeof _0x3303b2['offset']===_0x812b('0x1e')&&typeof _0x3303b2['limit']===_0x812b('0x1e');var _0x26d85f=_0xef9f3f[_0x812b('0x1f')];var _0x257aee=_0x13faf9?0x0:_0x3303b2[_0x812b('0x20')];var _0x2a042f=_0x13faf9?_0xef9f3f[_0x812b('0x1f')]:_0x3303b2[_0x812b('0x20')]+_0x3303b2[_0x812b('0x21')];var _0x2489b6;if(_0x2a042f>=_0x26d85f){_0x2a042f=_0x26d85f;_0x2489b6=0xc8;}else{_0x2489b6=0xce;}_0x161f62['status'](_0x2489b6);return _0x161f62[_0x812b('0x22')](_0x812b('0x23'),_0x257aee+'-'+_0x2a042f+'/'+_0x26d85f)[_0x812b('0x1d')](_0xef9f3f);}return null;};}function patchUpdates(_0x1f574f){return function(_0x1e1ffc){try{jsonpatch[_0x812b('0x24')](_0x1e1ffc,_0x1f574f,!![]);}catch(_0x45ee2d){return BPromise[_0x812b('0x25')](_0x45ee2d);}return _0x1e1ffc[_0x812b('0x26')]();};}function saveUpdates(_0xbb9bac,_0x39601b){return function(_0x586fe3){if(_0x586fe3){return _0x586fe3[_0x812b('0x27')](_0xbb9bac)[_0x812b('0x28')](function(_0x44edc5){return _0x44edc5;});}return null;};}function removeEntity(_0x3ad4a9,_0x5be22f){return function(_0x234178){if(_0x234178){return _0x234178[_0x812b('0x29')]()['then'](function(){var _0x4c3610=_0x234178[_0x812b('0x2a')]({'plain':!![]});var _0x417fed=_0x812b('0x2b');return db['UserProfileResource'][_0x812b('0x29')]({'where':{'type':_0x417fed,'resourceId':_0x4c3610['id']}})[_0x812b('0x28')](function(){return _0x234178;});})[_0x812b('0x28')](function(){_0x3ad4a9['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x354038,_0x160a37){return function(_0x1c9dea){if(!_0x1c9dea){_0x354038[_0x812b('0x1a')](0x194);}return _0x1c9dea;};}function handleError(_0x297b77,_0x171585){_0x171585=_0x171585||0x1f4;return function(_0x1fd2f2){logger[_0x812b('0x2c')](_0x1fd2f2[_0x812b('0x2d')]);if(_0x1fd2f2['name']){delete _0x1fd2f2['name'];}_0x297b77[_0x812b('0x1b')](_0x171585)[_0x812b('0x2e')](_0x1fd2f2);};}exports[_0x812b('0x2f')]=function(_0x31adce,_0xe359be){var _0x1690ce={},_0x16a0fd={},_0x156fef={'count':0x0,'rows':[]};var _0x42e44a=_[_0x812b('0x30')](db[_0x812b('0x31')]['rawAttributes'],function(_0x1b7194){return{'name':_0x1b7194[_0x812b('0x32')],'type':_0x1b7194[_0x812b('0x33')][_0x812b('0x34')]};});_0x16a0fd['model']=_[_0x812b('0x30')](_0x42e44a,'name');_0x16a0fd['query']=_[_0x812b('0x35')](_0x31adce['query']);_0x16a0fd['filters']=_[_0x812b('0x36')](_0x16a0fd[_0x812b('0x37')],_0x16a0fd[_0x812b('0x38')]);_0x1690ce['attributes']=_[_0x812b('0x36')](_0x16a0fd[_0x812b('0x37')],qs[_0x812b('0x39')](_0x31adce[_0x812b('0x38')][_0x812b('0x39')]));_0x1690ce[_0x812b('0x3a')]=_0x1690ce[_0x812b('0x3a')][_0x812b('0x3b')]?_0x1690ce[_0x812b('0x3a')]:_0x16a0fd[_0x812b('0x37')];if(!_0x31adce[_0x812b('0x38')][_0x812b('0x3c')](_0x812b('0x3d'))){_0x1690ce[_0x812b('0x21')]=qs['limit'](_0x31adce[_0x812b('0x38')][_0x812b('0x21')]);_0x1690ce['offset']=qs['offset'](_0x31adce[_0x812b('0x38')][_0x812b('0x20')]);}_0x1690ce[_0x812b('0x3e')]=qs[_0x812b('0x3f')](_0x31adce[_0x812b('0x38')]['sort']);_0x1690ce[_0x812b('0x40')]=qs[_0x812b('0x41')](_[_0x812b('0x42')](_0x31adce[_0x812b('0x38')],_0x16a0fd[_0x812b('0x41')]),_0x42e44a);if(_0x31adce[_0x812b('0x38')]['filter']){_0x1690ce[_0x812b('0x40')]=_['merge'](_0x1690ce[_0x812b('0x40')],{'$or':_[_0x812b('0x30')](_0x42e44a,function(_0x17a50a){if(_0x17a50a[_0x812b('0x33')]!=='VIRTUAL'){var _0x4debad={};_0x4debad[_0x17a50a[_0x812b('0x43')]]={'$like':'%'+_0x31adce[_0x812b('0x38')]['filter']+'%'};return _0x4debad;}})});}_0x1690ce=_[_0x812b('0x44')]({},_0x1690ce,_0x31adce[_0x812b('0x45')]);var _0x21723b={'where':_0x1690ce['where']};return db[_0x812b('0x31')][_0x812b('0x1f')](_0x21723b)[_0x812b('0x28')](function(_0x40c6fe){_0x156fef[_0x812b('0x1f')]=_0x40c6fe;if(_0x31adce['query'][_0x812b('0x46')]){_0x1690ce[_0x812b('0x47')]=[{'all':!![]}];}return db[_0x812b('0x31')][_0x812b('0x48')](_0x1690ce);})['then'](function(_0x20d429){_0x156fef['rows']=_0x20d429;return _0x156fef;})[_0x812b('0x28')](respondWithFilteredResult(_0xe359be,_0x1690ce))['catch'](handleError(_0xe359be,null));};exports['show']=function(_0x2713a0,_0x5b2cb2){var _0x482723={'raw':![],'where':{'id':_0x2713a0[_0x812b('0x49')]['id']}},_0x2087b5={};_0x2087b5[_0x812b('0x37')]=_[_0x812b('0x35')](db['AnalyticCustomReport'][_0x812b('0x4a')]);_0x2087b5[_0x812b('0x38')]=_[_0x812b('0x35')](_0x2713a0[_0x812b('0x38')]);_0x2087b5[_0x812b('0x41')]=_['intersection'](_0x2087b5[_0x812b('0x37')],_0x2087b5['query']);_0x482723[_0x812b('0x3a')]=_[_0x812b('0x36')](_0x2087b5[_0x812b('0x37')],qs[_0x812b('0x39')](_0x2713a0['query'][_0x812b('0x39')]));_0x482723[_0x812b('0x3a')]=_0x482723[_0x812b('0x3a')]['length']?_0x482723[_0x812b('0x3a')]:_0x2087b5[_0x812b('0x37')];if(_0x2713a0[_0x812b('0x38')]['includeAll']){_0x482723[_0x812b('0x47')]=[{'all':!![]}];}_0x482723=_['merge']({},_0x482723,_0x2713a0[_0x812b('0x45')]);return db['AnalyticCustomReport'][_0x812b('0x4b')](_0x482723)[_0x812b('0x28')](handleEntityNotFound(_0x5b2cb2,null))[_0x812b('0x28')](respondWithResult(_0x5b2cb2,null))[_0x812b('0x4c')](handleError(_0x5b2cb2,null));};exports[_0x812b('0x4d')]=function(_0x3bd80f,_0x12badf){return db[_0x812b('0x31')][_0x812b('0x4d')](_0x3bd80f[_0x812b('0x4e')],{})[_0x812b('0x28')](function(_0x5eae6f){var _0x2fce5b=_0x3bd80f[_0x812b('0x4f')]['get']({'plain':!![]});if(!_0x2fce5b)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x2fce5b[_0x812b('0x50')]===_0x812b('0x4f')){var _0x36e362=_0x5eae6f[_0x812b('0x2a')]({'plain':!![]});var _0x59620b=_0x812b('0x51');return db[_0x812b('0x52')][_0x812b('0x4b')]({'where':{'name':_0x59620b,'userProfileId':_0x2fce5b[_0x812b('0x53')]},'raw':!![]})[_0x812b('0x28')](function(_0x40fd8b){if(_0x40fd8b&&_0x40fd8b[_0x812b('0x54')]===0x0){return db[_0x812b('0x55')][_0x812b('0x4d')]({'name':_0x36e362[_0x812b('0x43')],'resourceId':_0x36e362['id'],'type':_0x812b('0x2b'),'sectionId':_0x40fd8b['id']},{})['then'](function(){return _0x5eae6f;});}else{return _0x5eae6f;}})['catch'](function(_0x1097cb){logger[_0x812b('0x2c')](_0x812b('0x56'),_0x1097cb);throw _0x1097cb;});}return _0x5eae6f;})[_0x812b('0x28')](respondWithResult(_0x12badf,0xc9))[_0x812b('0x4c')](handleError(_0x12badf,null));};exports[_0x812b('0x27')]=function(_0xf7b6fe,_0x5ad721){if(_0xf7b6fe[_0x812b('0x4e')]['id']){delete _0xf7b6fe[_0x812b('0x4e')]['id'];}return db[_0x812b('0x31')]['find']({'where':{'id':_0xf7b6fe['params']['id']}})[_0x812b('0x28')](handleEntityNotFound(_0x5ad721,null))['then'](saveUpdates(_0xf7b6fe[_0x812b('0x4e')],null))[_0x812b('0x28')](respondWithResult(_0x5ad721,null))[_0x812b('0x4c')](handleError(_0x5ad721,null));};exports[_0x812b('0x29')]=function(_0x1c98ed,_0x244158){return db['AnalyticCustomReport'][_0x812b('0x4b')]({'where':{'id':_0x1c98ed[_0x812b('0x49')]['id']}})[_0x812b('0x28')](handleEntityNotFound(_0x244158,null))['then'](removeEntity(_0x244158,null))[_0x812b('0x4c')](handleError(_0x244158,null));};exports[_0x812b('0x57')]=function(_0x21fef8,_0x48b815){var _0x91f3d0=0xa;var _0x783dbd=[_0x812b('0x58'),_0x812b('0x59'),_0x812b('0x5a'),_0x812b('0x5b')];var _0x5ad34c={'SUM':_0x812b('0x5c'),'COUNT':'COUNT(%s)','COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x812b('0x5d'),'MIN':_0x812b('0x5e'),'AVG':_0x812b('0x5f'),'GROUP_CONCAT':_0x812b('0x60'),'GROUP_CONCAT ASC':_0x812b('0x61'),'GROUP_CONCAT DESC':_0x812b('0x62')};var _0x2a2f72={'SEC_TO_TIME':_0x812b('0x63'),'DATE':_0x812b('0x64'),'HOUR':_0x812b('0x65'),'ROUND':_0x812b('0x66'),'UNIX_TIMESTAMP':_0x812b('0x67')};var _0x25702b=function(_0x40b81b){return!_[_0x812b('0x68')]([_0x812b('0x69'),_0x812b('0x6a'),'IS\x20EMPTY','IS\x20NOT\x20EMPTY'],_0x40b81b);};var _0x177e66=function(_0x30eac3){if(!_0x30eac3||!_0x30eac3[_0x812b('0x6b')]['length']){return'';}for(var _0x527cc1='(',_0x5bdbb9=0x0;_0x5bdbb9<_0x30eac3[_0x812b('0x6b')][_0x812b('0x3b')];_0x5bdbb9+=0x1){_0x5bdbb9>0x0&&(_0x527cc1+='\x20'+_0x30eac3['operator']+'\x20');_0x527cc1+=_0x30eac3[_0x812b('0x6b')][_0x5bdbb9]['group']?_0x177e66(_0x30eac3[_0x812b('0x6b')][_0x5bdbb9][_0x812b('0x6c')]):_0x30eac3[_0x812b('0x6b')][_0x5bdbb9][_0x812b('0x6d')]+'\x20'+_0x30eac3[_0x812b('0x6b')][_0x5bdbb9][_0x812b('0x6e')]+(_0x25702b(_0x30eac3[_0x812b('0x6b')][_0x5bdbb9][_0x812b('0x6e')])?'\x20'+_0x30eac3[_0x812b('0x6b')][_0x5bdbb9][_0x812b('0x6f')]:'');}return _0x527cc1+')';};var _0x478a10={'where':{'id':_0x21fef8['params']['id']}},_0x45da53,_0x4d6b9a,_0x355059,_0x50bf86,_0x1c3603;_0x478a10=_[_0x812b('0x44')]({},_0x478a10,_0x21fef8[_0x812b('0x45')]);return db['AnalyticCustomReport'][_0x812b('0x4b')](_0x478a10)[_0x812b('0x28')](function(_0x50ab03){if(_0x50ab03){_0x45da53=_0x50ab03;return _0x50ab03[_0x812b('0x70')]();}return null;})[_0x812b('0x28')](function(_0x1e86cd){if(_0x1e86cd){if(!_0x1e86cd['length']){throw new db[(_0x812b('0x71'))][(_0x812b('0x72'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x4d6b9a=_0x1e86cd;return db[_0x812b('0x73')][_0x812b('0x48')]({'raw':!![]});}return null;})[_0x812b('0x28')](function(_0x14219a){if(_0x14219a){_0x355059=_[_0x812b('0x74')](_0x14219a,'id');var _0x2db249;var _0xc83017=squel['select']();_0xc83017[_0x812b('0x75')](_0x45da53[_0x812b('0x76')]);for(var _0x27dc79=0x0;_0x27dc79<_0x4d6b9a[_0x812b('0x3b')];_0x27dc79+=0x1){_0x2db249=_0x4d6b9a[_0x27dc79][_0x812b('0x77')]?_0x355059[_0x4d6b9a[_0x27dc79][_0x812b('0x77')]]['metric']:_0x4d6b9a[_0x27dc79][_0x812b('0x6d')];_0x2db249=_0x4d6b9a[_0x27dc79][_0x812b('0x78')]?_[_0x812b('0x79')](_0x5ad34c[_0x4d6b9a[_0x27dc79][_0x812b('0x78')]],'%s',_0x2db249):_0x2db249;_0x2db249=_0x4d6b9a[_0x27dc79][_0x812b('0x7a')]?_['replace'](_0x2a2f72[_0x4d6b9a[_0x27dc79][_0x812b('0x7a')]],'%s',_0x2db249):_0x2db249;if(_0x4d6b9a[_0x27dc79][_0x812b('0x7b')]){_0xc83017[_0x812b('0x6c')](_0x2db249);}_0x4d6b9a[_0x27dc79][_0x812b('0x7c')]&&_0xc83017[_0x812b('0x3e')](_0x2db249,_0x4d6b9a[_0x27dc79][_0x812b('0x7c')]===_0x812b('0x7d')?![]:!![]);_0xc83017[_0x812b('0x6d')](_0x2db249,_0x4d6b9a[_0x27dc79][_0x812b('0x7e')]||_0x2db249);}if(_0x45da53['joins']){_0x45da53[_0x812b('0x7f')]=JSON['parse'](_0x45da53['joins']);for(var _0x1ae25b=0x0;_0x1ae25b<_0x45da53[_0x812b('0x7f')][_0x812b('0x3b')];_0x1ae25b+=0x1){if(_0x45da53[_0x812b('0x7f')][_0x1ae25b][_0x812b('0x33')]&&_[_0x812b('0x68')](_0x783dbd,_0x45da53['joins'][_0x1ae25b][_0x812b('0x33')])&&_0x45da53[_0x812b('0x7f')][_0x1ae25b]['parentKey']&&_0x45da53[_0x812b('0x7f')][_0x1ae25b][_0x812b('0x80')]&&_0x45da53[_0x812b('0x7f')][_0x1ae25b][_0x812b('0x81')]){_0xc83017[_0x45da53[_0x812b('0x7f')][_0x1ae25b][_0x812b('0x33')]](_0x45da53[_0x812b('0x7f')][_0x1ae25b][_0x812b('0x80')],null,util[_0x812b('0x7a')](_0x812b('0x82'),_0x45da53[_0x812b('0x76')],_0x45da53['joins'][_0x1ae25b][_0x812b('0x83')],_0x45da53[_0x812b('0x7f')][_0x1ae25b][_0x812b('0x80')],_0x45da53[_0x812b('0x7f')][_0x1ae25b][_0x812b('0x81')]));}}}if(_0x45da53[_0x812b('0x84')]){_0x45da53[_0x812b('0x84')]=JSON[_0x812b('0x85')](_0x45da53['conditions']);_0xc83017[_0x812b('0x40')](_0x177e66(_0x45da53[_0x812b('0x84')][_0x812b('0x6c')]));}_0x1c3603=_0xc83017[_0x812b('0x86')]();_0xc83017[_0x812b('0x21')](_0x91f3d0);_0xc83017['offset'](0x0);logger[_0x812b('0x87')](_0x812b('0x88'),_0xc83017[_0x812b('0x89')]());return dbH['sequelize']['query'](_0xc83017[_0x812b('0x89')](),{'type':dbH[_0x812b('0x8a')][_0x812b('0x8b')][_0x812b('0x8c')]});}})['then'](respondWithResult(_0x48b815,null))[_0x812b('0x4c')](handleError(_0x48b815,null));};function runReport(_0x5b4566,_0x50147b,_0x40aab8){var _0xa92f01=_0x50147b['name'];var _0x486085=0xa;var _0x283f2b=[_0x812b('0x58'),_0x812b('0x59'),'right_join',_0x812b('0x5b')];var _0x2c1ed6={'SUM':_0x812b('0x5c'),'COUNT':_0x812b('0x8d'),'COUNT DISTINCT':_0x812b('0x8e'),'MAX':_0x812b('0x5d'),'MIN':_0x812b('0x5e'),'AVG':_0x812b('0x5f'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x812b('0x62')};var _0x4423ed={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x812b('0x64'),'HOUR':_0x812b('0x65'),'ROUND':_0x812b('0x66'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x27bc53=function(_0x21538d){return!_[_0x812b('0x68')]([_0x812b('0x69'),_0x812b('0x6a'),'IS\x20EMPTY',_0x812b('0x8f')],_0x21538d);};var _0x5a08f1=function(_0xadf92d){if(!_0xadf92d||!_0xadf92d[_0x812b('0x6b')][_0x812b('0x3b')]){return'';}for(var _0x5d82d0='(',_0x5f4809=0x0;_0x5f4809<_0xadf92d[_0x812b('0x6b')][_0x812b('0x3b')];_0x5f4809+=0x1){_0x5f4809>0x0&&(_0x5d82d0+='\x20'+_0xadf92d[_0x812b('0x90')]+'\x20');_0x5d82d0+=_0xadf92d[_0x812b('0x6b')][_0x5f4809][_0x812b('0x6c')]?_0x5a08f1(_0xadf92d[_0x812b('0x6b')][_0x5f4809]['group']):_0xadf92d['rules'][_0x5f4809]['field']+'\x20'+_0xadf92d[_0x812b('0x6b')][_0x5f4809][_0x812b('0x6e')]+(_0x27bc53(_0xadf92d[_0x812b('0x6b')][_0x5f4809][_0x812b('0x6e')])?'\x20'+_0xadf92d[_0x812b('0x6b')][_0x5f4809][_0x812b('0x6f')]:'');}return _0x5d82d0+')';};var _0x463d2f={'where':{'id':_0x5b4566['id']}},_0x11c862,_0xea9a7c,_0x34b880,_0x3b5a60,_0x1ce63d;_0x463d2f=_[_0x812b('0x44')]({},_0x463d2f,_0x40aab8);return db['AnalyticCustomReport'][_0x812b('0x4b')](_0x463d2f)[_0x812b('0x28')](function(_0x590f5f){if(_0x590f5f){_0x11c862=_0x590f5f;return _0x590f5f['getFields']();}return null;})[_0x812b('0x28')](function(_0x43c90c){if(_0x43c90c){if(!_0x43c90c[_0x812b('0x3b')]){throw new db[(_0x812b('0x71'))]['ValidationErrorItem'](_0x812b('0x91'),0x193);}_0xea9a7c=_0x43c90c;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})['then'](function(_0xd53787){if(_0xd53787){_0x34b880=_[_0x812b('0x74')](_0xd53787,'id');var _0x23ebd7;var _0x5ebdbc=squel[_0x812b('0x92')]();_0x5ebdbc[_0x812b('0x75')](_0x11c862[_0x812b('0x76')]);for(var _0x44da79=0x0;_0x44da79<_0xea9a7c[_0x812b('0x3b')];_0x44da79+=0x1){_0x23ebd7=_0xea9a7c[_0x44da79]['MetricId']?_0x34b880[_0xea9a7c[_0x44da79]['MetricId']][_0x812b('0x93')]:_0xea9a7c[_0x44da79]['field'];_0x23ebd7=_0xea9a7c[_0x44da79][_0x812b('0x78')]?_[_0x812b('0x79')](_0x2c1ed6[_0xea9a7c[_0x44da79][_0x812b('0x78')]],'%s',_0x23ebd7):_0x23ebd7;_0x23ebd7=_0xea9a7c[_0x44da79][_0x812b('0x7a')]?_[_0x812b('0x79')](_0x4423ed[_0xea9a7c[_0x44da79][_0x812b('0x7a')]],'%s',_0x23ebd7):_0x23ebd7;if(_0xea9a7c[_0x44da79][_0x812b('0x7b')]){_0x5ebdbc['group'](_0x23ebd7);}_0xea9a7c[_0x44da79][_0x812b('0x7c')]&&_0x5ebdbc['order'](_0x23ebd7,_0xea9a7c[_0x44da79][_0x812b('0x7c')]==='DESC'?![]:!![]);_0x5ebdbc['field'](_0x23ebd7,_0xea9a7c[_0x44da79]['alias']||_0x23ebd7);}if(_0x11c862['joins']){_0x11c862[_0x812b('0x7f')]=JSON[_0x812b('0x85')](_0x11c862[_0x812b('0x7f')]);for(var _0xcbac4d=0x0;_0xcbac4d<_0x11c862['joins'][_0x812b('0x3b')];_0xcbac4d+=0x1){if(_0x11c862[_0x812b('0x7f')][_0xcbac4d][_0x812b('0x33')]&&_[_0x812b('0x68')](_0x283f2b,_0x11c862['joins'][_0xcbac4d][_0x812b('0x33')])&&_0x11c862[_0x812b('0x7f')][_0xcbac4d][_0x812b('0x83')]&&_0x11c862[_0x812b('0x7f')][_0xcbac4d][_0x812b('0x80')]&&_0x11c862['joins'][_0xcbac4d][_0x812b('0x81')]){_0x5ebdbc[_0x11c862[_0x812b('0x7f')][_0xcbac4d][_0x812b('0x33')]](_0x11c862[_0x812b('0x7f')][_0xcbac4d][_0x812b('0x80')],null,util[_0x812b('0x7a')]('%s.%s\x20=\x20%s.%s',_0x11c862[_0x812b('0x76')],_0x11c862[_0x812b('0x7f')][_0xcbac4d][_0x812b('0x83')],_0x11c862['joins'][_0xcbac4d][_0x812b('0x80')],_0x11c862[_0x812b('0x7f')][_0xcbac4d]['foreignKey']));}}}if(_0x11c862[_0x812b('0x84')]){_0x11c862[_0x812b('0x84')]=JSON[_0x812b('0x85')](_0x11c862[_0x812b('0x84')]);_0x5ebdbc[_0x812b('0x40')](_0x5a08f1(_0x11c862[_0x812b('0x84')][_0x812b('0x6c')]));}_0x1ce63d=_0x5ebdbc['clone']();_0x5ebdbc[_0x812b('0x21')](_0x486085);_0x5ebdbc[_0x812b('0x20')](0x0);return;}})[_0x812b('0x28')](function(){if(_0x50147b[_0x812b('0x94')]===_0x812b('0x95')){return null;}var _0x4cae2a=_['merge'](_0x50147b,{'name':_0x50147b[_0x812b('0x96')]||_0x50147b[_0x812b('0x43')]||_0x11c862['name'],'basename':_0xa92f01,'savename':util[_0x812b('0x7a')](_0x812b('0x97'),_0x50147b[_0x812b('0x43')]||_0x11c862['name'],require('randomstring')[_0x812b('0x98')](0x4),_0x50147b[_0x812b('0x94')]||_0x812b('0x99')),'reportId':_0x11c862['id'],'reportType':_0x812b('0x9a')});return db[_0x812b('0x9b')][_0x812b('0x4d')](_0x4cae2a,{'raw':!![]});})[_0x812b('0x28')](function(_0x4e897e){if(_0x11c862[_0x812b('0x76')]===_0x812b('0x9c')){_0x1ce63d['where'](_0x11c862[_0x812b('0x76')]+_0x812b('0x9d'),_0x50147b['startDate'],_0x50147b['endDate']);}else{_0x1ce63d[_0x812b('0x40')](_0x11c862[_0x812b('0x76')]+_0x812b('0x9e'),_0x50147b[_0x812b('0x9f')],_0x50147b[_0x812b('0xa0')]);}if(_0x4e897e){logger[_0x812b('0xa1')]('Run\x20Query:',_0x1ce63d[_0x812b('0x89')]());require(_0x812b('0xa2'))['fork'](path[_0x812b('0x58')](__dirname,_0x812b('0xa3'),_0x4e897e[_0x812b('0x94')]),[_0x4e897e['id'],_0x1ce63d[_0x812b('0x89')](),path[_0x812b('0x58')](__dirname,'../../files/reports',_0x4e897e[_0x812b('0xa4')]),_0xa92f01]);return _0x4e897e;}else{var _0x217bcf=squel['select']();_0x217bcf[_0x812b('0x75')]('('+_0x1ce63d[_0x812b('0x89')]()+')',_0x812b('0xa5'));_0x217bcf[_0x812b('0x6d')](_0x812b('0xa6'),'count');_0x1ce63d[_0x812b('0x21')](_0x50147b[_0x812b('0x21')]||_0x486085);_0x1ce63d[_0x812b('0x20')](_0x50147b[_0x812b('0x20')]||0x0);return dbH[_0x812b('0x8a')]['query'](_0x217bcf[_0x812b('0x89')](),{'type':dbH['sequelize']['QueryTypes'][_0x812b('0x8c')]})[_0x812b('0x28')](function(_0x1408d2){if(!_0x1408d2[_0x812b('0x3b')]){_0x3b5a60=0x0;}else{_0x3b5a60=_0x1408d2[0x0]['count']||0x0;}return dbH[_0x812b('0x8a')]['query'](_0x1ce63d[_0x812b('0x89')](),{'type':dbH[_0x812b('0x8a')]['QueryTypes']['SELECT']});})['then'](function(_0xc5bad5){return{'rows':_0xc5bad5||[],'count':_0x3b5a60};});}});}exports[_0x812b('0xa7')]=function(_0x2d02d9,_0x51e3b3){return runReport(_0x2d02d9[_0x812b('0x49')],_0x2d02d9['query'],_0x2d02d9[_0x812b('0x45')])['then'](respondWithResult(_0x51e3b3,null))[_0x812b('0x4c')](handleError(_0x51e3b3,null));};exports[_0x812b('0xa8')]=runReport;exports[_0x812b('0x38')]=function(_0x39f1d9,_0x49bd36){var _0xd7ea2b=0xa;var _0x5a35b9=[_0x812b('0x58'),_0x812b('0x59'),'right_join',_0x812b('0x5b')];var _0x246607={'SUM':_0x812b('0x5c'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0x812b('0x8e'),'MAX':_0x812b('0x5d'),'MIN':_0x812b('0x5e'),'AVG':_0x812b('0x5f'),'GROUP_CONCAT':_0x812b('0x60'),'GROUP_CONCAT ASC':_0x812b('0x61'),'GROUP_CONCAT DESC':_0x812b('0x62')};var _0x22499c={'SEC_TO_TIME':_0x812b('0x63'),'DATE':_0x812b('0x64'),'HOUR':_0x812b('0x65'),'ROUND':_0x812b('0x66'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x10e3ee=function(_0xd615d1){return!_[_0x812b('0x68')]([_0x812b('0x69'),_0x812b('0x6a'),'IS\x20EMPTY',_0x812b('0x8f')],_0xd615d1);};var _0x5a14a=function(_0x3d9395){if(!_0x3d9395||!_0x3d9395[_0x812b('0x6b')][_0x812b('0x3b')]){return'';}for(var _0x46344e='(',_0x344ccd=0x0;_0x344ccd<_0x3d9395[_0x812b('0x6b')]['length'];_0x344ccd+=0x1){_0x344ccd>0x0&&(_0x46344e+='\x20'+_0x3d9395[_0x812b('0x90')]+'\x20');_0x46344e+=_0x3d9395[_0x812b('0x6b')][_0x344ccd][_0x812b('0x6c')]?_0x5a14a(_0x3d9395['rules'][_0x344ccd][_0x812b('0x6c')]):_0x3d9395[_0x812b('0x6b')][_0x344ccd]['field']+'\x20'+_0x3d9395[_0x812b('0x6b')][_0x344ccd][_0x812b('0x6e')]+(_0x10e3ee(_0x3d9395[_0x812b('0x6b')][_0x344ccd][_0x812b('0x6e')])?'\x20'+_0x3d9395['rules'][_0x344ccd]['value']:'');}return _0x46344e+')';};var _0x3a4716={'where':{'id':_0x39f1d9[_0x812b('0x49')]['id']}},_0xa33dc4,_0x38f83e,_0x40d578,_0x40e680,_0x19f3e5;_0x3a4716=_[_0x812b('0x44')]({},_0x3a4716,_0x39f1d9['options']);return db[_0x812b('0x31')][_0x812b('0x4b')](_0x3a4716)['then'](function(_0x4f66ad){if(_0x4f66ad){_0xa33dc4=_0x4f66ad;return _0x4f66ad[_0x812b('0x70')]();}return null;})[_0x812b('0x28')](function(_0x264210){if(_0x264210){if(!_0x264210[_0x812b('0x3b')]){throw new db[(_0x812b('0x71'))][(_0x812b('0x72'))](_0x812b('0x91'),0x193);}_0x38f83e=_0x264210;return db[_0x812b('0x73')][_0x812b('0x48')]({'raw':!![]});}return null;})[_0x812b('0x28')](function(_0xd4b59){if(_0xd4b59){_0x40d578=_[_0x812b('0x74')](_0xd4b59,'id');var _0x4d4aff;var _0xbc476f=squel[_0x812b('0x92')]();_0xbc476f[_0x812b('0x75')](_0xa33dc4['table']);for(var _0xd2c36d=0x0;_0xd2c36d<_0x38f83e[_0x812b('0x3b')];_0xd2c36d+=0x1){_0x4d4aff=_0x38f83e[_0xd2c36d][_0x812b('0x77')]?_0x40d578[_0x38f83e[_0xd2c36d]['MetricId']][_0x812b('0x93')]:_0x38f83e[_0xd2c36d]['field'];_0x4d4aff=_0x38f83e[_0xd2c36d][_0x812b('0x78')]?_[_0x812b('0x79')](_0x246607[_0x38f83e[_0xd2c36d][_0x812b('0x78')]],'%s',_0x4d4aff):_0x4d4aff;_0x4d4aff=_0x38f83e[_0xd2c36d][_0x812b('0x7a')]?_['replace'](_0x22499c[_0x38f83e[_0xd2c36d]['format']],'%s',_0x4d4aff):_0x4d4aff;if(_0x38f83e[_0xd2c36d][_0x812b('0x7b')]){_0xbc476f[_0x812b('0x6c')](_0x4d4aff);}_0x38f83e[_0xd2c36d]['orderBy']&&_0xbc476f['order'](_0x4d4aff,_0x38f83e[_0xd2c36d][_0x812b('0x7c')]===_0x812b('0x7d')?![]:!![]);_0xbc476f['field'](_0x4d4aff,_0x38f83e[_0xd2c36d][_0x812b('0x7e')]||_0x4d4aff);}if(_0xa33dc4[_0x812b('0x7f')]){_0xa33dc4[_0x812b('0x7f')]=JSON[_0x812b('0x85')](_0xa33dc4[_0x812b('0x7f')]);for(var _0xa73c82=0x0;_0xa73c82<_0xa33dc4[_0x812b('0x7f')][_0x812b('0x3b')];_0xa73c82+=0x1){if(_0xa33dc4[_0x812b('0x7f')][_0xa73c82][_0x812b('0x33')]&&_['includes'](_0x5a35b9,_0xa33dc4['joins'][_0xa73c82][_0x812b('0x33')])&&_0xa33dc4[_0x812b('0x7f')][_0xa73c82]['parentKey']&&_0xa33dc4[_0x812b('0x7f')][_0xa73c82][_0x812b('0x80')]&&_0xa33dc4['joins'][_0xa73c82][_0x812b('0x81')]){_0xbc476f[_0xa33dc4[_0x812b('0x7f')][_0xa73c82][_0x812b('0x33')]](_0xa33dc4[_0x812b('0x7f')][_0xa73c82]['foreignTable'],null,util[_0x812b('0x7a')](_0x812b('0x82'),_0xa33dc4[_0x812b('0x76')],_0xa33dc4['joins'][_0xa73c82][_0x812b('0x83')],_0xa33dc4[_0x812b('0x7f')][_0xa73c82][_0x812b('0x80')],_0xa33dc4[_0x812b('0x7f')][_0xa73c82][_0x812b('0x81')]));}}}if(_0xa33dc4['conditions']){_0xa33dc4['conditions']=JSON[_0x812b('0x85')](_0xa33dc4[_0x812b('0x84')]);_0xbc476f[_0x812b('0x40')](_0x5a14a(_0xa33dc4[_0x812b('0x84')][_0x812b('0x6c')]));}_0x19f3e5=_0xbc476f['clone']();_0xbc476f[_0x812b('0x21')](_0xd7ea2b);_0xbc476f[_0x812b('0x20')](0x0);logger['debug'](_0x812b('0x88'),_0xbc476f['toString']());return dbH[_0x812b('0x8a')][_0x812b('0x38')](_0xbc476f[_0x812b('0x89')](),{'type':dbH[_0x812b('0x8a')][_0x812b('0x8b')][_0x812b('0x8c')]});}})[_0x812b('0x28')](function(){return{'sql':_0x19f3e5['toString']()};})['then'](respondWithResult(_0x49bd36,null))['catch'](handleError(_0x49bd36,null));};
\ No newline at end of file