Search in sources :

Example 11 with AccountPaymentEntity

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

the class WebTierAccountServiceFacadeTest method shouldAdjustBackdatedPaymentMadeOnAccountIfAllowed.

@Test
public void shouldAdjustBackdatedPaymentMadeOnAccountIfAllowed() throws ServiceException, AccountException, PersistenceException {
    String globalAccountNum = "123";
    String adjustmentNote = "note";
    Short personnelId = Short.valueOf("1");
    PersonnelBO personnelBO = mock(PersonnelBO.class);
    PersonnelBO loanOfficer = mock(PersonnelBO.class);
    Date paymentDate = TestUtils.getDate(10, 10, 2010);
    new DateTimeService().setCurrentDateTime(TestUtils.getDateTime(11, 10, 2010));
    Short recordOfficeId = new Short("1");
    Short recordLoanOfficer = new Short("1");
    Integer paymentId = 1;
    AccountPaymentEntity lastPmntToBeAdjusted = mock(AccountPaymentEntity.class);
    when(loanBO.getLastPmntToBeAdjusted()).thenReturn(lastPmntToBeAdjusted);
    when(loanBO.getOfficeId()).thenReturn(recordOfficeId);
    when(loanBO.getPersonnel()).thenReturn(loanOfficer);
    when(loanBO.getUserContext()).thenReturn(userContext);
    when(loanBO.findPaymentById(paymentId)).thenReturn(lastPmntToBeAdjusted);
    when(loanOfficer.getPersonnelId()).thenReturn(recordOfficeId);
    when(lastPmntToBeAdjusted.getPaymentDate()).thenReturn(paymentDate);
    when(lastPmntToBeAdjusted.getPaymentId()).thenReturn(paymentId);
    when(accountBusinessService.findBySystemId(globalAccountNum)).thenReturn(loanBO);
    when(personnelPersistence.findPersonnelById(personnelId)).thenReturn(personnelBO);
    accountServiceFacade.applyAdjustment(globalAccountNum, adjustmentNote, personnelId);
    verify(accountBusinessService, atLeastOnce()).findBySystemId(globalAccountNum);
    verify(personnelPersistence).findPersonnelById(personnelId);
    verify(loanBO).adjustLastPayment(adjustmentNote, personnelBO);
    verify(loanBO, atLeastOnce()).setUserContext(userContext);
    verify(legacyAccountDao).createOrUpdate(loanBO);
    verify(transactionHelper).startTransaction();
    verify(transactionHelper).commitTransaction();
    verify(accountBusinessService).checkPermissionForAdjustmentOnBackDatedPayments(paymentDate, userContext, recordOfficeId, recordLoanOfficer);
    verify(lastPmntToBeAdjusted, times(2)).getPaymentDate();
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Matchers.anyString(org.mockito.Matchers.anyString) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) Test(org.junit.Test)

Example 12 with AccountPaymentEntity

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

the class SavingsClosureActionStrutsTest method testSuccessfullCloseAccount.

@Test
public void testSuccessfullCloseAccount() throws Exception {
    createInitialObjects();
    createClients();
    savingsOffering = helper.createSavingsOffering("asfddsf", "213a");
    savings = helper.createSavingsAccount("000X00000000017", savingsOffering, group, AccountStates.SAVINGS_ACC_APPROVED, userContext);
    SavingBOTestUtils.setActivationDate(savings, helper.getDate("20/05/2006"));
    PersonnelBO createdBy = legacyPersonnelDao.getPersonnel(userContext.getId());
    AccountPaymentEntity payment1 = helper.createAccountPaymentToPersist(savings, TestUtils.createMoney("1000.0"), TestUtils.createMoney("1000.0"), helper.getDate("30/05/2006"), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), savings, createdBy, group);
    AccountTestUtils.addAccountPayment(payment1, savings);
    savings.update();
    StaticHibernateUtil.flushSession();
    Money balanceAmount = TestUtils.createMoney("1500.0");
    AccountPaymentEntity payment2 = helper.createAccountPaymentToPersist(savings, TestUtils.createMoney("500.0"), balanceAmount, helper.getDate("15/06/2006"), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), savings, createdBy, group);
    AccountTestUtils.addAccountPayment(payment2, savings);
    savings.update();
    StaticHibernateUtil.flushSession();
    Money interestAmount = TestUtils.createMoney("40");
    SavingBOTestUtils.setInterestToBePosted(savings, interestAmount);
    SavingBOTestUtils.setBalance(savings, balanceAmount);
    savings.update();
    StaticHibernateUtil.flushSession();
    savings = savingsDao.findById(savings.getAccountId());
    savings.setUserContext(userContext);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "load");
    actionPerform();
    verifyForward("load_success");
    addRequestParameter("receiptId", "101");
    addRequestParameter("receiptDate", DateUtils.makeDateAsSentFromBrowser());
    addRequestParameter("paymentTypeId", "1");
    addRequestParameter("customerId", "1");
    addRequestParameter("notes", "closing account");
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "preview");
    actionPerform();
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "close");
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward("close_success");
    savings = TestObjectFactory.getObject(SavingsBO.class, savings.getAccountId());
    Assert.assertEquals(new Money(getCurrency()), savings.getSavingsBalance());
    Assert.assertEquals(AccountState.SAVINGS_CLOSED.getValue(), savings.getAccountState().getId());
}
Also used : Money(org.mifos.framework.util.helpers.Money) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Test(org.junit.Test)

Example 13 with AccountPaymentEntity

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

the class SavingsClosureActionStrutsTest method testSuccessfullPreviewWithBlankPaymentId.

@Test
public void testSuccessfullPreviewWithBlankPaymentId() throws Exception {
    AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
    addRequestParameter("receiptId", "101");
    addRequestParameter("receiptDate", "");
    addRequestParameter("paymentTypeId", "");
    addRequestParameter("customerId", "1");
    addRequestParameter("notes", "notes");
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "preview");
    actionPerform();
    verifyNoActionErrors();
    verifyForward("preview_success");
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) Test(org.junit.Test)

Example 14 with AccountPaymentEntity

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

the class SavingsClosureActionStrutsTest method testSuccessfullPreview.

@Test
public void testSuccessfullPreview() throws Exception {
    AccountPaymentEntity payment = new AccountPaymentEntity(null, new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "500"), null, null, null, new Date(System.currentTimeMillis()));
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
    addRequestParameter("receiptId", "101");
    addRequestParameter("receiptDate", DateUtils.makeDateAsSentFromBrowser());
    addRequestParameter("paymentTypeId", "1");
    addRequestParameter("customerId", "1");
    addRequestParameter("notes", "notes");
    setRequestPathInfo("/savingsClosureAction.do");
    addRequestParameter("method", "preview");
    actionPerform();
    verifyNoActionErrors();
    verifyForward("preview_success");
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.util.Date) Test(org.junit.Test)

Example 15 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity 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)

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