use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class LoanAdjustmentsIntegrationTest method testWhenACompletedLoanIsAdjustedItGoesBackToBadStandingIfNecessary.
@Test
public void testWhenACompletedLoanIsAdjustedItGoesBackToBadStandingIfNecessary() throws Exception {
// relates to mifos-3479
new DateTimeService().setCurrentDateTimeFixed(date(2010, 10, 13));
loan = createLoan();
loan.updateDetails(TestUtils.makeUserWithLocales());
// pay 3 installments
makePayment(loan, "333.0");
loan.updateDetails(TestUtils.makeUserWithLocales());
makeEarlyPayment(loan);
loan.updateDetails(TestUtils.makeUserWithLocales());
// ensure loan is in bad standing when reopened
new DateTimeService().setCurrentDateTimeFixed(date(2010, 11, 13));
adjustLastLoanPayment(loan);
loan.updateDetails(TestUtils.makeUserWithLocales());
AccountStateEntity currentStatus = loan.getAccountState();
assertTrue("Current Status Should Have Been LOAN_ACTIVE_IN_BAD_STANDING", currentStatus.isInState(AccountState.LOAN_ACTIVE_IN_BAD_STANDING));
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class LoanScheduleEntityIntegrationTest method testMakeEarlyRepaymentEnteriesForNotPayingFee.
@Test
public void testMakeEarlyRepaymentEnteriesForNotPayingFee() {
for (AccountActionDateEntity accountAction : groupLoan.getAccountActionDates()) {
LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction;
Money preRepaymentInterest = accountActionDateEntity.getInterest();
Money preRepaymentPenalty = accountActionDateEntity.getPenalty();
Money preRepaymentMiscFee = accountActionDateEntity.getMiscFee();
accountActionDateEntity.makeEarlyRepaymentEntries(LoanConstants.DONOT_PAY_FEES_PENALTY_INTEREST, accountActionDateEntity.getInterestDue(), new DateTimeService().getCurrentJavaSqlDate());
Assert.assertEquals(accountActionDateEntity.getPrincipal(), accountActionDateEntity.getPrincipalPaid());
Assert.assertEquals(accountActionDateEntity.getInterest(), preRepaymentInterest);
Assert.assertEquals(accountActionDateEntity.getPenalty(), preRepaymentPenalty);
Assert.assertEquals(accountActionDateEntity.getMiscFee(), preRepaymentMiscFee);
Assert.assertTrue(accountActionDateEntity.isPaid());
}
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class LoanScheduleEntityIntegrationTest method testMakeEarlyRepaymentEnteriesForFeePayment.
@Test
public void testMakeEarlyRepaymentEnteriesForFeePayment() {
for (AccountActionDateEntity accountAction : groupLoan.getAccountActionDates()) {
LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction;
accountActionDateEntity.makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY_INTEREST, accountActionDateEntity.getInterestDue(), new DateTimeService().getCurrentJavaSqlDate());
Assert.assertEquals(accountActionDateEntity.getPrincipal(), accountActionDateEntity.getPrincipalPaid());
Assert.assertEquals(accountActionDateEntity.getInterest(), accountActionDateEntity.getInterestPaid());
Assert.assertEquals(accountActionDateEntity.getPenalty(), accountActionDateEntity.getPenaltyPaid());
Assert.assertEquals(accountActionDateEntity.getMiscFee(), accountActionDateEntity.getMiscFeePaid());
Assert.assertTrue(accountActionDateEntity.isPaid());
}
}
use of org.mifos.framework.util.DateTimeService 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;
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class SavingsBO method createDepositTrxnsForVolAccountsAfterAdjust.
/*
* FIXME - keithw - it doesnt make sense to be that voluntary account break up account payments into more than one account transaction
* just because the amount deposited is greater than the 'recommended' amount.
*
* As a result there is no need to make a distinction between the amount deposited (be it less or greater than recommended amount)
*/
private Set<AccountTrxnEntity> createDepositTrxnsForVolAccountsAfterAdjust(final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment, Money newAmount, LocalDate adjustmentDate, PersonnelBO loggedInUser) {
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;
}
Short installmentId = null;
Date dueDate = null;
Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
if (oldAccntTrxn.getAccountActionEntity().getId().equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
SavingsTrxnDetailEntity oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
if (oldAccntTrxn.getInstallmentId() != null) {
SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(oldSavingsAccntTrxn.getInstallmentId(), oldSavingsAccntTrxn.getCustomer().getCustomerId());
installmentId = accountAction.getInstallmentId();
dueDate = accountAction.getActionDate();
// if recommended amount is covered by payment
if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, accountAction.getDeposit(), loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(accountAction.getDeposit());
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.PAID);
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
} else if (newAmount.isNonZero()) {
// not zero and amount paid is less that recommended amount
this.savingsBalance = this.savingsBalance.add(newAmount);
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
newAmount = newAmount.subtract(newAmount);
accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
accountAction.setPaymentStatus(PaymentStatus.UNPAID);
accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
}
break;
}
}
}
if (accountTrxn != null) {
newTrxns.add(accountTrxn);
}
// Create a new transaction with remaining amount
if (newAmount.isGreaterThanZero()) {
this.savingsBalance = this.savingsBalance.add(newAmount);
accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);
this.savingsPerformance.setTotalDeposits(this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
newTrxns.add(accountTrxn);
}
return newTrxns;
}
Aggregations