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);
}
}
}
}
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());
}
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)));
}
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)));
}
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());
}
Aggregations