Beispiel #1
0
  public ActionForward summaryTotals(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    BudgetForm budgetForm = (BudgetForm) form;
    BudgetDocument budgetDocument = budgetForm.getDocument();
    populatePersonnelRoles(budgetDocument);
    Budget budget = budgetDocument.getBudget();
    for (BudgetPeriod period : budget.getBudgetPeriods()) {
      for (BudgetLineItem lineItem : period.getBudgetLineItems()) {
        for (BudgetPersonnelDetails budgetPersonnelDetails :
            lineItem.getBudgetPersonnelDetailsList()) {
          budgetPersonnelDetails.refreshReferenceObject("budgetPerson");
        }
      }
    }

    budget.getBudgetTotals();
    budgetForm.setProposalHierarchyIndirectObjectCode(
        getParameterService()
            .getParameterValue(
                BudgetDocument.class, "proposalHierarchySubProjectIndirectCostElement"));
    return mapping.findForward(Constants.BUDGET_SUMMARY_TOTALS_PAGE);
  }
Beispiel #2
0
  private void copyLineItemToPersonnelDetails(BudgetDocument budgetDocument) {
    for (BudgetPeriod budgetPeriod : budgetDocument.getBudget().getBudgetPeriods()) {
      if (budgetPeriod.getBudgetLineItems() != null
          && !budgetPeriod.getBudgetLineItems().isEmpty()) {
        for (BudgetLineItem budgetLineItem : budgetPeriod.getBudgetLineItems()) {

          if (budgetLineItem.getBudgetPersonnelDetailsList() != null
              && !budgetLineItem.getBudgetPersonnelDetailsList().isEmpty()) {
            for (BudgetPersonnelDetails budgetPersonnelDetails :
                budgetLineItem.getBudgetPersonnelDetailsList()) {
              //
              // budgetPersonnelDetails.setProposalNumber(budgetLineItem.getProposalNumber());
              //
              // budgetPersonnelDetails.setBudgetVersionNumber(budgetLineItem.getBudgetVersionNumber());
              budgetPersonnelDetails.setBudgetId(budgetLineItem.getBudgetId());
              budgetPersonnelDetails.setBudgetPeriod(budgetLineItem.getBudgetPeriod());
              budgetPersonnelDetails.setLineItemNumber(budgetLineItem.getLineItemNumber());
              budgetPersonnelDetails.setCostElement(budgetLineItem.getCostElement());
              budgetPersonnelDetails.setCostElementBO(budgetLineItem.getCostElementBO());
            }
          }
        }
      }
    }
  }
  /**
   * 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");
    }
  }
 protected List<BudgetLineItem> findSubAwardLineItems(
     BudgetPeriod budgetPeriod, Integer subAwardNumber) {
   List<BudgetLineItem> lineItems = new ArrayList<BudgetLineItem>();
   if (budgetPeriod.getBudgetLineItems() != null) {
     for (BudgetLineItem item : budgetPeriod.getBudgetLineItems()) {
       if (ObjectUtils.equals(item.getSubAwardNumber(), subAwardNumber)) {
         lineItems.add(item);
       }
     }
   }
   return lineItems;
 }
 private void updatePersonnelBudgetRate(BudgetLineItem budgetLineItem) {
   int j = 0;
   for (BudgetPersonnelDetails budgetPersonnelDetails :
       budgetLineItem.getBudgetPersonnelDetailsList()) {
     j = 0;
     for (BudgetPersonnelCalculatedAmount budgetPersonnelCalculatedAmount :
         budgetPersonnelDetails.getBudgetPersonnelCalculatedAmounts()) {
       budgetPersonnelCalculatedAmount.setApplyRateFlag(
           budgetLineItem.getBudgetLineItemCalculatedAmounts().get(j).getApplyRateFlag());
       j++;
     }
   }
 }
 /*
  * This method will set the values to AwardBudgetDetails attributes and
  * finally returns AwardBudgetDetails Xml object
  */
 private AwardBudgetDetails getAwardBudgetDetails() {
   AwardBudgetDetails awardBudgetDetails = AwardBudgetDetails.Factory.newInstance();
   List<BudgetDetails> budgetDetailsList = new ArrayList<BudgetDetails>();
   BudgetDocument budgetDocument = getBudgetDocument();
   if (budgetDocument != null) {
     for (BudgetLineItem budgetLineItem :
         budgetDocument.getBudget().getBudgetPeriod(0).getBudgetLineItems()) {
       BudgetDetails budgetDetails = BudgetDetails.Factory.newInstance();
       budgetDetails.setAwardNumber(award.getAwardNumber());
       budgetDetails.setSequenceNumber(award.getSequenceNumber());
       budgetDetails.setLineItemNumber(budgetLineItem.getLineItemNumber());
       budgetDetails.setCostElementCode(budgetLineItem.getCostElement());
       budgetDetails.setCostElementDescription(budgetLineItem.getCostElementBO().getDescription());
       budgetDetails.setLineItemDescription(budgetLineItem.getLineItemDescription());
       budgetDetailsList.add(budgetDetails);
     }
   }
   awardBudgetDetails.setBudgetDetailsArray(budgetDetailsList.toArray(new BudgetDetails[0]));
   return awardBudgetDetails;
 }
