use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class LoanBOTest method repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest.
@Test
public void repayInstallmentsShouldPopulateCalculatedInterestsForDIPBLoansWithWaiverInterest() throws PersistenceException {
final LegacyLoanDao legacyLoanDao = mock(LegacyLoanDao.class);
final CustomerBO customerBO = mock(CustomerBO.class);
final LoanSummaryEntity loanSummaryEntity = mock(LoanSummaryEntity.class);
LoanBO loanBO = new LoanBO() {
@Override
public boolean isDecliningBalanceInterestRecalculation() {
return true;
}
@Override
public LegacyLoanDao getlegacyLoanDao() {
return legacyLoanDao;
}
@Override
public CustomerBO getCustomer() {
return customerBO;
}
@Override
public LoanSummaryEntity getLoanSummary() {
return loanSummaryEntity;
}
@Override
public MifosCurrency getCurrency() {
return rupee;
}
};
AccountActionTypes accountActionTypes = AccountActionTypes.LOAN_REPAYMENT;
AccountActionEntity accountActionEntity = mock(AccountActionEntity.class);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntityBuilder().with(loanBO).build();
PersonnelBO user = new PersonnelBO();
Money extraInterestDue = new Money(rupee, "0.98");
Money interest = new Money(rupee, "10");
Money interestDue = new Money(rupee, "0");
when(legacyLoanDao.getPersistentObject(AccountActionEntity.class, accountActionTypes.getValue())).thenReturn(accountActionEntity);
when(loanScheduleEntity.getPrincipalDue()).thenReturn(new Money(rupee, "1000"));
when(loanScheduleEntity.getTotalFeeDueWithMiscFeeDue()).thenReturn(new Money(rupee, "10"));
when(loanScheduleEntity.getPenaltyDue()).thenReturn(new Money(rupee, "10"));
when(loanScheduleEntity.getPenalty()).thenReturn(new Money(rupee, "100"));
when(loanScheduleEntity.getExtraInterestDue()).thenReturn(extraInterestDue);
when(loanScheduleEntity.getExtraInterestPaid()).thenReturn(extraInterestDue);
when(loanScheduleEntity.getInterest()).thenReturn(interest);
loanBO.repayInstallmentWithInterestWaiver(loanScheduleEntity, accountPaymentEntity, "", accountActionTypes, user);
Set<AccountTrxnEntity> accountTrxns = accountPaymentEntity.getAccountTrxns();
AccountTrxnEntity accountTrxnEntity = accountTrxns.toArray(new AccountTrxnEntity[accountTrxns.size()])[0];
LoanTrxnDetailEntity loanTrxnDetailEntity = (LoanTrxnDetailEntity) accountTrxnEntity;
assertThat(loanTrxnDetailEntity.getInterestAmount().getAmount().doubleValue(), is(0.98));
CalculatedInterestOnPayment calculatedInterestOnPayment = loanTrxnDetailEntity.getCalculatedInterestOnPayment();
assertNotNull(calculatedInterestOnPayment);
assertThat(calculatedInterestOnPayment.getExtraInterestPaid(), is(extraInterestDue));
assertThat(calculatedInterestOnPayment.getInterestDueTillPaid(), is(interestDue));
assertThat(calculatedInterestOnPayment.getOriginalInterest(), is(interest));
Mockito.verify(loanScheduleEntity).makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY, interestDue, accountPaymentEntity.getPaymentDate());
}
use of org.mifos.customers.business.CustomerBO 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.customers.business.CustomerBO 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.customers.business.CustomerBO in project head by mifos.
the class SavingsBO method makePayment.
/**
* @deprecated for deposits use {@link SavingsBO#deposit(AccountPaymentEntity, Integer)} and withdrawals use
* {@link SavingsBO#withdraw(AccountPaymentEntity)}
*/
@Deprecated
@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
Money totalAmount = paymentData.getTotalAmount();
Money enteredAmount = totalAmount;
Date transactionDate = paymentData.getTransactionDate();
List<AccountPaymentData> accountPayments = paymentData.getAccountPayments();
if (paymentData.getCustomer() == null) {
throw new NullPointerException("Customer in payment data during payment should not be null");
}
CustomerBO customer = paymentData.getCustomer();
AccountPaymentEntity accountPayment = new AccountPaymentEntity(this, totalAmount, paymentData.getReceiptNum(), paymentData.getReceiptDate(), getPaymentTypeEntity(paymentData.getPaymentTypeId()), transactionDate);
accountPayment.setCreatedByUser(paymentData.getPersonnel());
accountPayment.setComment(paymentData.getComment());
// make savings account active if inactive
if (this.getState().getValue().equals(AccountState.SAVINGS_INACTIVE.getValue())) {
this.changeStatus(AccountState.SAVINGS_ACTIVE, null, "Account Made Active Due to Payment", paymentData.getPersonnel());
}
if (totalAmount.isGreaterThanZero() && paymentData.getAccountPayments().size() <= 0) {
SavingsTrxnDetailEntity accountTrxn = buildUnscheduledDeposit(accountPayment, totalAmount, paymentData.getPersonnel(), customer, transactionDate);
accountPayment.addAccountTrxn(accountTrxn);
addSavingsActivityDetails(buildSavingsActivity(totalAmount, getSavingsBalance(), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), transactionDate, paymentData.getPersonnel()));
return accountPayment;
}
for (AccountPaymentData accountPaymentData : accountPayments) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(accountPaymentData.getInstallmentId(), customer.getCustomerId());
if (accountAction != null && depositAmountIsInExcess(enteredAmount)) {
if (accountAction.isPaid()) {
throw new AccountException("errors.update", new String[] { getGlobalAccountNum() });
}
Money depositAmount = new Money(getCurrency());
PaymentStatus paymentStatus = PaymentStatus.UNPAID;
if (enteredAmount.isGreaterThanOrEqual(accountAction.getTotalDepositDue())) {
depositAmount = accountAction.getTotalDepositDue();
enteredAmount = enteredAmount.subtract(accountAction.getTotalDepositDue());
paymentStatus = PaymentStatus.PAID;
} else {
depositAmount = enteredAmount;
enteredAmount = new Money(getCurrency());
}
if (this.isVoluntary() && depositAmountIsInExcess(depositAmount)) {
paymentStatus = PaymentStatus.PAID;
}
savingsBalance = savingsBalance.add(depositAmount);
savingsPerformance.setPaymentDetails(depositAmount);
accountAction.setPaymentDetails(depositAmount, paymentStatus, new java.sql.Date(transactionDate.getTime()));
Short installmentId = accountAction.getInstallmentId();
SavingsTrxnDetailEntity accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(accountPayment, customer, this.savingsBalance, depositAmount, paymentData.getPersonnel(), accountAction.getActionDate(), paymentData.getTransactionDate(), paymentData.getTransactionDate(), installmentId);
accountPayment.addAccountTrxn(accountTrxn);
}
}
if (depositAmountIsInExcess(enteredAmount)) {
SavingsTrxnDetailEntity accountTrxn = buildUnscheduledDeposit(accountPayment, enteredAmount, paymentData.getPersonnel(), customer, transactionDate);
accountPayment.addAccountTrxn(accountTrxn);
}
addSavingsActivityDetails(buildSavingsActivity(totalAmount, getSavingsBalance(), AccountActionTypes.SAVINGS_DEPOSIT.getValue(), transactionDate, paymentData.getPersonnel()));
return accountPayment;
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class SavingsBO method createDepositTrxnsForMandatoryAccountsAfterAdjust.
private Set<AccountTrxnEntity> createDepositTrxnsForMandatoryAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO createdBy) {
Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
SavingsTrxnDetailEntity accountTrxn = null;
CustomerBO customer = null;
Date trxnDate = adjustmentDate.toDateMidnight().toDate();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
customer = oldAccntTrxn.getCustomer();
break;
}
List<AccountActionDateEntity> accountActionList = getAccountActions(lastAccountPayment.getPaymentDate(), customer.getCustomerId());
for (AccountActionDateEntity accountActionDateEntity : accountActionList) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) accountActionDateEntity;
if (newAmount.isZero()) {
break;
}
accountTrxn = null;
// if payment covers required deposit
if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
Short installmentId = accountAction.getInstallmentId();
Date dueDate = accountAction.getActionDate();
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(accountAction.getDeposit());
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.PAID);
} else {
this.savingsBalance = this.savingsBalance.add(newAmount);
Short installmentId = accountAction.getInstallmentId();
Date dueDate = accountAction.getActionDate();
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.UNPAID);
}
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
// add trxn for excess amount
if (newAmount.isGreaterThanZero()) {
this.savingsBalance = this.savingsBalance.add(newAmount);
Short installmentId = null;
Date dueDate = null;
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
getSavingsPerformance().setTotalDeposits(getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
return newTrxns;
}
Aggregations