Search in sources :

Example 36 with CustomerDto

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;
}
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) LocalDate(org.joda.time.LocalDate) 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 37 with CustomerDto

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;
}
Also used : Money(org.mifos.framework.util.helpers.Money) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) HashMap(java.util.HashMap) CustomerDto(org.mifos.dto.domain.CustomerDto) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) MifosUser(org.mifos.security.MifosUser) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) DateTime(org.joda.time.DateTime)

Example 38 with CustomerDto

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;
}
Also used : GuarantyEntity(org.mifos.accounts.loan.business.GuarantyEntity) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) CustomerDto(org.mifos.dto.domain.CustomerDto)

Aggregations

CustomerDto (org.mifos.dto.domain.CustomerDto)38 ArrayList (java.util.ArrayList)15 PersonnelDto (org.mifos.dto.domain.PersonnelDto)12 Test (org.junit.Test)11 OfficeDetailsDto (org.mifos.dto.domain.OfficeDetailsDto)10 MifosRuntimeException (org.mifos.core.MifosRuntimeException)7 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)7 DateTime (org.joda.time.DateTime)6 CustomerBO (org.mifos.customers.business.CustomerBO)6 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)6 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)6 MifosUser (org.mifos.security.MifosUser)6 UserContext (org.mifos.security.util.UserContext)6 Date (java.util.Date)5 LocalDate (org.joda.time.LocalDate)5 Money (org.mifos.framework.util.helpers.Money)5 HashMap (java.util.HashMap)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)4 BigDecimal (java.math.BigDecimal)3