Beispiel #7
0
  public ActionForward personnel(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {
    BudgetForm budgetForm = (BudgetForm) form;
    populatePersonnelHierarchySummary(budgetForm);
    populatePersonnelCategoryTypeCodes(budgetForm);
    if (budgetForm.getBudgetDocument().getBudget().getBudgetPersons().isEmpty()) {
      KraServiceLocator.getService(BudgetPersonService.class)
          .synchBudgetPersonsToProposal(budgetForm.getBudgetDocument().getBudget());
    }
    reconcilePersonnelRoles(budgetForm.getDocument());
    BudgetDocument budgetDocument = budgetForm.getBudgetDocument();
    Budget budget = budgetDocument.getBudget();
    for (BudgetPeriod period : budget.getBudgetPeriods()) {
      for (BudgetLineItem lineItem : period.getBudgetLineItems()) {
        for (BudgetPersonnelDetails budgetPersonnelDetails :
            lineItem.getBudgetPersonnelDetailsList()) {
          budgetPersonnelDetails.refreshReferenceObject("budgetPerson");
          ObjectUtils.materializeObjects(
              budgetPersonnelDetails.getBudgetPersonnelCalculatedAmounts());
          for (BudgetPersonnelCalculatedAmount budgetPersonnelCalculatedAmount :
              budgetPersonnelDetails.getBudgetPersonnelCalculatedAmounts()) {
            if (budgetPersonnelCalculatedAmount.getRateClass() == null) {
              budgetPersonnelCalculatedAmount.refreshReferenceObject("rateClass");
            }
          }
        }

        for (BudgetLineItemCalculatedAmount lineItemCalculatedAmount :
            lineItem.getBudgetLineItemCalculatedAmounts()) {
          if (lineItemCalculatedAmount.getRateClass() == null) {
            lineItemCalculatedAmount.refreshReferenceObject("rateClass");
          }
        }
      }
    }
    return mapping.findForward(Constants.BUDGET_PERSONNEL_PAGE);
  }
 @Override
 public ActionForward save(
     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 |=
         personnelDatesCheck(
             selectedBudgetLineItem,
             budgetPersonnelDetails,
             selectedBudgetPeriodIndex,
             selectedBudgetLineItemIndex,
             k);
     k++;
   }
   GlobalVariables.getMessageMap().removeFromErrorPath("document");
   if (errorFound) {
     getCalculationService().calculateBudgetLineItem(budget, selectedBudgetLineItem);
     return mapping.findForward(Constants.MAPPING_BASIC);
   } else {
     ActionForward actionForward = super.save(mapping, form, request, response);
     selectedBudgetLineItem.setBudgetPersonnelLineItemDeleted(false);
     return actionForward;
   }
 }
  protected BudgetLineItem findOrCreateLineItem(
      List<BudgetLineItem> lineItems,
      BudgetSubAwardPeriodDetail subAwardDetail,
      BudgetSubAwards subAward,
      BudgetPeriod budgetPeriod,
      String costElement) {
    for (BudgetLineItem curLineItem : lineItems) {
      if (StringUtils.equals(curLineItem.getCostElement(), costElement)) {
        return curLineItem;
      }
    }

    // if we didn't find one already
    BudgetLineItem newLineItem = new BudgetLineItem();
    newLineItem.setCostElement(costElement);
    newLineItem.setSubAwardNumber(subAwardDetail.getSubAwardNumber());
    newLineItem.setLineItemDescription(subAward.getOrganizationName());
    getBudgetService().populateNewBudgetLineItem(newLineItem, budgetPeriod);
    lineItems.add(newLineItem);
    return newLineItem;
  }
