Search in sources :

Example 11 with Account

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

the class AccountReversionImportServiceImpl method importAccountReversions.

/* (non-Javadoc)
	 * @see edu.cornell.kfs.coa.service.AccountReversionImportService#importAccountReversions()
	 */
public void importAccountReversions(File f) {
    // KFSPTS-2174 : Repurposed this batch job to append the loaded values to the existing table, rather than delete all current values and reload the tables from scratch
    // arid.destroyAccountReversionsAndDetails();
    int count = 0;
    String objectCode = parameterService.getParameterValueAsString("KFS-COA", "Reversion", "CASH_REVERSION_OBJECT_CODE");
    Integer fiscalYear = Integer.parseInt(parameterService.getParameterValueAsString("KFS-COA", "Reversion", "ACCOUNT_REVERSION_FISCAL_YEAR"));
    try {
        CSVReader reader = new CSVReader(new FileReader(f));
        List<String[]> lines = reader.readAll();
        Object[] array = lines.toArray();
        LOG.info("Read: " + lines.toArray().length + " records");
        for (int i = 0; i < array.length; i++) {
            String[] line = (String[]) array[i];
            String fromChart = line[0];
            String fromAcct = line[1];
            String toChart = line[2];
            String toAcct = line[3];
            LOG.info("Creating Reversion for: from account: " + fromAcct + ": to account " + toAcct);
            if (StringUtils.isNotBlank(fromChart) && StringUtils.isNotBlank(fromAcct) && StringUtils.isNotBlank(toChart) && StringUtils.isNotBlank(toAcct)) {
                AccountReversion exists = null;
                Map<String, String> pks = new HashMap<String, String>();
                pks.put("UNIV_FISCAL_YR", String.valueOf(fiscalYear));
                pks.put("FIN_COA_CD", fromChart);
                pks.put("ACCT_NBR", fromAcct);
                exists = (AccountReversion) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(AccountReversion.class, pks);
                if (ObjectUtils.isNotNull(exists)) {
                    LOG.info("Account Reversion already exists for this fiscal year (" + fiscalYear + "): from account: " + fromAcct + ": to account " + toAcct);
                    continue;
                }
                // Validate from account; cannot add account reversion if account does not exist
                Account fromAcctExists = null;
                fromAcctExists = SpringContext.getBean(AccountService.class).getByPrimaryId(fromChart, fromAcct);
                if (ObjectUtils.isNull(fromAcctExists)) {
                    LOG.info("From account (" + fromAcct + ") does not exist.");
                    LOG.info("Account Reversion already exists for this fiscal year (" + fiscalYear + "): from account: " + fromAcct + ": to account " + toAcct);
                    continue;
                }
                // Validate to account; cannot add account reversion if account does not exist
                Account toAcctExists = null;
                toAcctExists = SpringContext.getBean(AccountService.class).getByPrimaryId(fromChart, fromAcct);
                if (ObjectUtils.isNull(toAcctExists)) {
                    LOG.info("To account (" + toAcct + ") does not exist.");
                    LOG.info("Account Reversion already exists for this fiscal year (" + fiscalYear + "): from account: " + fromAcct + ": to account " + toAcct);
                    continue;
                }
                AccountReversion accountReversion = new AccountReversion();
                accountReversion.setUniversityFiscalYear(fiscalYear);
                accountReversion.setChartOfAccountsCode(fromChart);
                accountReversion.setAccountNumber(fromAcct);
                accountReversion.setBudgetReversionChartOfAccountsCode(toChart);
                accountReversion.setBudgetReversionAccountNumber(toAcct);
                accountReversion.setCashReversionFinancialChartOfAccountsCode(toChart);
                accountReversion.setCashReversionAccountNumber(toAcct);
                accountReversion.setCarryForwardByObjectCodeIndicator(false);
                accountReversion.setActive(true);
                AccountReversionDetail accountReversionDetail = new AccountReversionDetail();
                accountReversionDetail.setUniversityFiscalYear(fiscalYear);
                accountReversionDetail.setChartOfAccountsCode(fromChart);
                accountReversionDetail.setAccountNumber(fromAcct);
                accountReversionDetail.setAccountReversionCategoryCode("A1");
                accountReversionDetail.setAccountReversionCode("CA");
                accountReversionDetail.setAccountReversionObjectCode(objectCode);
                accountReversionDetail.setActive(true);
                accountReversion.addAccountReversionDetail(accountReversionDetail);
                boService.save(accountReversion);
                count++;
            }
        }
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        LOG.info("Wrote: " + count + " records");
    }
}
Also used : Account(org.kuali.kfs.coa.businessobject.Account) CSVReader(au.com.bytecode.opencsv.CSVReader) HashMap(java.util.HashMap) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) AccountReversion(edu.cornell.kfs.coa.businessobject.AccountReversion) AccountReversionDetail(edu.cornell.kfs.coa.businessobject.AccountReversionDetail) FileReader(java.io.FileReader)

