Search in sources :

Example 1 with SavingsAdjustmentReferenceDto

use of org.mifos.dto.screen.SavingsAdjustmentReferenceDto in project head by mifos.

the class SavingsApplyAdjustmentAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    clearActionForm(form);
    doCleanUp(request);
    UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    Long savingsId = Long.valueOf(savings.getAccountId());
    savings = this.savingsDao.findById(savingsId);
    savings.setUserContext(uc);
    String paymentIdParam = request.getParameter("paymentId");
    Integer paymentId;
    if (paymentIdParam == null) {
        AccountPaymentEntity payment = savings.getLastPmnt();
        paymentId = (payment == null) ? null : payment.getPaymentId();
    } else {
        paymentId = Integer.valueOf(paymentIdParam);
    }
    SavingsAdjustmentReferenceDto savingsAdjustmentDto = this.savingsServiceFacade.retrieveAdjustmentReferenceData(savingsId, paymentId);
    if (savingsAdjustmentDto.isDepositOrWithdrawal()) {
        AccountPaymentEntity payment = (paymentId == null) ? savings.findMostRecentPaymentByPaymentDate() : savings.findPaymentById(paymentId);
        AccountActionEntity accountAction = legacyMasterDao.getPersistentObject(AccountActionEntity.class, new SavingsHelper().getPaymentActionType(payment));
        Hibernate.initialize(savings.findMostRecentPaymentByPaymentDate().getAccountTrxns());
        SessionUtils.setAttribute(SavingsConstants.ACCOUNT_ACTION, accountAction, request);
        SessionUtils.setAttribute(SavingsConstants.CLIENT_NAME, savingsAdjustmentDto.getClientName(), request);
        SessionUtils.setAttribute(SavingsConstants.IS_LAST_PAYMENT_VALID, Constants.YES, request);
        SessionUtils.setAttribute(SavingsConstants.ADJUSTMENT_AMOUNT, payment.getAmount().getAmount(), request);
        SavingsApplyAdjustmentActionForm actionForm = (SavingsApplyAdjustmentActionForm) form;
        actionForm.setPaymentId(paymentId);
        actionForm.setTrxnDate(new LocalDate(payment.getPaymentDate()));
    } else {
        SessionUtils.setAttribute(SavingsConstants.IS_LAST_PAYMENT_VALID, Constants.NO, request);
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    return mapping.findForward("load_success");
}
Also used : SavingsAdjustmentReferenceDto(org.mifos.dto.screen.SavingsAdjustmentReferenceDto) UserContext(org.mifos.security.util.UserContext) SavingsHelper(org.mifos.accounts.savings.util.helpers.SavingsHelper) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsApplyAdjustmentActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsApplyAdjustmentActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with SavingsAdjustmentReferenceDto

use of org.mifos.dto.screen.SavingsAdjustmentReferenceDto in project head by mifos.

the class SavingsServiceFacadeWebTier method retrieveAdjustmentReferenceData.

@Override
public SavingsAdjustmentReferenceDto retrieveAdjustmentReferenceData(Long savingsId, Integer paymentId) {
    SavingsBO savings = savingsDao.findById(savingsId);
    AccountPaymentEntity payment = (paymentId == null) ? null : savings.findPaymentById(paymentId);
    String clientName = null;
    String amount = null;
    boolean depositOrWithdrawal = false;
    if (payment != null) {
        amount = payment.getAmount().toString();
        depositOrWithdrawal = payment.isSavingsDepositOrWithdrawal();
    }
    if (!savings.getCustomer().isClient() && payment != null) {
        CustomerBO customer = null;
        for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
            customer = accountTrxn.getCustomer();
            break;
        }
        if (customer != null && customer.isClient()) {
            clientName = customer.getDisplayName();
        }
    }
    return new SavingsAdjustmentReferenceDto(clientName, amount, depositOrWithdrawal);
}
Also used : SavingsAdjustmentReferenceDto(org.mifos.dto.screen.SavingsAdjustmentReferenceDto) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 SavingsAdjustmentReferenceDto (org.mifos.dto.screen.SavingsAdjustmentReferenceDto)2 LocalDate (org.joda.time.LocalDate)1 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)1 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)1 SavingsApplyAdjustmentActionForm (org.mifos.accounts.savings.struts.actionforms.SavingsApplyAdjustmentActionForm)1 SavingsHelper (org.mifos.accounts.savings.util.helpers.SavingsHelper)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 UserContext (org.mifos.security.util.UserContext)1