@KcEventMethod
  public boolean processCheckBaseSalaryFormat(BudgetSaveEvent event) {
    boolean valid = true;

    MessageMap messageMap = GlobalVariables.getMessageMap();
    int i = 0;
    List<BudgetPerson> budgetPersons = event.getBudget().getBudgetPersons();
    for (BudgetPerson budgetPerson : budgetPersons) {
      if (budgetPerson.getCalculationBase() == null) {
        messageMap.putError(
            BUDGET_PERSONS_FIELD_NAME_START + i + BUDGET_PERSONS_FIELD_NAME_CALC_BASE,
            RiceKeyConstants.ERROR_REQUIRED,
            new String[] {"Base Salary"});
        valid = false;
      } else if (budgetPerson.getCalculationBase().isNegative()) {
        messageMap.putError(
            BUDGET_PERSONS_FIELD_NAME_START + i + BUDGET_PERSONS_FIELD_NAME_CALC_BASE,
            KeyConstants.ERROR_NEGATIVE_AMOUNT,
            new String[] {"Base Salary"});
        valid = false;
      }
      i++;
    }

    return valid;
  }
  /**
   * Validates a single collection activity document detail object.
   *
   * @param event The object to get validated.
   * @return Returns true if all validations succeed otherwise false.
   */
  public boolean validateEvent(Event event) {
    MessageMap errorMap = GlobalVariables.getMessageMap();

    boolean isValid = true;

    int originalErrorCount = errorMap.getErrorCount();
    // call the DD validation which checks basic data integrity
    SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(event);
    isValid = (errorMap.getErrorCount() == originalErrorCount);

    if (ObjectUtils.isNotNull(event.isFollowup())
        && event.isFollowup()
        && event.getFollowupDate() == null) {
      errorMap.putError(
          ArPropertyConstants.EventFields.FOLLOW_UP_DATE,
          ArKeyConstants.CollectionActivityDocumentErrors.ERROR_FOLLOW_UP_DATE_REQUIRED);
      isValid = false;
    }
    if (ObjectUtils.isNotNull(event.isCompleted())
        && event.isCompleted()
        && event.getCompletedDate() == null) {
      errorMap.putError(
          ArPropertyConstants.EventFields.COMPLETED_DATE,
          ArKeyConstants.CollectionActivityDocumentErrors.ERROR_COMPLETED_DATE_REQUIRED);
      isValid = false;
    }
    return isValid;
  }
