use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.
the class AccountApplyGroupPaymentAction method load.
@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
UserContext userContext = getUserContext(request);
AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
actionForm.setReceiptDate(null);
actionForm.setReceiptId(null);
actionForm.setPaymentTypeId(null);
actionForm.setTransactionDate(DateUtils.makeDateAsSentFromBrowser());
actionForm.setPrintReceipt(false);
actionForm.setTruePrintReceipt(false);
final AccountReferenceDto accountReferenceDto = new AccountReferenceDto(Integer.valueOf(actionForm.getAccountId()));
AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountReferenceDto.getAccountId(), request.getParameter(Constants.INPUT), userContext.getLocaleId(), new UserReferenceDto(userContext.getId()), DateUtils.getCurrentJavaDateTime());
setValuesInSession(request, actionForm, accountPaymentDto);
actionForm.setLastPaymentDate(accountPaymentDto.getLastPaymentDate());
actionForm.setAmount(accountPaymentDto.getTotalPaymentDue());
actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
LoanBO loan = loanDao.findById(accountReferenceDto.getAccountId());
if (loan.isGroupLoanAccountParent()) {
SessionUtils.setAttribute(LOAN_TYPE, PARENT, request);
} else if (loan.isGroupLoanAccountMember()) {
SessionUtils.setAttribute(LOAN_TYPE, MEMBER, request);
}
List<LoanBO> memberInfos = getMemberAccountsInformation(actionForm.getAccountId());
SessionUtils.setCollectionAttribute("memberInfos", memberInfos, request);
if (memberInfos.size() > 0) {
actionForm.getIndividualValues().clear();
List<GroupIndividualLoanDto> memberAccounts = groupLoanService.getMemberLoansAndDefaultPayments(Integer.valueOf(actionForm.getAccountId()), new BigDecimal(actionForm.getAmount()));
for (int i = 0; i < memberAccounts.size(); i++) {
actionForm.getIndividualValues().put(memberAccounts.get(i).getAccountId(), String.valueOf(memberAccounts.get(i).getDefaultAmount().doubleValue()));
}
}
return mapping.findForward(ActionForwards.load_success.toString());
}
use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.
the class ApplyPenaltyToLoanAccountsHelper method execute.
@Override
public void execute(final long timeInMillis) throws BatchJobException {
setCurrentDates(timeInMillis);
List<String> errorList = new ArrayList<String>();
List<LoanBO> loanAccounts;
try {
loanAccounts = getLoanAccounts();
} catch (Exception e) {
throw new BatchJobException(e);
}
if (loanAccounts != null && !loanAccounts.isEmpty()) {
Integer loanAccountId = null;
try {
for (LoanBO loanAccount : loanAccounts) {
loanAccountId = loanAccount.getAccountId();
List<AccountPenaltiesEntity> penaltyEntities = new ArrayList<AccountPenaltiesEntity>(loanAccount.getAccountPenalties());
for (AccountPenaltiesEntity penaltyEntity : penaltyEntities) {
List<LoanScheduleEntity> lateInstallments = loanAccount.getDetailsOfLateInstallmentsPeriod(new LocalDate(penaltyEntity.getCreatedDate()), currentLocalDate);
for (LoanScheduleEntity entity : lateInstallments) {
//check grace period for installment period type
if (penaltyEntity.getPenalty().getPeriodType().getPenaltyPeriod() == PenaltyPeriod.INSTALLMENTS && penaltyEntity.hasPeriodType()) {
if (lateInstallments.get(0).getInstallmentId().equals(entity.getInstallmentId()) && checkGracePeriodTypeInstallments(lateInstallments, penaltyEntity.getPenalty().getPeriodDuration())) {
continue;
}
} else //check grace period for daily period type
if (penaltyEntity.getPenalty().getPeriodType().getPenaltyPeriod() == PenaltyPeriod.DAYS && penaltyEntity.hasPeriodType()) {
if (checkGracePeriodTypeDays(entity, penaltyEntity.getPenalty().getPeriodDuration())) {
continue;
}
}
LoanPenaltyScheduleEntity penaltySchedule = entity.getPenaltyScheduleEntity(penaltyEntity.getPenalty().getPenaltyId());
if (checkPeriod(penaltyEntity, new LocalDate(entity.getActionDate().getTime())) || (penaltySchedule != null && penaltySchedule.isOn(currentLocalDate))) {
continue;
}
if (penaltyEntity.isAmountPenalty()) {
addAmountPenalty(penaltyEntity, loanAccount, entity);
} else {
addRatePenalty(penaltyEntity, loanAccount, entity);
}
}
}
}
} catch (Exception e) {
if (loanAccountId != null) {
getLogger().error(String.format("ApplyPenaltyToLoanAccountsTask execute failed with exception %s: %s at loan account %s", e.getClass().getName(), e.getMessage(), loanAccountId.toString()), e);
errorList.add(loanAccountId.toString());
}
StaticHibernateUtil.rollbackTransaction();
} finally {
StaticHibernateUtil.closeSession();
}
}
if (!errorList.isEmpty()) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
}
use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.
the class LegacyLoanDaoIntegrationTest method testFindIndividualLoans.
@Test
public void testFindIndividualLoans() throws Exception {
LegacyLoanDao loanPersistance = legacyLoanDao;
List<LoanBO> listLoanBO = loanPersistance.findIndividualLoans(loanAccount.getAccountId().toString());
Assert.assertEquals(0, listLoanBO.size());
}
use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.
the class LoanAccountActionStrutsTest method testGetForCancelledLoanAccount.
@Test
public void testGetForCancelledLoanAccount() throws Exception {
setMifosUserFromContext();
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
Date startDate = new Date(System.currentTimeMillis());
accountBO = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 1);
PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
accountBO.changeStatus(AccountState.LOAN_CANCELLED, AccountStateFlag.LOAN_WITHDRAW.getValue(), "status changed", loggedInUser);
accountBO.update();
StaticHibernateUtil.flushSession();
LoanBO loan = (LoanBO) accountBO;
setRequestPathInfo("/loanAccountAction.do");
addRequestParameter("method", "get");
addRequestParameter("globalAccountNum", loan.getGlobalAccountNum());
actionPerform();
verifyForward("get_success");
Assert.assertEquals(0, loan.getPerformanceHistory().getNoOfPayments().intValue());
// Assert.assertEquals(((LoanBO) accountBO).getTotalAmountDue().getAmountDoubleValue(), 212.0);
modifyActionDateForFirstInstallment();
Assert.assertEquals("Total no. of notes should be 6", 6, accountBO.getAccountNotes().size());
// LoanInformationDto loanInformationDto = retrieveLoanInformationDtoFromSession();
// Assert.assertEquals("Total no. of recent notes should be 3", 3, (loanInformationDto.getRecentAccountNotes().size()));
Assert.assertEquals("Total no. of flags should be 1", 1, accountBO.getAccountFlags().size());
}
use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.
the class LoanAccountActionStrutsTest method testShouldPopulateClientDetailsFromLoan.
@Test
public void testShouldPopulateClientDetailsFromLoan() throws Exception {
ClientBO clientMock1 = createMock(ClientBO.class);
expect(clientMock1.getCustomerId()).andReturn(1).anyTimes();
expect(clientMock1.getDisplayName()).andReturn("client 1");
ClientBO clientMock2 = createMock(ClientBO.class);
expect(clientMock2.getCustomerId()).andReturn(2).anyTimes();
expect(clientMock2.getDisplayName()).andReturn("client 2");
LoanBO loanMock = createMock(LoanBO.class);
expect(loanMock.getCustomer()).andReturn(clientMock1).anyTimes();
expect(loanMock.getBusinessActivityId()).andReturn(3);
expect(loanMock.getLoanAmount()).andReturn(new Money(getCurrency(), "100")).anyTimes();
LoanAccountDetailsDto clientDetails1 = new LoanAccountDetailsDto();
clientDetails1.setClientId("1");
clientDetails1.setClientName("client 1");
clientDetails1.setBusinessActivity("3");
clientDetails1.setLoanAmount("100.0");
LoanAccountDetailsDto clientDetails2 = new LoanAccountDetailsDto();
clientDetails2.setClientId("2");
clientDetails2.setClientName("client 2");
replay(clientMock1, clientMock2, loanMock);
List<LoanAccountDetailsDto> clientDetails = new LoanAccountAction().populateClientDetailsFromLoan(Arrays.asList(clientMock1, clientMock2), Arrays.asList(loanMock), new ArrayList<ValueListElement>());
Assert.assertEquals(Arrays.asList(clientDetails1, clientDetails2), clientDetails);
verify(clientMock1, clientMock2, loanMock);
}
Aggregations