use of org.mifos.dto.screen.RepayLoanInfoDto in project head by mifos.
the class RepayLoanAction method makeRepayment.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward makeRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Performing loan repayment");
UserContext userContext = getUserContext(request);
RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
Date receiptDate = null;
if (StringUtils.isNotEmpty(repayLoanActionForm.getReceiptDate())) {
receiptDate = repayLoanActionForm.getReceiptDateValue(userContext.getPreferredLocale());
}
String globalAccountNum = request.getParameter("globalAccountNum");
String forward = Constants.UPDATE_SUCCESS;
BigDecimal totalRepaymentAmount = ((Money) SessionUtils.getAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request)).getAmount();
BigDecimal waivedAmount = ((Money) SessionUtils.getAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request)).getAmount();
RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
if (repayLoanActionForm.isSavingsTransfer()) {
this.loanAccountServiceFacade.makeEarlyRepaymentFromSavings(repayLoanInfoDto, repayLoanActionForm.getAccountForTransfer());
} else {
this.loanAccountServiceFacade.makeEarlyRepayment(repayLoanInfoDto);
}
SessionUtils.removeAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request);
SessionUtils.removeAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request);
SessionUtils.removeAttribute(Constants.ACCOUNTS_FOR_TRANSFER, request);
request.getSession().setAttribute("globalAccountNum", globalAccountNum);
if (repayLoanActionForm.getPrintReceipt()) {
return mapping.findForward(ActionForwards.printPaymentReceipt.toString());
}
return mapping.findForward(forward);
}
use of org.mifos.dto.screen.RepayLoanInfoDto in project head by mifos.
the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepaymentFromSavings.
@Test
public void testMakeEarlyRepaymentFromSavings() throws AccountException, PersistenceException {
final String savingsAccGlobalNum = "0001-00000009";
setMifosUserFromContext();
when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
when(loanDao.findById(0)).thenReturn(loanBO);
final java.sql.Date date = new java.sql.Date(new Date().getTime());
when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
when(loanBO.getCurrency()).thenReturn(rupee);
boolean waiveInterest = true;
when(loanBO.isInterestWaived()).thenReturn(waiveInterest);
when(loanBO.getOfficeId()).thenReturn((short) 1);
when(loanBO.getCustomer()).thenReturn(customer);
when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
when(customer.getLoanOfficerId()).thenReturn((short) 1);
when(customer.getCustomerId()).thenReturn(2);
when(savingsServiceFacade.retrieveSavingsAccountDetails(savingsAccGlobalNum)).thenReturn(savingsAccountDetailDto);
when(savingsAccountDetailDto.getCustomerId()).thenReturn(2);
when(savingsAccountDetailDto.getAccountId()).thenReturn(1);
String paymentMethod = "4";
String receiptNumber = "001";
when(savingsServiceFacade.withdraw(any(SavingsWithdrawalDto.class), eq(true))).thenReturn(withdrawal);
when(withdrawal.getPaymentId()).thenReturn(1);
loanAccountServiceFacade.makeEarlyRepaymentFromSavings(new RepayLoanInfoDto("1", "100", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.TEN, BigDecimal.ZERO), savingsAccGlobalNum);
ArgumentCaptor<SavingsWithdrawalDto> withdrawal = ArgumentCaptor.forClass(SavingsWithdrawalDto.class);
verify(savingsServiceFacade).withdraw(withdrawal.capture(), eq(true));
final Long savingsId = savingsAccountDetailDto.getAccountId().longValue();
final Long customerId = savingsAccountDetailDto.getCustomerId().longValue();
final LocalDate trxnDate = new LocalDate(date);
final LocalDate receiptDate = new LocalDate(date);
final Double amount = Double.parseDouble("100");
final Integer modeOfPayment = 4;
AccountPaymentDto paymentDto = new AccountPaymentDto(amount, date, receiptNumber, date, Short.valueOf((short) 1));
assertEquals(withdrawal.getValue().getAmount(), amount);
assertEquals(withdrawal.getValue().getSavingsId(), savingsId);
assertEquals(withdrawal.getValue().getCustomerId(), customerId);
assertEquals(withdrawal.getValue().getDateOfWithdrawal(), trxnDate);
assertEquals(withdrawal.getValue().getDateOfReceipt(), receiptDate);
assertEquals(withdrawal.getValue().getModeOfPayment(), modeOfPayment);
assertEquals(withdrawal.getValue().getPreferredLocale(), userContext.getPreferredLocale());
verify(loanBO).makeEarlyRepayment(paymentDto, (short) 1, waiveInterest, new Money(rupee, BigDecimal.ZERO), 1, null);
}
use of org.mifos.dto.screen.RepayLoanInfoDto in project head by mifos.
the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepayment.
@Test
public void testMakeEarlyRepayment() throws AccountException, PersistenceException {
setMifosUserFromContext();
when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
when(loanDao.findById(0)).thenReturn(loanBO);
java.sql.Date date = new java.sql.Date(new Date().getTime());
when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
when(loanBO.getCurrency()).thenReturn(rupee);
boolean waiveInterest = true;
when(loanBO.isInterestWaived()).thenReturn(waiveInterest);
when(loanBO.getOfficeId()).thenReturn((short) 1);
when(loanBO.getCustomer()).thenReturn(customer);
when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
when(customer.getLoanOfficerId()).thenReturn((short) 1);
when(customer.getCustomerId()).thenReturn(2);
String paymentMethod = "1";
String receiptNumber = "001";
org.mifos.dto.domain.AccountPaymentDto paymentDto = new org.mifos.dto.domain.AccountPaymentDto(new Double(100), date, receiptNumber, date, Short.valueOf((short) 1));
loanAccountServiceFacade.makeEarlyRepayment(new RepayLoanInfoDto("1", "100", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.TEN, BigDecimal.ZERO));
verify(loanBO).makeEarlyRepayment(paymentDto, (short) 1, waiveInterest, new Money(rupee, BigDecimal.ZERO));
verify(loanBusinessService).computeExtraInterest(loanBO, date);
}
use of org.mifos.dto.screen.RepayLoanInfoDto in project head by mifos.
the class LoanAccountServiceFacadeWebTierTest method testValidateMakeEarlyRepayment.
@Test
public void testValidateMakeEarlyRepayment() throws AccountException, PersistenceException {
setMifosUserFromContext();
when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
when(loanDao.findById(0)).thenReturn(loanBO);
boolean actualWaiveInterestValue = false;
java.sql.Date date = mock(java.sql.Date.class);
when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
when(loanBO.isInterestWaived()).thenReturn(actualWaiveInterestValue);
when(loanBO.getOfficeId()).thenReturn((short) 1);
when(loanBO.getCustomer()).thenReturn(customer);
when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
when(customer.getLoanOfficerId()).thenReturn((short) 1);
when(customer.getCustomerId()).thenReturn(2);
try {
loanAccountServiceFacade.makeEarlyRepayment(new RepayLoanInfoDto("1", "100", "001", mock(java.sql.Date.class), "1", (short) 1, true, date, BigDecimal.ZERO, BigDecimal.ZERO));
} catch (BusinessRuleException e) {
verify(loanBO, never()).makeEarlyRepayment((AccountPaymentDto) anyObject(), (Short) anyObject(), anyBoolean(), Matchers.<Money>anyObject());
verify(loanBO, never()).getCurrency();
verify(loanBusinessService, never()).computeExtraInterest(eq(loanBO), Matchers.<Date>anyObject());
assertThat(e.getMessageKey(), is(LoanConstants.WAIVER_INTEREST_NOT_CONFIGURED));
}
}
Aggregations