Search in sources :

Example 11 with Money

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);
            }
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money)

Example 12 with Money

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;
}
Also used : Money(org.mifos.framework.util.helpers.Money) MeetingBO(org.mifos.application.meeting.business.MeetingBO) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Example 13 with Money

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);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 14 with Money

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;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity)

Example 15 with Money

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());
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Aggregations

Money (org.mifos.framework.util.helpers.Money)688 Test (org.junit.Test)326 Date (java.util.Date)110 ArrayList (java.util.ArrayList)93 LocalDate (org.joda.time.LocalDate)90 Date (java.sql.Date)85 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)80 DateTime (org.joda.time.DateTime)67 LoanBO (org.mifos.accounts.loan.business.LoanBO)64 MeetingBO (org.mifos.application.meeting.business.MeetingBO)57 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)56 BigDecimal (java.math.BigDecimal)53 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)49 AccountException (org.mifos.accounts.exceptions.AccountException)48 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)46 UserContext (org.mifos.security.util.UserContext)46 CustomerBO (org.mifos.customers.business.CustomerBO)39 MifosUser (org.mifos.security.MifosUser)35 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)34 PaymentData (org.mifos.accounts.util.helpers.PaymentData)34