Beispiel #10
0
  /**
   * This method checks business rules related to Budget Personnel Budget functionality
   *
   * @param budgetDocument
   * @return
   */
  protected boolean processBudgetPersonnelBudgetBusinessRules(BudgetDocument budgetDocument) {
    boolean valid = true;

    MessageMap errorMap = GlobalVariables.getMessageMap();

    List<BudgetPeriod> budgetPeriods = budgetDocument.getBudget().getBudgetPeriods();
    int i = 0;
    int j = 0;
    int k = 0;
    for (BudgetPeriod budgetPeriod : budgetPeriods) {
      j = 0;
      List<BudgetLineItem> budgetLineItems = budgetPeriod.getBudgetLineItems();
      k = 0;
      for (BudgetLineItem budgetLineItem : budgetLineItems) {
        for (BudgetPersonnelDetails budgetPersonnelDetails :
            budgetLineItem.getBudgetPersonnelDetailsList()) {
          if (budgetPersonnelDetails != null
              && budgetPersonnelDetails.getStartDate() != null
              && budgetPersonnelDetails.getStartDate().before(budgetLineItem.getStartDate())) {
            errorMap.putError(
                "budgetPeriod["
                    + i
                    + "].budgetLineItems["
                    + j
                    + "].budgetPersonnelDetailsList["
                    + k
                    + "].startDate",
                KeyConstants.ERROR_PERSONNELBUDGETLINEITEM_STARTDATE_BEFORE_LINEITEM_STARTDATE);
            valid = false;
          }
          if (budgetPersonnelDetails != null
              && budgetPersonnelDetails.getEndDate() != null
              && budgetPersonnelDetails.getEndDate().after(budgetLineItem.getEndDate())) {
            errorMap.putError(
                "budgetPeriod["
                    + i
                    + "].budgetLineItems["
                    + j
                    + "].budgetPersonnelDetailsList["
                    + k
                    + "].endDate",
                KeyConstants.ERROR_PERSONNELBUDGETLINEITEM_ENDDATE_AFTER_LINEITEM_ENDDATE);
            valid = false;
          }
          if (budgetPersonnelDetails.getPercentEffort().isGreaterThan(new ScaleTwoDecimal(100))) {
            errorMap.putError(
                "budgetPeriod["
                    + i
                    + "].budgetLineItems["
                    + j
                    + "].budgetPersonnelDetailsList["
                    + k
                    + "].percentEffort",
                KeyConstants.ERROR_PERCENTAGE,
                Constants.PERCENT_EFFORT_FIELD);
          }
          if (budgetPersonnelDetails.getPercentCharged().isGreaterThan(new ScaleTwoDecimal(100))) {
            errorMap.putError(
                "budgetPeriod["
                    + i
                    + "].budgetLineItems["
                    + j
                    + "].budgetPersonnelDetailsList["
                    + k
                    + "].percentCharged",
                KeyConstants.ERROR_PERCENTAGE,
                Constants.PERCENT_CHARGED_FIELD);
          }
          if (budgetPersonnelDetails
              .getPercentCharged()
              .isGreaterThan(budgetPersonnelDetails.getPercentEffort())) {
            errorMap.putError(
                "budgetPeriod["
                    + i
                    + "].budgetLineItems["
                    + j
                    + "].budgetPersonnelDetailsList["
                    + k
                    + "].percentCharged",
                KeyConstants.ERROR_PERCENT_EFFORT_LESS_THAN_PERCENT_CHARGED);
          }
          k++;
        }
        j++;
      }
      i++;
    }
    return valid;
  }
