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