18 var _0x1c20=['JSDOM','../../mysqldb','dbH','analytics','argv','MMMM\x20Do\x20YYYY,\x20h:mm:ss\x20a','AnalyticExtractedReport','update','map','tableHeader','toString','value','fill','auto','body','chunk','forEach','format','name','length','pageBreak','margin','push','landscape','\x20/\x20','footer','Arial','right','num','Empty','basename','.pdf','join','%s.%s','Setting','find','split','splitSizePdf','then','sequelize','query','%s\x20limit\x20%d\x20OFFSET\x20%d','QueryTypes','SELECT','all','flatten','%s%d.%s','zip','info','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','CSV','Completed','pdf','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','findOne','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','PDF','exit','/fonts/arial-regular.ttf','/fonts/arial-bold.ttf','/fonts/arial-italic.ttf','/fonts/arial-bold-italic.ttf','%s\x20#%d','channel','interactionId','YYYY-MM-DD','center','Interaction\x20Transcript','pipe','createWriteStream','finish','end','createPdfFromHTML','createPdfKitDocument','catch','lodash','path','moment','html-to-pdfmake','pdfmake/src/printer','zip-dir','jsdom'];(function(_0x3b380d,_0x4bf247){var _0x54502b=function(_0x35d207){while(--_0x35d207){_0x3b380d['push'](_0x3b380d['shift']());}};_0x54502b(++_0x4bf247);}(_0x1c20,0x145));var _0x01c2=function(_0x3d34da,_0x3abcc1){_0x3d34da=_0x3d34da-0x0;var _0xcf6af8=_0x1c20[_0x3d34da];return _0xcf6af8;};'use strict';var _=require(_0x01c2('0x0'));var fs=require('fs');var util=require('util');var path=require(_0x01c2('0x1'));var moment=require(_0x01c2('0x2'));var htmlToPdfmake=require(_0x01c2('0x3'));var PdfPrinter=require(_0x01c2('0x4'));var zipdir=require(_0x01c2('0x5'));var rimraf=require('rimraf');var JSDOM=require(_0x01c2('0x6'))[_0x01c2('0x7')];var window=new JSDOM('')['window'];var db=require(_0x01c2('0x8'))['db'];var dbH=require(_0x01c2('0x8'))[_0x01c2('0x9')];var logger=require('../../config/logger')(_0x01c2('0xa'));var EXTRACTED_REPORT_ID=Number(process[_0x01c2('0xb')][0x2]);var QUERY=process[_0x01c2('0xb')][0x3];var PATH=process['argv'][0x4];var NAME=process[_0x01c2('0xb')][0x5];var FORMAT=_0x01c2('0xc');var EXTRACTED_REPORT;var EXIT_CODE=0x0;function analyticExtractedReport(_0xe2b77c,_0x568431){var _0x12008e={'status':_0xe2b77c};var _0x316c79={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x568431){_0x12008e['savename']=_0x568431;}return db[_0x01c2('0xd')][_0x01c2('0xe')](_0x12008e,_0x316c79);}function getHeaders(_0x49f360){return _[_0x01c2('0xf')](_0x49f360,function(_0x1d23e2){return{'text':_0x1d23e2,'style':_0x01c2('0x10')};});}function getRows(_0x211780,_0x2afe49){return _[_0x01c2('0xf')](_0x2afe49,function(_0x233236){return _(_0x233236)['pick'](_0x211780)[_0x01c2('0xf')](function(_0x25e221){return _0x25e221?_[_0x01c2('0x11')](_0x25e221):'';})[_0x01c2('0x12')]();});}function createTable(_0x3c14a5,_0x3af85a){var _0x53e27f={'widths':_[_0x01c2('0x13')](Array(_0x3c14a5['length']),0x91),'heights':function(_0x8d8676){return _0x8d8676===0x0?_0x01c2('0x14'):0x32;},'dontBreakRows':!![],'headerRows':0x1,'body':[]};var _0x4cac4b=getHeaders(_0x3c14a5);_0x53e27f['body']['push'](_0x4cac4b);var _0x4c553a=getRows(_0x3c14a5,_0x3af85a);_0x53e27f[_0x01c2('0x15')]=_0x53e27f[_0x01c2('0x15')]['concat'](_0x4c553a);return _0x53e27f;}function createTables(_0x5e6e47){var _0x98af69=[];var _0x211a01=_[_0x01c2('0x16')](Object['keys'](_0x5e6e47[0x0]),0x5);_0x211a01[_0x01c2('0x17')](function(_0x7632ba){_0x98af69['push'](createTable(_0x7632ba,_0x5e6e47));});return _0x98af69;}function getPDFDocDefinition(_0x460ee0){var _0x500d66=util[_0x01c2('0x18')]('Name:\x20%s\x0aReport:\x20%s\x0aFrom:\x20%s\x20To:\x20%s',NAME,EXTRACTED_REPORT[_0x01c2('0x19')],moment(EXTRACTED_REPORT['startDate'])[_0x01c2('0x18')](FORMAT),moment(EXTRACTED_REPORT['endDate'])[_0x01c2('0x18')](FORMAT));var _0x1ac4cb=[];for(var _0x1f843f=0x0;_0x1f843f<_0x460ee0[_0x01c2('0x1a')];_0x1f843f++){var _0x1d4a2a=[];if(_0x1f843f===0x0){_0x1d4a2a['push']({'text':_0x500d66,'style':'header'});}var _0x552338={'table':_0x460ee0[_0x1f843f]};if(_0x1f843f>0x0){_0x552338[_0x01c2('0x1b')]='before';_0x552338[_0x01c2('0x1c')]=[0x0,0x46,0x0,0x0];}_0x1d4a2a['push'](_0x552338);_0x1ac4cb[_0x01c2('0x1d')](_0x1d4a2a);}return{'pageSize':'A4','pageOrientation':_0x01c2('0x1e'),'content':_0x1ac4cb,'footer':function(_0x54a423,_0x366d9c){return{'text':_0x54a423[_0x01c2('0x11')]()+_0x01c2('0x1f')+_0x366d9c,'style':_0x01c2('0x20')};},'defaultStyle':{'font':_0x01c2('0x21')},'styles':{'header':{'fontSize':0x12,'bold':!![],'margin':[0x0,0x0,0x0,0xa]},'tableHeader':{'bold':!![],'fontSize':0xd,'color':'black'},'footer':{'alignment':_0x01c2('0x22'),'margin':[0x0,0x0,0x28,0x0]}}};}function extractReport(_0x54d7e1){var _0xa8ed4a=0x1388;var _0x5458cf;if(!_0x54d7e1[0x0][_0x01c2('0x23')]){return analyticExtractedReport(_0x01c2('0x24'));}var _0x42eb13=[];var _0x3bba1f=0x0;var _0x1f6dd1=!![];var _0x3299ea=path['dirname'](PATH);var _0x4d8dcf=path[_0x01c2('0x25')](PATH,_0x01c2('0x26'));var _0x28312a=path[_0x01c2('0x27')](_0x3299ea,util[_0x01c2('0x18')](_0x01c2('0x28'),_0x4d8dcf,'pdf'));var _0xda5bce=![];return db[_0x01c2('0x29')][_0x01c2('0x2a')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x01c2('0x2b'),'splitSizePdf']})['then'](function(_0x50648e){if(_0x50648e){_0x5458cf=_0x50648e;_0xa8ed4a=_0x5458cf[_0x01c2('0x2c')]||0x3e8;}})[_0x01c2('0x2d')](function(){if(_0x54d7e1&&_0x54d7e1[_0x01c2('0x1a')]){var _0x5e3ab4=_0x54d7e1[0x0]['num']%(_0x3bba1f+_0xa8ed4a);if(_0x5458cf['split']){for(;_0x1f6dd1;_0x3bba1f+=_0xa8ed4a,_0x5e3ab4=_0x54d7e1[0x0]['num']%(_0x3bba1f+_0xa8ed4a)){if(_0x5e3ab4==0x0||_0x5e3ab4==_0x54d7e1[0x0][_0x01c2('0x23')]){_0x1f6dd1=![];}_0x42eb13[_0x01c2('0x1d')](dbH[_0x01c2('0x2e')][_0x01c2('0x2f')](util[_0x01c2('0x18')](_0x01c2('0x30'),QUERY,_0xa8ed4a,_0x3bba1f),{'type':dbH[_0x01c2('0x2e')][_0x01c2('0x31')]['SELECT']}));}}else{_0x42eb13[_0x01c2('0x1d')](dbH[_0x01c2('0x2e')][_0x01c2('0x2f')](QUERY,{'type':dbH[_0x01c2('0x2e')][_0x01c2('0x31')][_0x01c2('0x32')]}));}}_0xda5bce=_0x5458cf['split']&&_0x42eb13[_0x01c2('0x1a')]>0x1;if(!fs['existsSync'](path[_0x01c2('0x27')](_0x3299ea,_0x4d8dcf))&&_0xda5bce){fs['mkdirSync'](path['join'](_0x3299ea,_0x4d8dcf));}return Promise[_0x01c2('0x33')](_0x42eb13);})['then'](function(_0xe2555d){return createTables(_[_0x01c2('0x34')](_0xe2555d));})['then'](function(_0x59c840){var _0x169005=getPDFDocDefinition(_0x59c840);var _0x359547=getPDFPrinter();var _0x5cb3c1=_0x359547['createPdfKitDocument'](_0x169005);if(_0xda5bce)_0x28312a=path[_0x01c2('0x27')](_0x3299ea,_0x4d8dcf,util[_0x01c2('0x18')](_0x01c2('0x35'),_0x4d8dcf,index,'pdf'));return writePDFDocument(_0x5cb3c1,_0x28312a);})[_0x01c2('0x2d')](function(){if(!_0xda5bce)return;zipdir(path[_0x01c2('0x27')](_0x3299ea,_0x4d8dcf),{'saveTo':path['join'](_0x3299ea,util[_0x01c2('0x18')](_0x01c2('0x28'),_0x4d8dcf,_0x01c2('0x36')))},function(_0x331ecb){if(_0x331ecb)throw _0x331ecb;return;});})['then'](function(){if(!_0xda5bce)return;rimraf(path[_0x01c2('0x27')](_0x3299ea,_0x4d8dcf),function(){});})[_0x01c2('0x2d')](function(){logger[_0x01c2('0x37')](util['format'](_0x01c2('0x38'),EXTRACTED_REPORT_ID,_0x01c2('0x39')));return analyticExtractedReport(_0x01c2('0x3a'),_0xda5bce?util[_0x01c2('0x18')]('%s.%s',_0x4d8dcf,_0xda5bce?'zip':_0x01c2('0x3b')):null);});}function main(){if(!EXTRACTED_REPORT_ID)return;logger[_0x01c2('0x37')](util[_0x01c2('0x18')](_0x01c2('0x3c'),EXTRACTED_REPORT_ID,'PDF'));return db['AnalyticExtractedReport'][_0x01c2('0x3d')]({'where':{'id':EXTRACTED_REPORT_ID}})['then'](function(_0x8c68dc){EXTRACTED_REPORT=_0x8c68dc;return dbH['sequelize'][_0x01c2('0x2f')](util[_0x01c2('0x18')](_0x01c2('0x3e'),QUERY),{'type':dbH[_0x01c2('0x2e')]['QueryTypes'][_0x01c2('0x32')]});})['then'](extractReport)['catch'](function(_0x5ba63c){logger[_0x01c2('0x37')](util[_0x01c2('0x18')](_0x01c2('0x3f'),EXTRACTED_REPORT_ID,_0x01c2('0x40')),util['inspect'](_0x5ba63c,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport('Failed');})['finally'](function(){process[_0x01c2('0x41')](EXIT_CODE);});}main();function getPDFPrinter(){var _0x2c8f9f=new PdfPrinter({'Arial':{'normal':__dirname+_0x01c2('0x42'),'bold':__dirname+_0x01c2('0x43'),'italics':__dirname+_0x01c2('0x44'),'bolditalics':__dirname+_0x01c2('0x45')}});return _0x2c8f9f;}function getPDFDocDefinitionFromHTML(_0x21eb50,_0x10218d){var _0xf75fd8=util[_0x01c2('0x18')](_0x01c2('0x46'),_0x10218d[_0x01c2('0x47')],_0x10218d[_0x01c2('0x48')]);var _0x197d2a=moment()['format'](_0x01c2('0x49'))[_0x01c2('0x11')]();var _0x2e3cb5=htmlToPdfmake(_0x21eb50,{'window':window,'tableAutoSize':!![]});return{'content':[_0x2e3cb5],'defaultStyle':{'font':'Arial'},'styles':{'header':{'fontSize':0x12,'bold':!![],'alignment':'center','margin':[0xa,0xa,0xa,0xa]},'footer':{'fontSize':0x9,'alignment':_0x01c2('0x4a'),'margin':[0xa,0x14,0xa,0xa]},'textblock':{'fontSize':0xb},'textfield':{'bold':!![]},'messageContainer':{'fontSize':0xa},'messageInfo':{'bold':!![]},'interactionData':{'alignment':'center'}},'header':function(){return[{'text':_0x01c2('0x4b'),'style':'header'}];},'footer':function(_0x3839b6,_0xc77fb8){return[{'text':util[_0x01c2('0x18')]('\x09\x09XCALLY\x20Motion\x20-\x20%s\x09\x09\x09\x09%d/%d\x09\x09\x09\x09%s',_0xf75fd8,_0x3839b6,_0xc77fb8,_0x197d2a),'style':_0x01c2('0x20')}];}};}function writePDFDocument(_0x19294e,_0x3f36bb){return new Promise(function(_0x3cae11,_0x1f1425){var _0x2a5dd1=_0x19294e[_0x01c2('0x4c')](fs[_0x01c2('0x4d')](_0x3f36bb));_0x2a5dd1['on'](_0x01c2('0x4e'),function(){_0x3cae11(_0x01c2('0x4e'));});_0x2a5dd1['on']('error',function(_0x2a3f42){_0x1f1425(_0x2a3f42);});_0x19294e[_0x01c2('0x4f')]();});}exports[_0x01c2('0x50')]=function(_0x1bd453,_0x42bf14){var _0x1c2eda=getPDFPrinter();var _0x2aebf6=getPDFDocDefinitionFromHTML(_0x1bd453,_0x42bf14);var _0x252cad=_0x1c2eda[_0x01c2('0x51')](_0x2aebf6);return writePDFDocument(_0x252cad,_0x42bf14[_0x01c2('0x1')])[_0x01c2('0x52')](function(_0x33a666){throw _0x33a666;});};