71a64cbf5dcd9dd62668bc1765720122f6e143f7
[motion2.git] / server / api / saInvoice / saInvoice.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 _0x8784=['nolimit','order','sort','pick','filter','where','merge','key','VIRTUAL','field','options','count','include','findAll','rows','catch','show','includeAll','find','sequelize','transaction','Sequelize','ISOLATION_LEVELS','SERIALIZABLE','create','body','params','describe','getInvoicePDF','unix','toString','root','server','tmp','join','images','logo-invoice.png','logos','paid-invoice.png','format','Invoice_%s-%s.pdf','invoice','SAInvoiceDetail','details','portrait','1cm','10mm','<span\x20style=\x22color:\x20#444;\x22>{{page}}</span>/<span>{{pages}}</span>','footer','contents','default','<div\x20class=\x22issuerFiledWeb\x22>','issuerWeb','mkdirSync','<html>','<head>\x20<style\x20type=\x22text/css\x22>\x20body{font-family:\x20Verdana,\x20Geneva,\x20Tahoma,\x20sans-serif;}.itemTabTitle{background-color:\x20lightgray;\x20height:\x2040px;}.issuerInfo{color:\x20lightgray;\x20padding-top:\x2020px;\x20padding-bottom:\x2020px;\x20font-size:\x2012px;}.issuerData{font-weight:\x20normal}.issuerFiled{font-weight:\x20bold;\x20font-size:\x2010px;\x20padding-left:\x2010px;}.issuerFiledWeb{font-weight:\x20bold;\x20text-align:\x20center;}.receiperInfo{text-align:\x20right;\x20font-size:\x2012px}.receiperCompanyName{font-weight:\x20bold;\x20padding-top:\x2010px;\x20padding-bottom:\x2015px;\x20font-size:\x2016px}.reciperFiscalInfo{padding-top:\x205px;\x20padding-bottom:\x205px;}table.center{margin-left:\x20auto;\x20margin-right:\x20auto;\x20width:\x2090%;}.total{background-color:\x20lightgray;\x20font-size:\x2018px;\x20font-weight:\x20bold;}.totalText{background-color:\x20lightgray;\x20text-align:\x20right;\x20font-size:\x2016px;\x20padding-right:\x2010px;}.totalEmpty{background-color:\x20#ffffff;}.invoiceNumber{font-weight:\x20bolder;\x20font-size:\x2024px;\x20padding-bottom:\x2020px;}.invoiceNumber{font-weight:\x20bold;\x20font-size:\x2018px;}.createdDate{font-size:\x2014px;\x20padding-top:\x2020px;\x20padding-bottom:\x2020px;}.duedDate{font-size:\x2014px;\x20padding-bottom:\x2010px;}.TFtable{width:\x20100%;\x20font-size:\x2010px;\x20border-collapse:\x20collapse;}.TFtable\x20td{padding:\x207px;}.TFtable\x20tr:nth-child(even){background:\x20#ffffff;}.TFtable\x20tr:nth-child(odd){background:\x20rgb(237,\x20232,\x20232);}.numberRight{text-align:\x20right;}.numberCenter{text-align:\x20center}.currency{text-align:\x20left;}table.roundedCorners{border:\x202px\x20solid\x20lightgray;\x20border-radius:\x205px;\x20border-spacing:\x200;\x20width:\x20100%;\x20font-size:\x2010px;}table.roundedCorners\x20td,\x20table.roundedCorners\x20th{border-bottom:\x201px\x20solid\x20lightgray;\x20padding:\x2010px;}table.roundedCorners\x20tr:last-child\x20>\x20td{border-bottom:\x20none;}table.roundedCorners\x20tr:nth-child(even){background:\x20#ffffff;}table.roundedCorners\x20tr:nth-child(odd){background:\x20rgb(237,\x20232,\x20232);}.lex{padding-left:\x2010px;font-size:\x2010px;padding-bottom:\x2020px;}.divTotal{float:\x20right;\x20border-radius:\x205px;\x20border:\x202px\x20solid\x20lightgray;\x20padding:\x2010px;\x20margin-top:30px;}.itemTotal{width:\x20200px;\x20line-height:\x2030px;}.tabTotal{border-collapse:\x20collapse;}</style></head>','<body>','Phone','Telefono','Fax','Email','VAT\x20number','P.IVA','Tax\x20code','C.F.','I.S.\x20code','Soc.Cap.\x20fp','Cap.Soc.\x20iv','Fattura','Proforma','Scadenza','Item','Hrs/Qty','Ore/Qta','Sub\x20Total','Sub\x20Totale','Discount','Subtotal','Tax','Tasse','Total','Totale','Si\x20prega\x20di\x20inviare\x20il\x20pagamento\x20a','Account\x20Holder','Conto\x20intestato\x20a','Bank\x20name','Bank\x20Address','Indirizzo\x20banca','CAB','SWIF','IBAN','Pay\x20via\x20Paypal','Thank\x20you\x20for\x20your\x20business.\x20We\x20do\x20expect\x20payment\x20by\x20','Grazie.\x20Prevediamo\x20il\x20pagamento\x20entro\x20',',\x20so\x20please\x20do\x20so\x20within\x20this\x20time.','receivingCountry','<table\x20class=\x22center\x22>','<tr>\x20<td\x20colspan=\x223\x22><img\x20src=\x22file://','\x22\x20width=\x22180\x22></td></tr>','<tr>','issuerName','issuerStreet','issuerPostalCode','\x20%s','issuerCity','issuerCountry','phone',':\x20%s<br/>','issuerPhone','fax','issuerFax','email','issuerPIVA','issuerFiscalCode','sdi','issuerSocCap','</td>','<td></td>','companyName','%s<br/>','receivingStreet','%s\x20-\x20','receivingPostalCode','receivingCity','<div\x20class=\x22reciperFiscalInfo\x22>','piva','receivingSDICode','</div></td>','</tr>','<td\x20colspan=\x223\x22>','<div\x20class=\x22invoiceNumber\x22>','startDate','DD/MM/YYYY','saExpiryDay','days','endDate','<div\x20class=\x22duedDate\x22>','duedate',':\x20%s</div></td>','<table\x20class=\x22roundedCorners\x22>','<th\x20class=\x22itemTabTitle\x22>','item','description','</th>','hrsqty','unitprice','subtotal','netPrice','discount','tax','quantity','productName','<td>%s</td>','productDescription','<td\x20class=\x22numberCenter\x22>%d</td>','&euro;</td>','<td\x20class=\x22numberRight\x22>','toFixed','</tr></table><div\x20class=\x22divTotal\x22><table\x20class=\x22tabTotal\x22>','indexOf','split\x20payment','isNil','<td\x20>','<td\x20class=\x22numberRight\x22>\x20','<td\x20class=\x22itemTotal\x22>','<td\x20class=\x22total\x22>','nettopay','</td><td\x20class=\x22total\x20numberRight\x22>','</table></div><table>','<td\x20class=\x22lex\x22\x20colspan=\x222\x22>\x20%s\x20</td>','replace','fromCharCode','<br\x20/>','<div\x20class=\x22issuerFiled\x22>',':</div>','issuerBankAccount','accountholder',':\x20<span\x20class=\x22issuerData\x22>','</span></div>','bankname','issuerBankName','</span>\x20</div>','bankaddress','issuerBankStreet','issuerBankCountry','abi','cab','issuerCAB','bic','swif','issuerBankBICSWIFT','iban','thank1','<span>','</span>','thank2','paid','</table>','</html>','log','download','err','foldername','years','from','sa_invoices','count(id)','invoiceNumber','YEAR(startDate)','invoiceYear','invoiceMonth','MONTH(startDate)','group','QueryTypes','SELECT','getInvoicesRevenueBy','select','sa_invoice_details','(startDate)','month','monthTotal','sai','sai.id\x20=\x20said.InvoiceId','YEAR(startDate)\x20IN\x20(','getYearToCompare','distinct\x20YEAR(startDate)','year','YEAR(startDate)\x20!=\x20YEAR(CURDATE())','getTopClients','dateStart','top','area','relationship','relatedCompany','italy','sai.receivingCountry\x20=\x20\x22italy\x22','sai.receivingEurope\x20=\x201','com.CmCompanyId\x20=\x20','said','sai.companyName','sai.receivingCountry','nation','sum(((said.netPrice\x20-\x20(said.netPrice\x20/\x20100\x20*\x20said.discount))\x20*\x20said.quantity))\x20-\x20coalesce(sai.discount,0)','total','com.saCompanyRelationship','com.CmCompanyId','relCom.name','companyRelatedName','com','left_join','sa_company_relationships','rel','rel.Id\x20=\x20saCompanyRelationship','cm_companies','sai.startDate\x20>=\x20?','sai.startDate\x20<=\x20?','rel.name','said.discount','sai.discount','query.toString()','addInvoiceCreditnoteDetail->>','companyId','productCode','typeName','pricelistName','note','subscriptionId','subscriptionName','subscriptionMonthly','SACreditNoteDetail','automaticInvoiceCreditnote','SACreditNote','all','WARNING','No\x20product\x20to\x20assign\x20credit\x20note.\x20Credit\x20note\x20not\x20created!!\x20','SequelizeUniqueConstraintError','Duplicate\x20entry.','send','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../config/logger','../../config/utils','../../config/environment','sendStatus','status','end','json','offset','limit','Content-Range','reject','save','update','then','destroy','error','stack','name','index','SAInvoice','rawAttributes','model','keys','query','filters','attributes','intersection','fields','length','hasOwnProperty'];(function(_0x5e643d,_0x59d758){var _0x163a39=function(_0x359b8c){while(--_0x359b8c){_0x5e643d['push'](_0x5e643d['shift']());}};_0x163a39(++_0x59d758);}(_0x8784,0x116));var _0x4878=function(_0x5756f8,_0x22b6d5){_0x5756f8=_0x5756f8-0x0;var _0x3bb749=_0x8784[_0x5756f8];return _0x3bb749;};'use strict';var pdf=require(_0x4878('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x4878('0x1'));var zipdir=require(_0x4878('0x2'));var jsonpatch=require(_0x4878('0x3'));var rp=require(_0x4878('0x4'));var moment=require('moment');var BPromise=require(_0x4878('0x5'));var Mustache=require(_0x4878('0x6'));var util=require(_0x4878('0x7'));var path=require(_0x4878('0x8'));var sox=require('sox');var csv=require(_0x4878('0x9'));var ejs=require(_0x4878('0xa'));var fs=require('fs');var _=require(_0x4878('0xb'));var squel=require('squel');var crypto=require(_0x4878('0xc'));var jsforce=require(_0x4878('0xd'));var deskjs=require(_0x4878('0xe'));var toCsv=require(_0x4878('0x9'));var querystring=require(_0x4878('0xf'));var Papa=require(_0x4878('0x10'));var Redis=require(_0x4878('0x11'));var authService=require(_0x4878('0x12'));var qs=require('../../components/parsers/qs');var hardwareService=require('../../config/license/hardware');var logger=require(_0x4878('0x13'))('api');var utils=require(_0x4878('0x14'));var config=require(_0x4878('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x46dc9f,_0x482c1f){_0x482c1f=_0x482c1f||0xcc;return function(_0x2920e1){if(_0x2920e1){return _0x46dc9f[_0x4878('0x16')](_0x482c1f);}return _0x46dc9f[_0x4878('0x17')](_0x482c1f)[_0x4878('0x18')]();};}function respondWithResult(_0x143f00,_0x5643e5){_0x5643e5=_0x5643e5||0xc8;return function(_0x405fc3){if(_0x405fc3){return _0x143f00['status'](_0x5643e5)[_0x4878('0x19')](_0x405fc3);}};}function respondWithFilteredResult(_0x5c303c,_0x45740b){return function(_0x31b055){if(_0x31b055){var _0x32c32f=_0x31b055['count'],_0x25c414=_0x45740b['offset'],_0x56f3f1=_0x45740b[_0x4878('0x1a')]+_0x45740b[_0x4878('0x1b')],_0x5f00ee;if(_0x56f3f1>=_0x32c32f){_0x56f3f1=_0x32c32f;_0x5f00ee=0xc8;}else{_0x5f00ee=0xce;}_0x5c303c[_0x4878('0x17')](_0x5f00ee);return _0x5c303c['set'](_0x4878('0x1c'),_0x25c414+'-'+_0x56f3f1+'/'+_0x32c32f)['json'](_0x31b055);}return null;};}function patchUpdates(_0x17f41f){return function(_0x30b3c7){try{jsonpatch['apply'](_0x30b3c7,_0x17f41f,!![]);}catch(_0x4954d2){return BPromise[_0x4878('0x1d')](_0x4954d2);}return _0x30b3c7[_0x4878('0x1e')]();};}function saveUpdates(_0x4224a8,_0x239f67){return function(_0x3f91e6){if(_0x3f91e6){return _0x3f91e6[_0x4878('0x1f')](_0x4224a8)[_0x4878('0x20')](function(_0x24bcbc){return _0x24bcbc;});}return null;};}function removeEntity(_0x2cfed4,_0x51093f){return function(_0x4536b9){if(_0x4536b9){return _0x4536b9[_0x4878('0x21')]()[_0x4878('0x20')](function(){_0x2cfed4[_0x4878('0x17')](0xcc)[_0x4878('0x18')]();});}};}function handleEntityNotFound(_0x221ca0,_0x7e4f91){return function(_0x188f78){if(!_0x188f78){_0x221ca0['sendStatus'](0x194);}return _0x188f78;};}function handleError(_0x4e6000,_0x41f118){_0x41f118=_0x41f118||0x1f4;return function(_0x371cb1){logger[_0x4878('0x22')](_0x371cb1[_0x4878('0x23')]);if(_0x371cb1[_0x4878('0x24')]){delete _0x371cb1[_0x4878('0x24')];}_0x4e6000[_0x4878('0x17')](_0x41f118)['send'](_0x371cb1);};}exports[_0x4878('0x25')]=function(_0x43914a,_0x5dbec9){var _0x57bb1f={},_0x5650ec={},_0x5ba1b1={'count':0x0,'rows':[]};var _0x4a0d22=db[_0x4878('0x26')][_0x4878('0x27')];_0x5650ec[_0x4878('0x28')]=_[_0x4878('0x29')](_0x4a0d22);_0x5650ec[_0x4878('0x2a')]=_['keys'](_0x43914a[_0x4878('0x2a')]);_0x5650ec[_0x4878('0x2b')]=_['intersection'](_0x5650ec['model'],_0x5650ec[_0x4878('0x2a')]);_0x57bb1f[_0x4878('0x2c')]=_[_0x4878('0x2d')](_0x5650ec['model'],qs['fields'](_0x43914a[_0x4878('0x2a')][_0x4878('0x2e')]));_0x57bb1f['attributes']=_0x57bb1f[_0x4878('0x2c')][_0x4878('0x2f')]?_0x57bb1f[_0x4878('0x2c')]:_0x5650ec[_0x4878('0x28')];if(!_0x43914a['query'][_0x4878('0x30')](_0x4878('0x31'))){_0x57bb1f['limit']=qs[_0x4878('0x1b')](_0x43914a[_0x4878('0x2a')]['limit']);_0x57bb1f[_0x4878('0x1a')]=qs[_0x4878('0x1a')](_0x43914a['query'][_0x4878('0x1a')]);}_0x57bb1f[_0x4878('0x32')]=qs[_0x4878('0x33')](_0x43914a['query'][_0x4878('0x33')]);_0x57bb1f['where']=qs[_0x4878('0x2b')](_[_0x4878('0x34')](_0x43914a[_0x4878('0x2a')],_0x5650ec[_0x4878('0x2b')]));if(_0x43914a['query'][_0x4878('0x35')]){_0x57bb1f[_0x4878('0x36')]=_[_0x4878('0x37')](_0x57bb1f[_0x4878('0x36')],{'$or':_['map'](_0x4a0d22,function(_0x385f95){if(_0x385f95['type'][_0x4878('0x38')]!==_0x4878('0x39')){var _0x518c54={};_0x518c54[_0x385f95[_0x4878('0x3a')]]={'$like':'%'+_0x43914a[_0x4878('0x2a')][_0x4878('0x35')]+'%'};return _0x518c54;}})});}_0x57bb1f=_[_0x4878('0x37')]({},_0x57bb1f,_0x43914a[_0x4878('0x3b')]);var _0x1f8efb={'where':_0x57bb1f[_0x4878('0x36')]};return db[_0x4878('0x26')][_0x4878('0x3c')](_0x1f8efb)['then'](function(_0x56898e){_0x5ba1b1[_0x4878('0x3c')]=_0x56898e;if(_0x43914a[_0x4878('0x2a')]['includeAll']){_0x57bb1f[_0x4878('0x3d')]=[{'all':!![]}];}return db[_0x4878('0x26')][_0x4878('0x3e')](_0x57bb1f);})['then'](function(_0x2969d3){_0x5ba1b1[_0x4878('0x3f')]=_0x2969d3;return _0x5ba1b1;})[_0x4878('0x20')](respondWithFilteredResult(_0x5dbec9,_0x57bb1f))[_0x4878('0x40')](handleError(_0x5dbec9,null));};exports[_0x4878('0x41')]=function(_0x17353c,_0x545ab3){var _0x4c9aaf={'raw':![],'where':{'id':_0x17353c['params']['id']}},_0x50f995={};_0x50f995[_0x4878('0x28')]=_[_0x4878('0x29')](db[_0x4878('0x26')][_0x4878('0x27')]);_0x50f995[_0x4878('0x2a')]=_[_0x4878('0x29')](_0x17353c[_0x4878('0x2a')]);_0x50f995[_0x4878('0x2b')]=_[_0x4878('0x2d')](_0x50f995[_0x4878('0x28')],_0x50f995[_0x4878('0x2a')]);_0x4c9aaf[_0x4878('0x2c')]=_[_0x4878('0x2d')](_0x50f995[_0x4878('0x28')],qs[_0x4878('0x2e')](_0x17353c[_0x4878('0x2a')][_0x4878('0x2e')]));_0x4c9aaf[_0x4878('0x2c')]=_0x4c9aaf[_0x4878('0x2c')][_0x4878('0x2f')]?_0x4c9aaf['attributes']:_0x50f995[_0x4878('0x28')];if(_0x17353c[_0x4878('0x2a')][_0x4878('0x42')]){_0x4c9aaf[_0x4878('0x3d')]=[{'all':!![]}];}_0x4c9aaf=_[_0x4878('0x37')]({},_0x4c9aaf,_0x17353c[_0x4878('0x3b')]);return db['SAInvoice'][_0x4878('0x43')](_0x4c9aaf)[_0x4878('0x20')](handleEntityNotFound(_0x545ab3,null))[_0x4878('0x20')](respondWithResult(_0x545ab3,null))[_0x4878('0x40')](handleError(_0x545ab3,null));};exports['create']=function(_0x1b5c79,_0x4cc273){return db[_0x4878('0x44')][_0x4878('0x45')]({'isolationLevel':db[_0x4878('0x46')]['Transaction'][_0x4878('0x47')][_0x4878('0x48')]},function(_0x4f8ad7){return db[_0x4878('0x26')][_0x4878('0x49')](_0x1b5c79[_0x4878('0x4a')],{'transaction':_0x4f8ad7});})[_0x4878('0x20')](respondWithResult(_0x4cc273,0xc9))['catch'](handleError(_0x4cc273,null));};exports[_0x4878('0x1f')]=function(_0x405134,_0x463213){if(_0x405134[_0x4878('0x4a')]['id']){delete _0x405134[_0x4878('0x4a')]['id'];}return db[_0x4878('0x26')][_0x4878('0x43')]({'where':{'id':_0x405134[_0x4878('0x4b')]['id']}})['then'](handleEntityNotFound(_0x463213,null))[_0x4878('0x20')](saveUpdates(_0x405134[_0x4878('0x4a')],null))[_0x4878('0x20')](respondWithResult(_0x463213,null))['catch'](handleError(_0x463213,null));};exports[_0x4878('0x21')]=function(_0x35676a,_0x3fa05e){return db['SAInvoice'][_0x4878('0x43')]({'where':{'id':_0x35676a[_0x4878('0x4b')]['id']}})['then'](handleEntityNotFound(_0x3fa05e,null))[_0x4878('0x20')](removeEntity(_0x3fa05e,null))[_0x4878('0x40')](handleError(_0x3fa05e,null));};exports['describe']=function(_0xe02ff,_0xad338c){return db[_0x4878('0x26')][_0x4878('0x4c')]()[_0x4878('0x20')](respondWithResult(_0xad338c,null))['catch'](handleError(_0xad338c,null));};exports[_0x4878('0x4d')]=function(_0xefd6d0,_0x38987e){var _0x5c4d20=moment()[_0x4878('0x4e')]()[_0x4878('0x4f')]();var _0x5c47f2=path['join'](config[_0x4878('0x50')],_0x4878('0x51'),'files',_0x4878('0x52'));var _0x27be8a=path[_0x4878('0x53')](config[_0x4878('0x50')],_0x4878('0x51'),'files',_0x4878('0x54'),'logos',_0x4878('0x55'));var _0x288129=path[_0x4878('0x53')](config[_0x4878('0x50')],'server','files',_0x4878('0x54'),_0x4878('0x56'),_0x4878('0x57'));var _0x17c326=path[_0x4878('0x53')](_0x5c47f2,_0x5c4d20);var _0x5ce4ab=util[_0x4878('0x58')](_0x4878('0x59'),_0xefd6d0['params']['id'],_0x5c4d20);var _0x4e57fc=path[_0x4878('0x53')](_0x17c326,_0x5ce4ab);var _0x457afc=![];var _0x2bfa2c={};return db['SAInvoice'][_0x4878('0x43')]({'where':{'id':_0xefd6d0[_0x4878('0x4b')]['id']},'raw':!![]})[_0x4878('0x20')](handleEntityNotFound(_0x38987e,null))[_0x4878('0x20')](function(_0x2100b5){if(_0x2100b5){_0x2bfa2c[_0x4878('0x5a')]=_0x2100b5;return db[_0x4878('0x5b')][_0x4878('0x3e')]({'where':{'InvoiceId':_0x2100b5['id']},'raw':!![]})['then'](function(_0x2de893){_0x2bfa2c[_0x4878('0x5c')]=_0x2de893;_0x457afc=!![];var _0xa96611='';var _0x16d290={'format':'A4','orientation':_0x4878('0x5d'),'border':_0x4878('0x5e'),'footer':{'height':_0x4878('0x5f'),'contents':{'default':_0x4878('0x60')}}};_0x16d290[_0x4878('0x61')][_0x4878('0x62')][_0x4878('0x63')]=_0x16d290[_0x4878('0x61')][_0x4878('0x62')]['default']+_0x4878('0x64')+_0x2bfa2c['invoice'][_0x4878('0x65')]+'</div>';fs[_0x4878('0x66')](_0x17c326);_0xa96611=_0x4878('0x67');_0xa96611+=_0x4878('0x68');_0xa96611+=_0x4878('0x69');var _0x382679={'phone':{'en':_0x4878('0x6a'),'it':_0x4878('0x6b')},'fax':{'en':_0x4878('0x6c'),'it':_0x4878('0x6c')},'email':{'en':_0x4878('0x6d'),'it':_0x4878('0x6d')},'piva':{'en':_0x4878('0x6e'),'it':_0x4878('0x6f')},'cf':{'en':_0x4878('0x70'),'it':_0x4878('0x71')},'sdi':{'en':_0x4878('0x72'),'it':'Codice\x20S.D.I.'},'cs':{'en':_0x4878('0x73'),'it':_0x4878('0x74')},'invoice':{'en':'Invoice','it':_0x4878('0x75')},'proforma':{'en':'Proforma','it':_0x4878('0x76')},'creditnote':{'en':'Credit\x20note','it':'Nota\x20di\x20credito'},'duedate':{'en':'Due\x20date','it':_0x4878('0x77')},'item':{'en':_0x4878('0x78'),'it':'Articolo'},'description':{'en':'Description','it':'Descrizione'},'hrsqty':{'en':_0x4878('0x79'),'it':_0x4878('0x7a')},'unitprice':{'en':'Unit\x20Price','it':'Prezzo\x20Unitario'},'subtotal':{'en':_0x4878('0x7b'),'it':_0x4878('0x7c')},'discount':{'en':_0x4878('0x7d'),'it':'Sconto'},'total':{'en':_0x4878('0x7e'),'it':'Imponibile'},'tax':{'en':_0x4878('0x7f'),'it':_0x4878('0x80')},'nettopay':{'en':_0x4878('0x81'),'it':_0x4878('0x82')},'sendpayment':{'en':'Please\x20send\x20PAYMENT\x20to','it':_0x4878('0x83')},'accountholder':{'en':_0x4878('0x84'),'it':_0x4878('0x85')},'bankname':{'en':_0x4878('0x86'),'it':'Nome\x20banca'},'bankaddress':{'en':_0x4878('0x87'),'it':_0x4878('0x88')},'abi':{'en':'ABI','it':'ABI'},'cab':{'en':_0x4878('0x89'),'it':_0x4878('0x89')},'bic':{'en':'BIC','it':'BIC'},'swif':{'en':_0x4878('0x8a'),'it':'SWIF'},'iban':{'en':_0x4878('0x8b'),'it':_0x4878('0x8b')},'paypal':{'en':_0x4878('0x8c'),'it':'Paga\x20con\x20Paypal'},'thank1':{'en':_0x4878('0x8d'),'it':_0x4878('0x8e')},'thank2':{'en':_0x4878('0x8f'),'it':'\x20quindi\x20vi\x20preghiamo\x20di\x20provvedere\x20entro\x20tale\x20termine.'}};var _0x1d4e34='it';if(_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x90')]!=='Italy'){_0x1d4e34='en';}_0xa96611+=_0x4878('0x91');_0xa96611+=_0x4878('0x92')+_0x27be8a+_0x4878('0x93');_0xa96611+=_0x4878('0x94');_0xa96611+=util[_0x4878('0x58')]('<td\x20class=\x22issuerInfo\x22>\x20%s<br/>',_0x2bfa2c['invoice'][_0x4878('0x95')]);_0xa96611+=util['format']('%s<br/>',_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x96')]);_0xa96611+=util[_0x4878('0x58')]('%s',_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x97')]);_0xa96611+=util[_0x4878('0x58')](_0x4878('0x98'),_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x99')]);_0xa96611+=util[_0x4878('0x58')]('-\x20%s\x20<br/>',_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x9a')]);_0xa96611+=util['format'](_0x382679[_0x4878('0x9b')][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x9d')]);_0xa96611+=util[_0x4878('0x58')](_0x382679[_0x4878('0x9e')][_0x1d4e34]+':\x20%s<br/>',_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x9f')]);_0xa96611+=util['format'](_0x382679[_0x4878('0xa0')][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c['invoice']['issuerEmail']);_0xa96611+=util[_0x4878('0x58')](_0x382679['piva'][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xa1')]);_0xa96611+=util[_0x4878('0x58')](_0x382679['cf'][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c['invoice'][_0x4878('0xa2')]);_0xa96611+=util[_0x4878('0x58')](_0x382679[_0x4878('0xa3')][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c[_0x4878('0x5a')]['issuerSDICode']);_0xa96611+=util[_0x4878('0x58')](_0x382679['cs'][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xa4')]);_0xa96611+=_0x4878('0xa5');_0xa96611+=_0x4878('0xa6');_0xa96611+='<td\x20class=\x22receiperInfo\x22>';_0xa96611+=util[_0x4878('0x58')]('<div\x20class=\x22receiperCompanyName\x22>%s</div>',_0x2bfa2c['invoice'][_0x4878('0xa7')]);_0xa96611+=util[_0x4878('0x58')](_0x4878('0xa8'),_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xa9')]);_0xa96611+=util[_0x4878('0x58')](_0x4878('0xaa'),_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xab')]);_0xa96611+=util[_0x4878('0x58')](_0x4878('0xa8'),_0x2bfa2c['invoice'][_0x4878('0xac')]);_0xa96611+=util['format'](_0x4878('0xa8'),_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x90')]);_0xa96611+=_0x4878('0xad');if(_0x2bfa2c[_0x4878('0x5a')]['receivingFiscalCode']){_0xa96611+=util[_0x4878('0x58')](_0x382679['cf'][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c['invoice']['receivingFiscalCode']);}_0xa96611+=util[_0x4878('0x58')](_0x382679[_0x4878('0xae')][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c[_0x4878('0x5a')]['receivingPIVA']);if(_0x2bfa2c['invoice'][_0x4878('0xaf')]){_0xa96611+=util[_0x4878('0x58')](_0x382679[_0x4878('0xa3')][_0x1d4e34]+_0x4878('0x9c'),_0x2bfa2c['invoice']['receivingSDICode']);}_0xa96611+=_0x4878('0xb0');_0xa96611+=_0x4878('0xb1');_0xa96611+=_0x4878('0x94');_0xa96611+=_0x4878('0xb2');_0xa96611+=util['format'](_0x4878('0xb3')+_0x382679[_0x4878('0x5a')][_0x1d4e34]+'\x20N.%d</div>',_0x2100b5['number']);_0xa96611+=util[_0x4878('0x58')]('<div\x20class=\x22createdDate\x22>%s,\x20',_0x2bfa2c[_0x4878('0x5a')][_0x4878('0x99')]);var _0x48580b=moment(_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xb4')])[_0x4878('0x58')](_0x4878('0xb5'));_0xa96611+=util[_0x4878('0x58')]('%s\x20</div>',_0x48580b);var _0x153c5c=moment(_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xb4')])['add'](_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xb6')],_0x4878('0xb7'))['format']('DD/MM/YYYY');if(_0x2bfa2c['invoice'][_0x4878('0xb8')]){_0x153c5c=moment(_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xb8')])[_0x4878('0x58')](_0x4878('0xb5'));}_0xa96611+=util['format'](_0x4878('0xb9')+_0x382679[_0x4878('0xba')][_0x1d4e34]+_0x4878('0xbb'),_0x153c5c);_0xa96611+=_0x4878('0xb1');_0xa96611+=_0x4878('0x94');_0xa96611+=_0x4878('0xb2');_0xa96611+=_0x4878('0xbc');_0xa96611+=_0x4878('0x94');_0xa96611+=_0x4878('0xbd')+_0x382679[_0x4878('0xbe')][_0x1d4e34]+'</th>';_0xa96611+='<th\x20class=\x22itemTabTitle\x22>'+_0x382679[_0x4878('0xbf')][_0x1d4e34]+_0x4878('0xc0');_0xa96611+=_0x4878('0xbd')+_0x382679[_0x4878('0xc1')][_0x1d4e34]+'</th>';_0xa96611+=_0x4878('0xbd')+_0x382679[_0x4878('0xc2')][_0x1d4e34]+'</th>';_0xa96611+=_0x4878('0xbd')+_0x382679[_0x4878('0xc3')][_0x1d4e34]+_0x4878('0xc0');_0xa96611+=_0x4878('0xb1');var _0x136b51=0x0;var _0xdbf985=0x0;for(var _0x4a64fa=0x0;_0x4a64fa<_0x2bfa2c[_0x4878('0x5c')][_0x4878('0x2f')];_0x4a64fa++){var _0x450c48=0x0;var _0x5bc089=0x0;var _0x291d16=0x0;var _0xf675f4=0x0;_0x450c48=_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc4')]-_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc4')]/0x64*_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc5')];_0x5bc089=_0x450c48/0x64*_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc6')];_0x291d16=_0x450c48*_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc7')];_0xf675f4=_0x5bc089*_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc7')];_0xa96611+=_0x4878('0x94');_0xa96611+=util['format']('<td>%s</td>',_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc8')]);_0xa96611+=util['format'](_0x4878('0xc9'),_0x2bfa2c['details'][_0x4a64fa][_0x4878('0xca')]);_0xa96611+=util['format'](_0x4878('0xcb'),_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc7')]);_0xa96611+='<td\x20class=\x22numberRight\x22>'+_0x450c48['toFixed'](0x2)+_0x4878('0xcc');_0xa96611+=_0x4878('0xcd')+_0x291d16[_0x4878('0xce')](0x2)+_0x4878('0xcc');_0xa96611+=_0x4878('0xb1');_0x136b51+=_0x291d16;_0xdbf985+=_0xf675f4;}_0xa96611+=_0x4878('0xcf');if(!_['isNil'](_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xc5')])){var _0x24a8e8=0x0;var _0x503b6c=0x0;var _0x343678=_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xc5')]*0x64/_0x136b51;for(var _0x4a64fa=0x0;_0x4a64fa<_0x2bfa2c[_0x4878('0x5c')][_0x4878('0x2f')];_0x4a64fa++){var _0x154b74=0x0;var _0x27b426=0x0;var _0x10146f=0x0;_0x450c48=_0x2bfa2c['details'][_0x4a64fa][_0x4878('0xc4')]-_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc4')]/0x64*_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc5')];_0x154b74=_0x450c48/0x64*_0x343678;_0x27b426=_0x450c48-_0x154b74;_0x10146f=_0x27b426*_0x2bfa2c[_0x4878('0x5c')][_0x4a64fa][_0x4878('0xc7')];_0x24a8e8+=_0x10146f;_0x503b6c+=_0x10146f/0x64*_0x2bfa2c['details'][_0x4a64fa][_0x4878('0xc6')];}}var _0x2458e3=0x0;var _0x5a43f8=0x0;var _0x1b40f3=![];var _0x5ab37f=_0x2bfa2c[_0x4878('0x5a')]['receivingFiscalMessage'];if(_0x5ab37f[_0x4878('0xd0')](_0x4878('0xd1'))!=-0x1){_0x1b40f3=!![];}if(!_[_0x4878('0xd2')](_0x2bfa2c[_0x4878('0x5a')]['discount'])){_0xa96611+=_0x4878('0x94');if(_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xc5')]>0x0){_0xa96611+=_0x4878('0xd3')+_0x382679[_0x4878('0xc5')][_0x1d4e34]+_0x4878('0xa5');_0xa96611+=_0x4878('0xd4')+_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xc5')]['toFixed'](0x2)+_0x4878('0xcc');}_0xa96611+='</tr>';_0x2458e3=_0x503b6c;_0x5a43f8=_0x24a8e8;}else{_0x2458e3=_0xdbf985;_0x5a43f8=_0x136b51;}if(_0x2458e3>0x0||_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xc5')]>0x0){_0xa96611+='<tr>';_0xa96611+='<td\x20class=\x22itemTotal\x22>'+_0x382679['total'][_0x1d4e34]+'</td>';_0xa96611+=_0x4878('0xcd')+_0x5a43f8['toFixed'](0x2)+'&euro;</td>';_0xa96611+=_0x4878('0xb1');}if(_0x2458e3>0x0){_0xa96611+='<tr>';_0xa96611+=_0x4878('0xd5')+_0x382679[_0x4878('0xc6')][_0x1d4e34]+_0x4878('0xa5');_0xa96611+='<td\x20class=\x22numberRight\x22>'+_0x2458e3[_0x4878('0xce')](0x2)+_0x4878('0xcc');_0xa96611+=_0x4878('0xb1');}_0xa96611+=_0x4878('0x94');var _0x3a1c33;if(_0x1b40f3){_0x3a1c33=_0x5a43f8;}else{_0x3a1c33=_0x5a43f8+_0x2458e3;}_0xa96611+=_0x4878('0xd6')+_0x382679[_0x4878('0xd7')][_0x1d4e34]+_0x4878('0xd8')+_0x3a1c33['toFixed'](0x2)+_0x4878('0xcc');_0xa96611+='</table>\x20</td>';_0xa96611+=_0x4878('0xb1');_0xa96611+='<tr><td\x20class=\x22totalEmpty\x22>&nbsp;</td></tr>';_0xa96611+=_0x4878('0xd9');_0xa96611+=_0x4878('0x94');_0xa96611+=util[_0x4878('0x58')](_0x4878('0xda'),_0x2bfa2c['invoice']['receivingFiscalMessage'][_0x4878('0xdb')](new RegExp(String[_0x4878('0xdc')](0xd),'g'),_0x4878('0xdd')));_0xa96611+=_0x4878('0xb1');_0xa96611+=_0x4878('0x94');_0xa96611+='<td\x20colspan=\x223\x22>';_0xa96611+=_0x4878('0xde')+_0x382679['sendpayment'][_0x1d4e34]+_0x4878('0xdf');if(!_[_0x4878('0xd2')](_0x2bfa2c['invoice'][_0x4878('0xe0')])){_0xa96611+=_0x4878('0xde')+_0x382679[_0x4878('0xe1')][_0x1d4e34]+_0x4878('0xe2')+_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xe0')]+_0x4878('0xe3');_0xa96611+='<div\x20class=\x22issuerFiled\x22>'+_0x382679[_0x4878('0xe4')][_0x1d4e34]+_0x4878('0xe2')+_0x2bfa2c['invoice'][_0x4878('0xe5')]+_0x4878('0xe6');_0xa96611+='<div\x20class=\x22issuerFiled\x22>'+_0x382679[_0x4878('0xe7')][_0x1d4e34]+_0x4878('0xe2')+_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xe8')]+',\x20'+_0x2bfa2c[_0x4878('0x5a')]['issuerBankPostalCode']+'\x20-\x20'+_0x2bfa2c[_0x4878('0x5a')]['issuerBankCity']+'\x20('+_0x2bfa2c['invoice'][_0x4878('0xe9')]+')'+_0x4878('0xe3');_0xa96611+='<div\x20class=\x22issuerFiled\x22>'+_0x382679[_0x4878('0xea')][_0x1d4e34]+'/'+_0x382679[_0x4878('0xeb')][_0x1d4e34]+_0x4878('0xe2')+_0x2bfa2c[_0x4878('0x5a')]['issuerABI']+'/'+_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xec')]+'</span></div>';_0xa96611+='<div\x20class=\x22issuerFiled\x22>'+_0x382679[_0x4878('0xed')][_0x1d4e34]+'/'+_0x382679[_0x4878('0xee')][_0x1d4e34]+':\x20<span\x20class=\x22issuerData\x22>'+_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xef')]+_0x4878('0xe3');_0xa96611+=_0x4878('0xde')+_0x382679[_0x4878('0xf0')][_0x1d4e34]+_0x4878('0xe2')+_0x2bfa2c[_0x4878('0x5a')]['issuerBankIBAN']+_0x4878('0xe3');}if(!_[_0x4878('0xd2')](_0x2bfa2c[_0x4878('0x5a')]['issuerPayPal'])){_0xa96611+=_0x4878('0xde')+_0x382679['paypal'][_0x1d4e34]+':\x20<span\x20class=\x22issuerData\x22>'+_0x2bfa2c[_0x4878('0x5a')]['issuerPayPal']+'<br\x20/></span></div>';}_0xa96611+=_0x4878('0xde')+_0x382679[_0x4878('0xf1')][_0x1d4e34]+_0x4878('0xf2')+_0x153c5c+_0x4878('0xf3')+_0x382679[_0x4878('0xf4')][_0x1d4e34]+'</div>';_0xa96611+=_0x4878('0xa5');_0xa96611+='</tr>';if(_0x2bfa2c[_0x4878('0x5a')][_0x4878('0xf5')]===0x1){_0xa96611+=_0x4878('0x92')+_0x288129+'\x22\x20width=\x22180\x22></td></tr>';}_0xa96611+=_0x4878('0xf6');_0xa96611+='</body>';_0xa96611+=_0x4878('0xf7');console[_0x4878('0xf8')](_0x4878('0x4a'),_0xa96611);return new BPromise(function(_0x1dddba,_0x2c5565){pdf['create'](_0xa96611,_0x16d290)['toFile'](path['join'](_0x17c326,_0x5ce4ab),function(_0x1ca7e6,_0x4dd4a1){if(_0x1ca7e6)return _0x2c5565(_0x1ca7e6);_0x1dddba(_0x4dd4a1);});});});}})[_0x4878('0x20')](function(){if(_0x457afc){console[_0x4878('0xf8')]('TCL:\x20exports.getInvoicePDF\x20->\x20saveTo,\x20fileName',_0x4e57fc,_0x5ce4ab);return _0x38987e[_0x4878('0xf9')](_0x4e57fc,_0x5ce4ab,function(_0x39f04b){if(_0x39f04b){console['log'](_0x4878('0xfa'),_0x39f04b);}else{console['log'](_0x4878('0xfb'),_0x17c326);rimraf(_0x17c326,function(){});}});}else{return _0x38987e[_0x4878('0x16')](0xc8);}})[_0x4878('0x40')](handleError(_0x38987e,null));};exports['getInvoicesNumberByYear']=function(_0x2d7299,_0x2cae5c){var _0x3178c1=_0x2d7299[_0x4878('0x2a')][_0x4878('0xfc')];var _0x344455=squel['select']()[_0x4878('0xfd')](_0x4878('0xfe'))[_0x4878('0x3a')](_0x4878('0xff'),_0x4878('0x100'))[_0x4878('0x3a')](_0x4878('0x101'),_0x4878('0x102'))[_0x4878('0x3a')]('MONTH(startDate)',_0x4878('0x103'))[_0x4878('0x36')]('YEAR(startDate)\x20IN\x20('+_0x3178c1+')')[_0x4878('0x32')](_0x4878('0x104'))[_0x4878('0x32')]('YEAR(startDate)',![])[_0x4878('0x105')](_0x4878('0x101'))[_0x4878('0x105')](_0x4878('0x104'));return db[_0x4878('0x44')][_0x4878('0x2a')](_0x344455[_0x4878('0x4f')](),{'type':db[_0x4878('0x44')][_0x4878('0x106')][_0x4878('0x107')]})[_0x4878('0x20')](function(_0x2698f1){return{'count':_0x2698f1[_0x4878('0x2f')],'rows':_0x2698f1};})[_0x4878('0x20')](handleEntityNotFound(_0x2cae5c,null))[_0x4878('0x20')](respondWithResult(_0x2cae5c,null))[_0x4878('0x40')](handleError(_0x2cae5c,null));};exports[_0x4878('0x108')]=function(_0xb806c3,_0x3068d1){var _0x5c505a=_0xb806c3['query'][_0x4878('0xfc')];var _0x36b0b8=squel[_0x4878('0x109')]()['from'](_0x4878('0x10a'),'said')[_0x4878('0x3a')](_0xb806c3[_0x4878('0x2a')][_0x4878('0x105')]+_0x4878('0x10b'),_0x4878('0x10c'))[_0x4878('0x3a')](_0x4878('0x101'),'year')[_0x4878('0x3a')]('sum(said.netPrice\x20*\x20said.quantity)',_0x4878('0x10d'))[_0x4878('0x53')](_0x4878('0xfe'),_0x4878('0x10e'),_0x4878('0x10f'))[_0x4878('0x36')](_0x4878('0x110')+_0x5c505a+')')[_0x4878('0x32')](_0xb806c3['query'][_0x4878('0x105')]+_0x4878('0x10b'))[_0x4878('0x32')](_0xb806c3[_0x4878('0x2a')][_0x4878('0x105')]+'(startDate)',![])['group'](_0x4878('0x101'))['group'](_0xb806c3['query'][_0x4878('0x105')]+_0x4878('0x10b'));return db[_0x4878('0x44')]['query'](_0x36b0b8[_0x4878('0x4f')](),{'type':db[_0x4878('0x44')][_0x4878('0x106')][_0x4878('0x107')]})[_0x4878('0x20')](function(_0x114203){return{'count':_0x114203[_0x4878('0x2f')],'rows':_0x114203};})[_0x4878('0x20')](handleEntityNotFound(_0x3068d1,null))[_0x4878('0x20')](respondWithResult(_0x3068d1,null))[_0x4878('0x40')](handleError(_0x3068d1,null));};exports[_0x4878('0x111')]=function(_0x50e269,_0x9b6f41){var _0x41166f=squel[_0x4878('0x109')]()[_0x4878('0xfd')]('sa_invoices')['field'](_0x4878('0x112'),_0x4878('0x113'))[_0x4878('0x36')](_0x4878('0x114'))[_0x4878('0x32')](_0x4878('0x101'),![])[_0x4878('0x105')]('YEAR(startDate)');return db[_0x4878('0x44')][_0x4878('0x2a')](_0x41166f['toString'](),{'type':db[_0x4878('0x44')][_0x4878('0x106')][_0x4878('0x107')]})[_0x4878('0x20')](function(_0x4c4e86){return{'count':_0x4c4e86[_0x4878('0x2f')],'rows':_0x4c4e86};})[_0x4878('0x20')](handleEntityNotFound(_0x9b6f41,null))[_0x4878('0x20')](respondWithResult(_0x9b6f41,null))[_0x4878('0x40')](handleError(_0x9b6f41,null));};exports[_0x4878('0x115')]=function(_0x231ca4,_0x3be99d){var _0x53f0e3=_0x231ca4[_0x4878('0x2a')][_0x4878('0x116')];var _0x545e39=_0x231ca4[_0x4878('0x2a')]['dateEnd'];var _0xb3c748=_0x231ca4['query'][_0x4878('0x117')];var _0x1d9cef=_0x231ca4[_0x4878('0x2a')][_0x4878('0x118')];var _0x190222=_0x231ca4[_0x4878('0x2a')][_0x4878('0x119')];var _0x2d37a9=_0x231ca4[_0x4878('0x2a')][_0x4878('0x11a')];var _0x1e9761='';var _0x1b6823='';var _0x56aedd='';if(_0x1d9cef){switch(_0x1d9cef){case _0x4878('0x11b'):_0x1e9761=_0x4878('0x11c');break;case'europe':_0x1e9761=_0x4878('0x11d');}}if(_0x190222){_0x1b6823='com.saCompanyRelationship\x20=\x20'+_0x190222;}if(_0x2d37a9){_0x56aedd=_0x4878('0x11e')+_0x2d37a9;}var _0x4b0cce=squel['select']()[_0x4878('0xfd')](_0x4878('0x10a'),_0x4878('0x11f'))['field'](_0x4878('0x120'),_0x4878('0x24'))['field'](_0x4878('0x121'),_0x4878('0x122'))[_0x4878('0x3a')](_0x4878('0x123'),_0x4878('0x124'))[_0x4878('0x3a')](_0x4878('0x125'),'relationshipId')[_0x4878('0x3a')](_0x4878('0x126'),'relatedCompanyId')['field']('rel.name','relationshipName')['field'](_0x4878('0x127'),_0x4878('0x128'))[_0x4878('0x1b')](_0xb3c748)['offset'](0x0)[_0x4878('0x53')](_0x4878('0xfe'),'sai',_0x4878('0x10f'))[_0x4878('0x53')]('cm_companies',_0x4878('0x129'),'sai.companyName\x20=\x20com.name')[_0x4878('0x12a')](_0x4878('0x12b'),_0x4878('0x12c'),_0x4878('0x12d'))[_0x4878('0x12a')](_0x4878('0x12e'),'relCom','relCom.Id\x20=\x20com.CmCompanyId')[_0x4878('0x36')](_0x4878('0x12f'),_0x53f0e3)[_0x4878('0x36')](_0x4878('0x130'),_0x545e39)[_0x4878('0x36')](_0x1e9761)[_0x4878('0x36')](_0x1b6823)[_0x4878('0x36')](_0x56aedd)['order'](_0x4878('0x123'),![])[_0x4878('0x105')](_0x4878('0x120'))[_0x4878('0x105')](_0x4878('0x121'))[_0x4878('0x105')](_0x4878('0x125'))['group'](_0x4878('0x126'))['group'](_0x4878('0x131'))['group'](_0x4878('0x127'))['group'](_0x4878('0x132'))[_0x4878('0x105')](_0x4878('0x133'));console['log'](_0x4878('0x134'),_0x4b0cce[_0x4878('0x4f')]());return db[_0x4878('0x44')][_0x4878('0x2a')](_0x4b0cce[_0x4878('0x4f')](),{'type':db[_0x4878('0x44')]['QueryTypes']['SELECT']})[_0x4878('0x20')](function(_0x3048b6){return{'count':_0x3048b6['length'],'rows':_0x3048b6};})[_0x4878('0x20')](handleEntityNotFound(_0x3be99d,null))[_0x4878('0x20')](respondWithResult(_0x3be99d,null))[_0x4878('0x40')](handleError(_0x3be99d,null));};function addInvoiceCreditnoteDetail(_0x2ca783,_0x592e6e,_0x39139f){console[_0x4878('0xf8')](_0x4878('0x135'),_0x2ca783);var _0x260f08={'companyName':_0x2ca783['companyName'],'companyId':_0x2ca783[_0x4878('0x136')],'productName':_0x2ca783[_0x4878('0xc8')],'productCode':_0x2ca783[_0x4878('0x137')],'productDescription':_0x2ca783[_0x4878('0xca')],'typeName':_0x2ca783[_0x4878('0x138')],'pricelistName':_0x2ca783[_0x4878('0x139')],'priceListId':_0x2ca783['priceListId'],'netPrice':_0x2ca783[_0x4878('0xc4')],'discount':_0x2ca783[_0x4878('0xc5')],'tax':_0x2ca783[_0x4878('0xc6')],'agentFullname':_0x2ca783['agentFullname'],'note':_0x2ca783[_0x4878('0x13a')],'subscriptionId':_0x2ca783[_0x4878('0x13b')],'subscriptionName':_0x2ca783[_0x4878('0x13c')],'subscriptionMonthly':_0x2ca783[_0x4878('0x13d')],'quantity':_0x2ca783[_0x4878('0xc7')],'CreditNoteId':_0x592e6e,'unitName':_0x2ca783['unitName']};return db[_0x4878('0x13e')]['create'](_0x260f08,{'transaction':_0x39139f});}exports[_0x4878('0x13f')]=function(_0x3a0008,_0x2909d5,_0x2aae87){var _0x4b9a32;if(_0x3a0008[_0x4878('0x4a')]['id']){delete _0x3a0008[_0x4878('0x4a')]['id'];}console[_0x4878('0xf8')](_0x3a0008);return db[_0x4878('0x44')][_0x4878('0x45')](function(_0x3528e5){return db[_0x4878('0x140')][_0x4878('0x49')](_0x3a0008[_0x4878('0x4a')],{'transaction':_0x3528e5})[_0x4878('0x20')](function(_0x1bda72){_0x4b9a32=_0x1bda72;var _0x56fba2=_0x3a0008[_0x4878('0x4b')]['id'];return db[_0x4878('0x5b')]['findAll']({'where':{'InvoiceId':_0x56fba2},'raw':!![],'logging':console[_0x4878('0xf8')]});})[_0x4878('0x20')](function(_0x1a3bd5){if(_0x1a3bd5[_0x4878('0x2f')]>0x0){var _0x398489=[];for(var _0x10953a=0x0;_0x10953a<_0x1a3bd5['length'];_0x10953a++){_0x398489['push'](addInvoiceCreditnoteDetail(_0x1a3bd5[_0x10953a],_0x4b9a32['id'],_0x3528e5));}return BPromise[_0x4878('0x141')](_0x398489);}else{var _0x565fb4={'errors':[{'type':_0x4878('0x142'),'message':_0x4878('0x143')}]};throw _0x565fb4;}});})[_0x4878('0x20')](function(){return _0x2909d5[_0x4878('0x16')](0xc8);})[_0x4878('0x40')](function(_0x56839a){console[_0x4878('0xf8')]('TCL:\x20exports.automaticInvoiceCreditnote\x20->\x20err',_0x56839a);if(_0x56839a[_0x4878('0x24')]===_0x4878('0x144')){var _0x56839a={'errors':[{'message':_0x4878('0x145')}]};}_0x2909d5[_0x4878('0x17')](0x1f4)[_0x4878('0x146')](_0x56839a);});};