Esempio n. 3
0
  /**
   * This method checks business rules related to Budget Expenses functionality
   *
   * @param budgetDocument
   * @return
   */
  protected boolean processBudgetExpenseBusinessRules(BudgetDocument budgetDocument) {
    boolean valid = true;

    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.getQuantity() != null
            && budgetLineItem.getQuantity().intValue() < 0) {
          errorMap.putError(
              "budgetPeriod[" + i + "].budgetLineItem[" + j + "].quantity",
              KeyConstants.ERROR_NEGATIVE_AMOUNT,
              "Quantity");
          valid = false;
        }

        j++;
      }
      i++;
    }
    return valid;
  }
  /**
   * @see
   *     org.kuali.rice.kns.maintenance.KualiMaintainableImpl#processAfterEdit(org.kuali.rice.kns.document.MaintenanceDocument,
   *     java.util.Map)
   */
  @Override
  public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> parameters) {
    List<ErrorMessage> errorMessages = null;
    AgencyStagingData agency =
        (AgencyStagingData) document.getNewMaintainableObject().getBusinessObject();

    if (TemConstants.ExpenseImportTypes.IMPORT_BY_TRIP.equals(agency.getImportBy())) {
      errorMessages = getExpenseImportByTripService().validateAgencyData(agency);
    } else if (TemConstants.ExpenseImportTypes.IMPORT_BY_TRAVELLER.equals(agency.getImportBy())) {
      errorMessages = getExpenseImportByTravelerService().validateAgencyData(agency);
    }

    if (errorMessages.isEmpty()) {
      agency.setErrorCode(AgencyStagingDataErrorCodes.AGENCY_NO_ERROR);
    }

    MessageMap messageMap = GlobalVariables.getMessageMap();
    for (ErrorMessage message : errorMessages) {
      messageMap.putError(
          KFSConstants.GLOBAL_ERRORS, message.getErrorKey(), message.getMessageParameters());
    }

    updateCreditCardAgency(
        (AgencyStagingData) document.getNewMaintainableObject().getBusinessObject());

    super.processAfterEdit(document, parameters);
  }
  /*
   * ensure the uniqueness of award type/basis of payment
   */
  private boolean validateUniqueueCodes(
      final AwardType awardType, final AwardBasisOfPayment basisOfPayment) {

    boolean valid = true;
    if (awardType != null
        && basisOfPayment != null
        && StringUtils.isNotBlank(awardType.getAwardTypeCode().toString())
        && StringUtils.isNotBlank(basisOfPayment.getBasisOfPaymentCode())) {
      final Map<String, String> pkMap = new HashMap<String, String>();
      pkMap.put("awardTypeCode", awardType.getAwardTypeCode().toString());
      pkMap.put("basisOfPaymentCode", basisOfPayment.getBasisOfPaymentCode());
      final int matchingCount =
          KraServiceLocator.getService(BusinessObjectService.class)
              .countMatching(ValidAwardBasisPayment.class, pkMap);

      if (matchingCount > 0) {
        final MessageMap errorMap = GlobalVariables.getMessageMap();
        errorMap.putError(
            "document.newMaintainableObject.awardTypeCode",
            KeyConstants.ERROR_AWARD_BASIS_EXIST,
            new String[] {awardType.getDescription(), basisOfPayment.getDescription()});
        valid = false;
      }
    }
    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;
  }
  /**
   * This method checks budget versions business rules.
   *
   * @param budgetParentDocument the document
   * @param runDatactionaryValidation if dd validation should be run
   * @return true if valid false if not
   * @throws NullPointerException if the proposalDevelopmentDocument is null
   */
  protected boolean processBudgetVersionsBusinessRule(
      final BudgetParentDocument budgetParentDocument, final boolean runDatactionaryValidation) {
    if (budgetParentDocument == null) {
      throw new NullPointerException("the parentDocument is null.");
    }

    boolean valid = true;
    final MessageMap errorMap = GlobalVariables.getMessageMap();
    boolean finalVersionFound = false;

    final DictionaryValidationService dictionaryValidationService =
        getKnsDictionaryValidationService();

    int index = 0;
    for (BudgetDocumentVersion budgetDocumentVersion :
        budgetParentDocument.getBudgetDocumentVersions()) {
      BudgetVersionOverview budgetVersion = budgetDocumentVersion.getBudgetVersionOverview();
      if (runDatactionaryValidation) {
        dictionaryValidationService.validateBusinessObject(budgetVersion, true);
      }
      if (budgetVersion.isFinalVersionFlag()) {
        if (finalVersionFound) {
          errorMap.putError("finalVersionFlag", KeyConstants.ERROR_MULTIPLE_FINAL_BUDGETS);
        } else {
          finalVersionFound = true;
        }
      }

      final String budgetStatusCompleteCode =
          getParameterService()
              .getParameterValueAsString(
                  BudgetDocument.class, Constants.BUDGET_STATUS_COMPLETE_CODE);

      if (budgetStatusCompleteCode.equalsIgnoreCase(budgetVersion.getBudgetStatus())) {
        if (!budgetVersion.isFinalVersionFlag()) {
          errorMap.putError(
              "budgetVersionOverview[" + index + "].budgetStatus",
              KeyConstants.ERROR_NO_FINAL_BUDGET);
          valid = false;
        }
      }
      index++;
    }

    return valid;
  }
  /**
   * This method...
   *
   * @param nonInvoiced
   * @param paymentApplicationDocument
   * @param totalFromControl
   * @return
   */
  private static boolean validateNonInvoicedLineAmount(
      NonInvoiced nonInvoiced,
      PaymentApplicationDocument paymentApplicationDocument,
      KualiDecimal totalFromControl) {
    MessageMap errorMap = GlobalVariables.getMessageMap();
    KualiDecimal nonArLineAmount = nonInvoiced.getFinancialDocumentLineAmount();
    // check that dollar amount is not zero before continuing
    if (ObjectUtils.isNull(nonArLineAmount)) {
      errorMap.putError(
          ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT,
          ArKeyConstants.PaymentApplicationDocumentErrors.NON_AR_AMOUNT_REQUIRED);
      return false;
    } else {
      KualiDecimal cashControlBalanceToBeApplied = totalFromControl;
      cashControlBalanceToBeApplied =
          cashControlBalanceToBeApplied.add(paymentApplicationDocument.getTotalFromControl());
      cashControlBalanceToBeApplied.subtract(paymentApplicationDocument.getTotalApplied());
      cashControlBalanceToBeApplied.subtract(
          paymentApplicationDocument.getNonAppliedHoldingAmount());

      if (nonArLineAmount.isZero()) {
        errorMap.putError(
            ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT,
            ArKeyConstants.PaymentApplicationDocumentErrors.AMOUNT_TO_BE_APPLIED_CANNOT_BE_ZERO);
        return false;
      } else if (nonArLineAmount.isNegative()) {
        errorMap.putError(
            ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT,
            ArKeyConstants.PaymentApplicationDocumentErrors.AMOUNT_TO_BE_APPLIED_MUST_BE_POSTIIVE);
        return false;
      }
      //  check that we're not trying to apply more funds to the invoice than the invoice has
      // balance (ie, over-applying)
      else if (KualiDecimal.ZERO.isGreaterThan(
          cashControlBalanceToBeApplied.subtract(nonArLineAmount))) {
        errorMap.putError(
            ArPropertyConstants.PaymentApplicationDocumentFields.NON_INVOICED_LINE_AMOUNT,
            ArKeyConstants.PaymentApplicationDocumentErrors
                .NON_AR_AMOUNT_EXCEEDS_BALANCE_TO_BE_APPLIED);
        return false;
      }
    }
    return true;
  }
 protected boolean validateActiveDate(
     String errorPath, Timestamp activeFromDate, Timestamp activeToDate) {
   // TODO : do not have detail bus rule yet, so just check this for now.
   boolean valid = true;
   if (activeFromDate != null && activeToDate != null && activeToDate.before(activeFromDate)) {
     MessageMap errorMap = GlobalVariables.getMessageMap();
     errorMap.putError(errorPath, RiceKeyConstants.ERROR_ACTIVE_TO_DATE_BEFORE_FROM_DATE);
     valid = false;
   }
   return valid;
 }
