Search in sources :

Example 6 with IndirectCostRecoveryAccountChange

use of edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange in project cu-kfs by CU-CommunityApps.

the class GlobalObjectWithIndirectCostRecoveryAccountsServiceImpl method buildUpdatedIcrAccounts.

public List<IndirectCostRecoveryAccount> buildUpdatedIcrAccounts(GlobalObjectWithIndirectCostRecoveryAccounts globalObjectWithIndirectCostRecoveryAccounts, GlobalBusinessObjectDetailBase globalDetail, List<IndirectCostRecoveryAccount> icrAccounts) {
    List<IndirectCostRecoveryAccount> updatedIcrAccounts = new ArrayList<IndirectCostRecoveryAccount>();
    Map<Integer, Integer> alreadyUpdatedIndexes = new HashMap<>();
    List<IndirectCostRecoveryAccount> addList = new ArrayList<IndirectCostRecoveryAccount>();
    List<IndirectCostRecoveryAccountChange> newIndirectCostRecoveryAccounts = globalObjectWithIndirectCostRecoveryAccounts.getIndirectCostRecoveryAccounts();
    if (newIndirectCostRecoveryAccounts.size() > 0) {
        for (IndirectCostRecoveryAccountChange newICR : newIndirectCostRecoveryAccounts) {
            boolean foundMatch = false;
            int positionForMatchWithSameActiveIndicator = -1;
            int currentPosition = 0;
            int maxPosition = icrAccounts.size();
            while (noMatchFoundOrSameActiveIndicatorMatchFoundAndStillHaveICRAccountToCheck(currentPosition, maxPosition, foundMatch, positionForMatchWithSameActiveIndicator)) {
                if (!alreadyUpdatedIndexes.containsKey(currentPosition)) {
                    IndirectCostRecoveryAccount existingICR = icrAccounts.get(currentPosition);
                    if (newICR.matchesICRAccount(existingICR)) {
                        foundMatch = true;
                        if (newICR.isActive() == existingICR.isActive()) {
                            positionForMatchWithSameActiveIndicator = currentPosition;
                        } else {
                            existingICR.setActive(newICR.isActive());
                            alreadyUpdatedIndexes.put(currentPosition, currentPosition);
                            if (positionForMatchWithSameActiveIndicator != -1) {
                                positionForMatchWithSameActiveIndicator = -1;
                            }
                        }
                    }
                }
                currentPosition++;
            }
            if (foundMatch && positionForMatchWithSameActiveIndicator != -1) {
                alreadyUpdatedIndexes.put(positionForMatchWithSameActiveIndicator, positionForMatchWithSameActiveIndicator);
            }
            if (!foundMatch) {
                IndirectCostRecoveryAccount icrAccount = globalObjectWithIndirectCostRecoveryAccounts.createIndirectCostRecoveryAccountFromChange(globalDetail, newICR);
                addList.add(icrAccount);
            }
        }
        updatedIcrAccounts = combineExistingAndNewAccounts(icrAccounts, addList);
    } else {
        updatedIcrAccounts = icrAccounts;
    }
    return updatedIcrAccounts;
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) HashMap(java.util.HashMap) IndirectCostRecoveryAccountChange(edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange) ArrayList(java.util.ArrayList)

Example 7 with IndirectCostRecoveryAccountChange

use of edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange in project cu-kfs by CU-CommunityApps.

the class AccountGlobalPreRules method checkForContinuationAccounts.

