Search in sources :

Example 6 with SubAccount

use of org.kuali.kfs.coa.businessobject.SubAccount in project cu-kfs by CU-CommunityApps.

the class ConcurAccountValidationServiceImpl method checkSubAccount.

public ValidationResult checkSubAccount(String chartOfAccountsCode, String accountNumber, String subAccountNumber) {
    ValidationResult validationResult = new ValidationResult();
    if (StringUtils.isNotBlank(subAccountNumber)) {
        SubAccount subAccount = subAccountService.getByPrimaryId(chartOfAccountsCode, accountNumber, subAccountNumber);
        String subAccountErrorMessageString = ConcurUtils.formatStringForErrorMessage(ConcurConstants.AccountingStringFieldNames.SUB_ACCOUNT_NUMBER, chartOfAccountsCode, accountNumber, subAccountNumber);
        validationResult = checkMissingOrInactive(subAccount, MessageFormat.format(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_EXISTENCE), subAccountErrorMessageString), MessageFormat.format(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_INACTIVE), subAccountErrorMessageString));
    }
    return validationResult;
}
Also used : SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) ValidationResult(edu.cornell.kfs.concur.businessobjects.ValidationResult)

Example 7 with SubAccount

use of org.kuali.kfs.coa.businessobject.SubAccount in project cu-kfs by CU-CommunityApps.

the class ScrubberValidatorImpl method continuationAccountLogic.

/**
 * Called when the account of the origin entry is expired or closed, this validates the continuation account
 *
 * @param originEntry       the origin entry being scrubbed
 * @param workingEntry      the scrubbed version of the origin entry
 * @param universityRunDate the run date of the scrubber (to test against expiration dates)
 * @return a Message if an error was encountered, otherwise null
 */