Esempio n. 10
0
  /**
   * Validates if the job code is a valid value.
   *
   * @param person the current person
   * @return true is valid false if not valid
   */
  private boolean validateJobCodeValue(BudgetPerson person, String errorKey) {
    assert person != null : "the person is null";

    boolean valid = true;
    if (person.getJobCode() == null) {
      final MessageMap messageMap = GlobalVariables.getMessageMap();
      messageMap.putError(
          errorKey, KeyConstants.ERROR_PERSON_JOBCODE_VALUE, person.getPersonName());
      valid = false;
    }
    return valid;
  }
Esempio n. 11
0
 /**
  * Validates if the job code is a valid change.
  *
  * @param person the current person
  * @return true is valid false if not valid
  */
 private boolean validateJobCodeChange(final BudgetPerson person, String errorKey) {
   boolean valid = true;
   BudgetPerson personCopy = getOriginalBudgetPerson(person);
   if (personCopy != null && !person.isDuplicatePerson(personCopy)) {
     if (!StringUtils.equals(person.getJobCode(), personCopy.getJobCode())) {
       final MessageMap messageMap = GlobalVariables.getMessageMap();
       messageMap.putError(
           errorKey, KeyConstants.ERROR_PERSON_JOBCODE_CHANGE, person.getPersonName());
       valid = false;
     }
   }
   return valid;
 }
  /**
   * This method is checks individual line item start and end dates for validity and proper
   * ordering.
   *
   * @param currentBudgetPeriod the period containing the line item
   * @param budgetLineItem the number of the line item
   * @return true if the dates are valid, false otherwise
   */
  protected boolean processCheckLineItemDates(
      BudgetPeriod currentBudgetPeriod, BudgetLineItem budgetLineItem, String errorPath) {
    boolean valid = true;
    MessageMap errorMap = getGlobalVariableService().getMessageMap();

    if (budgetLineItem.getEndDate() == null) {
      errorMap.putError(errorPath + END_DATE, KeyConstants.ERROR_REQUIRED, UPPER_END_DATE);
      valid = false;
    }

    if (budgetLineItem.getStartDate() == null) {
      errorMap.putError(errorPath + START_DATE, KeyConstants.ERROR_REQUIRED, UPPER_START_DATE);
      valid = false;
    }

    if (!valid) return valid;

    if (budgetLineItem.getEndDate().compareTo(budgetLineItem.getStartDate()) < 0) {
      errorMap.putError(errorPath + END_DATE, KeyConstants.ERROR_LINE_ITEM_DATES);
      valid = false;
    }

    if (currentBudgetPeriod.getEndDate().compareTo(budgetLineItem.getEndDate()) < 0) {
      errorMap.putError(
          errorPath + END_DATE,
          KeyConstants.ERROR_LINE_ITEM_END_DATE,
          new String[] {CAN_NOT_BE_AFTER, LOWER_END_DATE});
      valid = false;
    }
    if (currentBudgetPeriod.getStartDate().compareTo(budgetLineItem.getEndDate()) > 0) {
      errorMap.putError(
          errorPath + END_DATE,
          KeyConstants.ERROR_LINE_ITEM_END_DATE,
          new String[] {CAN_NOT_BE_BEFORE, LOWER_START_DATE});
      valid = false;
    }
    if (currentBudgetPeriod.getStartDate().compareTo(budgetLineItem.getStartDate()) > 0) {
      errorMap.putError(
          errorPath + START_DATE,
          KeyConstants.ERROR_LINE_ITEM_START_DATE,
          new String[] {CAN_NOT_BE_BEFORE, LOWER_START_DATE});
      valid = false;
    }
    if (currentBudgetPeriod.getEndDate().compareTo(budgetLineItem.getStartDate()) < 0) {
      errorMap.putError(
          errorPath + START_DATE,
          KeyConstants.ERROR_LINE_ITEM_START_DATE,
          new String[] {CAN_NOT_BE_AFTER, LOWER_END_DATE});
      valid = false;
    }

    return valid;
  }
  @KcEventMethod
  public boolean processCheckExistBudgetPersonnelDetailsBusinessRules(
      DeleteBudgetLineItemEvent event) {
    boolean valid = true;

    MessageMap errorMap = getGlobalVariableService().getMessageMap();
    if (CollectionUtils.isNotEmpty(event.getBudgetLineItem().getBudgetPersonnelDetailsList())) {
      // just try to make sure key is on budget personnel tab
      errorMap.putError(event.getErrorPath() + COST_ELEMENT, KeyConstants.ERROR_DELETE_LINE_ITEM);
      valid = false;
    }

    return valid;
  }
  protected boolean processBudgetFormulatedCostValidations(
      BudgetFormulatedCostDetail budgetFormulatedCost, String errorKey) {
    boolean valid = true;
    MessageMap errorMap = getGlobalVariableService().getMessageMap();

    BigDecimal unitCost = budgetFormulatedCost.getUnitCost().bigDecimalValue();
    BigDecimal count = new ScaleTwoDecimal(budgetFormulatedCost.getCount()).bigDecimalValue();
    BigDecimal frequency =
        new ScaleTwoDecimal(budgetFormulatedCost.getFrequency()).bigDecimalValue();
    BigDecimal calculatedExpense = unitCost.multiply(count).multiply(frequency);
    if (new ScaleTwoDecimal(unitCost)
        .isGreaterThan(new ScaleTwoDecimal(MAX_BUDGET_DECIMAL_VALUE))) {
      valid = false;
      errorMap.putError(errorKey + UNIT_COST, KeyConstants.ERROR_FORMULATED_UNIT_COST);
    }
    if (new ScaleTwoDecimal(calculatedExpense)
        .isGreaterThan(new ScaleTwoDecimal(MAX_BUDGET_DECIMAL_VALUE))) {
      valid = false;
      errorMap.putError(
          errorKey + CALCULATED_EXPENSES, KeyConstants.ERROR_FORMULATED_CALCULATED_EXPENSES);
    }
    return valid;
  }
