In doing an eConnect transaction today, the customer was integrating documents into a closed period. eConnect sensed that and sent and error.
The customer asked me to update the document date to the earliest open date in that case.
The stored procedure below takes the series (explained in the script) and the target date and returns either the target date (meaning that it's a valid date) or the earliest open date that is later than the target date.