use of org.mifos.accounts.exceptions.AccountException 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.exceptions.AccountException in project head by mifos.
the class LoanBO method writeOff.
@Override
protected void writeOff(Date transactionDate) throws AccountException {
try {
if (!isTrxnDateValid(transactionDate, new CustomerPersistence().getLastMeetingDateForCustomer(getCustomer().getCustomerId()), new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled())) {
throw new BusinessRuleException("errors.invalidTxndate");
}
Short personnelId = this.getUserContext().getId();
PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
this.setUpdatedBy(personnelId);
this.setUpdatedDate(transactionDate);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, getEarlyClosureAmount(), null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
this.addAccountPayment(accountPaymentEntity);
makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.LOAN_WRITTEN_OFF, AccountActionTypes.WRITEOFF, currentUser);
//for past arrears installments writeOff and reschedule are the same as 'make early repayment'
//but differ in processing for future installments
makeWriteOffOrReschedulePaymentForFutureInstallments(accountPaymentEntity, AccountConstants.LOAN_WRITTEN_OFF, AccountActionTypes.WRITEOFF, currentUser);
addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_WRITTEN_OFF, transactionDate));
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
// Client performance entry
updateCustomerHistoryOnWriteOff();
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method reschedule.
@Override
protected void reschedule(Date transactionDate) throws AccountException {
try {
if (!isTrxnDateValid(transactionDate, new CustomerPersistence().getLastMeetingDateForCustomer(getCustomer().getCustomerId()), new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled())) {
throw new BusinessRuleException("errors.invalidTxndate");
}
Short personnelId = this.getUserContext().getId();
PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
this.setUpdatedBy(personnelId);
this.setUpdatedDate(transactionDate);
AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(this, getEarlyClosureAmount(), null, null, getPaymentTypeEntity(Short.valueOf("1")), transactionDate);
this.addAccountPayment(accountPaymentEntity);
makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.LOAN_RESCHEDULED, AccountActionTypes.LOAN_RESCHEDULED, currentUser);
//for past arrears installments writeOff and reschedule are the same as 'make early repayment'
//but differ in processing for future installments
makeWriteOffOrReschedulePaymentForFutureInstallments(accountPaymentEntity, AccountConstants.LOAN_RESCHEDULED, AccountActionTypes.LOAN_RESCHEDULED, currentUser);
addLoanActivity(buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_RESCHEDULED, transactionDate));
buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
// Client performance entry using the same as write off.
updateCustomerHistoryOnWriteOff();
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method removePenalty.
public void removePenalty(Short penaltyId, Short personnelId) throws AccountException {
List<Short> installmentIds = getApplicableInstallmentIdsForRemovePenalties();
Money totalPenaltyAmount = Money.zero();
if (isPenaltyActive(penaltyId)) {
PenaltyBO penalty = getAccountPenaltyObject(penaltyId);
if (!installmentIds.isEmpty()) {
totalPenaltyAmount = totalPenaltyAmount.add(removePenaltyFromLoanScheduleEntity(installmentIds, penaltyId));
updateTotalPenaltyAmount(totalPenaltyAmount);
}
updateAccountPenaltiesEntity(penaltyId);
String description = penalty.getPenaltyName() + " " + AccountConstants.PENALTIES_REMOVED;
updateAccountActivity(null, null, totalPenaltyAmount, null, personnelId, description);
try {
ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
}
use of org.mifos.accounts.exceptions.AccountException in project head by mifos.
the class LoanBO method adjustLastPayment.
@Override
public void adjustLastPayment(final String adjustmentComment, PersonnelBO loggedInUser) throws AccountException {
if (isAdjustPossibleOnLastTrxn()) {
logger.debug("Adjustment is possible hence attempting to adjust.");
AccountPaymentEntity lastPmntToBeAdjusted = getLastPmntToBeAdjusted();
Money equalizingPaymentAmount = lastPmntToBeAdjusted.getAmount();
short equalizingPaymentTypeId = lastPmntToBeAdjusted.getPaymentType().getId();
Date equalizingPaymentDate = lastPmntToBeAdjusted.getPaymentDate();
adjustPayment(lastPmntToBeAdjusted, loggedInUser, adjustmentComment);
if (hasMemberAccounts()) {
for (LoanBO memberAccount : this.memberAccounts) {
memberAccount.setUserContext(this.userContext);
if (memberAccount.isGroupLoanAccountMember()) {
memberAccount.adjustLastPaymentForMember(lastPmntToBeAdjusted, adjustmentComment, loggedInUser);
} else {
memberAccount.adjustLastPayment(adjustmentComment, loggedInUser);
}
}
//MIFOS-5742: equalizing payment made to solve the problem with adjusting very small payment on GLIM account
PaymentData equalizingPaymentData = new PaymentData(equalizingPaymentAmount, loggedInUser, equalizingPaymentTypeId, equalizingPaymentDate);
BigDecimal installmentsPaid = findNumberOfPaidInstallments();
applyPaymentToMemberAccounts(equalizingPaymentData, installmentsPaid);
}
} else if (this.parentAccount == null) {
//MIFOS-5694: if member account has no payments it could mean that payment was made before 2.4.0, remove this condition when MIFOS-5692 is done
throw new AccountException(AccountExceptionConstants.CANNOTADJUST);
}
}
Aggregations