Built motion from commit 25580385.|2.6.2
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 039f3b1..b545fea 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 _0x4c5a=['filters','intersection','fields','attributes','hasOwnProperty','nolimit','limit','order','sort','where','pick','merge','type','options','AnalyticCustomReport','includeAll','include','findAll','rows','keys','length','find','catch','create','body','user','role','get','Reports','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','preview','join','right_join','cross_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','DATE(%s)','HOUR(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20NOT\x20EMPTY','rules','group','field','condition','getFields','Sequelize','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','from','MetricId','function','replace','format','groupBy','orderBy','DESC','alias','joins','parse','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','parentKey','conditions','clone','debug','Limited\x20Query:','toString','sequelize','QueryTypes','left_join','SEC_TO_TIME(%s)','ROUND(%s)','IS\x20EMPTY','operator','ValidationErrorItem','select','table','metric','output','fullPath','%s-%s.%s','randomstring','generate','csv','custom','AnalyticExtractedReport','cdr','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','child_process','../../files/reports','savename','countTable','COUNT(*)','SELECT','run','runReport','value','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','path','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','json','offset','undefined','count','set','Content-Range','reject','update','destroy','UserProfileResource','then','end','name','send','index','map','rawAttributes','fieldName','key','model','query'];(function(_0x3d2534,_0x4d5dcc){var _0x3f38c0=function(_0x51d1f6){while(--_0x51d1f6){_0x3d2534['push'](_0x3d2534['shift']());}};_0x3f38c0(++_0x4d5dcc);}(_0x4c5a,0x1c0));var _0xa4c5=function(_0x1c2ad4,_0x42b3bb){_0x1c2ad4=_0x1c2ad4-0x0;var _0x129a4e=_0x4c5a[_0x1c2ad4];return _0x129a4e;};'use strict';var emlformat=require(_0xa4c5('0x0'));var rimraf=require(_0xa4c5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xa4c5('0x2'));var rp=require(_0xa4c5('0x3'));var moment=require('moment');var BPromise=require(_0xa4c5('0x4'));var Mustache=require(_0xa4c5('0x5'));var util=require('util');var path=require(_0xa4c5('0x6'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xa4c5('0x7'));var fs=require('fs');var fs_extra=require(_0xa4c5('0x8'));var _=require(_0xa4c5('0x9'));var squel=require(_0xa4c5('0xa'));var crypto=require('crypto');var jsforce=require(_0xa4c5('0xb'));var deskjs=require(_0xa4c5('0xc'));var toCsv=require(_0xa4c5('0xd'));var querystring=require(_0xa4c5('0xe'));var Papa=require('papaparse');var Redis=require(_0xa4c5('0xf'));var authService=require(_0xa4c5('0x10'));var qs=require(_0xa4c5('0x11'));var as=require(_0xa4c5('0x12'));var hardwareService=require(_0xa4c5('0x13'));var logger=require(_0xa4c5('0x14'))(_0xa4c5('0x15'));var utils=require(_0xa4c5('0x16'));var config=require(_0xa4c5('0x17'));var licenseUtil=require(_0xa4c5('0x18'));var db=require(_0xa4c5('0x19'))['db'];var dbH=require('../../mysqldb')[_0xa4c5('0x1a')];function respondWithStatusCode(_0x1ee5b6,_0x405327){_0x405327=_0x405327||0xcc;return function(_0x73d01c){if(_0x73d01c){return _0x1ee5b6[_0xa4c5('0x1b')](_0x405327);}return _0x1ee5b6[_0xa4c5('0x1c')](_0x405327)['end']();};}function respondWithResult(_0x44c912,_0x4dcc51){_0x4dcc51=_0x4dcc51||0xc8;return function(_0x29fbf7){if(_0x29fbf7){return _0x44c912['status'](_0x4dcc51)[_0xa4c5('0x1d')](_0x29fbf7);}};}function respondWithFilteredResult(_0x47bc0c,_0x2b4099){return function(_0x2a4950){if(_0x2a4950){var _0xad448f=typeof _0x2b4099[_0xa4c5('0x1e')]===_0xa4c5('0x1f')&&typeof _0x2b4099['limit']===_0xa4c5('0x1f');var _0x3daeab=_0x2a4950[_0xa4c5('0x20')];var _0x5769d8=_0xad448f?0x0:_0x2b4099['offset'];var _0x6c85b2=_0xad448f?_0x2a4950[_0xa4c5('0x20')]:_0x2b4099[_0xa4c5('0x1e')]+_0x2b4099['limit'];var _0x379fc2;if(_0x6c85b2>=_0x3daeab){_0x6c85b2=_0x3daeab;_0x379fc2=0xc8;}else{_0x379fc2=0xce;}_0x47bc0c[_0xa4c5('0x1c')](_0x379fc2);return _0x47bc0c[_0xa4c5('0x21')](_0xa4c5('0x22'),_0x5769d8+'-'+_0x6c85b2+'/'+_0x3daeab)[_0xa4c5('0x1d')](_0x2a4950);}return null;};}function patchUpdates(_0x4890c1){return function(_0x109546){try{jsonpatch['apply'](_0x109546,_0x4890c1,!![]);}catch(_0x547c2a){return BPromise[_0xa4c5('0x23')](_0x547c2a);}return _0x109546['save']();};}function saveUpdates(_0x47fd8e,_0x565c99){return function(_0x15fdd2){if(_0x15fdd2){return _0x15fdd2[_0xa4c5('0x24')](_0x47fd8e)['then'](function(_0x4aa906){return _0x4aa906;});}return null;};}function removeEntity(_0x287d99,_0x5de749){return function(_0x129d79){if(_0x129d79){return _0x129d79[_0xa4c5('0x25')]()['then'](function(){var _0x5acedf=_0x129d79['get']({'plain':!![]});var _0xdcf314='CustomReports';return db[_0xa4c5('0x26')]['destroy']({'where':{'type':_0xdcf314,'resourceId':_0x5acedf['id']}})[_0xa4c5('0x27')](function(){return _0x129d79;});})[_0xa4c5('0x27')](function(){_0x287d99['status'](0xcc)[_0xa4c5('0x28')]();});}};}function handleEntityNotFound(_0x56ab35,_0x8a4c13){return function(_0x1106f1){if(!_0x1106f1){_0x56ab35[_0xa4c5('0x1b')](0x194);}return _0x1106f1;};}function handleError(_0x38a3cc,_0x4b5620){_0x4b5620=_0x4b5620||0x1f4;return function(_0x271706){logger['error'](_0x271706['stack']);if(_0x271706[_0xa4c5('0x29')]){delete _0x271706[_0xa4c5('0x29')];}_0x38a3cc[_0xa4c5('0x1c')](_0x4b5620)[_0xa4c5('0x2a')](_0x271706);};}exports[_0xa4c5('0x2b')]=function(_0x281754,_0x1b57c9){var _0x57abe3={},_0x40c039={},_0xe6993f={'count':0x0,'rows':[]};var _0x21051e=_[_0xa4c5('0x2c')](db['AnalyticCustomReport'][_0xa4c5('0x2d')],function(_0x287257){return{'name':_0x287257[_0xa4c5('0x2e')],'type':_0x287257['type'][_0xa4c5('0x2f')]};});_0x40c039[_0xa4c5('0x30')]=_['map'](_0x21051e,'name');_0x40c039[_0xa4c5('0x31')]=_['keys'](_0x281754[_0xa4c5('0x31')]);_0x40c039[_0xa4c5('0x32')]=_[_0xa4c5('0x33')](_0x40c039['model'],_0x40c039['query']);_0x57abe3['attributes']=_[_0xa4c5('0x33')](_0x40c039[_0xa4c5('0x30')],qs[_0xa4c5('0x34')](_0x281754[_0xa4c5('0x31')][_0xa4c5('0x34')]));_0x57abe3[_0xa4c5('0x35')]=_0x57abe3[_0xa4c5('0x35')]['length']?_0x57abe3[_0xa4c5('0x35')]:_0x40c039[_0xa4c5('0x30')];if(!_0x281754['query'][_0xa4c5('0x36')](_0xa4c5('0x37'))){_0x57abe3[_0xa4c5('0x38')]=qs[_0xa4c5('0x38')](_0x281754[_0xa4c5('0x31')]['limit']);_0x57abe3[_0xa4c5('0x1e')]=qs[_0xa4c5('0x1e')](_0x281754['query']['offset']);}_0x57abe3[_0xa4c5('0x39')]=qs[_0xa4c5('0x3a')](_0x281754[_0xa4c5('0x31')][_0xa4c5('0x3a')]);_0x57abe3[_0xa4c5('0x3b')]=qs[_0xa4c5('0x32')](_[_0xa4c5('0x3c')](_0x281754['query'],_0x40c039[_0xa4c5('0x32')]),_0x21051e);if(_0x281754[_0xa4c5('0x31')]['filter']){_0x57abe3[_0xa4c5('0x3b')]=_[_0xa4c5('0x3d')](_0x57abe3[_0xa4c5('0x3b')],{'$or':_[_0xa4c5('0x2c')](_0x21051e,function(_0x568c4d){if(_0x568c4d[_0xa4c5('0x3e')]!=='VIRTUAL'){var _0x2363fd={};_0x2363fd[_0x568c4d['name']]={'$like':'%'+_0x281754[_0xa4c5('0x31')]['filter']+'%'};return _0x2363fd;}})});}_0x57abe3=_[_0xa4c5('0x3d')]({},_0x57abe3,_0x281754[_0xa4c5('0x3f')]);var _0x1a9bb3={'where':_0x57abe3[_0xa4c5('0x3b')]};return db[_0xa4c5('0x40')]['count'](_0x1a9bb3)[_0xa4c5('0x27')](function(_0x588e84){_0xe6993f[_0xa4c5('0x20')]=_0x588e84;if(_0x281754[_0xa4c5('0x31')][_0xa4c5('0x41')]){_0x57abe3[_0xa4c5('0x42')]=[{'all':!![]}];}return db['AnalyticCustomReport'][_0xa4c5('0x43')](_0x57abe3);})['then'](function(_0x410fde){_0xe6993f[_0xa4c5('0x44')]=_0x410fde;return _0xe6993f;})['then'](respondWithFilteredResult(_0x1b57c9,_0x57abe3))['catch'](handleError(_0x1b57c9,null));};exports['show']=function(_0x448cca,_0x40618f){var _0xadf767={'raw':![],'where':{'id':_0x448cca['params']['id']}},_0xe8ed15={};_0xe8ed15[_0xa4c5('0x30')]=_[_0xa4c5('0x45')](db['AnalyticCustomReport']['rawAttributes']);_0xe8ed15['query']=_[_0xa4c5('0x45')](_0x448cca[_0xa4c5('0x31')]);_0xe8ed15[_0xa4c5('0x32')]=_['intersection'](_0xe8ed15['model'],_0xe8ed15[_0xa4c5('0x31')]);_0xadf767['attributes']=_[_0xa4c5('0x33')](_0xe8ed15['model'],qs[_0xa4c5('0x34')](_0x448cca[_0xa4c5('0x31')][_0xa4c5('0x34')]));_0xadf767[_0xa4c5('0x35')]=_0xadf767[_0xa4c5('0x35')][_0xa4c5('0x46')]?_0xadf767[_0xa4c5('0x35')]:_0xe8ed15['model'];if(_0x448cca[_0xa4c5('0x31')]['includeAll']){_0xadf767['include']=[{'all':!![]}];}_0xadf767=_['merge']({},_0xadf767,_0x448cca[_0xa4c5('0x3f')]);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0xadf767)['then'](handleEntityNotFound(_0x40618f,null))['then'](respondWithResult(_0x40618f,null))[_0xa4c5('0x48')](handleError(_0x40618f,null));};exports[_0xa4c5('0x49')]=function(_0x353496,_0x4e2503){return db[_0xa4c5('0x40')][_0xa4c5('0x49')](_0x353496[_0xa4c5('0x4a')],{})[_0xa4c5('0x27')](function(_0x1dcbcf){var _0x393ef7=_0x353496[_0xa4c5('0x4b')]['get']({'plain':!![]});if(!_0x393ef7)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x393ef7[_0xa4c5('0x4c')]==='user'){var _0x4a084e=_0x1dcbcf[_0xa4c5('0x4d')]({'plain':!![]});var _0x16a54c=_0xa4c5('0x4e');return db[_0xa4c5('0x4f')][_0xa4c5('0x47')]({'where':{'name':_0x16a54c,'userProfileId':_0x393ef7[_0xa4c5('0x50')]},'raw':!![]})[_0xa4c5('0x27')](function(_0x351215){if(_0x351215&&_0x351215[_0xa4c5('0x51')]===0x0){return db[_0xa4c5('0x26')][_0xa4c5('0x49')]({'name':_0x4a084e['name'],'resourceId':_0x4a084e['id'],'type':'CustomReports','sectionId':_0x351215['id']},{})[_0xa4c5('0x27')](function(){return _0x1dcbcf;});}else{return _0x1dcbcf;}})[_0xa4c5('0x48')](function(_0x5a0b2d){logger[_0xa4c5('0x52')](_0xa4c5('0x53'),_0x5a0b2d);throw _0x5a0b2d;});}return _0x1dcbcf;})[_0xa4c5('0x27')](respondWithResult(_0x4e2503,0xc9))[_0xa4c5('0x48')](handleError(_0x4e2503,null));};exports[_0xa4c5('0x24')]=function(_0x47c018,_0x419bb2){if(_0x47c018['body']['id']){delete _0x47c018[_0xa4c5('0x4a')]['id'];}return db[_0xa4c5('0x40')]['find']({'where':{'id':_0x47c018[_0xa4c5('0x54')]['id']}})['then'](handleEntityNotFound(_0x419bb2,null))['then'](saveUpdates(_0x47c018[_0xa4c5('0x4a')],null))[_0xa4c5('0x27')](respondWithResult(_0x419bb2,null))[_0xa4c5('0x48')](handleError(_0x419bb2,null));};exports['destroy']=function(_0x50f370,_0x774ce6){return db[_0xa4c5('0x40')]['find']({'where':{'id':_0x50f370[_0xa4c5('0x54')]['id']}})[_0xa4c5('0x27')](handleEntityNotFound(_0x774ce6,null))[_0xa4c5('0x27')](removeEntity(_0x774ce6,null))[_0xa4c5('0x48')](handleError(_0x774ce6,null));};exports[_0xa4c5('0x55')]=function(_0x274cb4,_0x5c9bdc){var _0x2ff696=0xa;var _0x568766=[_0xa4c5('0x56'),'left_join',_0xa4c5('0x57'),_0xa4c5('0x58')];var _0x31c37a={'SUM':_0xa4c5('0x59'),'COUNT':_0xa4c5('0x5a'),'COUNT DISTINCT':_0xa4c5('0x5b'),'MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':_0xa4c5('0x5d'),'GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':_0xa4c5('0x5f'),'GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0xd2a4f2={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xa4c5('0x63')};var _0x7dd707=function(_0xe85930){return!_[_0xa4c5('0x64')]([_0xa4c5('0x65'),_0xa4c5('0x66'),'IS\x20EMPTY',_0xa4c5('0x67')],_0xe85930);};var _0x135bba=function(_0x27ad75){if(!_0x27ad75||!_0x27ad75[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0xe4b3f4='(',_0x5386b9=0x0;_0x5386b9<_0x27ad75[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x5386b9+=0x1){_0x5386b9>0x0&&(_0xe4b3f4+='\x20'+_0x27ad75['operator']+'\x20');_0xe4b3f4+=_0x27ad75['rules'][_0x5386b9][_0xa4c5('0x69')]?_0x135bba(_0x27ad75[_0xa4c5('0x68')][_0x5386b9][_0xa4c5('0x69')]):_0x27ad75['rules'][_0x5386b9][_0xa4c5('0x6a')]+'\x20'+_0x27ad75[_0xa4c5('0x68')][_0x5386b9]['condition']+(_0x7dd707(_0x27ad75[_0xa4c5('0x68')][_0x5386b9][_0xa4c5('0x6b')])?'\x20'+_0x27ad75['rules'][_0x5386b9]['value']:'');}return _0xe4b3f4+')';};var _0x141a95={'where':{'id':_0x274cb4[_0xa4c5('0x54')]['id']}},_0x1449ae,_0x5ae88e,_0x128805,_0x1e5cf8,_0x54efe4;_0x141a95=_[_0xa4c5('0x3d')]({},_0x141a95,_0x274cb4[_0xa4c5('0x3f')]);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0x141a95)[_0xa4c5('0x27')](function(_0x2ff202){if(_0x2ff202){_0x1449ae=_0x2ff202;return _0x2ff202[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x4d1551){if(_0x4d1551){if(!_0x4d1551[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))]['ValidationErrorItem'](_0xa4c5('0x6e'),0x193);}_0x5ae88e=_0x4d1551;return db[_0xa4c5('0x6f')][_0xa4c5('0x43')]({'raw':!![]});}return null;})[_0xa4c5('0x27')](function(_0x5c19d4){if(_0x5c19d4){_0x128805=_[_0xa4c5('0x70')](_0x5c19d4,'id');var _0x1da8b7;var _0x4c7b6e=squel['select']();_0x4c7b6e[_0xa4c5('0x71')](_0x1449ae['table']);for(var _0xf299ba=0x0;_0xf299ba<_0x5ae88e[_0xa4c5('0x46')];_0xf299ba+=0x1){_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x72')]?_0x128805[_0x5ae88e[_0xf299ba][_0xa4c5('0x72')]]['metric']:_0x5ae88e[_0xf299ba]['field'];_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x31c37a[_0x5ae88e[_0xf299ba][_0xa4c5('0x73')]],'%s',_0x1da8b7):_0x1da8b7;_0x1da8b7=_0x5ae88e[_0xf299ba][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0xd2a4f2[_0x5ae88e[_0xf299ba][_0xa4c5('0x75')]],'%s',_0x1da8b7):_0x1da8b7;if(_0x5ae88e[_0xf299ba][_0xa4c5('0x76')]){_0x4c7b6e[_0xa4c5('0x69')](_0x1da8b7);}_0x5ae88e[_0xf299ba][_0xa4c5('0x77')]&&_0x4c7b6e['order'](_0x1da8b7,_0x5ae88e[_0xf299ba][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x4c7b6e[_0xa4c5('0x6a')](_0x1da8b7,_0x5ae88e[_0xf299ba][_0xa4c5('0x79')]||_0x1da8b7);}if(_0x1449ae[_0xa4c5('0x7a')]){_0x1449ae['joins']=JSON[_0xa4c5('0x7b')](_0x1449ae[_0xa4c5('0x7a')]);for(var _0x3d357d=0x0;_0x3d357d<_0x1449ae['joins'][_0xa4c5('0x46')];_0x3d357d+=0x1){if(_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x568766,_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x3e')])&&_0x1449ae[_0xa4c5('0x7a')][_0x3d357d]['parentKey']&&_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7c')]&&_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7d')]){_0x4c7b6e[_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x3e')]](_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')](_0xa4c5('0x7e'),_0x1449ae['table'],_0x1449ae['joins'][_0x3d357d][_0xa4c5('0x7f')],_0x1449ae[_0xa4c5('0x7a')][_0x3d357d][_0xa4c5('0x7c')],_0x1449ae['joins'][_0x3d357d]['foreignKey']));}}}if(_0x1449ae['conditions']){_0x1449ae[_0xa4c5('0x80')]=JSON['parse'](_0x1449ae[_0xa4c5('0x80')]);_0x4c7b6e[_0xa4c5('0x3b')](_0x135bba(_0x1449ae[_0xa4c5('0x80')]['group']));}_0x54efe4=_0x4c7b6e[_0xa4c5('0x81')]();_0x4c7b6e['limit'](_0x2ff696);_0x4c7b6e[_0xa4c5('0x1e')](0x0);logger[_0xa4c5('0x82')](_0xa4c5('0x83'),_0x4c7b6e[_0xa4c5('0x84')]());return dbH['sequelize'][_0xa4c5('0x31')](_0x4c7b6e['toString'](),{'type':dbH[_0xa4c5('0x85')][_0xa4c5('0x86')]['SELECT']});}})[_0xa4c5('0x27')](respondWithResult(_0x5c9bdc,null))[_0xa4c5('0x48')](handleError(_0x5c9bdc,null));};function runReport(_0x129780,_0x470a0b,_0x7c17d8){var _0x114f35=_0x470a0b[_0xa4c5('0x29')];var _0x40c2af=0xa;var _0x14f818=[_0xa4c5('0x56'),_0xa4c5('0x87'),_0xa4c5('0x57'),'cross_join'];var _0x2264b0={'SUM':_0xa4c5('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0xa4c5('0x5b'),'MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':_0xa4c5('0x5d'),'GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0x15f9f5={'SEC_TO_TIME':_0xa4c5('0x88'),'DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':_0xa4c5('0x89'),'UNIX_TIMESTAMP':'UNIX_TIMESTAMP(%s)'};var _0x2a5209=function(_0x46318b){return!_['includes'](['IS\x20NULL',_0xa4c5('0x66'),_0xa4c5('0x8a'),_0xa4c5('0x67')],_0x46318b);};var _0x160424=function(_0x33e58b){if(!_0x33e58b||!_0x33e58b[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0x4ee1f7='(',_0x382c64=0x0;_0x382c64<_0x33e58b[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x382c64+=0x1){_0x382c64>0x0&&(_0x4ee1f7+='\x20'+_0x33e58b[_0xa4c5('0x8b')]+'\x20');_0x4ee1f7+=_0x33e58b['rules'][_0x382c64][_0xa4c5('0x69')]?_0x160424(_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x69')]):_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6a')]+'\x20'+_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6b')]+(_0x2a5209(_0x33e58b[_0xa4c5('0x68')][_0x382c64][_0xa4c5('0x6b')])?'\x20'+_0x33e58b[_0xa4c5('0x68')][_0x382c64]['value']:'');}return _0x4ee1f7+')';};var _0x3f7df6={'where':{'id':_0x129780['id']}},_0x5d8983,_0x8de116,_0x4a911f,_0x4fca6b,_0x33212a;_0x3f7df6=_['merge']({},_0x3f7df6,_0x7c17d8);return db[_0xa4c5('0x40')][_0xa4c5('0x47')](_0x3f7df6)[_0xa4c5('0x27')](function(_0x13b9a0){if(_0x13b9a0){_0x5d8983=_0x13b9a0;return _0x13b9a0[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x3b7847){if(_0x3b7847){if(!_0x3b7847[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))][(_0xa4c5('0x8c'))](_0xa4c5('0x6e'),0x193);}_0x8de116=_0x3b7847;return db[_0xa4c5('0x6f')][_0xa4c5('0x43')]({'raw':!![]});}return null;})['then'](function(_0x3315c6){if(_0x3315c6){_0x4a911f=_[_0xa4c5('0x70')](_0x3315c6,'id');var _0x2ee764;var _0x11735c=squel[_0xa4c5('0x8d')]();_0x11735c['from'](_0x5d8983[_0xa4c5('0x8e')]);for(var _0xe1055=0x0;_0xe1055<_0x8de116[_0xa4c5('0x46')];_0xe1055+=0x1){_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x72')]?_0x4a911f[_0x8de116[_0xe1055][_0xa4c5('0x72')]][_0xa4c5('0x8f')]:_0x8de116[_0xe1055][_0xa4c5('0x6a')];_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x2264b0[_0x8de116[_0xe1055][_0xa4c5('0x73')]],'%s',_0x2ee764):_0x2ee764;_0x2ee764=_0x8de116[_0xe1055][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0x15f9f5[_0x8de116[_0xe1055]['format']],'%s',_0x2ee764):_0x2ee764;if(_0x8de116[_0xe1055][_0xa4c5('0x76')]){_0x11735c[_0xa4c5('0x69')](_0x2ee764);}_0x8de116[_0xe1055][_0xa4c5('0x77')]&&_0x11735c['order'](_0x2ee764,_0x8de116[_0xe1055][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x11735c[_0xa4c5('0x6a')](_0x2ee764,_0x8de116[_0xe1055][_0xa4c5('0x79')]||_0x2ee764);}if(_0x5d8983[_0xa4c5('0x7a')]){_0x5d8983[_0xa4c5('0x7a')]=JSON['parse'](_0x5d8983[_0xa4c5('0x7a')]);for(var _0x512de7=0x0;_0x512de7<_0x5d8983[_0xa4c5('0x7a')][_0xa4c5('0x46')];_0x512de7+=0x1){if(_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x14f818,_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x3e')])&&_0x5d8983['joins'][_0x512de7]['parentKey']&&_0x5d8983['joins'][_0x512de7]['foreignTable']&&_0x5d8983['joins'][_0x512de7][_0xa4c5('0x7d')]){_0x11735c[_0x5d8983[_0xa4c5('0x7a')][_0x512de7]['type']](_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')](_0xa4c5('0x7e'),_0x5d8983[_0xa4c5('0x8e')],_0x5d8983['joins'][_0x512de7]['parentKey'],_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7c')],_0x5d8983[_0xa4c5('0x7a')][_0x512de7][_0xa4c5('0x7d')]));}}}if(_0x5d8983[_0xa4c5('0x80')]){_0x5d8983[_0xa4c5('0x80')]=JSON['parse'](_0x5d8983[_0xa4c5('0x80')]);_0x11735c[_0xa4c5('0x3b')](_0x160424(_0x5d8983[_0xa4c5('0x80')][_0xa4c5('0x69')]));}_0x33212a=_0x11735c['clone']();_0x11735c[_0xa4c5('0x38')](_0x40c2af);_0x11735c[_0xa4c5('0x1e')](0x0);return;}})['then'](function(){if(_0x470a0b[_0xa4c5('0x90')]==='web'){return null;}var _0x5a43a3=_[_0xa4c5('0x3d')](_0x470a0b,{'name':_0x470a0b[_0xa4c5('0x91')]||_0x470a0b['name']||_0x5d8983['name'],'basename':_0x114f35,'savename':util[_0xa4c5('0x75')](_0xa4c5('0x92'),_0x470a0b['name']||_0x5d8983['name'],require(_0xa4c5('0x93'))[_0xa4c5('0x94')](0x4),_0x470a0b['output']||_0xa4c5('0x95')),'reportId':_0x5d8983['id'],'reportType':_0xa4c5('0x96')});return db[_0xa4c5('0x97')][_0xa4c5('0x49')](_0x5a43a3,{'raw':!![]});})['then'](function(_0x33d8b2){if(_0x5d8983[_0xa4c5('0x8e')]===_0xa4c5('0x98')){_0x33212a[_0xa4c5('0x3b')](_0x5d8983[_0xa4c5('0x8e')]+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x470a0b[_0xa4c5('0x99')],_0x470a0b[_0xa4c5('0x9a')]);}else{_0x33212a['where'](_0x5d8983[_0xa4c5('0x8e')]+_0xa4c5('0x9b'),_0x470a0b['startDate'],_0x470a0b[_0xa4c5('0x9a')]);}if(_0x33d8b2){logger[_0xa4c5('0x9c')]('Run\x20Query:',_0x33212a[_0xa4c5('0x84')]());require(_0xa4c5('0x9d'))['fork'](path['join'](__dirname,'../../components/export/',_0x33d8b2[_0xa4c5('0x90')]),[_0x33d8b2['id'],_0x33212a[_0xa4c5('0x84')](),path['join'](__dirname,_0xa4c5('0x9e'),_0x33d8b2[_0xa4c5('0x9f')]),_0x114f35]);return _0x33d8b2;}else{var _0xff61e7=squel[_0xa4c5('0x8d')]();_0xff61e7['from']('('+_0x33212a[_0xa4c5('0x84')]()+')',_0xa4c5('0xa0'));_0xff61e7['field'](_0xa4c5('0xa1'),'count');_0x33212a[_0xa4c5('0x38')](_0x470a0b[_0xa4c5('0x38')]||_0x40c2af);_0x33212a[_0xa4c5('0x1e')](_0x470a0b['offset']||0x0);return dbH[_0xa4c5('0x85')]['query'](_0xff61e7[_0xa4c5('0x84')](),{'type':dbH['sequelize'][_0xa4c5('0x86')][_0xa4c5('0xa2')]})['then'](function(_0x67a6bb){if(!_0x67a6bb[_0xa4c5('0x46')]){_0x4fca6b=0x0;}else{_0x4fca6b=_0x67a6bb[0x0]['count']||0x0;}return dbH[_0xa4c5('0x85')][_0xa4c5('0x31')](_0x33212a[_0xa4c5('0x84')](),{'type':dbH[_0xa4c5('0x85')]['QueryTypes'][_0xa4c5('0xa2')]});})[_0xa4c5('0x27')](function(_0x20c0a4){return{'rows':_0x20c0a4||[],'count':_0x4fca6b};});}});}exports[_0xa4c5('0xa3')]=function(_0x8cfa2e,_0x1339b4){return runReport(_0x8cfa2e[_0xa4c5('0x54')],_0x8cfa2e['query'],_0x8cfa2e[_0xa4c5('0x3f')])['then'](respondWithResult(_0x1339b4,null))[_0xa4c5('0x48')](handleError(_0x1339b4,null));};exports[_0xa4c5('0xa4')]=runReport;exports[_0xa4c5('0x31')]=function(_0x570bfc,_0x23e4ad){var _0x462819=0xa;var _0x41c038=['join','left_join',_0xa4c5('0x57'),_0xa4c5('0x58')];var _0x4b074a={'SUM':_0xa4c5('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':_0xa4c5('0x5c'),'AVG':'AVG(%s)','GROUP_CONCAT':_0xa4c5('0x5e'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0xa4c5('0x60')};var _0x9f119c={'SEC_TO_TIME':_0xa4c5('0x88'),'DATE':_0xa4c5('0x61'),'HOUR':_0xa4c5('0x62'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0xa4c5('0x63')};var _0x118a17=function(_0xafc6ce){return!_[_0xa4c5('0x64')]([_0xa4c5('0x65'),'IS\x20NOT\x20NULL',_0xa4c5('0x8a'),_0xa4c5('0x67')],_0xafc6ce);};var _0x1a7cf6=function(_0xab9063){if(!_0xab9063||!_0xab9063[_0xa4c5('0x68')][_0xa4c5('0x46')]){return'';}for(var _0x2c5918='(',_0x43ed39=0x0;_0x43ed39<_0xab9063[_0xa4c5('0x68')][_0xa4c5('0x46')];_0x43ed39+=0x1){_0x43ed39>0x0&&(_0x2c5918+='\x20'+_0xab9063['operator']+'\x20');_0x2c5918+=_0xab9063['rules'][_0x43ed39]['group']?_0x1a7cf6(_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x69')]):_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x6a')]+'\x20'+_0xab9063['rules'][_0x43ed39][_0xa4c5('0x6b')]+(_0x118a17(_0xab9063[_0xa4c5('0x68')][_0x43ed39][_0xa4c5('0x6b')])?'\x20'+_0xab9063['rules'][_0x43ed39][_0xa4c5('0xa5')]:'');}return _0x2c5918+')';};var _0x25425f={'where':{'id':_0x570bfc[_0xa4c5('0x54')]['id']}},_0x55046e,_0x4cd138,_0x1794d6,_0x523163,_0x599026;_0x25425f=_[_0xa4c5('0x3d')]({},_0x25425f,_0x570bfc[_0xa4c5('0x3f')]);return db['AnalyticCustomReport'][_0xa4c5('0x47')](_0x25425f)[_0xa4c5('0x27')](function(_0x95b18c){if(_0x95b18c){_0x55046e=_0x95b18c;return _0x95b18c[_0xa4c5('0x6c')]();}return null;})[_0xa4c5('0x27')](function(_0x43bc8b){if(_0x43bc8b){if(!_0x43bc8b[_0xa4c5('0x46')]){throw new db[(_0xa4c5('0x6d'))][(_0xa4c5('0x8c'))](_0xa4c5('0x6e'),0x193);}_0x4cd138=_0x43bc8b;return db['AnalyticMetric']['findAll']({'raw':!![]});}return null;})[_0xa4c5('0x27')](function(_0x5b6c3f){if(_0x5b6c3f){_0x1794d6=_['keyBy'](_0x5b6c3f,'id');var _0x4143c4;var _0x99b1da=squel['select']();_0x99b1da[_0xa4c5('0x71')](_0x55046e[_0xa4c5('0x8e')]);for(var _0x124ab1=0x0;_0x124ab1<_0x4cd138[_0xa4c5('0x46')];_0x124ab1+=0x1){_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x72')]?_0x1794d6[_0x4cd138[_0x124ab1]['MetricId']][_0xa4c5('0x8f')]:_0x4cd138[_0x124ab1][_0xa4c5('0x6a')];_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x73')]?_[_0xa4c5('0x74')](_0x4b074a[_0x4cd138[_0x124ab1][_0xa4c5('0x73')]],'%s',_0x4143c4):_0x4143c4;_0x4143c4=_0x4cd138[_0x124ab1][_0xa4c5('0x75')]?_[_0xa4c5('0x74')](_0x9f119c[_0x4cd138[_0x124ab1][_0xa4c5('0x75')]],'%s',_0x4143c4):_0x4143c4;if(_0x4cd138[_0x124ab1]['groupBy']){_0x99b1da[_0xa4c5('0x69')](_0x4143c4);}_0x4cd138[_0x124ab1][_0xa4c5('0x77')]&&_0x99b1da[_0xa4c5('0x39')](_0x4143c4,_0x4cd138[_0x124ab1][_0xa4c5('0x77')]===_0xa4c5('0x78')?![]:!![]);_0x99b1da[_0xa4c5('0x6a')](_0x4143c4,_0x4cd138[_0x124ab1]['alias']||_0x4143c4);}if(_0x55046e[_0xa4c5('0x7a')]){_0x55046e['joins']=JSON[_0xa4c5('0x7b')](_0x55046e[_0xa4c5('0x7a')]);for(var _0x260821=0x0;_0x260821<_0x55046e[_0xa4c5('0x7a')][_0xa4c5('0x46')];_0x260821+=0x1){if(_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')]&&_[_0xa4c5('0x64')](_0x41c038,_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')])&&_0x55046e['joins'][_0x260821][_0xa4c5('0x7f')]&&_0x55046e['joins'][_0x260821][_0xa4c5('0x7c')]&&_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7d')]){_0x99b1da[_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x3e')]](_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7c')],null,util[_0xa4c5('0x75')]('%s.%s\x20=\x20%s.%s',_0x55046e['table'],_0x55046e['joins'][_0x260821][_0xa4c5('0x7f')],_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7c')],_0x55046e[_0xa4c5('0x7a')][_0x260821][_0xa4c5('0x7d')]));}}}if(_0x55046e[_0xa4c5('0x80')]){_0x55046e['conditions']=JSON[_0xa4c5('0x7b')](_0x55046e[_0xa4c5('0x80')]);_0x99b1da[_0xa4c5('0x3b')](_0x1a7cf6(_0x55046e[_0xa4c5('0x80')][_0xa4c5('0x69')]));}_0x599026=_0x99b1da[_0xa4c5('0x81')]();_0x99b1da[_0xa4c5('0x38')](_0x462819);_0x99b1da['offset'](0x0);logger[_0xa4c5('0x82')](_0xa4c5('0x83'),_0x99b1da[_0xa4c5('0x84')]());return dbH['sequelize'][_0xa4c5('0x31')](_0x99b1da['toString'](),{'type':dbH[_0xa4c5('0x85')][_0xa4c5('0x86')]['SELECT']});}})[_0xa4c5('0x27')](function(){return{'sql':_0x599026[_0xa4c5('0x84')]()};})['then'](respondWithResult(_0x23e4ad,null))[_0xa4c5('0x48')](handleError(_0x23e4ad,null));};
\ No newline at end of file