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;
}
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());
}
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;
}
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;
}
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);
}
}
Aggregations