protected Message continuationAccountLogic(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, UniversityDate universityRunDate, AccountingCycleCachingService accountingCycleCachingService) {
    Set<String> checkedAccountNumbers = new HashSet<String>();
    Account continuationAccount = null;
    Account originEntryAccount = accountingCycleCachingService.getAccount(originEntry.getChartOfAccountsCode(), originEntry.getAccountNumber());
    String chartCode = originEntryAccount.getContinuationFinChrtOfAcctCd();
    String accountNumber = originEntryAccount.getContinuationAccountNumber();
    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);
        }
        if ((chartCode == null) || (accountNumber == null)) {
            return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_NOT_FOUND, Message.TYPE_FATAL);
        }
        // Lookup the account
        continuationAccount = accountingCycleCachingService.getAccount(chartCode, accountNumber);
        if (null == continuationAccount) {
            // account not found
            return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_NOT_FOUND, Message.TYPE_FATAL);
        } else {
            // the account exists
            continuationAccount.setSubFundGroup(accountingCycleCachingService.getSubFundGroup(continuationAccount.getSubFundGroupCode()));
            if (continuationAccount.getAccountExpirationDate() == null) {
                // No expiration date
                workingEntry.setAccountNumber(accountNumber);
                workingEntry.setChartOfAccountsCode(chartCode);
                // to set subAcount with dashes
                continuationAccountIndicator = true;
                // workingEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
                // workingEntry.setTransactionLedgerEntryDescription(kualiConfigurationService.getPropertyValueAsString(KFSKeyConstants.MSG_AUTO_FORWARD) + " " + originEntry.getChartOfAccountsCode() + originEntry.getAccountNumber() + originEntry.getTransactionLedgerEntryDescription());
                // TODO:- use messageBuilder and KeyConstant - also, length issue!?!??
                workingEntry.setTransactionLedgerEntryDescription("AUTO FR " + originEntry.getChartOfAccountsCode() + originEntry.getAccountNumber() + originEntry.getTransactionLedgerEntryDescription());
                // FSKD-310 : need to check the account is closed for building message. if not, it is expired.
                if (!originEntryAccount.isActive()) {
                    return MessageBuilder.buildMessage(KFSKeyConstants.MSG_ACCOUNT_CLOSED_TO, chartCode + accountNumber, Message.TYPE_WARNING);
                } else {
                    return MessageBuilder.buildMessage(KFSKeyConstants.MSG_ACCOUNT_EXPIRED_TO, chartCode + accountNumber, Message.TYPE_WARNING);
                }
            } else {
                // the account does have an expiration date.
                // This is the only case in which we might go
                // on for another iteration of the loop.
                checkedAccountNumbers.add(chartCode + accountNumber);
                // If the account has expired go around for another iteration.
                if (isAccountExpired(continuationAccount, universityRunDate)) {
                    chartCode = continuationAccount.getContinuationFinChrtOfAcctCd();
                    accountNumber = continuationAccount.getContinuationAccountNumber();
                } else {
                    workingEntry.setAccountNumber(accountNumber);
                    workingEntry.setChartOfAccountsCode(chartCode);
                    // to set subAccount with dashes
                    continuationAccountIndicator = true;
                    // workingEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
                    // workingEntry.setTransactionLedgerEntryDescription(kualiConfigurationService.getPropertyValueAsString(KFSKeyConstants.MSG_AUTO_FORWARD) + originEntry.getChartOfAccountsCode() + originEntry.getAccountNumber() + originEntry.getTransactionLedgerEntryDescription());
                    // TODO:- use messageBuilder and KeyConstant - also, length issue!?!??
                    workingEntry.setTransactionLedgerEntryDescription("AUTO FR " + originEntry.getChartOfAccountsCode() + originEntry.getAccountNumber() + originEntry.getTransactionLedgerEntryDescription());
                    // FSKD-310 : need to check the account is closed for building message. if not, it is expired.
                    if (!originEntryAccount.isActive()) {
                        return MessageBuilder.buildMessage(KFSKeyConstants.MSG_ACCOUNT_CLOSED_TO, chartCode + accountNumber, Message.TYPE_WARNING);
                    } else {
                        return MessageBuilder.buildMessage(KFSKeyConstants.MSG_ACCOUNT_EXPIRED_TO, chartCode + accountNumber, Message.TYPE_WARNING);
                    }
                }
            }
        }
    }
    // We failed to find a valid continuation account.
    return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_CONTINUATION_ACCOUNT_LIMIT_REACHED, Message.TYPE_FATAL);
}
Also used : SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) Account(org.kuali.kfs.coa.businessobject.Account) HashSet(java.util.HashSet)

Example 8 with SubAccount

use of org.kuali.kfs.coa.businessobject.SubAccount in project cu-kfs by CU-CommunityApps.

the class ScrubberValidatorImpl method validateSubAccount.

/**
 * Validates the sub account of the origin entry
 *
 * @param originEntry  the origin entry being scrubbed
 * @param workingEntry the scrubbed version of the origin entry
 * @return a Message if an error was encountered, otherwise null
 */
