Search in sources :

Example 26 with COABO

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

the class LegacyAccountDao method deleteLedgerAccount.

public void deleteLedgerAccount(Short accountId) throws PersistenceException {
    Session session = StaticHibernateUtil.getSessionTL();
    Transaction transaction = session.beginTransaction();
    try {
        COABO coa = (COABO) session.load(COABO.class, accountId);
        COABO parent = coa.getCoaHierarchy().getParentAccount().getCoa();
        Short parentId = parent.getAccountId();
        Short glCodeId = coa.getAssociatedGlcode().getGlcodeId();
        Query query = session.getNamedQuery(NamedQueryConstants.REMOVE_COA_PARENT);
        query.setShort("coa_id", coa.getAccountId().shortValue());
        query.setShort("parent_id", parentId);
        query.executeUpdate();
        query = session.getNamedQuery(NamedQueryConstants.REMOVE_COA);
        query.setShort("coa_id", coa.getAccountId().shortValue());
        query.executeUpdate();
        query = session.getNamedQuery(NamedQueryConstants.REMOVE_GLCODE);
        query.setShort("glcode_id", glCodeId);
        query.executeUpdate();
        transaction.commit();
        session.flush();
    } catch (HibernateException e) {
        transaction.rollback();
        throw new PersistenceException(e);
    }
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) COABO(org.mifos.accounts.financial.business.COABO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Session(org.hibernate.Session)

Example 27 with COABO

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

the class LegacyAccountDao method dumpChartOfAccounts.

public String dumpChartOfAccounts() throws ConfigurationException {
    XMLConfiguration config = new XMLConfiguration();
    Query topLevelAccounts = getSession().getNamedQuery(NamedQueryConstants.GET_TOP_LEVEL_ACCOUNTS);
    List listAccounts = topLevelAccounts.list();
    Iterator it = listAccounts.iterator();
    LegacyAccountDao ap = new LegacyAccountDao();
    String assetsAccountGLCode = ap.getCategory(GLCategoryType.ASSET).getGlCode();
    String liabilitiesAccountGLCode = ap.getCategory(GLCategoryType.LIABILITY).getGlCode();
    String incomeAccountGLCode = ap.getCategory(GLCategoryType.INCOME).getGlCode();
    String expenditureAccountGLCode = ap.getCategory(GLCategoryType.EXPENDITURE).getGlCode();
    while (it.hasNext()) {
        COABO coa = (COABO) it.next();
        String name = coa.getAccountName();
        String glCode = coa.getAssociatedGlcode().getGlcode();
        String path = "ChartOfAccounts";
        if (glCode.equals(assetsAccountGLCode)) {
            path = path + ASSETS_GL_ACCOUNT_TAG;
        } else if (glCode.equals(liabilitiesAccountGLCode)) {
            path = path + LIABILITIES_GL_ACCOUNT_TAG;
        } else if (glCode.equals(incomeAccountGLCode)) {
            path = path + INCOME_GL_ACCOUNT_TAG;
        } else if (glCode.equals(expenditureAccountGLCode)) {
            path = path + EXPENDITURE_GL_ACCOUNT_TAG;
        } else {
            throw new RuntimeException("Unrecognized top level GLCode: " + glCode);
        }
        config.addProperty(path + "(-1)[@code]", glCode);
        config.addProperty(path + "[@name]", name);
        addAccountSubcategories(config, coa, path + GL_ACCOUNT_TAG);
    }
    StringWriter stringWriter = new StringWriter();
    config.save(stringWriter);
    String chart = stringWriter.toString();
    return chart;
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Query(org.hibernate.Query) StringWriter(java.io.StringWriter) COABO(org.mifos.accounts.financial.business.COABO) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 28 with COABO

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

the class ChartOfAccountsConfig method isLoaded.

/**
     * @return true if the chart of accounts has been loaded from the on-disk
     *         configuration file into the database.
     */
public static boolean isLoaded(Session session) {
    // A more comprehensive check would also make sure no rows exist in
    // the following tables: coahierarchy, coa_idmapper, gl_code
    Query query = session.getNamedQuery(NamedQueryConstants.GET_ALL_COA);
    List<COABO> coaBoList = query.list();
    return !coaBoList.isEmpty();
}
Also used : Query(org.hibernate.Query) COABO(org.mifos.accounts.financial.business.COABO)

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