Search in sources :

Example 1 with COAHierarchyEntity

use of org.mifos.accounts.financial.business.COAHierarchyEntity in project head by mifos.

the class InterestPostingAccountingEntryTest method makeCategory.

protected COABO makeCategory(Short categoryId, GLCategoryType categoryType, String glCode) {
    COABO category = new COABO(categoryId, categoryType.name(), new GLCodeEntity(categoryId, glCode));
    COAHierarchyEntity hierarchy = new COAHierarchyEntity(category, null);
    category.setCoaHierarchy(hierarchy);
    category.setCategoryType(categoryType);
    return category;
}
Also used : COABO(org.mifos.accounts.financial.business.COABO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) COAHierarchyEntity(org.mifos.accounts.financial.business.COAHierarchyEntity)

Example 2 with COAHierarchyEntity

use of org.mifos.accounts.financial.business.COAHierarchyEntity in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testAddCoaHierarchy.

/**
     * The Chart of Accounts hierarchy is created when TestCaseInitializer is instantiated in parent class static
     * initializer. Verify it worked as planned.
     */
@Test
public void testAddCoaHierarchy() {
    short id = TestGeneralLedgerCode.COST_OF_FUNDS;
    COAHierarchyEntity h = (COAHierarchyEntity) StaticHibernateUtil.getSessionTL().load(COAHierarchyEntity.class, id);
    Assert.assertEquals(DIRECT_EXPENDITURE_GL_ACCOUNT_CODE, h.getParentAccount().getCoa().getAssociatedGlcode().getGlcode());
}
Also used : COAHierarchyEntity(org.mifos.accounts.financial.business.COAHierarchyEntity) Test(org.junit.Test)

Example 3 with COAHierarchyEntity

use of org.mifos.accounts.financial.business.COAHierarchyEntity in project head by mifos.

the class InterestPostingAccountingEntryTest method makeChildCoaboOf.

/**
     * Establish child-parent relationship between two COABO instances.
     *
     * <p>
     * ASSUMPTION: the parentCoa's hierarchy has been created. In other words, build the hierarchy from top down.
     *
     * @throws RuntimeException  if parentCoa has no associated COAHierarchy.
     */
protected COABO makeChildCoaboOf(COABO parentCoa, Short accountId, String accountName, String glCode) {
    COAHierarchyEntity parentCoah = parentCoa.getCoaHierarchy();
    if (parentCoah == null) {
        throw new RuntimeException("ParentCoa.coaHierarchy has not been defined");
    }
    COABO childCoa = new COABO(accountId, accountName, new GLCodeEntity(accountId, glCode));
    COAHierarchyEntity hierarchy = new COAHierarchyEntity(childCoa, parentCoa.getCoaHierarchy());
    childCoa.setCoaHierarchy(hierarchy);
    return childCoa;
}
Also used : COABO(org.mifos.accounts.financial.business.COABO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) COAHierarchyEntity(org.mifos.accounts.financial.business.COAHierarchyEntity)

Example 4 with COAHierarchyEntity

use of org.mifos.accounts.financial.business.COAHierarchyEntity in project head by mifos.

the class FinancialInitializer method accountHierarchyMatch.

/**
     * Compares hierarchy (parent GL codes) of a general ledger account in the
     * database to an unpersisted general ledger account.
     */
private static boolean accountHierarchyMatch(COABO account1, GLAccount account2) {
    COAHierarchyEntity account1hierarchy = account1.getCoaHierarchy().getParentAccount();
    if (null == account1hierarchy) {
        if (null == account2.parentGlCode) {
            return true;
        }
        logger.error("persisted account has no parent, but new account does");
        return false;
    }
    COABO account1parent = account1hierarchy.getCoa();
    String account1parentGlCode = account1parent.getGlCode();
    if (!account1parentGlCode.equals(account2.parentGlCode)) {
        logger.error("persistent account parent gl code was " + account1parentGlCode + ", but new account parent gl code was " + account2.parentGlCode);
        return false;
    }
    return true;
}
Also used : COABO(org.mifos.accounts.financial.business.COABO) COAHierarchyEntity(org.mifos.accounts.financial.business.COAHierarchyEntity)

Example 5 with COAHierarchyEntity

use of org.mifos.accounts.financial.business.COAHierarchyEntity in project head by mifos.

the class LegacyAccountDao method addGeneralLedgerAccount.

/**
     * @see #addGeneralLedgerAccount(String, String, String, GLCategoryType)
     */
public COABO addGeneralLedgerAccount(String name, String glcode, Short parent_id, GLCategoryType categoryType) {
    Short id = getAccountIdFromGlCode(glcode);
    if (id != null) {
        throw new MifosRuntimeException("An account already exists with glcode: " + glcode + ". id was " + id);
    }
    GLCodeEntity glCodeEntity = new GLCodeEntity(null, glcode);
    try {
        createOrUpdate(glCodeEntity);
        COABO newAccount = new COABO(name, glCodeEntity);
        newAccount.setCategoryType(categoryType);
        createOrUpdate(newAccount);
        COABO parentCOA;
        COAHierarchyEntity coaHierarchyEntity = null;
        if (null == parent_id) {
            coaHierarchyEntity = new COAHierarchyEntity(newAccount, null);
        } else {
            parentCOA = (COABO) StaticHibernateUtil.getSessionTL().load(COABO.class, parent_id.shortValue());
            coaHierarchyEntity = new COAHierarchyEntity(newAccount, parentCOA.getCoaHierarchy());
        }
        createOrUpdate(coaHierarchyEntity);
        newAccount.setCoaHierarchy(coaHierarchyEntity);
        StaticHibernateUtil.commitTransaction();
        return newAccount;
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) COABO(org.mifos.accounts.financial.business.COABO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) COAHierarchyEntity(org.mifos.accounts.financial.business.COAHierarchyEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

COAHierarchyEntity (org.mifos.accounts.financial.business.COAHierarchyEntity)5 COABO (org.mifos.accounts.financial.business.COABO)4 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)3 Test (org.junit.Test)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1