public ActionForward deleteBudgetPersonnelDetails(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    BudgetForm budgetForm = (BudgetForm) form;
    BudgetDocument budgetDocument = budgetForm.getBudgetDocument();
    Budget budget = budgetDocument.getBudget();
    int selectedBudgetPeriodIndex = budgetForm.getViewBudgetPeriod() - 1;
    int selectedBudgetLineItemIndex = budgetForm.getSelectedBudgetLineItemIndex();
    BudgetPersonnelBudgetService budgetPersonnelBudgetService =
        KraServiceLocator.getService(BudgetPersonnelBudgetService.class);
    budgetPersonnelBudgetService.deleteBudgetPersonnelDetails(
        budget, selectedBudgetPeriodIndex, selectedBudgetLineItemIndex, getLineToDelete(request));
    HashMap uniqueBudgetPersonnelCount = new HashMap();
    int qty = 0;
    for (BudgetPersonnelDetails budgetPersonnelDetails :
        budget
            .getBudgetPeriod(selectedBudgetPeriodIndex)
            .getBudgetLineItem(selectedBudgetLineItemIndex)
            .getBudgetPersonnelDetailsList()) {
      if (!uniqueBudgetPersonnelCount.containsValue(budgetPersonnelDetails.getPersonId())) {
        uniqueBudgetPersonnelCount.put(qty, budgetPersonnelDetails.getPersonId());
        qty = qty + 1;
      }
    }
    budget
        .getBudgetPeriod(selectedBudgetPeriodIndex)
        .getBudgetLineItem(selectedBudgetLineItemIndex)
        .setQuantity(new Integer(qty));

    getCalculationService()
        .calculateBudgetPeriod(budget, budget.getBudgetPeriod(selectedBudgetPeriodIndex));
    return mapping.findForward(Constants.MAPPING_BASIC);
  }
 private void addSalaryDataForCostElement(
     CostElement costElement, List<SalaryTypeVO> salaryTypeVoList) {
   SalaryTypeVO groupVO = new SalaryTypeVO();
   groupVO.setCostElement(costElement.getDescription());
   salaryTypeVoList.add(groupVO);
   for (BudgetPersonnelDetails details : budget.getObjectCodePersonnelList().get(costElement)) {
     SalaryTypeVO salaryTypeVoPerPerson = new SalaryTypeVO();
     salaryTypeVoPerPerson.setName(details.getBudgetPerson().getPersonName());
     salaryTypeVoPerPerson.setBudgetPeriodVOs(
         getBudgetPeriodData(
             budget
                 .getObjectCodePersonnelSalaryTotals()
                 .get(costElement.getCostElement() + "," + details.getPersonId())));
     salaryTypeVoList.add(salaryTypeVoPerPerson);
   }
   if (budget.getObjectCodePersonnelSalaryTotals().get(costElement.getCostElement()) != null) {
     SalaryTypeVO salaryTypeVoPerPerson = new SalaryTypeVO();
     salaryTypeVoPerPerson.setName("Summary Line Item");
     salaryTypeVoPerPerson.setBudgetPeriodVOs(
         getBudgetPeriodData(
             budget.getObjectCodePersonnelSalaryTotals().get(costElement.getCostElement())));
     salaryTypeVoList.add(salaryTypeVoPerPerson);
   }
 }
  /**
   * This method is used to add a new Budget Line Item
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return mapping forward
   * @throws Exception
   */
  public ActionForward addBudgetPersonnelDetails(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    BudgetForm budgetForm = (BudgetForm) form;
    BudgetDocument budgetDocument = budgetForm.getBudgetDocument();
    Budget budget = budgetDocument.getBudget();
    int selectedBudgetPeriodIndex = budgetForm.getViewBudgetPeriod() - 1;
    int selectedBudgetLineItemIndex = budgetForm.getSelectedBudgetLineItemIndex();
    BudgetPersonnelDetails newBudgetPersonnelDetails = budgetForm.getNewBudgetPersonnelDetails();

    boolean errorFound = false;
    if (newBudgetPersonnelDetails.getPercentEffort().isGreaterThan(new BudgetDecimal(100))) {
      GlobalVariables.getMessageMap()
          .putError(
              "newBudgetPersonnelDetails.percentEffort",
              KeyConstants.ERROR_PERCENTAGE,
              Constants.PERCENT_EFFORT_FIELD);
      errorFound = true;
    }
    if (newBudgetPersonnelDetails.getPercentCharged().isGreaterThan(new BudgetDecimal(100))) {
      GlobalVariables.getMessageMap()
          .putError(
              "newBudgetPersonnelDetails.percentCharged",
              KeyConstants.ERROR_PERCENTAGE,
              Constants.PERCENT_CHARGED_FIELD);
      errorFound = true;
    }
    if (newBudgetPersonnelDetails
        .getPercentCharged()
        .isGreaterThan(newBudgetPersonnelDetails.getPercentEffort())) {
      GlobalVariables.getMessageMap()
          .putError(
              "newBudgetPersonnelDetails.percentCharged",
              KeyConstants.ERROR_PERCENT_EFFORT_LESS_THAN_PERCENT_CHARGED);
      errorFound = true;
    }
    if (StringUtils.isBlank((budgetForm.getNewBudgetPersonnelDetails().getPeriodTypeCode()))) {
      GlobalVariables.getMessageMap()
          .putError(
              "newBudgetPersonnelDetails.periodTypeCode",
              RiceKeyConstants.ERROR_REQUIRED,
              new String[] {"Period Type (Period Type)"});
      errorFound = true;
    }
    if (budgetForm.getNewBudgetPersonnelDetails().getPersonSequenceNumber() == null) {
      GlobalVariables.getMessageMap()
          .putError(
              "newBudgetPersonnelDetails.personSequenceNumber",
              RiceKeyConstants.ERROR_REQUIRED,
              new String[] {"Person (Person)"});
      errorFound = true;
    }

    HashMap uniqueBudgetPersonnelCount = new HashMap();
    int qty = 0;
    if (!errorFound) {
      BudgetPersonnelBudgetService budgetPersonnelBudgetService =
          KraServiceLocator.getService(BudgetPersonnelBudgetService.class);
      for (BudgetPersonnelDetails budgetPersonnelDetails :
          budget
              .getBudgetPeriod(selectedBudgetPeriodIndex)
              .getBudgetLineItem(selectedBudgetLineItemIndex)
              .getBudgetPersonnelDetailsList()) {
        if (!uniqueBudgetPersonnelCount.containsValue(budgetPersonnelDetails.getPersonId())) {
          uniqueBudgetPersonnelCount.put(qty, budgetPersonnelDetails.getPersonId());
          qty = qty + 1;
        }
      }
      budget
          .getBudgetPeriod(selectedBudgetPeriodIndex)
          .getBudgetLineItem(selectedBudgetLineItemIndex)
          .setQuantity(new Integer(qty));
      updatePersonnelBudgetRate(
          budget
              .getBudgetPeriod(selectedBudgetPeriodIndex)
              .getBudgetLineItem(selectedBudgetLineItemIndex));
      getCalculationService()
          .calculateBudgetPeriod(budget, budget.getBudgetPeriod(selectedBudgetPeriodIndex));
    }
    return mapping.findForward(Constants.MAPPING_BASIC);
  }