protected void checkForContinuationAccounts() {
    LOG.debug("entering checkForContinuationAccounts()");
    if (StringUtils.isNotBlank(accountGlobal.getReportsToAccountNumber())) {
        Account account = checkForContinuationAccount("Fringe Benefit Account", accountGlobal.getReportsToChartOfAccountsCode(), accountGlobal.getReportsToAccountNumber(), "");
        if (ObjectUtils.isNotNull(account)) {
            // override old user inputs
            accountGlobal.setReportsToAccountNumber(account.getAccountNumber());
            accountGlobal.setReportsToChartOfAccountsCode(account.getChartOfAccountsCode());
        }
    }
    if (StringUtils.isNotBlank(accountGlobal.getEndowmentIncomeAccountNumber())) {
        Account account = checkForContinuationAccount("Endowment Account", accountGlobal.getEndowmentIncomeAcctFinCoaCd(), accountGlobal.getEndowmentIncomeAccountNumber(), "");
        if (ObjectUtils.isNotNull(account)) {
            // override old user inputs
            accountGlobal.setEndowmentIncomeAccountNumber(account.getAccountNumber());
            accountGlobal.setEndowmentIncomeAcctFinCoaCd(account.getChartOfAccountsCode());
        }
    }
    if (StringUtils.isNotBlank(accountGlobal.getIncomeStreamAccountNumber())) {
        Account account = checkForContinuationAccount("Income Stream Account", accountGlobal.getIncomeStreamFinancialCoaCode(), accountGlobal.getIncomeStreamAccountNumber(), "");
        if (ObjectUtils.isNotNull(account)) {
            // override old user inputs
            accountGlobal.setIncomeStreamAccountNumber(account.getAccountNumber());
            accountGlobal.setIncomeStreamFinancialCoaCode(account.getChartOfAccountsCode());
        }
    }
    if (StringUtils.isNotBlank(accountGlobal.getContractControlAccountNumber())) {
        Account account = checkForContinuationAccount("Contract Control Account", accountGlobal.getContractControlFinCoaCode(), accountGlobal.getContractControlAccountNumber(), "");
        if (ObjectUtils.isNotNull(account)) {
            // override old user inputs
            accountGlobal.setContractControlAccountNumber(account.getAccountNumber());
            accountGlobal.setContractControlFinCoaCode(account.getChartOfAccountsCode());
        }
    }
    for (IndirectCostRecoveryAccountChange icra : accountGlobal.getActiveIndirectCostRecoveryAccounts()) {
        if (StringUtils.isNotBlank(icra.getIndirectCostRecoveryAccountNumber())) {
            Account account = checkForContinuationAccount("Indirect Cost Recovery Account", icra.getIndirectCostRecoveryAccountNumber(), icra.getIndirectCostRecoveryFinCoaCode(), "");
            if (ObjectUtils.isNotNull(account)) {
                // override old user inputs
                icra.setIndirectCostRecoveryAccountNumber(account.getAccountNumber());
                icra.setIndirectCostRecoveryFinCoaCode(account.getChartOfAccountsCode());
            }
        }
    }
}
Also used : Account(org.kuali.kfs.coa.businessobject.Account) IndirectCostRecoveryAccountChange(edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange)

Example 8 with IndirectCostRecoveryAccountChange

use of edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange in project cu-kfs by CU-CommunityApps.

the class GlobalIndirectCostRecoveryAccountsRule method buildCurrentActiveICRAccountsAfterICRUpdates.

