Search in sources :

Example 86 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class AccountServiceIntegrationTest method getLoanAccountWithAllTypesOfFees.

private AccountBO getLoanAccountWithAllTypesOfFees() {
    accountBO = getLoanAccount();
    LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountBO.getAccountActionDate(Short.valueOf("1"));
    FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.LOAN, Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT, null);
    AccountFeesEntity accountUpfrontFee = new AccountFeesEntity(accountBO, upfrontFee, new Double("20.0"), FeeStatus.ACTIVE.getValue(), null, loanScheduleEntity.getActionDate());
    AccountTestUtils.addAccountFees(accountUpfrontFee, accountBO);
    AccountFeesActionDetailEntity accountUpfrontFeesaction = new LoanFeeScheduleEntity(loanScheduleEntity, upfrontFee, accountUpfrontFee, new Money(getCurrency(), "20.0"));
    loanScheduleEntity.addAccountFeesAction(accountUpfrontFeesaction);
    TestObjectFactory.updateObject(accountBO);
    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
    loanScheduleEntity = (LoanScheduleEntity) accountBO.getAccountActionDate(Short.valueOf("1"));
    FeeBO timeOfDisbursementFees = TestObjectFactory.createOneTimeAmountFee("Disbursement Fee", FeeCategory.LOAN, "30", FeePayment.TIME_OF_DISBURSEMENT);
    AccountFeesEntity accountDisbursementFee = new AccountFeesEntity(accountBO, timeOfDisbursementFees, new Double("30.0"), FeeStatus.ACTIVE.getValue(), null, loanScheduleEntity.getActionDate());
    AccountTestUtils.addAccountFees(accountDisbursementFee, accountBO);
    AccountFeesActionDetailEntity accountDisbursementFeesaction = new LoanFeeScheduleEntity(loanScheduleEntity, timeOfDisbursementFees, accountDisbursementFee, new Money(getCurrency(), "30.0"));
    loanScheduleEntity.addAccountFeesAction(accountDisbursementFeesaction);
    TestObjectFactory.updateObject(accountBO);
    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
    loanScheduleEntity = (LoanScheduleEntity) accountBO.getAccountActionDate(Short.valueOf("1"));
    FeeBO firstLoanRepaymentFee = TestObjectFactory.createOneTimeAmountFee("First Loan Repayment Fee", FeeCategory.LOAN, "40", FeePayment.TIME_OF_FIRSTLOANREPAYMENT);
    AccountFeesEntity accountFirstLoanRepaymentFee = new AccountFeesEntity(accountBO, firstLoanRepaymentFee, new Double("40.0"), FeeStatus.ACTIVE.getValue(), null, loanScheduleEntity.getActionDate());
    AccountTestUtils.addAccountFees(accountFirstLoanRepaymentFee, accountBO);
    AccountFeesActionDetailEntity accountTimeOfFirstLoanRepaymentFeesaction = new LoanFeeScheduleEntity(loanScheduleEntity, firstLoanRepaymentFee, accountFirstLoanRepaymentFee, new Money(getCurrency(), "40.0"));
    loanScheduleEntity.addAccountFeesAction(accountTimeOfFirstLoanRepaymentFeesaction);
    TestObjectFactory.updateObject(accountBO);
    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "200", RecurrenceType.WEEKLY, Short.valueOf("1"));
    AccountFeesEntity accountPeriodicFee = new AccountFeesEntity(accountBO, periodicFee, new Double("200.0"), FeeStatus.INACTIVE.getValue(), null, null);
    AccountTestUtils.addAccountFees(accountPeriodicFee, accountBO);
    TestObjectFactory.updateObject(accountBO);
    return accountBO;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) LoanFeeScheduleEntity(org.mifos.accounts.loan.business.LoanFeeScheduleEntity) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity)

Example 87 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class AccountServiceIntegrationTest method testGetAppllicableFeesForInstallmentStartingOnCurrentDate.

