Example #1
0
  /**
   * Validate budget project income. costshare percentage must be between 0 and 999.99
   *
   * @param budgetDocument
   * @return
   */
  protected boolean processBudgetProjectIncomeBusinessRule(BudgetDocument budgetDocument) {
    boolean valid = true;
    MessageMap errorMap = GlobalVariables.getMessageMap();
    int i = 0;
    for (BudgetCostShare budgetCostShare : budgetDocument.getBudget().getBudgetCostShares()) {
      String errorPath = "budgetCostShare[" + i + "]";
      errorMap.addToErrorPath(errorPath);
      if (budgetCostShare.getSharePercentage() != null
          && (budgetCostShare.getSharePercentage().isLessThan(new ScaleTwoDecimal(0))
              || budgetCostShare.getSharePercentage().isGreaterThan(new ScaleTwoDecimal(100)))) {
        errorMap.putError("sharePercentage", KeyConstants.ERROR_COST_SHARE_PERCENTAGE);
        valid = false;
      }
      // check for duplicate fiscal year and source accounts on all unchecked cost shares
      if (i < budgetDocument.getBudget().getBudgetCostShareCount()) {
        for (int j = i + 1; j < budgetDocument.getBudget().getBudgetCostShareCount(); j++) {
          BudgetCostShare tmpCostShare = budgetDocument.getBudget().getBudgetCostShare(j);
          int thisFiscalYear =
              budgetCostShare.getProjectPeriod() == null
                  ? Integer.MIN_VALUE
                  : budgetCostShare.getProjectPeriod();
          int otherFiscalYear =
              tmpCostShare.getProjectPeriod() == null
                  ? Integer.MIN_VALUE
                  : tmpCostShare.getProjectPeriod();
          if (thisFiscalYear == otherFiscalYear
              && StringUtils.equalsIgnoreCase(
                  budgetCostShare.getSourceAccount(), tmpCostShare.getSourceAccount())) {
            errorMap.putError(
                "fiscalYear",
                KeyConstants.ERROR_COST_SHARE_DUPLICATE,
                thisFiscalYear == Integer.MIN_VALUE ? "" : thisFiscalYear + "",
                budgetCostShare.getSourceAccount() == null
                    ? "\"\""
                    : budgetCostShare.getSourceAccount());
            valid = false;
          }
        }
      }

      // validate project period stuff
      String currentField = "document.budget.budgetCostShare[" + i + "].projectPeriod";
      int numberOfProjectPeriods = budgetDocument.getBudget().getBudgetPeriods().size();
      boolean validationCheck =
          this.validateProjectPeriod(
              budgetCostShare.getProjectPeriod(), currentField, numberOfProjectPeriods);
      valid &= validationCheck;

      errorMap.removeFromErrorPath(errorPath);
      i++;
    }
    // check project income for values that are not greater than 0
    GlobalVariables.getMessageMap().removeFromErrorPath("budget");
    GlobalVariables.getMessageMap().addToErrorPath("budgets[0]");
    i = 0;
    for (BudgetProjectIncome budgetProjectIncome :
        budgetDocument.getBudget().getBudgetProjectIncomes()) {
      String errorPath = "budgetProjectIncomes[" + i + "]";
      errorMap.addToErrorPath(errorPath);
      if (budgetProjectIncome.getProjectIncome() == null
          || !budgetProjectIncome.getProjectIncome().isGreaterThan(new ScaleTwoDecimal(0.00))) {
        errorMap.putError("projectIncome", "error.projectIncome.negativeOrZero");
        valid = false;
      }
      errorMap.removeFromErrorPath(errorPath);
      i++;
    }
    GlobalVariables.getMessageMap().removeFromErrorPath("budgets[0]");
    GlobalVariables.getMessageMap().addToErrorPath("budget");

    return valid;
  }
Example #2
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;
  }