Beispiel #11
0
  /**
   * This method checks business rules related to Budget Expenses functionality
   *
   * @param budgetDocument
   * @return
   */
  protected boolean processBudgetExpenseBusinessRules(BudgetDocument budgetDocument) {
    boolean valid = true;
    // TODO - put budget expense validation rules here.
    MessageMap errorMap = GlobalVariables.getMessageMap();

    List<BudgetPeriod> budgetPeriods = budgetDocument.getBudget().getBudgetPeriods();
    int i = 0;
    int j = 0;
    for (BudgetPeriod budgetPeriod : budgetPeriods) {
      j = 0;
      List<BudgetLineItem> budgetLineItems = budgetPeriod.getBudgetLineItems();
      for (BudgetLineItem budgetLineItem : budgetLineItems) {
        if (budgetLineItem != null
            && budgetLineItem.getStartDate() != null
            && budgetLineItem.getStartDate().before(budgetPeriod.getStartDate())) {
          errorMap.putError(
              "budgetCategoryTypes["
                  + budgetLineItem.getBudgetCategory().getBudgetCategoryTypeCode()
                  + "].budgetPeriods["
                  + i
                  + "].budgetLineItems["
                  + j
                  + "].startDate",
              KeyConstants.ERROR_LINEITEM_STARTDATE_BEFORE_PERIOD_STARTDATE);
          valid = false;
        }
        if (budgetLineItem != null
            && budgetLineItem.getEndDate() != null
            && budgetLineItem.getEndDate().after(budgetPeriod.getEndDate())) {
          errorMap.putError(
              "budgetCategoryTypes["
                  + budgetLineItem.getBudgetCategory().getBudgetCategoryTypeCode()
                  + "].budgetPeriods["
                  + i
                  + "].budgetLineItems["
                  + j
                  + "].endDate",
              KeyConstants.ERROR_LINEITEM_ENDDATE_AFTER_PERIOD_ENDDATE);
          valid = false;
        }
        //                if (budgetLineItem!=null && budgetLineItem.getCostSharingAmount() != null
        // && budgetLineItem.getCostSharingAmount().isNegative()) {
        //                    errorMap.putError("budgetPeriod[" + i +"].budgetLineItem[" + j +
        // "].costSharingAmount", KeyConstants.ERROR_NEGATIVE_AMOUNT,"Cost Sharing");
        //                    valid = false;
        //                }
        if (budgetLineItem != null
            && budgetLineItem.getQuantity() != null
            && budgetLineItem.getQuantity().intValue() < 0) {
          errorMap.putError(
              "budgetPeriod[" + i + "].budgetLineItem[" + j + "].quantity",
              KeyConstants.ERROR_NEGATIVE_AMOUNT,
              "Quantity");
          valid = false;
        }
        //                if (budgetLineItem!=null && budgetLineItem.getLineItemCost() != null &&
        // budgetLineItem.getLineItemCost().isNegative()) {
        //                    errorMap.putError("budgetPeriod[" + i +"].budgetLineItem[" + j +
        // "].lineItemCost", KeyConstants.ERROR_NEGATIVE_AMOUNT,"Total Base Cost");
        //                    valid = false;
        //                }
        //                if(budgetLineItem.getEndDate().compareTo(budgetLineItem.getStartDate())
        // <=0 ) {
        //
        // errorMap.putError("budgetPeriod["+i+"].budgetLineItem["+j+"].endDate",
        // KeyConstants.ERROR_LINE_ITEM_DATES);
        //                        return false;
        //                }

        j++;
      }
      i++;
    }
    return valid;
  }
