Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index 9a0b31a..489cafb 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x384b=['send','merge','body','contact','message','agent','index','AnalyticCustomReport','rawAttributes','model','map','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','sort','where','filter','type','options','includeAll','include','rows','params','find','catch','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','join','left_join','right_join','cross_join','SUM(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','HOUR(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','IS\x20NULL','IS\x20NOT\x20NULL','rules','operator','group','field','condition','getFields','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','findAll','select','MetricId','metric','replace','function','format','groupBy','orderBy','order','DESC','alias','joins','parse','includes','parentKey','foreignTable','foreignKey','%s.%s\x20=\x20%s.%s','table','conditions','clone','debug','Limited\x20Query:','sequelize','toString','QueryTypes','SELECT','COUNT(DISTINCT\x20%s)','MAX(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','IS\x20EMPTY','IS\x20NOT\x20EMPTY','value','keyBy','from','web','fullPath','%s-%s.%s','randomstring','output','csv','custom','AnalyticExtractedReport','cdr','.calldate\x20BETWEEN\x20?\x20AND\x20?','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','child_process','../../components/export/','../../files/reports','savename','countTable','COUNT(*)','run','runReport','COUNT(%s)','DATE(%s)','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','dbH','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','reject','save','then','destroy','get','CustomReports','UserProfileResource','error','stack','name'];(function(_0x1c56b1,_0x12b079){var _0x137e84=function(_0x273391){while(--_0x273391){_0x1c56b1['push'](_0x1c56b1['shift']());}};_0x137e84(++_0x12b079);}(_0x384b,0x1cc));var _0xb384=function(_0x718c5c,_0x9d04e0){_0x718c5c=_0x718c5c-0x0;var _0xcd2d8b=_0x384b[_0x718c5c];return _0xcd2d8b;};'use strict';var emlformat=require(_0xb384('0x0'));var rimraf=require(_0xb384('0x1'));var zipdir=require(_0xb384('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xb384('0x3'));var BPromise=require(_0xb384('0x4'));var Mustache=require(_0xb384('0x5'));var util=require(_0xb384('0x6'));var path=require(_0xb384('0x7'));var sox=require(_0xb384('0x8'));var csv=require(_0xb384('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb384('0xa'));var _=require(_0xb384('0xb'));var squel=require('squel');var crypto=require(_0xb384('0xc'));var jsforce=require(_0xb384('0xd'));var deskjs=require(_0xb384('0xe'));var toCsv=require(_0xb384('0x9'));var querystring=require(_0xb384('0xf'));var Papa=require(_0xb384('0x10'));var Redis=require(_0xb384('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xb384('0x12'));var as=require(_0xb384('0x13'));var hardwareService=require(_0xb384('0x14'));var logger=require('../../config/logger')(_0xb384('0x15'));var utils=require(_0xb384('0x16'));var config=require(_0xb384('0x17'));var licenseUtil=require(_0xb384('0x18'));var db=require(_0xb384('0x19'))['db'];var dbH=require('../../mysqldb')[_0xb384('0x1a')];function respondWithStatusCode(_0xf8331c,_0x4f96f5){_0x4f96f5=_0x4f96f5||0xcc;return function(_0x134d2d){if(_0x134d2d){return _0xf8331c[_0xb384('0x1b')](_0x4f96f5);}return _0xf8331c[_0xb384('0x1c')](_0x4f96f5)[_0xb384('0x1d')]();};}function respondWithResult(_0x345f6a,_0x50ed6a){_0x50ed6a=_0x50ed6a||0xc8;return function(_0x3bf607){if(_0x3bf607){return _0x345f6a[_0xb384('0x1c')](_0x50ed6a)[_0xb384('0x1e')](_0x3bf607);}};}function respondWithFilteredResult(_0x16fb62,_0x11ba89){return function(_0x18866a){if(_0x18866a){var _0x33d7ed=typeof _0x11ba89[_0xb384('0x1f')]===_0xb384('0x20')&&typeof _0x11ba89[_0xb384('0x21')]==='undefined';var _0x5019ea=_0x18866a[_0xb384('0x22')];var _0x4211db=_0x33d7ed?0x0:_0x11ba89[_0xb384('0x1f')];var _0x4a5c60=_0x33d7ed?_0x18866a[_0xb384('0x22')]:_0x11ba89[_0xb384('0x1f')]+_0x11ba89['limit'];var _0xb43b1e;if(_0x4a5c60>=_0x5019ea){_0x4a5c60=_0x5019ea;_0xb43b1e=0xc8;}else{_0xb43b1e=0xce;}_0x16fb62[_0xb384('0x1c')](_0xb43b1e);return _0x16fb62[_0xb384('0x23')](_0xb384('0x24'),_0x4211db+'-'+_0x4a5c60+'/'+_0x5019ea)[_0xb384('0x1e')](_0x18866a);}return null;};}function patchUpdates(_0x52dbd3){return function(_0x217241){try{jsonpatch['apply'](_0x217241,_0x52dbd3,!![]);}catch(_0x48ea3b){return BPromise[_0xb384('0x25')](_0x48ea3b);}return _0x217241[_0xb384('0x26')]();};}function saveUpdates(_0x508311,_0x59aaac){return function(_0x37cdc7){if(_0x37cdc7){return _0x37cdc7['update'](_0x508311)[_0xb384('0x27')](function(_0x193ee1){return _0x193ee1;});}return null;};}function removeEntity(_0x55aff2,_0x2d83b5){return function(_0x4ca357){if(_0x4ca357){return _0x4ca357[_0xb384('0x28')]()[_0xb384('0x27')](function(){var _0x26541a=_0x4ca357[_0xb384('0x29')]({'plain':!![]});var _0x45bfd2=_0xb384('0x2a');return db[_0xb384('0x2b')][_0xb384('0x28')]({'where':{'type':_0x45bfd2,'resourceId':_0x26541a['id']}})[_0xb384('0x27')](function(){return _0x4ca357;});})[_0xb384('0x27')](function(){_0x55aff2[_0xb384('0x1c')](0xcc)[_0xb384('0x1d')]();});}};}function handleEntityNotFound(_0x4d846a,_0x13cb64){return function(_0xc912da){if(!_0xc912da){_0x4d846a[_0xb384('0x1b')](0x194);}return _0xc912da;};}function handleError(_0xcbd1ce,_0x16ff32){_0x16ff32=_0x16ff32||0x1f4;return function(_0x491393){logger[_0xb384('0x2c')](_0x491393[_0xb384('0x2d')]);if(_0x491393[_0xb384('0x2e')]){delete _0x491393['name'];}_0xcbd1ce[_0xb384('0x1c')](_0x16ff32)[_0xb384('0x2f')](_0x491393);};}function getMustacheRender(_0x1d346e,_0x43b4aa){return Mustache['render'](_0x1d346e,_[_0xb384('0x30')](_0x43b4aa[_0xb384('0x31')],{'contact':_0x43b4aa[_0xb384('0x32')],'message':_0x43b4aa[_0xb384('0x33')],'agent':_0x43b4aa[_0xb384('0x34')],'interaction':_0x43b4aa['interaction'],'account':_0x43b4aa['account']}))||'';}exports[_0xb384('0x35')]=function(_0x3327bb,_0x1af631){var _0x3ce6d2={},_0x487fc6={},_0x3664e3={'count':0x0,'rows':[]};var _0x5c0fb5=_['map'](db[_0xb384('0x36')][_0xb384('0x37')],function(_0x19fb44){return{'name':_0x19fb44['fieldName'],'type':_0x19fb44['type']['key']};});_0x487fc6[_0xb384('0x38')]=_[_0xb384('0x39')](_0x5c0fb5,_0xb384('0x2e'));_0x487fc6[_0xb384('0x3a')]=_[_0xb384('0x3b')](_0x3327bb[_0xb384('0x3a')]);_0x487fc6[_0xb384('0x3c')]=_['intersection'](_0x487fc6[_0xb384('0x38')],_0x487fc6[_0xb384('0x3a')]);_0x3ce6d2['attributes']=_[_0xb384('0x3d')](_0x487fc6[_0xb384('0x38')],qs['fields'](_0x3327bb[_0xb384('0x3a')][_0xb384('0x3e')]));_0x3ce6d2[_0xb384('0x3f')]=_0x3ce6d2['attributes'][_0xb384('0x40')]?_0x3ce6d2['attributes']:_0x487fc6[_0xb384('0x38')];if(!_0x3327bb['query'][_0xb384('0x41')]('nolimit')){_0x3ce6d2[_0xb384('0x21')]=qs[_0xb384('0x21')](_0x3327bb[_0xb384('0x3a')]['limit']);_0x3ce6d2['offset']=qs[_0xb384('0x1f')](_0x3327bb[_0xb384('0x3a')]['offset']);}_0x3ce6d2['order']=qs['sort'](_0x3327bb[_0xb384('0x3a')][_0xb384('0x42')]);_0x3ce6d2[_0xb384('0x43')]=qs[_0xb384('0x3c')](_['pick'](_0x3327bb['query'],_0x487fc6[_0xb384('0x3c')]),_0x5c0fb5);if(_0x3327bb['query'][_0xb384('0x44')]){_0x3ce6d2['where']=_[_0xb384('0x30')](_0x3ce6d2[_0xb384('0x43')],{'$or':_[_0xb384('0x39')](_0x5c0fb5,function(_0x14bbc4){if(_0x14bbc4[_0xb384('0x45')]!=='VIRTUAL'){var _0x87dd96={};_0x87dd96[_0x14bbc4[_0xb384('0x2e')]]={'$like':'%'+_0x3327bb[_0xb384('0x3a')][_0xb384('0x44')]+'%'};return _0x87dd96;}})});}_0x3ce6d2=_[_0xb384('0x30')]({},_0x3ce6d2,_0x3327bb[_0xb384('0x46')]);var _0x3cabbe={'where':_0x3ce6d2[_0xb384('0x43')]};return db[_0xb384('0x36')]['count'](_0x3cabbe)['then'](function(_0x29565c){_0x3664e3[_0xb384('0x22')]=_0x29565c;if(_0x3327bb['query'][_0xb384('0x47')]){_0x3ce6d2[_0xb384('0x48')]=[{'all':!![]}];}return db[_0xb384('0x36')]['findAll'](_0x3ce6d2);})[_0xb384('0x27')](function(_0x33d220){_0x3664e3[_0xb384('0x49')]=_0x33d220;return _0x3664e3;})[_0xb384('0x27')](respondWithFilteredResult(_0x1af631,_0x3ce6d2))['catch'](handleError(_0x1af631,null));};exports['show']=function(_0x1c1ac3,_0x9cbbd1){var _0x559d54={'raw':![],'where':{'id':_0x1c1ac3[_0xb384('0x4a')]['id']}},_0x3cc78b={};_0x3cc78b[_0xb384('0x38')]=_[_0xb384('0x3b')](db[_0xb384('0x36')][_0xb384('0x37')]);_0x3cc78b[_0xb384('0x3a')]=_[_0xb384('0x3b')](_0x1c1ac3[_0xb384('0x3a')]);_0x3cc78b['filters']=_[_0xb384('0x3d')](_0x3cc78b[_0xb384('0x38')],_0x3cc78b['query']);_0x559d54[_0xb384('0x3f')]=_[_0xb384('0x3d')](_0x3cc78b['model'],qs['fields'](_0x1c1ac3[_0xb384('0x3a')][_0xb384('0x3e')]));_0x559d54[_0xb384('0x3f')]=_0x559d54[_0xb384('0x3f')]['length']?_0x559d54['attributes']:_0x3cc78b[_0xb384('0x38')];if(_0x1c1ac3['query'][_0xb384('0x47')]){_0x559d54['include']=[{'all':!![]}];}_0x559d54=_[_0xb384('0x30')]({},_0x559d54,_0x1c1ac3[_0xb384('0x46')]);return db['AnalyticCustomReport'][_0xb384('0x4b')](_0x559d54)['then'](handleEntityNotFound(_0x9cbbd1,null))['then'](respondWithResult(_0x9cbbd1,null))[_0xb384('0x4c')](handleError(_0x9cbbd1,null));};exports[_0xb384('0x4d')]=function(_0x1312a8,_0x9e1812){return db[_0xb384('0x36')][_0xb384('0x4d')](_0x1312a8[_0xb384('0x31')],{})[_0xb384('0x27')](function(_0x5d8f84){var _0x52be83=_0x1312a8[_0xb384('0x4e')][_0xb384('0x29')]({'plain':!![]});if(!_0x52be83)throw new Error(_0xb384('0x4f'));if(_0x52be83[_0xb384('0x50')]===_0xb384('0x4e')){var _0x47ac00=_0x5d8f84[_0xb384('0x29')]({'plain':!![]});var _0xd91d13='Reports';return db[_0xb384('0x51')][_0xb384('0x4b')]({'where':{'name':_0xd91d13,'userProfileId':_0x52be83[_0xb384('0x52')]},'raw':!![]})[_0xb384('0x27')](function(_0x47a016){if(_0x47a016&&_0x47a016[_0xb384('0x53')]===0x0){return db[_0xb384('0x2b')][_0xb384('0x4d')]({'name':_0x47ac00[_0xb384('0x2e')],'resourceId':_0x47ac00['id'],'type':_0xb384('0x2a'),'sectionId':_0x47a016['id']},{})[_0xb384('0x27')](function(){return _0x5d8f84;});}else{return _0x5d8f84;}})['catch'](function(_0x5d5cef){logger[_0xb384('0x2c')](_0xb384('0x54'),_0x5d5cef);throw _0x5d5cef;});}return _0x5d8f84;})[_0xb384('0x27')](respondWithResult(_0x9e1812,0xc9))[_0xb384('0x4c')](handleError(_0x9e1812,null));};exports['update']=function(_0x222bd8,_0x3686b8){if(_0x222bd8[_0xb384('0x31')]['id']){delete _0x222bd8[_0xb384('0x31')]['id'];}return db[_0xb384('0x36')]['find']({'where':{'id':_0x222bd8['params']['id']}})['then'](handleEntityNotFound(_0x3686b8,null))[_0xb384('0x27')](saveUpdates(_0x222bd8[_0xb384('0x31')],null))[_0xb384('0x27')](respondWithResult(_0x3686b8,null))[_0xb384('0x4c')](handleError(_0x3686b8,null));};exports[_0xb384('0x28')]=function(_0x266330,_0x3ae53d){return db[_0xb384('0x36')][_0xb384('0x4b')]({'where':{'id':_0x266330[_0xb384('0x4a')]['id']}})[_0xb384('0x27')](handleEntityNotFound(_0x3ae53d,null))[_0xb384('0x27')](removeEntity(_0x3ae53d,null))['catch'](handleError(_0x3ae53d,null));};exports['preview']=function(_0xe19bdf,_0x191355){var _0x2f74ec=0xa;var _0x3f181e=[_0xb384('0x55'),_0xb384('0x56'),_0xb384('0x57'),_0xb384('0x58')];var _0x33e0a5={'SUM':_0xb384('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':'MAX(%s)','MIN':_0xb384('0x5a'),'AVG':_0xb384('0x5b'),'GROUP_CONCAT':_0xb384('0x5c'),'GROUP_CONCAT ASC':_0xb384('0x5d'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0xfb8e1f={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':'DATE(%s)','HOUR':_0xb384('0x5e'),'ROUND':_0xb384('0x5f'),'UNIX_TIMESTAMP':_0xb384('0x60')};var _0x154be5=function(_0x146631){return!_['includes']([_0xb384('0x61'),_0xb384('0x62'),'IS\x20EMPTY','IS\x20NOT\x20EMPTY'],_0x146631);};var _0x286de5=function(_0xb038b8){if(!_0xb038b8||!_0xb038b8['rules'][_0xb384('0x40')]){return'';}for(var _0x334cb2='(',_0x5d6432=0x0;_0x5d6432<_0xb038b8[_0xb384('0x63')][_0xb384('0x40')];_0x5d6432+=0x1){_0x5d6432>0x0&&(_0x334cb2+='\x20'+_0xb038b8[_0xb384('0x64')]+'\x20');_0x334cb2+=_0xb038b8['rules'][_0x5d6432]['group']?_0x286de5(_0xb038b8['rules'][_0x5d6432][_0xb384('0x65')]):_0xb038b8[_0xb384('0x63')][_0x5d6432][_0xb384('0x66')]+'\x20'+_0xb038b8['rules'][_0x5d6432][_0xb384('0x67')]+(_0x154be5(_0xb038b8['rules'][_0x5d6432][_0xb384('0x67')])?'\x20'+_0xb038b8[_0xb384('0x63')][_0x5d6432]['value']:'');}return _0x334cb2+')';};var _0x526866={'where':{'id':_0xe19bdf[_0xb384('0x4a')]['id']}},_0x331f92,_0x526f30,_0x2c1244,_0x43d504,_0x2f0edf;_0x526866=_['merge']({},_0x526866,_0xe19bdf[_0xb384('0x46')]);return db[_0xb384('0x36')][_0xb384('0x4b')](_0x526866)['then'](function(_0x17467b){if(_0x17467b){_0x331f92=_0x17467b;return _0x17467b[_0xb384('0x68')]();}return null;})[_0xb384('0x27')](function(_0x54c09e){if(_0x54c09e){if(!_0x54c09e['length']){throw new db['Sequelize'][(_0xb384('0x69'))](_0xb384('0x6a'),0x193);}_0x526f30=_0x54c09e;return db[_0xb384('0x6b')][_0xb384('0x6c')]({'raw':!![]});}return null;})[_0xb384('0x27')](function(_0x4f62db){if(_0x4f62db){_0x2c1244=_['keyBy'](_0x4f62db,'id');var _0x1d9134;var _0x2102a3=squel[_0xb384('0x6d')]();_0x2102a3['from'](_0x331f92['table']);for(var _0x350cd9=0x0;_0x350cd9<_0x526f30['length'];_0x350cd9+=0x1){_0x1d9134=_0x526f30[_0x350cd9][_0xb384('0x6e')]?_0x2c1244[_0x526f30[_0x350cd9][_0xb384('0x6e')]][_0xb384('0x6f')]:_0x526f30[_0x350cd9][_0xb384('0x66')];_0x1d9134=_0x526f30[_0x350cd9]['function']?_[_0xb384('0x70')](_0x33e0a5[_0x526f30[_0x350cd9][_0xb384('0x71')]],'%s',_0x1d9134):_0x1d9134;_0x1d9134=_0x526f30[_0x350cd9]['format']?_[_0xb384('0x70')](_0xfb8e1f[_0x526f30[_0x350cd9][_0xb384('0x72')]],'%s',_0x1d9134):_0x1d9134;if(_0x526f30[_0x350cd9][_0xb384('0x73')]){_0x2102a3[_0xb384('0x65')](_0x1d9134);}_0x526f30[_0x350cd9][_0xb384('0x74')]&&_0x2102a3[_0xb384('0x75')](_0x1d9134,_0x526f30[_0x350cd9][_0xb384('0x74')]===_0xb384('0x76')?![]:!![]);_0x2102a3[_0xb384('0x66')](_0x1d9134,_0x526f30[_0x350cd9][_0xb384('0x77')]||_0x1d9134);}if(_0x331f92[_0xb384('0x78')]){_0x331f92[_0xb384('0x78')]=JSON[_0xb384('0x79')](_0x331f92['joins']);for(var _0x105e59=0x0;_0x105e59<_0x331f92['joins']['length'];_0x105e59+=0x1){if(_0x331f92['joins'][_0x105e59][_0xb384('0x45')]&&_[_0xb384('0x7a')](_0x3f181e,_0x331f92[_0xb384('0x78')][_0x105e59][_0xb384('0x45')])&&_0x331f92[_0xb384('0x78')][_0x105e59][_0xb384('0x7b')]&&_0x331f92['joins'][_0x105e59][_0xb384('0x7c')]&&_0x331f92[_0xb384('0x78')][_0x105e59][_0xb384('0x7d')]){_0x2102a3[_0x331f92[_0xb384('0x78')][_0x105e59][_0xb384('0x45')]](_0x331f92[_0xb384('0x78')][_0x105e59][_0xb384('0x7c')],null,util['format'](_0xb384('0x7e'),_0x331f92[_0xb384('0x7f')],_0x331f92[_0xb384('0x78')][_0x105e59]['parentKey'],_0x331f92['joins'][_0x105e59]['foreignTable'],_0x331f92[_0xb384('0x78')][_0x105e59]['foreignKey']));}}}if(_0x331f92[_0xb384('0x80')]){_0x331f92[_0xb384('0x80')]=JSON['parse'](_0x331f92['conditions']);_0x2102a3['where'](_0x286de5(_0x331f92[_0xb384('0x80')]['group']));}_0x2f0edf=_0x2102a3[_0xb384('0x81')]();_0x2102a3[_0xb384('0x21')](_0x2f74ec);_0x2102a3[_0xb384('0x1f')](0x0);logger[_0xb384('0x82')](_0xb384('0x83'),_0x2102a3['toString']());return dbH[_0xb384('0x84')][_0xb384('0x3a')](_0x2102a3[_0xb384('0x85')](),{'type':dbH[_0xb384('0x84')][_0xb384('0x86')][_0xb384('0x87')]});}})['then'](respondWithResult(_0x191355,null))[_0xb384('0x4c')](handleError(_0x191355,null));};function runReport(_0x299d1e,_0x303067,_0x5ae8e4){var _0x37d465=_0x303067[_0xb384('0x2e')];var _0x2d979e=0xa;var _0x297987=[_0xb384('0x55'),_0xb384('0x56'),_0xb384('0x57'),'cross_join'];var _0x3513cb={'SUM':_0xb384('0x59'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0xb384('0x88'),'MAX':_0xb384('0x89'),'MIN':_0xb384('0x5a'),'AVG':_0xb384('0x5b'),'GROUP_CONCAT':_0xb384('0x5c'),'GROUP_CONCAT ASC':_0xb384('0x5d'),'GROUP_CONCAT DESC':_0xb384('0x8a')};var _0x1b62fd={'SEC_TO_TIME':_0xb384('0x8b'),'DATE':'DATE(%s)','HOUR':_0xb384('0x5e'),'ROUND':_0xb384('0x5f'),'UNIX_TIMESTAMP':_0xb384('0x60')};var _0x5cadfb=function(_0x774373){return!_['includes']([_0xb384('0x61'),_0xb384('0x62'),_0xb384('0x8c'),_0xb384('0x8d')],_0x774373);};var _0x35df10=function(_0x432657){if(!_0x432657||!_0x432657[_0xb384('0x63')][_0xb384('0x40')]){return'';}for(var _0x41c73a='(',_0x3c9a47=0x0;_0x3c9a47<_0x432657[_0xb384('0x63')]['length'];_0x3c9a47+=0x1){_0x3c9a47>0x0&&(_0x41c73a+='\x20'+_0x432657[_0xb384('0x64')]+'\x20');_0x41c73a+=_0x432657[_0xb384('0x63')][_0x3c9a47][_0xb384('0x65')]?_0x35df10(_0x432657[_0xb384('0x63')][_0x3c9a47]['group']):_0x432657[_0xb384('0x63')][_0x3c9a47]['field']+'\x20'+_0x432657['rules'][_0x3c9a47][_0xb384('0x67')]+(_0x5cadfb(_0x432657[_0xb384('0x63')][_0x3c9a47]['condition'])?'\x20'+_0x432657['rules'][_0x3c9a47][_0xb384('0x8e')]:'');}return _0x41c73a+')';};var _0x1d7706={'where':{'id':_0x299d1e['id']}},_0x266a41,_0x568260,_0x4a92b3,_0xcaae81,_0x350b18;_0x1d7706=_[_0xb384('0x30')]({},_0x1d7706,_0x5ae8e4);return db['AnalyticCustomReport']['find'](_0x1d7706)[_0xb384('0x27')](function(_0x24e0b3){if(_0x24e0b3){_0x266a41=_0x24e0b3;return _0x24e0b3[_0xb384('0x68')]();}return null;})[_0xb384('0x27')](function(_0x227099){if(_0x227099){if(!_0x227099[_0xb384('0x40')]){throw new db['Sequelize']['ValidationErrorItem'](_0xb384('0x6a'),0x193);}_0x568260=_0x227099;return db['AnalyticMetric'][_0xb384('0x6c')]({'raw':!![]});}return null;})[_0xb384('0x27')](function(_0x58d2be){if(_0x58d2be){_0x4a92b3=_[_0xb384('0x8f')](_0x58d2be,'id');var _0x3bc2d2;var _0x17c978=squel[_0xb384('0x6d')]();_0x17c978[_0xb384('0x90')](_0x266a41['table']);for(var _0x41536b=0x0;_0x41536b<_0x568260[_0xb384('0x40')];_0x41536b+=0x1){_0x3bc2d2=_0x568260[_0x41536b]['MetricId']?_0x4a92b3[_0x568260[_0x41536b][_0xb384('0x6e')]]['metric']:_0x568260[_0x41536b][_0xb384('0x66')];_0x3bc2d2=_0x568260[_0x41536b][_0xb384('0x71')]?_['replace'](_0x3513cb[_0x568260[_0x41536b][_0xb384('0x71')]],'%s',_0x3bc2d2):_0x3bc2d2;_0x3bc2d2=_0x568260[_0x41536b][_0xb384('0x72')]?_['replace'](_0x1b62fd[_0x568260[_0x41536b][_0xb384('0x72')]],'%s',_0x3bc2d2):_0x3bc2d2;if(_0x568260[_0x41536b][_0xb384('0x73')]){_0x17c978[_0xb384('0x65')](_0x3bc2d2);}_0x568260[_0x41536b][_0xb384('0x74')]&&_0x17c978[_0xb384('0x75')](_0x3bc2d2,_0x568260[_0x41536b]['orderBy']==='DESC'?![]:!![]);_0x17c978[_0xb384('0x66')](_0x3bc2d2,_0x568260[_0x41536b][_0xb384('0x77')]||_0x3bc2d2);}if(_0x266a41[_0xb384('0x78')]){_0x266a41[_0xb384('0x78')]=JSON[_0xb384('0x79')](_0x266a41[_0xb384('0x78')]);for(var _0x4a14b4=0x0;_0x4a14b4<_0x266a41[_0xb384('0x78')]['length'];_0x4a14b4+=0x1){if(_0x266a41[_0xb384('0x78')][_0x4a14b4][_0xb384('0x45')]&&_[_0xb384('0x7a')](_0x297987,_0x266a41[_0xb384('0x78')][_0x4a14b4][_0xb384('0x45')])&&_0x266a41[_0xb384('0x78')][_0x4a14b4][_0xb384('0x7b')]&&_0x266a41['joins'][_0x4a14b4][_0xb384('0x7c')]&&_0x266a41[_0xb384('0x78')][_0x4a14b4][_0xb384('0x7d')]){_0x17c978[_0x266a41[_0xb384('0x78')][_0x4a14b4][_0xb384('0x45')]](_0x266a41[_0xb384('0x78')][_0x4a14b4][_0xb384('0x7c')],null,util[_0xb384('0x72')](_0xb384('0x7e'),_0x266a41['table'],_0x266a41['joins'][_0x4a14b4][_0xb384('0x7b')],_0x266a41[_0xb384('0x78')][_0x4a14b4][_0xb384('0x7c')],_0x266a41['joins'][_0x4a14b4][_0xb384('0x7d')]));}}}if(_0x266a41['conditions']){_0x266a41[_0xb384('0x80')]=JSON['parse'](_0x266a41[_0xb384('0x80')]);_0x17c978[_0xb384('0x43')](_0x35df10(_0x266a41[_0xb384('0x80')]['group']));}_0x350b18=_0x17c978['clone']();_0x17c978['limit'](_0x2d979e);_0x17c978[_0xb384('0x1f')](0x0);return;}})[_0xb384('0x27')](function(){if(_0x303067['output']===_0xb384('0x91')){return null;}var _0x242361=_[_0xb384('0x30')](_0x303067,{'name':_0x303067[_0xb384('0x92')]||_0x303067[_0xb384('0x2e')]||_0x266a41['name'],'basename':_0x37d465,'savename':util[_0xb384('0x72')](_0xb384('0x93'),_0x303067[_0xb384('0x2e')]||_0x266a41[_0xb384('0x2e')],require(_0xb384('0x94'))['generate'](0x4),_0x303067[_0xb384('0x95')]||_0xb384('0x96')),'reportId':_0x266a41['id'],'reportType':_0xb384('0x97')});return db[_0xb384('0x98')][_0xb384('0x4d')](_0x242361,{'raw':!![]});})[_0xb384('0x27')](function(_0x2fc917){if(_0x266a41[_0xb384('0x7f')]===_0xb384('0x99')){_0x350b18[_0xb384('0x43')](_0x266a41['table']+_0xb384('0x9a'),_0x303067[_0xb384('0x9b')],_0x303067[_0xb384('0x9c')]);}else{_0x350b18['where'](_0x266a41[_0xb384('0x7f')]+_0xb384('0x9d'),_0x303067[_0xb384('0x9b')],_0x303067[_0xb384('0x9c')]);}if(_0x2fc917){logger[_0xb384('0x9e')]('Run\x20Query:',_0x350b18[_0xb384('0x85')]());require(_0xb384('0x9f'))['fork'](path['join'](__dirname,_0xb384('0xa0'),_0x2fc917[_0xb384('0x95')]),[_0x2fc917['id'],_0x350b18[_0xb384('0x85')](),path[_0xb384('0x55')](__dirname,_0xb384('0xa1'),_0x2fc917[_0xb384('0xa2')]),_0x37d465]);return _0x2fc917;}else{var _0x5756e5=squel[_0xb384('0x6d')]();_0x5756e5[_0xb384('0x90')]('('+_0x350b18['toString']()+')',_0xb384('0xa3'));_0x5756e5[_0xb384('0x66')](_0xb384('0xa4'),_0xb384('0x22'));_0x350b18['limit'](_0x303067[_0xb384('0x21')]||_0x2d979e);_0x350b18[_0xb384('0x1f')](_0x303067[_0xb384('0x1f')]||0x0);return dbH[_0xb384('0x84')][_0xb384('0x3a')](_0x5756e5['toString'](),{'type':dbH[_0xb384('0x84')][_0xb384('0x86')][_0xb384('0x87')]})[_0xb384('0x27')](function(_0x404f37){if(!_0x404f37[_0xb384('0x40')]){_0xcaae81=0x0;}else{_0xcaae81=_0x404f37[0x0][_0xb384('0x22')]||0x0;}return dbH[_0xb384('0x84')]['query'](_0x350b18['toString'](),{'type':dbH[_0xb384('0x84')]['QueryTypes']['SELECT']});})['then'](function(_0x5615c3){return{'rows':_0x5615c3||[],'count':_0xcaae81};});}});}exports[_0xb384('0xa5')]=function(_0x336fd3,_0x435587){return runReport(_0x336fd3[_0xb384('0x4a')],_0x336fd3[_0xb384('0x3a')],_0x336fd3[_0xb384('0x46')])[_0xb384('0x27')](respondWithResult(_0x435587,null))[_0xb384('0x4c')](handleError(_0x435587,null));};exports[_0xb384('0xa6')]=runReport;exports[_0xb384('0x3a')]=function(_0xbff713,_0x42e0e3){var _0x340e44=0xa;var _0x2a2600=[_0xb384('0x55'),_0xb384('0x56'),_0xb384('0x57'),_0xb384('0x58')];var _0x380e90={'SUM':'SUM(%s)','COUNT':_0xb384('0xa7'),'COUNT DISTINCT':_0xb384('0x88'),'MAX':_0xb384('0x89'),'MIN':_0xb384('0x5a'),'AVG':_0xb384('0x5b'),'GROUP_CONCAT':_0xb384('0x5c'),'GROUP_CONCAT ASC':_0xb384('0x5d'),'GROUP_CONCAT DESC':_0xb384('0x8a')};var _0x118b86={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0xb384('0xa8'),'HOUR':_0xb384('0x5e'),'ROUND':_0xb384('0x5f'),'UNIX_TIMESTAMP':_0xb384('0x60')};var _0x23fbd9=function(_0x1d4738){return!_[_0xb384('0x7a')]([_0xb384('0x61'),_0xb384('0x62'),_0xb384('0x8c'),_0xb384('0x8d')],_0x1d4738);};var _0xd81df2=function(_0x5a444f){if(!_0x5a444f||!_0x5a444f[_0xb384('0x63')]['length']){return'';}for(var _0x314d29='(',_0x3eff3a=0x0;_0x3eff3a<_0x5a444f['rules']['length'];_0x3eff3a+=0x1){_0x3eff3a>0x0&&(_0x314d29+='\x20'+_0x5a444f[_0xb384('0x64')]+'\x20');_0x314d29+=_0x5a444f['rules'][_0x3eff3a][_0xb384('0x65')]?_0xd81df2(_0x5a444f['rules'][_0x3eff3a][_0xb384('0x65')]):_0x5a444f[_0xb384('0x63')][_0x3eff3a][_0xb384('0x66')]+'\x20'+_0x5a444f[_0xb384('0x63')][_0x3eff3a][_0xb384('0x67')]+(_0x23fbd9(_0x5a444f[_0xb384('0x63')][_0x3eff3a][_0xb384('0x67')])?'\x20'+_0x5a444f[_0xb384('0x63')][_0x3eff3a][_0xb384('0x8e')]:'');}return _0x314d29+')';};var _0xdb6c91={'where':{'id':_0xbff713['params']['id']}},_0x5ba642,_0x3e90e8,_0x422c4b,_0xb760dd,_0x1ababb;_0xdb6c91=_[_0xb384('0x30')]({},_0xdb6c91,_0xbff713[_0xb384('0x46')]);return db[_0xb384('0x36')][_0xb384('0x4b')](_0xdb6c91)[_0xb384('0x27')](function(_0x37072b){if(_0x37072b){_0x5ba642=_0x37072b;return _0x37072b[_0xb384('0x68')]();}return null;})[_0xb384('0x27')](function(_0x40c922){if(_0x40c922){if(!_0x40c922[_0xb384('0x40')]){throw new db['Sequelize'][(_0xb384('0x69'))](_0xb384('0x6a'),0x193);}_0x3e90e8=_0x40c922;return db[_0xb384('0x6b')][_0xb384('0x6c')]({'raw':!![]});}return null;})[_0xb384('0x27')](function(_0x1dca74){if(_0x1dca74){_0x422c4b=_[_0xb384('0x8f')](_0x1dca74,'id');var _0x5e987c;var _0x39cc52=squel['select']();_0x39cc52[_0xb384('0x90')](_0x5ba642[_0xb384('0x7f')]);for(var _0x3c41ca=0x0;_0x3c41ca<_0x3e90e8[_0xb384('0x40')];_0x3c41ca+=0x1){_0x5e987c=_0x3e90e8[_0x3c41ca][_0xb384('0x6e')]?_0x422c4b[_0x3e90e8[_0x3c41ca]['MetricId']]['metric']:_0x3e90e8[_0x3c41ca][_0xb384('0x66')];_0x5e987c=_0x3e90e8[_0x3c41ca][_0xb384('0x71')]?_[_0xb384('0x70')](_0x380e90[_0x3e90e8[_0x3c41ca]['function']],'%s',_0x5e987c):_0x5e987c;_0x5e987c=_0x3e90e8[_0x3c41ca][_0xb384('0x72')]?_[_0xb384('0x70')](_0x118b86[_0x3e90e8[_0x3c41ca][_0xb384('0x72')]],'%s',_0x5e987c):_0x5e987c;if(_0x3e90e8[_0x3c41ca][_0xb384('0x73')]){_0x39cc52[_0xb384('0x65')](_0x5e987c);}_0x3e90e8[_0x3c41ca][_0xb384('0x74')]&&_0x39cc52[_0xb384('0x75')](_0x5e987c,_0x3e90e8[_0x3c41ca]['orderBy']===_0xb384('0x76')?![]:!![]);_0x39cc52[_0xb384('0x66')](_0x5e987c,_0x3e90e8[_0x3c41ca]['alias']||_0x5e987c);}if(_0x5ba642[_0xb384('0x78')]){_0x5ba642[_0xb384('0x78')]=JSON[_0xb384('0x79')](_0x5ba642[_0xb384('0x78')]);for(var _0x5d2a88=0x0;_0x5d2a88<_0x5ba642[_0xb384('0x78')][_0xb384('0x40')];_0x5d2a88+=0x1){if(_0x5ba642[_0xb384('0x78')][_0x5d2a88][_0xb384('0x45')]&&_[_0xb384('0x7a')](_0x2a2600,_0x5ba642[_0xb384('0x78')][_0x5d2a88]['type'])&&_0x5ba642[_0xb384('0x78')][_0x5d2a88][_0xb384('0x7b')]&&_0x5ba642[_0xb384('0x78')][_0x5d2a88][_0xb384('0x7c')]&&_0x5ba642[_0xb384('0x78')][_0x5d2a88]['foreignKey']){_0x39cc52[_0x5ba642[_0xb384('0x78')][_0x5d2a88][_0xb384('0x45')]](_0x5ba642[_0xb384('0x78')][_0x5d2a88][_0xb384('0x7c')],null,util[_0xb384('0x72')](_0xb384('0x7e'),_0x5ba642['table'],_0x5ba642['joins'][_0x5d2a88]['parentKey'],_0x5ba642[_0xb384('0x78')][_0x5d2a88][_0xb384('0x7c')],_0x5ba642[_0xb384('0x78')][_0x5d2a88][_0xb384('0x7d')]));}}}if(_0x5ba642[_0xb384('0x80')]){_0x5ba642[_0xb384('0x80')]=JSON[_0xb384('0x79')](_0x5ba642['conditions']);_0x39cc52[_0xb384('0x43')](_0xd81df2(_0x5ba642[_0xb384('0x80')][_0xb384('0x65')]));}_0x1ababb=_0x39cc52[_0xb384('0x81')]();_0x39cc52[_0xb384('0x21')](_0x340e44);_0x39cc52[_0xb384('0x1f')](0x0);logger['debug'](_0xb384('0x83'),_0x39cc52[_0xb384('0x85')]());return dbH[_0xb384('0x84')][_0xb384('0x3a')](_0x39cc52[_0xb384('0x85')](),{'type':dbH[_0xb384('0x84')][_0xb384('0x86')]['SELECT']});}})['then'](function(){return{'sql':_0x1ababb[_0xb384('0x85')]()};})[_0xb384('0x27')](respondWithResult(_0x42e0e3,null))[_0xb384('0x4c')](handleError(_0x42e0e3,null));};
\ No newline at end of file
+var _0xf3f8=['fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/environment','../../config/license/util','../../mysqldb','dbH','end','json','offset','undefined','limit','count','status','set','Content-Range','apply','reject','save','destroy','then','get','CustomReports','error','stack','name','render','body','message','agent','interaction','account','index','map','AnalyticCustomReport','rawAttributes','type','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','catch','show','params','include','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','Reports','find','autoAssociation','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','join','right_join','cross_join','COUNT(%s)','MAX(%s)','GROUP_CONCAT(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','SEC_TO_TIME(%s)','DATE(%s)','HOUR(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','rules','operator','group','field','condition','value','Sequelize','ValidationErrorItem','AnalyticMetric','keyBy','select','from','table','MetricId','metric','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','left_join','SUM(%s)','COUNT(DISTINCT\x20%s)','AVG(%s)','ROUND(%s)','getFields','Please\x20insert\x20at\x20least\x20one\x20field','web','%s-%s.%s','randomstring','generate','output','csv','custom','AnalyticExtractedReport','cdr','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','Run\x20Query:','child_process','fork','../../components/export/','../../files/reports','savename','countTable','run','runReport','MIN(%s)','IS\x20NOT\x20EMPTY','rimraf','zip-dir'];(function(_0xd421d7,_0x59635e){var _0x4a8eb4=function(_0x74aa1a){while(--_0x74aa1a){_0xd421d7['push'](_0xd421d7['shift']());}};_0x4a8eb4(++_0x59635e);}(_0xf3f8,0xa7));var _0x8f3f=function(_0x5f31fe,_0x465734){_0x5f31fe=_0x5f31fe-0x0;var _0x14eb19=_0xf3f8[_0x5f31fe];return _0x14eb19;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x8f3f('0x0'));var zipdir=require(_0x8f3f('0x1'));var jsonpatch=require(_0x8f3f('0x2'));var rp=require(_0x8f3f('0x3'));var moment=require(_0x8f3f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x8f3f('0x5'));var util=require(_0x8f3f('0x6'));var path=require('path');var sox=require(_0x8f3f('0x7'));var csv=require(_0x8f3f('0x8'));var ejs=require(_0x8f3f('0x9'));var fs=require('fs');var fs_extra=require(_0x8f3f('0xa'));var _=require(_0x8f3f('0xb'));var squel=require(_0x8f3f('0xc'));var crypto=require('crypto');var jsforce=require(_0x8f3f('0xd'));var deskjs=require(_0x8f3f('0xe'));var toCsv=require('to-csv');var querystring=require(_0x8f3f('0xf'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x8f3f('0x10'));var as=require(_0x8f3f('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x8f3f('0x12'));var licenseUtil=require(_0x8f3f('0x13'));var db=require(_0x8f3f('0x14'))['db'];var dbH=require('../../mysqldb')[_0x8f3f('0x15')];function respondWithStatusCode(_0x1b203b,_0x3c3d1a){_0x3c3d1a=_0x3c3d1a||0xcc;return function(_0x42dfb7){if(_0x42dfb7){return _0x1b203b['sendStatus'](_0x3c3d1a);}return _0x1b203b['status'](_0x3c3d1a)[_0x8f3f('0x16')]();};}function respondWithResult(_0x56980d,_0x33d77d){_0x33d77d=_0x33d77d||0xc8;return function(_0x1bac66){if(_0x1bac66){return _0x56980d['status'](_0x33d77d)[_0x8f3f('0x17')](_0x1bac66);}};}function respondWithFilteredResult(_0x1fddda,_0x2c5623){return function(_0x50d0eb){if(_0x50d0eb){var _0x24cbb3=typeof _0x2c5623[_0x8f3f('0x18')]===_0x8f3f('0x19')&&typeof _0x2c5623[_0x8f3f('0x1a')]===_0x8f3f('0x19');var _0xf34423=_0x50d0eb[_0x8f3f('0x1b')];var _0x5c6aee=_0x24cbb3?0x0:_0x2c5623[_0x8f3f('0x18')];var _0x45d8ff=_0x24cbb3?_0x50d0eb[_0x8f3f('0x1b')]:_0x2c5623[_0x8f3f('0x18')]+_0x2c5623['limit'];var _0x4af487;if(_0x45d8ff>=_0xf34423){_0x45d8ff=_0xf34423;_0x4af487=0xc8;}else{_0x4af487=0xce;}_0x1fddda[_0x8f3f('0x1c')](_0x4af487);return _0x1fddda[_0x8f3f('0x1d')](_0x8f3f('0x1e'),_0x5c6aee+'-'+_0x45d8ff+'/'+_0xf34423)[_0x8f3f('0x17')](_0x50d0eb);}return null;};}function patchUpdates(_0x54a7ef){return function(_0xbcb522){try{jsonpatch[_0x8f3f('0x1f')](_0xbcb522,_0x54a7ef,!![]);}catch(_0x55502f){return BPromise[_0x8f3f('0x20')](_0x55502f);}return _0xbcb522[_0x8f3f('0x21')]();};}function saveUpdates(_0x5aafa2,_0x1e674f){return function(_0x5efb98){if(_0x5efb98){return _0x5efb98['update'](_0x5aafa2)['then'](function(_0x2c00c2){return _0x2c00c2;});}return null;};}function removeEntity(_0x3e1e17,_0xc05329){return function(_0x5d65f6){if(_0x5d65f6){return _0x5d65f6[_0x8f3f('0x22')]()[_0x8f3f('0x23')](function(){var _0x4fc460=_0x5d65f6[_0x8f3f('0x24')]({'plain':!![]});var _0x314471=_0x8f3f('0x25');return db['UserProfileResource']['destroy']({'where':{'type':_0x314471,'resourceId':_0x4fc460['id']}})[_0x8f3f('0x23')](function(){return _0x5d65f6;});})[_0x8f3f('0x23')](function(){_0x3e1e17[_0x8f3f('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x50567a,_0x21b3a1){return function(_0x2a51e3){if(!_0x2a51e3){_0x50567a['sendStatus'](0x194);}return _0x2a51e3;};}function handleError(_0x29912f,_0x5275d4){_0x5275d4=_0x5275d4||0x1f4;return function(_0x86f093){logger[_0x8f3f('0x26')](_0x86f093[_0x8f3f('0x27')]);if(_0x86f093[_0x8f3f('0x28')]){delete _0x86f093[_0x8f3f('0x28')];}_0x29912f[_0x8f3f('0x1c')](_0x5275d4)['send'](_0x86f093);};}function getMustacheRender(_0x31f19a,_0x3d0a3f){return Mustache[_0x8f3f('0x29')](_0x31f19a,_['merge'](_0x3d0a3f[_0x8f3f('0x2a')],{'contact':_0x3d0a3f['contact'],'message':_0x3d0a3f[_0x8f3f('0x2b')],'agent':_0x3d0a3f[_0x8f3f('0x2c')],'interaction':_0x3d0a3f[_0x8f3f('0x2d')],'account':_0x3d0a3f[_0x8f3f('0x2e')]}))||'';}exports[_0x8f3f('0x2f')]=function(_0x221ac9,_0xfe6596){var _0x373f5f={},_0x282749={},_0xb4e472={'count':0x0,'rows':[]};var _0x5e03e9=_[_0x8f3f('0x30')](db[_0x8f3f('0x31')][_0x8f3f('0x32')],function(_0x4b8208){return{'name':_0x4b8208['fieldName'],'type':_0x4b8208[_0x8f3f('0x33')]['key']};});_0x282749[_0x8f3f('0x34')]=_[_0x8f3f('0x30')](_0x5e03e9,_0x8f3f('0x28'));_0x282749[_0x8f3f('0x35')]=_[_0x8f3f('0x36')](_0x221ac9[_0x8f3f('0x35')]);_0x282749['filters']=_[_0x8f3f('0x37')](_0x282749[_0x8f3f('0x34')],_0x282749[_0x8f3f('0x35')]);_0x373f5f[_0x8f3f('0x38')]=_[_0x8f3f('0x37')](_0x282749[_0x8f3f('0x34')],qs[_0x8f3f('0x39')](_0x221ac9['query'][_0x8f3f('0x39')]));_0x373f5f[_0x8f3f('0x38')]=_0x373f5f[_0x8f3f('0x38')][_0x8f3f('0x3a')]?_0x373f5f[_0x8f3f('0x38')]:_0x282749['model'];if(!_0x221ac9[_0x8f3f('0x35')][_0x8f3f('0x3b')](_0x8f3f('0x3c'))){_0x373f5f[_0x8f3f('0x1a')]=qs['limit'](_0x221ac9[_0x8f3f('0x35')][_0x8f3f('0x1a')]);_0x373f5f[_0x8f3f('0x18')]=qs[_0x8f3f('0x18')](_0x221ac9[_0x8f3f('0x35')]['offset']);}_0x373f5f[_0x8f3f('0x3d')]=qs['sort'](_0x221ac9[_0x8f3f('0x35')][_0x8f3f('0x3e')]);_0x373f5f[_0x8f3f('0x3f')]=qs[_0x8f3f('0x40')](_[_0x8f3f('0x41')](_0x221ac9[_0x8f3f('0x35')],_0x282749[_0x8f3f('0x40')]),_0x5e03e9);if(_0x221ac9[_0x8f3f('0x35')][_0x8f3f('0x42')]){_0x373f5f['where']=_[_0x8f3f('0x43')](_0x373f5f[_0x8f3f('0x3f')],{'$or':_[_0x8f3f('0x30')](_0x5e03e9,function(_0x2c5e26){if(_0x2c5e26[_0x8f3f('0x33')]!==_0x8f3f('0x44')){var _0x54d01e={};_0x54d01e[_0x2c5e26[_0x8f3f('0x28')]]={'$like':'%'+_0x221ac9[_0x8f3f('0x35')][_0x8f3f('0x42')]+'%'};return _0x54d01e;}})});}_0x373f5f=_['merge']({},_0x373f5f,_0x221ac9[_0x8f3f('0x45')]);var _0x195551={'where':_0x373f5f[_0x8f3f('0x3f')]};return db[_0x8f3f('0x31')][_0x8f3f('0x1b')](_0x195551)[_0x8f3f('0x23')](function(_0x47217c){_0xb4e472[_0x8f3f('0x1b')]=_0x47217c;if(_0x221ac9[_0x8f3f('0x35')][_0x8f3f('0x46')]){_0x373f5f['include']=[{'all':!![]}];}return db['AnalyticCustomReport'][_0x8f3f('0x47')](_0x373f5f);})[_0x8f3f('0x23')](function(_0x20490b){_0xb4e472[_0x8f3f('0x48')]=_0x20490b;return _0xb4e472;})['then'](respondWithFilteredResult(_0xfe6596,_0x373f5f))[_0x8f3f('0x49')](handleError(_0xfe6596,null));};exports[_0x8f3f('0x4a')]=function(_0x21a371,_0x3f9ebb){var _0x2e7dc3={'raw':![],'where':{'id':_0x21a371[_0x8f3f('0x4b')]['id']}},_0x5d1630={};_0x5d1630[_0x8f3f('0x34')]=_[_0x8f3f('0x36')](db[_0x8f3f('0x31')][_0x8f3f('0x32')]);_0x5d1630[_0x8f3f('0x35')]=_['keys'](_0x21a371[_0x8f3f('0x35')]);_0x5d1630[_0x8f3f('0x40')]=_[_0x8f3f('0x37')](_0x5d1630[_0x8f3f('0x34')],_0x5d1630['query']);_0x2e7dc3[_0x8f3f('0x38')]=_['intersection'](_0x5d1630[_0x8f3f('0x34')],qs[_0x8f3f('0x39')](_0x21a371[_0x8f3f('0x35')][_0x8f3f('0x39')]));_0x2e7dc3[_0x8f3f('0x38')]=_0x2e7dc3[_0x8f3f('0x38')][_0x8f3f('0x3a')]?_0x2e7dc3[_0x8f3f('0x38')]:_0x5d1630[_0x8f3f('0x34')];if(_0x21a371[_0x8f3f('0x35')]['includeAll']){_0x2e7dc3[_0x8f3f('0x4c')]=[{'all':!![]}];}_0x2e7dc3=_[_0x8f3f('0x43')]({},_0x2e7dc3,_0x21a371[_0x8f3f('0x45')]);return db[_0x8f3f('0x31')]['find'](_0x2e7dc3)[_0x8f3f('0x23')](handleEntityNotFound(_0x3f9ebb,null))[_0x8f3f('0x23')](respondWithResult(_0x3f9ebb,null))[_0x8f3f('0x49')](handleError(_0x3f9ebb,null));};exports[_0x8f3f('0x4d')]=function(_0x449236,_0x3925c1){return db[_0x8f3f('0x31')][_0x8f3f('0x4d')](_0x449236[_0x8f3f('0x2a')],{})[_0x8f3f('0x23')](function(_0x23a729){var _0x2f0b9c=_0x449236[_0x8f3f('0x4e')]['get']({'plain':!![]});if(!_0x2f0b9c)throw new Error(_0x8f3f('0x4f'));if(_0x2f0b9c[_0x8f3f('0x50')]===_0x8f3f('0x4e')){var _0x22140c=_0x23a729['get']({'plain':!![]});var _0x58268c=_0x8f3f('0x51');return db['UserProfileSection'][_0x8f3f('0x52')]({'where':{'name':_0x58268c,'userProfileId':_0x2f0b9c['userProfileId']},'raw':!![]})[_0x8f3f('0x23')](function(_0x135a6e){if(_0x135a6e&&_0x135a6e[_0x8f3f('0x53')]===0x0){return db[_0x8f3f('0x54')][_0x8f3f('0x4d')]({'name':_0x22140c[_0x8f3f('0x28')],'resourceId':_0x22140c['id'],'type':_0x8f3f('0x25'),'sectionId':_0x135a6e['id']},{})[_0x8f3f('0x23')](function(){return _0x23a729;});}else{return _0x23a729;}})[_0x8f3f('0x49')](function(_0x527155){logger[_0x8f3f('0x26')](_0x8f3f('0x55'),_0x527155);throw _0x527155;});}return _0x23a729;})[_0x8f3f('0x23')](respondWithResult(_0x3925c1,0xc9))[_0x8f3f('0x49')](handleError(_0x3925c1,null));};exports[_0x8f3f('0x56')]=function(_0x5b9805,_0x11c263){if(_0x5b9805[_0x8f3f('0x2a')]['id']){delete _0x5b9805[_0x8f3f('0x2a')]['id'];}return db[_0x8f3f('0x31')][_0x8f3f('0x52')]({'where':{'id':_0x5b9805['params']['id']}})['then'](handleEntityNotFound(_0x11c263,null))['then'](saveUpdates(_0x5b9805[_0x8f3f('0x2a')],null))[_0x8f3f('0x23')](respondWithResult(_0x11c263,null))['catch'](handleError(_0x11c263,null));};exports[_0x8f3f('0x22')]=function(_0x334b65,_0x3448d7){return db[_0x8f3f('0x31')]['find']({'where':{'id':_0x334b65[_0x8f3f('0x4b')]['id']}})[_0x8f3f('0x23')](handleEntityNotFound(_0x3448d7,null))[_0x8f3f('0x23')](removeEntity(_0x3448d7,null))[_0x8f3f('0x49')](handleError(_0x3448d7,null));};exports['preview']=function(_0x19d9e4,_0x40fa3c){var _0x872f25=0xa;var _0x308d92=[_0x8f3f('0x57'),'left_join',_0x8f3f('0x58'),_0x8f3f('0x59')];var _0x3613de={'SUM':'SUM(%s)','COUNT':_0x8f3f('0x5a'),'COUNT DISTINCT':'COUNT(DISTINCT\x20%s)','MAX':_0x8f3f('0x5b'),'MIN':'MIN(%s)','AVG':'AVG(%s)','GROUP_CONCAT':_0x8f3f('0x5c'),'GROUP_CONCAT ASC':_0x8f3f('0x5d'),'GROUP_CONCAT DESC':_0x8f3f('0x5e')};var _0x15d350={'SEC_TO_TIME':_0x8f3f('0x5f'),'DATE':_0x8f3f('0x60'),'HOUR':_0x8f3f('0x61'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x8f3f('0x62')};var _0x2cafac=function(_0x19d623){return!_[_0x8f3f('0x63')]([_0x8f3f('0x64'),_0x8f3f('0x65'),_0x8f3f('0x66'),'IS\x20NOT\x20EMPTY'],_0x19d623);};var _0x2e771a=function(_0x38bb07){if(!_0x38bb07||!_0x38bb07[_0x8f3f('0x67')][_0x8f3f('0x3a')]){return'';}for(var _0x9a5e10='(',_0x8becc1=0x0;_0x8becc1<_0x38bb07[_0x8f3f('0x67')][_0x8f3f('0x3a')];_0x8becc1+=0x1){_0x8becc1>0x0&&(_0x9a5e10+='\x20'+_0x38bb07[_0x8f3f('0x68')]+'\x20');_0x9a5e10+=_0x38bb07[_0x8f3f('0x67')][_0x8becc1]['group']?_0x2e771a(_0x38bb07['rules'][_0x8becc1][_0x8f3f('0x69')]):_0x38bb07['rules'][_0x8becc1][_0x8f3f('0x6a')]+'\x20'+_0x38bb07[_0x8f3f('0x67')][_0x8becc1][_0x8f3f('0x6b')]+(_0x2cafac(_0x38bb07[_0x8f3f('0x67')][_0x8becc1][_0x8f3f('0x6b')])?'\x20'+_0x38bb07[_0x8f3f('0x67')][_0x8becc1][_0x8f3f('0x6c')]:'');}return _0x9a5e10+')';};var _0x1c207d={'where':{'id':_0x19d9e4[_0x8f3f('0x4b')]['id']}},_0x531a3b,_0x3fb9f4,_0xd34bae,_0x171c84,_0x29db6b;_0x1c207d=_[_0x8f3f('0x43')]({},_0x1c207d,_0x19d9e4[_0x8f3f('0x45')]);return db[_0x8f3f('0x31')][_0x8f3f('0x52')](_0x1c207d)[_0x8f3f('0x23')](function(_0x1a3c1c){if(_0x1a3c1c){_0x531a3b=_0x1a3c1c;return _0x1a3c1c['getFields']();}return null;})[_0x8f3f('0x23')](function(_0x118277){if(_0x118277){if(!_0x118277[_0x8f3f('0x3a')]){throw new db[(_0x8f3f('0x6d'))][(_0x8f3f('0x6e'))]('Please\x20insert\x20at\x20least\x20one\x20field',0x193);}_0x3fb9f4=_0x118277;return db[_0x8f3f('0x6f')][_0x8f3f('0x47')]({'raw':!![]});}return null;})[_0x8f3f('0x23')](function(_0x282afb){if(_0x282afb){_0xd34bae=_[_0x8f3f('0x70')](_0x282afb,'id');var _0x4e9fae;var _0x68d56a=squel[_0x8f3f('0x71')]();_0x68d56a[_0x8f3f('0x72')](_0x531a3b[_0x8f3f('0x73')]);for(var _0x1caece=0x0;_0x1caece<_0x3fb9f4[_0x8f3f('0x3a')];_0x1caece+=0x1){_0x4e9fae=_0x3fb9f4[_0x1caece][_0x8f3f('0x74')]?_0xd34bae[_0x3fb9f4[_0x1caece][_0x8f3f('0x74')]][_0x8f3f('0x75')]:_0x3fb9f4[_0x1caece][_0x8f3f('0x6a')];_0x4e9fae=_0x3fb9f4[_0x1caece][_0x8f3f('0x76')]?_[_0x8f3f('0x77')](_0x3613de[_0x3fb9f4[_0x1caece][_0x8f3f('0x76')]],'%s',_0x4e9fae):_0x4e9fae;_0x4e9fae=_0x3fb9f4[_0x1caece][_0x8f3f('0x78')]?_[_0x8f3f('0x77')](_0x15d350[_0x3fb9f4[_0x1caece]['format']],'%s',_0x4e9fae):_0x4e9fae;if(_0x3fb9f4[_0x1caece][_0x8f3f('0x79')]){_0x68d56a['group'](_0x4e9fae);}_0x3fb9f4[_0x1caece][_0x8f3f('0x7a')]&&_0x68d56a[_0x8f3f('0x3d')](_0x4e9fae,_0x3fb9f4[_0x1caece]['orderBy']===_0x8f3f('0x7b')?![]:!![]);_0x68d56a[_0x8f3f('0x6a')](_0x4e9fae,_0x3fb9f4[_0x1caece][_0x8f3f('0x7c')]||_0x4e9fae);}if(_0x531a3b['joins']){_0x531a3b[_0x8f3f('0x7d')]=JSON['parse'](_0x531a3b['joins']);for(var _0x472abf=0x0;_0x472abf<_0x531a3b['joins'][_0x8f3f('0x3a')];_0x472abf+=0x1){if(_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x33')]&&_['includes'](_0x308d92,_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x33')])&&_0x531a3b['joins'][_0x472abf]['parentKey']&&_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x7e')]&&_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x7f')]){_0x68d56a[_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x33')]](_0x531a3b['joins'][_0x472abf][_0x8f3f('0x7e')],null,util[_0x8f3f('0x78')](_0x8f3f('0x80'),_0x531a3b[_0x8f3f('0x73')],_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x81')],_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x7e')],_0x531a3b[_0x8f3f('0x7d')][_0x472abf][_0x8f3f('0x7f')]));}}}if(_0x531a3b[_0x8f3f('0x82')]){_0x531a3b[_0x8f3f('0x82')]=JSON[_0x8f3f('0x83')](_0x531a3b['conditions']);_0x68d56a['where'](_0x2e771a(_0x531a3b[_0x8f3f('0x82')][_0x8f3f('0x69')]));}_0x29db6b=_0x68d56a[_0x8f3f('0x84')]();_0x68d56a[_0x8f3f('0x1a')](_0x872f25);_0x68d56a[_0x8f3f('0x18')](0x0);logger[_0x8f3f('0x85')](_0x8f3f('0x86'),_0x68d56a[_0x8f3f('0x87')]());return dbH[_0x8f3f('0x88')]['query'](_0x68d56a[_0x8f3f('0x87')](),{'type':dbH[_0x8f3f('0x88')][_0x8f3f('0x89')][_0x8f3f('0x8a')]});}})[_0x8f3f('0x23')](respondWithResult(_0x40fa3c,null))[_0x8f3f('0x49')](handleError(_0x40fa3c,null));};function runReport(_0x1e46e4,_0x5e5cc2,_0x4df1a8){var _0x3548b4=_0x5e5cc2[_0x8f3f('0x28')];var _0x1bc146=0xa;var _0x527496=['join',_0x8f3f('0x8b'),'right_join',_0x8f3f('0x59')];var _0x5b3240={'SUM':_0x8f3f('0x8c'),'COUNT':_0x8f3f('0x5a'),'COUNT DISTINCT':_0x8f3f('0x8d'),'MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':_0x8f3f('0x8e'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x8f3f('0x5d'),'GROUP_CONCAT DESC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)'};var _0x374b70={'SEC_TO_TIME':_0x8f3f('0x5f'),'DATE':'DATE(%s)','HOUR':_0x8f3f('0x61'),'ROUND':_0x8f3f('0x8f'),'UNIX_TIMESTAMP':_0x8f3f('0x62')};var _0x698af=function(_0x56fac6){return!_[_0x8f3f('0x63')](['IS\x20NULL',_0x8f3f('0x65'),_0x8f3f('0x66'),'IS\x20NOT\x20EMPTY'],_0x56fac6);};var _0x212985=function(_0x16fb24){if(!_0x16fb24||!_0x16fb24['rules'][_0x8f3f('0x3a')]){return'';}for(var _0x4a3f2b='(',_0x16fb7b=0x0;_0x16fb7b<_0x16fb24[_0x8f3f('0x67')][_0x8f3f('0x3a')];_0x16fb7b+=0x1){_0x16fb7b>0x0&&(_0x4a3f2b+='\x20'+_0x16fb24[_0x8f3f('0x68')]+'\x20');_0x4a3f2b+=_0x16fb24['rules'][_0x16fb7b][_0x8f3f('0x69')]?_0x212985(_0x16fb24[_0x8f3f('0x67')][_0x16fb7b]['group']):_0x16fb24['rules'][_0x16fb7b][_0x8f3f('0x6a')]+'\x20'+_0x16fb24[_0x8f3f('0x67')][_0x16fb7b][_0x8f3f('0x6b')]+(_0x698af(_0x16fb24['rules'][_0x16fb7b]['condition'])?'\x20'+_0x16fb24['rules'][_0x16fb7b][_0x8f3f('0x6c')]:'');}return _0x4a3f2b+')';};var _0xd659df={'where':{'id':_0x1e46e4['id']}},_0xabf2a,_0x2a1d44,_0x281355,_0x2c5726,_0x27dbd1;_0xd659df=_['merge']({},_0xd659df,_0x4df1a8);return db['AnalyticCustomReport'][_0x8f3f('0x52')](_0xd659df)[_0x8f3f('0x23')](function(_0x2c8f37){if(_0x2c8f37){_0xabf2a=_0x2c8f37;return _0x2c8f37[_0x8f3f('0x90')]();}return null;})[_0x8f3f('0x23')](function(_0x55ce6d){if(_0x55ce6d){if(!_0x55ce6d['length']){throw new db['Sequelize'][(_0x8f3f('0x6e'))](_0x8f3f('0x91'),0x193);}_0x2a1d44=_0x55ce6d;return db['AnalyticMetric'][_0x8f3f('0x47')]({'raw':!![]});}return null;})[_0x8f3f('0x23')](function(_0x24ec0c){if(_0x24ec0c){_0x281355=_[_0x8f3f('0x70')](_0x24ec0c,'id');var _0x4955c2;var _0x1d8f9f=squel[_0x8f3f('0x71')]();_0x1d8f9f[_0x8f3f('0x72')](_0xabf2a[_0x8f3f('0x73')]);for(var _0x358107=0x0;_0x358107<_0x2a1d44['length'];_0x358107+=0x1){_0x4955c2=_0x2a1d44[_0x358107][_0x8f3f('0x74')]?_0x281355[_0x2a1d44[_0x358107][_0x8f3f('0x74')]][_0x8f3f('0x75')]:_0x2a1d44[_0x358107][_0x8f3f('0x6a')];_0x4955c2=_0x2a1d44[_0x358107][_0x8f3f('0x76')]?_[_0x8f3f('0x77')](_0x5b3240[_0x2a1d44[_0x358107][_0x8f3f('0x76')]],'%s',_0x4955c2):_0x4955c2;_0x4955c2=_0x2a1d44[_0x358107][_0x8f3f('0x78')]?_['replace'](_0x374b70[_0x2a1d44[_0x358107][_0x8f3f('0x78')]],'%s',_0x4955c2):_0x4955c2;if(_0x2a1d44[_0x358107][_0x8f3f('0x79')]){_0x1d8f9f[_0x8f3f('0x69')](_0x4955c2);}_0x2a1d44[_0x358107][_0x8f3f('0x7a')]&&_0x1d8f9f[_0x8f3f('0x3d')](_0x4955c2,_0x2a1d44[_0x358107][_0x8f3f('0x7a')]==='DESC'?![]:!![]);_0x1d8f9f[_0x8f3f('0x6a')](_0x4955c2,_0x2a1d44[_0x358107][_0x8f3f('0x7c')]||_0x4955c2);}if(_0xabf2a['joins']){_0xabf2a[_0x8f3f('0x7d')]=JSON[_0x8f3f('0x83')](_0xabf2a['joins']);for(var _0x2e7377=0x0;_0x2e7377<_0xabf2a[_0x8f3f('0x7d')][_0x8f3f('0x3a')];_0x2e7377+=0x1){if(_0xabf2a[_0x8f3f('0x7d')][_0x2e7377][_0x8f3f('0x33')]&&_[_0x8f3f('0x63')](_0x527496,_0xabf2a[_0x8f3f('0x7d')][_0x2e7377][_0x8f3f('0x33')])&&_0xabf2a[_0x8f3f('0x7d')][_0x2e7377]['parentKey']&&_0xabf2a[_0x8f3f('0x7d')][_0x2e7377][_0x8f3f('0x7e')]&&_0xabf2a['joins'][_0x2e7377][_0x8f3f('0x7f')]){_0x1d8f9f[_0xabf2a['joins'][_0x2e7377][_0x8f3f('0x33')]](_0xabf2a[_0x8f3f('0x7d')][_0x2e7377][_0x8f3f('0x7e')],null,util['format'](_0x8f3f('0x80'),_0xabf2a[_0x8f3f('0x73')],_0xabf2a[_0x8f3f('0x7d')][_0x2e7377][_0x8f3f('0x81')],_0xabf2a[_0x8f3f('0x7d')][_0x2e7377][_0x8f3f('0x7e')],_0xabf2a[_0x8f3f('0x7d')][_0x2e7377][_0x8f3f('0x7f')]));}}}if(_0xabf2a[_0x8f3f('0x82')]){_0xabf2a[_0x8f3f('0x82')]=JSON['parse'](_0xabf2a['conditions']);_0x1d8f9f[_0x8f3f('0x3f')](_0x212985(_0xabf2a['conditions'][_0x8f3f('0x69')]));}_0x27dbd1=_0x1d8f9f[_0x8f3f('0x84')]();_0x1d8f9f[_0x8f3f('0x1a')](_0x1bc146);_0x1d8f9f[_0x8f3f('0x18')](0x0);return;}})[_0x8f3f('0x23')](function(){if(_0x5e5cc2['output']===_0x8f3f('0x92')){return null;}var _0x38dd29=_[_0x8f3f('0x43')](_0x5e5cc2,{'name':_0x5e5cc2['fullPath']||_0x5e5cc2['name']||_0xabf2a['name'],'basename':_0x3548b4,'savename':util['format'](_0x8f3f('0x93'),_0x5e5cc2[_0x8f3f('0x28')]||_0xabf2a[_0x8f3f('0x28')],require(_0x8f3f('0x94'))[_0x8f3f('0x95')](0x4),_0x5e5cc2[_0x8f3f('0x96')]||_0x8f3f('0x97')),'reportId':_0xabf2a['id'],'reportType':_0x8f3f('0x98')});return db[_0x8f3f('0x99')][_0x8f3f('0x4d')](_0x38dd29,{'raw':!![]});})[_0x8f3f('0x23')](function(_0x231258){if(_0xabf2a['table']===_0x8f3f('0x9a')){_0x27dbd1[_0x8f3f('0x3f')](_0xabf2a['table']+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x5e5cc2[_0x8f3f('0x9b')],_0x5e5cc2[_0x8f3f('0x9c')]);}else{_0x27dbd1[_0x8f3f('0x3f')](_0xabf2a[_0x8f3f('0x73')]+_0x8f3f('0x9d'),_0x5e5cc2['startDate'],_0x5e5cc2[_0x8f3f('0x9c')]);}if(_0x231258){logger['info'](_0x8f3f('0x9e'),_0x27dbd1[_0x8f3f('0x87')]());require(_0x8f3f('0x9f'))[_0x8f3f('0xa0')](path['join'](__dirname,_0x8f3f('0xa1'),_0x231258[_0x8f3f('0x96')]),[_0x231258['id'],_0x27dbd1[_0x8f3f('0x87')](),path[_0x8f3f('0x57')](__dirname,_0x8f3f('0xa2'),_0x231258[_0x8f3f('0xa3')]),_0x3548b4]);return _0x231258;}else{var _0x3e6a34=squel[_0x8f3f('0x71')]();_0x3e6a34['from']('('+_0x27dbd1['toString']()+')',_0x8f3f('0xa4'));_0x3e6a34[_0x8f3f('0x6a')]('COUNT(*)',_0x8f3f('0x1b'));_0x27dbd1['limit'](_0x5e5cc2[_0x8f3f('0x1a')]||_0x1bc146);_0x27dbd1[_0x8f3f('0x18')](_0x5e5cc2[_0x8f3f('0x18')]||0x0);return dbH['sequelize']['query'](_0x3e6a34['toString'](),{'type':dbH[_0x8f3f('0x88')]['QueryTypes']['SELECT']})[_0x8f3f('0x23')](function(_0x5d8b31){if(!_0x5d8b31[_0x8f3f('0x3a')]){_0x2c5726=0x0;}else{_0x2c5726=_0x5d8b31[0x0][_0x8f3f('0x1b')]||0x0;}return dbH[_0x8f3f('0x88')]['query'](_0x27dbd1[_0x8f3f('0x87')](),{'type':dbH[_0x8f3f('0x88')][_0x8f3f('0x89')][_0x8f3f('0x8a')]});})[_0x8f3f('0x23')](function(_0xba61ca){return{'rows':_0xba61ca||[],'count':_0x2c5726};});}});}exports[_0x8f3f('0xa5')]=function(_0x262f1f,_0x1bad88){return runReport(_0x262f1f['params'],_0x262f1f[_0x8f3f('0x35')],_0x262f1f[_0x8f3f('0x45')])['then'](respondWithResult(_0x1bad88,null))[_0x8f3f('0x49')](handleError(_0x1bad88,null));};exports[_0x8f3f('0xa6')]=runReport;exports[_0x8f3f('0x35')]=function(_0x167b3a,_0x6caf09){var _0x2d01f3=0xa;var _0x290e8c=[_0x8f3f('0x57'),_0x8f3f('0x8b'),'right_join',_0x8f3f('0x59')];var _0x52f383={'SUM':_0x8f3f('0x8c'),'COUNT':'COUNT(%s)','COUNT DISTINCT':_0x8f3f('0x8d'),'MAX':_0x8f3f('0x5b'),'MIN':_0x8f3f('0xa7'),'AVG':_0x8f3f('0x8e'),'GROUP_CONCAT':_0x8f3f('0x5c'),'GROUP_CONCAT ASC':_0x8f3f('0x5d'),'GROUP_CONCAT DESC':_0x8f3f('0x5e')};var _0xc7d1c6={'SEC_TO_TIME':_0x8f3f('0x5f'),'DATE':'DATE(%s)','HOUR':_0x8f3f('0x61'),'ROUND':_0x8f3f('0x8f'),'UNIX_TIMESTAMP':_0x8f3f('0x62')};var _0x25d6fb=function(_0x2a1855){return!_['includes']([_0x8f3f('0x64'),_0x8f3f('0x65'),'IS\x20EMPTY',_0x8f3f('0xa8')],_0x2a1855);};var _0xf5f1dd=function(_0x2de002){if(!_0x2de002||!_0x2de002[_0x8f3f('0x67')][_0x8f3f('0x3a')]){return'';}for(var _0x508726='(',_0x453e04=0x0;_0x453e04<_0x2de002[_0x8f3f('0x67')][_0x8f3f('0x3a')];_0x453e04+=0x1){_0x453e04>0x0&&(_0x508726+='\x20'+_0x2de002[_0x8f3f('0x68')]+'\x20');_0x508726+=_0x2de002[_0x8f3f('0x67')][_0x453e04][_0x8f3f('0x69')]?_0xf5f1dd(_0x2de002[_0x8f3f('0x67')][_0x453e04][_0x8f3f('0x69')]):_0x2de002[_0x8f3f('0x67')][_0x453e04]['field']+'\x20'+_0x2de002[_0x8f3f('0x67')][_0x453e04][_0x8f3f('0x6b')]+(_0x25d6fb(_0x2de002['rules'][_0x453e04][_0x8f3f('0x6b')])?'\x20'+_0x2de002['rules'][_0x453e04][_0x8f3f('0x6c')]:'');}return _0x508726+')';};var _0x717d8d={'where':{'id':_0x167b3a[_0x8f3f('0x4b')]['id']}},_0x355e9c,_0xbdc752,_0x30c509,_0x19261b,_0x3e9ed9;_0x717d8d=_['merge']({},_0x717d8d,_0x167b3a[_0x8f3f('0x45')]);return db[_0x8f3f('0x31')]['find'](_0x717d8d)[_0x8f3f('0x23')](function(_0x5383cf){if(_0x5383cf){_0x355e9c=_0x5383cf;return _0x5383cf[_0x8f3f('0x90')]();}return null;})[_0x8f3f('0x23')](function(_0x18d34f){if(_0x18d34f){if(!_0x18d34f[_0x8f3f('0x3a')]){throw new db['Sequelize'][(_0x8f3f('0x6e'))](_0x8f3f('0x91'),0x193);}_0xbdc752=_0x18d34f;return db['AnalyticMetric'][_0x8f3f('0x47')]({'raw':!![]});}return null;})['then'](function(_0x131809){if(_0x131809){_0x30c509=_[_0x8f3f('0x70')](_0x131809,'id');var _0x11ed35;var _0x2ac1da=squel[_0x8f3f('0x71')]();_0x2ac1da[_0x8f3f('0x72')](_0x355e9c['table']);for(var _0x396c24=0x0;_0x396c24<_0xbdc752[_0x8f3f('0x3a')];_0x396c24+=0x1){_0x11ed35=_0xbdc752[_0x396c24][_0x8f3f('0x74')]?_0x30c509[_0xbdc752[_0x396c24][_0x8f3f('0x74')]][_0x8f3f('0x75')]:_0xbdc752[_0x396c24][_0x8f3f('0x6a')];_0x11ed35=_0xbdc752[_0x396c24]['function']?_[_0x8f3f('0x77')](_0x52f383[_0xbdc752[_0x396c24][_0x8f3f('0x76')]],'%s',_0x11ed35):_0x11ed35;_0x11ed35=_0xbdc752[_0x396c24]['format']?_[_0x8f3f('0x77')](_0xc7d1c6[_0xbdc752[_0x396c24][_0x8f3f('0x78')]],'%s',_0x11ed35):_0x11ed35;if(_0xbdc752[_0x396c24][_0x8f3f('0x79')]){_0x2ac1da['group'](_0x11ed35);}_0xbdc752[_0x396c24][_0x8f3f('0x7a')]&&_0x2ac1da['order'](_0x11ed35,_0xbdc752[_0x396c24][_0x8f3f('0x7a')]===_0x8f3f('0x7b')?![]:!![]);_0x2ac1da[_0x8f3f('0x6a')](_0x11ed35,_0xbdc752[_0x396c24][_0x8f3f('0x7c')]||_0x11ed35);}if(_0x355e9c[_0x8f3f('0x7d')]){_0x355e9c[_0x8f3f('0x7d')]=JSON[_0x8f3f('0x83')](_0x355e9c[_0x8f3f('0x7d')]);for(var _0xc4e0f=0x0;_0xc4e0f<_0x355e9c['joins'][_0x8f3f('0x3a')];_0xc4e0f+=0x1){if(_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x33')]&&_['includes'](_0x290e8c,_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x33')])&&_0x355e9c['joins'][_0xc4e0f][_0x8f3f('0x81')]&&_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x7e')]&&_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x7f')]){_0x2ac1da[_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x33')]](_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x7e')],null,util[_0x8f3f('0x78')]('%s.%s\x20=\x20%s.%s',_0x355e9c['table'],_0x355e9c['joins'][_0xc4e0f]['parentKey'],_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x7e')],_0x355e9c[_0x8f3f('0x7d')][_0xc4e0f][_0x8f3f('0x7f')]));}}}if(_0x355e9c[_0x8f3f('0x82')]){_0x355e9c[_0x8f3f('0x82')]=JSON[_0x8f3f('0x83')](_0x355e9c[_0x8f3f('0x82')]);_0x2ac1da['where'](_0xf5f1dd(_0x355e9c[_0x8f3f('0x82')][_0x8f3f('0x69')]));}_0x3e9ed9=_0x2ac1da[_0x8f3f('0x84')]();_0x2ac1da['limit'](_0x2d01f3);_0x2ac1da[_0x8f3f('0x18')](0x0);logger[_0x8f3f('0x85')]('Limited\x20Query:',_0x2ac1da['toString']());return dbH[_0x8f3f('0x88')][_0x8f3f('0x35')](_0x2ac1da['toString'](),{'type':dbH[_0x8f3f('0x88')]['QueryTypes'][_0x8f3f('0x8a')]});}})[_0x8f3f('0x23')](function(){return{'sql':_0x3e9ed9[_0x8f3f('0x87')]()};})[_0x8f3f('0x23')](respondWithResult(_0x6caf09,null))[_0x8f3f('0x49')](handleError(_0x6caf09,null));};
\ No newline at end of file