use of org.mifos.accounts.business.AccountStatusChangeHistoryEntity in project head by mifos.
the class ApplyAdjustmentActionStrutsTest method testApplyAdjustment.
@Ignore
@Test
public void testApplyAdjustment() throws Exception {
PersonnelBO personnel = legacyPersonnelDao.getPersonnel(PersonnelConstants.SYSTEM_USER);
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
loan = (LoanBO) getLoanAccount();
applyPayment(loan, 212);
loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
applyPayment(loan, 700);
loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), personnel, loan);
AccountTestUtils.addToAccountStatusChangeHistory(loan, historyEntity);
TestObjectFactory.updateObject(loan);
StaticHibernateUtil.flushAndClearSession();
loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
loan.setUserContext(userContext);
for (AccountStatusChangeHistoryEntity accountStatus : loan.getAccountStatusChangeHistory()) {
Assert.assertEquals(loan.getAccountId(), accountStatus.getAccount().getAccountId());
Assert.assertNotNull(accountStatus.getAccountStatusChangeId());
Assert.assertEquals(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue(), accountStatus.getNewStatus().getId());
Assert.assertEquals(personnel.getPersonnelId(), accountStatus.getPersonnel().getPersonnelId());
Assert.assertEquals(personnel.getDisplayName(), accountStatus.getPersonnel().getDisplayName());
Assert.assertEquals("-", accountStatus.getOldStatusName());
Assert.assertNotNull(accountStatus.getNewStatusName());
Assert.assertNull(accountStatus.getLocale());
Assert.assertNotNull(accountStatus.getUserPrefferedTransactionDate());
}
SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
setRequestPathInfo("/applyAdjustment");
addRequestParameter("method", "applyAdjustment");
addRequestParameter("adjustmentNote", "Loan adjustment testing");
addRequestParameter("globalAccountNum", loan.getGlobalAccountNum());
addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
setUpSecurityContext();
getRequest().getSession().setAttribute(Constants.USERCONTEXT, TestUtils.makeUser());
actionPerform();
loan = (LoanBO) TestObjectFactory.getObject(AccountBO.class, loan.getAccountId());
verifyForward("applyadj_success");
}
use of org.mifos.accounts.business.AccountStatusChangeHistoryEntity in project head by mifos.
the class LoanBO method handleArrears.
public void handleArrears() throws AccountException {
AccountStateEntity stateEntity;
try {
stateEntity = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_BADSTANDING);
} catch (PersistenceException e) {
throw new AccountException(e);
}
AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(this.getAccountState(), stateEntity, this.getPersonnel(), this);
this.addAccountStatusChangeHistory(historyEntity);
this.setAccountState(stateEntity);
try {
String systemDate = DateUtils.getCurrentDate();
Date currrentDate = DateUtils.getLocaleDate(systemDate);
this.setUpdatedDate(currrentDate);
} catch (InvalidDateException ide) {
throw new AccountException(ide);
}
try {
getlegacyLoanDao().createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.business.AccountStatusChangeHistoryEntity in project head by mifos.
the class LoanBO method disburseLoan.
private void disburseLoan(final String receiptNum, final Date transactionDate, final Short paymentTypeId, final PersonnelBO loggedInUser, final Date receiptDate, final Short rcvdPaymentTypeId, final boolean persistChange, final Short paymentTypeIdForFees, Integer accountForTransferId) throws AccountException, PersistenceException {
if ((this.getState().compareTo(AccountState.LOAN_APPROVED) != 0) && (this.getState().compareTo(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER) != 0)) {
throw new AccountException("Loan not in a State to be Disbursed: " + this.getState().toString());
}
if (this.getCustomer().isDisbursalPreventedDueToAnyExistingActiveLoansForTheSameProduct(this.getLoanOffering())) {
throw new AccountException("errors.cannotDisburseLoan.because.otherLoansAreActive");
}
try {
new ProductMixValidator().checkIfProductsOfferingCanCoexist(this);
} catch (ServiceException e1) {
throw new AccountException(e1.getMessage());
}
addLoanActivity(buildLoanActivity(this.loanAmount, loggedInUser, AccountConstants.LOAN_DISBURSAL, transactionDate));
// regenerate the installments
if (!isFixedRepaymentSchedule() && !DateUtils.getDateWithoutTimeStamp(disbursementDate.getTime()).equals(DateUtils.getDateWithoutTimeStamp(transactionDate.getTime()))) {
final boolean lsimEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (lsimEnabled) {
// QUESTION: does minDays
final int minDaysInterval = new ConfigurationPersistence().getConfigurationValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY);
this.disbursementDate = new DateTime(transactionDate).plusDays(minDaysInterval - 1).toDate();
} else {
this.disbursementDate = transactionDate;
}
regeneratePaymentSchedule(lsimEnabled, null);
if (this.isParentGroupLoanAccount()) {
groupLoanAccountServiceFacade.fixMemberAndParentInstallmentDetails(this.getAccountId());
}
}
this.disbursementDate = transactionDate;
final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(this.getAccountState(), newState, loggedInUser, this));
this.setAccountState(newState);
//
// Client performance entry
updateCustomerHistoryOnDisbursement(this.loanAmount);
if (getPerformanceHistory() != null) {
getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
}
//
//
// build up account payment related data
AccountPaymentEntity accountPayment = null;
if (this.isInterestDeductedAtDisbursement()) {
// the 1st payment is made and creates an initial accountPaymentEntity.
// This disbursal process carries on with that accountPaymentEntity by updating the 'amount' to the actual
// disbursed amount.
accountPayment = payInterestAtDisbursement(receiptNum, transactionDate, rcvdPaymentTypeId, loggedInUser, receiptDate);
accountPayment.setAmount(this.loanAmount.subtract(accountPayment.getAmount()));
} else {
// Disbursal process has to create its own accountPayment taking into account any disbursement fees
Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
accountPayment = new AccountPaymentEntity(this, this.loanAmount.subtract(feeAmountAtDisbursement), receiptNum, receiptDate, getPaymentTypeEntity(paymentTypeId), transactionDate);
accountPayment.setCreatedByUser(loggedInUser);
if (feeAmountAtDisbursement.isGreaterThanZero()) {
processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, paymentTypeIdForFees, accountForTransferId);
}
}
// create trxn entry for disbursal
final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, loggedInUser, transactionDate, this.loanAmount, "-", null, this.loanAmount, new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
accountPayment.addAccountTrxn(loanTrxnDetailEntity);
this.addAccountPayment(accountPayment);
this.buildFinancialEntries(accountPayment.getAccountTrxns());
if (persistChange) {
try {
ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
}
use of org.mifos.accounts.business.AccountStatusChangeHistoryEntity in project head by mifos.
the class LoanBO method makeEarlyRepayment.
public void makeEarlyRepayment(final AccountPaymentDto paymentDto, final Short personnelId, boolean waiveInterest, Money interestDue, Integer savingsPaymentId, AccountPaymentEntity parentPayment) throws AccountException {
try {
PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
this.setUpdatedBy(personnelId);
this.setUpdatedDate(paymentDto.getTransactionDate());
AccountPaymentEntity accountPaymentEntity;
if (this.isGroupLoanAccount() && null != this.getParentAccount()) {
accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate(), parentPayment);
} else {
accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate());
}
if (savingsPaymentId != null) {
AccountPaymentEntity withdrawal = legacyAccountDao.findPaymentById(savingsPaymentId);
accountPaymentEntity.setOtherTransferPayment(withdrawal);
}
addAccountPayment(accountPaymentEntity);
makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
makeEarlyRepaymentForNextInstallment(currentUser, accountPaymentEntity, waiveInterest, interestDue);
makeEarlyRepaymentForFutureInstallments(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
if (getPerformanceHistory() != null) {
getPerformanceHistory().setNoOfPayments(getPerformanceHistory().getNoOfPayments() + 1);
}
LoanActivityEntity loanActivity = buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_REPAYMENT, paymentDto.getTransactionDate());
addLoanActivity(loanActivity);
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
AccountStateEntity newAccountState = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET);
addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(getAccountState(), newAccountState, legacyPersonnelDao.getPersonnel(personnelId), this));
setAccountState(legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET));
changeStateForAllFees(FeeStatus.INACTIVE);
setClosedDate(paymentDto.getTransactionDate());
// Client performance entry
updateCustomerHistoryOnRepayment();
this.delete(loanArrearsAgingEntity);
loanArrearsAgingEntity = null;
// GLIM
if (this.isGroupLoanAccountParent()) {
for (Entry<String, AmountWithInterest> entry : paymentDto.getMemberNumWithAmount().entrySet()) {
AccountPaymentDto memberPayment = new AccountPaymentDto(entry.getValue().getAmount(), paymentDto.getTransactionDate(), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), paymentDto.getPaymentTypeId());
legacyLoanDao.getAccount(Integer.valueOf(entry.getKey())).makeEarlyRepayment(memberPayment, personnelId, waiveInterest, new Money(this.getCurrency(), entry.getValue().getInterest()), null, accountPaymentEntity);
}
} else if (hasMemberAccounts() && !this.isGroupLoanAccount()) {
for (LoanBO memberAccount : this.memberAccounts) {
BigDecimal fraction = memberAccount.calcFactorOfEntireLoan();
paymentDto.setTotalAmount(new BigDecimal(paymentDto.getTotalAmount()).divide(fraction, RoundingMode.HALF_UP).doubleValue());
memberAccount.makeEarlyRepayment(paymentDto, personnelId, waiveInterest, interestDue, null, null);
}
}
this.legacyAccountDao.createOrUpdate(accountPaymentEntity);
this.legacyAccountDao.createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.business.AccountStatusChangeHistoryEntity in project head by mifos.
the class LoanBO method openGroupLoanForAccount.
public static LoanBO openGroupLoanForAccount(LoanBO parentLoan, LoanOfferingBO loanProduct, ClientBO member, MeetingBO repaymentDayMeeting, LoanSchedule loanSchedule, LoanProductOverridenDetail overridenDetail, LoanScheduleConfiguration configuration, InstallmentRange installmentRange, AmountRange loanAmountRange, CreationDetail creationDetail, PersonnelBO createdBy, Boolean groupLoan) {
AccountState loanState = AccountState.LOAN_PENDING_APPROVAL;
LoanBO standardLoan = new LoanBO(loanProduct, member, loanState, overridenDetail, repaymentDayMeeting, loanSchedule, configuration, installmentRange, loanAmountRange, creationDetail, AccountTypes.GROUP_LOAN_ACCOUNT);
standardLoan.setParentAccount(parentLoan);
standardLoan.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(standardLoan.getAccountState(), standardLoan.getAccountState(), createdBy, standardLoan));
return standardLoan;
}
Aggregations