Beispiel #12
0
  /**
   * This method is to get estimated project funds for RRSF424
   *
   * @return EstimatedProjectFunding estimated total cost for the project.
   * @throws S2SException
   */
  private EstimatedProjectFunding getProjectFunding() throws S2SException {
    BudgetDocument budgetDocument = null;
    try {
      budgetDocument = proposalBudgetService.getFinalBudgetVersion(pdDoc);
    } catch (WorkflowException e) {
      throw new S2SException(e);
    }
    Budget budget = budgetDocument == null ? null : budgetDocument.getBudget();
    EstimatedProjectFunding funding = EstimatedProjectFunding.Factory.newInstance();
    funding.setTotalEstimatedAmount(BigDecimal.ZERO);
    funding.setTotalfedNonfedrequested(BigDecimal.ZERO);
    funding.setEstimatedProgramIncome(BigDecimal.ZERO);
    boolean hasBudgetLineItem = false;
    if (budget != null) {
      if (budget.getModularBudgetFlag()) {
        ScaleTwoDecimal fundsRequested = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal totalDirectCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal totalCost = ScaleTwoDecimal.ZERO;
        // get modular budget amounts instead of budget detail amounts
        for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
          totalDirectCost =
              totalDirectCost.add(budgetPeriod.getBudgetModular().getTotalDirectCost());
          for (BudgetModularIdc budgetModularIdc :
              budgetPeriod.getBudgetModular().getBudgetModularIdcs()) {
            fundsRequested = fundsRequested.add(budgetModularIdc.getFundsRequested());
          }
        }
        totalCost = totalCost.add(totalDirectCost);
        totalCost = totalCost.add(fundsRequested);
        budget.setTotalIndirectCost(fundsRequested);
        budget.setTotalCost(totalCost);
      }
      ScaleTwoDecimal fedNonFedCost = budget.getTotalCost();

      BigDecimal totalProjectIncome = BigDecimal.ZERO;

      ScaleTwoDecimal costSharingAmount = ScaleTwoDecimal.ZERO;

      for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
        for (BudgetLineItem lineItem : budgetPeriod.getBudgetLineItems()) {
          hasBudgetLineItem = true;
          if (budget.getSubmitCostSharingFlag() && lineItem.getSubmitCostSharingFlag()) {
            costSharingAmount = costSharingAmount.add(lineItem.getCostSharingAmount());
            List<BudgetLineItemCalculatedAmount> calculatedAmounts =
                lineItem.getBudgetCalculatedAmounts();
            for (BudgetLineItemCalculatedAmount budgetLineItemCalculatedAmount :
                calculatedAmounts) {
              costSharingAmount =
                  costSharingAmount.add(budgetLineItemCalculatedAmount.getCalculatedCostSharing());
            }
          }
        }
      }
      if (!hasBudgetLineItem && budget.getSubmitCostSharingFlag()) {
        costSharingAmount = budget.getCostSharingAmount();
      }
      fedNonFedCost = fedNonFedCost.add(costSharingAmount);

      for (BudgetProjectIncome budgetProjectIncome : budget.getBudgetProjectIncomes()) {
        totalProjectIncome =
            totalProjectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
      }

      funding = EstimatedProjectFunding.Factory.newInstance();
      funding.setTotalEstimatedAmount(budget.getTotalCost().bigDecimalValue());
      funding.setTotalfedNonfedrequested(fedNonFedCost.bigDecimalValue());
      funding.setEstimatedProgramIncome(totalProjectIncome);
    }
    return funding;
  }
 public void generateSubAwardLineItems(BudgetSubAwards subAward, Budget budget) {
   BudgetDecimal amountChargeFA = new BudgetDecimal(25000);
   String directLtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_DIRECT_LT_25K_PARAM);
   String directGtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_DIRECT_GT_25K_PARAM);
   String inDirectLtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_F_AND_A_LT_25K_PARAM);
   String inDirectGtCostElement =
       getParameterService()
           .getParameterValueAsString(
               BudgetDocument.class, Constants.SUBCONTRACTOR_F_AND_A_GT_25K_PARAM);
   for (BudgetSubAwardPeriodDetail detail : subAward.getBudgetSubAwardPeriodDetails()) {
     BudgetPeriod budgetPeriod = findBudgetPeriod(detail, budget);
     List<BudgetLineItem> currentLineItems =
         findSubAwardLineItems(budgetPeriod, subAward.getSubAwardNumber());
     // zero out existing line items before recalculating
     for (BudgetLineItem item : currentLineItems) {
       item.setDirectCost(BudgetDecimal.ZERO);
       item.setCostSharingAmount(BudgetDecimal.ZERO);
       item.setSubAwardNumber(subAward.getSubAwardNumber());
       item.setLineItemDescription(subAward.getOrganizationName());
     }
     if (BudgetDecimal.returnZeroIfNull(detail.getDirectCost()).isNonZero()
         || hasBeenChanged(detail, true)) {
       BudgetDecimal ltValue = lesserValue(detail.getDirectCost(), amountChargeFA);
       BudgetDecimal gtValue = detail.getDirectCost().subtract(ltValue);
       if (ltValue.isNonZero()) {
         BudgetLineItem lt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, directLtCostElement);
         lt.setLineItemCost(ltValue);
       }
       if (gtValue.isNonZero()) {
         BudgetLineItem gt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, directGtCostElement);
         gt.setLineItemCost(gtValue);
       }
       amountChargeFA = amountChargeFA.subtract(ltValue);
     }
     if (BudgetDecimal.returnZeroIfNull(detail.getIndirectCost()).isNonZero()
         || hasBeenChanged(detail, false)) {
       BudgetDecimal ltValue = lesserValue(detail.getIndirectCost(), amountChargeFA);
       BudgetDecimal gtValue = detail.getIndirectCost().subtract(ltValue);
       if (ltValue.isNonZero()) {
         BudgetLineItem lt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, inDirectLtCostElement);
         lt.setLineItemCost(ltValue);
       }
       if (gtValue.isNonZero()) {
         BudgetLineItem gt =
             findOrCreateLineItem(
                 currentLineItems, detail, subAward, budgetPeriod, inDirectGtCostElement);
         gt.setLineItemCost(gtValue);
       }
       amountChargeFA = amountChargeFA.subtract(ltValue);
     }
     Collections.sort(
         currentLineItems,
         new Comparator<BudgetLineItem>() {
           public int compare(BudgetLineItem arg0, BudgetLineItem arg1) {
             return arg0.getLineItemNumber().compareTo(arg1.getLineItemNumber());
           }
         });
     Iterator<BudgetLineItem> iter = currentLineItems.iterator();
     while (iter.hasNext()) {
       BudgetLineItem lineItem = iter.next();
       if (BudgetDecimal.returnZeroIfNull(lineItem.getLineItemCost()).isZero()) {
         budgetPeriod.getBudgetLineItems().remove(lineItem);
         iter.remove();
       } else {
         if (!budgetPeriod.getBudgetLineItems().contains(lineItem)) {
           budgetPeriod.getBudgetLineItems().add(lineItem);
         }
       }
     }
     if (!currentLineItems.isEmpty()
         && BudgetDecimal.returnZeroIfNull(detail.getCostShare()).isNonZero()) {
       currentLineItems.get(0).setCostSharingAmount(detail.getCostShare());
     }
   }
 }
  private boolean personnelDatesCheck(
      BudgetLineItem budgetLineItem,
      BudgetPersonnelDetails budgetPersonnelDetails,
      int selectedBudgetPeriodIndex,
      int selectedBudgetLineItemIndex,
      int detailIndex) {
    boolean errorFound = false;
    if (budgetPersonnelDetails.getEndDate().compareTo(budgetPersonnelDetails.getStartDate()) < 0) {
      GlobalVariables.getMessageMap()
          .putError(
              "budgetPeriod["
                  + selectedBudgetPeriodIndex
                  + "].budgetLineItems["
                  + selectedBudgetLineItemIndex
                  + "].budgetPersonnelDetailsList["
                  + detailIndex
                  + "].endDate",
              KeyConstants.ERROR_PERSONNEL_DETAIL_DATES);
      errorFound = true;
    }
    if (budgetLineItem.getEndDate().compareTo(budgetPersonnelDetails.getEndDate()) < 0) {
      GlobalVariables.getMessageMap()
          .putError(
              "budgetPeriod["
                  + selectedBudgetPeriodIndex
                  + "].budgetLineItems["
                  + selectedBudgetLineItemIndex
                  + "].budgetPersonnelDetailsList["
                  + detailIndex
                  + "].endDate",
              KeyConstants.ERROR_PERSONNEL_DETAIL_END_DATE,
              new String[] {"can not be after", "end date"});
      errorFound = true;
    }
    if (budgetLineItem.getStartDate().compareTo(budgetPersonnelDetails.getEndDate()) > 0) {
      GlobalVariables.getMessageMap()
          .putError(
              "budgetPeriod["
                  + selectedBudgetPeriodIndex
                  + "].budgetLineItems["
                  + selectedBudgetLineItemIndex
                  + "].budgetPersonnelDetailsList["
                  + detailIndex
                  + "].endDate",
              KeyConstants.ERROR_PERSONNEL_DETAIL_END_DATE,
              new String[] {"can not be before", "start date"});
      errorFound = true;
    }
    if (budgetLineItem.getStartDate().compareTo(budgetPersonnelDetails.getStartDate()) > 0) {
      GlobalVariables.getMessageMap()
          .putError(
              "budgetPeriod["
                  + selectedBudgetPeriodIndex
                  + "].budgetLineItems["
                  + selectedBudgetLineItemIndex
                  + "].budgetPersonnelDetailsList["
                  + detailIndex
                  + "].startDate",
              KeyConstants.ERROR_PERSONNEL_DETAIL_START_DATE,
              new String[] {"can not be before", "start date"});
      errorFound = true;
    }
    if (budgetLineItem.getEndDate().compareTo(budgetPersonnelDetails.getStartDate()) < 0) {
      GlobalVariables.getMessageMap()
          .putError(
              "budgetPeriod["
                  + selectedBudgetPeriodIndex
                  + "].budgetLineItems["
                  + selectedBudgetLineItemIndex
                  + "].budgetPersonnelDetailsList["
                  + detailIndex
                  + "].startDate",
              KeyConstants.ERROR_PERSONNEL_DETAIL_START_DATE,
              new String[] {"can not be after", "end date"});
      errorFound = true;
    }

    return errorFound;
  }
 /**
  * This method calculates the salary
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return mapping forward
  * @throws Exception
  */
 public ActionForward calculateSalary(
     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);
   BudgetPersonnelDetails budgetPersonnelDetails =
       selectedBudgetLineItem.getBudgetPersonnelDetailsList().get(getLineToDelete(request));
   boolean errorFound = false;
   GlobalVariables.getMessageMap().addToErrorPath("document");
   if (budgetPersonnelDetails.getPercentEffort().isGreaterThan(new BudgetDecimal(100))) {
     GlobalVariables.getMessageMap()
         .putError(
             "budgetPeriod["
                 + selectedBudgetPeriodIndex
                 + "].budgetLineItems["
                 + selectedBudgetLineItemIndex
                 + "].budgetPersonnelDetailsList["
                 + getLineToDelete(request)
                 + "].percentEffort",
             KeyConstants.ERROR_PERCENTAGE,
             Constants.PERCENT_EFFORT_FIELD);
     errorFound = true;
   }
   if (budgetPersonnelDetails.getPercentCharged().isGreaterThan(new BudgetDecimal(100))) {
     GlobalVariables.getMessageMap()
         .putError(
             "budgetPeriod["
                 + selectedBudgetPeriodIndex
                 + "].budgetLineItems["
                 + selectedBudgetLineItemIndex
                 + "].budgetPersonnelDetailsList["
                 + getLineToDelete(request)
                 + "].percentCharged",
             KeyConstants.ERROR_PERCENTAGE,
             Constants.PERCENT_CHARGED_FIELD);
     errorFound = true;
   }
   if (budgetPersonnelDetails
       .getPercentCharged()
       .isGreaterThan(budgetPersonnelDetails.getPercentEffort())) {
     GlobalVariables.getMessageMap()
         .putError(
             "budgetPeriod["
                 + selectedBudgetPeriodIndex
                 + "].budgetLineItems["
                 + selectedBudgetLineItemIndex
                 + "].budgetPersonnelDetailsList["
                 + getLineToDelete(request)
                 + "].percentCharged",
             KeyConstants.ERROR_PERCENT_EFFORT_LESS_THAN_PERCENT_CHARGED);
     errorFound = true;
   }
   errorFound =
       errorFound
           || personnelDatesCheck(
               selectedBudgetLineItem,
               budgetPersonnelDetails,
               selectedBudgetPeriodIndex,
               selectedBudgetLineItemIndex,
               getLineToDelete(request));
   if (!errorFound) {
     BudgetPersonnelBudgetService budgetPersonnelBudgetService =
         KraServiceLocator.getService(BudgetPersonnelBudgetService.class);
     budgetPersonnelBudgetService.calculateBudgetPersonnelBudget(
         budget, selectedBudgetLineItem, budgetPersonnelDetails, getLineToDelete(request));
   }
   return mapping.findForward(Constants.MAPPING_BASIC);
 }