/**
   * @see org.kuali.kfs.sys.document.FinancialSystemMaintainable#populateChartOfAccountsCodeFields()
   *     <p>Special treatment is needed to populate the chart code from the account number field in
   *     IndirectCostRecoveryRateDetails, as the potential reference account doesn't exist in the
   *     collection due to wild cards, which also needs special handling.
   */
  @Override
  protected void populateChartOfAccountsCodeFields() {
    // calling super method in case there're reference accounts/collections other than ICR rates
    super.populateChartOfAccountsCodeFields();

    PersistableBusinessObject bo = getBusinessObject();
    AccountService acctService = SpringContext.getBean(AccountService.class);
    PersistableBusinessObject newAccount =
        getNewCollectionLine(KFSPropertyConstants.INDIRECT_COST_RECOVERY_RATE_DETAILS);
    String accountNumber =
        (String) ObjectUtils.getPropertyValue(newAccount, KFSPropertyConstants.ACCOUNT_NUMBER);
    String coaCode = null;

    // if accountNumber is wild card, populate chart code with the same wild card
    if (GeneralLedgerConstants.PosterService.SYMBOL_USE_EXPENDITURE_ENTRY.equals(accountNumber)
        || GeneralLedgerConstants.PosterService.SYMBOL_USE_ICR_FROM_ACCOUNT.equals(accountNumber)) {
      coaCode = accountNumber;
    }
    // otherwise do the normal account lookup
    else {
      Account account = acctService.getUniqueAccountForAccountNumber(accountNumber);
      if (ObjectUtils.isNotNull(account)) {
        coaCode = account.getChartOfAccountsCode();
      }
    }

    // populate chart code field
    try {
      ObjectUtils.setObjectProperty(
          newAccount, KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, coaCode);
    } catch (Exception e) {
      LOG.error(
          "Error in setting property value for " + KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
    }
  }
 /**
  * Sets the accountNumber attribute value.
  *
  * @param accountNumber The accountNumber to set.
  */
 public void setAccountNumber(String accountNumber) {
   this.accountNumber = accountNumber;
   // if accounts can't cross charts, set chart code whenever account number is set
   AccountService accountService = SpringContext.getBean(AccountService.class);
   if (!accountService.accountsCanCrossCharts()) {
     Account account = accountService.getUniqueAccountForAccountNumber(accountNumber);
     if (ObjectUtils.isNotNull(account)) {
       setChartOfAccountsCode(account.getChartOfAccountsCode());
       setChartOfAccounts(account.getChartOfAccounts());
     }
   }
 }
  /**
   * If accounts can't cross charts, then we need to make sure the account number is unique.
   *
   * @param accountNumber
   * @return
   */
  protected boolean checkUniqueAccountNumber(String accountNumber) {
    boolean success = true;

    // while account is not allowed to cross chart
    // and with an account number that already exists
    if (!accountService.accountsCanCrossCharts()
        && !accountService.getAccountsForAccountNumber(accountNumber).isEmpty()) {
      success = false;
    }

    return success;
  }
  /** This method changes account to suspenseAccount */
  protected Message useSuspenseAccount(LaborOriginEntry workingEntry) {
    String suspenseAccountNumber =
        parameterService.getParameterValueAsString(
            LaborScrubberStep.class, LaborConstants.Scrubber.SUSPENSE_ACCOUNT);
    String suspenseCOAcode =
        parameterService.getParameterValueAsString(
            LaborScrubberStep.class, LaborConstants.Scrubber.SUSPENSE_CHART);
    String suspenseSubAccountNumber =
        parameterService.getParameterValueAsString(
            LaborScrubberStep.class, LaborConstants.Scrubber.SUSPENSE_SUB_ACCOUNT);

    Account account = accountService.getByPrimaryId(suspenseCOAcode, suspenseAccountNumber);

    if (ObjectUtils.isNull(account)) {
      return MessageBuilder.buildMessage(
          LaborKeyConstants.ERROR_INVALID_SUSPENSE_ACCOUNT, Message.TYPE_FATAL);
    }

    workingEntry.setAccount(account);
    workingEntry.setAccountNumber(suspenseAccountNumber);
    workingEntry.setChartOfAccountsCode(suspenseCOAcode);
    workingEntry.setSubAccountNumber(suspenseSubAccountNumber);

    return MessageBuilder.buildMessageWithPlaceHolder(
        LaborKeyConstants.MESSAGE_SUSPENSE_ACCOUNT_APPLIED,
        Message.TYPE_WARNING,
        new Object[] {suspenseCOAcode, suspenseAccountNumber, suspenseSubAccountNumber});
  }
  /**
   * For fringe transaction types checks if the account accepts fringe benefits. If not, retrieves
   * the alternative account, then calls expiration checking on either the alternative account or
   * the account passed in.
   */
  protected Message checkAccountFringeIndicator(
      LaborOriginEntry laborOriginEntry,
      LaborOriginEntry laborWorkingEntry,
      Account account,
      UniversityDate universityRunDate,
      LaborAccountingCycleCachingService laborAccountingCycleCachingService) {
    // check for fringe tranaction type
    // LaborObject laborObject = (LaborObject)
    // businessObjectService.findByPrimaryKey(LaborObject.class, fieldValues);
    LaborObject laborObject =
        laborAccountingCycleCachingService.getLaborObject(
            laborOriginEntry.getUniversityFiscalYear(),
            laborOriginEntry.getChartOfAccountsCode(),
            laborOriginEntry.getFinancialObjectCode());
    boolean isFringeTransaction =
        laborObject != null
            && org.apache.commons.lang.StringUtils.equals(
                LaborConstants.BenefitExpenseTransfer.LABOR_LEDGER_BENEFIT_CODE,
                laborObject.getFinancialObjectFringeOrSalaryCode());

    // alternative account handling for non fringe accounts
    if (isFringeTransaction && !account.isAccountsFringesBnftIndicator()) {
      Account altAccount =
          accountService.getByPrimaryId(
              laborOriginEntry.getAccount().getReportsToChartOfAccountsCode(),
              laborOriginEntry.getAccount().getReportsToAccountNumber());
      if (ObjectUtils.isNotNull(altAccount)) {
        laborWorkingEntry.setAccount(altAccount);
        laborWorkingEntry.setAccountNumber(altAccount.getAccountNumber());
        laborWorkingEntry.setChartOfAccountsCode(altAccount.getChartOfAccountsCode());
        Message err =
            handleExpiredClosedAccount(
                altAccount, laborOriginEntry, laborWorkingEntry, universityRunDate);
        if (err == null) {
          err =
              MessageBuilder.buildMessageWithPlaceHolder(
                  LaborKeyConstants.MESSAGE_FRINGES_MOVED_TO,
                  Message.TYPE_WARNING,
                  new Object[] {altAccount.getAccountNumber()});
        }
        return err;
      }

      // no alt acct, use suspense acct if active
      boolean suspenseAccountLogicInd =
          parameterService.getParameterValueAsBoolean(
              LaborScrubberStep.class, LaborConstants.Scrubber.SUSPENSE_ACCOUNT_LOGIC_PARAMETER);
      if (suspenseAccountLogicInd) {
        return useSuspenseAccount(laborWorkingEntry);
      }

      return MessageBuilder.buildMessage(
          LaborKeyConstants.ERROR_NON_FRINGE_ACCOUNT_ALTERNATIVE_NOT_FOUND, Message.TYPE_FATAL);
    }

    return handleExpiredClosedAccount(
        account, laborOriginEntry, laborWorkingEntry, universityRunDate);
  }
 public boolean isValidChartAccount(String chartOfAccountsCode, String accountNumber) {
   AccountService accountService = SpringContext.getBean(AccountService.class);
   Account account = accountService.getByPrimaryId(chartOfAccountsCode, accountNumber);
   return (account != null);
 }
  /**
   * Loops through continuation accounts for 10 tries or until it finds an account that is not
   * expired.
   */
  protected Message continuationAccountLogic(
      Account expiredClosedAccount,
      LaborOriginEntry laborOriginEntry,
      LaborOriginEntry laborWorkingEntry,
      UniversityDate universityRunDate) {
    String chartCode = expiredClosedAccount.getContinuationFinChrtOfAcctCd();
    String accountNumber = expiredClosedAccount.getContinuationAccountNumber();

    List<String> checkedAccountNumbers = new ArrayList<String>();
    for (int i = 0; i < 10; ++i) {
      if (checkedAccountNumbers.contains(chartCode + accountNumber)) {
        // Something is really wrong with the data because this account has already been evaluated.
        return MessageBuilder.buildMessage(
            KFSKeyConstants.ERROR_CIRCULAR_DEPENDENCY_IN_CONTINUATION_ACCOUNT_LOGIC,
            Message.TYPE_FATAL);
      }

      checkedAccountNumbers.add(chartCode + accountNumber);

      if (chartCode == null || accountNumber == null) {
        return MessageBuilder.buildMessage(
            KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_NOT_FOUND, Message.TYPE_FATAL);
      }

      // Lookup the account
      Account account = accountService.getByPrimaryId(chartCode, accountNumber);
      if (ObjectUtils.isNull(account)) {
        return MessageBuilder.buildMessage(
            KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_NOT_FOUND, Message.TYPE_FATAL);
      }

      // check account expiration
      long offsetAccountExpirationTime = getAdjustedAccountExpirationDate(account);
      if (ObjectUtils.isNotNull(account.getAccountExpirationDate())
          && isAccountExpired(account, universityRunDate)) {
        chartCode = account.getContinuationFinChrtOfAcctCd();
        accountNumber = account.getContinuationAccountNumber();
      } else {

        // set continuationAccountLogicIndi
        continuationAccountIndicator = true;

        laborWorkingEntry.setAccount(account);
        laborWorkingEntry.setAccountNumber(accountNumber);
        laborWorkingEntry.setChartOfAccountsCode(chartCode);
        laborWorkingEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
        laborWorkingEntry.setTransactionLedgerEntryDescription(
            kualiConfigurationService.getPropertyValueAsString(KFSKeyConstants.MSG_AUTO_FORWARD)
                + " "
                + expiredClosedAccount.getChartOfAccountsCode()
                + expiredClosedAccount.getAccountNumber()
                + laborOriginEntry.getTransactionLedgerEntryDescription());

        return MessageBuilder.buildMessage(
            KFSKeyConstants.MSG_ACCOUNT_CLOSED_TO,
            laborWorkingEntry.getChartOfAccountsCode() + "-" + laborWorkingEntry.getAccountNumber(),
            Message.TYPE_WARNING);
      }
    }

    // We failed to find a valid continuation account.
    boolean suspenseAccountLogicInd =
        parameterService.getParameterValueAsBoolean(
            LaborScrubberStep.class, LaborConstants.Scrubber.SUSPENSE_ACCOUNT_LOGIC_PARAMETER);
    if (suspenseAccountLogicInd) {
      return useSuspenseAccount(laborWorkingEntry);
    } else {
      return MessageBuilder.buildMessage(
          KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_LIMIT_REACHED, Message.TYPE_FATAL);
    }
  }
 @Override
 public boolean isValidChartAccount(String chartOfAccountsCode, String accountNumber) {
   Account account = accountService.getByPrimaryId(chartOfAccountsCode, accountNumber);
   return (account != null);
 }
 @Override
 public boolean isValidAccount(String accountNumber) {
   Collection<Account> accounts = accountService.getAccountsForAccountNumber(accountNumber);
   return (accounts != null && !accounts.isEmpty());
 }
 @Override
 public boolean accountsCanCrossCharts() {
   return accountService.accountsCanCrossCharts();
 }
Beispiel #11
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()");
    }
  }