use of org.springframework.web.bind.annotation.RequestMapping 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.springframework.web.bind.annotation.RequestMapping in project head by mifos.
the class LoanAccountRESTController method applyCharge.
@RequestMapping(value = "/account/loan/num-{globalAccountNum}/charge", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> applyCharge(@PathVariable String globalAccountNum, @RequestParam BigDecimal amount, @RequestParam Short feeId) throws Exception {
validateAmount(amount);
List<String> applicableFees = new ArrayList<String>();
for (Map<String, String> feeMap : this.getApplicableFees(globalAccountNum).values()) {
applicableFees.add(feeMap.get("feeId"));
}
validateFeeId(feeId, applicableFees);
Map<String, String> map = new HashMap<String, String>();
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
Integer accountId = loan.getAccountId();
CustomerBO client = loan.getCustomer();
String outstandingBeforeCharge = loan.getLoanSummary().getOutstandingBalance().toString();
this.accountServiceFacade.applyCharge(accountId, feeId, amount.doubleValue(), false);
DateTime today = new DateTime();
map.put("status", "success");
map.put("clientName", client.getDisplayName());
map.put("clientNumber", client.getGlobalCustNum());
map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
map.put("chargeDate", today.toLocalDate().toString());
map.put("chargeTime", today.toLocalTime().toString());
map.put("chargeAmount", Double.valueOf(amount.doubleValue()).toString());
map.put("chargeMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
map.put("outstandingBeforeCharge", outstandingBeforeCharge);
map.put("outstandingAfterCharge", loan.getLoanSummary().getOutstandingBalance().toString());
return map;
}
use of org.springframework.web.bind.annotation.RequestMapping in project head by mifos.
the class LoanAccountRESTController method getApplicableFees.
@RequestMapping(value = "/account/loan/num-{globalAccountNum}/fees", method = RequestMethod.GET)
@ResponseBody
public Map<String, Map<String, String>> getApplicableFees(@PathVariable String globalAccountNum) throws Exception {
LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
Integer accountId = loan.getAccountId();
List<ApplicableCharge> applicableCharges = this.accountServiceFacade.getApplicableFees(accountId);
Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
for (ApplicableCharge applicableCharge : applicableCharges) {
Map<String, String> feeMap = new HashMap<String, String>();
feeMap.put("feeId", applicableCharge.getFeeId());
feeMap.put("amountOrRate", applicableCharge.getAmountOrRate());
feeMap.put("formula", applicableCharge.getFormula());
feeMap.put("periodicity", applicableCharge.getPeriodicity());
feeMap.put("paymentType", applicableCharge.getPaymentType());
feeMap.put("isRateType", applicableCharge.getIsRateType());
map.put(applicableCharge.getFeeName(), feeMap);
}
return map;
}
use of org.springframework.web.bind.annotation.RequestMapping in project head by mifos.
the class PersonnelRESTController method getOverdueBorrowersUnderPersonnel.
@RequestMapping(value = "personnel/id-current/overdue_borrowers", method = RequestMethod.GET)
@ResponseBody
public OverdueCustomer[] getOverdueBorrowersUnderPersonnel() {
List<OverdueCustomer> overdueCustomers = new ArrayList<OverdueCustomer>();
PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(getCurrentPersonnel().getPersonnelId());
for (CustomerDetailDto group : this.customerDao.findGroupsUnderUser(loanOfficer)) {
addClientIfHasOverdueLoan(customerDao.findGroupBySystemId(group.getGlobalCustNum()), overdueCustomers);
for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsUnderParent(group.getSearchId(), loanOfficer.getOffice().getOfficeId())) {
addClientIfHasOverdueLoan(client, overdueCustomers);
}
}
for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsWithoutGroupForLoanOfficer(loanOfficer.getPersonnelId(), loanOfficer.getOffice().getOfficeId())) {
addClientIfHasOverdueLoan(client, overdueCustomers);
}
return overdueCustomers.toArray(new OverdueCustomer[] {});
}
use of org.springframework.web.bind.annotation.RequestMapping in project head by mifos.
the class PersonnelRESTController method getLastRepayments.
@RequestMapping(value = "personnel/id-current/last-repayments", method = RequestMethod.GET)
@ResponseBody
public List<LastRepaymentDto> getLastRepayments() {
List<LastRepaymentDto> lastRepayments = new ArrayList<LastRepaymentDto>();
PersonnelBO loanOfficer = personnelDao.findPersonnelById(getCurrentPersonnel().getPersonnelId());
List<CustomerBO> borrowers = new ArrayList<CustomerBO>();
for (CustomerDetailDto group : this.customerDao.findGroupsUnderUser(loanOfficer)) {
borrowers.add(customerDao.findGroupBySystemId(group.getGlobalCustNum()));
for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsUnderParent(group.getSearchId(), loanOfficer.getOffice().getOfficeId())) {
borrowers.add(client);
}
}
for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsWithoutGroupForLoanOfficer(loanOfficer.getPersonnelId(), loanOfficer.getOffice().getOfficeId())) {
borrowers.add(client);
}
for (CustomerBO borrower : borrowers) {
List<LoanBO> loans = borrower.getOpenLoanAccountsAndGroupLoans();
if (loans != null && loans.size() != 0) {
LoanBO lastLoan = null;
Date lastLoanDate = null;
for (LoanBO loan : loans) {
Date lastAction = null;
for (AccountActionDateEntity accountAction : loan.getAccountActionDates()) {
if (lastAction == null || lastAction.before(accountAction.getActionDate())) {
lastAction = accountAction.getActionDate();
}
}
if (lastLoanDate == null || lastLoanDate.before(lastAction)) {
lastLoan = loan;
lastLoanDate = lastAction;
}
}
if (lastLoan == null || lastLoanDate == null) {
continue;
}
ClientDescriptionDto clientDescription = new ClientDescriptionDto(borrower.getCustomerId(), borrower.getDisplayName(), borrower.getGlobalCustNum(), borrower.getSearchId());
LoanDetailDto loanDetails = new LoanDetailDto(lastLoan.getGlobalAccountNum(), lastLoan.getLoanOffering().getPrdOfferingName(), lastLoan.getAccountState().getId(), lastLoan.getAccountState().getName(), lastLoan.getLoanBalance().toString(), lastLoan.getTotalAmountDue().toString(), lastLoan.getAccountType().getAccountTypeId(), lastLoan.getTotalAmountInArrears().toString());
LastRepaymentDto lastRepayment = new LastRepaymentDto(clientDescription, loanDetails, lastLoanDate);
if (borrower instanceof GroupBO) {
lastRepayment.setGroup(true);
}
lastRepayments.add(lastRepayment);
}
}
return lastRepayments;
}
Aggregations