protected List<IndirectCostRecoveryAccount> buildCurrentActiveICRAccountsAfterICRUpdates(List<IndirectCostRecoveryAccountChange> icrUpdates, List<IndirectCostRecoveryAccount> existingIcrAccounts, GlobalBusinessObjectDetailBase globalDetail, GlobalObjectWithIndirectCostRecoveryAccounts globalObjectWithIndirectCostRecoveryAccounts) {
    List<IndirectCostRecoveryAccount> currentActiveIndirectCostRecoveryAccountList = new ArrayList<IndirectCostRecoveryAccount>();
    List<IndirectCostRecoveryAccount> existingICRsToBeUpdated = new ArrayList<IndirectCostRecoveryAccount>();
    List<IndirectCostRecoveryAccount> icrAccountsNotUpdated = new ArrayList<IndirectCostRecoveryAccount>();
    for (IndirectCostRecoveryAccount icrAccount : existingIcrAccounts) {
        icrAccountsNotUpdated.add(icrAccount);
    }
    List<IndirectCostRecoveryAccount> icrAccountsToBeUpdatedToActive = new ArrayList<IndirectCostRecoveryAccount>();
    List<IndirectCostRecoveryAccount> icrAccountsToBeAddedAsActive = new ArrayList<IndirectCostRecoveryAccount>();
    if (icrUpdates.size() > 0) {
        // for each new icr on account global doc search for a matching icr on account to be updated
        for (IndirectCostRecoveryAccountChange newICR : icrUpdates) {
            boolean foundMatch = false;
            existingICRsToBeUpdated.clear();
            for (IndirectCostRecoveryAccount icrAccount : icrAccountsNotUpdated) {
                existingICRsToBeUpdated.add(icrAccount);
            }
            IndirectCostRecoveryAccount matchingICRAccountWithSameActiveIndicator = null;
            int currentPosition = 0;
            int maxPosition = existingICRsToBeUpdated.size();
            while (noMatchFoundOrSameActiveIndicatorMatchFoundAndStillHaveICRAccountsToCheck(currentPosition, maxPosition, foundMatch, matchingICRAccountWithSameActiveIndicator)) {
                IndirectCostRecoveryAccount existingICR = existingICRsToBeUpdated.get(currentPosition);
                if (newICR.matchesICRAccount(existingICR)) {
                    foundMatch = true;
                    if (newICR.isActive() == existingICR.isActive()) {
                        // both have the same active indicator, save in
                        // a temp and keep looking
                        matchingICRAccountWithSameActiveIndicator = existingICR;
                    } else {
                        // done stop looking
                        if (newICR.isActive()) {
                            // add to update active
                            IndirectCostRecoveryAccount icrAccount = globalObjectWithIndirectCostRecoveryAccounts.createIndirectCostRecoveryAccountFromChange(globalDetail, newICR);
                            icrAccountsToBeUpdatedToActive.add(icrAccount);
                        }
                        icrAccountsNotUpdated.remove(existingICR);
                        if (ObjectUtils.isNotNull(matchingICRAccountWithSameActiveIndicator)) {
                            matchingICRAccountWithSameActiveIndicator = null;
                        }
                    }
                }
                currentPosition++;
            }
            if (foundMatch && ObjectUtils.isNotNull(matchingICRAccountWithSameActiveIndicator)) {
                // done stop looking
                if (matchingICRAccountWithSameActiveIndicator.isActive()) {
                    // add to update active
                    IndirectCostRecoveryAccount icrAccount = globalObjectWithIndirectCostRecoveryAccounts.createIndirectCostRecoveryAccountFromChange(globalDetail, newICR);
                    icrAccountsToBeUpdatedToActive.add(icrAccount);
                }
                icrAccountsNotUpdated.remove(matchingICRAccountWithSameActiveIndicator);
            }
            if (!foundMatch) {
                // done stop looking
                if (newICR.isActive()) {
                    // add to update active
                    IndirectCostRecoveryAccount icrAccount = globalObjectWithIndirectCostRecoveryAccounts.createIndirectCostRecoveryAccountFromChange(globalDetail, newICR);
                    icrAccountsToBeAddedAsActive.add(icrAccount);
                }
            }
        }
        if (icrAccountsToBeUpdatedToActive.size() > 0) {
            for (IndirectCostRecoveryAccount icrAccount : icrAccountsToBeUpdatedToActive) {
                currentActiveIndirectCostRecoveryAccountList.add(icrAccount);
            }
        }
        if (icrAccountsToBeAddedAsActive.size() > 0) {
            for (IndirectCostRecoveryAccount icrAccount : icrAccountsToBeAddedAsActive) {
                currentActiveIndirectCostRecoveryAccountList.add(icrAccount);
            }
        }
        if (ObjectUtils.isNotNull(icrAccountsNotUpdated) && !icrAccountsNotUpdated.isEmpty()) {
            for (IndirectCostRecoveryAccount icrAccount : icrAccountsNotUpdated) {
                if (icrAccount.isActive()) {
                    currentActiveIndirectCostRecoveryAccountList.add(icrAccount);
                }
            }
        }
    }
    return currentActiveIndirectCostRecoveryAccountList;
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) IndirectCostRecoveryAccountChange(edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange) ArrayList(java.util.ArrayList)

Example 9 with IndirectCostRecoveryAccountChange

use of edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange in project cu-kfs by CU-CommunityApps.

the class GlobalIndirectCostRecoveryAccountsRule method validateIndirectCostRecoveryAccounts.

protected boolean validateIndirectCostRecoveryAccounts(List<IndirectCostRecoveryAccountChange> indirectCostRecoveryAccounts) {
    boolean success = true;
    int index = 0;
    for (IndirectCostRecoveryAccountChange icrAccount : indirectCostRecoveryAccounts) {
        String errorPath = MAINTAINABLE_ERROR_PREFIX + KFSPropertyConstants.INDIRECT_COST_RECOVERY_ACCOUNTS + "[" + index + "]";
        GlobalVariables.getMessageMap().addToErrorPath(errorPath);
        success &= validateIndirectCostRecoveryAccount(icrAccount);
        GlobalVariables.getMessageMap().removeFromErrorPath(errorPath);
        index++;
    }
    return success;
}
Also used : IndirectCostRecoveryAccountChange(edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange)

Example 10 with IndirectCostRecoveryAccountChange

use of edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange in project cu-kfs by CU-CommunityApps.

the class SubAccountGlobalRule method checkCgIcrRules.

/**
 * This checks that if the ICR information is entered that it is valid for this fiscal year and that all of its fields are valid
 * as well (such as account)
 *
 * @return true if the ICR information is filled in and it is valid
 */
