8144a36b32984d87001fff2ba6660a6cc23d9ebf
[motion2.git] / server / api / saInvoice / saInvoice.model.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 _0xd67b=['findOne','transaction','then','number','update','create','log','TCL:\x20error','util','api','moment','bluebird','path','../../config/environment','exports','define','SAInvoice','sa_invoices','models','get','format','has','SAInvoiceNumber'];(function(_0x1a4eef,_0x1a2ed3){var _0x1d7082=function(_0x22d2cf){while(--_0x22d2cf){_0x1a4eef['push'](_0x1a4eef['shift']());}};_0x1d7082(++_0x1a2ed3);}(_0xd67b,0x133));var _0xbd67=function(_0x22510b,_0x1dbc40){_0x22510b=_0x22510b-0x0;var _0x52003c=_0xd67b[_0x22510b];return _0x52003c;};'use strict';var _=require('lodash');var util=require(_0xbd67('0x0'));var logger=require('../../config/logger')(_0xbd67('0x1'));var moment=require(_0xbd67('0x2'));var BPromise=require(_0xbd67('0x3'));var rp=require('request-promise');var fs=require('fs');var path=require(_0xbd67('0x4'));var rimraf=require('rimraf');var config=require(_0xbd67('0x5'));var attributes=require('./saInvoice.attributes');module[_0xbd67('0x6')]=function(_0xa5c384,_0x2ad142){return _0xa5c384[_0xbd67('0x7')](_0xbd67('0x8'),attributes,{'tableName':_0xbd67('0x9'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x2d4af6,_0xfad775,_0x1da7f1){var _0x461231=_0xa5c384[_0xbd67('0xa')];var _0x3a7f43=_0x2d4af6[_0xbd67('0xb')]({'plain':!![]});var _0x52b981=0x1;var _0x54954b=parseInt(moment()[_0xbd67('0xc')]('YYYY'));try{if(_[_0xbd67('0xd')](_0x3a7f43,'id')){return _0x461231[_0xbd67('0xe')][_0xbd67('0xf')]({'where':{'year':_0x54954b},'raw':!![],'logging':!![],'transaction':_0xfad775[_0xbd67('0x10')]})[_0xbd67('0x11')](function(_0xb05237){if(_0xb05237){_0x52b981=_0xb05237[_0xbd67('0x12')]+0x1;return _0x461231[_0xbd67('0xe')][_0xbd67('0x13')]({'number':_0x52b981},{'where':{'id':_0xb05237['id']},'transaction':_0xfad775[_0xbd67('0x10')],'logging':!![]});}return _0x461231['SAInvoiceNumber'][_0xbd67('0x14')]({'year':_0x54954b,'number':_0x52b981},{'logging':!![],'transaction':_0xfad775[_0xbd67('0x10')]});})[_0xbd67('0x11')](function(){_0x3a7f43[_0xbd67('0x12')]=_0x52b981;})[_0xbd67('0x11')](function(){_0x1da7f1();});}}catch(_0x23b626){console[_0xbd67('0x15')](_0xbd67('0x16'),_0x23b626);_0x1da7f1();}}}});};