use of org.mifos.framework.util.helpers.Money in project head by mifos.
the class LoanBO method makeEarlyRepaymentForNextInstallment.
private void makeEarlyRepaymentForNextInstallment(PersonnelBO currentUser, AccountPaymentEntity accountPaymentEntity, boolean waiveInterest, Money interestDue) {
AccountActionDateEntity nextInstallment = getDetailsOfNextInstallment();
if (nextInstallment != null && nextInstallment.isNotPaid()) {
if (waiveInterest) {
repayInstallmentWithInterestWaiver(nextInstallment, accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
} else {
LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) nextInstallment;
Money originalInterestDue = loanScheduleEntity.getInterestDue();
repayInstallment(loanScheduleEntity, accountPaymentEntity, AccountActionTypes.LOAN_REPAYMENT, currentUser, AccountConstants.PAYMENT_RCVD, interestDue);
if (isDecliningBalanceInterestRecalculation()) {
loanSummary.decreaseBy(null, originalInterestDue.subtract(interestDue), null, null);
}
}
}
}
use of org.mifos.framework.util.helpers.Money in project head by mifos.
the class LoanBO method handlePeriodic.
/**
* Calculate and return the list of {@link FeeInstallment}s to be applied. A fee installment will apply to one of
* the given loan installmentDates if the installmentIds match. Here's the criteria for matching a fee installment
* to a loan installment: Calculate the dates in nonAdjustedInstallmentDates that the fee would be due if the fee
* were to start today. For each unadjusted fee date, build a FeeInstallment object based on the installmentId of
* the nearest loan installment date in the list installmentDates (this is what causes fees to pile up on a future
* loan installment that has been pushed out of a holiday), and add it to the list to be returned.
*/
@Override
protected final List<FeeInstallment> handlePeriodic(final AccountFeesEntity accountFees, final List<InstallmentDate> installmentDates, final List<InstallmentDate> nonAdjustedInstallmentDates) throws AccountException {
Money accountFeeAmount = accountFees.getAccountFeeAmount();
MeetingBO feeMeetingFrequency = accountFees.getFees().getFeeFrequency().getFeeMeetingFrequency();
// Generate the dates in nonAdjustedInstallmentDates that the fee would be due if
// the fee were to start today
List<Date> feeDates = getFeeDates(feeMeetingFrequency, nonAdjustedInstallmentDates, false);
// For each unadjusted fee date, build a FeeInstallment object based on the installmentId of the
// nearest loan installment date adjusted for holidays (this is what causes fees to pile up
// on a future loan installment that has been pushed out of a holiday), and add it to the list to
// be returned
ListIterator<Date> feeDatesIterator = feeDates.listIterator();
List<FeeInstallment> feeInstallmentList = new ArrayList<FeeInstallment>();
while (feeDatesIterator.hasNext()) {
Date feeDate = feeDatesIterator.next();
logger.debug("Handling periodic fee.." + feeDate);
Short installmentId = getMatchingInstallmentId(installmentDates, feeDate);
feeInstallmentList.add(buildFeeInstallment(installmentId, accountFeeAmount, accountFees));
}
return feeInstallmentList;
}
use of org.mifos.framework.util.helpers.Money in project head by mifos.
the class LoanBO method waiveFeeAmountOverDue.
private void waiveFeeAmountOverDue() throws AccountException {
Money chargeWaived = new Money(getCurrency());
Money principal = new Money(getCurrency());
Money interest = new Money(getCurrency());
Money penalty = new Money(getCurrency());
List<AccountActionDateEntity> accountActionDateList = getApplicableIdsForNextInstallmentAndArrears();
// installment.
if (getDetailsOfNextInstallment() != null) {
accountActionDateList.remove(accountActionDateList.size() - 1);
}
for (AccountActionDateEntity accountActionDateEntity : accountActionDateList) {
chargeWaived = chargeWaived.add(((LoanScheduleEntity) accountActionDateEntity).waiveFeeCharges());
}
if (chargeWaived != null && chargeWaived.isGreaterThanZero()) {
updateTotalFeeAmount(chargeWaived);
updateAccountActivity(principal, interest, chargeWaived, penalty, userContext.getId(), AccountConstants.AMOUNT + chargeWaived + AccountConstants.WAIVED);
waiveOverdueChargesFromMemberAccounts(LoanConstants.FEE_WAIVED);
}
try {
getlegacyLoanDao().createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.framework.util.helpers.Money in project head by mifos.
the class LoanBO method getTotalPrincipalAmount.
public Money getTotalPrincipalAmount() {
Money amount = new Money(getCurrency());
List<AccountActionDateEntity> installments = getAllInstallments();
for (AccountActionDateEntity accountActionDateEntity : installments) {
amount = amount.add(((LoanScheduleEntity) accountActionDateEntity).getPrincipal());
}
return amount;
}
use of org.mifos.framework.util.helpers.Money in project head by mifos.
the class LoanBO method disburse.
public void disburse(PersonnelBO createdBy, AccountPaymentEntity disbursalPayment) throws AccountException {
Date transactionDate = disbursalPayment.getPaymentDate();
addLoanActivity(buildLoanActivity(getLoanAmount(), createdBy, AccountConstants.LOAN_DISBURSAL, transactionDate));
final AccountStateEntity newState = new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(getAccountState(), newState, createdBy, this));
setAccountState(newState);
if (getPerformanceHistory() != null) {
getPerformanceHistory().setLoanMaturityDate(getLastInstallmentAccountAction().getActionDate());
}
// build up account payment related data
AccountPaymentEntity accountPayment = null;
// Disbursal process has to create its own accountPayment taking into account any disbursement fees
Money feeAmountAtDisbursement = getFeesDueAtDisbursement();
accountPayment = new AccountPaymentEntity(this, getLoanAmount().subtract(feeAmountAtDisbursement), disbursalPayment.getReceiptNumber(), disbursalPayment.getReceiptDate(), getPaymentTypeEntity(disbursalPayment.getPaymentType().getId()), transactionDate);
accountPayment.setCreatedByUser(createdBy);
if (feeAmountAtDisbursement.isGreaterThanZero()) {
processFeesAtDisbursement(accountPayment, feeAmountAtDisbursement, disbursalPayment.getOtherTransferPaymentDto().getPaymentTypeId(), disbursalPayment.getOtherTransferPayment().getAccount().getAccountId());
}
// create trxn entry for disbursal
final LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPayment, AccountActionTypes.DISBURSAL, Short.valueOf("0"), transactionDate, createdBy, transactionDate, getLoanAmount(), "-", null, getLoanAmount(), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
accountPayment.addAccountTrxn(loanTrxnDetailEntity);
addAccountPayment(accountPayment);
buildFinancialEntries(accountPayment.getAccountTrxns());
}
Aggregations