use of org.mifos.accounts.financial.business.COABO in project head by mifos.
the class SavingsCloseTest method setupChartOfAccountsAndFinancialTransactions.
@BeforeClass
public static void setupChartOfAccountsAndFinancialTransactions() {
defaultCurrency = TestUtils.RUPEE;
Money.setDefaultCurrency(defaultCurrency);
Short glcodeId = Short.valueOf("1");
String glcode = "123456";
GLCodeEntity glCodeEntity = new GLCodeEntity(glcodeId, glcode);
COABO coabo = new COABO("testAccountName", glCodeEntity);
ChartOfAccountsCache chartOfAccountsCache = new ChartOfAccountsCache();
chartOfAccountsCache.clear();
chartOfAccountsCache.add(coabo);
Map<FinancialActionConstants, String> actionToCreditAccount = new HashMap<FinancialActionConstants, String>();
actionToCreditAccount.put(FinancialActionConstants.SAVINGS_INTERESTPOSTING, glcode);
actionToCreditAccount.put(FinancialActionConstants.MANDATORYDEPOSIT, glcode);
actionToCreditAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL, glcode);
actionToCreditAccount.put(FinancialActionConstants.MANDATORYDEPOSIT_ADJUSTMENT, glcode);
actionToCreditAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL_ADJUSTMENT, glcode);
actionToCreditAccount.put(FinancialActionConstants.ROUNDING, glcode);
FinancialRules.getInstance().setActionToCreditAccount(actionToCreditAccount);
Map<FinancialActionConstants, String> actionToDebitAccount = new HashMap<FinancialActionConstants, String>();
actionToDebitAccount.put(FinancialActionConstants.SAVINGS_INTERESTPOSTING, glcode);
actionToDebitAccount.put(FinancialActionConstants.MANDATORYDEPOSIT, glcode);
actionToDebitAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL, glcode);
actionToDebitAccount.put(FinancialActionConstants.MANDATORYDEPOSIT_ADJUSTMENT, glcode);
actionToDebitAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL_ADJUSTMENT, glcode);
actionToDebitAccount.put(FinancialActionConstants.ROUNDING, glcode);
FinancialRules.getInstance().setActionToDebitAccount(actionToDebitAccount);
FinancialActionTypeEntity roundingAction = new FinancialActionTypeEntity();
roundingAction.setId(FinancialActionConstants.ROUNDING.getValue());
FinancialActionTypeEntity depositAction = new FinancialActionTypeEntity();
depositAction.setId(FinancialActionConstants.MANDATORYDEPOSIT.getValue());
FinancialActionTypeEntity withdrawalAction = new FinancialActionTypeEntity();
withdrawalAction.setId(FinancialActionConstants.MANDATORYWITHDRAWAL.getValue());
FinancialActionTypeEntity depositAdjustmentAction = new FinancialActionTypeEntity();
depositAdjustmentAction.setId(FinancialActionConstants.MANDATORYDEPOSIT_ADJUSTMENT.getValue());
FinancialActionTypeEntity withdrawalAdjustmentAction = new FinancialActionTypeEntity();
withdrawalAdjustmentAction.setId(FinancialActionConstants.MANDATORYWITHDRAWAL_ADJUSTMENT.getValue());
FinancialActionTypeEntity interestPostingAction = new FinancialActionTypeEntity();
interestPostingAction.setId(FinancialActionConstants.SAVINGS_INTERESTPOSTING.getValue());
FinancialActionCache.addToCache(depositAction);
FinancialActionCache.addToCache(withdrawalAction);
FinancialActionCache.addToCache(depositAdjustmentAction);
FinancialActionCache.addToCache(withdrawalAdjustmentAction);
FinancialActionCache.addToCache(interestPostingAction);
FinancialActionCache.addToCache(roundingAction);
}
use of org.mifos.accounts.financial.business.COABO in project head by mifos.
the class SavingsAdjustmentTest method setupChartOfAccountsAndFinancialTransactions.
@BeforeClass
public static void setupChartOfAccountsAndFinancialTransactions() {
defaultCurrency = TestUtils.RUPEE;
Money.setDefaultCurrency(defaultCurrency);
Short glcodeId = Short.valueOf("1");
String glcode = "123456";
GLCodeEntity glCodeEntity = new GLCodeEntity(glcodeId, glcode);
COABO coabo = new COABO("testAccountName", glCodeEntity);
ChartOfAccountsCache chartOfAccountsCache = new ChartOfAccountsCache();
chartOfAccountsCache.clear();
chartOfAccountsCache.add(coabo);
Map<FinancialActionConstants, String> actionToCreditAccount = new HashMap<FinancialActionConstants, String>();
actionToCreditAccount.put(FinancialActionConstants.MANDATORYDEPOSIT, glcode);
actionToCreditAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL, glcode);
actionToCreditAccount.put(FinancialActionConstants.MANDATORYDEPOSIT_ADJUSTMENT, glcode);
actionToCreditAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL_ADJUSTMENT, glcode);
FinancialRules.getInstance().setActionToCreditAccount(actionToCreditAccount);
Map<FinancialActionConstants, String> actionToDebitAccount = new HashMap<FinancialActionConstants, String>();
actionToDebitAccount.put(FinancialActionConstants.MANDATORYDEPOSIT, glcode);
actionToDebitAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL, glcode);
actionToDebitAccount.put(FinancialActionConstants.MANDATORYDEPOSIT_ADJUSTMENT, glcode);
actionToDebitAccount.put(FinancialActionConstants.MANDATORYWITHDRAWAL_ADJUSTMENT, glcode);
FinancialRules.getInstance().setActionToDebitAccount(actionToDebitAccount);
FinancialActionTypeEntity depositAction = new FinancialActionTypeEntity();
depositAction.setId(FinancialActionConstants.MANDATORYDEPOSIT.getValue());
FinancialActionTypeEntity withdrawalAction = new FinancialActionTypeEntity();
withdrawalAction.setId(FinancialActionConstants.MANDATORYWITHDRAWAL.getValue());
FinancialActionTypeEntity depositAdjustmentAction = new FinancialActionTypeEntity();
depositAdjustmentAction.setId(FinancialActionConstants.MANDATORYDEPOSIT_ADJUSTMENT.getValue());
FinancialActionTypeEntity withdrawalAdjustmentAction = new FinancialActionTypeEntity();
withdrawalAdjustmentAction.setId(FinancialActionConstants.MANDATORYWITHDRAWAL_ADJUSTMENT.getValue());
FinancialActionCache.addToCache(depositAction);
FinancialActionCache.addToCache(withdrawalAction);
FinancialActionCache.addToCache(depositAdjustmentAction);
FinancialActionCache.addToCache(withdrawalAdjustmentAction);
}
use of org.mifos.accounts.financial.business.COABO 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.COABO in project head by mifos.
the class FinancialInitializer method loadCOA.
/**
* Reads chart of accounts from a configuration file and inserts into the
* database. Deleting accounts is not currently supported, but if the user
* tries to do this (by leaving it out of the custom chart of accounts
* config file), there is currently no error reported.
* <p>
* QUESION: what if custom config was missing entries from default config,
* but then is moved _out_ of the app server classpath?
* <p>
* ANSWER: once ChartOfAccountsConfig.isLoaded() returns true, <em>only
* the custom CoA config file will be considered</em>. Using the custom
* config will be the only way to add new accounts after the initial CoA
* data is loaded in the database.
*/
public static void loadCOA() throws FinancialException {
Session session = StaticHibernateUtil.getSessionTL();
final String coaLocation;
try {
if (!ChartOfAccountsConfig.canLoadCoa(session)) {
logger.info("Chart of accounts data will not be modified since " + "the custom chart of accounts configuration file was " + "not found on the classpath.");
return;
}
coaLocation = ChartOfAccountsConfig.getCoaUri(session);
logger.info("going to load or modify chart of accounts " + "configuration from " + coaLocation);
} catch (IOException e) {
throw new FinancialException("Charts of accounts loading failed", e);
}
ChartOfAccountsConfig coa;
try {
coa = ChartOfAccountsConfig.load(coaLocation);
} catch (ConfigurationException e) {
throw new FinancialException(coaLocation + " loading failed", e);
}
LegacyAccountDao ap = ApplicationContextProvider.getBean(LegacyAccountDao.class);
for (GLAccount glAccount : coa.getGLAccounts()) {
Short accountId = ap.getAccountIdFromGlCode(glAccount.glCode);
if (null == accountId) {
logger.info("Adding new general ledger account: " + glAccount);
ap.addGeneralLedgerAccount(glAccount.name, glAccount.glCode, glAccount.parentGlCode, glAccount.categoryType);
} else {
COABO account = (COABO) session.load(COABO.class, accountId);
if (account.getCategoryType() != glAccount.categoryType) {
throw new FinancialException("category type change not supported");
}
if (!accountHierarchyMatch(account, glAccount)) {
throw new FinancialException("chart of accounts hierarchy change not supported");
}
if (!account.getAccountName().equals(glAccount.name)) {
logger.info("updating general ledger account name. code=" + account.getGlCode() + ". old name=" + account.getAccountName() + ", new name=" + glAccount.name);
ap.updateAccountName(account, glAccount.name);
}
}
}
}
use of org.mifos.accounts.financial.business.COABO 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