Esempio n. 15
0
 /**
  * This method to check the 'selected' person to delete is not associate with budget personnel
  * details
  *
  * @return
  */
 @KcEventMethod
 public boolean processCheckExistBudgetPersonnelDetailsBusinessRules(
     DeleteBudgetPersonEvent event) {
   boolean valid = true;
   String errorPath = event.getErrorPath();
   // User  may delete person before the deleted detail is persisted
   if (isPersonDetailsFound(event.getBudget(), event.getBudgetPerson())) {
     final MessageMap messageMap = GlobalVariables.getMessageMap();
     messageMap.putError(
         errorPath,
         KeyConstants.ERROR_DELETE_PERSON_WITH_PERSONNEL_DETAIL,
         event.getBudgetPerson().getPersonName());
     valid = false;
   }
   return valid;
 }
Esempio n. 16
0
  protected KcEventResult isNotDuplicateBudgetPersons(List<BudgetPerson> budgetPersons) {
    KcEventResult result = new KcEventResult();
    MessageMap messages = new MessageMap();
    result.setSuccess(true);

    for (int i = 0; i < budgetPersons.size(); i++) {
      BudgetPerson budgetPerson = budgetPersons.get(i);
      for (int j = i + 1; j < budgetPersons.size(); j++) {
        BudgetPerson budgetPersonCompare = budgetPersons.get(j);
        if (budgetPerson.isDuplicatePerson(budgetPersonCompare)) {
          messages.putError(
              "budgetPersons[" + j + "].personName",
              KeyConstants.ERROR_DUPLICATE_BUDGET_PERSON,
              budgetPerson.getPersonName());
          result.setSuccess(false);
        }
      }
    }

    result.setMessageMap(messages);
    return result;
  }