Example 12 with Account

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

the class AccountVerificationWebServiceImpl method isValidAccountString.

public boolean isValidAccountString(String chartOfAccountsCode, String accountNumber, String subAccountNumber, String objectCode, String subObjectCode, String projectCode) throws Exception {
    boolean isValid = false;
    if (chartOfAccountsCode == null || chartOfAccountsCode.isEmpty() || accountNumber == null || accountNumber.isEmpty() || objectCode == null || objectCode.isEmpty()) {
        return false;
    }
    Account account = SpringContext.getBean(AccountService.class).getByPrimaryId(chartOfAccountsCode, accountNumber);
    if (account == null || account.toString().isEmpty()) {
        isValid = false;
    } else {
        // isValid = true;
        if (!account.isActive() || account.isClosed() || account.isExpired()) {
            isValid = false;
        } else {
            isValid = true;
        }
        if (objectCode != null && !objectCode.isEmpty()) {
            isValid = isValid && isValidObjectCode(chartOfAccountsCode, objectCode);
        }
        if (subAccountNumber != null && !subAccountNumber.isEmpty()) {
            isValid = isValid && isValidSubAccount(chartOfAccountsCode, accountNumber, subAccountNumber);
        }
        if (subObjectCode != null && !subObjectCode.isEmpty()) {
            isValid = isValid && isValidSubObjectCode(chartOfAccountsCode, accountNumber, objectCode, subObjectCode);
        }
        if (projectCode != null && !projectCode.isEmpty()) {
            isValid = isValid && isValidProjectCode(projectCode);
        }
    }
    return isValid;
}
Also used : SubAccount(org.kuali.kfs.coa.businessobject.SubAccount) Account(org.kuali.kfs.coa.businessobject.Account) SubAccountService(org.kuali.kfs.coa.service.SubAccountService) AccountService(org.kuali.kfs.coa.service.AccountService)

Example 13 with Account

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

the class CuAccountDelegateGlobal method generateGlobalChangesToPersist.

/**
 * @see org.kuali.kfs.krad.document.GlobalBusinessObject#applyGlobalChanges(org.kuali.rice.krad.bo.BusinessObject)
 */
@SuppressWarnings("deprecation")
public List<PersistableBusinessObject> generateGlobalChangesToPersist() {
    BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class);
    List<AccountDelegate> persistables = new ArrayList();
    List<AccountDelegateGlobalDetail> changeDocuments = this.getDelegateGlobals();
    List<AccountGlobalDetail> accountDetails = this.getAccountGlobalDetails();
    for (AccountDelegateGlobalDetail changeDocument : changeDocuments) {
        for (AccountGlobalDetail accountDetail : accountDetails) {
            Account account = (Account) boService.findByPrimaryKey(Account.class, accountDetail.getPrimaryKeys());
            // the busines rules for this document should have caught this.
            if (account == null) {
                throw new RuntimeException("Account [" + accountDetail.getChartOfAccountsCode() + "-" + accountDetail.getAccountNumber() + "] was not present in the database. " + "This should never happen under normal circumstances, as an invalid account should have " + "been caught by the Business Rules infrastructure.");
            }
            // attempt to load the existing Delegate from the DB, if it exists. we do this to avoid
            // versionNumber conflicts if we tried to just insert a new record that already existed.
            Map pkMap = new HashMap();
            // chartOfAccountsCode & accountNumber
            pkMap.putAll(accountDetail.getPrimaryKeys());
            pkMap.put("financialDocumentTypeCode", changeDocument.getFinancialDocumentTypeCode());
            pkMap.put("accountDelegateSystemId", changeDocument.getAccountDelegateUniversalId());
            AccountDelegate delegate = (AccountDelegate) boService.findByPrimaryKey(AccountDelegate.class, pkMap);
            // so lets populate it with the primary keys
            if (delegate == null) {
                delegate = new AccountDelegate();
                delegate.setChartOfAccountsCode(accountDetail.getChartOfAccountsCode());
                delegate.setAccountNumber(accountDetail.getAccountNumber());
                delegate.setAccountDelegateSystemId(changeDocument.getAccountDelegateUniversalId());
                delegate.setFinancialDocumentTypeCode(changeDocument.getFinancialDocumentTypeCode());
                delegate.setActive(true);
            } else {
                delegate.setActive(true);
            }
            // APPROVAL FROM AMOUNT
            delegate.setFinDocApprovalFromThisAmt(changeDocument.getApprovalFromThisAmount());
            // APPROVAL TO AMOUNT
            delegate.setFinDocApprovalToThisAmount(changeDocument.getApprovalToThisAmount());
            // PRIMARY ROUTING
            delegate.setAccountsDelegatePrmrtIndicator(changeDocument.getAccountDelegatePrimaryRoutingIndicator());
            // START DATE
            if (changeDocument.getAccountDelegateStartDate() != null) {
                delegate.setAccountDelegateStartDate(new Date(changeDocument.getAccountDelegateStartDate().getTime()));
            }
            persistables.add(delegate);
        }
    }
    return new ArrayList<PersistableBusinessObject>(persistables);
}
Also used : Account(org.kuali.kfs.coa.businessobject.Account) AccountDelegateGlobalDetail(org.kuali.kfs.coa.businessobject.AccountDelegateGlobalDetail) HashMap(java.util.HashMap) AccountDelegate(org.kuali.kfs.coa.businessobject.AccountDelegate) ArrayList(java.util.ArrayList) Date(java.sql.Date) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Account

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

