use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.
the class LoanBO method updateInstallmentAfterAdjustment.
@Override
protected void updateInstallmentAfterAdjustment(final List<AccountTrxnEntity> reversedTrxns, PersonnelBO loggedInUser) throws AccountException {
Money increaseInterest = new Money(this.getCurrency());
Money increaseFees = new Money(this.getCurrency());
Money increasePenalty = new Money(this.getCurrency());
int numberOfFullPayments = 0;
short numberOfInstalments = (short) reversedTrxns.size();
List<AccountActionDateEntity> allInstallments = this.getAllInstallments();
if (isNotEmpty(reversedTrxns)) {
for (AccountTrxnEntity reversedTrxn : reversedTrxns) {
Short prevInstallmentId = null;
Short currentInstallmentId = reversedTrxn.getInstallmentId();
numberOfFullPayments = getIncrementedNumberOfFullPaymentsIfPaid(numberOfFullPayments, allInstallments, prevInstallmentId, currentInstallmentId);
if (!reversedTrxn.isTrxnForReversalOfLoanDisbursal()) {
LoanTrxnDetailEntity loanReverseTrxn = (LoanTrxnDetailEntity) reversedTrxn;
loanSummary.updatePaymentDetails(loanReverseTrxn);
if (loanReverseTrxn.isNotEmptyTransaction()) {
LoanScheduleEntity installment = (LoanScheduleEntity) getAccountActionDate(loanReverseTrxn.getInstallmentId());
installment.updatePaymentDetailsForAdjustment(loanReverseTrxn);
if (installment.isPaid()) {
increaseInterest = increaseInterest.add(installment.getInterestDue().add(installment.getExtraInterestDue())).add(loanReverseTrxn.getInterestAmount());
increaseFees = increaseFees.add(installment.getTotalFeesDue());
if (!this.noOfInstallments.equals(numberOfInstalments)) {
increaseFees = increaseFees.add(installment.getMiscFeeDue()).add(loanReverseTrxn.getMiscFeeAmount());
increasePenalty = increasePenalty.add(installment.getPenaltyDue()).add(loanReverseTrxn.getPenaltyAmount());
}
}
installment.recordForAdjustment();
if (installment.hasFees()) {
for (AccountFeesActionDetailEntity accntFeesAction : installment.getAccountFeesActionDetails()) {
loanReverseTrxn.adjustFees(accntFeesAction);
}
}
if (installment.hasPenalties()) {
for (LoanPenaltyScheduleEntity entity : installment.getLoanPenaltyScheduleEntities()) {
loanReverseTrxn.adjustPenalties(entity);
}
}
}
}
}
AccountStateEntity currentAccountState = this.getAccountState();
AccountStateEntity newAccountState = currentAccountState;
boolean statusChangeNeeded = false;
if (isLoanActiveWithStatusChangeHistory()) {
AccountStatusChangeHistoryEntity lastAccountStatusChange = getLastAccountStatusChange();
if (lastAccountStatusChange.isLoanActive()) {
statusChangeNeeded = true;
} else if (currentAccountState.isLoanClosedObligationsMet()) {
statusChangeNeeded = true;
newAccountState = lastAccountStatusChange.getOldStatus();
}
}
boolean accountReOpened = isAccountReOpened(currentAccountState, newAccountState);
updatePerformanceHistory(accountReOpened);
/*
* John W - mifos-1986 - see related comment above
*/
if (accountReOpened) {
loanSummary.increaseBy(null, increaseInterest, increasePenalty, increaseFees);
// fix for MIFOS-3287
this.setClosedDate(null);
}
// Else reverse payments equal to number of transactions reversed.
if (accountReOpened) {
updatePerformanceHistoryOnAdjustment(1);
} else if (reversedTrxns.size() > 0) {
updatePerformanceHistoryOnAdjustment(numberOfFullPayments);
}
if (statusChangeNeeded) {
Short daysInArrears = getDaysInArrears(accountReOpened);
if (currentAccountState.isLoanClosedObligationsMet()) {
AccountState newStatus = AccountState.LOAN_ACTIVE_IN_BAD_STANDING;
if (daysInArrears == 0) {
newStatus = AccountState.LOAN_ACTIVE_IN_GOOD_STANDING;
}
changeStatus(newStatus, null, "Account Reopened", loggedInUser);
} else {
if (daysInArrears == 0) {
if (!currentAccountState.isLoanActiveInGoodStanding()) {
changeStatus(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, null, "Account Adjusted", loggedInUser);
}
} else {
if (!currentAccountState.isLoanActiveInBadStanding()) {
changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "Account Adjusted", loggedInUser);
handleArrearsAging();
}
}
}
}
try {
PersonnelBO personnel = legacyPersonnelDao.getPersonnel(getUserContext().getId());
addLoanActivity(buildLoanActivity(reversedTrxns, personnel, AccountConstants.LOAN_ADJUSTED, DateUtils.getCurrentDateWithoutTimeStamp()));
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
}
use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.
the class LoanBO method openGroupMemberLoanAccount.
public static LoanBO openGroupMemberLoanAccount(LoanBO parentLoan, LoanOfferingBO loanProduct, ClientBO member, MeetingBO repaymentDayMeeting, LoanSchedule loanSchedule, LoanProductOverridenDetail overridenDetail, LoanScheduleConfiguration configuration, InstallmentRange installmentRange, AmountRange loanAmountRange, CreationDetail creationDetail, PersonnelBO createdBy) {
AccountState loanState = AccountState.LOAN_PENDING_APPROVAL;
LoanBO groupMemberLoan = new LoanBO(loanProduct, member, loanState, overridenDetail, repaymentDayMeeting, loanSchedule, configuration, installmentRange, loanAmountRange, creationDetail, AccountTypes.GROUP_LOAN_ACCOUNT);
groupMemberLoan.setParentAccount(parentLoan);
groupMemberLoan.markAsIndividualLoanAccount();
groupMemberLoan.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(groupMemberLoan.getAccountState(), groupMemberLoan.getAccountState(), createdBy, groupMemberLoan));
return groupMemberLoan;
}
use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.
the class GroupLoanAccountServiceFacadeWebTier method assembleLoanAccountDetail.
private LoanAccountDetail assembleLoanAccountDetail(CreateGroupLoanAccount loanAccountInfo) {
CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getGroupLoanAccountDetails().getCustomerId());
LoanOfferingBO loanProduct = this.loanProductDao.findById(loanAccountInfo.getGroupLoanAccountDetails().getProductId());
Money loanAmount = new Money(loanProduct.getCurrency(), loanAccountInfo.getGroupLoanAccountDetails().getLoanAmount());
AccountState accountStateType = AccountState.fromShort(loanAccountInfo.getGroupLoanAccountDetails().getAccountState().shortValue());
FundBO fund = null;
if (loanAccountInfo.getGroupLoanAccountDetails().getSourceOfFundId() != null) {
fund = this.fundDao.findById(loanAccountInfo.getGroupLoanAccountDetails().getSourceOfFundId().shortValue());
}
return new LoanAccountDetail(customer, loanProduct, loanAmount, accountStateType, fund);
}
use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.
the class LoanAccountServiceFacadeWebTier method updateLoanAccountStatus.
@Override
public String updateLoanAccountStatus(AccountUpdateStatus updateStatus, Date transactionDate) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
LoanBO loanAccount = this.loanDao.findById(updateStatus.getSavingsId().intValue());
loanAccount.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(loanAccount);
AccountState newStatus = AccountState.fromShort(updateStatus.getNewStatusId());
loanAccount.changeStatus(newStatus, updateStatus.getFlagId(), updateStatus.getComment(), loggedInUser, transactionDate);
this.loanDao.save(loanAccount);
this.transactionHelper.commitTransaction();
return loanAccount.getGlobalAccountNum();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.
the class AccountStateIntegrationTest method testRetrieveAllAccountStateList.
/*
* Check that the values in the enumerated type AccountState match with the
* Entity values in terms of ids, state names, and the text that they
* eventually resolve to.
*/
@Test
public void testRetrieveAllAccountStateList() throws NumberFormatException, PersistenceException {
List<AccountStateEntity> accountStateEntityList = legacyAccountDao.retrieveAllAccountStateList(ProductType.SAVINGS.getValue());
Assert.assertNotNull(accountStateEntityList);
Assert.assertEquals(6, accountStateEntityList.size());
List<AccountStateEntity> accountStateEntityList2 = legacyAccountDao.retrieveAllAccountStateList(ProductType.LOAN.getValue());
Assert.assertNotNull(accountStateEntityList2);
Assert.assertEquals(12, accountStateEntityList2.size());
accountStateEntityList.addAll(accountStateEntityList2);
// order by id
Collections.sort(accountStateEntityList, new Comparator<AccountStateEntity>() {
@Override
public int compare(AccountStateEntity state1, AccountStateEntity state2) {
return state1.getId().compareTo(state2.getId());
}
});
Assert.assertEquals(AccountState.values().length, accountStateEntityList.size());
Iterator<AccountStateEntity> stateListIterator = accountStateEntityList.iterator();
for (AccountState state : AccountState.values()) {
AccountStateEntity stateInDatabase = stateListIterator.next();
Assert.assertEquals(state.getValue(), stateInDatabase.getId());
Assert.assertEquals(state.getPropertiesKey(), stateInDatabase.getLookUpValue().getLookUpName());
Assert.assertEquals(ApplicationContextProvider.getBean(MessageLookup.class).lookup(state), ApplicationContextProvider.getBean(MessageLookup.class).lookup(stateInDatabase));
}
}
Aggregations