Search in sources :

Example 1 with WaiveEnum

use of org.mifos.accounts.util.helpers.WaiveEnum in project head by mifos.

the class CenterServiceFacadeWebTier method waiveChargesDue.

@Override
public void waiveChargesDue(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);
        PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
        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());
        }
        try {
            this.transactionHelper.startTransaction();
            if (account instanceof LoanBO) {
                ((LoanBO) account).waiveAmountDue(waiveEnum);
            } else if (account instanceof SavingsBO) {
                ((SavingsBO) account).waiveNextDepositAmountDue(loggedInUser);
            } else {
                ((CustomerAccountBO) account).waiveAmountDue();
            }
            this.customerDao.save(account);
            this.transactionHelper.commitTransaction();
        } catch (Exception e) {
            this.transactionHelper.rollbackTransaction();
            throw new BusinessRuleException(account.getAccountId().toString(), e);
        } finally {
            this.transactionHelper.closeSession();
        }
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) ServiceException(org.mifos.framework.exceptions.ServiceException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with WaiveEnum

use of org.mifos.accounts.util.helpers.WaiveEnum in project head by mifos.

the class WaiveEnumTest method shouldReturnPenaltyWaiveEnum.

@Test
public void shouldReturnPenaltyWaiveEnum() {
    WaiveEnum result = WaiveEnum.fromInt(1);
    assertThat(result, is(WaiveEnum.PENALTY));
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) Test(org.junit.Test)

Example 3 with WaiveEnum

use of org.mifos.accounts.util.helpers.WaiveEnum in project head by mifos.

the class WaiveEnumTest method shouldReturnAllWaiveEnumForValuesNotEqualToZeroOrOne.

@Test
public void shouldReturnAllWaiveEnumForValuesNotEqualToZeroOrOne() {
    WaiveEnum result = WaiveEnum.fromInt(-1);
    assertThat(result, is(WaiveEnum.ALL));
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) Test(org.junit.Test)

Example 4 with WaiveEnum

use of org.mifos.accounts.util.helpers.WaiveEnum in project head by mifos.

the class WaiveEnumTest method shouldReturnFeeWaiveEnum.

@Test
public void shouldReturnFeeWaiveEnum() {
    WaiveEnum result = WaiveEnum.fromInt(0);
    assertThat(result, is(WaiveEnum.FEES));
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) Test(org.junit.Test)

Example 5 with WaiveEnum

use of org.mifos.accounts.util.helpers.WaiveEnum in project head by mifos.

the class WaiveEnumTest method shouldReturnAllWaiveEnumForValuesNotEqualToZeroOrOne_2.

@Test
public void shouldReturnAllWaiveEnumForValuesNotEqualToZeroOrOne_2() {
    WaiveEnum result = WaiveEnum.fromInt(2);
    assertThat(result, is(WaiveEnum.ALL));
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) Test(org.junit.Test)

Aggregations

WaiveEnum (org.mifos.accounts.util.helpers.WaiveEnum)8 Test (org.junit.Test)4 AccountBO (org.mifos.accounts.business.AccountBO)4 UserContext (org.mifos.security.util.UserContext)4 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)2 ApplicationException (org.mifos.framework.exceptions.ApplicationException)2 ServiceException (org.mifos.framework.exceptions.ServiceException)2 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)2 MifosUser (org.mifos.security.MifosUser)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 AccountException (org.mifos.accounts.exceptions.AccountException)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)1 CustomerException (org.mifos.customers.exceptions.CustomerException)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 StatesInitializationException (org.mifos.framework.exceptions.StatesInitializationException)1 SystemException (org.mifos.framework.exceptions.SystemException)1