Search in sources :

Example 66 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping in project head by mifos.

the class LoanAccountRESTController method createLoanAccount.

@RequestMapping(value = "/account/loan/create", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createLoanAccount(@RequestBody String request) throws Throwable {
    ObjectMapper om = createLoanAccountMapping();
    Map<String, String> map = new HashMap<String, String>();
    CreationLoanAccountDto creationDetails = null;
    try {
        creationDetails = om.readValue(request, CreationLoanAccountDto.class);
    } catch (JsonMappingException e) {
        e.getCause();
    }
    loanValidator(creationDetails);
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    LoanCreationResultDto loanResult = null;
    LoanBO loanInfo = null;
    CreateLoanAccount loanAccount = createLoan(creationDetails);
    if (creationDetails.getGlim()) {
        List<GroupMemberAccountDto> memberAccounts = creationDetails.glimsAsGroupMemberAccountDto(creationDetails.getGlimAccounts());
        CreateGlimLoanAccount createGroupLoanAccount = new CreateGlimLoanAccount(memberAccounts, creationDetails.getLoanAmount(), loanAccount);
        loanResult = loanAccountServiceFacade.createGroupLoanWithIndividualMonitoring(createGroupLoanAccount, questionGroups, null);
        List<LoanBO> individuals = loanDao.findIndividualLoans(loanResult.getAccountId());
        for (int i = 0; i < individuals.size(); i++) {
            map.put("individualCustomer[" + i + "]", individuals.get(i).getCustomer().getDisplayName());
            map.put("individualAccount[" + i + "]", individuals.get(i).getGlobalAccountNum());
            map.put("individualAmmount[" + i + "]", individuals.get(i).getLoanAmount().toString());
        }
    } else {
        loanResult = loanAccountServiceFacade.createLoan(loanAccount, questionGroups, null);
    }
    loanInfo = loanDao.findByGlobalAccountNum(loanResult.getGlobalAccountNum());
    map.put("status", "success");
    map.put("accountNum", loanInfo.getGlobalAccountNum());
    map.put("GLIM", creationDetails.getGlim().toString());
    map.put("customer", loanInfo.getCustomer().getDisplayName());
    map.put("loanAmmount", loanInfo.getLoanAmount().toString());
    map.put("noOfInstallments", loanInfo.getNoOfInstallments().toString());
    map.put("externalId", loanInfo.getExternalId());
    return map;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) GroupMemberAccountDto(org.mifos.clientportfolio.newloan.applicationservice.GroupMemberAccountDto) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) LoanCreationResultDto(org.mifos.dto.screen.LoanCreationResultDto) CreateGlimLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateGlimLoanAccount) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CreationLoanAccountDto(org.mifos.application.servicefacade.CreationLoanAccountDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 67 with RequestMapping

use of org.springframework.web.bind.annotation.RequestMapping 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;
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) HashMap(java.util.HashMap) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) DateTime(org.joda.time.DateTime) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 68 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 69 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 70 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)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1964 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)459 ModelAndView (org.springframework.web.servlet.ModelAndView)413 ApiOperation (io.swagger.annotations.ApiOperation)305 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)234 ArrayList (java.util.ArrayList)197 HashMap (java.util.HashMap)155 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)124 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)124 IOException (java.io.IOException)97 ResponseEntity (org.springframework.http.ResponseEntity)92 Date (java.util.Date)83 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)80 DBObject (com.mongodb.DBObject)71 BasicDBObject (com.mongodb.BasicDBObject)67 InputStream (java.io.InputStream)66 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)64 HttpServletResponse (javax.servlet.http.HttpServletResponse)59 User (org.hisp.dhis.user.User)59 List (java.util.List)53