Search in sources :

Example 6 with IndirectCostRecoveryAccount

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

the class GlobalIndirectCostRecoveryAccountsRuleTest method testSubAccountGlobalCheckICRAccountTotalDistributionOnDetailWillBe100PercentAfterUpdate_Pass.

@Test
public void testSubAccountGlobalCheckICRAccountTotalDistributionOnDetailWillBe100PercentAfterUpdate_Pass() {
    LOG.debug("enter testSubAccountGlobalCheckICRAccountTotalDistributionOnDetailWillBe100PercentAfterUpdate_Pass");
    SubAccountGlobal subAccountGlobal = (SubAccountGlobal) SubAccountGlobalFixture.SUB_ACCT_GLOBAL_3333333_100_ACTIVE_1111111_2222222_98_2_INACTIVE.getSubAccountGlobal();
    SubAccountGlobalDetail subAccountGlobalDetail = SubAccountGlobalDetailFixture.SUB_ACCOUNT_GLOBAL_DETAIL_1111111_2222222_98_2.getSubAccountGlobalDetail();
    List<IndirectCostRecoveryAccount> existingIcrAccountsOnDetail = new ArrayList<IndirectCostRecoveryAccount>();
    existingIcrAccountsOnDetail.addAll(subAccountGlobalDetail.getSubAccount().getA21SubAccount().getA21IndirectCostRecoveryAccounts());
    LOG.debug("updates");
    List<IndirectCostRecoveryAccountChange> updates = subAccountGlobal.getIndirectCostRecoveryAccounts();
    logDetailsForIcrAccountChanges(updates);
    LOG.debug("existing");
    logDetailsForIcrAccounts(existingIcrAccountsOnDetail);
    boolean result = globalIndirectCostRecoveryAccountsRule.checkICRAccountTotalDistributionOnDetailWillBe100PercentAfterUpdate(updates, existingIcrAccountsOnDetail, subAccountGlobalDetail, subAccountGlobal);
    assertTrue("Updated Sub Account Global ICR account distribution should have been 100%", result);
}
Also used : SubAccountGlobal(edu.cornell.kfs.coa.businessobject.SubAccountGlobal) SubAccountGlobalDetail(edu.cornell.kfs.coa.businessobject.SubAccountGlobalDetail) IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) IndirectCostRecoveryAccountChange(edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with IndirectCostRecoveryAccount

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

the class AccountGlobalRule method checkICRCollectionExistsWhenUpdatingToCGSubFund.

protected boolean checkICRCollectionExistsWhenUpdatingToCGSubFund(CuAccountGlobal newAccount, String subFundGroupCode) {
    boolean success = true;
    if (newAccount.getActiveIndirectCostRecoveryAccounts().isEmpty()) {
        if (ObjectUtils.isNotNull(newAccount.getAccountGlobalDetails()) && !newAccount.getAccountGlobalDetails().isEmpty()) {
            for (AccountGlobalDetail accountGlobalDetail : newAccount.getAccountGlobalDetails()) {
                List<IndirectCostRecoveryAccount> activeICRList = getActiveUpdatedIcrAccounts(newAccount, accountGlobalDetail);
                if (activeICRList.isEmpty()) {
                    success &= false;
                    putFieldError(KFSPropertyConstants.INDIRECT_COST_RECOVERY_ACCOUNTS, CUKFSKeyConstants.ERROR_DOCUMENT_ACCT_GLB_MAINT_ICR_EMPTY_FOR_CG_ACCOUNT, new String[] { subFundGroupCode, accountGlobalDetail.getAccountNumber() });
                }
            }
        }
    }
    return success;
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail)

Example 8 with IndirectCostRecoveryAccount

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

the class AccountGlobalRule method checkICRCollectionDoesNotExistWhenUpdatingToNonCGSubFund.

protected boolean checkICRCollectionDoesNotExistWhenUpdatingToNonCGSubFund(CuAccountGlobal newAccount, String subFundGroupCode) {
    boolean success = true;
    boolean hasActiveUpdates = !newAccount.getActiveIndirectCostRecoveryAccounts().isEmpty();
    if (hasActiveUpdates) {
        success = false;
        putFieldError(KFSPropertyConstants.INDIRECT_COST_RECOVERY_ACCOUNTS, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_CG_ICR_FIELDS_FILLED_FOR_NON_CG_ACCOUNT, newAccount.getSubFundGroupCode());
    } else {
        if (ObjectUtils.isNotNull(newAccount.getAccountGlobalDetails()) && !newAccount.getAccountGlobalDetails().isEmpty()) {
            for (AccountGlobalDetail accountGlobalDetail : newAccount.getAccountGlobalDetails()) {
                List<IndirectCostRecoveryAccount> activeICRList = getActiveUpdatedIcrAccounts(newAccount, accountGlobalDetail);
                if (!activeICRList.isEmpty()) {
                    success &= false;
                    putFieldError(KFSPropertyConstants.INDIRECT_COST_RECOVERY_ACCOUNTS, CUKFSKeyConstants.ERROR_DOCUMENT_ACCT_GLB_MAINT_ICR_NOT_EMPTY_FOR_NON_CG_ACCOUNT, new String[] { subFundGroupCode, accountGlobalDetail.getAccountNumber() });
                }
            }
        }
    }
    return success;
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail)

Example 9 with IndirectCostRecoveryAccount

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

the class AccountGlobalRule method getActiveUpdatedIcrAccounts.

private List<IndirectCostRecoveryAccount> getActiveUpdatedIcrAccounts(CuAccountGlobal newAccount, AccountGlobalDetail accountGlobalDetail) {
    accountGlobalDetail.refreshReferenceObject(KFSPropertyConstants.ACCOUNT);
    List<IndirectCostRecoveryAccount> existingICRList = accountGlobalDetail.getAccount().getIndirectCostRecoveryAccounts();
    List<IndirectCostRecoveryAccount> copyOfExistingICRList = new ArrayList<IndirectCostRecoveryAccount>();
    if (existingICRList != null && !existingICRList.isEmpty()) {
        for (IndirectCostRecoveryAccount icrAccount : existingICRList) {
            copyOfExistingICRList.add(new IndirectCostRecoveryAccount(icrAccount));
        }
    }
    List<IndirectCostRecoveryAccount> updatedICRList = SpringContext.getBean(GlobalObjectWithIndirectCostRecoveryAccountsService.class).buildUpdatedIcrAccounts(newAccount, accountGlobalDetail, copyOfExistingICRList);
    List<IndirectCostRecoveryAccount> activeICRList = getActiveICRAccounts(updatedICRList);
    return activeICRList;
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) GlobalObjectWithIndirectCostRecoveryAccountsService(edu.cornell.kfs.coa.service.GlobalObjectWithIndirectCostRecoveryAccountsService) ArrayList(java.util.ArrayList)

Example 10 with IndirectCostRecoveryAccount

use of org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount 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)

