Search in sources :

Example 36 with LoanBO

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

the class BulkEntryPersistenceIntegrationTest method testSuccessfulApplyPayment.

@Test
public void testSuccessfulApplyPayment() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    Date startDate = new Date(System.currentTimeMillis());
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
    account = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering);
    StaticHibernateUtil.flushSession();
    account = legacyAccountDao.getAccount(account.getAccountId());
    Assert.assertEquals(((LoanBO) account).getLoanOffering().getPrdOfferingName(), "Loan");
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.add(account.getAccountActionDates().iterator().next());
    Date currentDate = startDate;
    PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney("100.0"), null, account.getPersonnel(), "423423", Short.valueOf("1"), currentDate, currentDate);
    try {
        IntegrationTestObjectMother.applyAccountPayment(account, paymentData);
        Assert.assertEquals(((LoanBO) account).getLoanSummary().getFeesPaid(), TestUtils.createMoney("100.0"));
    } catch (Exception e) {
        e.printStackTrace();
    }
    account.getAccountPayments().clear();
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) ArrayList(java.util.ArrayList) Date(java.util.Date) AccountException(org.mifos.accounts.exceptions.AccountException) Test(org.junit.Test)

Example 37 with LoanBO

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

the class BulkEntryPersistenceIntegrationTest method testFailureApplyPayment.

@Test
public void testFailureApplyPayment() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
    account = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering);
    StaticHibernateUtil.flushSession();
    account = legacyAccountDao.getAccount(account.getAccountId());
    Assert.assertEquals(((LoanBO) account).getLoanOffering().getPrdOfferingName(), "Loan");
    for (AccountActionDateEntity actionDate : account.getAccountActionDates()) {
        if (actionDate.getInstallmentId().equals(Short.valueOf("1"))) {
            actionDate.setPaymentStatus(PaymentStatus.PAID);
        }
    }
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.addAll(account.getAccountActionDates());
    PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney("3000.0"), null, account.getPersonnel(), "423423", Short.valueOf("1"), startDate, startDate);
    try {
        account.applyPayment(paymentData);
        Assert.fail("should throw exception");
    } catch (AccountException be) {
        Assert.assertNotNull(be);
        Assert.assertEquals(be.getKey(), "errors.makePayment");
        Assert.assertTrue(true);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 38 with LoanBO

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

the class BulkEntryPersistenceIntegrationTest method testSuccessfulLoanUpdate.

@Test
public void testSuccessfulLoanUpdate() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
    account = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering);
    StaticHibernateUtil.flushSession();
    account = legacyAccountDao.getAccount(account.getAccountId());
    Assert.assertEquals(((LoanBO) account).getLoanOffering().getPrdOfferingName(), "Loan");
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.add(account.getAccountActionDates().iterator().next());
    Date currentDate = startDate;
    PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney("100.0"), null, account.getPersonnel(), "423423", Short.valueOf("1"), currentDate, currentDate);
    IntegrationTestObjectMother.applyAccountPayment(account, paymentData);
    Assert.assertEquals(((LoanBO) account).getLoanSummary().getFeesPaid(), TestUtils.createMoney("100.0"));
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 39 with LoanBO

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

the class AccountAppAction method removePenalties.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward removePenalties(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    Integer accountId = getIntegerValue(request.getParameter("accountId"));
    Short penaltyId = getShortValue(request.getParameter("penaltyId"));
    AccountBO accountBO = getAccountBusinessService().getAccount(accountId);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
    if (accountBO instanceof LoanBO) {
        this.loanAccountServiceFacade.removeLoanPenalty(accountId, penaltyId);
    }
    String fromPage = request.getParameter(CenterConstants.FROM_PAGE);
    StringBuilder forward = new StringBuilder();
    forward = forward.append(AccountConstants.REMOVE + "_" + fromPage + "_" + AccountConstants.CHARGES);
    if (fromPage != null) {
        return mapping.findForward(forward.toString());
    }
    return mapping.findForward(AccountConstants.REMOVE_SUCCESS);
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 40 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)

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