Search in sources :

Example 81 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class CenterServiceFacadeWebTier method retrieveChargesDetails.

@Override
public CustomerChargesDetailsDto retrieveChargesDetails(Integer customerId) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
    CustomerAccountBO customerAccount = customerBO.getCustomerAccount();
    try {
        personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    List<AccountFeesDto> accountFeesDtos = new ArrayList<AccountFeesDto>();
    if (!customerAccount.getAccountFees().isEmpty()) {
        for (AccountFeesEntity accountFeesEntity : customerAccount.getAccountFees()) {
            AccountFeesDto accountFeesDto = new AccountFeesDto(accountFeesEntity.getFees().getFeeFrequency().getFeeFrequencyType().getId(), (accountFeesEntity.getFees().getFeeFrequency().getFeePayment() != null ? accountFeesEntity.getFees().getFeeFrequency().getFeePayment().getId() : null), accountFeesEntity.getFeeStatus(), accountFeesEntity.getFees().getFeeName(), accountFeesEntity.getAccountFeeAmount().toString(), getMeetingRecurrence(accountFeesEntity.getFees().getFeeFrequency().getFeeMeetingFrequency(), userContext), accountFeesEntity.getFees().getFeeId());
            accountFeesDtos.add(accountFeesDto);
        }
    }
    CustomerScheduleDto customerSchedule = null;
    CustomerScheduleEntity scheduleEntity = (CustomerScheduleEntity) customerAccount.getUpcomingInstallment();
    if (scheduleEntity != null) {
        Set<AccountFeesActionDetailEntity> feeEntities = scheduleEntity.getAccountFeesActionDetails();
        List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
        for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
            feeDtos.add(convertToDto(feeEntity));
        }
        customerSchedule = new CustomerScheduleDto(scheduleEntity.getMiscFee().toString(), scheduleEntity.getMiscFeePaid().toString(), scheduleEntity.getMiscPenalty().toString(), scheduleEntity.getMiscPenaltyPaid().toString(), feeDtos);
    }
    return new CustomerChargesDetailsDto(customerAccount.getNextDueAmount().toString(), customerAccount.getTotalAmountInArrears().toString(), customerAccount.getTotalAmountDue().toString(), customerAccount.getUpcomingChargesDate(), customerSchedule, accountFeesDtos);
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountFeesDto(org.mifos.dto.screen.AccountFeesDto) AccountFeeScheduleDto(org.mifos.dto.domain.AccountFeeScheduleDto) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) CustomerChargesDetailsDto(org.mifos.dto.domain.CustomerChargesDetailsDto) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerScheduleDto(org.mifos.dto.domain.CustomerScheduleDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 82 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class ProductMixValidatorIntegrationTest method testShouldDetectProductMixConflicts.

@Test
public void testShouldDetectProductMixConflicts() throws Exception {
    short PRD_OFFERING_ID_TWO = (short) 2;
    LoanBO loanMock1 = createMock(LoanBO.class);
    LoanBO loanMock2 = createMock(LoanBO.class);
    LoanOfferingBO loanOfferingMock1 = createMock(LoanOfferingBO.class);
    LoanOfferingBO loanOfferingMock2 = createMock(LoanOfferingBO.class);
    expect(loanMock2.getLoanOffering()).andReturn(loanOfferingMock2);
    expect(loanMock1.getLoanOffering()).andReturn(loanOfferingMock1);
    expect(loanOfferingMock2.getPrdOfferingId()).andReturn(PRD_OFFERING_ID_TWO);
    expect(productMixBusinessServiceMock.canProductsCoExist(loanOfferingMock2, loanOfferingMock1)).andReturn(false);
    replay(loanMock1, loanMock2, loanOfferingMock1, loanOfferingMock2, productMixBusinessServiceMock);
    try {
        new ProductMixValidator(configServiceMock, productMixBusinessServiceMock) {

            @Override
            void handleConflict(LoanBO newloan, LoanBO loan) throws AccountException {
                throw new AccountException("Some exception code");
            }
        }.validateProductMix(loanMock2, Arrays.asList(loanMock1));
        Assert.fail("Product mix conflict not detected");
        verify(loanMock1, loanMock2, loanOfferingMock1, loanOfferingMock2, productMixBusinessServiceMock);
    } catch (AccountException e) {
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) Test(org.junit.Test)

Example 83 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class CustomerAccountBOIntegrationTest method testApplyMiscChargeWithNonActiveCustomer.

@Test
public void testApplyMiscChargeWithNonActiveCustomer() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_PARTIAL, center);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    customerAccountBO = group.getCustomerAccount();
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    try {
        customerAccountBO.applyCharge(Short.valueOf("-1"), new Double("33"));
        Assert.assertFalse(false);
    } catch (AccountException e) {
        Assert.assertEquals(AccountConstants.MISC_CHARGE_NOT_APPLICABLE, e.getKey());
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 84 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class IntegrationTestObjectMother method applyAccountPayment.

public static void applyAccountPayment(AccountBO loan, PaymentData paymentData) {
    try {
        StaticHibernateUtil.startTransaction();
        loan.applyPayment(paymentData);
        StaticHibernateUtil.commitTransaction();
    } catch (AccountException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new RuntimeException(e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException)

Example 85 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class LoanBO method handleArrears.

public void handleArrears() throws AccountException {
    AccountStateEntity stateEntity;
    try {
        stateEntity = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_BADSTANDING);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
    AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(this.getAccountState(), stateEntity, this.getPersonnel(), this);
    this.addAccountStatusChangeHistory(historyEntity);
    this.setAccountState(stateEntity);
    try {
        String systemDate = DateUtils.getCurrentDate();
        Date currrentDate = DateUtils.getLocaleDate(systemDate);
        this.setUpdatedDate(currrentDate);
    } catch (InvalidDateException ide) {
        throw new AccountException(ide);
    }
    try {
        getlegacyLoanDao().createOrUpdate(this);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Aggregations

AccountException (org.mifos.accounts.exceptions.AccountException)115 MifosRuntimeException (org.mifos.core.MifosRuntimeException)47 UserContext (org.mifos.security.util.UserContext)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)42 Money (org.mifos.framework.util.helpers.Money)42 MifosUser (org.mifos.security.MifosUser)38 LoanBO (org.mifos.accounts.loan.business.LoanBO)31 ArrayList (java.util.ArrayList)30 LocalDate (org.joda.time.LocalDate)30 BusinessRuleException (org.mifos.service.BusinessRuleException)29 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)26 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)25 Date (java.util.Date)22 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)21 CustomerBO (org.mifos.customers.business.CustomerBO)19 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)17 PaymentData (org.mifos.accounts.util.helpers.PaymentData)17 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)16 ServiceException (org.mifos.framework.exceptions.ServiceException)16 BigDecimal (java.math.BigDecimal)14