use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class LoanBOTestUtils method createLoanRepaymentSchedule.
public LoanScheduleEntity[] createLoanRepaymentSchedule() throws Exception {
Date startDate = new Date(System.currentTimeMillis());
AccountBO accountBO = getLoanAccountWithMiscFeeAndPenalty(AccountState.LOAN_APPROVED, startDate, TestUtils.createMoney("20"), TestUtils.createMoney("30"));
Set<AccountActionDateEntity> intallments = accountBO.getAccountActionDates();
AccountActionDateEntity firstInstallment = null;
for (AccountActionDateEntity entity : intallments) {
if (entity.getInstallmentId().intValue() == 1) {
firstInstallment = entity;
break;
}
}
Calendar disbursalDate = new GregorianCalendar();
disbursalDate.setTimeInMillis(firstInstallment.getActionDate().getTime());
Calendar cal = new GregorianCalendar(disbursalDate.get(Calendar.YEAR), disbursalDate.get(Calendar.MONTH), disbursalDate.get(Calendar.DATE), 0, 0);
((LoanBO) accountBO).disburseLoan("1234", cal.getTime(), Short.valueOf("1"), accountBO.getPersonnel(), startDate, Short.valueOf("1"), Short.valueOf("1"), null);
Set<AccountActionDateEntity> actionDateEntities = accountBO.getAccountActionDates();
LoanScheduleEntity[] paymentsArray = getSortedAccountActionDateEntity(actionDateEntities);
return paymentsArray;
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class LoanBusinessServiceTest method originalLoanScheduleShouldPersistMiscFee.
@Test
public void originalLoanScheduleShouldPersistMiscFee() throws PersistenceException {
Set<LoanScheduleEntity> installments = new LinkedHashSet<LoanScheduleEntity>();
MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
Money money = new Money(mifosCurrency, "123");
AccountBO accountBO = mock(AccountBO.class);
CustomerBO customerBO = mock(CustomerBO.class);
when(accountBO.getCurrency()).thenReturn(mifosCurrency);
LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(accountBO, customerBO, new Short("1"), new java.sql.Date(new Date().getTime()), PaymentStatus.UNPAID, money, money);
loanScheduleEntity.setMiscFee(money);
installments.add(loanScheduleEntity);
when(loanBO.getLoanScheduleEntities()).thenReturn(installments);
loanBusinessService.persistOriginalSchedule(loanBO);
ArrayList<OriginalLoanScheduleEntity> expected = new ArrayList<OriginalLoanScheduleEntity>();
OriginalLoanScheduleEntity originalLoanScheduleEntity = new OriginalLoanScheduleEntity(loanScheduleEntity);
assertEquals(originalLoanScheduleEntity.getMiscFee(), loanScheduleEntity.getMiscFee());
expected.add(originalLoanScheduleEntity);
verify(legacyLoanDao).saveOriginalSchedule(Mockito.argThat(new OriginalLoanScheduleEntitiesMatcher(expected)));
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class LoanBusinessServiceTest method persistOriginalSchedule.
@Test
public void persistOriginalSchedule() throws PersistenceException {
Set<LoanScheduleEntity> installments = new LinkedHashSet<LoanScheduleEntity>();
MifosCurrency mifosCurrency = new MifosCurrency(Short.valueOf("1"), "Rupee", BigDecimal.valueOf(1), "INR");
Money money = new Money(mifosCurrency, "123");
AccountBO accountBO = mock(AccountBO.class);
CustomerBO customerBO = mock(CustomerBO.class);
when(accountBO.getCurrency()).thenReturn(mifosCurrency);
LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity(accountBO, customerBO, new Short("1"), new java.sql.Date(new Date().getTime()), PaymentStatus.UNPAID, money, money);
installments.add(loanScheduleEntity);
when(loanBO.getLoanScheduleEntities()).thenReturn(installments);
loanBusinessService.persistOriginalSchedule(loanBO);
ArrayList<OriginalLoanScheduleEntity> expected = new ArrayList<OriginalLoanScheduleEntity>();
expected.add(new OriginalLoanScheduleEntity(loanScheduleEntity));
verify(legacyLoanDao).saveOriginalSchedule(Mockito.argThat(new OriginalLoanScheduleEntitiesMatcher(expected)));
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class SavingsPersistence method getSavingsAccountWithAccountActionsInitialized.
@SuppressWarnings("unchecked")
public AccountBO getSavingsAccountWithAccountActionsInitialized(Integer accountId) throws PersistenceException {
Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put("accountId", accountId);
List obj = executeNamedQuery("accounts.retrieveSavingsAccountWithAccountActions", queryParameters);
Object[] obj1 = (Object[]) obj.get(0);
return (AccountBO) obj1[0];
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class WebTierAccountServiceFacade method applyCharge.
@Override
public void applyCharge(Integer accountId, Short chargeId, Double chargeAmount, boolean isPenaltyType) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
AccountBO account = new AccountBusinessService().getAccount(accountId);
if (account instanceof LoanBO && !account.isGroupLoanAccount()) {
List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
if (individualLoans != null && individualLoans.size() > 0) {
for (LoanBO individual : individualLoans) {
individual.updateDetails(userContext);
if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
} else {
FeeBO fee = this.feeDao.findById(chargeId);
if (fee instanceof RateFeeBO) {
individual.applyCharge(chargeId, chargeAmount);
} else {
Double radio = individual.getLoanAmount().getAmount().doubleValue() / ((LoanBO) account).getLoanAmount().getAmount().doubleValue();
individual.applyCharge(chargeId, chargeAmount * radio);
}
}
}
}
}
account.updateDetails(userContext);
CustomerLevel customerLevel = null;
if (account.isCustomerAccount()) {
customerLevel = account.getCustomer().getLevel();
}
if (account.getPersonnel() != null) {
checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
} else {
checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), userContext.getId());
}
this.transactionHelper.startTransaction();
if (isPenaltyType && account instanceof LoanBO) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
((LoanBO) account).addAccountPenalty(new AccountPenaltiesEntity(account, penalty, chargeAmount));
} else {
account.applyCharge(chargeId, chargeAmount);
}
this.transactionHelper.commitTransaction();
} catch (ServiceException e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
}
}
Aggregations