Aggregations

IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount)20 ArrayList (java.util.ArrayList)11 IndirectCostRecoveryAccountChange (edu.cornell.kfs.coa.businessobject.IndirectCostRecoveryAccountChange)8 AccountGlobalDetail (org.kuali.kfs.coa.businessobject.AccountGlobalDetail)7 SubAccountGlobalDetail (edu.cornell.kfs.coa.businessobject.SubAccountGlobalDetail)6 Test (org.junit.Test)6 A21IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.A21IndirectCostRecoveryAccount)5 CuAccountGlobal (edu.cornell.kfs.coa.businessobject.CuAccountGlobal)3 SubAccountGlobal (edu.cornell.kfs.coa.businessobject.SubAccountGlobal)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Account (org.kuali.kfs.coa.businessobject.Account)3 A21SubAccount (org.kuali.kfs.coa.businessobject.A21SubAccount)2 SubAccount (org.kuali.kfs.coa.businessobject.SubAccount)2 GlobalBusinessObjectDetailBase (org.kuali.kfs.krad.bo.GlobalBusinessObjectDetailBase)2 AppropriationAccount (edu.cornell.kfs.coa.businessobject.AppropriationAccount)1 GlobalObjectWithIndirectCostRecoveryAccountsService (edu.cornell.kfs.coa.service.GlobalObjectWithIndirectCostRecoveryAccountsService)1 BigDecimal (java.math.BigDecimal)1 MaintenanceDocumentRestrictions (org.kuali.kfs.kns.document.authorization.MaintenanceDocumentRestrictions)1 BusinessObjectAuthorizationService (org.kuali.kfs.kns.service.BusinessObjectAuthorizationService)1