Built motion from commit (unavailable).|2.4.21
[motion2.git] / server / components / export / xlsx.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xf2f2=['push','QueryTypes','dirname','.xlsx','existsSync','join','mkdirSync','%s%d.%s','xlsx','%s.%s','writeFileSync','binary','zip','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','XLSX','Completed','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','inspect','Failed','util','path','json2xls','zip-dir','rimraf','../../mysqldb','../../config/logger','argv','savename','AnalyticExtractedReport','update','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Setting','find','then','splitSizeXlsx','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','SELECT','num','Empty','split','length'];(function(_0x1b59cd,_0x389255){var _0x442af8=function(_0x1e5e92){while(--_0x1e5e92){_0x1b59cd['push'](_0x1b59cd['shift']());}};_0x442af8(++_0x389255);}(_0xf2f2,0x70));var _0x2f2f=function(_0x30a528,_0x1d04f2){_0x30a528=_0x30a528-0x0;var _0x3e029c=_0xf2f2[_0x30a528];return _0x3e029c;};'use strict';var util=require(_0x2f2f('0x0'));var path=require(_0x2f2f('0x1'));var _=require('lodash');var fs=require('fs');var json2xls=require(_0x2f2f('0x2'));var BPromise=require('bluebird');var zipdir=require(_0x2f2f('0x3'));var rimraf=require(_0x2f2f('0x4'));var db=require(_0x2f2f('0x5'))['db'];var dbH=require('../../mysqldb')['dbH'];var logger=require(_0x2f2f('0x6'))('analytics');var EXTRACTED_REPORT_ID=Number(process['argv'][0x2]);var QUERY=process[_0x2f2f('0x7')][0x3];var PATH=process[_0x2f2f('0x7')][0x4];function analyticExtractedReport(_0x54f597,_0x3e19fe){var _0x6f4b73={'status':_0x54f597};var _0x501cf9={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x3e19fe){_0x6f4b73[_0x2f2f('0x8')]=_0x3e19fe;}return db[_0x2f2f('0x9')][_0x2f2f('0xa')](_0x6f4b73,_0x501cf9);}function main(){var _0x27d74e=0x1388;var _0x1fd87f;logger[_0x2f2f('0xb')](util[_0x2f2f('0xc')](_0x2f2f('0xd'),EXTRACTED_REPORT_ID,'XLSX'));return db[_0x2f2f('0xe')][_0x2f2f('0xf')]({'where':{'id':0x1},'raw':!![],'attributes':['id','split','splitSizeXlsx']})[_0x2f2f('0x10')](function(_0x456838){if(_0x456838){_0x1fd87f=_0x456838;_0x27d74e=_0x1fd87f[_0x2f2f('0x11')]||0x1388;}})['then'](function(){return dbH[_0x2f2f('0x12')][_0x2f2f('0x13')](util[_0x2f2f('0xc')](_0x2f2f('0x14'),QUERY),{'type':dbH['sequelize']['QueryTypes'][_0x2f2f('0x15')]});})[_0x2f2f('0x10')](function(_0x5738ad){if(!_0x5738ad[0x0][_0x2f2f('0x16')]){return analyticExtractedReport(_0x2f2f('0x17'));}var _0x446f4f=[];var _0x1fb28=0x0;var _0x238ef3=!![];if(_0x1fd87f[_0x2f2f('0x18')]){if(_0x5738ad&&_0x5738ad[_0x2f2f('0x19')]){var _0x193ebc=_0x5738ad[0x0][_0x2f2f('0x16')]%(_0x1fb28+_0x27d74e);for(;_0x238ef3;_0x1fb28+=_0x27d74e,_0x193ebc=_0x5738ad[0x0][_0x2f2f('0x16')]%(_0x1fb28+_0x27d74e)){if(_0x193ebc==0x0||_0x193ebc==_0x5738ad[0x0][_0x2f2f('0x16')]){_0x238ef3=![];}_0x446f4f[_0x2f2f('0x1a')](dbH[_0x2f2f('0x12')]['query'](util[_0x2f2f('0xc')]('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x27d74e,_0x1fb28),{'type':dbH[_0x2f2f('0x12')][_0x2f2f('0x1b')][_0x2f2f('0x15')]}));}}}else{_0x446f4f['push'](dbH['sequelize']['query'](QUERY,{'type':dbH[_0x2f2f('0x12')]['QueryTypes'][_0x2f2f('0x15')]}));}var _0x46766a=path[_0x2f2f('0x1c')](PATH);var _0x2ce31d=path['basename'](PATH,_0x2f2f('0x1d'));var _0xa38efb=_0x1fd87f['split']&&_0x446f4f[_0x2f2f('0x19')]>0x1;var _0x45ebe4=[];if(!fs[_0x2f2f('0x1e')](path[_0x2f2f('0x1f')](_0x46766a,_0x2ce31d))&&_0xa38efb){fs[_0x2f2f('0x20')](path[_0x2f2f('0x1f')](_0x46766a,_0x2ce31d));}return BPromise['each'](_0x446f4f,function(_0x42b9d1){_0x45ebe4[_0x2f2f('0x1a')](_0x42b9d1);})[_0x2f2f('0x10')](function(){for(var _0x44ba7c=0x0;_0x44ba7c<_0x45ebe4[_0x2f2f('0x19')];_0x44ba7c+=0x1){var _0x19aa3b;var _0x3a4366=_0x45ebe4[_0x44ba7c];if(_0xa38efb){_0x19aa3b=path[_0x2f2f('0x1f')](_0x46766a,_0x2ce31d,util[_0x2f2f('0xc')](_0x2f2f('0x21'),_0x2ce31d,_0x44ba7c,_0x2f2f('0x22')));}else{_0x19aa3b=path['join'](_0x46766a,util[_0x2f2f('0xc')](_0x2f2f('0x23'),_0x2ce31d,'xlsx'));}fs[_0x2f2f('0x24')](_0x19aa3b,json2xls(_0x3a4366),_0x2f2f('0x25'));}})['then'](function(){if(_0xa38efb){zipdir(path[_0x2f2f('0x1f')](_0x46766a,_0x2ce31d),{'saveTo':path[_0x2f2f('0x1f')](_0x46766a,util[_0x2f2f('0xc')](_0x2f2f('0x23'),_0x2ce31d,_0x2f2f('0x26')))},function(_0x4c7a9e,_0x13c7ab){});rimraf(path[_0x2f2f('0x1f')](_0x46766a,_0x2ce31d),function(){});}})[_0x2f2f('0x10')](function(){logger[_0x2f2f('0xb')](util['format'](_0x2f2f('0x27'),EXTRACTED_REPORT_ID,_0x2f2f('0x28')));return analyticExtractedReport(_0x2f2f('0x29'),_0xa38efb?util[_0x2f2f('0xc')]('%s.%s',_0x2ce31d,_0xa38efb?'zip':_0x2f2f('0x22')):null);});})[_0x2f2f('0x2a')](function(_0x3794ce){logger[_0x2f2f('0xb')](util[_0x2f2f('0xc')](_0x2f2f('0x2b'),EXTRACTED_REPORT_ID,_0x2f2f('0x28')),util[_0x2f2f('0x2c')](_0x3794ce,{'showHidden':![],'depth':null}));return analyticExtractedReport(_0x2f2f('0x2d'));});}main();