Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / components / interaction / sql-utils.js
index f55affb..bfcc05e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9bc9=['read','and','Contact','$substring','split','contact','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','type','Tag','tags','ids','User','operator','user','CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','body','text','compact','concat','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','resolve','then','fields','tag','clause','filter','get','capitalize','chat','Websites','Accounts','\x20IS\x20NULL','\x20IS\x20NOT\x20NULL','i.thirdDisposition','i.secondDisposition','unshift','i.substatus','closed','CONCAT_WS(\x27\x27,\x20','join','Interaction','QueryTypes','SELECT','sequelize','query','toString','attributes','a.key','Account.key','a.mandatoryDisposition','Account.mandatoryDisposition','a.email','Account.email','i.id','i.createdAt','i.closedAt','i.lastMsgAt','i.lastMsgDirection','i.disposition','i.to','i.MailAccountId','CASE\x20WHEN\x20i.from\x20IS\x20NOT\x20NULL\x20AND\x20i.from\x20<>\x20\x27\x27\x20THEN\x20i.from\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','contactName','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','Contact.email','c.phone','c.mobile','Contact.mobile','c.fax','Contact.fax','o.fullname','Owner.fullname','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','limit','offset','enableEmailPreview','all','COUNT(*)','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','getSelectedTags','isEmpty','Sequelize','exports','lodash','squel','../parsers/advancedSearch','../parsers/qs','./update-interaction','updateInteraction','./utils','../../mysqldb','getAccountFK','role','agent','search','select','name','color','from','getInteractionFK','user_has_','_interactions','u.id','field','left_join','users','u.id\x20=\x20ui.UserId','length','where','ui.','\x20IN\x20?','map','getInteractionsTables','interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','o.id\x20=\x20i.UserId','a.id\x20=\x20i.','messages','\x20=\x20i.id','interactionsTags','t.id\x20=\x20it.TagId','expr','forEach','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','{OPERATOR}','replace','i.id\x20LIKE\x20?','sms','whatsapp','includes','i.fax\x20LIKE\x20?','i.from\x20LIKE\x20?','isEmail','c.email\x20LIKE\x20?','mail','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','parseSearch','sqlOperator','conditions','find','buildExpression','default','value','start','end','unreadMessages'];(function(_0x9df060,_0x253d33){var _0x338dfe=function(_0x17d9a5){while(--_0x17d9a5){_0x9df060['push'](_0x9df060['shift']());}};_0x338dfe(++_0x253d33);}(_0x9bc9,0x108));var _0x99bc=function(_0x129fb9,_0x31992e){_0x129fb9=_0x129fb9-0x0;var _0x4c47ac=_0x9bc9[_0x129fb9];return _0x4c47ac;};'use strict';var _=require(_0x99bc('0x0'));var squel=require(_0x99bc('0x1'));var as=require(_0x99bc('0x2'));var qs=require(_0x99bc('0x3'));var updateInteraction=require(_0x99bc('0x4'))[_0x99bc('0x5')];var utils=require(_0x99bc('0x6'));var db=require(_0x99bc('0x7'))['db'];function skipInteractionsQuery(_0x4a0e20,_0x71d793,_0x282c23){var _0x40729a=![];var _0x4cd445=utils[_0x99bc('0x8')](_0x4a0e20);if(_0x71d793[_0x99bc('0x9')]===_0x99bc('0xa')&&!_0x282c23[_0x99bc('0xb')]&&!_0x282c23[_0x4cd445]){_0x40729a=!![];}return _0x40729a;}function getTagsQuery(){return squel[_0x99bc('0xc')]()['field']('id')['field'](_0x99bc('0xd'))['field'](_0x99bc('0xe'))[_0x99bc('0xf')]('tools_tags');}function getUsersQuery(_0x175a76,_0x23e9cb){var _0x26602c=utils[_0x99bc('0x10')](_0x175a76);var _0x5f49be=_0x99bc('0x11')+_0x175a76+_0x99bc('0x12');var _0x5364b0=squel[_0x99bc('0xc')]()['field'](_0x99bc('0x13'))[_0x99bc('0x14')]('u.fullname')[_0x99bc('0x14')]('ui.'+_0x26602c)[_0x99bc('0xf')](_0x5f49be,'ui')[_0x99bc('0x15')](_0x99bc('0x16'),'u',_0x99bc('0x17'));if(_0x23e9cb[_0x99bc('0x18')]>0x0){_0x5364b0[_0x99bc('0x19')](_0x99bc('0x1a')+_0x26602c+_0x99bc('0x1b'),_[_0x99bc('0x1c')](_0x23e9cb,'id'));}return _0x5364b0;}function getInteractionsQuery(_0x31e4f3){var _0x3a4a5b=utils[_0x99bc('0x1d')](_0x31e4f3);var _0x5c6c04=utils['getAccountFK'](_0x31e4f3);var _0x21c8a8=utils[_0x99bc('0x10')](_0x31e4f3);return squel['select']()[_0x99bc('0xf')](_0x3a4a5b[_0x99bc('0x1e')],'i')['left_join'](_0x99bc('0x1f'),'c',_0x99bc('0x20'))[_0x99bc('0x15')](_0x99bc('0x16'),'o',_0x99bc('0x21'))[_0x99bc('0x15')](_0x3a4a5b['accounts'],'a',_0x99bc('0x22')+_0x5c6c04)[_0x99bc('0x15')](_0x3a4a5b[_0x99bc('0x23')],'me','me.'+_0x21c8a8+_0x99bc('0x24'))[_0x99bc('0x15')](_0x3a4a5b[_0x99bc('0x25')],'it','it.'+_0x21c8a8+_0x99bc('0x24'))['left_join']('tools_tags','t',_0x99bc('0x26'));}function getSqlClauses(){var _0x3498e1={'body':squel['expr'](),'contact':squel['expr'](),'default':squel[_0x99bc('0x27')](),'fields':squel[_0x99bc('0x27')](),'filter':squel['expr'](),'read':squel[_0x99bc('0x27')](),'tags':{'clause':squel['expr'](),'ids':null},'user':squel[_0x99bc('0x27')]()};return _0x3498e1;}function parseTagParameter(_0x13c39d){var _0xdbc6eb=squel[_0x99bc('0x27')]();if(_0x13c39d){var _0x4a3beb=utils['getSelectedTags'](_0x13c39d);_0x4a3beb[_0x99bc('0x28')](function(_0x30c436){_0xdbc6eb['or'](_0x99bc('0x29'),'%,'+_0x30c436+',%');});}return _0xdbc6eb;}function parseReadParameter(_0x5c53e4){var _0x5b1771='';if(_0x5c53e4){_0x5b1771='unreadMessages\x20{OPERATOR}\x200';if(_0x5c53e4==='1'){_0x5b1771=_0x5b1771['replace'](_0x99bc('0x2a'),'=');}else{_0x5b1771=_0x5b1771[_0x99bc('0x2b')](_0x99bc('0x2a'),'>');}}return _0x5b1771;}function parseSearchFilter(_0x5b0748,_0x499dc3){var _0x175eb4=squel[_0x99bc('0x27')]();if(_0x499dc3){var _0x35b997=_0x499dc3['replace']('\x5c','\x5c\x5c')[_0x99bc('0x2b')](/'/g,'\x27\x27');if(qs['isNumeric'](_0x35b997)){_0x175eb4['or'](_0x99bc('0x2c'),_0x35b997+'%');if([_0x99bc('0x2d'),_0x99bc('0x2e')][_0x99bc('0x2f')](_0x5b0748)){_0x175eb4['or']('i.phone\x20LIKE\x20?',_0x35b997+'%');}else if(_0x5b0748==='fax'){_0x175eb4['or'](_0x99bc('0x30'),_0x35b997+'%');}else if(_0x5b0748==='openchannel'){_0x175eb4['or'](_0x99bc('0x31'),_0x35b997+'%');}}else if(_0x5b0748==='mail'&&qs[_0x99bc('0x32')](_0x35b997)){_0x175eb4['or'](_0x99bc('0x33'),_0x35b997+'%');}else{if(_0x5b0748===_0x99bc('0x34')){_0x175eb4['or'](_0x99bc('0x35'),qs['getFullTextValue'](_0x35b997,!![]))['or'](_0x99bc('0x36'),qs[_0x99bc('0x37')](_0x35b997));}else if(_0x5b0748!=='fax'){_0x175eb4['or'](_0x99bc('0x38'),qs['getFullTextValue'](_0x35b997));}_0x175eb4['or'](_0x99bc('0x39'),qs[_0x99bc('0x37')](_0x35b997,!![]),null);}}return _0x175eb4;}function parseAdvancedSearchFilter(_0x6c30e5,_0x345caf){var _0x33268e=getSqlClauses();var _0x4c4cc8=as[_0x99bc('0x3a')](_0x6c30e5);var _0x58136b=_0x4c4cc8[_0x99bc('0x3b')];for(var _0x3ca2c7=0x0;_0x3ca2c7<_0x4c4cc8[_0x99bc('0x3c')][_0x99bc('0x18')];_0x3ca2c7++){var _0x39e997=_0x4c4cc8[_0x99bc('0x3c')][_0x3ca2c7];var _0x5c261b='i';var _0x40ba60=_[_0x99bc('0x3d')](_0x345caf,[_0x99bc('0xd'),_0x39e997[_0x99bc('0x14')]]);if(_0x40ba60){var _0x1e52a8=as[_0x99bc('0x3e')](_0x5c261b,_0x40ba60['type'],_0x39e997);_0x33268e[_0x99bc('0x3f')][_0x58136b](_0x1e52a8['text'],_0x1e52a8[_0x99bc('0x40')][_0x99bc('0x41')],_0x1e52a8[_0x99bc('0x40')][_0x99bc('0x42')]);}else{switch(_0x39e997[_0x99bc('0x14')]){case _0x99bc('0x43'):var _0x11a6ac=parseReadParameter(_0x39e997[_0x99bc('0x40')]);_0x33268e[_0x99bc('0x44')][_0x99bc('0x45')](_0x11a6ac);break;case _0x99bc('0x46'):if(_0x39e997['operator']===_0x99bc('0x47')){if(_0x39e997['value'][_0x99bc('0x48')]('\x20')[_0x99bc('0x18')]>0x1){_0x33268e[_0x99bc('0x49')][_0x58136b](_0x99bc('0x39'),qs['getFullTextValue'](_0x39e997['value'],!![]),null);}else{var _0x3c3504='%'+_0x39e997[_0x99bc('0x40')]+'%';_0x33268e['contact'][_0x58136b](_0x99bc('0x4a'),_0x3c3504,_0x3c3504,_0x3c3504);}}else{_0x40ba60=_['find'](_0x345caf,[_0x99bc('0xd'),'ContactId']);_0x39e997[_0x99bc('0x14')]=_0x99bc('0x4b');_0x1e52a8=as[_0x99bc('0x3e')](_0x5c261b,_0x40ba60[_0x99bc('0x4c')],_0x39e997);_0x33268e[_0x99bc('0x49')][_0x58136b](_0x1e52a8['text'],_0x1e52a8['value'][_0x99bc('0x41')],_0x1e52a8[_0x99bc('0x40')]['end']);}break;case _0x99bc('0x4d'):var _0x244fb6=_0x39e997['value']['split'](',')[_0x99bc('0x1c')](function(_0x565070){return Number(_0x565070);});var _0x24c518=parseTagParameter(_0x244fb6);_0x33268e[_0x99bc('0x4e')]['clause']['and'](_0x24c518);_0x33268e[_0x99bc('0x4e')][_0x99bc('0x4f')]=_0x244fb6;break;case _0x99bc('0x50'):if(_0x39e997[_0x99bc('0x51')]===_0x99bc('0x47')){_0x33268e[_0x99bc('0x52')][_0x58136b](_0x99bc('0x53'),'%'+_0x39e997['value']+'%',null);}else{_0x40ba60=_[_0x99bc('0x3d')](_0x345caf,[_0x99bc('0xd'),_0x99bc('0x54')]);_0x39e997[_0x99bc('0x14')]=_0x99bc('0x54');_0x1e52a8=as[_0x99bc('0x3e')](_0x5c261b,_0x40ba60['type'],_0x39e997);_0x33268e[_0x99bc('0x52')][_0x58136b](_0x1e52a8['text'],_0x1e52a8[_0x99bc('0x40')][_0x99bc('0x41')],_0x1e52a8[_0x99bc('0x40')][_0x99bc('0x42')]);}break;case'body':case'plainBody':_0x1e52a8=as[_0x99bc('0x3e')]('me',null,_0x39e997);_0x33268e[_0x99bc('0x55')][_0x58136b](_0x1e52a8[_0x99bc('0x56')],_0x1e52a8['value'][_0x99bc('0x41')],_0x1e52a8[_0x99bc('0x40')][_0x99bc('0x42')]);break;}}}return _0x33268e;}function parseModelFields(_0x37c170,_0x34ac6d,_0x2de0ec){var _0x47cd17=utils[_0x99bc('0x8')](_0x37c170);var _0x151955=squel[_0x99bc('0x27')]();var _0x476f31=_(_0x34ac6d)['keys']()[_0x99bc('0x1c')](function(_0x48f6d9){return _['some'](_0x2de0ec,[_0x99bc('0xd'),_0x48f6d9])?_0x48f6d9:undefined;})[_0x99bc('0x57')]()[_0x99bc('0x40')]();if(_0x476f31[_0x99bc('0x18')]>0x0){_0x476f31[_0x99bc('0x28')](function(_0x1388b5){if(_0x1388b5===_0x47cd17){_0x151955[_0x99bc('0x45')]('i.'+_0x47cd17+_0x99bc('0x1b'),[][_0x99bc('0x58')](_0x34ac6d[_0x1388b5]));}else if(_0x1388b5===_0x99bc('0x59')){var _0x2ff3ef=JSON[_0x99bc('0x5a')](_0x34ac6d[_0x1388b5])[_0x99bc('0x5b')];var _0x1f9cd9=JSON['parse'](_0x34ac6d[_0x1388b5])[_0x99bc('0x5c')];_0x151955[_0x99bc('0x45')](_0x99bc('0x5d'),_0x2ff3ef,_0x1f9cd9);}else{if(_0x34ac6d[_0x1388b5]===_0x99bc('0x5e')){_0x151955['and']('i.'+_0x1388b5+'\x20IS\x20NULL');}else{_0x151955[_0x99bc('0x45')]('i.'+_0x1388b5+'\x20=\x20?',_0x34ac6d[_0x1388b5]);}}});}return _0x151955;}function parseQueryParameters(_0xc65fca,_0x18b191,_0x55d807){var _0x535eab=getSqlClauses();return Promise[_0x99bc('0x5f')]()[_0x99bc('0x60')](function(){return parseModelFields(_0xc65fca,_0x18b191,_0x55d807);})['then'](function(_0x1a2e51){_0x535eab[_0x99bc('0x61')][_0x99bc('0x45')](_0x1a2e51);return parseReadParameter(_0x18b191['read']);})[_0x99bc('0x60')](function(_0x7946df){_0x535eab['read'][_0x99bc('0x45')](_0x7946df);return parseTagParameter(_0x18b191[_0x99bc('0x62')]);})[_0x99bc('0x60')](function(_0x2ea788){_0x535eab[_0x99bc('0x4e')][_0x99bc('0x63')][_0x99bc('0x45')](_0x2ea788);return parseSearchFilter(_0xc65fca,_0x18b191['filter']);})[_0x99bc('0x60')](function(_0x5190b8){_0x535eab[_0x99bc('0x64')]=_0x5190b8;return _0x535eab;});}function checkAccountsRestrictions(_0x4db44e,_0x4b9138,_0x38aec7){var _0x58f4c2=utils[_0x99bc('0x8')](_0x4db44e);var _0x4e9fa3=_0x99bc('0x65')+_[_0x99bc('0x66')](_0x4db44e)+(_0x4db44e===_0x99bc('0x67')?_0x99bc('0x68'):_0x99bc('0x69'));var _0x1a5871=squel[_0x99bc('0x27')]();return Promise[_0x99bc('0x5f')]()[_0x99bc('0x60')](function(){if(_0x38aec7[_0x99bc('0xb')]&&_0x4b9138[_0x99bc('0x9')]==='agent'){return _0x4b9138[_0x4e9fa3]({'attributes':['id'],'raw':!![]});}})[_0x99bc('0x60')](function(_0x289c6d){if(_0x289c6d){if(_0x289c6d[_0x99bc('0x18')]===0x0){_0x1a5871[_0x99bc('0x45')]('i.'+_0x58f4c2+_0x99bc('0x6a'));}else{_0x1a5871['and']('i.'+_0x58f4c2+_0x99bc('0x1b'),_['map'](_0x289c6d,'id'));}}else if(!_0x38aec7[_0x58f4c2]){_0x1a5871[_0x99bc('0x45')]('i.'+_0x58f4c2+_0x99bc('0x6b'));}})[_0x99bc('0x60')](function(){return _0x1a5871;});}function getClosedOrderClause(_0x4261d9,_0x42803f){var _0x261b4c='';var _0x1da36a=[_0x99bc('0x6c'),_0x99bc('0x6d'),'i.disposition'];if(_0x4261d9==='mail'){_0x1da36a[_0x99bc('0x6e')](_0x99bc('0x6f'));}if(_0x42803f[_0x99bc('0x70')]==='0'&&_0x4261d9==='mail'){_0x261b4c='i.substatus';}else{if(_0x42803f['closed']==='1'){_0x1da36a['shift']();}_0x261b4c=_0x99bc('0x71')+_0x1da36a[_0x99bc('0x72')](',\x20')+')';}return _0x261b4c;}function getFilteredInteractions(_0xed8dcd,_0x12d7a7,_0x580474,_0x5b0305){var _0x5da232=utils[_0x99bc('0x10')](_0xed8dcd);var _0x23e1b6=_[_0x99bc('0x66')](_0xed8dcd)+_0x99bc('0x73');var _0x30c736=[];var _0x5d588e=getTagsQuery();var _0x376d62={'type':db['Sequelize'][_0x99bc('0x74')][_0x99bc('0x75')],'raw':!![]};var _0x14e73c=[];var _0x2923dd=[];return db[_0x99bc('0x76')][_0x99bc('0x77')](_0x5d588e[_0x99bc('0x78')](),_0x376d62)['then'](function(_0x31b9dd){_0x30c736=_['keyBy'](_0x31b9dd,'id');_0x376d62=_['merge'](_0x376d62,{'model':db[_0x23e1b6],'mapToModel':!![],'nest':!![]});if(_0x580474[_0x99bc('0x61')]){_0x5b0305[_0x99bc('0x79')]['forEach'](function(_0x5d40ae){_0x12d7a7[_0x99bc('0x14')]('i.'+_0x5d40ae);});}else{_0x12d7a7['field']('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x7a'),_0x99bc('0x7b'));_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x7c'),_0x99bc('0x7d'));if(_0xed8dcd===_0x99bc('0x34')){_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x7e'),_0x99bc('0x7f'));_0x12d7a7['field']('CASE\x20WHEN\x20i.to\x20IS\x20NOT\x20NULL\x20AND\x20i.to\x20<>\x20\x27\x27\x20AND\x20i.to\x20NOT\x20LIKE\x20CONCAT(\x27%\x27,\x20a.email,\x20\x27%\x27)\x20THEN\x20TRIM(SUBSTRING_INDEX(i.to,\x20\x27<\x27,\x201))\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','contactName');_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x80'));_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x81'));_0x12d7a7['field']('i.updatedAt');_0x12d7a7[_0x99bc('0x14')]('i.closed');_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x82'));_0x12d7a7[_0x99bc('0x14')]('i.attach');_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x83'));_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x84'));_0x12d7a7[_0x99bc('0x14')]('i.subject');_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x85'));_0x12d7a7['field'](_0x99bc('0x6d'));_0x12d7a7[_0x99bc('0x14')]('i.thirdDisposition');_0x12d7a7['field']('i.substatus');_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x86'));_0x12d7a7[_0x99bc('0x14')]('i.ContactId');_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x87'));_0x12d7a7['field']('i.UserId');}else if(_0xed8dcd==='openchannel'){_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x88'),_0x99bc('0x89'));}else{_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x8a'),_0x99bc('0x89'));}if(_0xed8dcd!==_0x99bc('0x34')){_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x8b'));}_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x8c'),_0x99bc('0x8d'));_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x8e'),_0x99bc('0x8f'));_0x12d7a7[_0x99bc('0x14')]('c.email',_0x99bc('0x90'));_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x91'),'Contact.phone');_0x12d7a7['field'](_0x99bc('0x92'),_0x99bc('0x93'));_0x12d7a7['field'](_0x99bc('0x94'),_0x99bc('0x95'));_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x96'),_0x99bc('0x97'));_0x12d7a7[_0x99bc('0x14')](_0x99bc('0x98'),_0x99bc('0x99'));_0x12d7a7['field'](_0x99bc('0x9a'),_0x99bc('0x9b'));}if(_0x5b0305[_0x99bc('0x9c')]){_0x12d7a7[_0x99bc('0x9c')](_0x5b0305[_0x99bc('0x9c')]);}if(_0x5b0305[_0x99bc('0x9d')]){_0x12d7a7[_0x99bc('0x9d')](_0x5b0305[_0x99bc('0x9d')]);}return db['sequelize']['query'](_0x12d7a7['toString'](),_0x376d62);})[_0x99bc('0x60')](function(_0x2eaf9f){_0x14e73c=_0x2eaf9f;var _0x358f04=getUsersQuery(_0xed8dcd,_0x14e73c);return db['sequelize'][_0x99bc('0x77')](_0x358f04['toString'](),_0x376d62);})[_0x99bc('0x60')](function(_0x54f8e0){_0x2923dd=_['groupBy'](_0x54f8e0,_0x5da232);if(_0xed8dcd==='mail'){return db['Setting']['findOne']({'attributes':[_0x99bc('0x9e')],'raw':!![]});}})['then'](function(_0x524947){var _0x4402aa=_0x524947?_0x524947[_0x99bc('0x9e')]:undefined;var _0x4bbcb5=_0x14e73c[_0x99bc('0x1c')](function(_0x1c0497){return updateInteraction(_0x1c0497,_0x30c736,_0x2923dd,_0x4402aa);});return Promise[_0x99bc('0x9f')](_0x4bbcb5);});}function countFilteredInteractions(_0xa469c0,_0x3855f1){var _0x26d066=_0xa469c0['clone']();_0x26d066[_0x99bc('0x14')](_0x99bc('0xa0'));_0x26d066[_0x99bc('0x14')](_0x99bc('0xa1'),_0x99bc('0x43'));var _0x283c9b=utils[_0x99bc('0xa2')](_0x3855f1);if(!_[_0x99bc('0xa3')](_0x283c9b)){_0x26d066['where']('t.id\x20IN\x20?',_0x283c9b);}var _0x61f4d1={'type':db[_0x99bc('0xa4')][_0x99bc('0x74')][_0x99bc('0x75')],'raw':!![]};return db['sequelize'][_0x99bc('0x77')](_0x26d066[_0x99bc('0x78')](),_0x61f4d1);}module[_0x99bc('0xa5')]={'checkAccountsRestrictions':checkAccountsRestrictions,'countFilteredInteractions':countFilteredInteractions,'getClosedOrderClause':getClosedOrderClause,'getFilteredInteractions':getFilteredInteractions,'getInteractionsQuery':getInteractionsQuery,'parseAdvancedSearchFilter':parseAdvancedSearchFilter,'parseQueryParameters':parseQueryParameters,'skipInteractionsQuery':skipInteractionsQuery};
\ No newline at end of file
+var _0xe3ef=['CONCAT_WS(\x27\x20\x27,\x20o.name,\x20o.fullname)\x20LIKE\x20?','UserId','user','body','plainBody','some','compact','forEach','createdAt','parse','$gte','$lte','i.createdAt\x20BETWEEN\x20?\x20AND\x20?','null','\x20=\x20?','resolve','fields','read','then','tag','filter','get','capitalize','chat','Accounts','\x20IS\x20NOT\x20NULL','i.thirdDisposition','i.secondDisposition','i.disposition','unshift','i.substatus','closed','CONCAT_WS(\x27\x27,\x20','join','Interaction','Sequelize','QueryTypes','SELECT','sequelize','query','toString','keyBy','merge','attributes','a.key','Account.key','a.mandatoryDisposition','a.email','Account.email','CASE\x20WHEN\x20i.to\x20IS\x20NOT\x20NULL\x20AND\x20i.to\x20<>\x20\x27\x27\x20AND\x20i.to\x20NOT\x20LIKE\x20CONCAT(\x27%\x27,\x20a.email,\x20\x27%\x27)\x20THEN\x20TRIM(SUBSTRING_INDEX(i.to,\x20\x27<\x27,\x201))\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','i.createdAt','i.updatedAt','i.closed','i.closedAt','i.attach','i.lastMsgAt','i.lastMsgDirection','i.subject','i.to','CASE\x20WHEN\x20i.from\x20IS\x20NOT\x20NULL\x20AND\x20i.from\x20<>\x20\x27\x27\x20THEN\x20i.from\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','CASE\x20WHEN\x20(c.firstName\x20IS\x20NOT\x20NULL\x20AND\x20c.firstName\x20<>\x20\x27\x27)\x20OR\x20(c.lastName\x20IS\x20NOT\x20NULL\x20AND\x20c.lastName\x20<>\x20\x27\x27)\x20THEN\x20CONCAT(IFNULL(c.firstName,\x20\x27\x27),\x20\x27\x20\x27,\x20IFNULL(c.lastName,\x20\x27\x27))\x20ELSE\x20\x27Unknown\x27\x20END','contactName','i.*','c.firstName','Contact.firstName','c.lastName','Contact.lastName','c.email','Contact.email','c.phone','Contact.phone','c.mobile','Contact.mobile','c.fax','o.internal','Owner.internal','GROUP_CONCAT(DISTINCT\x20t.id)','TagIds','limit','offset','groupBy','Setting','findOne','enableEmailPreview','clone','COUNT(*)','SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','t.id\x20IN\x20?','lodash','../parsers/advancedSearch','../parsers/qs','./update-interaction','updateInteraction','../../mysqldb','role','agent','search','field','name','from','getInteractionFK','user_has_','u.id','u.fullname','left_join','length','where','\x20IN\x20?','map','getInteractionsTables','getAccountFK','interactions','cm_contacts','c.id\x20=\x20i.ContactId\x20AND\x20c.deletedAt\x20IS\x20NULL','users','o.id\x20=\x20i.UserId','accounts','a.id\x20=\x20i.','messages','me.','interactionsTags','\x20=\x20i.id','tools_tags','t.id\x20=\x20it.TagId','expr','getSelectedTags','CONCAT(\x27,\x27,\x20`TagIds`,\x20\x27,\x27)\x20LIKE\x20?','unreadMessages\x20{OPERATOR}\x200','{OPERATOR}','replace','isNumeric','i.id\x20LIKE\x20?','sms','whatsapp','includes','i.phone\x20LIKE\x20?','fax','i.fax\x20LIKE\x20?','openchannel','mail','isEmail','MATCH\x20(i.to,\x20i.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','getFullTextValue','MATCH\x20(me.body)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)','parseSearch','sqlOperator','conditions','find','buildExpression','type','default','value','start','end','unreadMessages','and','Contact','operator','contact','c.firstName\x20LIKE\x20?\x20OR\x20c.lastName\x20LIKE\x20?\x20OR\x20c.email\x20LIKE\x20?','ContactId','text','Tag','split','tags','clause','ids','$substring'];(function(_0x2d7f0e,_0x3e6fbd){var _0x110b07=function(_0x557b00){while(--_0x557b00){_0x2d7f0e['push'](_0x2d7f0e['shift']());}};_0x110b07(++_0x3e6fbd);}(_0xe3ef,0x101));var _0xfe3e=function(_0x11fe17,_0xbf3b3a){_0x11fe17=_0x11fe17-0x0;var _0x11dcf5=_0xe3ef[_0x11fe17];return _0x11dcf5;};'use strict';var _=require(_0xfe3e('0x0'));var squel=require('squel');var as=require(_0xfe3e('0x1'));var qs=require(_0xfe3e('0x2'));var updateInteraction=require(_0xfe3e('0x3'))[_0xfe3e('0x4')];var utils=require('./utils');var db=require(_0xfe3e('0x5'))['db'];function skipInteractionsQuery(_0x51897e,_0x57cd55,_0x5e16b2){var _0x1244a5=![];var _0x119c7f=utils['getAccountFK'](_0x51897e);if(_0x57cd55[_0xfe3e('0x6')]===_0xfe3e('0x7')&&!_0x5e16b2[_0xfe3e('0x8')]&&!_0x5e16b2[_0x119c7f]){_0x1244a5=!![];}return _0x1244a5;}function getTagsQuery(){return squel['select']()['field']('id')[_0xfe3e('0x9')](_0xfe3e('0xa'))[_0xfe3e('0x9')]('color')[_0xfe3e('0xb')]('tools_tags');}function getUsersQuery(_0x15346b,_0x4f9555){var _0x294100=utils[_0xfe3e('0xc')](_0x15346b);var _0x193a2c=_0xfe3e('0xd')+_0x15346b+'_interactions';var _0x382ea3=squel['select']()[_0xfe3e('0x9')](_0xfe3e('0xe'))[_0xfe3e('0x9')](_0xfe3e('0xf'))[_0xfe3e('0x9')]('ui.'+_0x294100)[_0xfe3e('0xb')](_0x193a2c,'ui')[_0xfe3e('0x10')]('users','u','u.id\x20=\x20ui.UserId');if(_0x4f9555[_0xfe3e('0x11')]>0x0){_0x382ea3[_0xfe3e('0x12')]('ui.'+_0x294100+_0xfe3e('0x13'),_[_0xfe3e('0x14')](_0x4f9555,'id'));}return _0x382ea3;}function getInteractionsQuery(_0x5d74f9){var _0x502a13=utils[_0xfe3e('0x15')](_0x5d74f9);var _0x4372b8=utils[_0xfe3e('0x16')](_0x5d74f9);var _0x462639=utils[_0xfe3e('0xc')](_0x5d74f9);return squel['select']()[_0xfe3e('0xb')](_0x502a13[_0xfe3e('0x17')],'i')[_0xfe3e('0x10')](_0xfe3e('0x18'),'c',_0xfe3e('0x19'))[_0xfe3e('0x10')](_0xfe3e('0x1a'),'o',_0xfe3e('0x1b'))[_0xfe3e('0x10')](_0x502a13[_0xfe3e('0x1c')],'a',_0xfe3e('0x1d')+_0x4372b8)[_0xfe3e('0x10')](_0x502a13[_0xfe3e('0x1e')],'me',_0xfe3e('0x1f')+_0x462639+'\x20=\x20i.id')[_0xfe3e('0x10')](_0x502a13[_0xfe3e('0x20')],'it','it.'+_0x462639+_0xfe3e('0x21'))[_0xfe3e('0x10')](_0xfe3e('0x22'),'t',_0xfe3e('0x23'));}function getSqlClauses(){var _0x19cfab={'body':squel['expr'](),'contact':squel[_0xfe3e('0x24')](),'default':squel['expr'](),'fields':squel['expr'](),'filter':squel[_0xfe3e('0x24')](),'read':squel[_0xfe3e('0x24')](),'tags':{'clause':squel[_0xfe3e('0x24')](),'ids':null},'user':squel[_0xfe3e('0x24')]()};return _0x19cfab;}function parseTagParameter(_0x2e26e9){var _0x566612=squel[_0xfe3e('0x24')]();if(_0x2e26e9){var _0xdb95a1=utils[_0xfe3e('0x25')](_0x2e26e9);_0xdb95a1['forEach'](function(_0x2d2eab){_0x566612['or'](_0xfe3e('0x26'),'%,'+_0x2d2eab+',%');});}return _0x566612;}function parseReadParameter(_0x3ddcf5){var _0x39789d='';if(_0x3ddcf5){_0x39789d=_0xfe3e('0x27');if(_0x3ddcf5==='1'){_0x39789d=_0x39789d['replace'](_0xfe3e('0x28'),'=');}else{_0x39789d=_0x39789d[_0xfe3e('0x29')](_0xfe3e('0x28'),'>');}}return _0x39789d;}function parseSearchFilter(_0x4368c2,_0x1eb36e){var _0x426ffc=squel['expr']();if(_0x1eb36e){var _0x2721ca=_0x1eb36e['replace']('\x5c','\x5c\x5c')['replace'](/'/g,'\x27\x27');if(qs[_0xfe3e('0x2a')](_0x2721ca)){_0x426ffc['or'](_0xfe3e('0x2b'),_0x2721ca+'%');if([_0xfe3e('0x2c'),_0xfe3e('0x2d')][_0xfe3e('0x2e')](_0x4368c2)){_0x426ffc['or'](_0xfe3e('0x2f'),_0x2721ca+'%');}else if(_0x4368c2===_0xfe3e('0x30')){_0x426ffc['or'](_0xfe3e('0x31'),_0x2721ca+'%');}else if(_0x4368c2===_0xfe3e('0x32')){_0x426ffc['or']('i.from\x20LIKE\x20?',_0x2721ca+'%');}}else if(_0x4368c2===_0xfe3e('0x33')&&qs[_0xfe3e('0x34')](_0x2721ca)){_0x426ffc['or']('c.email\x20LIKE\x20?',_0x2721ca+'%');}else{if(_0x4368c2===_0xfe3e('0x33')){_0x426ffc['or'](_0xfe3e('0x35'),qs[_0xfe3e('0x36')](_0x2721ca,!![]))['or']('MATCH\x20(me.plainBody,\x20me.subject)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xfe3e('0x36')](_0x2721ca));}else if(_0x4368c2!==_0xfe3e('0x30')){_0x426ffc['or'](_0xfe3e('0x37'),qs['getFullTextValue'](_0x2721ca));}_0x426ffc['or'](_0xfe3e('0x38'),qs['getFullTextValue'](_0x2721ca,!![]),null);}}return _0x426ffc;}function parseAdvancedSearchFilter(_0x152ddf,_0x53c65f){var _0xefe1f6=getSqlClauses();var _0x1730ac=as[_0xfe3e('0x39')](_0x152ddf);var _0x2360ce=_0x1730ac[_0xfe3e('0x3a')];for(var _0x528e29=0x0;_0x528e29<_0x1730ac[_0xfe3e('0x3b')][_0xfe3e('0x11')];_0x528e29++){var _0x1b891a=_0x1730ac[_0xfe3e('0x3b')][_0x528e29];var _0x7cb9f8='i';var _0x1055c3=_[_0xfe3e('0x3c')](_0x53c65f,[_0xfe3e('0xa'),_0x1b891a[_0xfe3e('0x9')]]);if(_0x1055c3){var _0x511439=as[_0xfe3e('0x3d')](_0x7cb9f8,_0x1055c3[_0xfe3e('0x3e')],_0x1b891a);_0xefe1f6[_0xfe3e('0x3f')][_0x2360ce](_0x511439['text'],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x41')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x42')]);}else{switch(_0x1b891a['field']){case _0xfe3e('0x43'):var _0x4f4e5c=parseReadParameter(_0x1b891a[_0xfe3e('0x40')]);_0xefe1f6['read'][_0xfe3e('0x44')](_0x4f4e5c);break;case _0xfe3e('0x45'):if(_0x1b891a[_0xfe3e('0x46')]==='$substring'){if(_0x1b891a[_0xfe3e('0x40')]['split']('\x20')[_0xfe3e('0x11')]>0x1){_0xefe1f6[_0xfe3e('0x47')][_0x2360ce]('MATCH\x20(c.firstName,\x20c.lastName,\x20c.phone,\x20c.mobile,\x20c.fax,\x20c.email)\x20AGAINST\x20(?\x20IN\x20BOOLEAN\x20MODE)',qs[_0xfe3e('0x36')](_0x1b891a['value'],!![]),null);}else{var _0x8dacde='%'+_0x1b891a[_0xfe3e('0x40')]+'%';_0xefe1f6[_0xfe3e('0x47')][_0x2360ce](_0xfe3e('0x48'),_0x8dacde,_0x8dacde,_0x8dacde);}}else{_0x1055c3=_['find'](_0x53c65f,[_0xfe3e('0xa'),_0xfe3e('0x49')]);_0x1b891a[_0xfe3e('0x9')]=_0xfe3e('0x49');_0x511439=as[_0xfe3e('0x3d')](_0x7cb9f8,_0x1055c3['type'],_0x1b891a);_0xefe1f6[_0xfe3e('0x47')][_0x2360ce](_0x511439[_0xfe3e('0x4a')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x41')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x42')]);}break;case _0xfe3e('0x4b'):var _0x36716c=_0x1b891a[_0xfe3e('0x40')][_0xfe3e('0x4c')](',')[_0xfe3e('0x14')](function(_0x781ef1){return Number(_0x781ef1);});var _0x2eaa91=parseTagParameter(_0x36716c);_0xefe1f6[_0xfe3e('0x4d')][_0xfe3e('0x4e')][_0xfe3e('0x44')](_0x2eaa91);_0xefe1f6['tags'][_0xfe3e('0x4f')]=_0x36716c;break;case'User':if(_0x1b891a[_0xfe3e('0x46')]===_0xfe3e('0x50')){_0xefe1f6['user'][_0x2360ce](_0xfe3e('0x51'),'%'+_0x1b891a[_0xfe3e('0x40')]+'%',null);}else{_0x1055c3=_[_0xfe3e('0x3c')](_0x53c65f,[_0xfe3e('0xa'),_0xfe3e('0x52')]);_0x1b891a[_0xfe3e('0x9')]=_0xfe3e('0x52');_0x511439=as[_0xfe3e('0x3d')](_0x7cb9f8,_0x1055c3[_0xfe3e('0x3e')],_0x1b891a);_0xefe1f6[_0xfe3e('0x53')][_0x2360ce](_0x511439[_0xfe3e('0x4a')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x41')],_0x511439[_0xfe3e('0x40')][_0xfe3e('0x42')]);}break;case _0xfe3e('0x54'):case _0xfe3e('0x55'):_0x511439=as[_0xfe3e('0x3d')]('me',null,_0x1b891a);_0xefe1f6[_0xfe3e('0x54')][_0x2360ce](_0x511439['text'],_0x511439[_0xfe3e('0x40')]['start'],_0x511439['value'][_0xfe3e('0x42')]);break;}}}return _0xefe1f6;}function parseModelFields(_0x543781,_0x183f0c,_0x315db4){var _0x543c2d=utils[_0xfe3e('0x16')](_0x543781);var _0x578738=squel['expr']();var _0x193bfe=_(_0x183f0c)['keys']()[_0xfe3e('0x14')](function(_0x57e48c){return _[_0xfe3e('0x56')](_0x315db4,['name',_0x57e48c])?_0x57e48c:undefined;})[_0xfe3e('0x57')]()[_0xfe3e('0x40')]();if(_0x193bfe[_0xfe3e('0x11')]>0x0){_0x193bfe[_0xfe3e('0x58')](function(_0x3eb3ef){if(_0x3eb3ef===_0x543c2d){_0x578738[_0xfe3e('0x44')]('i.'+_0x543c2d+_0xfe3e('0x13'),[]['concat'](_0x183f0c[_0x3eb3ef]));}else if(_0x3eb3ef===_0xfe3e('0x59')){var _0x4719e9=JSON[_0xfe3e('0x5a')](_0x183f0c[_0x3eb3ef])[_0xfe3e('0x5b')];var _0x6ff20d=JSON['parse'](_0x183f0c[_0x3eb3ef])[_0xfe3e('0x5c')];_0x578738[_0xfe3e('0x44')](_0xfe3e('0x5d'),_0x4719e9,_0x6ff20d);}else{if(_0x183f0c[_0x3eb3ef]===_0xfe3e('0x5e')){_0x578738[_0xfe3e('0x44')]('i.'+_0x3eb3ef+'\x20IS\x20NULL');}else{_0x578738[_0xfe3e('0x44')]('i.'+_0x3eb3ef+_0xfe3e('0x5f'),_0x183f0c[_0x3eb3ef]);}}});}return _0x578738;}function parseQueryParameters(_0x313ede,_0x3e8a8b,_0x431da8){var _0x12f2a8=getSqlClauses();return Promise[_0xfe3e('0x60')]()['then'](function(){return parseModelFields(_0x313ede,_0x3e8a8b,_0x431da8);})['then'](function(_0x2a4d9b){_0x12f2a8[_0xfe3e('0x61')]['and'](_0x2a4d9b);return parseReadParameter(_0x3e8a8b[_0xfe3e('0x62')]);})[_0xfe3e('0x63')](function(_0x52f847){_0x12f2a8['read'][_0xfe3e('0x44')](_0x52f847);return parseTagParameter(_0x3e8a8b[_0xfe3e('0x64')]);})[_0xfe3e('0x63')](function(_0x34f720){_0x12f2a8[_0xfe3e('0x4d')][_0xfe3e('0x4e')][_0xfe3e('0x44')](_0x34f720);return parseSearchFilter(_0x313ede,_0x3e8a8b[_0xfe3e('0x65')]);})[_0xfe3e('0x63')](function(_0x4d59c6){_0x12f2a8[_0xfe3e('0x65')]=_0x4d59c6;return _0x12f2a8;});}function checkAccountsRestrictions(_0x41bc8b,_0x37b17e,_0x5336cc){var _0x5db34e=utils['getAccountFK'](_0x41bc8b);var _0x17695a=_0xfe3e('0x66')+_[_0xfe3e('0x67')](_0x41bc8b)+(_0x41bc8b===_0xfe3e('0x68')?'Websites':_0xfe3e('0x69'));var _0x4c4fa8=squel[_0xfe3e('0x24')]();return Promise['resolve']()[_0xfe3e('0x63')](function(){if(_0x5336cc[_0xfe3e('0x8')]&&_0x37b17e[_0xfe3e('0x6')]===_0xfe3e('0x7')){return _0x37b17e[_0x17695a]({'attributes':['id'],'raw':!![]});}})['then'](function(_0xf916f3){if(_0xf916f3){if(_0xf916f3[_0xfe3e('0x11')]===0x0){_0x4c4fa8[_0xfe3e('0x44')]('i.'+_0x5db34e+'\x20IS\x20NULL');}else{_0x4c4fa8['and']('i.'+_0x5db34e+'\x20IN\x20?',_[_0xfe3e('0x14')](_0xf916f3,'id'));}}else if(!_0x5336cc[_0x5db34e]){_0x4c4fa8[_0xfe3e('0x44')]('i.'+_0x5db34e+_0xfe3e('0x6a'));}})['then'](function(){return _0x4c4fa8;});}function getClosedOrderClause(_0x4c2bc4,_0x30b9e0){var _0x1796f6='';var _0x110617=[_0xfe3e('0x6b'),_0xfe3e('0x6c'),_0xfe3e('0x6d')];if(_0x4c2bc4===_0xfe3e('0x33')){_0x110617[_0xfe3e('0x6e')](_0xfe3e('0x6f'));}if(_0x30b9e0[_0xfe3e('0x70')]==='0'&&_0x4c2bc4===_0xfe3e('0x33')){_0x1796f6='i.substatus';}else{if(_0x30b9e0['closed']==='1'){_0x110617['shift']();}_0x1796f6=_0xfe3e('0x71')+_0x110617[_0xfe3e('0x72')](',\x20')+')';}return _0x1796f6;}function getFilteredInteractions(_0x499240,_0x522ada,_0x4a5535,_0x548814){var _0x4fddf6=utils[_0xfe3e('0xc')](_0x499240);var _0xdfd456=_[_0xfe3e('0x67')](_0x499240)+_0xfe3e('0x73');var _0x32be98=[];var _0x57445e=getTagsQuery();var _0x266078={'type':db[_0xfe3e('0x74')][_0xfe3e('0x75')][_0xfe3e('0x76')],'raw':!![]};var _0x23948c=[];var _0x35daa6=[];return db[_0xfe3e('0x77')][_0xfe3e('0x78')](_0x57445e[_0xfe3e('0x79')](),_0x266078)[_0xfe3e('0x63')](function(_0x5db59f){_0x32be98=_[_0xfe3e('0x7a')](_0x5db59f,'id');_0x266078=_[_0xfe3e('0x7b')](_0x266078,{'model':db[_0xdfd456],'mapToModel':!![],'nest':!![]});if(_0x4a5535['fields']){_0x548814[_0xfe3e('0x7c')]['forEach'](function(_0x5b79b4){_0x522ada[_0xfe3e('0x9')]('i.'+_0x5b79b4);});}else{_0x522ada[_0xfe3e('0x9')]('SUM(me.read\x20=\x200\x20AND\x20me.direction\x20=\x20\x27in\x27)','unreadMessages');_0x522ada['field'](_0xfe3e('0x7d'),_0xfe3e('0x7e'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x7f'),'Account.mandatoryDisposition');if(_0x499240==='mail'){_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x80'),_0xfe3e('0x81'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x82'),'contactName');_0x522ada[_0xfe3e('0x9')]('i.id');_0x522ada['field'](_0xfe3e('0x83'));_0x522ada['field'](_0xfe3e('0x84'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x85'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x86'));_0x522ada['field'](_0xfe3e('0x87'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x88'));_0x522ada['field'](_0xfe3e('0x89'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8a'));_0x522ada['field'](_0xfe3e('0x6d'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x6c'));_0x522ada[_0xfe3e('0x9')]('i.thirdDisposition');_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x6f'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8b'));_0x522ada[_0xfe3e('0x9')]('i.ContactId');_0x522ada[_0xfe3e('0x9')]('i.MailAccountId');_0x522ada['field']('i.UserId');}else if(_0x499240===_0xfe3e('0x32')){_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8c'),'contactName');}else{_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8d'),_0xfe3e('0x8e'));}if(_0x499240!=='mail'){_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x8f'));}_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x90'),_0xfe3e('0x91'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x92'),_0xfe3e('0x93'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x94'),_0xfe3e('0x95'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x96'),_0xfe3e('0x97'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x98'),_0xfe3e('0x99'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x9a'),'Contact.fax');_0x522ada['field']('o.fullname','Owner.fullname');_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x9b'),_0xfe3e('0x9c'));_0x522ada[_0xfe3e('0x9')](_0xfe3e('0x9d'),_0xfe3e('0x9e'));}if(_0x548814[_0xfe3e('0x9f')]){_0x522ada[_0xfe3e('0x9f')](_0x548814['limit']);}if(_0x548814['offset']){_0x522ada[_0xfe3e('0xa0')](_0x548814['offset']);}return db['sequelize'][_0xfe3e('0x78')](_0x522ada['toString'](),_0x266078);})[_0xfe3e('0x63')](function(_0x2a549f){_0x23948c=_0x2a549f;var _0x4a0492=getUsersQuery(_0x499240,_0x23948c);return db[_0xfe3e('0x77')][_0xfe3e('0x78')](_0x4a0492[_0xfe3e('0x79')](),_0x266078);})[_0xfe3e('0x63')](function(_0xc38b97){_0x35daa6=_[_0xfe3e('0xa1')](_0xc38b97,_0x4fddf6);if(_0x499240===_0xfe3e('0x33')){return db[_0xfe3e('0xa2')][_0xfe3e('0xa3')]({'attributes':[_0xfe3e('0xa4')],'raw':!![]});}})['then'](function(_0x5c5753){var _0x3f5c53=_0x5c5753?_0x5c5753['enableEmailPreview']:undefined;var _0x187267=_0x23948c[_0xfe3e('0x14')](function(_0x3b9488){return updateInteraction(_0x3b9488,_0x32be98,_0x35daa6,_0x3f5c53);});return Promise['all'](_0x187267);});}function countFilteredInteractions(_0x5298ff,_0x39dfeb){var _0x1d9ca7=_0x5298ff[_0xfe3e('0xa5')]();_0x1d9ca7[_0xfe3e('0x9')](_0xfe3e('0xa6'));_0x1d9ca7[_0xfe3e('0x9')](_0xfe3e('0xa7'),'unreadMessages');var _0x420963=utils['getSelectedTags'](_0x39dfeb);if(!_['isEmpty'](_0x420963)){_0x1d9ca7[_0xfe3e('0x12')](_0xfe3e('0xa8'),_0x420963);}var _0x409239={'type':db[_0xfe3e('0x74')][_0xfe3e('0x75')][_0xfe3e('0x76')],'raw':!![]};return db[_0xfe3e('0x77')][_0xfe3e('0x78')](_0x1d9ca7[_0xfe3e('0x79')](),_0x409239);}module['exports']={'checkAccountsRestrictions':checkAccountsRestrictions,'countFilteredInteractions':countFilteredInteractions,'getClosedOrderClause':getClosedOrderClause,'getFilteredInteractions':getFilteredInteractions,'getInteractionsQuery':getInteractionsQuery,'parseAdvancedSearchFilter':parseAdvancedSearchFilter,'parseQueryParameters':parseQueryParameters,'skipInteractionsQuery':skipInteractionsQuery};
\ No newline at end of file