Esempio n. 17
0
  public void setFromFileForCollectorDetail(
      String detailLine,
      Map<String, String> accountRecordBalanceTypeMap,
      Date curDate,
      UniversityDate universityDate,
      int lineNumber,
      MessageMap messageMap) {

    try {

      final Map<String, Integer> pMap =
          getCollectorDetailFieldUtil().getFieldBeginningPositionMap();

      detailLine =
          org.apache.commons.lang.StringUtils.rightPad(
              detailLine, GeneralLedgerConstants.getSpaceAllCollectorDetailFields().length(), ' ');

      setCreateDate(curDate);
      if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear()
          .equals(
              detailLine.substring(
                  pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                  pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)))) {
        try {
          setUniversityFiscalYear(
              new Integer(
                  getValue(
                      detailLine,
                      pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                      pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))));
        } catch (NumberFormatException e) {
          messageMap.putError(
              KFSConstants.GLOBAL_ERRORS,
              KFSKeyConstants.ERROR_CUSTOM,
              "Collector detail university fiscal year "
                  + lineNumber
                  + " string "
                  + detailLine.substring(
                      pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                      pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)));
          setUniversityFiscalYear(null);
        }
      } else {
        setUniversityFiscalYear(null);
      }

      if (!GeneralLedgerConstants.getSpaceChartOfAccountsCode()
          .equals(
              detailLine.substring(
                  pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                  pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))))
        setChartOfAccountsCode(
            getValue(
                detailLine,
                pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE),
                pMap.get(KFSPropertyConstants.ACCOUNT_NUMBER)));
      else setChartOfAccountsCode(GeneralLedgerConstants.getSpaceChartOfAccountsCode());
      setAccountNumber(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.ACCOUNT_NUMBER),
              pMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER)));

      // if chart code is empty while accounts cannot cross charts, then derive chart code from
      // account number
      AccountService acctserv = SpringContext.getBean(AccountService.class);
      if (StringUtils.isEmpty(getChartOfAccountsCode())
          && StringUtils.isNotEmpty(getAccountNumber())
          && !acctserv.accountsCanCrossCharts()) {
        Account account = acctserv.getUniqueAccountForAccountNumber(getAccountNumber());
        if (account != null) {
          setChartOfAccountsCode(account.getChartOfAccountsCode());
        }
      }

      setSubAccountNumber(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER),
              pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE)));
      setFinancialObjectCode(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE),
              pMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE)));
      setFinancialSubObjectCode(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE),
              pMap.get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE)));

      // We are in Collector Detail for ID Billing Details because the value from file positions 26,
      // 27 = DT.  We don not want to set Financial Balance Type Code to detail type code (DT)
      // Generate the account record key to retrieve the balance type from the map which contains
      // the balance type from the accounting record/origin entry
      String accountRecordKey = generateAccountRecordBalanceTypeKey();
      String financialBalanceTypeCode = accountRecordBalanceTypeMap.get(accountRecordKey);
      // Default to "AC" if we do not find account record key record from the map
      setFinancialBalanceTypeCode(
          StringUtils.defaultIfEmpty(
              financialBalanceTypeCode,
              GeneralLedgerConstants.FINALNCIAL_BALANCE_TYPE_FOR_COLLECTOR_DETAIL_RECORD));
      setFinancialObjectTypeCode(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE),
              pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_SEQUENCE_NUMBER)));
      setUniversityFiscalPeriodCode(universityDate.getUniversityFiscalAccountingPeriod());
      setCollectorDetailSequenceNumber(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_SEQUENCE_NUMBER),
              pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE)));
      setFinancialDocumentTypeCode(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE),
              pMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE)));
      setFinancialSystemOriginationCode(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE),
              pMap.get(KFSPropertyConstants.DOCUMENT_NUMBER)));
      setDocumentNumber(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.DOCUMENT_NUMBER),
              pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_AMOUNT)));
      try {
        setCollectorDetailItemAmount(
            getValue(
                detailLine,
                pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_AMOUNT),
                pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_GL_CREDIT_CODE)));
      } catch (NumberFormatException e) {
        setCollectorDetailItemAmount(KualiDecimal.ZERO);
        messageMap.putError(
            KFSConstants.GLOBAL_ERRORS,
            KFSKeyConstants.ERROR_CUSTOM,
            "Collector detail amount cannot be parsed on line "
                + lineNumber
                + " amount string "
                + detailLine.substring(
                    pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_AMOUNT),
                    pMap.get(KFSPropertyConstants.GL_CREDIT_CODE)));
      }
      if (KFSConstants.GL_CREDIT_CODE.equalsIgnoreCase(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_GL_CREDIT_CODE),
              pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_NOTE_TEXT)))) {
        setCollectorDetailItemAmount(getCollectorDetailItemAmount().negated());
      }
      setCollectorDetailNoteText(
          getValue(
              detailLine,
              pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_NOTE_TEXT),
              GeneralLedgerConstants.getSpaceAllCollectorDetailFields().length()));

      if (org.apache.commons.lang.StringUtils.isEmpty(getSubAccountNumber())) {
        setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
      }
      if (org.apache.commons.lang.StringUtils.isEmpty(getFinancialSubObjectCode())) {
        setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
      }
      if (org.apache.commons.lang.StringUtils.isEmpty(getCollectorDetailSequenceNumber())) {
        setCollectorDetailSequenceNumber(" ");
      }
    } catch (Exception e) {
      throw new RuntimeException(
          e + " occurred in CollectorDetail.setFromFileForCollectorDetail()");
    }
  }
 protected static void putError(String errorPropertyName, String errorMessageKey, String value) {
   MessageMap errorMap = GlobalVariables.getMessageMap();
   errorMap.putError(errorPropertyName, errorMessageKey, value);
 }
