Ejemplo n.º 1
0
 public ActionForward printBudgetForm(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   BudgetForm budgetForm = (BudgetForm) form;
   Budget budget = budgetForm.getBudgetDocument().getBudget();
   Integer selectedLine = getSelectedLine(request);
   String budgetFormToPrint = budget.getBudgetPrintForms().get(selectedLine).getBudgetReportId();
   if (budgetForm.getSelectedToPrintComment() != null && budgetFormToPrint != null) {
     String forms[] = budgetForm.getSelectedToPrintComment();
     if (forms[0].equals(budgetFormToPrint)) {
       budget.setPrintBudgetCommentFlag("true");
     }
   }
   budgetForm.setSelectedToPrintComment(null);
   BudgetPrintService budgetPrintService = KcServiceLocator.getService(BudgetPrintService.class);
   ActionForward forward = mapping.findForward(MAPPING_BASIC);
   if (budgetFormToPrint != null) {
     AttachmentDataSource dataStream =
         budgetPrintService.readBudgetPrintStream(budget, budgetFormToPrint);
     if (dataStream.getData() != null) {
       streamToResponse(dataStream, response);
       forward = null;
     }
   }
   return forward;
 }
  /**
   * This method returns the personnel calculated direct cost.
   *
   * @return
   */
  public Map<RateClassRateType, ScaleTwoDecimal> getPersonnelCalculatedDirectCost(
      Budget currentBudget, AwardBudgetExt previousBudget) {
    SortedMap<RateType, List<ScaleTwoDecimal>> currentTotals =
        currentBudget.getPersonnelCalculatedExpenseTotals();
    int period = currentBudget.getBudgetPeriods().size() - 1;
    Map<RateClassRateType, ScaleTwoDecimal> currentCost =
        new HashMap<RateClassRateType, ScaleTwoDecimal>();
    Map<RateClassRateType, ScaleTwoDecimal> netCost =
        new HashMap<RateClassRateType, ScaleTwoDecimal>();
    for (RateType rate : currentTotals.keySet()) {
      // For some reason indirect cost shows up in this, remove it.
      if (!StringUtils.equalsIgnoreCase(rate.getRateClass().getRateClassTypeCode(), "O")) {
        LOG.info(
            "Rate Class: " + rate.getRateClassCode() + "RateType: " + rate.getRateTypeCode() + "");
        currentCost.put(
            new RateClassRateType(rate.getRateClassCode(), rate.getRateTypeCode()),
            currentTotals.get(rate).get(period));
      }
    }

    for (RateClassRateType rate : currentCost.keySet()) {
      netCost.put(rate, currentCost.get(rate));
    }

    return netCost;
  }
