Search in sources :

Example 71 with AccountBO

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

the class LoanBOTestUtils method createLoanRepaymentSchedule.

public LoanScheduleEntity[] createLoanRepaymentSchedule() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    AccountBO accountBO = getLoanAccountWithMiscFeeAndPenalty(AccountState.LOAN_APPROVED, startDate, TestUtils.createMoney("20"), TestUtils.createMoney("30"));
    Set<AccountActionDateEntity> intallments = accountBO.getAccountActionDates();
    AccountActionDateEntity firstInstallment = null;
    for (AccountActionDateEntity entity : intallments) {
        if (entity.getInstallmentId().intValue() == 1) {
            firstInstallment = entity;
            break;
        }
    }
    Calendar disbursalDate = new GregorianCalendar();
    disbursalDate.setTimeInMillis(firstInstallment.getActionDate().getTime());
    Calendar cal = new GregorianCalendar(disbursalDate.get(Calendar.YEAR), disbursalDate.get(Calendar.MONTH), disbursalDate.get(Calendar.DATE), 0, 0);
    ((LoanBO) accountBO).disburseLoan("1234", cal.getTime(), Short.valueOf("1"), accountBO.getPersonnel(), startDate, Short.valueOf("1"), Short.valueOf("1"), null);
    Set<AccountActionDateEntity> actionDateEntities = accountBO.getAccountActionDates();
    LoanScheduleEntity[] paymentsArray = getSortedAccountActionDateEntity(actionDateEntities);
    return paymentsArray;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 72 with AccountBO

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

the class LoanBusinessServiceTest method originalLoanScheduleShouldPersistMiscFee.

@Test
public void originalLoanScheduleShouldPersistMiscFee() throws PersistenceException {
    Set<LoanScheduleEntity> installments = new LinkedHashSet<LoanScheduleEntity>();
    MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
    Money money = new Money(mifosCurrency, "123");
    AccountBO accountBO = mock(AccountBO.class);
    CustomerBO customerBO = mock(CustomerBO.class);
    when(accountBO.getCurrency()).thenReturn(mifosCurrency);
    LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(accountBO, customerBO, new Short("1"), new java.sql.Date(new Date().getTime()), PaymentStatus.UNPAID, money, money);
    loanScheduleEntity.setMiscFee(money);
    installments.add(loanScheduleEntity);
    when(loanBO.getLoanScheduleEntities()).thenReturn(installments);
    loanBusinessService.persistOriginalSchedule(loanBO);
    ArrayList<OriginalLoanScheduleEntity> expected = new ArrayList<OriginalLoanScheduleEntity>();
    OriginalLoanScheduleEntity originalLoanScheduleEntity = new OriginalLoanScheduleEntity(loanScheduleEntity);
    assertEquals(originalLoanScheduleEntity.getMiscFee(), loanScheduleEntity.getMiscFee());
    expected.add(originalLoanScheduleEntity);
    verify(legacyLoanDao).saveOriginalSchedule(Mockito.argThat(new OriginalLoanScheduleEntitiesMatcher(expected)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) OriginalLoanScheduleEntitiesMatcher(org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Example 73 with AccountBO

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

the class LoanBusinessServiceTest method persistOriginalSchedule.

@Test
public void persistOriginalSchedule() throws PersistenceException {
    Set<LoanScheduleEntity> installments = new LinkedHashSet<LoanScheduleEntity>();
    MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
    Money money = new Money(mifosCurrency, "123");
    AccountBO accountBO = mock(AccountBO.class);
    CustomerBO customerBO = mock(CustomerBO.class);
    when(accountBO.getCurrency()).thenReturn(mifosCurrency);
    LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(accountBO, customerBO, new Short("1"), new java.sql.Date(new Date().getTime()), PaymentStatus.UNPAID, money, money);
    installments.add(loanScheduleEntity);
    when(loanBO.getLoanScheduleEntities()).thenReturn(installments);
    loanBusinessService.persistOriginalSchedule(loanBO);
    ArrayList<OriginalLoanScheduleEntity> expected = new ArrayList<OriginalLoanScheduleEntity>();
    expected.add(new OriginalLoanScheduleEntity(loanScheduleEntity));
    verify(legacyLoanDao).saveOriginalSchedule(Mockito.argThat(new OriginalLoanScheduleEntitiesMatcher(expected)));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) OriginalLoanScheduleEntitiesMatcher(org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Example 74 with AccountBO

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

the class SavingsPersistence method getSavingsAccountWithAccountActionsInitialized.

@SuppressWarnings("unchecked")
public AccountBO getSavingsAccountWithAccountActionsInitialized(Integer accountId) throws PersistenceException {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("accountId", accountId);
    List obj = executeNamedQuery("accounts.retrieveSavingsAccountWithAccountActions", queryParameters);
    Object[] obj1 = (Object[]) obj.get(0);
    return (AccountBO) obj1[0];
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) HashMap(java.util.HashMap) List(java.util.List)

Example 75 with AccountBO

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

the class WebTierAccountServiceFacade method applyCharge.

@Override
public void applyCharge(Integer accountId, Short chargeId, Double chargeAmount, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        if (account instanceof LoanBO && !account.isGroupLoanAccount()) {
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);
                    if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                        PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                        individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
                    } else {
                        FeeBO fee = this.feeDao.findById(chargeId);
                        if (fee instanceof RateFeeBO) {
                            individual.applyCharge(chargeId, chargeAmount);
                        } else {
                            Double radio = individual.getLoanAmount().getAmount().doubleValue() / ((LoanBO) account).getLoanAmount().getAmount().doubleValue();
                            individual.applyCharge(chargeId, chargeAmount * radio);
                        }
                    }
                }
            }
        }
        account.updateDetails(userContext);
        CustomerLevel customerLevel = null;
        if (account.isCustomerAccount()) {
            customerLevel = account.getCustomer().getLevel();
        }
        if (account.getPersonnel() != null) {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        if (isPenaltyType && account instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) account).addAccountPenalty(new AccountPenaltiesEntity(account, penalty, chargeAmount));
        } else {
            account.applyCharge(chargeId, chargeAmount);
        }
        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);
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) CustomerLevel(org.mifos.customers.api.CustomerLevel) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

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