use of org.mifos.dto.domain.CustomerDto in project head by mifos.
the class LoanAccountRESTController method repay.
@RequestMapping(value = "/account/loan/num-{globalAccountNum}/repay", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> repay(@PathVariable String globalAccountNum, @RequestParam BigDecimal amount, @RequestParam(required = false) String paymentDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam(required = false) Short paymentModeId) throws Exception {
validateAmount(amount);
LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
validateLoanAccountState(loan);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserReferenceDto userDto = new UserReferenceDto((short) user.getUserId());
Money outstandingBeforePayment = loan.getLoanSummary().getOutstandingBalance();
AccountReferenceDto accountDto = new AccountReferenceDto(loan.getAccountId());
DateTime today = new DateTime();
DateTime paymentDateTime = today;
if (paymentDate != null && !paymentDate.isEmpty()) {
paymentDateTime = validateDateString(paymentDate, format);
}
String receiptIdString = null;
if (receiptId != null) {
receiptIdString = receiptId.toString();
}
LocalDate receiptLocalDate = null;
if (receiptDate != null && !receiptDate.isEmpty()) {
receiptLocalDate = validateDateString(receiptDate, format).toLocalDate();
}
PaymentTypeDto paymentType = new PaymentTypeDto(paymentModeId, "");
validatePaymentTypeId(paymentType, accountService.getLoanPaymentTypes());
CustomerBO client = loan.getCustomer();
CustomerDto customer = new CustomerDto();
customer.setCustomerId(client.getCustomerId());
AccountPaymentParametersDto payment = new AccountPaymentParametersDto(userDto, accountDto, amount, paymentDateTime.toLocalDate(), paymentType, globalAccountNum, receiptLocalDate, receiptIdString, customer);
accountService.makePayment(payment);
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.domain.CustomerDto in project head by mifos.
the class SavingsAccountRESTController method doSavingsTrxn.
private Map<String, String> doSavingsTrxn(String globalAccountNum, BigDecimal amount, String trxnDate, Short receiptId, String receiptDate, Short paymentTypeId, TrxnTypes trxnType) throws Exception {
validateAmount(amount);
String format = "dd-MM-yyyy";
DateTime trnxDate = validateDateString(trxnDate, format);
validateSavingsDate(trnxDate);
DateTime receiptDateTime = null;
if (receiptDate != null && !receiptDate.isEmpty()) {
receiptDateTime = validateDateString(receiptDate, format);
validateSavingsDate(receiptDateTime);
} else {
receiptDateTime = new DateTime(trnxDate);
}
SavingsBO savingsBO = savingsDao.findBySystemId(globalAccountNum);
validateAccountState(savingsBO);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Integer accountId = savingsBO.getAccountId();
DateTime today = new DateTime();
String receiptIdString;
if (receiptId == null) {
receiptIdString = "";
} else {
receiptIdString = receiptId.toString();
}
CustomerBO client = savingsBO.getCustomer();
CustomerDto customer = new CustomerDto();
customer.setCustomerId(client.getCustomerId());
Money balanceBeforePayment = savingsBO.getSavingsBalance();
if (trxnType.equals(TrxnTypes.savings_deposit)) {
validateSavingsPaymentTypeId(paymentTypeId, accountService.getSavingsPaymentTypes());
SavingsDepositDto savingsDeposit = new SavingsDepositDto(accountId.longValue(), savingsBO.getCustomer().getCustomerId().longValue(), trnxDate.toLocalDate(), amount.doubleValue(), paymentTypeId.intValue(), receiptIdString, receiptDateTime.toLocalDate(), Locale.UK);
this.savingsServiceFacade.deposit(savingsDeposit);
} else {
validateSavingsPaymentTypeId(paymentTypeId, accountService.getSavingsWithdrawalTypes());
SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(accountId.longValue(), savingsBO.getCustomer().getCustomerId().longValue(), trnxDate.toLocalDate(), amount.doubleValue(), paymentTypeId.intValue(), receiptIdString, receiptDateTime.toLocalDate(), Locale.UK);
this.savingsServiceFacade.withdraw(savingsWithdrawal);
}
Map<String, String> map = new HashMap<String, String>();
map.put("status", "success");
map.put("clientName", client.getDisplayName());
map.put("clientNumber", client.getGlobalCustNum());
map.put("savingsDisplayName", savingsBO.getSavingsOffering().getPrdOfferingName());
map.put("paymentDate", today.toLocalDate().toString());
map.put("paymentTime", today.toLocalTime().toString());
map.put("paymentAmount", savingsBO.getLastPmnt().getAmount().toString());
map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
map.put("balanceBeforePayment", balanceBeforePayment.toString());
map.put("balanceAfterPayment", savingsBO.getSavingsBalance().toString());
return map;
}
use of org.mifos.dto.domain.CustomerDto in project head by mifos.
the class LoanAccountServiceFacadeWebTier method getGuarantorsByLoanId.
public List<CustomerDto> getGuarantorsByLoanId(Integer loanId) throws PersistenceException {
List<CustomerDto> guarantors = new ArrayList<CustomerDto>();
List<GuarantyEntity> guaranties = legacyAccountDao.getGuarantyByLoanId(loanId);
for (GuarantyEntity guaranty : guaranties) {
ClientBO guarantor = customerDao.findClientById(guaranty.getGuarantorId());
CustomerDto customerDto = new CustomerDto(guarantor.getCustomerId(), guarantor.getClientName().getDisplayName(), guarantor.getGlobalCustNum(), null);
guarantors.add(customerDto);
}
return guarantors;
}
Aggregations