Search in sources :

Example 1 with SavingsDepositDto

use of org.mifos.dto.domain.SavingsDepositDto in project head by mifos.

the class SavingsDepositWithdrawalAction method makePayment.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward makePayment(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    SavingsBO savedAccount = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    SavingsBO savings = savingsDao.findById(savedAccount.getAccountId());
    checkVersionMismatch(savedAccount.getVersionNo(), savings.getVersionNo());
    savings.setVersionNo(savedAccount.getVersionNo());
    SavingsDepositWithdrawalActionForm actionForm = (SavingsDepositWithdrawalActionForm) form;
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    Date trxnDate = getDateFromString(actionForm.getTrxnDate(), uc.getPreferredLocale());
    monthClosingServiceFacade.validateTransactionDate(trxnDate);
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (!savings.isTrxnDateValid(trxnDate, meetingDate, repaymentIndependentOfMeetingEnabled)) {
        throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
    }
    Long savingsId = Long.valueOf(savings.getAccountId());
    Long customerId = Long.valueOf(savings.getCustomer().getCustomerId());
    if (StringUtils.isNotBlank(actionForm.getCustomerId())) {
        customerId = Long.valueOf(actionForm.getCustomerId());
    }
    Locale preferredLocale = uc.getPreferredLocale();
    LocalDate dateOfDepositOrWithdrawalTransaction = new LocalDate(trxnDate);
    Double amount = Double.valueOf(actionForm.getAmount());
    Integer modeOfPayment = Integer.valueOf(actionForm.getPaymentTypeId());
    String receiptId = actionForm.getReceiptId();
    LocalDate dateOfReceipt = null;
    if (StringUtils.isNotBlank(actionForm.getReceiptDate())) {
        dateOfReceipt = new LocalDate(getDateFromString(actionForm.getReceiptDate(), preferredLocale));
    }
    try {
        Short trxnTypeId = Short.valueOf(actionForm.getTrxnTypeId());
        if (trxnTypeId.equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
            SavingsDepositDto savingsDeposit = new SavingsDepositDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
            this.savingsServiceFacade.deposit(savingsDeposit);
        } else if (trxnTypeId.equals(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue())) {
            SavingsWithdrawalDto savingsWithdrawal = new SavingsWithdrawalDto(savingsId, customerId, dateOfDepositOrWithdrawalTransaction, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
            this.savingsServiceFacade.withdraw(savingsWithdrawal);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessageKey(), e);
    }
    return mapping.findForward(ActionForwards.account_details_page.toString());
}
Also used : Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) SavingsDepositWithdrawalActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) AccountException(org.mifos.accounts.exceptions.AccountException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with SavingsDepositDto

use of org.mifos.dto.domain.SavingsDepositDto in project head by mifos.

the class SavingsServiceFacadeWebTier method fundTransfer.

@Override
public void fundTransfer(FundTransferDto fundTransferDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO targetAcc = this.savingsDao.findBySystemId(fundTransferDto.getTargetGlobalAccountNum());
    SavingsBO sourceAcc = this.savingsDao.findBySystemId(fundTransferDto.getSourceGlobalAccountNum());
    SavingsDepositDto depositDto;
    SavingsWithdrawalDto withdrawalDto;
    // prepare data
    try {
        depositDto = new SavingsDepositDto(targetAcc.getAccountId().longValue(), targetAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
        withdrawalDto = new SavingsWithdrawalDto(sourceAcc.getAccountId().longValue(), sourceAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
    } catch (PersistenceException ex) {
        throw new MifosRuntimeException(ex);
    }
    // transaction
    try {
        this.transactionHelper.startTransaction();
        PaymentDto deposit = deposit(depositDto, true);
        PaymentDto withdrawal = withdraw(withdrawalDto, true);
        // connect the two payments
        AccountPaymentEntity sourcePayment = sourceAcc.findPaymentById(withdrawal.getPaymentId());
        AccountPaymentEntity targetPayment = targetAcc.findPaymentById(deposit.getPaymentId());
        sourcePayment.setOtherTransferPayment(targetPayment);
        targetPayment.setOtherTransferPayment(sourcePayment);
        this.savingsDao.save(sourceAcc);
        this.savingsDao.save(targetAcc);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException ex) {
        this.transactionHelper.rollbackTransaction();
        throw ex;
    } catch (Exception ex) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(ex);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) UserContext(org.mifos.security.util.UserContext) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) PaymentDto(org.mifos.dto.domain.PaymentDto) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with SavingsDepositDto

use of org.mifos.dto.domain.SavingsDepositDto in project head by mifos.

the class K2RESTController method processSavingsDeposit.

private Map<String, String> processSavingsDeposit(SavingsBO savingsBO, String k2TransactionId, String mmSystemId, LocalDate transactionDate, BigDecimal amount, String currency) throws Exception {
    Integer paymentTypeId = null;
    List<PaymentTypeDto> savingsPaymentTypes = accountService.getSavingsPaymentTypes();
    for (PaymentTypeDto paymentTypeDtoIterator : savingsPaymentTypes) {
        if (paymentTypeDtoIterator.getName().equals(mmSystemId)) {
            paymentTypeId = paymentTypeDtoIterator.getValue().intValue();
        }
    }
    if (paymentTypeId == null || !savingsBO.getCurrency().getCurrencyCode().equals(currency)) {
        return invalidPayment();
    }
    Long accountId = savingsBO.getAccountId().longValue();
    Long customerId = savingsBO.getCustomer().getCustomerId().longValue();
    String receiptIdString = k2TransactionId;
    SavingsDepositDto savingsDeposit = new SavingsDepositDto(accountId, customerId, transactionDate, amount.doubleValue(), paymentTypeId, receiptIdString, transactionDate, Locale.UK);
    this.savingsServiceFacade.deposit(savingsDeposit);
    return accepted();
}
Also used : SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto)

Example 4 with SavingsDepositDto

use of org.mifos.dto.domain.SavingsDepositDto 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)

Aggregations

SavingsDepositDto (org.mifos.dto.domain.SavingsDepositDto)4 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3 SavingsWithdrawalDto (org.mifos.dto.domain.SavingsWithdrawalDto)3 AccountException (org.mifos.accounts.exceptions.AccountException)2 MifosUser (org.mifos.security.MifosUser)2 UserContext (org.mifos.security.util.UserContext)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 SavingsDepositWithdrawalActionForm (org.mifos.accounts.savings.struts.actionforms.SavingsDepositWithdrawalActionForm)1 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)1 ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)1 CustomerDto (org.mifos.dto.domain.CustomerDto)1