Search in sources :

Example 26 with LoanScheduleEntity

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

the class LoanAccountServiceFacadeWebTier method checkScheduleForMembers.

private void checkScheduleForMembers(LoanSchedule loanSchedule, LoanBO loan, List<GroupMemberLoanDetail> individualMembersOfGroupLoan, List<BigDecimal> radio) {
    for (int i = 0; i < loan.getNoOfInstallments(); ++i) {
        BigDecimal principal = loanSchedule.getRoundedLoanSchedules().get(i).getPrincipal().getAmount();
        BigDecimal interest = loanSchedule.getRoundedLoanSchedules().get(i).getInterest().getAmount();
        BigDecimal miscFee = loanSchedule.getRoundedLoanSchedules().get(i).getMiscFee().getAmount();
        BigDecimal miscPenalty = loanSchedule.getRoundedLoanSchedules().get(i).getMiscPenalty().getAmount();
        for (GroupMemberLoanDetail groupMemberLoanDetail : individualMembersOfGroupLoan) {
            LoanScheduleEntity loanScheduleEntity = groupMemberLoanDetail.getMemberSchedule().getRoundedLoanSchedules().get(i);
            principal = principal.subtract(loanScheduleEntity.getPrincipal().getAmount());
            interest = interest.subtract(loanScheduleEntity.getInterest().getAmount());
            miscFee = miscFee.subtract(loanScheduleEntity.getMiscFee().getAmount());
            miscPenalty = miscPenalty.subtract(loanScheduleEntity.getMiscPenalty().getAmount());
        }
        if (principal.compareTo(BigDecimal.ZERO) != 0) {
            for (int j = 0; j < individualMembersOfGroupLoan.size(); ++j) {
                Money oldPrincipal = individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).getPrincipal();
                Money newPrincipal = oldPrincipal.add(new Money(loan.getCurrency(), principal.multiply(radio.get(j))));
                individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).setPrincipal(newPrincipal);
            }
        }
        if (interest.compareTo(BigDecimal.ZERO) != 0) {
            for (int j = 0; j < individualMembersOfGroupLoan.size(); ++j) {
                Money oldinterest = individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).getInterest();
                Money newInterest = oldinterest.add(new Money(loan.getCurrency(), interest.multiply(radio.get(j))));
                individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).setInterest(newInterest);
            }
        }
        if (miscFee.compareTo(BigDecimal.ZERO) != 0) {
            for (int j = 0; j < individualMembersOfGroupLoan.size(); ++j) {
                Money oldMiscFee = individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).getMiscFee();
                Money newMiscFee = oldMiscFee.add(new Money(loan.getCurrency(), miscFee.multiply(radio.get(j))));
                individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).setMiscFee(newMiscFee);
            }
        }
        if (miscPenalty.compareTo(BigDecimal.ZERO) != 0) {
            for (int j = 0; j < individualMembersOfGroupLoan.size(); ++j) {
                Money oldMiscPenalty = individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).getMiscPenalty();
                Money newMiscPenalty = oldMiscPenalty.add(new Money(loan.getCurrency(), miscPenalty.multiply(radio.get(j))));
                individualMembersOfGroupLoan.get(j).getMemberSchedule().getRoundedLoanSchedules().get(i).setMiscPenalty(newMiscPenalty);
            }
        }
    }
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) GroupMemberLoanDetail(org.mifos.clientportfolio.newloan.domain.GroupMemberLoanDetail) BigDecimal(java.math.BigDecimal)

Example 27 with LoanScheduleEntity

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

the class LoanAccountServiceFacadeWebTier method getOverDueInstallmentDetails.

private InstallmentDetailsDto getOverDueInstallmentDetails(final List<AccountActionDateEntity> overDueInstallmentList, final MifosCurrency currency) {
    Money principalDue = new Money(currency);
    Money interestDue = new Money(currency);
    Money feesDue = new Money(currency);
    Money penaltyDue = new Money(currency);
    for (AccountActionDateEntity accountActionDate : overDueInstallmentList) {
        LoanScheduleEntity installment = (LoanScheduleEntity) accountActionDate;
        principalDue = principalDue.add(installment.getPrincipalDue());
        interestDue = interestDue.add(installment.getInterestDue());
        feesDue = feesDue.add(installment.getTotalFeeDueWithMiscFeeDue());
        penaltyDue = penaltyDue.add(installment.getPenaltyDue());
    }
    Money subTotal = principalDue.add(interestDue).add(feesDue).add(penaltyDue);
    return new InstallmentDetailsDto(principalDue.toString(), interestDue.toString(), feesDue.toString(), penaltyDue.toString(), subTotal.toString());
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) InstallmentDetailsDto(org.mifos.dto.domain.InstallmentDetailsDto) LoanInstallmentDetailsDto(org.mifos.dto.domain.LoanInstallmentDetailsDto)