the class CuAccountGlobal method updateAccountValuesOnAccountGlobalDetailWithNewValuesFromAccountGlobalDoc.

private Account updateAccountValuesOnAccountGlobalDetailWithNewValuesFromAccountGlobalDoc(GlobalBusinessObjectDetailBase globalDetail) {
    AccountGlobalDetail accountGlobalDetail = (AccountGlobalDetail) globalDetail;
    Account account = getBusinessObjectService().findByPrimaryKey(Account.class, accountGlobalDetail.getPrimaryKeys());
    if (ObjectUtils.isNotNull(account)) {
        updateAccountBasicFields(account);
        updateAccountExtendedAttribute(account);
        if (ObjectUtils.isNotNull(this.getIndirectCostRecoveryAccounts()) && this.getIndirectCostRecoveryAccounts().size() > 0) {
            updateIcrAccounts(globalDetail, account.getIndirectCostRecoveryAccounts());
        }
    }
    return account;
}
Also used : IndirectCostRecoveryAccount(org.kuali.kfs.coa.businessobject.IndirectCostRecoveryAccount) Account(org.kuali.kfs.coa.businessobject.Account) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail)

Example 15 with Account

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

the class AccountReversionGlobalPreRules method checkForContinuationAccounts.

/**
 * This method checks to see if the budget reversion or cash reversion accounts have continuation accounts.
 *
 * @param globalOrgReversion Global Organization Reversion to check.
 */
public void checkForContinuationAccounts(AccountReversionGlobal globalAcctReversion) {
    if (!StringUtils.isBlank(globalAcctReversion.getBudgetReversionChartOfAccountsCode()) && !StringUtils.isBlank(globalAcctReversion.getBudgetReversionAccountNumber())) {
        Account account = checkForContinuationAccount("Budget Reversion Account Number", globalAcctReversion.getBudgetReversionChartOfAccountsCode(), globalAcctReversion.getBudgetReversionAccountNumber(), "");
        if (ObjectUtils.isNotNull(account)) {
            globalAcctReversion.setBudgetReversionChartOfAccountsCode(account.getChartOfAccountsCode());
            globalAcctReversion.setBudgetReversionAccountNumber(account.getAccountNumber());
        }
    }
    if (!StringUtils.isBlank(globalAcctReversion.getCashReversionFinancialChartOfAccountsCode()) && !StringUtils.isBlank(globalAcctReversion.getBudgetReversionAccountNumber())) {
        Account account = checkForContinuationAccount("Cash Reversion Account Number", globalAcctReversion.getCashReversionFinancialChartOfAccountsCode(), globalAcctReversion.getCashReversionAccountNumber(), "");
        if (ObjectUtils.isNotNull(account)) {
            globalAcctReversion.setCashReversionFinancialChartOfAccountsCode(account.getChartOfAccountsCode());
            globalAcctReversion.setCashReversionAccountNumber(account.getAccountNumber());
        }
    }
}
Also used : AccountReversionGlobalAccount(edu.cornell.kfs.coa.businessobject.AccountReversionGlobalAccount) Account(org.kuali.kfs.coa.businessobject.Account)

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