Exemplo n.º 1
0
        public void MoveBudgetAcross(string budget, string year, Priorities priority)
        {
            //Get next budget.
            var nextBudget = GetNextBudget(budget);

            //Add what is left from current budget (and priority) to the the next budget.

            string    budgetCheck = budget.Trim();
            Hashtable hashYearAmount;
            Hashtable hashYearAmountOriginal;
            float     available = 0;
            float     original  = 0;

            //Budget not defined
            try
            {
                if (!BudgetYear.Contains(budgetCheck))
                {
                    return;
                }
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year. " + e.Message));
                throw e;
            }


            try
            {
                hashYearAmount = (Hashtable)BudgetYear[budgetCheck];
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year. " + e.Message));
                throw e;
            }
            try
            {
                if (!hashYearAmount.Contains(year))
                {
                    return;
                }
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking year amount. " + e.Message));
                throw e;
            }

            try
            {
                available = (float)hashYearAmount[year];
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount. " + e.Message));
                throw e;
            }

            try
            {
                if (!BudgetYearOriginal.Contains(budgetCheck))
                {
                    return;
                }
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year original. " + e.Message));
                throw e;
            }

            try
            {
                hashYearAmountOriginal = (Hashtable)BudgetYearOriginal[budgetCheck];
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year original. " + e.Message));
                throw e;
            }


            try
            {
                if (!hashYearAmountOriginal.Contains(year))
                {
                    return;
                }
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking year amount original. " + e.Message));
                throw e;
            }

            try
            {
                original = (float)hashYearAmountOriginal[year];
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount original. " + e.Message));
                throw e;
            }


            if (original <= 0)
            {
                return;
            }
            var percent = (1 - available / original) * 100;

            try
            {
                var percentLimit = (float)priority.BudgetPercent[budgetCheck];
                if (percent < percentLimit)
                {
                    var difference   = percentLimit - percent;
                    var budgetToMove = original * difference / 100;
                    hashYearAmount[year] = (float)hashYearAmount[year] - budgetToMove;

                    hashYearAmount       = (Hashtable)BudgetYear[nextBudget];
                    hashYearAmount[year] = (float)hashYearAmount[year] + budgetToMove;
                }
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year original. " + e.Message));
                throw e;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check if budget can support treatment.  Checks for each priority.
        /// </summary>
        /// <param name="fAmount"></param>
        /// <param name="strBudget"></param>
        /// <param name="strYear"></param>
        /// <param name="hashAttributeValue"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public string IsBudgetAvailable(float fAmount, String strBudget, String strYear, Hashtable hashAttributeValue, Priorities priority)
        {
            string[] budgets;
            try
            {
                budgets = strBudget.Split('|');
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Budget is null." + e.Message));
                throw e;
            }

            foreach (string budget in budgets)
            {
                string    budgetCheck = budget.Trim();
                Hashtable hashYearAmount;
                Hashtable hashYearAmountOriginal;
                float     fAvailable;
                float     fOriginal;
                float     fAfterSpending;
                float     fPercent;

                //Budget not defined
                try
                {
                    if (!BudgetYear.Contains(budgetCheck))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year. " + e.Message));
                    throw e;
                }


                try
                {
                    hashYearAmount = (Hashtable)BudgetYear[budgetCheck];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year. " + e.Message));
                    throw e;
                }
                try
                {
                    if (!hashYearAmount.Contains(strYear))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking year amount. " + e.Message));
                    throw e;
                }

                try
                {
                    fAvailable = (float)hashYearAmount[strYear];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount. " + e.Message));
                    throw e;
                }

                try
                {
                    if (!BudgetYearOriginal.Contains(budgetCheck))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year original. " + e.Message));
                    throw e;
                }

                try
                {
                    hashYearAmountOriginal = (Hashtable)BudgetYearOriginal[budgetCheck];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year original. " + e.Message));
                    throw e;
                }


                try
                {
                    if (!hashYearAmountOriginal.Contains(strYear))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking year amount original. " + e.Message));
                    throw e;
                }

                try
                {
                    fOriginal = (float)hashYearAmountOriginal[strYear];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount original. " + e.Message));
                    throw e;
                }

                fAfterSpending = fAvailable - fAmount;
                if (fOriginal <= 0)
                {
                    continue;
                }
                fPercent = (1 - fAfterSpending / fOriginal) * 100;

                try
                {
                    if (priority.IsAllSections)
                    {
                        float fPercentLimit = (float)priority.BudgetPercent[budgetCheck];
                        if (fPercent < fPercentLimit)
                        {
                            return(budgetCheck);
                        }
                    }
                    else
                    {
                        if (priority.Criteria.IsCriteriaMet(hashAttributeValue))
                        {
                            float fPercentLimit = (float)priority.BudgetPercent[budgetCheck];
                            if (fPercent < fPercentLimit)
                            {
                                return(budgetCheck);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year original. " + e.Message));
                    throw e;
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check if budget can support treatment.  Checks for each priority.
        /// </summary>
        /// <param name="fAmount"></param>
        /// <param name="strBudget"></param>
        /// <param name="strYear"></param>
        /// <param name="hashAttributeValue"></param>
        /// <param name="priority"></param>
        /// <param name="limits">Limits where treatments are split over multiple years</param>
        /// <returns></returns>
        public string IsBudgetAvailable(float fAmount, string strBudget, String strYear, Hashtable hashAttributeValue, Priorities priority, List <ISplitTreatmentLimit> limits, string budgetLimitType, out string budgetHash, out ISplitTreatmentLimit splitTreatmentLimit, out string reasonNoBudget)
        {
            reasonNoBudget = "";
            string noBudgetAvailable = "";

            splitTreatmentLimit = limits[0];

            //Check priority.  If not possible just return null.
            if (!(priority.IsAllSections || priority.Criteria.IsCriteriaMet(hashAttributeValue)))
            {
                budgetHash     = "";
                reasonNoBudget = "Priority (" + priority.PriorityLevel + ") criteria not met for year " + strYear;
                return(noBudgetAvailable);
            }

            string[] possibleBudgets;


            foreach (var limit in limits)
            {
                if (limit.Amount > fAmount)
                {
                    splitTreatmentLimit = limit;
                    break;
                }
            }



            budgetHash = "";
            try
            {
                possibleBudgets = strBudget.Split('|');

                for (int i = 0; i < possibleBudgets.Length; i++)
                {
                    possibleBudgets[i] = possibleBudgets[i].Trim();
                }
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Budget is null." + e.Message));
                throw e;
            }

            //If there are no budget criteria, then ignore.  The list is enforced.

            var budgets = new List <string>();

            if (SimulationMessaging.BudgetCriterias.Count > 0)
            {
                var listAvailableBudget = new List <BudgetCriteria>();
                foreach (var budgetCriteria in SimulationMessaging.BudgetCriterias)
                {
                    if (budgetCriteria.Criteria.IsCriteriaMet(hashAttributeValue))
                    {
                        listAvailableBudget.Add(budgetCriteria);
                    }
                }


                foreach (var budget in possibleBudgets)
                {
                    var available = listAvailableBudget.Find(b => b.BudgetName == budget);
                    if (available != null && !budgets.Contains(available.BudgetName))
                    {
                        budgets.Add(available.BudgetName);
                    }
                }
            }
            else
            {
                foreach (var budget in possibleBudgets)
                {
                    budgets.Add(budget);
                }
            }

            if (budgets.Count == 0)
            {
                reasonNoBudget = "Budget (" + strBudget + ") did not meet budget criteria.";
            }

            foreach (string budget in budgets)
            {
                string    budgetCheck = budget.Trim();
                Hashtable hashYearAmount;
                Hashtable hashYearAmountOriginal;
                float     fAvailable;
                float     fOriginal;
                float     fAfterSpending;
                float     fPercent;

                //Budget not defined
                try
                {
                    if (!BudgetYear.Contains(budgetCheck))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year. " + e.Message));
                    throw e;
                }


                try
                {
                    hashYearAmount = (Hashtable)BudgetYear[budgetCheck];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year. " + e.Message));
                    throw e;
                }

                try
                {
                    if (!BudgetYearOriginal.Contains(budgetCheck))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year original. " + e.Message));
                    throw e;
                }

                bool currentBudgetAvailable = true;

                if (budgetLimitType.ToLower() == "unlimited")//If the budget is available (possible budget) and is unlimited... we are good.
                {
                    return(budgetCheck);
                }


                //Starting here need to loop through year amounts.
                var year = Convert.ToInt32(strYear);
                for (int i = 0; i < splitTreatmentLimit.Percentages.Count; i++)
                {
                    var currentYearAmount = fAmount * splitTreatmentLimit.Percentages[i] / 100;
                    var currentYear       = year + i;

                    //Priority must be all years, match the current year or the current year must be greater than maximum year and the Maximum year must be a priority.
                    if (!(priority.IsAllYears || priority.Years == currentYear || (currentYear > MaximumYear && priority.Years == MaximumYear)))
                    {
                        reasonNoBudget = "Priority is not set for year " + currentYear;
                        return(null);
                    }

                    try
                    {
                        //This occurs when a split treament goes past then end.
                        if (!hashYearAmount.Contains(currentYear.ToString()))
                        {
                            continue;
                        }
                        //Not past end of analysis.
                        fAvailable = (float)hashYearAmount[currentYear.ToString()];
                    }
                    catch (Exception e)
                    {
                        SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount. " + e.Message));
                        throw e;
                    }


                    //This gets a hash of all years and the amount of budgets originally available.
                    try
                    {
                        hashYearAmountOriginal = (Hashtable)BudgetYearOriginal[budgetCheck];
                        //This occurs when a split treament goes pas then end.
                        if (!hashYearAmountOriginal.ContainsKey(currentYear.ToString()))
                        {
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year original. " + e.Message));
                        throw e;
                    }


                    try
                    {
                        if (!hashYearAmountOriginal.Contains(currentYear.ToString()))
                        {
                            continue;
                        }
                        fOriginal = (float)hashYearAmountOriginal[currentYear.ToString()];
                    }
                    catch (Exception e)
                    {
                        SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount original. " + e.Message));
                        throw e;
                    }

                    fAfterSpending = fAvailable - currentYearAmount;
                    if (fOriginal <= 0)
                    {
                        continue;
                    }
                    fPercent = (1 - fAfterSpending / fOriginal) * 100;


                    try
                    {
                        float fPercentLimit = (float)priority.BudgetPercent[budgetCheck];
                        var   original      = (float)priority.BudgetPercent[budgetCheck] * fOriginal / 100;
                        budgetHash = currentYearAmount.ToString("#,##0.##") + "/" + fAmount.ToString("#,##0.##") + "/" + fAvailable.ToString("#,##0.##") + "/" + original.ToString("#,##0.##");
                        //if (fPercent < fPercentLimit) return budgetCheck;
                        if (fPercent > fPercentLimit)
                        {
                            currentBudgetAvailable = false;
                            reasonNoBudget         = "Percent after spending greater than priority limit " + fPercent.ToString("f2") + "/" + fPercentLimit.ToString("f2") + " for year(" + currentYear + ")";
                            return(noBudgetAvailable);
                        }
                    }
                    catch (Exception e)
                    {
                        SimulationMessaging.AddMessage(new SimulationMessage("Error: Evaluating priority. " + e.Message));
                        throw e;
                    }
                }
                //To be true here, there must be money available for each year.
                if (currentBudgetAvailable)
                {
                    return(budgetCheck);
                }
            }
            return(noBudgetAvailable);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Check if budget can support treatment.  Checks for each priority.
        /// </summary>
        /// <param name="fAmount"></param>
        /// <param name="strBudget"></param>
        /// <param name="strYear"></param>
        /// <param name="hashAttributeValue"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public string IsBudgetAvailable(float fAmount, String strBudget, String strYear, Hashtable hashAttributeValue, Priorities priority)
        {
            string[] possibleBudgets;
            try
            {
                possibleBudgets = strBudget.Split('|');
            }
            catch (Exception e)
            {
                SimulationMessaging.AddMessage(new SimulationMessage("Error: Budget is null." + e.Message));
                throw e;
            }

            //If there are no budget criteria, then ignore.  The list is enforced.

            var budgets = new List <string>();

            if (SimulationMessaging.BudgetCriterias.Count > 0)
            {
                var listAvailableBudget = new List <BudgetCriteria>();
                foreach (var budgetCriteria in SimulationMessaging.BudgetCriterias)
                {
                    if (budgetCriteria.Criteria.IsCriteriaMet(hashAttributeValue))
                    {
                        listAvailableBudget.Add(budgetCriteria);
                    }
                }


                foreach (var budget in possibleBudgets)
                {
                    var available = listAvailableBudget.Find(b => b.BudgetName == budget);
                    if (available != null && !budgets.Contains(available.BudgetName))
                    {
                        budgets.Add(available.BudgetName);
                    }
                }
            }
            else
            {
                foreach (var budget in possibleBudgets)
                {
                    budgets.Add(budget);
                }
            }



            foreach (string budget in budgets)
            {
                string    budgetCheck = budget.Trim();
                Hashtable hashYearAmount;
                Hashtable hashYearAmountOriginal;
                float     fAvailable;
                float     fOriginal;
                float     fAfterSpending;
                float     fPercent;

                //Budget not defined
                try
                {
                    if (!BudgetYear.Contains(budgetCheck))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year. " + e.Message));
                    throw e;
                }


                try
                {
                    hashYearAmount = (Hashtable)BudgetYear[budgetCheck];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year. " + e.Message));
                    throw e;
                }
                try
                {
                    if (!hashYearAmount.Contains(strYear))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking year amount. " + e.Message));
                    throw e;
                }

                try
                {
                    fAvailable = (float)hashYearAmount[strYear];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount. " + e.Message));
                    throw e;
                }

                try
                {
                    if (!BudgetYearOriginal.Contains(budgetCheck))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking budget year original. " + e.Message));
                    throw e;
                }

                try
                {
                    hashYearAmountOriginal = (Hashtable)BudgetYearOriginal[budgetCheck];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year original. " + e.Message));
                    throw e;
                }


                try
                {
                    if (!hashYearAmountOriginal.Contains(strYear))
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Checking year amount original. " + e.Message));
                    throw e;
                }

                try
                {
                    fOriginal = (float)hashYearAmountOriginal[strYear];
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving year amount original. " + e.Message));
                    throw e;
                }

                fAfterSpending = fAvailable - fAmount;
                if (fOriginal <= 0)
                {
                    continue;
                }
                fPercent = (1 - fAfterSpending / fOriginal) * 100;

                try
                {
                    if (priority.IsAllSections)
                    {
                        float fPercentLimit = (float)priority.BudgetPercent[budgetCheck];
                        if (fPercent < fPercentLimit)
                        {
                            return(budgetCheck);
                        }
                    }
                    else
                    {
                        if (priority.Criteria.IsCriteriaMet(hashAttributeValue))
                        {
                            float fPercentLimit = (float)priority.BudgetPercent[budgetCheck];
                            if (fPercent < fPercentLimit)
                            {
                                return(budgetCheck);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    SimulationMessaging.AddMessage(new SimulationMessage("Error: Retrieving budget year original. " + e.Message));
                    throw e;
                }
            }

            return(null);
        }