Search in sources :

Example 16 with LoanBO

use of org.mifos.accounts.loan.business.LoanBO in project head by mifos.

the class LoanRepaymentTag method generateGroupSchedule.

private List<AccountActionDateEntity> generateGroupSchedule(List<LoanBO> memberAccounts, LoanBO parent) {
    Money principal = new Money(Money.getDefaultCurrency(), 0.0), principalPaid = new Money(Money.getDefaultCurrency(), 0.0), interest = new Money(Money.getDefaultCurrency(), 0.0), interestPaid = new Money(Money.getDefaultCurrency(), 0.0), penalty = new Money(Money.getDefaultCurrency(), 0.0), penaltyPaid = new Money(Money.getDefaultCurrency(), 0.0), extraInterest = new Money(Money.getDefaultCurrency(), 0.0), extraInterestPaid = new Money(Money.getDefaultCurrency(), 0.0), miscFee = new Money(Money.getDefaultCurrency(), 0.0), miscFeePaid = new Money(Money.getDefaultCurrency(), 0.0), miscPenalty = new Money(Money.getDefaultCurrency(), 0.0), miscPenaltyPaid = new Money(Money.getDefaultCurrency(), 0.0);
    List<List<AccountActionDateEntity>> accActionList = new ArrayList<List<AccountActionDateEntity>>();
    for (LoanBO memberLoan : memberAccounts) {
        accActionList.add(new ArrayList<AccountActionDateEntity>(memberLoan.getAccountActionDates()));
    }
    List<AccountActionDateEntity> newGroupSchedule = copyAndSetToZeroSchedule(principal, principalPaid, interest, interestPaid, penalty, extraInterest, extraInterestPaid, miscFee, miscFeePaid, miscPenalty, penaltyPaid, miscPenaltyPaid, new ArrayList<AccountActionDateEntity>(parent.getAccountActionDates()));
    for (List<AccountActionDateEntity> accList : accActionList) {
        for (int i = 0; i < accList.size(); i++) {
            LoanScheduleEntity schedule = (LoanScheduleEntity) accList.get(i);
            LoanScheduleEntity newSchedule = (LoanScheduleEntity) newGroupSchedule.get(i);
            principal = principal.add(schedule.getPrincipal());
            newSchedule.setPrincipal(newSchedule.getPrincipal().add(principal));
            principal = new Money(Money.getDefaultCurrency(), 0.0);
            principalPaid = principalPaid.add(schedule.getPrincipalPaid());
            newSchedule.setPrincipalPaid(newSchedule.getPrincipalPaid().add(principalPaid));
            principalPaid = new Money(Money.getDefaultCurrency(), 0.0);
            interest = interest.add(schedule.getInterest());
            newSchedule.setInterest(newSchedule.getInterest().add(interest));
            interest = new Money(Money.getDefaultCurrency(), 0.0);
            interestPaid = interestPaid.add(schedule.getInterestPaid());
            newSchedule.setInterestPaid(newSchedule.getInterestPaid().add(interestPaid));
            interestPaid = new Money(Money.getDefaultCurrency(), 0.0);
            penalty = penalty.add(schedule.getPenalty());
            newSchedule.setPenalty(newSchedule.getPenalty().add(penaltyPaid));
            penalty = new Money(Money.getDefaultCurrency(), 0.0);
            penaltyPaid = penaltyPaid.add(schedule.getPenaltyPaid());
            newSchedule.setPenaltyPaid(newSchedule.getPenaltyPaid().add(penaltyPaid));
            penaltyPaid = new Money(Money.getDefaultCurrency(), 0.0);
            extraInterest = extraInterest.add(schedule.getExtraInterest());
            newSchedule.setExtraInterest(newSchedule.getExtraInterest().add(extraInterest));
            extraInterest = new Money(Money.getDefaultCurrency(), 0.0);
            extraInterestPaid = extraInterestPaid.add(schedule.getExtraInterestPaid());
            newSchedule.setExtraInterestPaid(newSchedule.getExtraInterestPaid().add(extraInterestPaid));
            extraInterestPaid = new Money(Money.getDefaultCurrency(), 0.0);
            miscFee = miscFee.add(schedule.getMiscFee());
            newSchedule.setMiscFee(newSchedule.getMiscFee().add(miscFee));
            miscFee = new Money(Money.getDefaultCurrency(), 0.0);
            miscFeePaid = miscFeePaid.add(schedule.getMiscFeePaid());
            newSchedule.setMiscFeePaid(newSchedule.getMiscFeePaid().add(miscFeePaid));
            miscFeePaid = new Money(Money.getDefaultCurrency(), 0.0);
            miscPenalty = miscPenalty.add(schedule.getMiscPenalty());
            newSchedule.setMiscPenalty(newSchedule.getMiscPenalty().add(miscPenalty));
            miscPenalty = new Money(Money.getDefaultCurrency(), 0.0);
            miscPenaltyPaid = miscPenaltyPaid.add(schedule.getMiscPenaltyPaid());
            newSchedule.setMiscPenaltyPaid(newSchedule.getMiscPenaltyPaid().add(miscPenaltyPaid));
            miscPenaltyPaid = new Money(Money.getDefaultCurrency(), 0.0);
        }
    }
    return newGroupSchedule;
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with LoanBO

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());
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) GroupIndividualLoanDto(org.mifos.dto.domain.GroupIndividualLoanDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) BigDecimal(java.math.BigDecimal) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 18 with LoanBO

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);
    }
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) LoanPenaltyScheduleEntity(org.mifos.accounts.loan.business.LoanPenaltyScheduleEntity)

Example 19 with LoanBO

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());
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) LegacyLoanDao(org.mifos.accounts.loan.persistance.LegacyLoanDao) Test(org.junit.Test)

Example 20 with LoanBO

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());
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) Test(org.junit.Test)

Aggregations

LoanBO (org.mifos.accounts.loan.business.LoanBO)215 ArrayList (java.util.ArrayList)76 Test (org.junit.Test)62 Money (org.mifos.framework.util.helpers.Money)60 UserContext (org.mifos.security.util.UserContext)45 MifosRuntimeException (org.mifos.core.MifosRuntimeException)42 Date (java.util.Date)37 AccountException (org.mifos.accounts.exceptions.AccountException)35 AccountBO (org.mifos.accounts.business.AccountBO)34 MifosUser (org.mifos.security.MifosUser)33 BigDecimal (java.math.BigDecimal)30 HashMap (java.util.HashMap)28 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)26 LocalDate (org.joda.time.LocalDate)23 PaymentData (org.mifos.accounts.util.helpers.PaymentData)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 ServiceException (org.mifos.framework.exceptions.ServiceException)19 BusinessRuleException (org.mifos.service.BusinessRuleException)19 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)18