Search in sources :

Example 26 with Account

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

the class GlobalIndirectCostRecoveryAccountsRule method validateIndirectCostRecoveryAccount.

protected boolean validateIndirectCostRecoveryAccount(IndirectCostRecoveryAccountChange icrAccount) {
    boolean success = true;
    String chartOfAccountsCode = icrAccount.getIndirectCostRecoveryFinCoaCode();
    String accountNumber = icrAccount.getIndirectCostRecoveryAccountNumber();
    BigDecimal icraAccountLinePercentage = ObjectUtils.isNotNull(icrAccount.getAccountLinePercent()) ? icrAccount.getAccountLinePercent() : BigDecimal.ZERO;
    boolean active = icrAccount.isActive();
    if (StringUtils.isBlank(chartOfAccountsCode)) {
        GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ICR_CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.ERROR_REQUIRED, getDDAttributeLabel(KFSPropertyConstants.ICR_CHART_OF_ACCOUNTS_CODE));
        success &= false;
    }
    if (StringUtils.isBlank(accountNumber)) {
        GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ICR_ACCOUNT_NUMBER, KFSKeyConstants.ERROR_REQUIRED, getDDAttributeLabel(KFSPropertyConstants.ICR_ACCOUNT_NUMBER));
        success &= false;
    }
    if (StringUtils.isNotBlank(chartOfAccountsCode) && StringUtils.isNotBlank(accountNumber)) {
        Map<String, String> chartAccountMap = new HashMap<String, String>();
        chartAccountMap.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
        if (getBoService().countMatching(Chart.class, chartAccountMap) < 1) {
            GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ICR_CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.ERROR_EXISTENCE, getDDAttributeLabel(KFSPropertyConstants.ICR_CHART_OF_ACCOUNTS_CODE));
            success &= false;
        }
        chartAccountMap.put(KFSPropertyConstants.ACCOUNT_NUMBER, accountNumber);
        if (getBoService().countMatching(Account.class, chartAccountMap) < 1) {
            GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ICR_ACCOUNT_NUMBER, KFSKeyConstants.ERROR_EXISTENCE, getDDAttributeLabel(KFSPropertyConstants.ICR_ACCOUNT_NUMBER));
            success &= false;
        }
        if (success && active) {
            Collection<Account> accounts = getBoService().findMatching(Account.class, chartAccountMap);
            if (ObjectUtils.isNotNull(accounts) && accounts.size() > 0) {
                Account account = accounts.iterator().next();
                if (account.isClosed()) {
                    GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ICR_ACCOUNT_NUMBER, CUKFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ICR_ACCOUNT_CANNOT_BE_INACTIVE, chartOfAccountsCode + "-" + accountNumber);
                    success &= false;
                }
            }
        }
    }
    if (icraAccountLinePercentage.compareTo(BigDecimal.ZERO) <= 0 || icraAccountLinePercentage.compareTo(ONE_HUNDRED_PERCENT) == 1) {
        GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ICR_ACCOUNT_LINE_PERCENT, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ICR_ACCOUNT_INVALID_LINE_PERCENT);
        success &= false;
    }
    return success;
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) Account(org.kuali.kfs.coa.businessobject.Account) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal) Chart(org.kuali.kfs.coa.businessobject.Chart)

Example 27 with Account

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

the class SubAccountGlobalRule method checkCgRules.

/**
 * Checks to make sure that if cgAuthorized is false it succeeds immediately, otherwise it checks that all the information
 * for CG is correctly entered and identified including:
 * <ul>
 * <li>If the {@link SubFundGroup} isn't for Contracts and Grants then check to make sure that the cost share and ICR fields are
 * not empty</li>
 * <li>If it isn't a child of CG, then the SubAccount must be of type ICR</li>
 * </ul>
 *
 * @param document
 * @return true if the user is not authorized to change CG fields, otherwise it checks the above conditions
 */