Ejemplo n.º 3
0
 @Test
 public void testTotalingProjectIncomesForPeriod() throws Exception {
   Assert.assertEquals(7, document.getBudgetProjectIncomes().size());
   Assert.assertEquals(4, document.getProjectIncomePeriodTotalsForEachBudgetPeriod().size());
   Assert.assertEquals(_1K, extractPeriodTotal(document.getBudgetPeriod(0)), 0.01);
   Assert.assertEquals(_2K, extractPeriodTotal(document.getBudgetPeriod(1)), 0.01);
   Assert.assertEquals(_3K + _500, extractPeriodTotal(document.getBudgetPeriod(2)), 0.01);
   Assert.assertEquals(_4K + _500 + _1K, extractPeriodTotal(document.getBudgetPeriod(3)), 0.01);
 }
 /**
  * Determines if the given {@link List} of {@link Budget} instances contains the given {@link
  * Budget}. It does this by getting the name of the {@link Budget} and compares it to those in the
  * {@link List}. We use this to prevent duplicate names among {@link Budget} instances.
  *
  * @param existingBudgets {@link List} of {@link Budget} instances
  * @param versionName is the name of the {@link Budget} to look for
  * @return true if it found <code>versionName</code> inside <code>existingBudgets</code>, false
  *     otherwise
  */
 protected boolean containsVersionName(
     List<? extends Budget> existingBudgets, String versionName) {
   for (Budget version : existingBudgets) {
     LOG.info("Comparing " + version.getName() + " to " + versionName);
     if (version.getName().equals(versionName)) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 5
0
 @Before
 public void setUp() throws Exception {
   initializeDocument();
   document.add(createBudgetProjectIncome(document.getBudgetPeriod(0), _1K));
   document.add(createBudgetProjectIncome(document.getBudgetPeriod(1), _2K));
   document.add(createBudgetProjectIncome(document.getBudgetPeriod(2), _3K));
   document.add(createBudgetProjectIncome(document.getBudgetPeriod(2), _500));
   document.add(createBudgetProjectIncome(document.getBudgetPeriod(3), _4K));
   document.add(createBudgetProjectIncome(document.getBudgetPeriod(3), _500));
   document.add(createBudgetProjectIncome(document.getBudgetPeriod(3), _1K));
 }
Ejemplo n.º 6
0
  @Test
  public void testTotalingProjectIncomesForBudgetDocument() throws Exception {
    Assert.assertEquals(
        _1K + _2K + _3K + _500 + _4K + _500 + _1K,
        document.getProjectIncomeTotal().doubleValue(),
        0.01);

    double total = 0.0;
    for (BudgetPeriod bp : document.getBudgetPeriods()) {
      total += extractPeriodTotal(bp);
    }

    Assert.assertEquals(total, document.getProjectIncomeTotal().doubleValue(), 0.01);
  }
  /*
   * Returns the non personnel calculated direct cost.
   */
  public SortedMap<RateType, ScaleTwoDecimal> getNonPersonnelCalculatedDirectCost(
      Budget currentBudget, AwardBudgetExt previousBudget) {
    SortedMap<RateType, List<ScaleTwoDecimal>> currentNonPersonnelCalcDirectCost =
        currentBudget.getNonPersonnelCalculatedExpenseTotals();
    SortedMap<RateType, ScaleTwoDecimal> netNonPersonnelCalculatedDirectCost =
        new TreeMap<RateType, ScaleTwoDecimal>();
    int period = currentBudget.getBudgetPeriods().size() - 1;

    for (RateType rateType : currentNonPersonnelCalcDirectCost.keySet()) {
      List<ScaleTwoDecimal> currentExpenses = currentNonPersonnelCalcDirectCost.get(rateType);
      netNonPersonnelCalculatedDirectCost.put(rateType, currentExpenses.get(period));
    }
    return netNonPersonnelCalculatedDirectCost;
  }
Ejemplo n.º 8
0
  @SuppressWarnings("serial")
  private void initializeDocument() {
    document =
        new Budget() {
          // stub out method to avoid loading Spring and database
          @Override
          public Integer getNextValue(String propertyName) {
            return nextValue++;
          }
        };

    document.add(createBudgetPeriod(1, 2007));
    document.add(createBudgetPeriod(2, 2008));
    document.add(createBudgetPeriod(3, 2009));
    document.add(createBudgetPeriod(4, 2010));
  }
  @KcEventMethod
  public boolean processApplyToLaterPeriodsWithPersonnelDetails(ApplyToPeriodsBudgetEvent event) {
    MessageMap errorMap = getGlobalVariableService().getMessageMap();
    Budget budget = event.getBudget();
    BudgetLineItem budgetLineItem = event.getBudgetLineItem();

    List<BudgetPeriod> budgetPeriods = budget.getBudgetPeriods();
    BudgetLineItem prevBudgetLineItem = budgetLineItem;
    for (BudgetPeriod budgetPeriod : budgetPeriods) {
      if (budgetPeriod.getBudgetPeriod() <= event.getBudgetPeriod().getBudgetPeriod()) continue;
      QueryList<BudgetLineItem> currentBudgetPeriodLineItems =
          new QueryList<BudgetLineItem>(budgetPeriod.getBudgetLineItems());
      for (BudgetLineItem budgetLineItemToBeApplied : currentBudgetPeriodLineItems) {
        if (prevBudgetLineItem
            .getLineItemNumber()
            .equals(budgetLineItemToBeApplied.getBasedOnLineItem())) {
          if (budgetLineItemToBeApplied
                  .getBudgetCategory()
                  .getBudgetCategoryTypeCode()
                  .equals(PERSONNEL_CATEGORY)
              && (!budgetLineItemToBeApplied.getBudgetPersonnelDetailsList().isEmpty()
                  || !prevBudgetLineItem.getBudgetPersonnelDetailsList().isEmpty())) {
            errorMap.putError(
                event.getErrorPath() + COST_ELEMENT,
                KeyConstants.ERROR_APPLY_TO_LATER_PERIODS,
                budgetLineItemToBeApplied.getBudgetPeriod().toString());
            return false;
          }
        } else if (StringUtils.equals(
            budgetLineItem.getBudgetCategory().getBudgetCategoryTypeCode(), PERSONNEL_CATEGORY)) {
          // Additional Check for Personnel Source Line Item
          if (StringUtils.equals(
                  budgetLineItem.getCostElement(), budgetLineItemToBeApplied.getCostElement())
              && StringUtils.equals(
                  budgetLineItem.getGroupName(), budgetLineItemToBeApplied.getGroupName())) {
            errorMap.putError(
                event.getErrorPath() + COST_ELEMENT,
                KeyConstants.ERROR_PERSONNELLINEITEM_APPLY_TO_LATER_PERIODS,
                budgetLineItemToBeApplied.getBudgetPeriod().toString());
            return false;
          }
        }
      }
    }

    return true;
  }
Ejemplo n.º 10
0
 public void setBudget(Budget budget) {
   this.budget = budget;
   if (budget != null) {
     this.budgetId = budget.getBudgetId();
   } else {
     budgetId = null;
   }
 }
  /**
   * In order to decrease or increase, the change amount is used, so this can be sent as is without
   * subtracting from previous budget.
   *
   * @return
   */
  public HashMap<String, ScaleTwoDecimal> getNonPersonnelCost(
      Budget currentBudget, AwardBudgetExt previousBudget) {
    HashMap<String, ScaleTwoDecimal> netCost = new HashMap<String, ScaleTwoDecimal>();
    // only do for one period, assume it is the first
    int period = currentBudget.getBudgetPeriods().size() - 1;
    List<BudgetLineItem> currentLineItems =
        currentBudget.getBudgetPeriods().get(period).getBudgetLineItems();

    HashMap<String, ScaleTwoDecimal> currentLineItemCosts = new HashMap<String, ScaleTwoDecimal>();
    for (BudgetLineItem currentLineItem : currentLineItems) {
      if (!StringUtils.equalsIgnoreCase(
          currentLineItem.getBudgetCategory().getBudgetCategoryTypeCode(), "P")) {
        currentLineItemCosts.put(
            currentLineItem.getCostElement(), currentLineItem.getLineItemCost());
      }
    }

    return currentLineItemCosts;
  }
  /**
   * This method returns the personnel salary cost.
   *
   * @return
   * @throws Exception
   */
  public SortedMap<String, ScaleTwoDecimal> getPersonnelSalaryCost(
      Budget currentBudget, AwardBudgetExt previousBudget) throws Exception {
    SortedMap<String, List<ScaleTwoDecimal>> currentSalaryTotals =
        currentBudget.getObjectCodePersonnelSalaryTotals();
    SortedMap<String, ScaleTwoDecimal> netSalary = new TreeMap<String, ScaleTwoDecimal>();
    int period = currentBudget.getBudgetPeriods().size() - 1;

    for (String person : currentSalaryTotals.keySet()) {
      String key = person;
      if (person.contains(",")) {
        String[] objectCode = getElements(key);
        key = objectCode[0];
      }
      ScaleTwoDecimal currentSalary = currentSalaryTotals.get(person).get(period);
      netSalary.put(key, currentSalary);
    }

    return netSalary;
  }
  @KcEventMethod
  public KcEventResult processBudgetLineItemExpenseRules(BudgetExpensesRuleEvent event) {
    KcEventResult result = new KcEventResult();
    Budget budget = event.getBudget();

    if (budget.getTotalCostLimit().isGreaterThan(new ScaleTwoDecimal(0))
        && budget.getTotalCost().isGreaterThan(budget.getTotalCostLimit())) {
      result
          .getMessageMap()
          .putWarning(event.getErrorPath(), KeyConstants.WARNING_TOTAL_COST_LIMIT_EXCEEDED);
    }

    if (budget.getTotalDirectCostLimit().isGreaterThan(new ScaleTwoDecimal(0))
        && budget.getTotalDirectCost().isGreaterThan(budget.getTotalDirectCostLimit())) {
      result
          .getMessageMap()
          .putWarning(event.getErrorPath(), KeyConstants.WARNING_TOTAL_DIRECT_COST_LIMIT_EXCEEDED);
    }

    String errorPath = BUDGET_PERSONNEL_COST_DETAILS_ID;
    if (event
        .getErrorPath()
        .equalsIgnoreCase(BudgetConstants.BudgetAuditRules.NON_PERSONNEL_COSTS.getPageId())) {
      errorPath = BUDGET_NON_PERSONNEL_COST_DETAILS_ID;
    }

    for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
      if (budgetPeriod.getTotalCostLimit().isGreaterThan(new ScaleTwoDecimal(0))
          && budgetPeriod.getTotalCost().isGreaterThan(budgetPeriod.getTotalCostLimit())) {
        result
            .getMessageMap()
            .putWarning(
                errorPath + "_" + budgetPeriod.getBudgetPeriod(),
                KeyConstants.WARNING_PERIOD_COST_LIMIT_EXCEEDED,
                new String[] {budgetPeriod.getBudgetPeriod().toString()});
      }
      if (budgetPeriod.getDirectCostLimit().isGreaterThan(new ScaleTwoDecimal(0))
          && budgetPeriod.getTotalDirectCost().isGreaterThan(budgetPeriod.getDirectCostLimit())) {
        result
            .getMessageMap()
            .putWarning(
                errorPath + "_" + budgetPeriod.getBudgetPeriod(),
                KeyConstants.WARNING_PERIOD_DIRECT_COST_LIMIT_EXCEEDED,
                new String[] {budgetPeriod.getBudgetPeriod().toString()});
      }
    }
    return result;
  }
  /**
   * This method returns the indirect cost for the accounting line.
   *
   * @return
   */
  public Map<RateClassRateType, ScaleTwoDecimal> getIndirectCost(
      Budget currentBudget, AwardBudgetExt previousBudget) {
    int period = currentBudget.getBudgetPeriods().size() - 1;
    List<BudgetLineItem> currentLineItems =
        currentBudget.getBudgetPeriods().get(period).getBudgetLineItems();
    Map<RateClassRateType, ScaleTwoDecimal> currentIndirectTotals =
        new HashMap<RateClassRateType, ScaleTwoDecimal>();

    for (BudgetLineItem lineItem : currentLineItems) {
      for (BudgetLineItemCalculatedAmount lineItemCalculatedAmount :
          lineItem.getBudgetLineItemCalculatedAmounts()) {
        lineItemCalculatedAmount.refreshReferenceObject("rateClass");
        if (lineItemCalculatedAmount.getRateClass().getRateClassTypeCode().equalsIgnoreCase("O")) {
          RateClassRateType currentKey =
              new RateClassRateType(
                  lineItemCalculatedAmount.getRateClassCode(),
                  lineItemCalculatedAmount.getRateTypeCode());
          if (currentIndirectTotals.containsKey(currentKey)) {
            currentIndirectTotals.put(
                currentKey,
                currentIndirectTotals
                    .get(currentKey)
                    .add(lineItemCalculatedAmount.getCalculatedCost()));
          } else {
            currentIndirectTotals.put(currentKey, lineItemCalculatedAmount.getCalculatedCost());
          }
        }
      }
    }

    Map<RateClassRateType, ScaleTwoDecimal> netIndirectTotals =
        new HashMap<RateClassRateType, ScaleTwoDecimal>();
    for (RateClassRateType rate : currentIndirectTotals.keySet()) {
      netIndirectTotals.put(rate, currentIndirectTotals.get(rate));
    }

    return netIndirectTotals;
  }
Ejemplo n.º 15
0
 /*
  * Check if this budget person has any budgetdetail set.  This is called before checking whether
  * this person can be deleted.  If retrieve from DB, then it might not be correct because
  * the deleted detail may have not been persisted before delete person is called.
  */
 private boolean isPersonDetailsFound(Budget budget, BudgetPerson budgetPerson) {
   for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
     for (BudgetLineItem lineItem : budgetPeriod.getBudgetLineItems()) {
       for (BudgetPersonnelDetails budgetPersonnelDetail :
           lineItem.getBudgetPersonnelDetailsList()) {
         if (budgetPersonnelDetail
             .getPersonSequenceNumber()
             .equals(budgetPerson.getPersonSequenceNumber())) {
           return true;
         }
       }
     }
   }
   return false;
 }
  /*
   * The BudgetCalculationService does this by objectCodeType but we need by RateClass,RateType.
   */
  public Map<RateClassRateType, ScaleTwoDecimal> getPersonnelFringeCost(
      Budget currentBudget, AwardBudgetExt previousBudget) {

    BudgetCategoryType personnelCategory = getPersonnelCategoryType();
    List<CostElement> currentPersonnelObjectCodes =
        currentBudget.getObjectCodeListByBudgetCategoryType().get(personnelCategory);

    Map<RateClassRateType, ScaleTwoDecimal> currentFringeTotals =
        getFringeTotals(currentPersonnelObjectCodes, currentBudget);
    Map<RateClassRateType, ScaleTwoDecimal> netFringeTotals =
        new HashMap<RateClassRateType, ScaleTwoDecimal>();
    for (RateClassRateType rate : currentFringeTotals.keySet()) {
      netFringeTotals.put(rate, currentFringeTotals.get(rate));
    }

    return netFringeTotals;
  }
  /**
   * This method returns the fringe totals.
   *
   * @param currentPersonnelObjectCodes
   * @param budget
   * @return
   */
  protected Map<RateClassRateType, ScaleTwoDecimal> getFringeTotals(
      List<CostElement> currentPersonnelObjectCodes, Budget budget) {
    /*
     * Things like Animal care and Travel also have a rateClassType of E so need to filter that
     * out to only get Personnel
     */
    Map<RateClassRateType, ScaleTwoDecimal> fringeTotals =
        new HashMap<RateClassRateType, ScaleTwoDecimal>();

    if (CollectionUtils.isNotEmpty(currentPersonnelObjectCodes)) {
      for (CostElement personnelCostElement : currentPersonnelObjectCodes) {
        for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
          List<BudgetLineItem> filteredLineItems =
              getPersonnelLineItems(budgetPeriod, personnelCostElement);
          for (BudgetLineItem lineItem : filteredLineItems) {
            for (BudgetLineItemCalculatedAmount lineItemCalculatedAmount :
                lineItem.getBudgetLineItemCalculatedAmounts()) {
              lineItemCalculatedAmount.refreshReferenceObject("rateClass");
              // Check for Employee Benefits RateClassType
              if (lineItemCalculatedAmount
                  .getRateClass()
                  .getRateClassTypeCode()
                  .equalsIgnoreCase("E")) {
                RateClassRateType currentKey =
                    new RateClassRateType(
                        lineItemCalculatedAmount.getRateClassCode(),
                        lineItemCalculatedAmount.getRateTypeCode());
                if (fringeTotals.containsKey(currentKey)) {
                  fringeTotals.put(
                      currentKey,
                      fringeTotals
                          .get(currentKey)
                          .add(lineItemCalculatedAmount.getCalculatedCost()));
                } else {
                  fringeTotals.put(currentKey, lineItemCalculatedAmount.getCalculatedCost());
                }
              }
            }
          }
        }
      }
    }
    return fringeTotals;
  }
