Search in sources :

Example 1 with OriginalLoanScheduleEntity

use of org.mifos.accounts.loan.business.OriginalLoanScheduleEntity in project head by mifos.

the class LoanServiceFacadeWebTier method retrieveOriginalLoanSchedule.

@Override
public OriginalScheduleInfoDto retrieveOriginalLoanSchedule(Integer accountId) {
    try {
        List<OriginalLoanScheduleEntity> loanScheduleEntities = loanBusinessService.retrieveOriginalLoanSchedule(accountId);
        ArrayList<RepaymentScheduleInstallment> repaymentScheduleInstallments = new ArrayList<RepaymentScheduleInstallment>();
        for (OriginalLoanScheduleEntity loanScheduleEntity : loanScheduleEntities) {
            repaymentScheduleInstallments.add(loanScheduleEntity.toDto());
        }
        LoanBO loan = this.loanDao.findById(accountId);
        return new OriginalScheduleInfoDto(loan.getLoanAmount().toString(), loan.getDisbursementDate(), repaymentScheduleInstallments);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with OriginalLoanScheduleEntity

use of org.mifos.accounts.loan.business.OriginalLoanScheduleEntity in project head by mifos.

the class LegacyLoanDaoIntegrationTest method testSaveAndGetOriginalLoanScheduleEntityWithFees.

@Test
public void testSaveAndGetOriginalLoanScheduleEntityWithFees() throws PersistenceException {
    ArrayList<OriginalLoanScheduleEntity> originalLoanScheduleEntities = new ArrayList<OriginalLoanScheduleEntity>();
    Date date = new Date(new java.util.Date().getTime());
    Short installmentId = new Short("1");
    FeeBO upfrontFee = TestObjectFactory.createOneTimeRateFee("Upfront Fee", FeeCategory.LOAN, Double.valueOf("20"), FeeFormula.AMOUNT, FeePayment.UPFRONT, null);
    AccountFeesEntity accountUpfrontFee = new AccountFeesEntity(goodAccount, upfrontFee, new Double("20.0"), FeeStatus.ACTIVE.getValue(), null, date);
    AccountTestUtils.addAccountFees(accountUpfrontFee, goodAccount);
    TestObjectFactory.updateObject(goodAccount);
    goodAccount = (LoanBO) TestObjectFactory.getObject(AccountBO.class, goodAccount.getAccountId());
    LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(goodAccount, group, installmentId, date, PaymentStatus.UNPAID, Money.zero(), Money.zero());
    LoanFeeScheduleEntity feesEntity = new LoanFeeScheduleEntity(loanScheduleEntity, upfrontFee, accountUpfrontFee, Money.zero());
    loanScheduleEntity.addAccountFeesAction(feesEntity);
    OriginalLoanScheduleEntity originalLoanScheduleEntity = new OriginalLoanScheduleEntity(loanScheduleEntity);
    OriginalLoanFeeScheduleEntity scheduleEntityFee = new OriginalLoanFeeScheduleEntity(feesEntity, originalLoanScheduleEntity);
    originalLoanScheduleEntities.add(originalLoanScheduleEntity);
    legacyLoanDao.saveOriginalSchedule(originalLoanScheduleEntities);
    List<OriginalLoanScheduleEntity> actual = legacyLoanDao.getOriginalLoanScheduleEntity(goodAccount.getAccountId());
    List<OriginalLoanFeeScheduleEntity> fees = new ArrayList<OriginalLoanFeeScheduleEntity>(actual.get(0).getAccountFeesActionDetails());
    Assert.assertEquals(1, actual.size());
    Assert.assertEquals(1, fees.size());
    assertThat(actual, is(new OriginalLoanScheduleEntitiesMatcher(originalLoanScheduleEntities)));
    assertThat(fees.get(0), is(new OriginalLoanFeeScheduleEntityMatcher(scheduleEntityFee)));
}
Also used : OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) OriginalLoanFeeScheduleEntityMatcher(org.mifos.accounts.loan.business.matchers.OriginalLoanFeeScheduleEntityMatcher) ArrayList(java.util.ArrayList) Date(java.sql.Date) OriginalLoanScheduleEntitiesMatcher(org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher) OriginalLoanFeeScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanFeeScheduleEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) LoanFeeScheduleEntity(org.mifos.accounts.loan.business.LoanFeeScheduleEntity) OriginalLoanFeeScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanFeeScheduleEntity) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 3 with OriginalLoanScheduleEntity

use of org.mifos.accounts.loan.business.OriginalLoanScheduleEntity in project head by mifos.

the class LoanServiceFacadeWebTierTest method retrieveOriginalLoanSchedule.

