Search in sources :

Example 1 with SavingsClosureActionForm

use of org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm in project head by mifos.

the class SavingsClosureAction method close.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward close(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
    AccountPaymentEntity payment = (AccountPaymentEntity) SessionUtils.getAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
    SavingsBO savingsInSession = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = Long.valueOf(savingsInSession.getAccountId());
    SavingsBO savings = this.savingsDao.findById(savingsId);
    checkVersionMismatch(savingsInSession.getVersionNo(), savings.getVersionNo());
    savings.setUserContext(getUserContext(request));
    UserContext userContext = getUserContext(request);
    Long customerId = null;
    if (actionForm.getCustomerId() != null) {
        customerId = Long.valueOf(actionForm.getCustomerId());
    }
    LocalDate dateOfWithdrawal = new LocalDate(payment.getPaymentDate());
    Double amount = payment.getAmount().getAmountDoubleValue();
    Integer modeOfPayment = payment.getPaymentType().getId().intValue();
    String receiptId = payment.getReceiptNumber();
    LocalDate dateOfReceipt = null;
    if (payment.getReceiptDate() != null) {
        dateOfReceipt = new LocalDate(payment.getReceiptDate());
    }
    Locale preferredLocale = userContext.getPreferredLocale();
    SavingsWithdrawalDto closeAccount = new SavingsWithdrawalDto(savingsId, customerId, dateOfWithdrawal, amount, modeOfPayment, receiptId, dateOfReceipt, preferredLocale);
    this.savingsServiceFacade.closeSavingsAccount(savingsId, actionForm.getNotes(), closeAccount);
    SessionUtils.removeAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
    closeSavingsQuestionnaire.saveResponses(request, actionForm, savingsInSession.getAccountId());
    return mapping.findForward("close_success");
}
Also used : Locale(java.util.Locale) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with SavingsClosureActionForm

use of org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm in project head by mifos.

the class SavingsClosureAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
    actionForm.clearForm();
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = Long.valueOf(savings.getAccountId());
    savings = this.savingsDao.findById(savingsId);
    savings.setUserContext(uc);
    // NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
    // use within Tag library in jsp.
    new SavingsPersistence().initialize(savings);
    LocalDate accountCloseDate = new LocalDate();
    SavingsAccountClosureDto closureDetails = this.savingsServiceFacade.retrieveClosingDetails(savingsId, accountCloseDate);
    LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
    List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
    Money interestAmountDue = new Money(savings.getCurrency(), closureDetails.getInterestAmountAtClosure());
    Money endOfAccountBalance = new Money(savings.getCurrency(), closureDetails.getBalance());
    Date transactionDate = closureDetails.getClosureDate().toDateMidnight().toDate();
    Money withdrawalAmountAtClosure = endOfAccountBalance.add(interestAmountDue);
    AccountPaymentEntity payment = new AccountPaymentEntity(savings, withdrawalAmountAtClosure, null, null, null, transactionDate);
    actionForm.setAmount(withdrawalAmountAtClosure.toString());
    actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
    return mapping.findForward("load_success");
}
Also used : SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) SavingsAccountClosureDto(org.mifos.dto.domain.SavingsAccountClosureDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 3 with SavingsClosureActionForm

use of org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm in project head by mifos.

the class SavingsClosureAction method preview.

@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
    AccountPaymentEntity payment = (AccountPaymentEntity) SessionUtils.getAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
    AccountPaymentEntity accountPaymentEntity = null;
    Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
    if (actionForm.getReceiptDate() != null && actionForm.getReceiptDate() != "") {
        accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), new java.util.Date(DateUtils.getDateAsSentFromBrowser(actionForm.getReceiptDate()).getTime()), new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
    } else {
        if (actionForm.getPaymentTypeId() != null && !actionForm.getPaymentTypeId().equals("")) {
            if (!(actionForm.getPaymentTypeId().equals(""))) {
                accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
            } else {
                accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
            }
        } else {
            accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
        }
    }
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, accountPaymentEntity, request);
    return closeSavingsQuestionnaire.fetchAppliedQuestions(mapping, actionForm, request, ActionForwards.preview_success);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

LocalDate (org.joda.time.LocalDate)3 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)3 SavingsClosureActionForm (org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm)3 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)3 Date (java.util.Date)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)2 UserContext (org.mifos.security.util.UserContext)2 Locale (java.util.Locale)1 LegacyAcceptedPaymentTypeDao (org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao)1 SavingsPersistence (org.mifos.accounts.savings.persistence.SavingsPersistence)1 SavingsAccountClosureDto (org.mifos.dto.domain.SavingsAccountClosureDto)1 SavingsWithdrawalDto (org.mifos.dto.domain.SavingsWithdrawalDto)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 CloseSession (org.mifos.framework.util.helpers.CloseSession)1 Money (org.mifos.framework.util.helpers.Money)1