Ejemplo n.º 18
0
  @SuppressWarnings("unchecked")
  private List<ValidCeJobCode> getApplicableCostElements(
      Budget budget, BudgetPersonnelDetails newBudgetPersonnelDetails, boolean save) {
    List<ValidCeJobCode> validCostElements = null;

    if (save) {
      String jobCodeValidationEnabledInd =
          this.paramService.getParameterValueAsString(
              Budget.class, Constants.BUDGET_JOBCODE_VALIDATION_ENABLED);

      Map<String, Object> fieldValues = new HashMap<String, Object>();
      BudgetPerson budgetPerson = null;

      if (StringUtils.isNotEmpty(jobCodeValidationEnabledInd)
          && jobCodeValidationEnabledInd.equals("Y")) {

        List<BudgetPerson> budgetPersons = budget.getBudgetPersons();
        for (BudgetPerson tmpBudgetPerson : budgetPersons) {
          if (tmpBudgetPerson.getPersonSequenceNumber().intValue()
              == newBudgetPersonnelDetails.getPersonSequenceNumber().intValue()) {
            budgetPerson = tmpBudgetPerson;
            break;
          }
        }
        if (budgetPerson != null && StringUtils.isNotEmpty(budgetPerson.getJobCode())) {
          fieldValues.put("jobCode", budgetPerson.getJobCode().toUpperCase());
          validCostElements =
              (List<ValidCeJobCode>) this.boService.findMatching(ValidCeJobCode.class, fieldValues);
        }
      }

    } else {
      validCostElements =
          budgetPersonService.getApplicableCostElements(
              budget, newBudgetPersonnelDetails.getPersonSequenceNumber().toString());
    }

    return validCostElements;
  }
Ejemplo n.º 19
0
 private double extractPeriodTotal(BudgetPeriod budgetPeriod) {
   return document
       .getProjectIncomePeriodTotalsForEachBudgetPeriod()
       .get(budgetPeriod.getBudgetPeriod() - 1)
       .doubleValue();
 }
Ejemplo n.º 20
0
 private BudgetSubAwards getSelectedBudgetSubAward(ActionForm form, HttpServletRequest request) {
   BudgetForm budgetForm = (BudgetForm) form;
   Budget budget = budgetForm.getBudgetDocument().getBudget();
   int selectedLineNumber = getSelectedLine(request);
   return budget.getBudgetSubAwards().get(selectedLineNumber);
 }
Ejemplo n.º 21
0
 public void setBudget(Budget budget) {
   this.budget = budget;
   this.budgetId = budget != null ? budget.getBudgetId() : null;
 }