Esempio n. 19
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;
  }
Esempio n. 20
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;
  }
Esempio n. 21
0
  /**
   * Validate budget rates. Applicable rates are mandatory
   *
   * @param budgetDocument
   * @return
   */
  protected boolean processBudgetRatesBusinessRule(BudgetDocument budgetDocument) {
    boolean valid = true;
    final int APPLICABLE_RATE_LENGTH_EXCEEDED = 1;
    final int APPLICABLE_RATE_NEGATIVE = -1;

    MessageMap errorMap = GlobalVariables.getMessageMap();
    int i = 0;
    for (BudgetRate budgetRate : budgetDocument.getBudget().getBudgetRates()) {
      String rateClassType = budgetRate.getRateClass().getRateClassTypeT().getDescription();
      String errorPath = "budgetProposalRate[" + rateClassType + "][" + i + "]";
      errorMap.addToErrorPath(errorPath);
      /* look for applicable rate */
      if (budgetRate.isApplicableRateNull()) {
        valid = false;
        errorMap.putError("applicableRate", KeyConstants.ERROR_REQUIRED_APPLICABLE_RATE);
      } else if (!ScaleTwoDecimal.isNumeric(budgetRate.getApplicableRate().toString())) {
        valid = false;
        errorMap.putError("applicableRate", KeyConstants.ERROR_APPLICABLE_RATE_NOT_NUMERIC);
      } else {
        switch (verifyApplicableRate(budgetRate.getApplicableRate())) {
          case APPLICABLE_RATE_LENGTH_EXCEEDED:
            valid = false;
            errorMap.putError(
                "applicableRate",
                KeyConstants.ERROR_APPLICABLE_RATE_LIMIT,
                Constants.APPLICABLE_RATE_LIMIT);
            break;
          case APPLICABLE_RATE_NEGATIVE:
            valid = false;
            errorMap.putError("applicableRate", KeyConstants.ERROR_APPLICABLE_RATE_NEGATIVE);
            break;
        }
      }
      errorMap.removeFromErrorPath(errorPath);
      i++;
    }

    i = 0;
    for (BudgetLaRate budgetLaRate : budgetDocument.getBudget().getBudgetLaRates()) {
      String rateClassType = "";
      if (ObjectUtils.isNotNull(budgetLaRate.getRateClass())
          && ObjectUtils.isNotNull(budgetLaRate.getRateClass().getRateClassTypeT())) {
        rateClassType = budgetLaRate.getRateClass().getRateClassTypeT().getDescription();
      }
      String errorPath = "budgetRate[" + rateClassType + "][" + i + "]";
      errorMap.addToErrorPath(errorPath);
      /* look for applicable rate */
      if (budgetLaRate.isApplicableRateNull()) {
        valid = false;
        errorMap.putError("applicableRate", KeyConstants.ERROR_REQUIRED_APPLICABLE_RATE);
      } else if (!ScaleTwoDecimal.isNumeric(budgetLaRate.getApplicableRate().toString())) {
        valid = false;
        errorMap.putError("applicableRate", KeyConstants.ERROR_APPLICABLE_RATE_NOT_NUMERIC);
      } else {
        switch (verifyApplicableRate(budgetLaRate.getApplicableRate())) {
          case APPLICABLE_RATE_LENGTH_EXCEEDED:
            valid = false;
            errorMap.putError(
                "applicableRate",
                KeyConstants.ERROR_APPLICABLE_RATE_LIMIT,
                Constants.APPLICABLE_RATE_LIMIT);
            break;
          case APPLICABLE_RATE_NEGATIVE:
            valid = false;
            errorMap.putError("applicableRate", KeyConstants.ERROR_APPLICABLE_RATE_NEGATIVE);
            break;
        }
      }
      errorMap.removeFromErrorPath(errorPath);
      i++;
    }

    return valid;
  }
