Built motion from commit e1760111.|2.6.18
[motion2.git] / server / api / analyticCustomReport / analyticCustomReport.controller.js
index b545fea..ef108d1 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-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
+var _0xf7e1=['format','groupBy','orderBy','joins','parse','foreignTable','foreignKey','parentKey','conditions','clone','debug','toString','sequelize','SELECT','right_join','GROUP_CONCAT(%s)','SEC_TO_TIME(%s)','from','DESC','output','web','fullPath','%s-%s.%s','csv','custom','AnalyticExtractedReport','cdr','startDate','endDate','.createdAt\x20BETWEEN\x20?\x20AND\x20?','info','Run\x20Query:','child_process','fork','../../files/reports','countTable','COUNT(*)','QueryTypes','run','runReport','cross_join','%s.%s\x20=\x20%s.%s','eml-format','rimraf','zip-dir','fast-json-patch','bluebird','util','path','sox','ejs','squel','crypto','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/license/util','../../mysqldb','dbH','sendStatus','status','end','json','limit','undefined','count','offset','set','Content-Range','reject','save','then','destroy','UserProfileResource','name','send','map','AnalyticCustomReport','rawAttributes','fieldName','type','key','keys','filters','attributes','intersection','model','fields','length','query','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','params','find','create','body','get','role','user','Reports','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','preview','join','left_join','SUM(%s)','COUNT(%s)','COUNT(DISTINCT\x20%s)','MAX(%s)','MIN(%s)','AVG(%s)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20DESC)','DATE(%s)','HOUR(%s)','ROUND(%s)','UNIX_TIMESTAMP(%s)','includes','IS\x20NULL','IS\x20NOT\x20NULL','IS\x20EMPTY','IS\x20NOT\x20EMPTY','rules','operator','group','condition','value','getFields','Sequelize','ValidationErrorItem','Please\x20insert\x20at\x20least\x20one\x20field','AnalyticMetric','keyBy','select','table','MetricId','metric','field','replace','function'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xf7e1,0x170));var _0x1f7e=function(_0x31ced5,_0x5d5415){_0x31ced5=_0x31ced5-0x0;var _0x10d9e5=_0xf7e1[_0x31ced5];return _0x10d9e5;};'use strict';var emlformat=require(_0x1f7e('0x0'));var rimraf=require(_0x1f7e('0x1'));var zipdir=require(_0x1f7e('0x2'));var jsonpatch=require(_0x1f7e('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x1f7e('0x4'));var Mustache=require('mustache');var util=require(_0x1f7e('0x5'));var path=require(_0x1f7e('0x6'));var sox=require(_0x1f7e('0x7'));var csv=require('to-csv');var ejs=require(_0x1f7e('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x1f7e('0x9'));var crypto=require(_0x1f7e('0xa'));var jsforce=require(_0x1f7e('0xb'));var deskjs=require(_0x1f7e('0xc'));var toCsv=require(_0x1f7e('0xd'));var querystring=require(_0x1f7e('0xe'));var Papa=require('papaparse');var Redis=require(_0x1f7e('0xf'));var authService=require(_0x1f7e('0x10'));var qs=require(_0x1f7e('0x11'));var as=require(_0x1f7e('0x12'));var hardwareService=require(_0x1f7e('0x13'));var logger=require(_0x1f7e('0x14'))(_0x1f7e('0x15'));var utils=require(_0x1f7e('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0x1f7e('0x17'));var db=require(_0x1f7e('0x18'))['db'];var dbH=require(_0x1f7e('0x18'))[_0x1f7e('0x19')];function respondWithStatusCode(_0x447d64,_0xe7bed1){_0xe7bed1=_0xe7bed1||0xcc;return function(_0x25510c){if(_0x25510c){return _0x447d64[_0x1f7e('0x1a')](_0xe7bed1);}return _0x447d64[_0x1f7e('0x1b')](_0xe7bed1)[_0x1f7e('0x1c')]();};}function respondWithResult(_0x1eee34,_0x536761){_0x536761=_0x536761||0xc8;return function(_0x55493c){if(_0x55493c){return _0x1eee34['status'](_0x536761)[_0x1f7e('0x1d')](_0x55493c);}};}function respondWithFilteredResult(_0x1425bb,_0x3ca63a){return function(_0x1b2c0a){if(_0x1b2c0a){var _0x45ed5f=typeof _0x3ca63a['offset']==='undefined'&&typeof _0x3ca63a[_0x1f7e('0x1e')]===_0x1f7e('0x1f');var _0x268e7d=_0x1b2c0a[_0x1f7e('0x20')];var _0x264b2e=_0x45ed5f?0x0:_0x3ca63a[_0x1f7e('0x21')];var _0x466b35=_0x45ed5f?_0x1b2c0a[_0x1f7e('0x20')]:_0x3ca63a[_0x1f7e('0x21')]+_0x3ca63a[_0x1f7e('0x1e')];var _0x43cb41;if(_0x466b35>=_0x268e7d){_0x466b35=_0x268e7d;_0x43cb41=0xc8;}else{_0x43cb41=0xce;}_0x1425bb[_0x1f7e('0x1b')](_0x43cb41);return _0x1425bb[_0x1f7e('0x22')](_0x1f7e('0x23'),_0x264b2e+'-'+_0x466b35+'/'+_0x268e7d)[_0x1f7e('0x1d')](_0x1b2c0a);}return null;};}function patchUpdates(_0x2b1bac){return function(_0x1d341b){try{jsonpatch['apply'](_0x1d341b,_0x2b1bac,!![]);}catch(_0x4fe2b0){return BPromise[_0x1f7e('0x24')](_0x4fe2b0);}return _0x1d341b[_0x1f7e('0x25')]();};}function saveUpdates(_0x1fe475,_0x13fd01){return function(_0x81f52e){if(_0x81f52e){return _0x81f52e['update'](_0x1fe475)[_0x1f7e('0x26')](function(_0x55b875){return _0x55b875;});}return null;};}function removeEntity(_0x38a0d4,_0x179d01){return function(_0x175dc9){if(_0x175dc9){return _0x175dc9[_0x1f7e('0x27')]()[_0x1f7e('0x26')](function(){var _0x25c398=_0x175dc9['get']({'plain':!![]});var _0x29b7ca='CustomReports';return db[_0x1f7e('0x28')][_0x1f7e('0x27')]({'where':{'type':_0x29b7ca,'resourceId':_0x25c398['id']}})['then'](function(){return _0x175dc9;});})[_0x1f7e('0x26')](function(){_0x38a0d4[_0x1f7e('0x1b')](0xcc)[_0x1f7e('0x1c')]();});}};}function handleEntityNotFound(_0x1219f0,_0x3eaecf){return function(_0x543152){if(!_0x543152){_0x1219f0[_0x1f7e('0x1a')](0x194);}return _0x543152;};}function handleError(_0x5a8d22,_0x37ef72){_0x37ef72=_0x37ef72||0x1f4;return function(_0x57d55a){logger['error'](_0x57d55a['stack']);if(_0x57d55a[_0x1f7e('0x29')]){delete _0x57d55a[_0x1f7e('0x29')];}_0x5a8d22[_0x1f7e('0x1b')](_0x37ef72)[_0x1f7e('0x2a')](_0x57d55a);};}exports['index']=function(_0x4ef977,_0x310b08){var _0x2c2e41={},_0x40c33e={},_0x2bd5f0={'count':0x0,'rows':[]};var _0x273a4e=_[_0x1f7e('0x2b')](db[_0x1f7e('0x2c')][_0x1f7e('0x2d')],function(_0x4a8858){return{'name':_0x4a8858[_0x1f7e('0x2e')],'type':_0x4a8858[_0x1f7e('0x2f')][_0x1f7e('0x30')]};});_0x40c33e['model']=_[_0x1f7e('0x2b')](_0x273a4e,_0x1f7e('0x29'));_0x40c33e['query']=_[_0x1f7e('0x31')](_0x4ef977['query']);_0x40c33e[_0x1f7e('0x32')]=_['intersection'](_0x40c33e['model'],_0x40c33e['query']);_0x2c2e41[_0x1f7e('0x33')]=_[_0x1f7e('0x34')](_0x40c33e[_0x1f7e('0x35')],qs['fields'](_0x4ef977['query'][_0x1f7e('0x36')]));_0x2c2e41[_0x1f7e('0x33')]=_0x2c2e41['attributes'][_0x1f7e('0x37')]?_0x2c2e41['attributes']:_0x40c33e['model'];if(!_0x4ef977[_0x1f7e('0x38')][_0x1f7e('0x39')](_0x1f7e('0x3a'))){_0x2c2e41[_0x1f7e('0x1e')]=qs[_0x1f7e('0x1e')](_0x4ef977[_0x1f7e('0x38')]['limit']);_0x2c2e41[_0x1f7e('0x21')]=qs[_0x1f7e('0x21')](_0x4ef977[_0x1f7e('0x38')]['offset']);}_0x2c2e41[_0x1f7e('0x3b')]=qs[_0x1f7e('0x3c')](_0x4ef977[_0x1f7e('0x38')]['sort']);_0x2c2e41['where']=qs[_0x1f7e('0x32')](_[_0x1f7e('0x3d')](_0x4ef977['query'],_0x40c33e['filters']),_0x273a4e);if(_0x4ef977[_0x1f7e('0x38')][_0x1f7e('0x3e')]){_0x2c2e41[_0x1f7e('0x3f')]=_[_0x1f7e('0x40')](_0x2c2e41['where'],{'$or':_[_0x1f7e('0x2b')](_0x273a4e,function(_0x231937){if(_0x231937['type']!==_0x1f7e('0x41')){var _0xeb4b67={};_0xeb4b67[_0x231937[_0x1f7e('0x29')]]={'$like':'%'+_0x4ef977[_0x1f7e('0x38')][_0x1f7e('0x3e')]+'%'};return _0xeb4b67;}})});}_0x2c2e41=_[_0x1f7e('0x40')]({},_0x2c2e41,_0x4ef977[_0x1f7e('0x42')]);var _0x3f7428={'where':_0x2c2e41[_0x1f7e('0x3f')]};return db[_0x1f7e('0x2c')][_0x1f7e('0x20')](_0x3f7428)[_0x1f7e('0x26')](function(_0x3130eb){_0x2bd5f0[_0x1f7e('0x20')]=_0x3130eb;if(_0x4ef977[_0x1f7e('0x38')][_0x1f7e('0x43')]){_0x2c2e41[_0x1f7e('0x44')]=[{'all':!![]}];}return db[_0x1f7e('0x2c')][_0x1f7e('0x45')](_0x2c2e41);})[_0x1f7e('0x26')](function(_0x4f571e){_0x2bd5f0[_0x1f7e('0x46')]=_0x4f571e;return _0x2bd5f0;})[_0x1f7e('0x26')](respondWithFilteredResult(_0x310b08,_0x2c2e41))[_0x1f7e('0x47')](handleError(_0x310b08,null));};exports['show']=function(_0x59aa64,_0x28b0dd){var _0x38bbbb={'raw':![],'where':{'id':_0x59aa64[_0x1f7e('0x48')]['id']}},_0x10e163={};_0x10e163[_0x1f7e('0x35')]=_['keys'](db[_0x1f7e('0x2c')][_0x1f7e('0x2d')]);_0x10e163[_0x1f7e('0x38')]=_[_0x1f7e('0x31')](_0x59aa64['query']);_0x10e163[_0x1f7e('0x32')]=_[_0x1f7e('0x34')](_0x10e163[_0x1f7e('0x35')],_0x10e163[_0x1f7e('0x38')]);_0x38bbbb[_0x1f7e('0x33')]=_[_0x1f7e('0x34')](_0x10e163[_0x1f7e('0x35')],qs[_0x1f7e('0x36')](_0x59aa64[_0x1f7e('0x38')][_0x1f7e('0x36')]));_0x38bbbb['attributes']=_0x38bbbb['attributes'][_0x1f7e('0x37')]?_0x38bbbb[_0x1f7e('0x33')]:_0x10e163[_0x1f7e('0x35')];if(_0x59aa64[_0x1f7e('0x38')][_0x1f7e('0x43')]){_0x38bbbb[_0x1f7e('0x44')]=[{'all':!![]}];}_0x38bbbb=_[_0x1f7e('0x40')]({},_0x38bbbb,_0x59aa64[_0x1f7e('0x42')]);return db[_0x1f7e('0x2c')][_0x1f7e('0x49')](_0x38bbbb)[_0x1f7e('0x26')](handleEntityNotFound(_0x28b0dd,null))['then'](respondWithResult(_0x28b0dd,null))['catch'](handleError(_0x28b0dd,null));};exports['create']=function(_0x443454,_0x524c78){return db[_0x1f7e('0x2c')][_0x1f7e('0x4a')](_0x443454[_0x1f7e('0x4b')],{})['then'](function(_0x213776){var _0xf12cb6=_0x443454['user'][_0x1f7e('0x4c')]({'plain':!![]});if(!_0xf12cb6)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0xf12cb6[_0x1f7e('0x4d')]===_0x1f7e('0x4e')){var _0x52955e=_0x213776['get']({'plain':!![]});var _0x234c19=_0x1f7e('0x4f');return db['UserProfileSection'][_0x1f7e('0x49')]({'where':{'name':_0x234c19,'userProfileId':_0xf12cb6[_0x1f7e('0x50')]},'raw':!![]})[_0x1f7e('0x26')](function(_0x3c953e){if(_0x3c953e&&_0x3c953e['autoAssociation']===0x0){return db[_0x1f7e('0x28')][_0x1f7e('0x4a')]({'name':_0x52955e['name'],'resourceId':_0x52955e['id'],'type':'CustomReports','sectionId':_0x3c953e['id']},{})[_0x1f7e('0x26')](function(){return _0x213776;});}else{return _0x213776;}})[_0x1f7e('0x47')](function(_0x4bda50){logger['error'](_0x1f7e('0x51'),_0x4bda50);throw _0x4bda50;});}return _0x213776;})[_0x1f7e('0x26')](respondWithResult(_0x524c78,0xc9))[_0x1f7e('0x47')](handleError(_0x524c78,null));};exports[_0x1f7e('0x52')]=function(_0x427a4f,_0x17d528){if(_0x427a4f[_0x1f7e('0x4b')]['id']){delete _0x427a4f[_0x1f7e('0x4b')]['id'];}return db[_0x1f7e('0x2c')][_0x1f7e('0x49')]({'where':{'id':_0x427a4f['params']['id']}})['then'](handleEntityNotFound(_0x17d528,null))[_0x1f7e('0x26')](saveUpdates(_0x427a4f['body'],null))['then'](respondWithResult(_0x17d528,null))[_0x1f7e('0x47')](handleError(_0x17d528,null));};exports['destroy']=function(_0x28d124,_0x5176df){return db[_0x1f7e('0x2c')][_0x1f7e('0x49')]({'where':{'id':_0x28d124['params']['id']}})['then'](handleEntityNotFound(_0x5176df,null))['then'](removeEntity(_0x5176df,null))['catch'](handleError(_0x5176df,null));};exports[_0x1f7e('0x53')]=function(_0x5dcdda,_0x3ad11c){var _0x103513=0xa;var _0x141669=[_0x1f7e('0x54'),_0x1f7e('0x55'),'right_join','cross_join'];var _0xad2c04={'SUM':_0x1f7e('0x56'),'COUNT':_0x1f7e('0x57'),'COUNT DISTINCT':_0x1f7e('0x58'),'MAX':_0x1f7e('0x59'),'MIN':_0x1f7e('0x5a'),'AVG':_0x1f7e('0x5b'),'GROUP_CONCAT':'GROUP_CONCAT(%s)','GROUP_CONCAT ASC':_0x1f7e('0x5c'),'GROUP_CONCAT DESC':_0x1f7e('0x5d')};var _0x266178={'SEC_TO_TIME':'SEC_TO_TIME(%s)','DATE':_0x1f7e('0x5e'),'HOUR':_0x1f7e('0x5f'),'ROUND':_0x1f7e('0x60'),'UNIX_TIMESTAMP':_0x1f7e('0x61')};var _0x56d58b=function(_0x2228e6){return!_[_0x1f7e('0x62')]([_0x1f7e('0x63'),_0x1f7e('0x64'),_0x1f7e('0x65'),_0x1f7e('0x66')],_0x2228e6);};var _0x333eb6=function(_0x323eef){if(!_0x323eef||!_0x323eef[_0x1f7e('0x67')][_0x1f7e('0x37')]){return'';}for(var _0x484c52='(',_0x2e3ec3=0x0;_0x2e3ec3<_0x323eef[_0x1f7e('0x67')][_0x1f7e('0x37')];_0x2e3ec3+=0x1){_0x2e3ec3>0x0&&(_0x484c52+='\x20'+_0x323eef[_0x1f7e('0x68')]+'\x20');_0x484c52+=_0x323eef[_0x1f7e('0x67')][_0x2e3ec3][_0x1f7e('0x69')]?_0x333eb6(_0x323eef[_0x1f7e('0x67')][_0x2e3ec3][_0x1f7e('0x69')]):_0x323eef[_0x1f7e('0x67')][_0x2e3ec3]['field']+'\x20'+_0x323eef['rules'][_0x2e3ec3][_0x1f7e('0x6a')]+(_0x56d58b(_0x323eef['rules'][_0x2e3ec3][_0x1f7e('0x6a')])?'\x20'+_0x323eef[_0x1f7e('0x67')][_0x2e3ec3][_0x1f7e('0x6b')]:'');}return _0x484c52+')';};var _0x47e6db={'where':{'id':_0x5dcdda[_0x1f7e('0x48')]['id']}},_0x2cb213,_0xa2756,_0x7a0c58,_0x1db4bd,_0x3a1637;_0x47e6db=_[_0x1f7e('0x40')]({},_0x47e6db,_0x5dcdda[_0x1f7e('0x42')]);return db[_0x1f7e('0x2c')][_0x1f7e('0x49')](_0x47e6db)[_0x1f7e('0x26')](function(_0x21ab7f){if(_0x21ab7f){_0x2cb213=_0x21ab7f;return _0x21ab7f[_0x1f7e('0x6c')]();}return null;})[_0x1f7e('0x26')](function(_0x5c9632){if(_0x5c9632){if(!_0x5c9632[_0x1f7e('0x37')]){throw new db[(_0x1f7e('0x6d'))][(_0x1f7e('0x6e'))](_0x1f7e('0x6f'),0x193);}_0xa2756=_0x5c9632;return db[_0x1f7e('0x70')][_0x1f7e('0x45')]({'raw':!![]});}return null;})[_0x1f7e('0x26')](function(_0x10fdd8){if(_0x10fdd8){_0x7a0c58=_[_0x1f7e('0x71')](_0x10fdd8,'id');var _0x49dbd3;var _0x108436=squel[_0x1f7e('0x72')]();_0x108436['from'](_0x2cb213[_0x1f7e('0x73')]);for(var _0x2f8515=0x0;_0x2f8515<_0xa2756[_0x1f7e('0x37')];_0x2f8515+=0x1){_0x49dbd3=_0xa2756[_0x2f8515][_0x1f7e('0x74')]?_0x7a0c58[_0xa2756[_0x2f8515][_0x1f7e('0x74')]][_0x1f7e('0x75')]:_0xa2756[_0x2f8515][_0x1f7e('0x76')];_0x49dbd3=_0xa2756[_0x2f8515]['function']?_[_0x1f7e('0x77')](_0xad2c04[_0xa2756[_0x2f8515][_0x1f7e('0x78')]],'%s',_0x49dbd3):_0x49dbd3;_0x49dbd3=_0xa2756[_0x2f8515][_0x1f7e('0x79')]?_['replace'](_0x266178[_0xa2756[_0x2f8515][_0x1f7e('0x79')]],'%s',_0x49dbd3):_0x49dbd3;if(_0xa2756[_0x2f8515][_0x1f7e('0x7a')]){_0x108436['group'](_0x49dbd3);}_0xa2756[_0x2f8515][_0x1f7e('0x7b')]&&_0x108436[_0x1f7e('0x3b')](_0x49dbd3,_0xa2756[_0x2f8515][_0x1f7e('0x7b')]==='DESC'?![]:!![]);_0x108436['field'](_0x49dbd3,_0xa2756[_0x2f8515]['alias']||_0x49dbd3);}if(_0x2cb213['joins']){_0x2cb213[_0x1f7e('0x7c')]=JSON[_0x1f7e('0x7d')](_0x2cb213[_0x1f7e('0x7c')]);for(var _0x59f384=0x0;_0x59f384<_0x2cb213[_0x1f7e('0x7c')][_0x1f7e('0x37')];_0x59f384+=0x1){if(_0x2cb213['joins'][_0x59f384][_0x1f7e('0x2f')]&&_[_0x1f7e('0x62')](_0x141669,_0x2cb213[_0x1f7e('0x7c')][_0x59f384][_0x1f7e('0x2f')])&&_0x2cb213[_0x1f7e('0x7c')][_0x59f384]['parentKey']&&_0x2cb213[_0x1f7e('0x7c')][_0x59f384][_0x1f7e('0x7e')]&&_0x2cb213['joins'][_0x59f384][_0x1f7e('0x7f')]){_0x108436[_0x2cb213[_0x1f7e('0x7c')][_0x59f384][_0x1f7e('0x2f')]](_0x2cb213[_0x1f7e('0x7c')][_0x59f384]['foreignTable'],null,util['format']('%s.%s\x20=\x20%s.%s',_0x2cb213[_0x1f7e('0x73')],_0x2cb213[_0x1f7e('0x7c')][_0x59f384][_0x1f7e('0x80')],_0x2cb213[_0x1f7e('0x7c')][_0x59f384][_0x1f7e('0x7e')],_0x2cb213[_0x1f7e('0x7c')][_0x59f384][_0x1f7e('0x7f')]));}}}if(_0x2cb213['conditions']){_0x2cb213[_0x1f7e('0x81')]=JSON['parse'](_0x2cb213['conditions']);_0x108436[_0x1f7e('0x3f')](_0x333eb6(_0x2cb213[_0x1f7e('0x81')]['group']));}_0x3a1637=_0x108436[_0x1f7e('0x82')]();_0x108436['limit'](_0x103513);_0x108436[_0x1f7e('0x21')](0x0);logger[_0x1f7e('0x83')]('Limited\x20Query:',_0x108436[_0x1f7e('0x84')]());return dbH[_0x1f7e('0x85')][_0x1f7e('0x38')](_0x108436[_0x1f7e('0x84')](),{'type':dbH['sequelize']['QueryTypes'][_0x1f7e('0x86')]});}})[_0x1f7e('0x26')](respondWithResult(_0x3ad11c,null))[_0x1f7e('0x47')](handleError(_0x3ad11c,null));};function runReport(_0x37287a,_0x31274a,_0x3f65cc){var _0x2ec868=_0x31274a[_0x1f7e('0x29')];var _0x698b91=0xa;var _0x81b1e8=[_0x1f7e('0x54'),_0x1f7e('0x55'),_0x1f7e('0x87'),'cross_join'];var _0x245eb9={'SUM':_0x1f7e('0x56'),'COUNT':_0x1f7e('0x57'),'COUNT DISTINCT':_0x1f7e('0x58'),'MAX':'MAX(%s)','MIN':'MIN(%s)','AVG':_0x1f7e('0x5b'),'GROUP_CONCAT':_0x1f7e('0x88'),'GROUP_CONCAT ASC':_0x1f7e('0x5c'),'GROUP_CONCAT DESC':_0x1f7e('0x5d')};var _0x4299e4={'SEC_TO_TIME':_0x1f7e('0x89'),'DATE':'DATE(%s)','HOUR':_0x1f7e('0x5f'),'ROUND':'ROUND(%s)','UNIX_TIMESTAMP':_0x1f7e('0x61')};var _0x4cafbf=function(_0x6d1ad3){return!_[_0x1f7e('0x62')](['IS\x20NULL','IS\x20NOT\x20NULL',_0x1f7e('0x65'),'IS\x20NOT\x20EMPTY'],_0x6d1ad3);};var _0x83c5be=function(_0x118695){if(!_0x118695||!_0x118695[_0x1f7e('0x67')]['length']){return'';}for(var _0x40bd4e='(',_0x4fb672=0x0;_0x4fb672<_0x118695['rules']['length'];_0x4fb672+=0x1){_0x4fb672>0x0&&(_0x40bd4e+='\x20'+_0x118695[_0x1f7e('0x68')]+'\x20');_0x40bd4e+=_0x118695['rules'][_0x4fb672][_0x1f7e('0x69')]?_0x83c5be(_0x118695[_0x1f7e('0x67')][_0x4fb672]['group']):_0x118695[_0x1f7e('0x67')][_0x4fb672][_0x1f7e('0x76')]+'\x20'+_0x118695[_0x1f7e('0x67')][_0x4fb672]['condition']+(_0x4cafbf(_0x118695[_0x1f7e('0x67')][_0x4fb672][_0x1f7e('0x6a')])?'\x20'+_0x118695[_0x1f7e('0x67')][_0x4fb672][_0x1f7e('0x6b')]:'');}return _0x40bd4e+')';};var _0x551bb7={'where':{'id':_0x37287a['id']}},_0x3efbb6,_0x3c338d,_0x366f57,_0x4377aa,_0x5aaadf;_0x551bb7=_[_0x1f7e('0x40')]({},_0x551bb7,_0x3f65cc);return db[_0x1f7e('0x2c')][_0x1f7e('0x49')](_0x551bb7)[_0x1f7e('0x26')](function(_0x56d22e){if(_0x56d22e){_0x3efbb6=_0x56d22e;return _0x56d22e['getFields']();}return null;})[_0x1f7e('0x26')](function(_0x361da3){if(_0x361da3){if(!_0x361da3[_0x1f7e('0x37')]){throw new db[(_0x1f7e('0x6d'))][(_0x1f7e('0x6e'))](_0x1f7e('0x6f'),0x193);}_0x3c338d=_0x361da3;return db[_0x1f7e('0x70')][_0x1f7e('0x45')]({'raw':!![]});}return null;})[_0x1f7e('0x26')](function(_0x47edd2){if(_0x47edd2){_0x366f57=_['keyBy'](_0x47edd2,'id');var _0x407d99;var _0x353a9c=squel[_0x1f7e('0x72')]();_0x353a9c[_0x1f7e('0x8a')](_0x3efbb6[_0x1f7e('0x73')]);for(var _0x29423d=0x0;_0x29423d<_0x3c338d[_0x1f7e('0x37')];_0x29423d+=0x1){_0x407d99=_0x3c338d[_0x29423d][_0x1f7e('0x74')]?_0x366f57[_0x3c338d[_0x29423d]['MetricId']][_0x1f7e('0x75')]:_0x3c338d[_0x29423d][_0x1f7e('0x76')];_0x407d99=_0x3c338d[_0x29423d][_0x1f7e('0x78')]?_[_0x1f7e('0x77')](_0x245eb9[_0x3c338d[_0x29423d][_0x1f7e('0x78')]],'%s',_0x407d99):_0x407d99;_0x407d99=_0x3c338d[_0x29423d][_0x1f7e('0x79')]?_['replace'](_0x4299e4[_0x3c338d[_0x29423d][_0x1f7e('0x79')]],'%s',_0x407d99):_0x407d99;if(_0x3c338d[_0x29423d][_0x1f7e('0x7a')]){_0x353a9c[_0x1f7e('0x69')](_0x407d99);}_0x3c338d[_0x29423d][_0x1f7e('0x7b')]&&_0x353a9c['order'](_0x407d99,_0x3c338d[_0x29423d][_0x1f7e('0x7b')]===_0x1f7e('0x8b')?![]:!![]);_0x353a9c[_0x1f7e('0x76')](_0x407d99,_0x3c338d[_0x29423d]['alias']||_0x407d99);}if(_0x3efbb6['joins']){_0x3efbb6[_0x1f7e('0x7c')]=JSON[_0x1f7e('0x7d')](_0x3efbb6['joins']);for(var _0x31c9b8=0x0;_0x31c9b8<_0x3efbb6[_0x1f7e('0x7c')][_0x1f7e('0x37')];_0x31c9b8+=0x1){if(_0x3efbb6[_0x1f7e('0x7c')][_0x31c9b8][_0x1f7e('0x2f')]&&_[_0x1f7e('0x62')](_0x81b1e8,_0x3efbb6[_0x1f7e('0x7c')][_0x31c9b8][_0x1f7e('0x2f')])&&_0x3efbb6[_0x1f7e('0x7c')][_0x31c9b8]['parentKey']&&_0x3efbb6[_0x1f7e('0x7c')][_0x31c9b8][_0x1f7e('0x7e')]&&_0x3efbb6['joins'][_0x31c9b8][_0x1f7e('0x7f')]){_0x353a9c[_0x3efbb6[_0x1f7e('0x7c')][_0x31c9b8][_0x1f7e('0x2f')]](_0x3efbb6[_0x1f7e('0x7c')][_0x31c9b8][_0x1f7e('0x7e')],null,util[_0x1f7e('0x79')]('%s.%s\x20=\x20%s.%s',_0x3efbb6['table'],_0x3efbb6['joins'][_0x31c9b8][_0x1f7e('0x80')],_0x3efbb6['joins'][_0x31c9b8][_0x1f7e('0x7e')],_0x3efbb6['joins'][_0x31c9b8][_0x1f7e('0x7f')]));}}}if(_0x3efbb6[_0x1f7e('0x81')]){_0x3efbb6[_0x1f7e('0x81')]=JSON[_0x1f7e('0x7d')](_0x3efbb6[_0x1f7e('0x81')]);_0x353a9c[_0x1f7e('0x3f')](_0x83c5be(_0x3efbb6['conditions']['group']));}_0x5aaadf=_0x353a9c[_0x1f7e('0x82')]();_0x353a9c[_0x1f7e('0x1e')](_0x698b91);_0x353a9c[_0x1f7e('0x21')](0x0);return;}})[_0x1f7e('0x26')](function(){if(_0x31274a[_0x1f7e('0x8c')]===_0x1f7e('0x8d')){return null;}var _0x4b6ce3=_[_0x1f7e('0x40')](_0x31274a,{'name':_0x31274a[_0x1f7e('0x8e')]||_0x31274a[_0x1f7e('0x29')]||_0x3efbb6[_0x1f7e('0x29')],'basename':_0x2ec868,'savename':util[_0x1f7e('0x79')](_0x1f7e('0x8f'),_0x31274a[_0x1f7e('0x29')]||_0x3efbb6[_0x1f7e('0x29')],require('randomstring')['generate'](0x4),_0x31274a[_0x1f7e('0x8c')]||_0x1f7e('0x90')),'reportId':_0x3efbb6['id'],'reportType':_0x1f7e('0x91')});return db[_0x1f7e('0x92')][_0x1f7e('0x4a')](_0x4b6ce3,{'raw':!![]});})['then'](function(_0x6226bd){if(_0x3efbb6['table']===_0x1f7e('0x93')){_0x5aaadf[_0x1f7e('0x3f')](_0x3efbb6['table']+'.calldate\x20BETWEEN\x20?\x20AND\x20?',_0x31274a[_0x1f7e('0x94')],_0x31274a[_0x1f7e('0x95')]);}else{_0x5aaadf[_0x1f7e('0x3f')](_0x3efbb6['table']+_0x1f7e('0x96'),_0x31274a[_0x1f7e('0x94')],_0x31274a[_0x1f7e('0x95')]);}if(_0x6226bd){logger[_0x1f7e('0x97')](_0x1f7e('0x98'),_0x5aaadf[_0x1f7e('0x84')]());require(_0x1f7e('0x99'))[_0x1f7e('0x9a')](path['join'](__dirname,'../../components/export/',_0x6226bd[_0x1f7e('0x8c')]),[_0x6226bd['id'],_0x5aaadf['toString'](),path[_0x1f7e('0x54')](__dirname,_0x1f7e('0x9b'),_0x6226bd['savename']),_0x2ec868]);return _0x6226bd;}else{var _0x37f757=squel['select']();_0x37f757[_0x1f7e('0x8a')]('('+_0x5aaadf[_0x1f7e('0x84')]()+')',_0x1f7e('0x9c'));_0x37f757['field'](_0x1f7e('0x9d'),_0x1f7e('0x20'));_0x5aaadf[_0x1f7e('0x1e')](_0x31274a['limit']||_0x698b91);_0x5aaadf[_0x1f7e('0x21')](_0x31274a[_0x1f7e('0x21')]||0x0);return dbH[_0x1f7e('0x85')]['query'](_0x37f757[_0x1f7e('0x84')](),{'type':dbH[_0x1f7e('0x85')][_0x1f7e('0x9e')]['SELECT']})[_0x1f7e('0x26')](function(_0x48503c){if(!_0x48503c['length']){_0x4377aa=0x0;}else{_0x4377aa=_0x48503c[0x0]['count']||0x0;}return dbH['sequelize'][_0x1f7e('0x38')](_0x5aaadf[_0x1f7e('0x84')](),{'type':dbH[_0x1f7e('0x85')][_0x1f7e('0x9e')][_0x1f7e('0x86')]});})['then'](function(_0x2f5fe6){return{'rows':_0x2f5fe6||[],'count':_0x4377aa};});}});}exports[_0x1f7e('0x9f')]=function(_0x289066,_0x450c9b){return runReport(_0x289066[_0x1f7e('0x48')],_0x289066[_0x1f7e('0x38')],_0x289066[_0x1f7e('0x42')])[_0x1f7e('0x26')](respondWithResult(_0x450c9b,null))[_0x1f7e('0x47')](handleError(_0x450c9b,null));};exports[_0x1f7e('0xa0')]=runReport;exports['query']=function(_0x50e18a,_0x3fe8d4){var _0x2f3173=0xa;var _0x3ea287=['join',_0x1f7e('0x55'),_0x1f7e('0x87'),_0x1f7e('0xa1')];var _0x5266ff={'SUM':'SUM(%s)','COUNT':_0x1f7e('0x57'),'COUNT DISTINCT':_0x1f7e('0x58'),'MAX':_0x1f7e('0x59'),'MIN':_0x1f7e('0x5a'),'AVG':_0x1f7e('0x5b'),'GROUP_CONCAT':_0x1f7e('0x88'),'GROUP_CONCAT ASC':'GROUP_CONCAT(%s\x20ORDER\x20BY\x20%s\x20ASC)','GROUP_CONCAT DESC':_0x1f7e('0x5d')};var _0xe2ed3c={'SEC_TO_TIME':_0x1f7e('0x89'),'DATE':_0x1f7e('0x5e'),'HOUR':_0x1f7e('0x5f'),'ROUND':_0x1f7e('0x60'),'UNIX_TIMESTAMP':_0x1f7e('0x61')};var _0x18947a=function(_0x2defa0){return!_[_0x1f7e('0x62')]([_0x1f7e('0x63'),_0x1f7e('0x64'),_0x1f7e('0x65'),'IS\x20NOT\x20EMPTY'],_0x2defa0);};var _0x470bb9=function(_0x10d3c7){if(!_0x10d3c7||!_0x10d3c7['rules']['length']){return'';}for(var _0x397c82='(',_0x81e232=0x0;_0x81e232<_0x10d3c7['rules'][_0x1f7e('0x37')];_0x81e232+=0x1){_0x81e232>0x0&&(_0x397c82+='\x20'+_0x10d3c7[_0x1f7e('0x68')]+'\x20');_0x397c82+=_0x10d3c7[_0x1f7e('0x67')][_0x81e232][_0x1f7e('0x69')]?_0x470bb9(_0x10d3c7[_0x1f7e('0x67')][_0x81e232][_0x1f7e('0x69')]):_0x10d3c7['rules'][_0x81e232][_0x1f7e('0x76')]+'\x20'+_0x10d3c7[_0x1f7e('0x67')][_0x81e232]['condition']+(_0x18947a(_0x10d3c7[_0x1f7e('0x67')][_0x81e232][_0x1f7e('0x6a')])?'\x20'+_0x10d3c7[_0x1f7e('0x67')][_0x81e232][_0x1f7e('0x6b')]:'');}return _0x397c82+')';};var _0x3660b6={'where':{'id':_0x50e18a[_0x1f7e('0x48')]['id']}},_0x2de0aa,_0x493a9d,_0x4aa420,_0x5231ae,_0x3b646c;_0x3660b6=_['merge']({},_0x3660b6,_0x50e18a['options']);return db[_0x1f7e('0x2c')]['find'](_0x3660b6)['then'](function(_0x16dd79){if(_0x16dd79){_0x2de0aa=_0x16dd79;return _0x16dd79[_0x1f7e('0x6c')]();}return null;})['then'](function(_0x1d1672){if(_0x1d1672){if(!_0x1d1672[_0x1f7e('0x37')]){throw new db[(_0x1f7e('0x6d'))][(_0x1f7e('0x6e'))](_0x1f7e('0x6f'),0x193);}_0x493a9d=_0x1d1672;return db[_0x1f7e('0x70')][_0x1f7e('0x45')]({'raw':!![]});}return null;})[_0x1f7e('0x26')](function(_0x5303c0){if(_0x5303c0){_0x4aa420=_['keyBy'](_0x5303c0,'id');var _0x21ffe7;var _0x31396a=squel[_0x1f7e('0x72')]();_0x31396a[_0x1f7e('0x8a')](_0x2de0aa['table']);for(var _0x3ea907=0x0;_0x3ea907<_0x493a9d[_0x1f7e('0x37')];_0x3ea907+=0x1){_0x21ffe7=_0x493a9d[_0x3ea907][_0x1f7e('0x74')]?_0x4aa420[_0x493a9d[_0x3ea907][_0x1f7e('0x74')]][_0x1f7e('0x75')]:_0x493a9d[_0x3ea907][_0x1f7e('0x76')];_0x21ffe7=_0x493a9d[_0x3ea907][_0x1f7e('0x78')]?_['replace'](_0x5266ff[_0x493a9d[_0x3ea907][_0x1f7e('0x78')]],'%s',_0x21ffe7):_0x21ffe7;_0x21ffe7=_0x493a9d[_0x3ea907]['format']?_['replace'](_0xe2ed3c[_0x493a9d[_0x3ea907][_0x1f7e('0x79')]],'%s',_0x21ffe7):_0x21ffe7;if(_0x493a9d[_0x3ea907][_0x1f7e('0x7a')]){_0x31396a[_0x1f7e('0x69')](_0x21ffe7);}_0x493a9d[_0x3ea907][_0x1f7e('0x7b')]&&_0x31396a[_0x1f7e('0x3b')](_0x21ffe7,_0x493a9d[_0x3ea907][_0x1f7e('0x7b')]==='DESC'?![]:!![]);_0x31396a[_0x1f7e('0x76')](_0x21ffe7,_0x493a9d[_0x3ea907]['alias']||_0x21ffe7);}if(_0x2de0aa[_0x1f7e('0x7c')]){_0x2de0aa[_0x1f7e('0x7c')]=JSON[_0x1f7e('0x7d')](_0x2de0aa[_0x1f7e('0x7c')]);for(var _0x155245=0x0;_0x155245<_0x2de0aa[_0x1f7e('0x7c')][_0x1f7e('0x37')];_0x155245+=0x1){if(_0x2de0aa[_0x1f7e('0x7c')][_0x155245][_0x1f7e('0x2f')]&&_[_0x1f7e('0x62')](_0x3ea287,_0x2de0aa[_0x1f7e('0x7c')][_0x155245][_0x1f7e('0x2f')])&&_0x2de0aa[_0x1f7e('0x7c')][_0x155245]['parentKey']&&_0x2de0aa[_0x1f7e('0x7c')][_0x155245][_0x1f7e('0x7e')]&&_0x2de0aa[_0x1f7e('0x7c')][_0x155245][_0x1f7e('0x7f')]){_0x31396a[_0x2de0aa['joins'][_0x155245][_0x1f7e('0x2f')]](_0x2de0aa[_0x1f7e('0x7c')][_0x155245][_0x1f7e('0x7e')],null,util[_0x1f7e('0x79')](_0x1f7e('0xa2'),_0x2de0aa['table'],_0x2de0aa[_0x1f7e('0x7c')][_0x155245][_0x1f7e('0x80')],_0x2de0aa[_0x1f7e('0x7c')][_0x155245][_0x1f7e('0x7e')],_0x2de0aa['joins'][_0x155245][_0x1f7e('0x7f')]));}}}if(_0x2de0aa['conditions']){_0x2de0aa[_0x1f7e('0x81')]=JSON[_0x1f7e('0x7d')](_0x2de0aa[_0x1f7e('0x81')]);_0x31396a['where'](_0x470bb9(_0x2de0aa[_0x1f7e('0x81')]['group']));}_0x3b646c=_0x31396a[_0x1f7e('0x82')]();_0x31396a[_0x1f7e('0x1e')](_0x2f3173);_0x31396a[_0x1f7e('0x21')](0x0);logger[_0x1f7e('0x83')]('Limited\x20Query:',_0x31396a['toString']());return dbH[_0x1f7e('0x85')][_0x1f7e('0x38')](_0x31396a[_0x1f7e('0x84')](),{'type':dbH['sequelize']['QueryTypes'][_0x1f7e('0x86')]});}})['then'](function(){return{'sql':_0x3b646c[_0x1f7e('0x84')]()};})[_0x1f7e('0x26')](respondWithResult(_0x3fe8d4,null))[_0x1f7e('0x47')](handleError(_0x3fe8d4,null));};
\ No newline at end of file