protected Message validateSubAccount(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, AccountingCycleCachingService accountingCycleCachingService) {
    LOG.debug("validateSubAccount() started");
    // when continuationAccount used, the subAccountNumber should be changed to dashes and skip validation subAccount process
    if (continuationAccountIndicator) {
        workingEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
        return null;
    }
    // If the sub account number is empty, set it to dashes.
    // Otherwise set the workingEntry sub account number to the
    // sub account number of the input origin entry.
    String subAccount = originEntry.getSubAccountNumber();
    if (StringUtils.hasText(subAccount)) {
        // sub account IS specified
        // check if need upper case
        DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
        // uppercase the data used to generate the collector header
        if (dataDictionaryService.getAttributeForceUppercase(SubAccount.class, KFSPropertyConstants.SUB_ACCOUNT_NUMBER)) {
            subAccount = originEntry.getSubAccountNumber().toUpperCase();
        }
        if (!KFSConstants.getDashSubAccountNumber().equals(subAccount)) {
            SubAccount originEntrySubAccount = accountingCycleCachingService.getSubAccount(originEntry.getChartOfAccountsCode(), originEntry.getAccountNumber(), subAccount);
            // SubAccount originEntrySubAccount = getSubAccount(originEntry);
            if (originEntrySubAccount == null) {
                // sub account does not exist
                int messageType = Message.TYPE_FATAL;
                if (isAssetRecoveryGlobalOrTransfer(originEntry)) {
                    // Not fatal: We want to remove the invalid subAccountNumber and post it
                    messageType = Message.TYPE_WARNING;
                    originEntry.setSubAccountNumber(null);
                    workingEntry.setSubAccountNumber(null);
                }
                return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_SUB_ACCOUNT_NOT_FOUND, originEntry.getChartOfAccountsCode() + "-" + originEntry.getAccountNumber() + "-" + subAccount, messageType);
            } else {
                // sub account IS valid
                if (originEntrySubAccount.isActive()) {
                    // sub account IS active
                    workingEntry.setSubAccountNumber(subAccount);
                } else {
                    // sub account IS NOT active
                    if (parameterService.getParameterValueAsString(KfsParameterConstants.GENERAL_LEDGER_BATCH.class, KFSConstants.SystemGroupParameterNames.GL_ANNUAL_CLOSING_DOC_TYPE).equals(originEntry.getFinancialDocumentTypeCode())) {
                        // document IS annual closing
                        workingEntry.setSubAccountNumber(subAccount);
                    } else {
                        // sub account not active
                        int messageType = Message.TYPE_FATAL;
                        if (isAssetRecoveryGlobalOrTransfer(originEntry)) {
                            // Not fatal: We want to remove the invalid subAccountNumber and post it
                            messageType = Message.TYPE_WARNING;
                            originEntry.setSubAccountNumber(null);
                            workingEntry.setSubAccountNumber(null);
                        }
                        // document is NOT annual closing
                        return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_SUB_ACCOUNT_NOT_ACTIVE, originEntry.getChartOfAccountsCode() + "-" + originEntry.getAccountNumber() + "-" + subAccount, messageType);
                    }
                }
            }
        } else {
            // the sub account is dashes
            workingEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
        }
    } else {
        // No sub account is specified.
        workingEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
    }
    return null;
}
Also used : SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) DataDictionaryService(org.kuali.kfs.kns.service.DataDictionaryService)

Example 9 with SubAccount

use of org.kuali.kfs.coa.businessobject.SubAccount in project cu-kfs by CU-CommunityApps.

the class AccountVerificationWebServiceImpl method isValidSubAccount.

public boolean isValidSubAccount(String chartOfAccountsCode, String accountNumber, String subAccountNumber) throws Exception {
    boolean isValidSubAccount = false;
    SubAccount subAccount = SpringContext.getBean(SubAccountService.class).getByPrimaryId(chartOfAccountsCode, accountNumber, subAccountNumber);
    if (subAccount == null || subAccount.toString().isEmpty() || (!subAccount.isActive())) {
        isValidSubAccount = false;
    } else {
        isValidSubAccount = true;
    }
    return isValidSubAccount;
}
Also used : SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) SubAccountService(org.kuali.kfs.coa.service.SubAccountService)

Example 10 with SubAccount

use of org.kuali.kfs.coa.businessobject.SubAccount in project cu-kfs by CU-CommunityApps.

the class CuSubAccountTrickleDownInactivationServiceImpl method trickleDownInactivateSubAccounts.

/**
 * @see org.kuali.kfs.coa.service.impl.SubAccountTrickleDownInactivationServiceImpl#trickleDownInactivateSubAccounts(org.kuali.kfs.coa.businessobject.Account, java.lang.String)
 */
