18 var _0x4456=['QueryTypes','SELECT','dirname','.pdf','join','mkdirSync','each','flatten','%s%d.%s','pdf','%s.%s','all','zip','zip\x20finished','info','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','PDF','Completed','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Failed','exit','/fonts/arial-regular.ttf','/fonts/arial-bold-italic.ttf','%s\x20#%d','interactionId','YYYY-MM-DD','Arial','center','Interaction\x20Transcript','finish','error','end','createPdfFromHTML','createPdfKitDocument','lodash','moment','html-to-pdfmake','pdfmake/src/printer','zip-dir','rimraf','jsdom','JSDOM','window','../../mysqldb','dbH','argv','savename','AnalyticExtractedReport','update','map','tableHeader','pick','toString','value','fill','length','auto','push','body','concat','chunk','keys','forEach','format','Name:\x20%s\x0aReport:\x20%s\x0aFrom:\x20%s\x20To:\x20%s','startDate','endDate','header','pageBreak','before','margin','landscape','black','right','num','Empty','Setting','find','split','splitSizePdf','then','isInteger','sequelize','query','%s\x20limit\x20%d\x20OFFSET\x20%d'];(function(_0x318ebd,_0x23253a){var _0x56e1e3=function(_0x48f1d9){while(--_0x48f1d9){_0x318ebd['push'](_0x318ebd['shift']());}};_0x56e1e3(++_0x23253a);}(_0x4456,0x1d7));var _0x6445=function(_0x386f62,_0x597de){_0x386f62=_0x386f62-0x0;var _0x2658bb=_0x4456[_0x386f62];return _0x2658bb;};'use strict';var _=require(_0x6445('0x0'));var fs=require('fs');var util=require('util');var path=require('path');var moment=require(_0x6445('0x1'));var htmlToPdfmake=require(_0x6445('0x2'));var PdfPrinter=require(_0x6445('0x3'));var zipdir=require(_0x6445('0x4'));var rimraf=require(_0x6445('0x5'));var JSDOM=require(_0x6445('0x6'))[_0x6445('0x7')];var window=new JSDOM('')[_0x6445('0x8')];var BPromise=require('bluebird');var db=require(_0x6445('0x9'))['db'];var dbH=require(_0x6445('0x9'))[_0x6445('0xa')];var logger=require('../../config/logger')('analytics');var EXTRACTED_REPORT_ID=Number(process[_0x6445('0xb')][0x2]);var QUERY=process['argv'][0x3];var PATH=process[_0x6445('0xb')][0x4];var NAME=process['argv'][0x5];var FORMAT='MMMM\x20Do\x20YYYY,\x20h:mm:ss\x20a';var EXTRACTED_REPORT;var EXIT_CODE=0x0;function analyticExtractedReport(_0x3f278a,_0x3405f5){var _0x4349d3={'status':_0x3f278a};var _0x19bcc2={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x3405f5){_0x4349d3[_0x6445('0xc')]=_0x3405f5;}return db[_0x6445('0xd')][_0x6445('0xe')](_0x4349d3,_0x19bcc2);}function getHeaders(_0x56d0ac){return _[_0x6445('0xf')](_0x56d0ac,function(_0x58fe45){return{'text':_0x58fe45,'style':_0x6445('0x10')};});}function getRows(_0x59b7e3,_0x56f307){return _[_0x6445('0xf')](_0x56f307,function(_0x47caf2){return _(_0x47caf2)[_0x6445('0x11')](_0x59b7e3)[_0x6445('0xf')](function(_0x312869){return _0x312869?_[_0x6445('0x12')](_0x312869):'';})[_0x6445('0x13')]();});}function createTable(_0x1435cd,_0x1b39a9){var _0x5a9501={'widths':_[_0x6445('0x14')](Array(_0x1435cd[_0x6445('0x15')]),0x91),'heights':function(_0x4779b7){return _0x4779b7===0x0?_0x6445('0x16'):0x32;},'dontBreakRows':!![],'headerRows':0x1,'body':[]};var _0x25f80f=getHeaders(_0x1435cd);_0x5a9501['body'][_0x6445('0x17')](_0x25f80f);var _0xe816e4=getRows(_0x1435cd,_0x1b39a9);_0x5a9501[_0x6445('0x18')]=_0x5a9501[_0x6445('0x18')][_0x6445('0x19')](_0xe816e4);return _0x5a9501;}function createTables(_0x1f0d09){var _0x4e92a5=[];var _0x127578=_[_0x6445('0x1a')](Object[_0x6445('0x1b')](_0x1f0d09[0x0]),0x5);_0x127578[_0x6445('0x1c')](function(_0x1209b0){_0x4e92a5[_0x6445('0x17')](createTable(_0x1209b0,_0x1f0d09));});return _0x4e92a5;}function getPDFDocDefinition(_0x220baa){var _0x66a219=util[_0x6445('0x1d')](_0x6445('0x1e'),NAME,EXTRACTED_REPORT['name'],moment(EXTRACTED_REPORT[_0x6445('0x1f')])[_0x6445('0x1d')](FORMAT),moment(EXTRACTED_REPORT[_0x6445('0x20')])[_0x6445('0x1d')](FORMAT));var _0x114f14=[];for(var _0x5091d0=0x0;_0x5091d0<_0x220baa[_0x6445('0x15')];_0x5091d0++){var _0x3557cd=[];if(_0x5091d0===0x0){_0x3557cd[_0x6445('0x17')]({'text':_0x66a219,'style':_0x6445('0x21')});}var _0x53bf59={'table':_0x220baa[_0x5091d0]};if(_0x5091d0>0x0){_0x53bf59[_0x6445('0x22')]=_0x6445('0x23');_0x53bf59[_0x6445('0x24')]=[0x0,0x46,0x0,0x0];}_0x3557cd['push'](_0x53bf59);_0x114f14[_0x6445('0x17')](_0x3557cd);}return{'pageSize':'A4','pageOrientation':_0x6445('0x25'),'content':_0x114f14,'footer':function(_0xe99214,_0x5d7622){return{'text':_0xe99214[_0x6445('0x12')]()+'\x20/\x20'+_0x5d7622,'style':'footer'};},'defaultStyle':{'font':'Arial'},'styles':{'header':{'fontSize':0x12,'bold':!![],'margin':[0x0,0x0,0x0,0xa]},'tableHeader':{'bold':!![],'fontSize':0xd,'color':_0x6445('0x26')},'footer':{'alignment':_0x6445('0x27'),'margin':[0x0,0x0,0x28,0x0]}}};}function extractReport(_0x232aba){var _0x10f18a=0x1388;var _0x110422;if(!_0x232aba[0x0][_0x6445('0x28')]){return analyticExtractedReport(_0x6445('0x29'));}return db[_0x6445('0x2a')][_0x6445('0x2b')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x6445('0x2c'),_0x6445('0x2d')]})[_0x6445('0x2e')](function(_0x25c294){if(_0x25c294){_0x110422=_0x25c294;_0x10f18a=_0x110422[_0x6445('0x2d')]||0x3e8;}})[_0x6445('0x2e')](function(){var _0x1c720b=[];var _0x169010=0x0;if(_0x110422[_0x6445('0x2c')]){if(_0x232aba&&_0x232aba['length']){var _0xf352c2=_['range'](_0x232aba[0x0][_0x6445('0x28')]/_0x10f18a);var _0x32f15b=Number[_0x6445('0x2f')](_0x232aba[0x0][_0x6445('0x28')]/_0x10f18a)?_0x232aba[0x0]['num']%_0x10f18a:0x0;_0xf352c2['forEach'](function(_0x5d70e9){if(_0x5d70e9>0x0){_0x169010+=_0x10f18a;}_0x1c720b[_0x6445('0x17')](dbH[_0x6445('0x30')][_0x6445('0x31')](util['format'](_0x6445('0x32'),QUERY,_0x10f18a,_0x169010),{'type':dbH[_0x6445('0x30')][_0x6445('0x33')]['SELECT']}));});if(_0x32f15b>0x0){_0x169010+=_0x10f18a;_0x1c720b[_0x6445('0x17')](dbH[_0x6445('0x30')][_0x6445('0x31')](util[_0x6445('0x1d')](_0x6445('0x32'),QUERY,_0x32f15b,_0x169010),{'type':dbH['sequelize'][_0x6445('0x33')]['SELECT']}));}}}else{_0x1c720b['push'](dbH[_0x6445('0x30')][_0x6445('0x31')](QUERY,{'type':dbH[_0x6445('0x30')]['QueryTypes'][_0x6445('0x34')]}));}var _0x4759f6=path[_0x6445('0x35')](PATH);var _0x41b416=path['basename'](PATH,_0x6445('0x36'));var _0x4adf7a=_0x110422['split']&&_0x1c720b[_0x6445('0x15')]>0x1;var _0x432db8=[];if(!fs['existsSync'](path[_0x6445('0x37')](_0x4759f6,_0x41b416))&&_0x4adf7a){fs[_0x6445('0x38')](path[_0x6445('0x37')](_0x4759f6,_0x41b416));}return BPromise[_0x6445('0x39')](_0x1c720b,function(_0x12151a){_0x432db8['push'](_0x12151a);})[_0x6445('0x2e')](function(){var _0x343f01=[];for(var _0x79814d=0x0;_0x79814d<_0x432db8[_0x6445('0x15')];_0x79814d+=0x1){var _0x5a0f28=_0x432db8[_0x79814d];var _0x3e7bbf=createTables(_[_0x6445('0x3a')](_0x5a0f28));var _0x3bbbd0;var _0x40a2e5=getPDFDocDefinition(_0x3e7bbf);var _0x1ff6b1=getPDFPrinter();var _0x2f00f6=_0x1ff6b1['createPdfKitDocument'](_0x40a2e5);if(_0x4adf7a){_0x3bbbd0=path[_0x6445('0x37')](_0x4759f6,_0x41b416,util[_0x6445('0x1d')](_0x6445('0x3b'),_0x41b416,_0x79814d,_0x6445('0x3c')));}else{_0x3bbbd0=path['join'](_0x4759f6,util[_0x6445('0x1d')](_0x6445('0x3d'),_0x41b416,'pdf'));}_0x343f01['push'](writePDFDocument(_0x2f00f6,_0x3bbbd0));}return Promise[_0x6445('0x3e')](_0x343f01);})[_0x6445('0x2e')](function(){if(_0x4adf7a){return new Promise(function(_0x2d0057){zipdir(path['join'](_0x4759f6,_0x41b416),{'saveTo':path['join'](_0x4759f6,util[_0x6445('0x1d')](_0x6445('0x3d'),_0x41b416,_0x6445('0x3f')))},function(){rimraf(path[_0x6445('0x37')](_0x4759f6,_0x41b416),function(){});_0x2d0057(_0x6445('0x40'));});});}})[_0x6445('0x2e')](function(){if(!_0x4adf7a)return;rimraf(path[_0x6445('0x37')](_0x4759f6,_0x41b416),function(){});})['then'](function(){logger[_0x6445('0x41')](util[_0x6445('0x1d')](_0x6445('0x42'),EXTRACTED_REPORT_ID,_0x6445('0x43')));return analyticExtractedReport(_0x6445('0x44'),_0x4adf7a?util[_0x6445('0x1d')](_0x6445('0x3d'),_0x41b416,_0x4adf7a?_0x6445('0x3f'):'pdf'):null);});});}function main(){if(!EXTRACTED_REPORT_ID)return;logger[_0x6445('0x41')](util[_0x6445('0x1d')](_0x6445('0x45'),EXTRACTED_REPORT_ID,_0x6445('0x43')));return db[_0x6445('0xd')]['findOne']({'where':{'id':EXTRACTED_REPORT_ID}})[_0x6445('0x2e')](function(_0x19d6f0){EXTRACTED_REPORT=_0x19d6f0;return dbH[_0x6445('0x30')][_0x6445('0x31')](util[_0x6445('0x1d')](_0x6445('0x46'),QUERY),{'type':dbH['sequelize'][_0x6445('0x33')][_0x6445('0x34')]});})[_0x6445('0x2e')](extractReport)['catch'](function(_0x4c1164){logger[_0x6445('0x41')](util['format'](_0x6445('0x47'),EXTRACTED_REPORT_ID,'PDF'),util['inspect'](_0x4c1164,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0x6445('0x48'));})['finally'](function(){process[_0x6445('0x49')](EXIT_CODE);});}main();function getPDFPrinter(){var _0x3d75b0=new PdfPrinter({'Arial':{'normal':__dirname+_0x6445('0x4a'),'bold':__dirname+'/fonts/arial-bold.ttf','italics':__dirname+'/fonts/arial-italic.ttf','bolditalics':__dirname+_0x6445('0x4b')}});return _0x3d75b0;}function getPDFDocDefinitionFromHTML(_0x4e7dc4,_0x246d8a){var _0x2b900b=util[_0x6445('0x1d')](_0x6445('0x4c'),_0x246d8a['channel'],_0x246d8a[_0x6445('0x4d')]);var _0x681db=moment()[_0x6445('0x1d')](_0x6445('0x4e'))[_0x6445('0x12')]();var _0x1dc44b=htmlToPdfmake(_0x4e7dc4,{'window':window,'tableAutoSize':!![]});return{'content':[_0x1dc44b],'defaultStyle':{'font':_0x6445('0x4f')},'styles':{'header':{'fontSize':0x12,'bold':!![],'alignment':_0x6445('0x50'),'margin':[0xa,0xa,0xa,0xa]},'footer':{'fontSize':0x9,'alignment':_0x6445('0x50'),'margin':[0xa,0x14,0xa,0xa]},'textblock':{'fontSize':0xb},'textfield':{'bold':!![]},'messageContainer':{'fontSize':0xa},'messageInfo':{'bold':!![]},'interactionData':{'alignment':_0x6445('0x50')}},'header':function(){return[{'text':_0x6445('0x51'),'style':_0x6445('0x21')}];},'footer':function(_0xbf7f9f,_0x4d204a){return[{'text':util[_0x6445('0x1d')]('\x09\x09XCALLY\x20Motion\x20-\x20%s\x09\x09\x09\x09%d/%d\x09\x09\x09\x09%s',_0x2b900b,_0xbf7f9f,_0x4d204a,_0x681db),'style':'footer'}];}};}function writePDFDocument(_0x41e5f6,_0x33a518){return new Promise(function(_0x90e1ed,_0x1d8b00){var _0x3083c2=_0x41e5f6['pipe'](fs['createWriteStream'](_0x33a518));_0x3083c2['on'](_0x6445('0x52'),function(){_0x90e1ed(_0x6445('0x52'));});_0x3083c2['on'](_0x6445('0x53'),function(_0x19f436){_0x1d8b00(_0x19f436);});_0x41e5f6[_0x6445('0x54')]();});}exports[_0x6445('0x55')]=function(_0xbed42b,_0x321973){var _0xeb530=getPDFPrinter();var _0x3ac04a=getPDFDocDefinitionFromHTML(_0xbed42b,_0x321973);var _0x3cdbf7=_0xeb530[_0x6445('0x56')](_0x3ac04a);return writePDFDocument(_0x3cdbf7,_0x321973['path'])['catch'](function(_0x12dd09){throw _0x12dd09;});};