Search in sources :

Example 61 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class ApplyAdjustment method loadAdjustment.

@TransactionDemarcate(joinToken = true)
public ActionForward loadAdjustment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
    request.setAttribute("method", "loadAdjustment");
    UserContext userContext = getUserContext(request);
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
    AccountPaymentEntity payment = null;
    if (request.getParameter(Constants.ADJ_TYPE_KEY) != null && request.getParameter(Constants.ADJ_TYPE_KEY).equals(Constants.ADJ_SPECIFIC)) {
        Integer paymentId = appAdjustActionForm.getPaymentId();
        payment = accnt.findPaymentById(paymentId);
        AccountPaymentEntity previous = null;
        AccountPaymentEntity next = null;
        boolean getPrevious = false;
        for (AccountPaymentEntity p : accnt.getAccountPayments()) {
            if (!p.getAmount().equals(Money.zero())) {
                if (getPrevious) {
                    previous = p;
                    break;
                } else if (p.getPaymentId().equals(payment.getPaymentId())) {
                    getPrevious = true;
                } else {
                    next = p;
                }
            }
        }
        Date previousPaymentDate = (previous == null) ? null : previous.getPaymentDate();
        Date nextPaymentDate = (next == null) ? null : next.getPaymentDate();
        appAdjustActionForm.setPreviousPaymentDate(previousPaymentDate);
        appAdjustActionForm.setNextPaymentDate(nextPaymentDate);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, payment.getAmount().getAmount(), request);
        Short transferPaymentTypeId = legacyAcceptedPaymentTypeDao.getSavingsTransferId();
        if (payment.getPaymentType().getId().equals(transferPaymentTypeId)) {
            List<ListItem<Short>> paymentTypeList = this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId());
            for (Iterator<ListItem<Short>> it = paymentTypeList.iterator(); it.hasNext(); ) {
                ListItem<Short> listItem = it.next();
                if (!listItem.getId().equals(transferPaymentTypeId)) {
                    it.remove();
                }
            }
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, paymentTypeList, request);
        } else {
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
        }
    } else {
        SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
        payment = accnt.getLastPmntToBeAdjusted();
        appAdjustActionForm.setPaymentId(null);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, accnt.getLastPmntAmntToBeAdjusted(), request);
    }
    if (accnt.isParentGroupLoanAccount()) {
        SessionUtils.setAttribute(Constants.TYPE_OF_GROUP_LOAN, "parentAcc", request);
    } else if (accnt.isGroupLoanAccountMember()) {
        appAdjustActionForm.setGroupLoanMember(Boolean.TRUE);
    }
    populateForm(appAdjustActionForm, payment);
    return mapping.findForward("loadadjustment_success");
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ListItem(org.mifos.application.servicefacade.ListItem) Date(java.util.Date) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 62 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class ApplyAdjustment method loadAdjustmentWhenObligationMet.

/*
     * This method do the same thing as loadAdjustment, but added to allow
     * handling permission : can adjust payment when account is closed
     * obligation met
     */
@TransactionDemarcate(joinToken = true)
public ActionForward loadAdjustmentWhenObligationMet(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
    request.setAttribute("method", "loadAdjustmentWhenObligationMet");
    AccountPaymentEntity payment = null;
    if (request.getParameter(Constants.ADJ_TYPE_KEY) != null && request.getParameter(Constants.ADJ_TYPE_KEY).equals(Constants.ADJ_SPECIFIC)) {
        Integer paymentId = appAdjustActionForm.getPaymentId();
        payment = accnt.findPaymentById(paymentId);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, payment.getAmount().getAmount(), request);
    } else {
        payment = accnt.getLastPmntToBeAdjusted();
        appAdjustActionForm.setPaymentId(null);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, accnt.getLastPmntAmntToBeAdjusted(), request);
    }
    appAdjustActionForm.setAdjustData(false);
    populateForm(appAdjustActionForm, payment);
    return mapping.findForward("loadadjustment_success");
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 63 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class LoanBOTest method repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest.

