use of org.mifos.dto.domain.PaymentTypeDto 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.domain.PaymentTypeDto in project head by mifos.
the class StandardAccountService method getPaymentTypes.
private List<PaymentTypeDto> getPaymentTypes(short transactionType) throws PersistenceException {
final Short IGNORED_LOCALE_ID = 1;
List<PaymentTypeEntity> paymentTypeEntities = this.acceptedPaymentTypePersistence.getAcceptedPaymentTypesForATransaction(IGNORED_LOCALE_ID, transactionType);
List<PaymentTypeDto> paymentTypeDtos = new ArrayList<PaymentTypeDto>();
for (PaymentTypeEntity paymentTypeEntity : paymentTypeEntities) {
paymentTypeDtos.add(new PaymentTypeDto(paymentTypeEntity.getId(), paymentTypeEntity.getName()));
}
return paymentTypeDtos;
}
use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.
the class LoanAccountRESTController method disburseLoan.
@RequestMapping(value = "/account/loan/num-{globalAccountNum}/disburse", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> disburseLoan(@PathVariable String globalAccountNum, @RequestParam String disbursalDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam Short disbursePaymentTypeId, @RequestParam(required = false) Short paymentModeOfPayment) throws Exception {
String format = "dd-MM-yyyy";
DateTime trnxDate = validateDateString(disbursalDate, format);
validateDisbursementDate(trnxDate);
DateTime receiptDateTime = null;
if (receiptDate != null && !receiptDate.isEmpty()) {
receiptDateTime = validateDateString(receiptDate, format);
validateDisbursementDate(receiptDateTime);
}
validateDisbursementPaymentTypeId(disbursePaymentTypeId, accountService.getLoanDisbursementTypes());
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
String comment = "";
Short paymentTypeId = Short.valueOf(disbursePaymentTypeId);
Money outstandingBeforeDisbursement = loan.getLoanSummary().getOutstandingBalance();
CustomerDto customerDto = null;
PaymentTypeDto paymentType = null;
AccountPaymentParametersDto loanDisbursement;
if (receiptId == null || receiptDateTime == null) {
loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()), new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(), trnxDate.toLocalDate(), paymentType, comment);
} else {
loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()), new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(), trnxDate.toLocalDate(), paymentType, comment, receiptDateTime.toLocalDate(), receiptId.toString(), customerDto);
}
// TODO : Pass the account for transfer id properly
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, PaymentTypes.CASH.getValue(), null);
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("disbursementDate", trnxDate.toLocalDate().toString());
map.put("disbursementTime", new DateTime().toLocalTime().toString());
map.put("disbursementAmount", loan.getLastPmnt().getAmount().toString());
map.put("disbursementMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
map.put("outstandingBeforeDisbursement", outstandingBeforeDisbursement.toString());
map.put("outstandingAfterDisbursement", loan.getLoanSummary().getOutstandingBalance().toString());
return map;
}
use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.
the class K2RESTController method processSavingsDeposit.
private Map<String, String> processSavingsDeposit(SavingsBO savingsBO, String k2TransactionId, String mmSystemId, LocalDate transactionDate, BigDecimal amount, String currency) throws Exception {
Integer paymentTypeId = null;
List<PaymentTypeDto> savingsPaymentTypes = accountService.getSavingsPaymentTypes();
for (PaymentTypeDto paymentTypeDtoIterator : savingsPaymentTypes) {
if (paymentTypeDtoIterator.getName().equals(mmSystemId)) {
paymentTypeId = paymentTypeDtoIterator.getValue().intValue();
}
}
if (paymentTypeId == null || !savingsBO.getCurrency().getCurrencyCode().equals(currency)) {
return invalidPayment();
}
Long accountId = savingsBO.getAccountId().longValue();
Long customerId = savingsBO.getCustomer().getCustomerId().longValue();
String receiptIdString = k2TransactionId;
SavingsDepositDto savingsDeposit = new SavingsDepositDto(accountId, customerId, transactionDate, amount.doubleValue(), paymentTypeId, receiptIdString, transactionDate, Locale.UK);
this.savingsServiceFacade.deposit(savingsDeposit);
return accepted();
}
use of org.mifos.dto.domain.PaymentTypeDto in project head by mifos.
the class AccountApplyPaymentAction method applyPayment.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward applyPayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
Integer accountId = Integer.valueOf(actionForm.getAccountId());
String paymentType = request.getParameter(Constants.INPUT);
UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountId, paymentType, userContext.getLocaleId(), userReferenceDto, actionForm.getTrxnDate());
validateAccountPayment(accountPaymentDto, accountId, request);
validateAmount(accountPaymentDto, actionForm.getAmount());
PaymentTypeDto paymentTypeDto;
String amount = actionForm.getAmount();
if (accountPaymentDto.getAccountType().equals(AccountTypeDto.LOAN_ACCOUNT)) {
paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
} else {
paymentTypeDto = getFeePaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
}
AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto());
if (paymentTypeDto.getValue().equals(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId())) {
this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, actionForm.getAccountForTransfer());
} else {
this.accountServiceFacade.makePayment(accountPaymentParametersDto);
}
request.getSession().setAttribute("globalAccountNum", ((AccountApplyPaymentActionForm) form).getGlobalAccountNum());
ActionForward findForward;
if (actionForm.getPrintReceipt()) {
if (accountPaymentDto.getAccountType().equals(AccountTypeDto.LOAN_ACCOUNT)) {
findForward = mapping.findForward(getForward("PRINT"));
} else {
request.getSession().setAttribute("clientSystemId", accountPaymentDto.getCustomerDto().getGlobalCustNum());
findForward = mapping.findForward(getForward("PRINT_CLIENT"));
}
} else {
findForward = mapping.findForward(getForward(((AccountApplyPaymentActionForm) form).getInput()));
}
return findForward;
}
Aggregations