Search in sources :

Example 1 with LoanPaymentTypes

use of org.mifos.accounts.loan.util.helpers.LoanPaymentTypes in project head by mifos.

the class LoanBO method makePayment.

/*
     * PaymentData is the payment information entered in the UI An AccountPaymentEntity is created from the PaymentData
     * passed in.
     */
@Override
protected AccountPaymentEntity makePayment(final PaymentData paymentData) throws AccountException {
    AccountPaymentEntity accountPaymentEntity = prePayment(paymentData);
    LoanPaymentTypes loanPaymentType = getLoanPaymentType(paymentData.getTotalAmount());
    ApplicationContextProvider.getBean(LoanBusinessService.class).applyPayment(paymentData, this, accountPaymentEntity);
    postPayment(paymentData, accountPaymentEntity, loanPaymentType);
    if (paymentData.getOverpaymentAmount() != null) {
        AccountOverpaymentEntity overpaymentEntity = new AccountOverpaymentEntity(this, accountPaymentEntity, paymentData.getOverpaymentAmount(), OverpaymentStatus.UNCLEARED.getValue());
        addAccountOverpayment(overpaymentEntity);
    }
    // GLIM
    BigDecimal installmentsPaid = findNumberOfPaidInstallments();
    applyPaymentToMemberAccounts(paymentData, installmentsPaid);
    return accountPaymentEntity;
}
Also used : LoanBusinessService(org.mifos.accounts.loan.business.service.LoanBusinessService) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LoanPaymentTypes(org.mifos.accounts.loan.util.helpers.LoanPaymentTypes) BigDecimal(java.math.BigDecimal) AccountOverpaymentEntity(org.mifos.accounts.business.AccountOverpaymentEntity)

Example 2 with LoanPaymentTypes

use of org.mifos.accounts.loan.util.helpers.LoanPaymentTypes in project head by mifos.

the class LoanBO method applyNewPaymentMechanism.

public Money applyNewPaymentMechanism(LocalDate paymentDate, BigDecimal repaymentAmount, PersonnelBO user, String receiptId, LocalDate receiptDate, Short modeOfPayment) throws AccountException {
    Money totalAmount = new Money(getCurrency(), repaymentAmount);
    Date transactionDate = paymentDate.toDateMidnight().toDate();
    PaymentData paymentData = new PaymentData(totalAmount, user, modeOfPayment, transactionDate);
    if (receiptId != null) {
        paymentData.setReceiptNum(receiptId);
    }
    if (receiptDate != null) {
        paymentData.setReceiptDate(receiptDate.toDateMidnight().toDate());
    }
    AccountPaymentEntity accountPaymentEntity = prePayment(paymentData);
    Money balance = totalAmount;
    LoanPaymentTypes loanPaymentType = getLoanPaymentType(paymentData.getTotalAmount());
    // 1. pay off installments in arrears
    List<AccountActionDateEntity> inArrears = getDetailsOfInstallmentsInArrearsOn(paymentDate);
    for (AccountActionDateEntity accountActionDate : inArrears) {
        balance = ((LoanScheduleEntity) accountActionDate).applyPayment(accountPaymentEntity, balance, user, transactionDate);
    }
    // 2. pay off due installment (normal way)
    if (balance.isGreaterThanZero()) {
        AccountActionDateEntity upcomingInstallment = getDetailsOfNextInstallmentOn(paymentDate);
        balance = ((LoanScheduleEntity) upcomingInstallment).applyPayment(accountPaymentEntity, balance, user, transactionDate);
    }
    if (!accountPaymentEntity.getAccountTrxns().isEmpty()) {
        postPayment(paymentData, accountPaymentEntity, loanPaymentType);
        addAccountPayment(accountPaymentEntity);
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
    }
    return balance;
}
Also used : Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LoanPaymentTypes(org.mifos.accounts.loan.util.helpers.LoanPaymentTypes) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Example 3 with LoanPaymentTypes

use of org.mifos.accounts.loan.util.helpers.LoanPaymentTypes in project head by mifos.

the class LoanBO method recordOverpayment.

public void recordOverpayment(Money balance, LocalDate paymentDate, PersonnelBO user, String receiptId, LocalDate receiptDate, Short modeOfPayment) throws AccountException {
    if (balance.isGreaterThanZero()) {
        Date transactionDate = paymentDate.toDateMidnight().toDate();
        PaymentData paymentData = new PaymentData(balance, user, modeOfPayment, transactionDate);
        if (receiptId != null) {
            paymentData.setReceiptNum(receiptId);
        }
        if (receiptDate != null) {
            paymentData.setReceiptDate(receiptDate.toDateMidnight().toDate());
        }
        AccountPaymentEntity accountPaymentEntity = prePayment(paymentData);
        // update
        Money overpayment = balance;
        List<AccountActionDateEntity> paidInstallments = getDetailsOfPaidInstallmentsOn(paymentDate);
        if (!paidInstallments.isEmpty()) {
            LoanScheduleEntity lastFullyPaidInstallment = (LoanScheduleEntity) paidInstallments.get(paidInstallments.size() - 1);
            lastFullyPaidInstallment.updatePrincipalPaidby(accountPaymentEntity, user);
            LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPaymentEntity, lastFullyPaidInstallment, user, transactionDate, AccountActionTypes.LOAN_REPAYMENT, AccountConstants.PAYMENT_RCVD, legacyLoanDao);
            accountPaymentEntity.addAccountTrxn(loanTrxnDetailEntity);
            PaymentAllocation paymentAllocation = new PaymentAllocation(overpayment.getCurrency());
            paymentAllocation.allocateForPrincipal(overpayment);
            this.loanSummary.updatePaymentDetails(paymentAllocation);
        }
        LoanPaymentTypes loanPaymentType = getLoanPaymentType(paymentData.getTotalAmount());
        postPayment(paymentData, accountPaymentEntity, loanPaymentType);
        addAccountPayment(accountPaymentEntity);
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
    }
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LoanPaymentTypes(org.mifos.accounts.loan.util.helpers.LoanPaymentTypes) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)3 LoanPaymentTypes (org.mifos.accounts.loan.util.helpers.LoanPaymentTypes)3 Date (java.util.Date)2 LocalDate (org.joda.time.LocalDate)2 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)2 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)2 PaymentData (org.mifos.accounts.util.helpers.PaymentData)2 Money (org.mifos.framework.util.helpers.Money)2 BigDecimal (java.math.BigDecimal)1 AccountOverpaymentEntity (org.mifos.accounts.business.AccountOverpaymentEntity)1 LoanBusinessService (org.mifos.accounts.loan.business.service.LoanBusinessService)1