@Test
public void repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest() throws PersistenceException {
    final LegacyLoanDao legacyLoanDao = mock(LegacyLoanDao.class);
    final CustomerBO customerBO = mock(CustomerBO.class);
    final LoanSummaryEntity loanSummaryEntity = mock(LoanSummaryEntity.class);
    LoanBO loanBO = new LoanBO() {

        @Override
        public boolean isDecliningBalanceInterestRecalculation() {
            return true;
        }

        @Override
        public LegacyLoanDao getlegacyLoanDao() {
            return legacyLoanDao;
        }

        @Override
        public CustomerBO getCustomer() {
            return customerBO;
        }

        @Override
        public LoanSummaryEntity getLoanSummary() {
            return loanSummaryEntity;
        }

        @Override
        public MifosCurrency getCurrency() {
            return rupee;
        }
    };
    AccountActionTypes accountActionTypes = AccountActionTypes.LOAN_REPAYMENT;
    AccountActionEntity accountActionEntity = mock(AccountActionEntity.class);
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntityBuilder().with(loanBO).build();
    PersonnelBO user = new PersonnelBO();
    Money extraInterestDue = new Money(rupee, "0.98");
    Money interest = new Money(rupee, "10");
    Money interestDue = new Money(rupee, "0");
    when(legacyLoanDao.getPersistentObject(AccountActionEntity.class, accountActionTypes.getValue())).thenReturn(accountActionEntity);
    when(loanScheduleEntity.getPrincipalDue()).thenReturn(new Money(rupee, "1000"));
    when(loanScheduleEntity.getTotalFeeDueWithMiscFeeDue()).thenReturn(new Money(rupee, "10"));
    when(loanScheduleEntity.getPenaltyDue()).thenReturn(new Money(rupee, "10"));
    when(loanScheduleEntity.getPenalty()).thenReturn(new Money(rupee, "100"));
    when(loanScheduleEntity.getExtraInterestDue()).thenReturn(extraInterestDue);
    when(loanScheduleEntity.getExtraInterestPaid()).thenReturn(extraInterestDue);
    when(loanScheduleEntity.getInterest()).thenReturn(interest);
    loanBO.repayInstallmentWithInterestWaiver(loanScheduleEntity, accountPaymentEntity, "", accountActionTypes, user);
    Set<AccountTrxnEntity> accountTrxns = accountPaymentEntity.getAccountTrxns();
    AccountTrxnEntity accountTrxnEntity = accountTrxns.toArray(new AccountTrxnEntity[accountTrxns.size()])[0];
    LoanTrxnDetailEntity loanTrxnDetailEntity = (LoanTrxnDetailEntity) accountTrxnEntity;
    assertThat(loanTrxnDetailEntity.getInterestAmount().getAmount().doubleValue(), is(0.98));
    CalculatedInterestOnPayment calculatedInterestOnPayment = loanTrxnDetailEntity.getCalculatedInterestOnPayment();
    assertNotNull(calculatedInterestOnPayment);
    assertThat(calculatedInterestOnPayment.getExtraInterestPaid(), is(extraInterestDue));
    assertThat(calculatedInterestOnPayment.getInterestDueTillPaid(), is(interestDue));
    assertThat(calculatedInterestOnPayment.getOriginalInterest(), is(interest));
    Mockito.verify(loanScheduleEntity).makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY, interestDue, accountPaymentEntity.getPaymentDate());
}
Also used : AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) Money(org.mifos.framework.util.helpers.Money) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerBO(org.mifos.customers.business.CustomerBO) LegacyLoanDao(org.mifos.accounts.loan.persistance.LegacyLoanDao) Test(org.junit.Test)

Example 64 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class ScheduleMapperTest method shouldMapScheduleToLoanScheduleEntity.

@Test
public void shouldMapScheduleToLoanScheduleEntity() throws PersistenceException {
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loanBO, null, null, null, null, null);
    LoanScheduleEntity scheduleEntityForPopulateTestInput = getLoanScheduleEntityForPopulateTestInput();
    Set<LoanScheduleEntity> loanScheduleEntities = new LinkedHashSet<LoanScheduleEntity>();
    loanScheduleEntities.add(scheduleEntityForPopulateTestInput);
    when(loanBO.getLoanScheduleEntities()).thenReturn(loanScheduleEntities);
    when(loanBO.getlegacyLoanDao()).thenReturn(legacyLoanDao);
    Date paymentDate = getDate(24, 11, 2010);
    Schedule schedule = getScheduleWithSingleInstallment();
    scheduleMapper.populatePaymentDetails(schedule, loanBO, paymentDate, personnelBO, accountPaymentEntity);
    assertCalculatedInterestOnPayment(accountPaymentEntity);
    assertThat(getLoanScheduleEntity(paymentDate), new LoanScheduleEntityMatcher(scheduleEntityForPopulateTestInput));
    verify(loanBO, times(1)).getLoanScheduleEntities();
    verify(loanBO, times(1)).getlegacyLoanDao();
    verify(loanBO, times(1)).recordSummaryAndPerfHistory(anyBoolean(), Matchers.<PaymentAllocation>any());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LoanScheduleEntityMatcher(org.mifos.accounts.loan.business.matchers.LoanScheduleEntityMatcher) Schedule(org.mifos.accounts.loan.schedule.domain.Schedule) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) TestUtils.getDate(org.mifos.framework.TestUtils.getDate) Test(org.junit.Test)

Example 65 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class SavingsDaoHibernate method prepareForInterestRecalculation.

@Override
public void prepareForInterestRecalculation(SavingsBO savingsAccount, Date fromDate) {
    List<AccountPaymentEntity> paymentsForRemoval = savingsAccount.getInterestPostingPaymentsForRemoval(fromDate);
    this.save(savingsAccount);
    for (AccountPaymentEntity payment : paymentsForRemoval) {
        this.baseDao.delete(payment);
    }
    List<SavingsActivityEntity> activitesForRemoval = savingsAccount.getInterestPostingActivitesForRemoval(fromDate);
    for (SavingsActivityEntity activity : activitesForRemoval) {
        this.baseDao.delete(activity);
    }
}
Also used : AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsActivityEntity(org.mifos.accounts.savings.business.SavingsActivityEntity)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)113 Money (org.mifos.framework.util.helpers.Money)56 Date (java.util.Date)43 LocalDate (org.joda.time.LocalDate)41 Test (org.junit.Test)36 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)34 AccountException (org.mifos.accounts.exceptions.AccountException)30 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)24 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)23 UserContext (org.mifos.security.util.UserContext)23 ArrayList (java.util.ArrayList)22 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)22 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 PaymentData (org.mifos.accounts.util.helpers.PaymentData)18 CustomerBO (org.mifos.customers.business.CustomerBO)18 AccountBO (org.mifos.accounts.business.AccountBO)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 BigDecimal (java.math.BigDecimal)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 Date (java.sql.Date)13