use of org.mifos.dto.screen.RepayLoanDto 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.RepayLoanDto in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentDetails.
@Override
public RepayLoanDto retrieveLoanRepaymentDetails(String globalAccountNumber) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNumber);
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
Money repaymentAmount;
Money waiverAmount;
if (loan.isDecliningBalanceInterestRecalculation()) {
RepaymentResultsHolder repaymentResultsHolder = scheduleCalculatorAdaptor.computeRepaymentAmount(loan, DateUtils.getCurrentDateWithoutTimeStamp());
repaymentAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getTotalRepaymentAmount());
waiverAmount = new Money(loan.getCurrency(), repaymentResultsHolder.getWaiverAmount());
} else {
repaymentAmount = loan.getEarlyRepayAmount();
waiverAmount = loan.waiverAmount();
}
Money waivedRepaymentAmount = repaymentAmount.subtract(waiverAmount);
List<SavingsDetailDto> savingsInUse = clientServiceFacade.retrieveSavingsInUseForClient(loan.getCustomer().getCustomerId());
List<SavingsDetailDto> accountsForTransfer = new ArrayList<SavingsDetailDto>();
if (savingsInUse != null) {
for (SavingsDetailDto savingsAccount : savingsInUse) {
if (savingsAccount.getAccountStateId().equals(AccountState.SAVINGS_ACTIVE.getValue())) {
accountsForTransfer.add(savingsAccount);
}
}
}
return new RepayLoanDto(repaymentAmount.toString(), waivedRepaymentAmount.toString(), loan.isInterestWaived(), accountsForTransfer);
}
use of org.mifos.dto.screen.RepayLoanDto 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;
}
use of org.mifos.dto.screen.RepayLoanDto in project head by mifos.
the class RepayLoanAction method loadRepayment.
@TransactionDemarcate(joinToken = true)
public ActionForward loadRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Loading repay loan page");
RepayLoanActionForm actionForm = (RepayLoanActionForm) form;
actionForm.setReceiptNumber(null);
actionForm.setReceiptDate(null);
actionForm.setPaymentTypeId(null);
actionForm.setWaiverInterest(true);
actionForm.setDateOfPayment(DateUtils.makeDateAsSentFromBrowser());
actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
actionForm.setPrintReceipt(false);
actionForm.setTruePrintReceipt(false);
UserContext userContext = getUserContext(request);
String globalAccountNum = request.getParameter("globalAccountNum");
RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
java.util.Date lastPaymentDate = new java.util.Date(0);
AccountPaymentEntity lastPayment = loan.findMostRecentNonzeroPaymentByPaymentDate();
if (lastPayment != null) {
lastPaymentDate = lastPayment.getPaymentDate();
}
actionForm.setLastPaymentDate(lastPaymentDate);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, repayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, repayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney()), request);
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney()), request);
SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, repayLoanDto.getSavingsAccountsForTransfer(), request);
List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
return mapping.findForward(Constants.LOAD_SUCCESS);
}
use of org.mifos.dto.screen.RepayLoanDto in project head by mifos.
the class RepayLoanAction method loadGroupRepayment.
@TransactionDemarcate(joinToken = true)
public ActionForward loadGroupRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.info("Loading repay group loan page");
RepayLoanActionForm actionForm = (RepayLoanActionForm) form;
actionForm.setReceiptNumber(null);
actionForm.setReceiptDate(null);
actionForm.setPaymentTypeId(null);
actionForm.setWaiverInterest(true);
actionForm.setDateOfPayment(DateUtils.makeDateAsSentFromBrowser());
actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
actionForm.setPrintReceipt(false);
actionForm.setTruePrintReceipt(false);
UserContext userContext = getUserContext(request);
LoanBO parent = loanDao.findByGlobalAccountNum(request.getParameter("globalAccountNum"));
RepayLoanDto parentRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(parent.getGlobalAccountNum());
Map<String, Double> memberNumWithAmount = new HashMap<String, Double>();
Money earlyRepaymentMoney;
Money waivedRepaymentMoney;
if (parent.isGroupLoanAccountMember()) {
earlyRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getEarlyRepaymentMoney());
waivedRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getWaivedRepaymentMoney());
} else {
earlyRepaymentMoney = new Money(parent.getCurrency());
waivedRepaymentMoney = new Money(parent.getCurrency());
}
for (LoanBO member : parent.getMemberAccounts()) {
RepayLoanDto memberRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(member.getGlobalAccountNum());
earlyRepaymentMoney = earlyRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getEarlyRepaymentMoney()));
waivedRepaymentMoney = waivedRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getWaivedRepaymentMoney()));
memberNumWithAmount.put(member.getAccountId().toString(), Double.valueOf(memberRepayLoanDto.getEarlyRepaymentMoney()));
}
java.util.Date lastPaymentDate = new java.util.Date(0);
AccountPaymentEntity lastPayment = parent.findMostRecentNonzeroPaymentByPaymentDate();
if (lastPayment != null) {
lastPaymentDate = lastPayment.getPaymentDate();
}
actionForm.setLastPaymentDate(lastPaymentDate);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, parentRepayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, parentRepayLoanDto.shouldWaiverInterest(), request);
SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, earlyRepaymentMoney, request);
SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, waivedRepaymentMoney, request);
SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, parentRepayLoanDto.getSavingsAccountsForTransfer(), request);
SessionUtils.setMapAttribute(LoanConstants.MEMBER_LOAN_REPAYMENT, new HashMap<String, Double>(memberNumWithAmount), request);
List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
return mapping.findForward(Constants.LOAD_GROUP_SUCCESS);
}
Aggregations