protected boolean checkCgRules(SubAccountGlobal newSubAccountGlobal, SubAccountGlobalDetail subAccountGlobalDetail) {
    boolean success = true;
    // short circuit if the parent account is NOT part of a CG fund group
    boolean a21SubAccountRefreshed = false;
    subAccountGlobalDetail.refreshReferenceObject(KFSPropertyConstants.ACCOUNT);
    if (ObjectUtils.isNotNull(subAccountGlobalDetail.getAccount())) {
        Account account = subAccountGlobalDetail.getAccount();
        account.refreshReferenceObject(KFSPropertyConstants.SUB_FUND_GROUP);
        if (ObjectUtils.isNotNull(account.getSubFundGroup())) {
            // compare them, exit if the account isn't for contracts and grants
            if (!getSubFundGroupService().isForContractsAndGrants(account.getSubFundGroup())) {
                if (checkCgCostSharingIsEmpty(subAccountGlobalDetail) == false) {
                    putFieldError(KFSPropertyConstants.A21_SUB_ACCOUNT + "." + KFSPropertyConstants.COST_SHARE_SOURCE_CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.ERROR_DOCUMENT_SUBACCTMAINT_NON_FUNDED_ACCT_CS_INVALID, new String[] { getSubFundGroupService().getContractsAndGrantsDenotingAttributeLabel(), getSubFundGroupService().getContractsAndGrantsDenotingValueForMessage() });
                    success = false;
                }
                if (checkCgIcrIsEmpty() == false) {
                    putFieldError(KFSPropertyConstants.A21_SUB_ACCOUNT + "." + KFSPropertyConstants.INDIRECT_COST_RECOVERY_TYPE_CODE, KFSKeyConstants.ERROR_DOCUMENT_SUBACCTMAINT_NON_FUNDED_ACCT_ICR_INVALID, new String[] { getSubFundGroupService().getContractsAndGrantsDenotingAttributeLabel(), getSubFundGroupService().getContractsAndGrantsDenotingValueForMessage() });
                    success = false;
                }
                if (newSubAccountGlobal.getIndirectCostRecoveryAccounts().isEmpty() == false) {
                    putFieldError(KFSPropertyConstants.INDIRECT_COST_RECOVERY_ACCOUNTS, KFSKeyConstants.ERROR_DOCUMENT_SUBACCTMAINT_NON_FUNDED_ACCT_ICR_INVALID, new String[] { getSubFundGroupService().getContractsAndGrantsDenotingAttributeLabel(), getSubFundGroupService().getContractsAndGrantsDenotingValueForMessage() });
                    success = false;
                }
                return success;
            }
        }
    }
    subAccountGlobalDetail.refreshReferenceObject(KFSPropertyConstants.SUB_ACCOUNT);
    if (ObjectUtils.isNull(subAccountGlobalDetail.getSubAccount())) {
        return success;
    }
    SubAccount subAccount = subAccountGlobalDetail.getSubAccount();
    subAccount.refreshReferenceObject(KFSPropertyConstants.A21_SUB_ACCOUNT);
    A21SubAccount a21 = subAccount.getA21SubAccount();
    // short circuit if there is no A21SubAccount object at all (ie, null)
    if (ObjectUtils.isNull(a21)) {
        return success;
    }
    if (!a21SubAccountRefreshed) {
        // preserve the ICRAccounts before refresh to prevent the list from dropping
        List<A21IndirectCostRecoveryAccount> icrAccounts = a21.getA21IndirectCostRecoveryAccounts();
        a21.refresh();
        a21.setA21IndirectCostRecoveryAccounts(icrAccounts);
    }
    // get a convenience reference to this code
    String cgA21TypeCode = a21.getSubAccountTypeCode();
    // if this is a Cost Sharing SubAccount, run the Cost Sharing rules
    if (KFSConstants.SubAccountType.COST_SHARE.trim().equalsIgnoreCase(StringUtils.trim(cgA21TypeCode))) {
        success &= checkCgCostSharingRules(cgA21TypeCode);
    }
    // if this is an ICR subaccount, run the ICR rules
    if (KFSConstants.SubAccountType.EXPENSE.trim().equals(StringUtils.trim(cgA21TypeCode))) {
        success &= checkCgIcrRules(cgA21TypeCode, subAccountGlobalDetail);
    }
    return success;
}
Also used : A21IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.A21IndirectCostRecoveryAccount) SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) Account(org.kuali.kfs.coa.businessobject.Account) A21IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.A21IndirectCostRecoveryAccount) A21SubAccount(org.kuali.kfs.coa.businessobject.A21SubAccount) SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) A21SubAccount(org.kuali.kfs.coa.businessobject.A21SubAccount) A21SubAccount(org.kuali.kfs.coa.businessobject.A21SubAccount)

Example 28 with Account

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

the class ConcurAccountValidationServiceImpl method checkAccount.

