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();
}
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());
}
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");
}
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");
}
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");
}
Aggregations