Search in sources :

Example 21 with ConfigurationPersistence

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());
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 22 with ConfigurationPersistence

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();
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AuditInterceptorFactory(org.mifos.framework.hibernate.helper.AuditInterceptorFactory)

Example 23 with ConfigurationPersistence

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);
        }
    }
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) DateTime(org.joda.time.DateTime) Money(org.mifos.framework.util.helpers.Money) ProductMixValidator(org.mifos.accounts.loan.struts.action.validate.ProductMixValidator) AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Example 24 with ConfigurationPersistence

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);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Example 25 with ConfigurationPersistence

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);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Aggregations

ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)28 LocalDate (org.joda.time.LocalDate)9 DateTime (org.joda.time.DateTime)8 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)8 Date (java.util.Date)7 AccountException (org.mifos.accounts.exceptions.AccountException)6 Test (org.junit.Test)5 Money (org.mifos.framework.util.helpers.Money)5 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)4 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)4 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 ConfigurationKeyValue (org.mifos.config.business.ConfigurationKeyValue)3 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 DateTimeService (org.mifos.framework.util.DateTimeService)3 ArrayList (java.util.ArrayList)2 After (org.junit.After)2 Before (org.junit.Before)2