public ValidationResult checkAccount(String chartOfAccountsCode, String accountNumber) {
    Account account = accountService.getByPrimaryId(chartOfAccountsCode, accountNumber);
    String accountErrorMessageString = ConcurUtils.formatStringForErrorMessage(ConcurConstants.AccountingStringFieldNames.ACCOUNT_NUMBER, chartOfAccountsCode, accountNumber);
    return checkMissingOrInactive(account, MessageFormat.format(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_EXISTENCE), accountErrorMessageString), MessageFormat.format(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_INACTIVE), accountErrorMessageString));
}
Also used : SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) Account(org.kuali.kfs.coa.businessobject.Account)

Example 29 with Account

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

the class AccountGlobalRule method checkAccountUsers.

/**
 * This method checks that the new users (fiscal officer, supervisor, manager) are not the same individual for the
 * {@link Account} being changed (contained in the {@link AccountGlobalDetail})
 *
 * @param detail - where the Account information is stored
 * @param newFiscalOfficer
 * @param newManager
 * @param newSupervisor
 * @param index - for storing the error line
 * @return true if the new users pass this sub-rule
 */
protected boolean checkAccountUsers(AccountGlobalDetail detail, Person newFiscalOfficer, Person newManager, Person newSupervisor, int index) {
    boolean success = true;
    // only need to do this check if at least one of the user fields is non null
    if (newSupervisor != null || newFiscalOfficer != null || newManager != null) {
        // loop over all AccountGlobalDetail records
        detail.refreshReferenceObject("account");
        Account account = detail.getAccount();
        if (ObjectUtils.isNotNull(account)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("old-Supervisor: " + account.getAccountSupervisoryUser());
                LOG.debug("old-FiscalOfficer: " + account.getAccountFiscalOfficerUser());
                LOG.debug("old-Manager: " + account.getAccountManagerUser());
            }
            // only need to check if they are not being overridden by the change document
            if (newSupervisor != null && newSupervisor.getPrincipalId() != null) {
                if (areTwoUsersTheSame(newSupervisor, account.getAccountFiscalOfficerUser())) {
                    success = false;
                    putFieldError(KFSPropertyConstants.ACCOUNT_CHANGE_DETAILS + "[" + index + "]." + KFSPropertyConstants.ACCOUNT_NUMBER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_EQUAL_EXISTING_FISCAL_OFFICER, new String[] { account.getAccountFiscalOfficerUser().getPrincipalName(), "Fiscal Officer", detail.getAccountNumber() });
                }
                if (areTwoUsersTheSame(newSupervisor, account.getAccountManagerUser())) {
                    success = false;
                    putFieldError(KFSPropertyConstants.ACCOUNT_CHANGE_DETAILS + "[" + index + "]." + KFSPropertyConstants.ACCOUNT_NUMBER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_SUPER_CANNOT_EQUAL_EXISTING_ACCT_MGR, new String[] { account.getAccountManagerUser().getPrincipalName(), "Account Manager", detail.getAccountNumber() });
                }
            }
            if (newManager != null && newManager.getPrincipalId() != null) {
                if (areTwoUsersTheSame(newManager, account.getAccountSupervisoryUser())) {
                    success = false;
                    putFieldError(KFSPropertyConstants.ACCOUNT_CHANGE_DETAILS + "[" + index + "]." + KFSPropertyConstants.ACCOUNT_NUMBER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_MGR_CANNOT_EQUAL_EXISTING_ACCT_SUPERVISOR, new String[] { account.getAccountSupervisoryUser().getPrincipalName(), "Account Supervisor", detail.getAccountNumber() });
                }
            }
            if (newFiscalOfficer != null && newFiscalOfficer.getPrincipalId() != null) {
                if (areTwoUsersTheSame(newFiscalOfficer, account.getAccountSupervisoryUser())) {
                    success = false;
                    putFieldError(KFSPropertyConstants.ACCOUNT_CHANGE_DETAILS + "[" + index + "]." + KFSPropertyConstants.ACCOUNT_NUMBER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_FISCAL_OFFICER_CANNOT_EQUAL_EXISTING_ACCT_SUPERVISOR, new String[] { account.getAccountSupervisoryUser().getPrincipalName(), "Account Supervisor", detail.getAccountNumber() });
                }
            }
        } else {
            LOG.warn("AccountGlobalDetail object has null account object:" + detail.getChartOfAccountsCode() + "-" + detail.getAccountNumber());
        }
    }
    return success;
}
Also used : AppropriationAccount(edu.cornell.kfs.coa.businessobject.AppropriationAccount) Account(org.kuali.kfs.coa.businessobject.Account) IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount)