@Test
@Ignore
public void testGetAppllicableFeesForInstallmentStartingOnCurrentDate() throws Exception {
    AccountBusinessService accountBusinessService = new AccountBusinessService();
    accountBO = getLoanAccountWithAllTypesOfFees();
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
    StaticHibernateUtil.flushAndClearSession();
    UserContext uc = TestUtils.makeUser();
    List<ApplicableCharge> applicableChargeList = accountBusinessService.getAppllicableFees(accountBO.getAccountId(), uc);
    Assert.assertEquals(4, applicableChargeList.size());
    for (ApplicableCharge applicableCharge : applicableChargeList) {
        if (applicableCharge.getFeeName().equalsIgnoreCase("Upfront Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "20.0"), new Money(getCurrency(), applicableCharge.getAmountOrRate()));
            Assert.assertNotNull(applicableCharge.getFormula());
            Assert.assertNull(applicableCharge.getPeriodicity());
        } else if (applicableCharge.getFeeName().equalsIgnoreCase("Periodic Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "200.0"), new Money(getCurrency(), applicableCharge.getAmountOrRate()));
            Assert.assertNull(applicableCharge.getFormula());
            Assert.assertNotNull(applicableCharge.getPeriodicity());
        } else if (applicableCharge.getFeeName().equalsIgnoreCase("Misc Fee")) {
            Assert.assertNull(applicableCharge.getAmountOrRate());
            Assert.assertNull(applicableCharge.getFormula());
            Assert.assertNull(applicableCharge.getPeriodicity());
        }
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) UserContext(org.mifos.security.util.UserContext) ApplicableCharge(org.mifos.dto.domain.ApplicableCharge) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 88 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class AccountServiceIntegrationTest method testGetAppllicableFeesForInstallmentStartingAfterCurrentDate.

@Test
public void testGetAppllicableFeesForInstallmentStartingAfterCurrentDate() throws Exception {
    AccountBusinessService accountBusinessService = new AccountBusinessService();
    accountBO = getLoanAccountWithAllTypesOfFees();
    incrementInstallmentDate(accountBO, 1, Short.valueOf("1"));
    accountBO.setUserContext(TestObjectFactory.getContext());
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    accountBO.changeStatus(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER, null, "", loggedInUser);
    TestObjectFactory.updateObject(accountBO);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    StaticHibernateUtil.flushAndClearSession();
    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
    UserContext uc = TestUtils.makeUser();
    List<ApplicableCharge> applicableChargeList = accountBusinessService.getAppllicableFees(accountBO.getAccountId(), uc);
    Assert.assertEquals(3, applicableChargeList.size());
    for (ApplicableCharge applicableCharge : applicableChargeList) {
        if (applicableCharge.getFeeName().equalsIgnoreCase("Periodic Fee")) {
            Assert.assertEquals(new Money(getCurrency(), "200.0"), new Money(getCurrency(), applicableCharge.getAmountOrRate()));
            Assert.assertNull(applicableCharge.getFormula());
            Assert.assertNotNull(applicableCharge.getPeriodicity());
        } else if (applicableCharge.getFeeName().equalsIgnoreCase("Misc Fee")) {
            Assert.assertNull(applicableCharge.getAmountOrRate());
            Assert.assertNull(applicableCharge.getFormula());
            Assert.assertNull(applicableCharge.getPeriodicity());
        }
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) ApplicableCharge(org.mifos.dto.domain.ApplicableCharge) Test(org.junit.Test)

Example 89 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class CenterServiceFacadeWebTier method waiveChargesOverDue.

@Override
public void waiveChargesOverDue(Integer accountId, Integer waiveType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        account.updateDetails(userContext);
        WaiveEnum waiveEnum = WaiveEnum.fromInt(waiveType);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        account.waiveAmountOverDue(waiveEnum);
        this.customerDao.save(account);
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 90 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class CenterServiceFacadeWebTier method createAccountFeeEntities.

private List<AccountFeesEntity> createAccountFeeEntities(List<CreateAccountFeeDto> feesToApply) {
    List<AccountFeesEntity> feesForCustomerAccount = new ArrayList<AccountFeesEntity>();
    for (CreateAccountFeeDto feeDto : feesToApply) {
        FeeBO fee = feeDao.findById(feeDto.getFeeId().shortValue());
        Double feeAmount = new LocalizationConverter().getDoubleValueForCurrentLocale(feeDto.getAmount());
        AccountBO nullReferenceForNow = null;
        AccountFeesEntity accountFee = new AccountFeesEntity(nullReferenceForNow, fee, feeAmount);
        feesForCustomerAccount.add(accountFee);
    }
    return feesForCustomerAccount;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) LocalizationConverter(org.mifos.framework.util.LocalizationConverter) ArrayList(java.util.ArrayList) FeeBO(org.mifos.accounts.fees.business.FeeBO) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity)

Aggregations

AccountBO (org.mifos.accounts.business.AccountBO)106 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)39 LoanBO (org.mifos.accounts.loan.business.LoanBO)35 ArrayList (java.util.ArrayList)30 Money (org.mifos.framework.util.helpers.Money)30 UserContext (org.mifos.security.util.UserContext)29 Test (org.junit.Test)27 MifosRuntimeException (org.mifos.core.MifosRuntimeException)26 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)20 ServiceException (org.mifos.framework.exceptions.ServiceException)19 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)18 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)16 AccountException (org.mifos.accounts.exceptions.AccountException)15 MifosUser (org.mifos.security.MifosUser)14 Date (java.util.Date)13 LocalDate (org.joda.time.LocalDate)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)11 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 FeeBO (org.mifos.accounts.fees.business.FeeBO)9