@Override
  public ActionForward reload(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    BudgetForm budgetForm = (BudgetForm) form;
    // setBudgetPersonDefaultPeriodTypeCode(budgetForm);
    ActionForward actionForward = super.reload(mapping, form, request, response);
    BusinessObjectService bos = KraServiceLocator.getService(BusinessObjectService.class);
    BudgetDocument budgetDocument = budgetForm.getBudgetDocument();
    Budget budget = budgetDocument.getBudget();
    Map queryMap = new HashMap();
    queryMap.put("budgetId", budget.getBudgetId());
    Collection budgetPersons = bos.findMatching(BudgetPerson.class, queryMap);
    budget.setBudgetPersons(budgetPersons == null ? new ArrayList() : (List) budgetPersons);

    BudgetCategoryTypeValuesFinder budgetCategoryTypeValuesFinder =
        new BudgetCategoryTypeValuesFinder();
    List<KeyValue> budgetCategoryTypes = new ArrayList<KeyValue>();
    budgetCategoryTypes = budgetCategoryTypeValuesFinder.getKeyValues();
    for (int i = 0; i < budgetCategoryTypes.size(); i++) {
      budgetForm.getNewBudgetLineItems().add(budget.getNewBudgetLineItem());
    }
    budget.setBudgetCategoryTypeCodes(budgetCategoryTypes);

    return actionForward;
  }
  /**
   * This method is used to return back to expenses tab
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return mapping forward
   * @throws Exception
   */
  public ActionForward returnToExpenses(
      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();
    BudgetLineItem selectedBudgetLineItem =
        budget
            .getBudgetPeriod(selectedBudgetPeriodIndex)
            .getBudgetLineItem(selectedBudgetLineItemIndex);
    int k = 0;
    boolean errorFound = false;
    GlobalVariables.getMessageMap().addToErrorPath("document");
    for (BudgetPersonnelDetails budgetPersonnelDetails :
        selectedBudgetLineItem.getBudgetPersonnelDetailsList()) {
      errorFound =
          errorFound
              || personnelDatesCheck(
                  selectedBudgetLineItem,
                  budgetPersonnelDetails,
                  selectedBudgetPeriodIndex,
                  selectedBudgetLineItemIndex,
                  k);
      k++;
    }
    GlobalVariables.getMessageMap().removeFromErrorPath("document");
    if (errorFound) {
      return mapping.findForward(Constants.MAPPING_BASIC);
    } else {
      getCalculationService().calculateBudgetLineItem(budget, selectedBudgetLineItem);

      BudgetCategoryTypeValuesFinder budgetCategoryTypeValuesFinder =
          new BudgetCategoryTypeValuesFinder();
      List<KeyValue> budgetCategoryTypes = new ArrayList<KeyValue>();
      budgetCategoryTypes = budgetCategoryTypeValuesFinder.getKeyValues();
      for (int i = 0; i < budgetCategoryTypes.size(); i++) {
        budgetForm.getNewBudgetLineItems().add(budget.getNewBudgetLineItem());
      }
      budget.setBudgetCategoryTypeCodes(budgetCategoryTypes);
      request.setAttribute(
          "fromPersonnelBudget"
              + budgetForm.getViewBudgetPeriod()
              + ""
              + selectedBudgetLineItemIndex,
          true);

      return mapping.findForward("expenses");
    }
  }
Beispiel #3
0
  protected void populatePersonnelCategoryTypeCodes(BudgetForm budgetForm) {
    BudgetDocument budgetDocument = budgetForm.getBudgetDocument();
    Budget budget = budgetDocument.getBudget();

    BudgetCategoryTypeValuesFinder budgetCategoryTypeValuesFinder =
        new BudgetCategoryTypeValuesFinder();
    List<KeyLabelPair> budgetCategoryTypes = new ArrayList<KeyLabelPair>();
    String personnelBudgetCategoryTypeCode = getPersonnelBudgetCategoryTypeCode();

    for (KeyLabelPair budgetCategoryType : budgetCategoryTypeValuesFinder.getKeyValues()) {
      String budgetCategoryTypeCode = (String) budgetCategoryType.getKey();
      if (StringUtils.isNotBlank(budgetCategoryTypeCode)
          && StringUtils.equalsIgnoreCase(
              budgetCategoryTypeCode, personnelBudgetCategoryTypeCode)) {
        budgetCategoryTypes.add(budgetCategoryType);
        BudgetLineItem newBudgetLineItem = budget.getNewBudgetLineItem();
        if (budgetForm.getNewBudgetLineItems() == null) {
          budgetForm.setNewBudgetLineItems(new ArrayList<BudgetLineItem>());
        }
        budgetForm.getNewBudgetLineItems().add(newBudgetLineItem);
      }
    }
    budget.setBudgetCategoryTypeCodes(budgetCategoryTypes);
  }