private boolean budgetPersonnelDetailsCheck(
      Budget budget, BudgetLineItem budgetLineItem, String errorPath) {
    boolean valid = true;
    boolean validJobCodeCECombo = false;

    int k = 0;
    for (BudgetPersonnelDetails budgetPersonnelDetails :
        budgetLineItem.getBudgetPersonnelDetailsList()) {
      String detailsErrorPath = errorPath + ".budgetPersonnelDetailsList[" + k + "]";
      valid &=
          !(personnelDetailsCheck(
              budget, budgetLineItem, budgetPersonnelDetails, detailsErrorPath));

      validJobCodeCECombo =
          processCheckJobCodeObjectCodeCombo(budget, budgetPersonnelDetails, true);
      if (!validJobCodeCECombo) {
        GlobalVariables.getMessageMap()
            .putError(
                detailsErrorPath + ".personSequenceNumber",
                KeyConstants.ERROR_SAVE_JOBCODE_COST_ELEMENT_COMBO_INVALID);
      }
      valid &= validJobCodeCECombo;
      k++;
    }

    return valid;
  }
  @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;
  }
 protected boolean isBudgetPersonExistsInPersonnelDetails(
     List<BudgetLineItem> budgetLineItems, BudgetPerson budgetPerson) {
   for (BudgetLineItem budgetLineItem : budgetLineItems) {
     for (BudgetPersonnelDetails budgetPersonnelDetails :
         budgetLineItem.getBudgetPersonnelDetailsList()) {
       if (budgetPersonnelDetails
           .getPersonSequenceNumber()
           .equals(budgetPerson.getPersonSequenceNumber())) {
         return true;
       }
     }
   }
   return false;
 }
  /**
   * Gets a Collection of sequence numbers from every lines items personnel details
   *
   * @param budgetLineItems the lines items
   * @return Collection of sequence numbers
   */
  private Collection<Integer> getBudgetPersonSequencesFromPersonnelDetails(
      final Collection<BudgetLineItem> budgetLineItems) {
    assert budgetLineItems != null : "the budgetLineItems is null";

    final Collection<Integer> budgetPersonSequences = new ArrayList<Integer>();

    for (final BudgetLineItem budgetLineItem : budgetLineItems) {
      for (final BudgetPersonnelDetails budgetPersonnelDetails :
          budgetLineItem.getBudgetPersonnelDetailsList()) {
        budgetPersonSequences.add(budgetPersonnelDetails.getPersonSequenceNumber());
      }
    }
    return budgetPersonSequences;
  }
 /*
  * 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;
 }
  protected BudgetLineItem getPersonnelLineItem(
      BudgetPeriod budgetPeriod, Date startDate, Date endDate) {
    BudgetLineItem lineItem = new BudgetLineItemMock();
    lineItem.setBudgetCategory(createBudgetCategory("26", "Test", "E"));
    lineItem.setBudgetCategoryCode("26");
    lineItem.setCostElement("400350");
    lineItem.setLineItemCost(new ScaleTwoDecimal(10000.00));
    lineItem.setEndDate(endDate);
    lineItem.setStartDate(startDate);
    lineItem.setCostElementBO(getCostElementTravel());
    lineItem.setApplyInRateFlag(Boolean.TRUE);
    lineItem.setOnOffCampusFlag(Boolean.TRUE);
    lineItem.setBudgetPeriodBO(budgetPeriod);
    lineItem.setBudgetPeriod(1);
    lineItem.setBudgetLineItemId(5L);
    lineItem.setLineItemNumber(3);
    lineItem.setBudgetCategoryCode(PERSONNEL_CATEGORY_CODE);
    final BudgetCategory budgetCategory = new BudgetCategory();
    budgetCategory.setBudgetCategoryTypeCode(PERSONNEL_CATEGORY_CODE);
    lineItem.setBudgetCategory(budgetCategory);

    BudgetPersonnelDetails budgetPersonnelDetails = new BudgetPersonnelDetails();
    budgetPersonnelDetails.setLineItemNumber(3);
    budgetPersonnelDetails.setPersonNumber(1);
    budgetPersonnelDetails.setOnOffCampusFlag(Boolean.TRUE);
    budgetPersonnelDetails.setEndDate(endDate);
    budgetPersonnelDetails.setStartDate(startDate);
    budgetPersonnelDetails.setApplyInRateFlag(Boolean.TRUE);
    budgetPersonnelDetails.setJobCode("AA000");
    budgetPersonnelDetails.setPercentCharged(ScaleTwoDecimal.ONE_HUNDRED);
    budgetPersonnelDetails.setPercentEffort(ScaleTwoDecimal.ONE_HUNDRED);
    budgetPersonnelDetails.setPersonId("10000000002");
    budgetPersonnelDetails.setSalaryRequested(new ScaleTwoDecimal(102000L));
    budgetPersonnelDetails.setCostElement("400350");
    budgetPersonnelDetails.setCostElementBO(getCostElementPersonnel());
    budgetPersonnelDetails.setBudgetLineItem(lineItem);
    budgetPersonnelDetails.setBudgetPeriod(1);
    budgetPersonnelDetails.setBudgetPeriodBO(budgetPeriod);
    lineItem.getBudgetPersonnelDetailsList().add(budgetPersonnelDetails);
    lineItem.setCostElementBO(getCostElementPersonnel());
    return lineItem;
  }
  /**
   * Updates personnel details job code from a person's job code.
   *
   * @param budgetLineItems the lines items
   * @param person the person
   */
  private void updateJobCodeOnDetailsFromPerson(
      final Collection<BudgetLineItem> budgetLineItems, final BudgetPerson person) {
    assert budgetLineItems != null : "the budgetLineItems is null";
    assert person != null : "the person is null";

    if (person.getJobCode() == null) {
      return;
    }

    for (final BudgetLineItem budgetLineItem : budgetLineItems) {
      for (final BudgetPersonnelDetails budgetPersonnelDetails :
          budgetLineItem.getBudgetPersonnelDetailsList()) {
        if (person
            .getPersonSequenceNumber()
            .equals(budgetPersonnelDetails.getPersonSequenceNumber())) {
          budgetPersonnelDetails.setJobCode(person.getJobCode());
        }
      }
    }
  }
Esempio n. 8
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;
  }