use of org.mifos.dto.screen.RepayLoanInfoDto in project head by mifos.
the class RepayLoanAction method makeGroupRepayment.
public ActionForward makeGroupRepayment(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");
LoanBO loan = loanDao.findByGlobalAccountNum(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 = null;
Map<String, Double> memberRepayment = new HashMap<String, Double>();
if (loan.isGroupLoanAccountParent()) {
memberRepayment = (Map<String, Double>) SessionUtils.getAttribute(LoanConstants.MEMBER_LOAN_REPAYMENT, request);
repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
} else if (loan.isGroupLoanAccountMember()) {
repayLoanInfoDto = new RepayLoanInfoDto(loan.getParentAccount().getGlobalAccountNum(), repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
memberRepayment.put(loan.getAccountId().toString(), Double.valueOf(repayLoanInfoDto.getEarlyRepayAmount()));
}
if (repayLoanActionForm.isSavingsTransfer()) {
this.loanAccountServiceFacade.makeEarlyRepaymentFromSavings(repayLoanInfoDto, repayLoanActionForm.getAccountForTransfer());
} else {
this.loanAccountServiceFacade.makeEarlyGroupRepayment(repayLoanInfoDto, memberRepayment);
}
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 RepayLoanAction method makeGroupMemberRepayment.
public ActionForward makeGroupMemberRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Performing loan repayment");
UserContext userContext = getUserContext(request);
UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
String globalAccountNum = request.getParameter("globalAccountNum");
String forward = Constants.UPDATE_SUCCESS;
Date receiptDate = null;
if (StringUtils.isNotEmpty(repayLoanActionForm.getReceiptDate())) {
receiptDate = repayLoanActionForm.getReceiptDateValue(userContext.getPreferredLocale());
}
PaymentTypeDto paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(repayLoanActionForm.getPaymentTypeId()));
LoanBO acctualMemberAccount = loanDao.findByGlobalAccountNum(globalAccountNum);
Integer accountId = acctualMemberAccount.getAccountId();
AccountPaymentDto accountPaymentDto = this.accountServiceFacade.getAccountPaymentInformation(accountId, repayLoanActionForm.getPaymentTypeId(), userContext.getLocaleId(), userReferenceDto, repayLoanActionForm.getDateOfPaymentValue(defaultLocale));
LoanBO parrentAccount = acctualMemberAccount.getParentAccount();
Integer parentAccountId = parrentAccount.getAccountId();
AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(parentAccountId), new BigDecimal(repayLoanActionForm.getAmount()), new LocalDate(DateUtils.getDate(repayLoanActionForm.getDateOfPayment())), paymentTypeDto, AccountConstants.NO_COMMENT, new LocalDate(DateUtils.getDate(repayLoanActionForm.getReceiptDate())), repayLoanActionForm.getReceiptNumber(), accountPaymentDto.getCustomerDto());
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);
HashMap<Integer, String> individualValues = new HashMap<Integer, String>();
for (LoanBO member : loanDao.findIndividualLoans(parentAccountId)) {
if (member.isAccountActive()) {
if (member.getAccountId().equals(acctualMemberAccount.getAccountId())) {
individualValues.put(member.getAccountId(), repayLoanActionForm.getAmount());
} else {
individualValues.put(member.getAccountId(), "0.0");
}
}
}
accountPaymentParametersDto.setMemberInfo(individualValues);
accountPaymentParametersDto.setMemberAccountIdToRepay(accountId);
accountPaymentParametersDto.setRepayLoanInfoDto(repayLoanInfoDto);
accountPaymentParametersDto.setInterestDueForCurrentInstalmanet(this.loanAccountServiceFacade.calculateInterestDueForCurrentInstalmanet(repayLoanInfoDto));
if (repayLoanActionForm.isSavingsTransfer()) {
this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, repayLoanActionForm.getAccountForTransfer());
} else {
this.accountServiceFacade.makePayment(accountPaymentParametersDto);
}
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 LoanAccountServiceFacadeWebTier method generateAmountWithInterest.
private Map<String, AmountWithInterest> generateAmountWithInterest(Map<String, Double> memberNumWithAmount, RepayLoanInfoDto parentRLIDto) {
Map<String, AmountWithInterest> awi = new HashMap<String, AmountWithInterest>();
for (Map.Entry<String, Double> entry : memberNumWithAmount.entrySet()) {
LoanBO loan = this.loanDao.findById(Integer.valueOf(entry.getKey()));
String globalAccountNum = loan.getGlobalAccountNum();
RepayLoanDto memberRLDto = retrieveLoanRepaymentDetails(globalAccountNum);
RepayLoanInfoDto memberRLIDto = new RepayLoanInfoDto(globalAccountNum, memberRLDto.getEarlyRepaymentMoney(), parentRLIDto.getReceiptNumber(), parentRLIDto.getReceiptDate(), parentRLIDto.getPaymentTypeId(), parentRLIDto.getId(), parentRLIDto.isWaiveInterest(), parentRLIDto.getDateOfPayment(), new BigDecimal(entry.getValue()), new BigDecimal(memberRLDto.getWaivedRepaymentMoney()));
awi.put(entry.getKey(), new org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest(entry.getValue(), calculateInterestDueForCurrentInstalmanet(memberRLIDto)));
}
return awi;
}
use of org.mifos.dto.screen.RepayLoanInfoDto in project head by mifos.
the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepaymentForNotWaiverInterestLoanProduct.
@Test
public void testMakeEarlyRepaymentForNotWaiverInterestLoanProduct() throws AccountException, PersistenceException {
setMifosUserFromContext();
when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
when(loanDao.findById(0)).thenReturn(loanBO);
boolean waiveInterest = false;
when(loanBO.getCurrency()).thenReturn(rupee);
when(loanBO.getOfficeId()).thenReturn((short) 1);
when(loanBO.getCustomer()).thenReturn(customer);
when(customer.getLoanOfficerId()).thenReturn((short) 1);
when(customer.getCustomerId()).thenReturn(2);
LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity() {
};
loanScheduleEntity.setInterest(new Money(rupee, 100d));
when(loanBO.getDetailsOfNextInstallment()).thenReturn(loanScheduleEntity);
java.sql.Date date = mock(java.sql.Date.class);
when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
String paymentMethod = "1";
String receiptNumber = "001";
AccountPaymentDto paymentDto = new AccountPaymentDto(new Double(100), date, receiptNumber, date, Short.valueOf((short) 1));
loanAccountServiceFacade.makeEarlyRepayment(new RepayLoanInfoDto("1", "100.0", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.ZERO, BigDecimal.ZERO));
short userId = (short) 1;
verify(loanBO).makeEarlyRepayment(paymentDto, userId, waiveInterest, new Money(rupee, 100d));
verify(loanBusinessService).computeExtraInterest(loanBO, date);
}
use of org.mifos.dto.screen.RepayLoanInfoDto in project head by mifos.
the class LoanAccountRESTController method fullRepay.
@RequestMapping(value = "/account/loan/num-{globalAccountNum}/fullrepay", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> fullRepay(@PathVariable String globalAccountNum, @RequestParam(required = false) String paymentDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam(required = false) Short paymentModeId, @RequestParam Boolean waiveInterest) throws Exception {
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
validateLoanAccountState(loan);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
DateTime today = new DateTime();
Date paymentDateTime = new Date(today.toDate().getTime());
if (paymentDate != null && !paymentDate.isEmpty()) {
paymentDateTime = new Date(validateDateString(paymentDate, format).toDate().getTime());
}
String receiptIdString = null;
if (receiptId != null) {
receiptIdString = receiptId.toString();
}
Date receiptDateTime = null;
if (receiptDate != null && !receiptDate.isEmpty()) {
receiptDateTime = new Date(validateDateString(receiptDate, format).toDate().getTime());
}
String paymentTypeId = null;
if (paymentModeId != null) {
paymentTypeId = paymentModeId.toString();
}
validateDisbursementPaymentTypeId(paymentModeId, accountService.getLoanPaymentTypes());
BigDecimal totalRepaymentAmount = (new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney())).getAmount();
BigDecimal waivedAmount = (new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney())).getAmount();
BigDecimal earlyRepayAmount = totalRepaymentAmount;
if (Boolean.TRUE.equals(waiveInterest)) {
earlyRepayAmount = waivedAmount;
}
RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, Double.toString(earlyRepayAmount.doubleValue()), receiptIdString, receiptDateTime, paymentTypeId, (short) user.getUserId(), waiveInterest.booleanValue(), paymentDateTime, totalRepaymentAmount, waivedAmount);
Money outstandingBeforePayment = loan.getLoanSummary().getOutstandingBalance();
this.loanAccountServiceFacade.makeEarlyRepaymentWithCommit(repayLoanInfoDto);
CustomerBO client = loan.getCustomer();
Map<String, String> map = new HashMap<String, String>();
map.put("status", "success");
map.put("clientName", client.getDisplayName());
map.put("clientNumber", client.getGlobalCustNum());
map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
map.put("paymentDate", today.toLocalDate().toString());
map.put("paymentTime", today.toLocalTime().toString());
map.put("paymentAmount", loan.getLastPmnt().getAmount().toString());
map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
map.put("outstandingBeforePayment", outstandingBeforePayment.toString());
map.put("outstandingAfterPayment", loan.getLoanSummary().getOutstandingBalance().toString());
return map;
}
Aggregations