use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class CustomerPersistenceIntegrationTest method testGetAllClosedAccounts.
@Test
public void testGetAllClosedAccounts() throws Exception {
getCustomer();
PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
clientAccount.approve(loggedInUser, "approved", new LocalDate());
ConfigurationPersistence configurationPersistence = new ConfigurationPersistence();
int lsim = configurationPersistence.getConfigurationValueInteger(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED);
configurationPersistence.updateConfigurationKeyValueInteger(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED, 1);
groupAccount.changeStatus(AccountState.LOAN_CANCELLED, AccountStateFlag.LOAN_WITHDRAW.getValue(), "WITHDRAW LOAN ACCOUNT", loggedInUser);
clientAccount.changeStatus(AccountState.LOAN_CLOSED_WRITTEN_OFF, null, "WITHDRAW LOAN ACCOUNT", loggedInUser);
clientSavingsAccount.changeStatus(AccountState.SAVINGS_CANCELLED, AccountStateFlag.SAVINGS_REJECTED.getValue(), "WITHDRAW LOAN ACCOUNT", loggedInUser);
TestObjectFactory.updateObject(groupAccount);
TestObjectFactory.updateObject(clientAccount);
TestObjectFactory.updateObject(clientSavingsAccount);
StaticHibernateUtil.flushSession();
new ConfigurationPersistence().updateConfigurationKeyValueInteger(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED, lsim);
Assert.assertEquals(1, customerPersistence.getAllClosedAccount(client.getCustomerId(), AccountTypes.LOAN_ACCOUNT.getValue()).size());
Assert.assertEquals(1, customerPersistence.getAllClosedAccount(group.getCustomerId(), AccountTypes.LOAN_ACCOUNT.getValue()).size());
Assert.assertEquals(1, customerPersistence.getAllClosedAccount(client.getCustomerId(), AccountTypes.SAVINGS_ACCOUNT.getValue()).size());
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class TestCaseInitializer method initializeDB.
private void initializeDB(SessionFactory sessionFactory) throws Exception {
StaticHibernateUtil.initialize(new AuditInterceptorFactory(), sessionFactory);
Money.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
FinancialInitializer.initialize();
ActivityMapper.getInstance().init();
HierarchyManager.getInstance().init();
AuditConfiguration.init(Localization.getInstance().getConfiguredLocale());
AccountingRules.init();
StaticHibernateUtil.commitTransaction();
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class LoanBO method disburseLoan.
private void disburseLoan(final String receiptNum, final Date transactionDate, final Short paymentTypeId, final PersonnelBO loggedInUser, final Date receiptDate, final Short rcvdPaymentTypeId, final boolean persistChange, final Short paymentTypeIdForFees, Integer accountForTransferId) throws AccountException, PersistenceException {
if ((this.getState().compareTo(AccountState.LOAN_APPROVED) != 0) && (this.getState().compareTo(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER) != 0)) {
throw new AccountException("Loan not in a State to be Disbursed: " + this.getState().toString());
}
if (this.getCustomer().isDisbursalPreventedDueToAnyExistingActiveLoansForTheSameProduct(this.getLoanOffering())) {
throw new AccountException("errors.cannotDisburseLoan.because.otherLoansAreActive");
}
try {
new ProductMixValidator().checkIfProductsOfferingCanCoexist(this);
} catch (ServiceException e1) {
throw new AccountException(e1.getMessage());
}
addLoanActivity(buildLoanActivity(this.loanAmount, loggedInUser, AccountConstants.LOAN_DISBURSAL, transactionDate));
// regenerate the installments
if (!isFixedRepaymentSchedule() && !DateUtils.getDateWithoutTimeStamp(disbursementDate.getTime()).equals(DateUtils.getDateWithoutTimeStamp(transactionDate.getTime()))) {
final boolean lsimEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (lsimEnabled) {
// QUESTION: does minDays
final int minDaysInterval = new ConfigurationPersistence().getConfigurationValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY);
this.disbursementDate = new DateTime(transactionDate).plusDays(minDaysInterval - 1).toDate();
} else {
this.disbursementDate = transactionDate;
}
regeneratePaymentSchedule(lsimEnabled, null);
if (this.isParentGroupLoanAccount()) {
groupLoanAccountServiceFacade.fixMemberAndParentInstallmentDetails(this.getAccountId());
}
}
this.disbursementDate = transactionDate;
final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(this.getAccountState(), newState, loggedInUser, this));
this.setAccountState(newState);
//
// Client performance entry
updateCustomerHistoryOnDisbursement(this.loanAmount);
if (getPerformanceHistory() != null) {
getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
}
//
//
// build up account payment related data
AccountPaymentEntity accountPayment = null;
if (this.isInterestDeductedAtDisbursement()) {
// the 1st payment is made and creates an initial accountPaymentEntity.
// This disbursal process carries on with that accountPaymentEntity by updating the 'amount' to the actual
// disbursed amount.
accountPayment = payInterestAtDisbursement(receiptNum, transactionDate, rcvdPaymentTypeId, loggedInUser, receiptDate);
accountPayment.setAmount(this.loanAmount.subtract(accountPayment.getAmount()));
} else {
// Disbursal process has to create its own accountPayment taking into account any disbursement fees
Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
accountPayment = new AccountPaymentEntity(this, this.loanAmount.subtract(feeAmountAtDisbursement), receiptNum, receiptDate, getPaymentTypeEntity(paymentTypeId), transactionDate);
accountPayment.setCreatedByUser(loggedInUser);
if (feeAmountAtDisbursement.isGreaterThanZero()) {
processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, paymentTypeIdForFees, accountForTransferId);
}
}
// create trxn entry for disbursal
final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, loggedInUser, transactionDate, this.loanAmount, "-", null, this.loanAmount, new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
accountPayment.addAccountTrxn(loanTrxnDetailEntity);
this.addAccountPayment(accountPayment);
this.buildFinancialEntries(accountPayment.getAccountTrxns());
if (persistChange) {
try {
ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class LoanBO method writeOff.
@Override
protected void writeOff(Date transactionDate) throws AccountException {
try {
if (!isTrxnDateValid(transactionDate, new CustomerPersistence().getLastMeetingDateForCustomer(getCustomer().getCustomerId()), new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled())) {
throw new BusinessRuleException("errors.invalidTxndate");
}
Short personnelId = this.getUserContext().getId();
PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
this.setUpdatedBy(personnelId);
this.setUpdatedDate(transactionDate);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, getEarlyClosureAmount(), null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
this.addAccountPayment(accountPaymentEntity);
makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.LOAN_WRITTEN_OFF, AccountActionTypes.WRITEOFF, currentUser);
//for past arrears installments writeOff and reschedule are the same as 'make early repayment'
//but differ in processing for future installments
makeWriteOffOrReschedulePaymentForFutureInstallments(accountPaymentEntity, AccountConstants.LOAN_WRITTEN_OFF, AccountActionTypes.WRITEOFF, currentUser);
addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_WRITTEN_OFF, transactionDate));
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
// Client performance entry
updateCustomerHistoryOnWriteOff();
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.config.persistence.ConfigurationPersistence in project head by mifos.
the class LoanBO method reschedule.
@Override
protected void reschedule(Date transactionDate) throws AccountException {
try {
if (!isTrxnDateValid(transactionDate, new CustomerPersistence().getLastMeetingDateForCustomer(getCustomer().getCustomerId()), new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled())) {
throw new BusinessRuleException("errors.invalidTxndate");
}
Short personnelId = this.getUserContext().getId();
PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
this.setUpdatedBy(personnelId);
this.setUpdatedDate(transactionDate);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, getEarlyClosureAmount(), null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
this.addAccountPayment(accountPaymentEntity);
makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.LOAN_RESCHEDULED, AccountActionTypes.LOAN_RESCHEDULED, currentUser);
//for past arrears installments writeOff and reschedule are the same as 'make early repayment'
//but differ in processing for future installments
makeWriteOffOrReschedulePaymentForFutureInstallments(accountPaymentEntity, AccountConstants.LOAN_RESCHEDULED, AccountActionTypes.LOAN_RESCHEDULED, currentUser);
addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_RESCHEDULED, transactionDate));
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
// Client performance entry using the same as write off.
updateCustomerHistoryOnWriteOff();
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
Aggregations