@Test
public void retrieveOriginalLoanSchedule() throws PersistenceException {
    Integer accountId = new Integer(1);
    List<OriginalLoanScheduleEntity> loanScheduleEntities = new ArrayList<OriginalLoanScheduleEntity>();
    OriginalLoanScheduleEntity originalLoanScheduleEntity1 = mock(OriginalLoanScheduleEntity.class);
    OriginalLoanScheduleEntity originalLoanScheduleEntity2 = mock(OriginalLoanScheduleEntity.class);
    loanScheduleEntities.add(originalLoanScheduleEntity1);
    loanScheduleEntities.add(originalLoanScheduleEntity2);
    RepaymentScheduleInstallment installment1 = new RepaymentScheduleInstallment();
    RepaymentScheduleInstallment installment2 = new RepaymentScheduleInstallment();
    when(originalLoanScheduleEntity1.toDto()).thenReturn(installment1);
    when(originalLoanScheduleEntity2.toDto()).thenReturn(installment2);
    List<RepaymentScheduleInstallment> expected = new ArrayList<RepaymentScheduleInstallment>();
    expected.add(installment1);
    expected.add(installment2);
    Date date = new Date();
    when(loanBO.getDisbursementDate()).thenReturn(date);
    Money money = new Money(rupee, "4.9");
    when(loanBO.getLoanAmount()).thenReturn(money);
    when(loanBusinessService.retrieveOriginalLoanSchedule(accountId)).thenReturn(loanScheduleEntities);
    when(loanDao.findById(accountId)).thenReturn(loanBO);
    OriginalScheduleInfoDto expectedOriginalScheduleInfoDto = new OriginalScheduleInfoDto(money.toString(), date, expected);
    OriginalScheduleInfoDto originalScheduleInfoDto = loanServiceFacade.retrieveOriginalLoanSchedule(accountId);
    assertThat(originalScheduleInfoDto, is(new OriginalScheduleInfoDtoMatcher(expectedOriginalScheduleInfoDto)));
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDtoMatcher(org.mifos.accounts.loan.business.matchers.OriginalScheduleInfoDtoMatcher) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 4 with OriginalLoanScheduleEntity

use of org.mifos.accounts.loan.business.OriginalLoanScheduleEntity in project head by mifos.

the class LoanBusinessService method clearAndPersistOriginalSchedule.

public void clearAndPersistOriginalSchedule(LoanBO loan) throws PersistenceException {
    List<OriginalLoanScheduleEntity> originalLoanScheduleEntities = this.getlegacyLoanDao().getOriginalLoanScheduleEntity(loan.getAccountId());
    Collection<LoanScheduleEntity> loanScheduleEntities = loan.getLoanScheduleEntities();
    Iterator<LoanScheduleEntity> loanScheduleEntitiesIterator = loanScheduleEntities.iterator();
    for (OriginalLoanScheduleEntity originalLoanScheduleEntity : originalLoanScheduleEntities) {
        Iterator<AccountFeesActionDetailEntity> accountFeesIterator = loanScheduleEntitiesIterator.next().getAccountFeesActionDetails().iterator();
        for (OriginalLoanFeeScheduleEntity originalLoanFeeScheduleEntity : originalLoanScheduleEntity.getAccountFeesActionDetails()) {
            originalLoanFeeScheduleEntity.updateFeeAmount(accountFeesIterator.next().getFeeAmount().getAmount());
        }
    }
    this.getlegacyLoanDao().saveOriginalSchedule(originalLoanScheduleEntities);
}
Also used : OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) OriginalLoanFeeScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanFeeScheduleEntity)

Example 5 with OriginalLoanScheduleEntity

use of org.mifos.accounts.loan.business.OriginalLoanScheduleEntity 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)

Aggregations

OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)9 ArrayList (java.util.ArrayList)8 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)6 Test (org.junit.Test)5 OriginalLoanScheduleEntitiesMatcher (org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher)4 Date (java.util.Date)3 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)3 Money (org.mifos.framework.util.helpers.Money)3 Date (java.sql.Date)2 LinkedHashSet (java.util.LinkedHashSet)2 AccountBO (org.mifos.accounts.business.AccountBO)2 LoanBO (org.mifos.accounts.loan.business.LoanBO)2 OriginalLoanFeeScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanFeeScheduleEntity)2 OriginalScheduleInfoDto (org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto)2 MifosCurrency (org.mifos.application.master.business.MifosCurrency)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 CustomerBO (org.mifos.customers.business.CustomerBO)2 PersistenceException (org.mifos.framework.exceptions.PersistenceException)2 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)1 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)1