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;
}
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;
}
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());
}
}
Aggregations