/*===================================================================================*/ /*=========================== FUNCTIONS =============================================*/ /*===================================================================================*/ /** * Function to now date with special string format * @return : formatted date in string **/ var getFormattedDate = function () { var now = new Date(); var year = now.getFullYear(); var month = (now.getMonth() + 1).toString().padStart(2, '0'); // Mois commence à 0, donc +1 var day = now.getDate().toString().padStart(2, '0'); var hour = now.getHours().toString().padStart(2, '0'); var minute = now.getMinutes().toString().padStart(2, '0'); //var seconde = maintenant.getSeconds().toString().padStart(2, '0'); return year + month + day +hour + minute;// + seconde; }; /** * Function to get VAT account associated with current line handled * @parameters : pLine : current account entry line handled * @parameters : associatedTVAWithCharge : object containing account number in key and vat account in relation to in value * @parameters : listTVAAccountInAccountEntry : array of vat account used in current account entry * @return : VAT account in relation to current line given in parameter **/ var getVATAccountFromLine = function(pLine, associatedTVAWithCharge, listTVAAccountInAccountEntry){ if(pLine == null || pLine.accountNumber == null || associatedTVAWithCharge == null) return null; //Handle case of juste one VAT on accountEntry if(listTVAAccountInAccountEntry != null && listTVAAccountInAccountEntry.length == 1) return listTVAAccountInAccountEntry[0]; //Handle case of matching charge and tva amount if(associatedTVAWithCharge[pLine.accountNumber] != undefined) return associatedTVAWithCharge[pLine.accountNumber]; return null; }; /** * Function to get all VATAccount in Capture filtered by buyer owners of current accountEntry * @parameters : pParameters : object with all informations to get needed values * @parameters : ws : Webservice object already initialized to be used to get informations from Capture webservice * @return : array of all VATAccount object **/ var getAllVATAccounts = function(pParameters, ws){ var resA = ws.send("/ws/account/list/"+FOLDER.id+"/VATAccount/_/_/_/_/_", "GET", {"Authorization" : "Bearer "+ CAPTURE_WS_TOKEN}); resA = JSON.parse(resA.StringResponse); return resA != null && resA.items != null && resA.items.length > 0 ? resA.items : []; }; /** * Function to get index value from id and idUnit * @parameters : pParameters : object with all informations to get needed values * @parameters : idIndex : string id of index * @parameters : idUnit : id unit * @return : value of index found by id and idunit **/ var getIndexFromIDAndIDUnit = function(pParameters, idIndex, idUnit){ var listIndex = getIndexesFromID(pParameters, idIndex); if(listIndex != null){ for(var i=0;i VATAccount in relation ex ["665450"] -> {type : "VATAccount", "accountNumber": "445650", ...} * @parameters : pLines : lines of current account entry * @parameters : pParameters : object with all informations to get needed values * @parameters : ws : Webservice object already initialized to be used to get informations from Capture webservice * @return : object containing key (account number), value(VAT account in relation) **/ var getAssociatedTVAAccount = function(pLines, pParameters, ws){ if(pLines == null || pLines.length == 0) return {}; var result = {}; var accounts = getAllVATAccounts(pParameters, ws); for(var l = 0;l