Search in sources :

Example 21 with RequestMapping

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;
}
Also used : HashMap(java.util.HashMap) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerDto(org.mifos.dto.domain.CustomerDto) MifosUser(org.mifos.security.MifosUser) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) DateTime(org.joda.time.DateTime) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) Money(org.mifos.framework.util.helpers.Money) CustomerBO(org.mifos.customers.business.CustomerBO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with RequestMapping

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;
}
Also used : HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with RequestMapping

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;
}
Also used : HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ApplicableCharge(org.mifos.dto.domain.ApplicableCharge) Map(java.util.Map) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with RequestMapping

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[] {});
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) OverdueCustomer(org.mifos.dto.domain.OverdueCustomer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with RequestMapping

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;
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanDetailDto(org.mifos.dto.domain.LoanDetailDto) ArrayList(java.util.ArrayList) ClientDescriptionDto(org.mifos.dto.domain.ClientDescriptionDto) Date(java.util.Date) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LastRepaymentDto(org.mifos.dto.domain.LastRepaymentDto) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) CustomerBO(org.mifos.customers.business.CustomerBO) GroupBO(org.mifos.customers.group.business.GroupBO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1622 ModelAndView (org.springframework.web.servlet.ModelAndView)401 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)375 ArrayList (java.util.ArrayList)177 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)175 HashMap (java.util.HashMap)147 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)124 IOException (java.io.IOException)83 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)75 Date (java.util.Date)73 ApiOperation (io.swagger.annotations.ApiOperation)68 User (org.hisp.dhis.user.User)59 HttpServletResponse (javax.servlet.http.HttpServletResponse)56 ResponseEntity (org.springframework.http.ResponseEntity)56 InputStream (java.io.InputStream)53 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)51 Locale (java.util.Locale)50 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)47 DBObject (com.mongodb.DBObject)46 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)45