protected boolean checkCgIcrRules(String subAccountTypeCode, SubAccountGlobalDetail subAccountGlobalDetail) {
    SubAccountGlobal newSubAccountGlobal = (SubAccountGlobal) super.getNewBo();
    A21SubAccountChange a21 = newSubAccountGlobal.getA21SubAccount();
    if (ObjectUtils.isNull(a21)) {
        return true;
    }
    boolean success = true;
    // existence check for Financial Series ID
    if (StringUtils.isNotEmpty(a21.getFinancialIcrSeriesIdentifier())) {
        String fiscalYear = StringUtils.EMPTY + SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear();
        String icrSeriesId = a21.getFinancialIcrSeriesIdentifier();
        Map<String, String> pkMap = new HashMap<String, String>();
        pkMap.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, fiscalYear);
        pkMap.put(KFSPropertyConstants.FINANCIAL_ICR_SERIES_IDENTIFIER, icrSeriesId);
        Collection<IndirectCostRecoveryRateDetail> icrRateDetails = getBoService().findMatching(IndirectCostRecoveryRateDetail.class, pkMap);
        if (ObjectUtils.isNull(icrRateDetails) || icrRateDetails.isEmpty()) {
            String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(A21SubAccount.class, KFSPropertyConstants.FINANCIAL_ICR_SERIES_IDENTIFIER);
            putFieldError(KFSPropertyConstants.A21_SUB_ACCOUNT + "." + KFSPropertyConstants.FINANCIAL_ICR_SERIES_IDENTIFIER, KFSKeyConstants.ERROR_EXISTENCE, label + " (" + icrSeriesId + ")");
            success = false;
        } else {
            for (IndirectCostRecoveryRateDetail icrRateDetail : icrRateDetails) {
                if (ObjectUtils.isNull(icrRateDetail.getIndirectCostRecoveryRate())) {
                    putFieldError(KFSPropertyConstants.A21_SUB_ACCOUNT + "." + KFSPropertyConstants.FINANCIAL_ICR_SERIES_IDENTIFIER, KFSKeyConstants.IndirectCostRecovery.ERROR_DOCUMENT_ICR_RATE_NOT_FOUND, new String[] { fiscalYear, icrSeriesId });
                    success = false;
                    break;
                }
            }
        }
    }
    // existence check for ICR Account
    for (IndirectCostRecoveryAccountChange account : newSubAccountGlobal.getActiveIndirectCostRecoveryAccounts()) {
        if (StringUtils.isNotBlank(account.getIndirectCostRecoveryAccountNumber()) && StringUtils.isNotBlank(account.getIndirectCostRecoveryFinCoaCode())) {
            if (ObjectUtils.isNull(account.getIndirectCostRecoveryAccount())) {
                putFieldError(KFSPropertyConstants.INDIRECT_COST_RECOVERY_ACCOUNTS, KFSKeyConstants.ERROR_EXISTENCE, "ICR Account: " + account.getIndirectCostRecoveryFinCoaCode() + "-" + account.getIndirectCostRecoveryAccountNumber());
                success = false;
                break;
            }
        }
    }
    // The cost sharing fields must be empty if the sub-account type code is for ICR
    if (checkCgCostSharingIsEmpty(subAccountGlobalDetail) == false) {
        putFieldError(KFSPropertyConstants.A21_SUB_ACCOUNT + "." + KFSPropertyConstants.COST_SHARE_SOURCE_CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.ERROR_DOCUMENT_SUBACCTMAINT_COST_SHARE_SECTION_INVALID, subAccountTypeCode);
        success &= false;
    }
    return success;
}
Also used : SubAccountGlobal(edu.cornell.kfs.coa.businessobject.SubAccountGlobal) HashMap(java.util.HashMap) IndirectCostRecoveryAccountChange(edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange) IndirectCostRecoveryRateDetail(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryRateDetail) A21SubAccountChange(edu.cornell.kfs.coa.businessobject.A21SubAccountChange) DataDictionaryService(org.kuali.kfs.kns.service.DataDictionaryService)

Aggregations

IndirectCostRecoveryAccountChange (edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange)12 IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount)8 SubAccountGlobalDetail (edu.cornell.kfs.coa.businessobject.SubAccountGlobalDetail)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 SubAccountGlobal (edu.cornell.kfs.coa.businessobject.SubAccountGlobal)4 CuAccountGlobal (edu.cornell.kfs.coa.businessobject.CuAccountGlobal)3 AccountGlobalDetail (org.kuali.kfs.coa.businessobject.AccountGlobalDetail)3 HashMap (java.util.HashMap)2 A21SubAccountChange (edu.cornell.kfs.coa.businessobject.A21SubAccountChange)1 Account (org.kuali.kfs.coa.businessobject.Account)1 IndirectCostRecoveryRateDetail (org.kuali.kfs.coa.businessobject.IndirectCostRecoveryRateDetail)1 DataDictionaryService (org.kuali.kfs.kns.service.DataDictionaryService)1