/**
  * This method will return the budget data periods for calculated amounts.It checks rate type code
  * ,rate class code against list of Budget LineItem Calculated Amounts for each budget line item
  * of each budget period of budget ,if it is equals then add calculated cost of budget LineItem
  * Calculated Amount to period cost.
  *
  * @param rateClassCode
  * @param rateTypeCode
  * @return list of BudgetDataPeriod VO's
  */
 protected List<BudgetDataPeriodVO> getBudgetDataPeriodsForCalculatedAmounts(
     String rateClassCode, String rateTypeCode, boolean includeNonPersonnel) {
   List<BudgetDataPeriodVO> budgetPeriodDataList = new ArrayList<BudgetDataPeriodVO>();
   int budgetPeriodDataId = 0;
   for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
     BudgetDataPeriodVO budgetPeriodVO = new BudgetDataPeriodVO();
     budgetPeriodVO.setBudgetPeriodId(++budgetPeriodDataId);
     ScaleTwoDecimal periodCost = ScaleTwoDecimal.ZERO;
     for (BudgetLineItem budgetLineItem : budgetPeriod.getBudgetLineItems()) {
       String budgetCategoryType = getBudgetCategoryTypeCode(budgetLineItem);
       if (includeNonPersonnel || isPersonnel(budgetCategoryType)) {
         for (BudgetLineItemCalculatedAmount budgetLineItemCalcAmount :
             budgetLineItem.getBudgetLineItemCalculatedAmounts()) {
           if (budgetLineItemCalcAmount.getRateClassCode() != null
               && budgetLineItemCalcAmount.getRateClassCode().equals(rateClassCode)
               && budgetLineItemCalcAmount.getRateTypeCode() != null
               && budgetLineItemCalcAmount.getRateTypeCode().equals(rateTypeCode)) {
             periodCost = periodCost.add(budgetLineItemCalcAmount.getCalculatedCost());
           }
         }
       }
     }
     budgetPeriodVO.setPeriodCost(periodCost);
     budgetPeriodDataList.add(budgetPeriodVO);
   }
   return budgetPeriodDataList;
 }
 /*
  * This method will calculate the total for cost element of all periods
  * period cost.
  */
 private ScaleTwoDecimal getTotalForCostElementOfAllPeriodsCost(
     List<BudgetDataPeriodVO> budgetDataPeriodVOs) {
   ScaleTwoDecimal total = ScaleTwoDecimal.ZERO;
   for (BudgetDataPeriodVO budgetDataPeriodVO : budgetDataPeriodVOs) {
     total = total.add(budgetDataPeriodVO.getPeriodCost());
   }
   return total;
 }
 /*
  * This method will get the budget data periods . For a given cost element
  * description from budget get list of budget periods , iterate over budget
  * periods and get list of budget line items ,iterate over budget line items
  * compare with the cost element description which ever matches add line
  * item cost to period cost.finally set period cost to BudgetDataPeriodVO
  *
  */
 private List<BudgetDataPeriodVO> getBudgetDataPeriodVOsForCostElement(String costElementDesc) {
   List<BudgetDataPeriodVO> budgetPeriodDataList = new ArrayList<BudgetDataPeriodVO>();
   int budgetPeriodDataId = 0;
   for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
     BudgetDataPeriodVO budgetDataPeriodVO = new BudgetDataPeriodVO();
     budgetDataPeriodVO.setBudgetPeriodId(++budgetPeriodDataId);
     ScaleTwoDecimal periodCost = ScaleTwoDecimal.ZERO;
     for (BudgetLineItem lineItem : budgetPeriod.getBudgetLineItems()) {
       if (lineItem.getCostElementBO() != null
           && lineItem.getCostElementBO().getDescription() != null
           && lineItem.getCostElementBO().getDescription().equals(costElementDesc)) {
         periodCost = periodCost.add(lineItem.getLineItemCost());
       }
     }
     budgetDataPeriodVO.setPeriodCost(periodCost);
     budgetPeriodDataList.add(budgetDataPeriodVO);
   }
   return budgetPeriodDataList;
 }
 /*
  * This method will set the values to budget data period xml object and
  * finally return the set of budget data period xml objects.
  */
 private BudgetPeriodData[] getBudgetDataPeriodXmlObjects(
     List<BudgetDataPeriodVO> budgetDataPeriods,
     Map<Integer, ScaleTwoDecimal> budgetPeriodWiseTotalMap) {
   List<BudgetPeriodData> budgetPeriodList = null;
   budgetPeriodList = new ArrayList<BudgetPeriodData>();
   for (BudgetDataPeriodVO budgetPeriodVO : budgetDataPeriods) {
     BudgetPeriodData budgetPeriodData = BudgetPeriodData.Factory.newInstance();
     int budgetPeriodId = budgetPeriodVO.getBudgetPeriodId();
     budgetPeriodData.setBudgetPeriodID(budgetPeriodId);
     ScaleTwoDecimal periodCost = budgetPeriodVO.getPeriodCost();
     budgetPeriodData.setPeriodCost(periodCost.bigDecimalValue());
     if (budgetPeriodWiseTotalMap.containsKey(budgetPeriodId)) {
       ScaleTwoDecimal periodTotal = budgetPeriodWiseTotalMap.get(budgetPeriodId);
       periodTotal = periodTotal.add(periodCost);
       budgetPeriodWiseTotalMap.put(budgetPeriodId, periodTotal);
     } else {
       budgetPeriodWiseTotalMap.put(budgetPeriodId, periodCost);
     }
     budgetPeriodList.add(budgetPeriodData);
   }
   BudgetPeriodData[] budgetPeriodArray = budgetPeriodList.toArray(new BudgetPeriodData[0]);
   return budgetPeriodArray;
 }