Esempio n. 22
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;
  }
  /**
   * Validation for the Stipulation tab.
   *
   * @param poDocument the purchase order document to be validated
   * @return boolean false if the vendor stipulation description is blank.
   */
  @Override
  public boolean validate(AttributedDocumentEvent event) {
    boolean valid = super.validate(event);
    PurchasingAccountsPayableDocument purapDocument =
        (PurchasingAccountsPayableDocument) event.getDocument();
    PurchaseOrderDocument poDocument = (PurchaseOrderDocument) purapDocument;
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();
    errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);

    // check to see if the vendor exists in the database, i.e. its ID is not null
    Integer vendorHeaderID = poDocument.getVendorHeaderGeneratedIdentifier();
    if (ObjectUtils.isNull(vendorHeaderID)) {
      valid = false;
      errorMap.putError(
          VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_NONEXIST_VENDOR);
    }

    // vendor active validation...
    VendorDetail vendorDetail =
        super.getVendorService()
            .getVendorDetail(
                poDocument.getVendorHeaderGeneratedIdentifier(),
                poDocument.getVendorDetailAssignedIdentifier());
    if (ObjectUtils.isNull(vendorDetail)) {
      return valid;
    }

    // make sure that the vendor is active
    if (!vendorDetail.isActiveIndicator()) {
      valid &= false;
      errorMap.putError(
          VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
    }

    // validate vendor address
    super.getPostalCodeValidationService()
        .validateAddress(
            poDocument.getVendorCountryCode(),
            poDocument.getVendorStateCode(),
            poDocument.getVendorPostalCode(),
            PurapPropertyConstants.VENDOR_STATE_CODE,
            PurapPropertyConstants.VENDOR_POSTAL_CODE);

    // Do checks for alternate payee vendor.
    Integer alternateVendorHdrGeneratedId =
        poDocument.getAlternateVendorHeaderGeneratedIdentifier();
    Integer alternateVendorHdrDetailAssignedId =
        poDocument.getAlternateVendorDetailAssignedIdentifier();

    VendorDetail alternateVendor =
        super.getVendorService()
            .getVendorDetail(alternateVendorHdrGeneratedId, alternateVendorHdrDetailAssignedId);

    if (alternateVendor != null) {
      if (alternateVendor.isVendorDebarred()) {
        errorMap.putError(
            PurapPropertyConstants.ALTERNATE_VENDOR_NAME,
            PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DEBARRED);
        valid &= false;
      }
      if (StringUtils.equals(
          alternateVendor.getVendorHeader().getVendorTypeCode(),
          VendorTypes.DISBURSEMENT_VOUCHER)) {
        errorMap.putError(
            PurapPropertyConstants.ALTERNATE_VENDOR_NAME,
            PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DV_TYPE);
        valid &= false;
      }
      if (!alternateVendor.isActiveIndicator()) {
        errorMap.putError(
            PurapPropertyConstants.ALTERNATE_VENDOR_NAME,
            PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_INACTIVE,
            PODocumentsStrings.ALTERNATE_PAYEE_VENDOR);
        valid &= false;
      }
    }

    // make sure that the vendor contract expiration date and not marked inactive.
    if (StringUtils.isNotBlank(poDocument.getVendorContractName())) {
      if (super.getVendorService()
          .isVendorContractExpired(
              poDocument, poDocument.getVendorContractGeneratedIdentifier(), vendorDetail)) {
        errorMap.putError(
            VendorPropertyConstants.VENDOR_CONTRACT_END_DATE,
            PurapKeyConstants.ERROR_EXPIRED_CONTRACT_END_DATE);
        valid &= false;
      }
    }

    errorMap.clearErrorPath();
    return valid;
  }