Example 30 with Account

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

the class AccountGlobalRule method checkFringeBenefitAccountRule.

/**
 * the fringe benefit account (otherwise known as the reportsToAccount) is required if the fringe benefit code is set to N. The
 * fringe benefit code of the account designated to accept the fringes must be Y.
 *
 * @param newAccount
 * @return
 */
protected boolean checkFringeBenefitAccountRule(CuAccountGlobal newAccount) {
    boolean result = true;
    if (newAccount.getAccountsFringesBnftIndicator() != null && !newAccount.getAccountsFringesBnftIndicator()) {
        if (StringUtils.isBlank(newAccount.getReportsToAccountNumber())) {
            putFieldError(KFSPropertyConstants.REPORTS_TO_ACCOUNT_NUMBER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_RPTS_TO_ACCT_REQUIRED_IF_FRINGEBENEFIT_FALSE);
            result &= false;
        }
        if (StringUtils.isBlank(newAccount.getReportsToChartOfAccountsCode())) {
            putFieldError(KFSPropertyConstants.REPORTS_TO_CHART_OF_ACCOUNTS_CODE, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_RPTS_TO_ACCT_REQUIRED_IF_FRINGEBENEFIT_FALSE);
            result &= false;
        }
        if (result == false) {
            return result;
        }
        Account fringeBenefitAccount = accountService.getByPrimaryId(newAccount.getReportsToChartOfAccountsCode(), newAccount.getReportsToAccountNumber());
        if (fringeBenefitAccount == null) {
            putFieldError(KFSPropertyConstants.REPORTS_TO_ACCOUNT_NUMBER, KFSKeyConstants.ERROR_EXISTENCE, getFieldLabel(Account.class, "reportsToAccountNumber"));
            return false;
        }
        if (!fringeBenefitAccount.isActive()) {
            putFieldError(KFSPropertyConstants.REPORTS_TO_ACCOUNT_NUMBER, KFSKeyConstants.ERROR_INACTIVE, getFieldLabel(Account.class, "reportsToAccountNumber"));
            result &= false;
        }
        if (!fringeBenefitAccount.isAccountsFringesBnftIndicator()) {
            putFieldError(KFSPropertyConstants.REPORTS_TO_ACCOUNT_NUMBER, KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_RPTS_TO_ACCT_MUST_BE_FLAGGED_FRINGEBENEFIT, fringeBenefitAccount.getChartOfAccountsCode() + "-" + fringeBenefitAccount.getAccountNumber());
            result &= false;
        }
    }
    return result;
}
Also used : AppropriationAccount(edu.cornell.kfs.coa.businessobject.AppropriationAccount) Account(org.kuali.kfs.coa.businessobject.Account) IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount)

Aggregations

Account (org.kuali.kfs.coa.businessobject.Account)38 IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount)14 SubAccount (org.kuali.kfs.coa.businessobject.SubAccount)11 AppropriationAccount (edu.cornell.kfs.coa.businessobject.AppropriationAccount)9 HashMap (java.util.HashMap)6 A21SubAccount (org.kuali.kfs.coa.businessobject.A21SubAccount)6 ArrayList (java.util.ArrayList)5 BusinessObjectService (org.kuali.kfs.krad.service.BusinessObjectService)5 List (java.util.List)4 A21IndirectCostRecoveryAccount (org.kuali.kfs.coa.businessobject.A21IndirectCostRecoveryAccount)4 Message (org.kuali.kfs.sys.Message)4 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)3 AccountExtendedAttribute (edu.cornell.kfs.coa.businessobject.AccountExtendedAttribute)2 SubFundProgram (edu.cornell.kfs.coa.businessobject.SubFundProgram)2 Date (java.sql.Date)2 AccountGlobalDetail (org.kuali.kfs.coa.businessobject.AccountGlobalDetail)2 AccountService (org.kuali.kfs.coa.service.AccountService)2 SubAccountService (org.kuali.kfs.coa.service.SubAccountService)2 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)2 DocumentService (org.kuali.kfs.krad.service.DocumentService)2