Search in sources :

Example 6 with COABO

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

the class BaseAccountingEntry method getGLcode.

/**
     * gets the general ledger code (an entity object) for the account to be credited or debited, from a set of COABO
     * objects. If the set is empty, return null. If the set contains exactly one COABO object, return its associated
     * GLCodeEntity. If the set contains two or more COABO objects, return the associated GLCodeEntity for one chosen at
     * random (determined by the implementation of the set's iterator.)
     * <p>
     * The account returned must be at the lowest level in the chart-of-accounts hierarchy (see this <a href="http://www.mifos.org/knowledge/functional-specifications/system-setup/chart-of-accounts#debit-credit-financial-transactions"
     * > functional specification</a>, "The entries should be made against the lowest level GL Code under a category".
     * Subclasses enforces this rule by creating the set by invoking <code>COABO.getAssociatedChartOfAccounts()</code>
     * which creates a set of only lowest-level COABO objects below the give COABO.
     * <p>
     * This random behavior occurs when the GL code mapped to by a financial action is not at the lowest level. For
     * example, in the default financial action mapping,
     *
     * @param a set of GL accounts
     * @return the GL account code entity of the member of the account set, if it contains just one account. If the set
     *         is empty, return null. If the set contains two or more accounts, return an account code chosen at random.
     */
protected GLCodeEntity getGLcode(final Set<COABO> chartsOfAccounts) {
    Iterator<COABO> iter = chartsOfAccounts.iterator();
    GLCodeEntity glcode = null;
    while (iter.hasNext()) {
        glcode = iter.next().getAssociatedGlcode();
    }
    return glcode;
}
Also used : COABO(org.mifos.accounts.financial.business.COABO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity)

Example 7 with COABO

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

the class InterestPostingAccountingEntryTest method setupAndInjectMocks.

@Before
public void setupAndInjectMocks() {
    // Build a little Chart of Accounts
    coaLiability = makeCategory((short) 1, GLCategoryType.LIABILITY, "22000");
    coaSavingsInterestPayable = makeChildCoaboOf(coaLiability, (short) 2, "SavingsInterest Payable", "22100");
    coaClientsSavings = makeChildCoaboOf(coaLiability, (short) 3, "ClientsSavings", "22200");
    interestPostingAccountingEntry = new InterestPostingAccountingEntry() {

        @Override
        protected FinancialActionTypeEntity getFinancialAction(@SuppressWarnings("unused") final FinancialActionConstants financialActionId) throws FinancialException {
            return financialAction;
        }

        @Override
        protected COABO getChartOfAccountsEntry(final String glcode) throws FinancialException {
            if (glcode.equals("22000")) {
                return coaLiability;
            } else if (glcode.equals("22100")) {
                return coaSavingsInterestPayable;
            } else if (glcode.equals("22200")) {
                return coaClientsSavings;
            } else {
                throw new FinancialException("unexpected glcode: " + glcode);
            }
        }
    };
}
Also used : FinancialActionConstants(org.mifos.accounts.financial.util.helpers.FinancialActionConstants) FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) COABO(org.mifos.accounts.financial.business.COABO) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) Before(org.junit.Before)

Example 8 with COABO

use of org.mifos.accounts.financial.business.COABO 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 9 with COABO

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

the class ChartOfAccountsCacheTest method createMockAccountPersistance.

private LegacyAccountDao createMockAccountPersistance() {
    LegacyAccountDao ap = createMock(LegacyAccountDao.class);
    expect(ap.getCategory(GLCategoryType.INCOME)).andReturn(new COABO(ACCOUNT_ID, ACCOUNT_NAME));
    replay(ap);
    return ap;
}
Also used : LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) COABO(org.mifos.accounts.financial.business.COABO)

Example 10 with COABO

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

the class ChartOfAccountsCacheTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    GLCodeEntity glCodeEntityForStandardAccount = new GLCodeEntity(GL_CODE_ENTITY_ID, GL_CODE);
    testAccount = new COABO(ACCOUNT_ID, ACCOUNT_NAME, glCodeEntityForStandardAccount);
    /*
         * Hack. Has no effect when this test is run alone. When running as part
         * of a full unit/integration test, the ChartOfAccounts static cache
         * will have already been populated, so the add (below) would otherwise
         * cause an exception to be thrown.
         */
    ChartOfAccountsCache.remove(testAccount);
    ChartOfAccountsCache.add(testAccount);
    GLCodeEntity glCodeEntityForTopLevelAccount = new GLCodeEntity(GL_CODE_ENTITY_ID, INCOME_GL_ACCOUNT_CODE);
    COABO testIncomeAccount = new COABO(ACCOUNT_ID, ACCOUNT_NAME, glCodeEntityForTopLevelAccount);
    /*
         * Hack. Has no effect when this test is run alone. When running as part
         * of a full unit/integration test, the ChartOfAccounts static cache
         * will have already been populated, so the add (below) would otherwise
         * cause an exception to be thrown.
         */
    ChartOfAccountsCache.remove(testIncomeAccount);
    ChartOfAccountsCache.add(testIncomeAccount);
}
Also used : COABO(org.mifos.accounts.financial.business.COABO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity)

Aggregations

COABO (org.mifos.accounts.financial.business.COABO)28 GLCodeEntity (org.mifos.accounts.financial.business.GLCodeEntity)10 FinancialActionTypeEntity (org.mifos.accounts.financial.business.FinancialActionTypeEntity)6 Query (org.hibernate.Query)5 ArrayList (java.util.ArrayList)4 COAHierarchyEntity (org.mifos.accounts.financial.business.COAHierarchyEntity)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 PersistenceException (org.mifos.framework.exceptions.PersistenceException)4 Session (org.hibernate.Session)3 Test (org.junit.Test)3 FinancialActionConstants (org.mifos.accounts.financial.util.helpers.FinancialActionConstants)3 LegacyAccountDao (org.mifos.accounts.persistence.LegacyAccountDao)3 HashMap (java.util.HashMap)2 BeforeClass (org.junit.BeforeClass)2 FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)2 ChartOfAccountsCache (org.mifos.accounts.financial.util.helpers.ChartOfAccountsCache)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Iterator (java.util.Iterator)1