/**
  * Determines if any imported expenses on the document have a card type of CORP
  *
  * @return true if there are CORP imported expenses on the document, false otherwise
  */
 public boolean isCorporateCardPayable() {
   if (getImportedExpenses() != null && !getImportedExpenses().isEmpty()) {
     for (ImportedExpense expense : getImportedExpenses()) {
       if (StringUtils.equals(expense.getCardType(), TemConstants.TRAVEL_TYPE_CORP)) {
         return true;
       }
     }
   }
   return false;
 }
 /**
  * Looks through the imported expenses on the document to find a corporate card record which has a
  * credit card agency - returns that
  *
  * @param document a document to find a corporate card vendor for
  * @return the id of the found vendor or null if nothing was found
  */
 protected CreditCardAgency getCorporateCreditCardAgency(TEMReimbursementDocument document) {
   for (ImportedExpense importedExpense : document.getImportedExpenses()) {
     if (StringUtils.equals(importedExpense.getCardType(), TemConstants.TRAVEL_TYPE_CORP)
         && !ObjectUtils.isNull(importedExpense.getHistoricalTravelExpense())) {
       importedExpense
           .getHistoricalTravelExpense()
           .refreshReferenceObject(TemPropertyConstants.CREDIT_CARD_AGENCY);
       if (!ObjectUtils.isNull(importedExpense.getHistoricalTravelExpense().getCreditCardAgency())
           && !StringUtils.isBlank(
               importedExpense
                   .getHistoricalTravelExpense()
                   .getCreditCardAgency()
                   .getVendorNumber())) {
         return importedExpense.getHistoricalTravelExpense().getCreditCardAgency();
       }
     }
   }
   return null;
 }
  @Override
  public boolean validate(AttributedDocumentEvent event) {
    boolean rulePassed = true;
    TravelDocument travelDocument = (TravelDocument) event.getDocument();
    GlobalVariables.getMessageMap().addToErrorPath(KRADPropertyConstants.DOCUMENT);
    // Actual Expenses
    int counter = 0;
    for (ActualExpense actualExpense : travelDocument.getActualExpenses()) {
      String property = TemPropertyConstants.ACTUAL_EXPENSES + "[" + counter + "]";
      /*
       * Determine if the detail is an amount that doesn't go over the threshold
       */
      KualiDecimal total = actualExpense.getTotalDetailExpenseAmount();
      if (!total.isZero()) {
        if (total.isGreaterThan(actualExpense.getExpenseAmount())) {
          GlobalVariables.getMessageMap()
              .putError(
                  property + "." + TemPropertyConstants.EXPENSE_AMOUNT,
                  TemKeyConstants.ERROR_TEM_DETAIL_GREATER_THAN_EXPENSE);
          rulePassed = false;
        } else if (total.isLessThan(actualExpense.getExpenseAmount())) {
          GlobalVariables.getMessageMap()
              .putError(
                  property + "." + TemPropertyConstants.EXPENSE_AMOUNT,
                  TemKeyConstants.ERROR_TEM_DETAIL_LESS_THAN_EXPENSE);
          rulePassed = false;
        }
      }
      counter++;
    }

    // Imported Expenses
    counter = 0;
    for (ImportedExpense importedExpense : travelDocument.getImportedExpenses()) {
      String property = TemPropertyConstants.IMPORTED_EXPENSES + "[" + counter + "]";

      // Determine if the detail is an amount that doesn't go over the threshold
      KualiDecimal total = KualiDecimal.ZERO;
      for (TemExpense detail : importedExpense.getExpenseDetails()) {
        total = total.add(detail.getExpenseAmount());
      }
      if (!total.isZero()) {
        if (total.isGreaterThan(importedExpense.getExpenseAmount())) {
          GlobalVariables.getMessageMap()
              .putError(
                  property + "." + TemPropertyConstants.EXPENSE_AMOUNT,
                  TemKeyConstants.ERROR_TEM_DETAIL_GREATER_THAN_EXPENSE);
          rulePassed = false;
        } else if (total.isLessThan(importedExpense.getExpenseAmount())) {
          GlobalVariables.getMessageMap()
              .putError(
                  property + "." + TemPropertyConstants.EXPENSE_AMOUNT,
                  TemKeyConstants.ERROR_TEM_DETAIL_LESS_THAN_EXPENSE);
          rulePassed = false;
        }
      }
      counter++;
    }

    GlobalVariables.getMessageMap().clearErrorPath();

    return rulePassed;
  }