Example 28 with LoanScheduleEntity

use of org.mifos.accounts.loan.business.LoanScheduleEntity 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 29 with LoanScheduleEntity

use of org.mifos.accounts.loan.business.LoanScheduleEntity 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 30 with LoanScheduleEntity

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

the class LoanBusinessServiceTest method shouldApplyPaymentForNonInterestRecalculationLoanInterestType.

@Test
public void shouldApplyPaymentForNonInterestRecalculationLoanInterestType() {
    when(loanBO.isDecliningBalanceInterestRecalculation()).thenReturn(false);
    List<AccountActionDateEntity> installments = new ArrayList<AccountActionDateEntity>();
    LoanScheduleEntity installment1 = mock(LoanScheduleEntity.class);
    LoanScheduleEntity installment2 = mock(LoanScheduleEntity.class);
    when(installment1.applyPayment(Mockito.<AccountPaymentEntity>any(), Mockito.<Money>any(), Mockito.eq(personnel), Mockito.<Date>any())).thenReturn(new Money(rupee, 100d));
    when(installment2.applyPayment(Mockito.<AccountPaymentEntity>any(), Mockito.<Money>any(), Mockito.eq(personnel), Mockito.<Date>any())).thenReturn(new Money(rupee, 0d));
    installments.add(installment1);
    installments.add(installment2);
    when(loanBO.getAccountActionDatesSortedByInstallmentId()).thenReturn(installments);
    Date transactionDate = new Date();
    Money totalAmount = new Money(rupee, 10.0);
    when(paymentData.getTransactionDate()).thenReturn(transactionDate);
    when(paymentData.getTotalAmount()).thenReturn(totalAmount);
    when(paymentData.getPersonnel()).thenReturn(personnel);
    loanBusinessService.applyPayment(paymentData, loanBO, accountPaymentEntity);
    verify(scheduleCalculatorAdaptor, times(0)).applyPayment(loanBO, totalAmount, transactionDate, personnel, accountPaymentEntity, false);
    verify(loanBO, times(1)).getAccountActionDatesSortedByInstallmentId();
    verify(loanBO, times(1)).isDecliningBalanceInterestRecalculation();
    verify(paymentData).getTransactionDate();
    verify(paymentData).getTotalAmount();
    verify(paymentData).getPersonnel();
    verify(installment1).applyPayment(Matchers.<AccountPaymentEntity>any(), Matchers.<Money>any(), Matchers.eq(personnel), Matchers.<Date>any());
    verify(installment2).applyPayment(Matchers.<AccountPaymentEntity>any(), Matchers.<Money>any(), Matchers.eq(personnel), Matchers.<Date>any());
}
Also used : OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Aggregations

LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)54 Money (org.mifos.framework.util.helpers.Money)32 ArrayList (java.util.ArrayList)19 OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)18 Test (org.junit.Test)16 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)14 BigDecimal (java.math.BigDecimal)11 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)8 LoanBO (org.mifos.accounts.loan.business.LoanBO)8 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)7 Date (java.util.Date)5 CustomerBO (org.mifos.customers.business.CustomerBO)5 UserContext (org.mifos.security.util.UserContext)5 LocalDate (org.joda.time.LocalDate)4 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)4 OriginalLoanScheduleEntitiesMatcher (org.mifos.accounts.loan.business.matchers.OriginalLoanScheduleEntitiesMatcher)4 InstallmentDetailsDto (org.mifos.dto.domain.InstallmentDetailsDto)4 LoanInstallmentDetailsDto (org.mifos.dto.domain.LoanInstallmentDetailsDto)4 MifosUser (org.mifos.security.MifosUser)4 Date (java.sql.Date)3