public void trickleDownInactivateSubAccounts(Account inactivatedAccount, String documentNumber) {
    List<SubAccount> inactivatedSubAccounts = new ArrayList<SubAccount>();
    Map<SubAccount, String> alreadyLockedSubAccounts = new HashMap<SubAccount, String>();
    List<SubAccount> errorPersistingSubAccounts = new ArrayList<SubAccount>();
    Maintainable subAccountMaintainable;
    try {
        subAccountMaintainable = (Maintainable) maintenanceDocumentDictionaryService.getMaintainableClass(SubAccount.class.getName()).newInstance();
        subAccountMaintainable.setBoClass(SubAccount.class);
        subAccountMaintainable.setDocumentNumber(documentNumber);
    } catch (Exception e) {
        LOG.error("Unable to instantiate SubAccount Maintainable", e);
        throw new RuntimeException("Unable to instantiate SubAccount Maintainable", e);
    }
    inactivatedAccount.refreshReferenceObject(KFSPropertyConstants.SUB_ACCOUNTS);
    if (ObjectUtils.isNotNull(inactivatedAccount.getSubAccounts()) && !inactivatedAccount.getSubAccounts().isEmpty()) {
        for (Iterator<SubAccount> i = inactivatedAccount.getSubAccounts().iterator(); i.hasNext(); ) {
            SubAccount subAccount = i.next();
            if (subAccount.isActive()) {
                subAccountMaintainable.setBusinessObject(subAccount);
                List<MaintenanceLock> subAccountLocks = subAccountMaintainable.generateMaintenanceLocks();
                MaintenanceLock failedLock = verifyAllLocksFromThisDocument(subAccountLocks, documentNumber);
                if (failedLock != null) {
                    // another document has locked this sub account, so we don't try to inactivate the account
                    alreadyLockedSubAccounts.put(subAccount, failedLock.getDocumentNumber());
                } else {
                    // no locks other than our own (but there may have been no locks at all), just go ahead and try to update
                    subAccount.setActive(false);
                    try {
                        subAccountMaintainable.saveBusinessObject();
                        inactivatedSubAccounts.add(subAccount);
                    } catch (RuntimeException e) {
                        LOG.error("Unable to trickle-down inactivate sub-account " + subAccount.toString(), e);
                        errorPersistingSubAccounts.add(subAccount);
                    }
                }
            }
        }
        // KFSPTS-3877 add note to object level instead of document
        addNotesToAccountObject(documentNumber, inactivatedAccount, inactivatedSubAccounts, alreadyLockedSubAccounts, errorPersistingSubAccounts);
    }
}
Also used : HashMap(java.util.HashMap) SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) ArrayList(java.util.ArrayList) MaintenanceLock(org.kuali.kfs.krad.maintenance.MaintenanceLock) Maintainable(org.kuali.kfs.kns.maintenance.Maintainable)

Aggregations

SubAccount (org.kuali.kfs.coa.businessobject.SubAccount)22 A21IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.A21IndirectCostRecoveryAccount)7 A21SubAccount (org.kuali.kfs.coa.businessobject.A21SubAccount)7 ArrayList (java.util.ArrayList)4 Account (org.kuali.kfs.coa.businessobject.Account)4 IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount)3 SubAccountService (org.kuali.kfs.coa.service.SubAccountService)2 SubAccountGlobal (edu.cornell.kfs.coa.businessobject.SubAccountGlobal)1 SubAccountGlobalDetail (edu.cornell.kfs.coa.businessobject.SubAccountGlobalDetail)1 ValidationResult (edu.cornell.kfs.concur.businessobjects.ValidationResult)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Maintainable (org.kuali.kfs.kns.maintenance.Maintainable)1 DataDictionaryService (org.kuali.kfs.kns.service.DataDictionaryService)1 PersistableBusinessObject (org.kuali.kfs.krad.bo.PersistableBusinessObject)1 MaintenanceDocument (org.kuali.kfs.krad.maintenance.MaintenanceDocument)1 MaintenanceLock (org.kuali.kfs.krad.maintenance.MaintenanceLock)1 DocumentService (org.kuali.kfs.krad.service.DocumentService)1