08135c33e7364eae32fc7c1a53634f0878508e41
[motion2.git] / server / api / saInvoiceDetail / saInvoiceDetail.controller.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 _0xbf40=['offset','Content-Range','apply','reject','save','update','then','destroy','stack','name','send','rawAttributes','model','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','limit','order','sort','where','filter','merge','map','key','VIRTUAL','SAInvoiceDetail','includeAll','findAll','show','params','include','options','find','catch','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','mustache','path','sox','to-csv','lodash','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','end','json','count'];(function(_0x10df99,_0x438044){var _0x5f0213=function(_0x2b1528){while(--_0x2b1528){_0x10df99['push'](_0x10df99['shift']());}};_0x5f0213(++_0x438044);}(_0xbf40,0x70));var _0x0bf4=function(_0x5834bc,_0x3d4801){_0x5834bc=_0x5834bc-0x0;var _0x3e183a=_0xbf40[_0x5834bc];return _0x3e183a;};'use strict';var pdf=require(_0x0bf4('0x0'));var emlformat=require(_0x0bf4('0x1'));var rimraf=require(_0x0bf4('0x2'));var zipdir=require(_0x0bf4('0x3'));var jsonpatch=require(_0x0bf4('0x4'));var rp=require(_0x0bf4('0x5'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x0bf4('0x6'));var util=require('util');var path=require(_0x0bf4('0x7'));var sox=require(_0x0bf4('0x8'));var csv=require(_0x0bf4('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x0bf4('0xa'));var squel=require('squel');var crypto=require(_0x0bf4('0xb'));var jsforce=require(_0x0bf4('0xc'));var deskjs=require(_0x0bf4('0xd'));var toCsv=require(_0x0bf4('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x0bf4('0xe'));var authService=require(_0x0bf4('0xf'));var qs=require(_0x0bf4('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x0bf4('0x11'))(_0x0bf4('0x12'));var utils=require('../../config/utils');var config=require(_0x0bf4('0x13'));var db=require(_0x0bf4('0x14'))['db'];function respondWithStatusCode(_0x31e62c,_0x48ef75){_0x48ef75=_0x48ef75||0xcc;return function(_0x48b43e){if(_0x48b43e){return _0x31e62c[_0x0bf4('0x15')](_0x48ef75);}return _0x31e62c[_0x0bf4('0x16')](_0x48ef75)[_0x0bf4('0x17')]();};}function respondWithResult(_0x45a413,_0x4aebdd){_0x4aebdd=_0x4aebdd||0xc8;return function(_0x408ada){if(_0x408ada){return _0x45a413[_0x0bf4('0x16')](_0x4aebdd)[_0x0bf4('0x18')](_0x408ada);}};}function respondWithFilteredResult(_0x5ebf5c,_0xb6dcc9){return function(_0x4443b8){if(_0x4443b8){var _0x1b5b8d=_0x4443b8[_0x0bf4('0x19')],_0x592fca=_0xb6dcc9[_0x0bf4('0x1a')],_0x1a88ee=_0xb6dcc9[_0x0bf4('0x1a')]+_0xb6dcc9['limit'],_0x53549a;if(_0x1a88ee>=_0x1b5b8d){_0x1a88ee=_0x1b5b8d;_0x53549a=0xc8;}else{_0x53549a=0xce;}_0x5ebf5c[_0x0bf4('0x16')](_0x53549a);return _0x5ebf5c['set'](_0x0bf4('0x1b'),_0x592fca+'-'+_0x1a88ee+'/'+_0x1b5b8d)[_0x0bf4('0x18')](_0x4443b8);}return null;};}function patchUpdates(_0x4fb23d){return function(_0x26eed0){try{jsonpatch[_0x0bf4('0x1c')](_0x26eed0,_0x4fb23d,!![]);}catch(_0x159ac0){return BPromise[_0x0bf4('0x1d')](_0x159ac0);}return _0x26eed0[_0x0bf4('0x1e')]();};}function saveUpdates(_0x1ae440,_0x5eb644){return function(_0x5607b2){if(_0x5607b2){return _0x5607b2[_0x0bf4('0x1f')](_0x1ae440)[_0x0bf4('0x20')](function(_0x3a8e86){return _0x3a8e86;});}return null;};}function removeEntity(_0x1498a2,_0x298140){return function(_0x1e5824){if(_0x1e5824){return _0x1e5824[_0x0bf4('0x21')]()[_0x0bf4('0x20')](function(){_0x1498a2[_0x0bf4('0x16')](0xcc)[_0x0bf4('0x17')]();});}};}function handleEntityNotFound(_0x3e1e81,_0x2c09d7){return function(_0x34330c){if(!_0x34330c){_0x3e1e81[_0x0bf4('0x15')](0x194);}return _0x34330c;};}function handleError(_0x5ab900,_0x228b15){_0x228b15=_0x228b15||0x1f4;return function(_0x140c11){logger['error'](_0x140c11[_0x0bf4('0x22')]);if(_0x140c11[_0x0bf4('0x23')]){delete _0x140c11[_0x0bf4('0x23')];}_0x5ab900[_0x0bf4('0x16')](_0x228b15)[_0x0bf4('0x24')](_0x140c11);};}exports['index']=function(_0x19d07e,_0x5bf261){var _0x4224db={},_0x4b631b={},_0x28af33={'count':0x0,'rows':[]};var _0x3dd107=db['SAInvoiceDetail'][_0x0bf4('0x25')];_0x4b631b[_0x0bf4('0x26')]=_[_0x0bf4('0x27')](_0x3dd107);_0x4b631b['query']=_[_0x0bf4('0x27')](_0x19d07e[_0x0bf4('0x28')]);_0x4b631b[_0x0bf4('0x29')]=_[_0x0bf4('0x2a')](_0x4b631b[_0x0bf4('0x26')],_0x4b631b['query']);_0x4224db['attributes']=_[_0x0bf4('0x2a')](_0x4b631b['model'],qs[_0x0bf4('0x2b')](_0x19d07e['query'][_0x0bf4('0x2b')]));_0x4224db['attributes']=_0x4224db[_0x0bf4('0x2c')][_0x0bf4('0x2d')]?_0x4224db[_0x0bf4('0x2c')]:_0x4b631b[_0x0bf4('0x26')];if(!_0x19d07e[_0x0bf4('0x28')][_0x0bf4('0x2e')](_0x0bf4('0x2f'))){_0x4224db[_0x0bf4('0x30')]=qs[_0x0bf4('0x30')](_0x19d07e[_0x0bf4('0x28')][_0x0bf4('0x30')]);_0x4224db[_0x0bf4('0x1a')]=qs[_0x0bf4('0x1a')](_0x19d07e[_0x0bf4('0x28')][_0x0bf4('0x1a')]);}_0x4224db[_0x0bf4('0x31')]=qs[_0x0bf4('0x32')](_0x19d07e[_0x0bf4('0x28')]['sort']);_0x4224db[_0x0bf4('0x33')]=qs[_0x0bf4('0x29')](_['pick'](_0x19d07e[_0x0bf4('0x28')],_0x4b631b[_0x0bf4('0x29')]));if(_0x19d07e[_0x0bf4('0x28')][_0x0bf4('0x34')]){_0x4224db[_0x0bf4('0x33')]=_[_0x0bf4('0x35')](_0x4224db['where'],{'$or':_[_0x0bf4('0x36')](_0x3dd107,function(_0x51aaa2){if(_0x51aaa2['type'][_0x0bf4('0x37')]!==_0x0bf4('0x38')){var _0x8424a7={};_0x8424a7[_0x51aaa2['field']]={'$like':'%'+_0x19d07e[_0x0bf4('0x28')][_0x0bf4('0x34')]+'%'};return _0x8424a7;}})});}_0x4224db=_['merge']({},_0x4224db,_0x19d07e['options']);var _0x9b48e8={'where':_0x4224db[_0x0bf4('0x33')]};return db[_0x0bf4('0x39')][_0x0bf4('0x19')](_0x9b48e8)['then'](function(_0x3385da){_0x28af33[_0x0bf4('0x19')]=_0x3385da;if(_0x19d07e[_0x0bf4('0x28')][_0x0bf4('0x3a')]){_0x4224db['include']=[{'all':!![]}];}return db['SAInvoiceDetail'][_0x0bf4('0x3b')](_0x4224db);})[_0x0bf4('0x20')](function(_0x436d1c){_0x28af33['rows']=_0x436d1c;return _0x28af33;})['then'](respondWithFilteredResult(_0x5bf261,_0x4224db))['catch'](handleError(_0x5bf261,null));};exports[_0x0bf4('0x3c')]=function(_0x5a4db0,_0x16fa38){var _0x10059d={'raw':![],'where':{'id':_0x5a4db0[_0x0bf4('0x3d')]['id']}},_0x47be51={};_0x47be51[_0x0bf4('0x26')]=_[_0x0bf4('0x27')](db[_0x0bf4('0x39')]['rawAttributes']);_0x47be51[_0x0bf4('0x28')]=_['keys'](_0x5a4db0[_0x0bf4('0x28')]);_0x47be51[_0x0bf4('0x29')]=_[_0x0bf4('0x2a')](_0x47be51[_0x0bf4('0x26')],_0x47be51[_0x0bf4('0x28')]);_0x10059d[_0x0bf4('0x2c')]=_[_0x0bf4('0x2a')](_0x47be51[_0x0bf4('0x26')],qs[_0x0bf4('0x2b')](_0x5a4db0[_0x0bf4('0x28')]['fields']));_0x10059d[_0x0bf4('0x2c')]=_0x10059d[_0x0bf4('0x2c')][_0x0bf4('0x2d')]?_0x10059d['attributes']:_0x47be51[_0x0bf4('0x26')];if(_0x5a4db0[_0x0bf4('0x28')][_0x0bf4('0x3a')]){_0x10059d[_0x0bf4('0x3e')]=[{'all':!![]}];}_0x10059d=_[_0x0bf4('0x35')]({},_0x10059d,_0x5a4db0[_0x0bf4('0x3f')]);return db[_0x0bf4('0x39')][_0x0bf4('0x40')](_0x10059d)[_0x0bf4('0x20')](handleEntityNotFound(_0x16fa38,null))['then'](respondWithResult(_0x16fa38,null))[_0x0bf4('0x41')](handleError(_0x16fa38,null));};exports[_0x0bf4('0x42')]=function(_0x358236,_0x106c88){return db['SAInvoiceDetail']['create'](_0x358236['body'],{})['then'](respondWithResult(_0x106c88,0xc9))[_0x0bf4('0x41')](handleError(_0x106c88,null));};exports[_0x0bf4('0x1f')]=function(_0x5366de,_0x5e4948){if(_0x5366de['body']['id']){delete _0x5366de[_0x0bf4('0x43')]['id'];}return db[_0x0bf4('0x39')][_0x0bf4('0x40')]({'where':{'id':_0x5366de[_0x0bf4('0x3d')]['id']}})[_0x0bf4('0x20')](handleEntityNotFound(_0x5e4948,null))[_0x0bf4('0x20')](saveUpdates(_0x5366de[_0x0bf4('0x43')],null))[_0x0bf4('0x20')](respondWithResult(_0x5e4948,null))[_0x0bf4('0x41')](handleError(_0x5e4948,null));};exports[_0x0bf4('0x21')]=function(_0x37c244,_0x464ddb){return db[_0x0bf4('0x39')][_0x0bf4('0x40')]({'where':{'id':_0x37c244[_0x0bf4('0x3d')]['id']}})[_0x0bf4('0x20')](handleEntityNotFound(_0x464ddb,null))[_0x0bf4('0x20')](removeEntity(_0x464ddb,null))[_0x0bf4('0x41')](handleError(_0x464ddb,null));};exports[_0x0bf4('0x44')]=function(_0x5b311a,_0xdbddea){return db[_0x0bf4('0x39')][_0x0bf4('0x44')]()[_0x0bf4('0x20')](respondWithResult(_0xdbddea,null))[_0x0bf4('0x41')](handleError(_0xdbddea,null));};