Principle:
Calculation of the due date (the scripted index) from the date of the document to which 45 days are added. The end of the month thus calculated is then kept.
Examples:
- 01/01/2017 => 28/02/2017
- 20/07/2017 => 30/09/2017
- 20/12/2017 => 28/02/2018
Script:
/**
* @param pParameters : Informations du document (les index dans lesquels on va chercher la date)
* @param nbDaysToAdd : nombre de jours à ajouter à la date pour calculer la date d’échéance
* @param idDateIndex : ide de l'index date utilisé comme base pour le calcul
* @return DueDate au format "dd/MM/yyyy"
*/
var getDueDateEndOfMonth = function(pParameters, nbDaysToAdd, idDateIndex){
var dateGeneralIndex = getTextFromIndexInfo(getFirstIndexFromID(pParameters,idDateIndex));
var splitDate = dateGeneralIndex.split("/");
var expectedDate=new Date(parseInt(splitDate[2]),parseInt(splitDate[1])-1,parseInt(splitDate[0])+nbDaysToAdd);
var endOfMonthDueDate=new Date(expectedDate.getFullYear(),expectedDate.getMonth()+1,0);
var months = endOfMonthDueDate.getMonth() + 1;
var dayOn2Digits = endOfMonthDueDate.getDate() < 10 ? "0" + endOfMonthDueDate.getDate() : endOfMonthDueDate.getDate();
var monthOn2Digits = months < 10 ? "0" + months : months;
return dayOn2Digits + "/" + monthOn2Digits + "/" + endOfMonthDueDate.getFullYear();
};
return getDueDateEndOfMonth(pParameters, 45, idDateIndex);