Exemple #1
0
        /// <summary>
        /// Check that the StartDate provided is valid, and return a string.
        /// </summary>
        ///
        /// <param name="StartDate"> A start date provided by an external function</param>
        ///
        /// <returns>
        /// string
        /// </returns>
        public string CheckStartDateIsValid(string StartDate, IConfiguration Settings)
        {
            DateTime InitialDate           = new DateTime();
            int      InitialProcessingDays = new int();
            bool     AutoFixStartDate      = new bool();

            try
            {
                InitialDate = DateTime.Parse(StartDate);
            }
            catch (FormatException)
            {
                throw new Exceptions.InvalidStartDateException(string.Format("The start date {0} is not valid. Please re-submit in ISO format (yyyy-mm-dd)", StartDate));
            }

            try
            {
                InitialProcessingDays = int.Parse(Settings.GetSection("directDebitProcessingDays")["InitialProcessingDays"]);
            }
            catch (FormatException)
            {
                string InvalidIPD = Settings.GetSection("directDebitProcessingDays")["InitialProcessingDays"];
                throw new Exceptions.InvalidSettingsConfigurationException("The InitialProcessingDays setting is misconfigured. It was expecting an integer, and received '{0}' instead", InvalidIPD);
            }

            try
            {
                AutoFixStartDate = bool.Parse(Settings.GetSection("contracts")["AutoFixStartDate"]);
            }
            catch (FormatException)
            {
                string InvalidAFSD = Settings.GetSection("contracts")["AutoFixStartDate"];
                throw new Exceptions.InvalidSettingsConfigurationException("The AutoFixStartDate setting is misconfigured. It was expecting a boolean, and received '{0}' instead", InvalidAFSD);
            }

            CheckWorkingDays WorkingDays        = new CheckWorkingDays();
            DateTime         FirstAvailableDate = WorkingDays.CheckWorkingDaysInFuture(InitialProcessingDays);


            if (InitialDate < FirstAvailableDate)
            {
                if (AutoFixStartDate)
                {
                    return(FirstAvailableDate.ToString("yyyy-MM-dd"));
                }
                else
                {
                    throw new Exceptions.InvalidStartDateException(string.Format("The start date of {0} is too soon. The earliest possible start date for this contract is {1}", StartDate, FirstAvailableDate.ToString("yyyy-MM-dd")));
                }
            }
            else
            {
                return(InitialDate.ToString("yyyy-MM-dd"));
            }
        }
Exemple #2
0
        /// <summary>
        /// Check that the collection_date argument is a valid ISO date and is at least x working days in the future, where x is the predetermined OngoingProcessingDays setting.
        /// Throw an error if this is not the case.
        /// </summary>
        ///
        /// <param name="CollectionDate">A collection date provided by an external function</param>
        /// <param name="Settings">Settings configuration used for making a call to EazyCustomerManager</param>
        ///
        /// <example>
        /// CheckPaymentDate("2019-06-24", Settings)
        /// </example>
        ///
        /// <returns>
        /// date formatted as string
        /// </returns>
        public string CheckPaymentDate(string CollectionDate, IConfiguration Settings)
        {
            DateTime InitialDate           = new DateTime();
            int      OngoingProcessingDays = new int();
            bool     AutoFixStartDate      = new bool();

            try
            {
                InitialDate = DateTime.Parse(CollectionDate);
            }
            catch (FormatException)
            {
                throw new Exceptions.InvalidPaymentDateException(string.Format("The payment date {0} is not valid. Please re-submit in ISO format (yyyy-mm-dd)", CollectionDate));
            }

            try
            {
                OngoingProcessingDays = int.Parse(Settings.GetSection("directDebitProcessingDays")["OngoingProcessingDays"]);
            }
            catch (FormatException)
            {
                string InvalidOPD = Settings.GetSection("directDebitProcessingDays")["OngoingProcessingDays"];
                throw new Exceptions.InvalidSettingsConfigurationException(string.Format("The ongoingProcessingDays requires an integer. '{0}' is not a valid value for this setting.", InvalidOPD));
            }

            try
            {
                AutoFixStartDate = bool.Parse(Settings.GetSection("payments")["AutoFixPaymentDate"]);
            }
            catch (FormatException)
            {
                string InvalidAFSD = Settings.GetSection("contracts")["AutoFixStartDate"];
                throw new Exceptions.InvalidSettingsConfigurationException(string.Format("The AutoFixStartDate requires a boolean. '{0}' is not a valid value for this setting.", InvalidAFSD));
            }

            CheckWorkingDays WorkingDays        = new CheckWorkingDays();
            DateTime         FirstAvailableDate = WorkingDays.CheckWorkingDaysInFuture(OngoingProcessingDays);

            if (InitialDate < FirstAvailableDate)
            {
                if (AutoFixStartDate)
                {
                    return(FirstAvailableDate.ToString("yyyy-MM-dd"));
                }
                else
                {
                    throw new Exceptions.InvalidPaymentDateException(string.Format("The payment date of {0} is too soon. The earliest possible payment date is {1}", CollectionDate, FirstAvailableDate.ToString("yyyy-MM-dd")));
                }
            }
            else
            {
                return(InitialDate.ToString("yyyy-MM-dd"));
            }
        }