Search in sources :

Example 1 with AmountWithInterest

use of org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest in project head by mifos.

the class LoanAccountServiceFacadeWebTier method generateAmountWithInterest.

private Map<String, AmountWithInterest> generateAmountWithInterest(Map<String, Double> memberNumWithAmount, RepayLoanInfoDto parentRLIDto) {
    Map<String, AmountWithInterest> awi = new HashMap<String, AmountWithInterest>();
    for (Map.Entry<String, Double> entry : memberNumWithAmount.entrySet()) {
        LoanBO loan = this.loanDao.findById(Integer.valueOf(entry.getKey()));
        String globalAccountNum = loan.getGlobalAccountNum();
        RepayLoanDto memberRLDto = retrieveLoanRepaymentDetails(globalAccountNum);
        RepayLoanInfoDto memberRLIDto = new RepayLoanInfoDto(globalAccountNum, memberRLDto.getEarlyRepaymentMoney(), parentRLIDto.getReceiptNumber(), parentRLIDto.getReceiptDate(), parentRLIDto.getPaymentTypeId(), parentRLIDto.getId(), parentRLIDto.isWaiveInterest(), parentRLIDto.getDateOfPayment(), new BigDecimal(entry.getValue()), new BigDecimal(memberRLDto.getWaivedRepaymentMoney()));
        awi.put(entry.getKey(), new org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest(entry.getValue(), calculateInterestDueForCurrentInstalmanet(memberRLIDto)));
    }
    return awi;
}
Also used : AmountWithInterest(org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) AmountWithInterest(org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest) BigDecimal(java.math.BigDecimal) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) AccountPaymentDto(org.mifos.dto.screen.AccountPaymentDto) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 2 with AmountWithInterest

use of org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest in project head by mifos.

the class LoanBO method makeEarlyRepayment.

public void makeEarlyRepayment(final AccountPaymentDto paymentDto, final Short personnelId, boolean waiveInterest, Money interestDue, Integer savingsPaymentId, AccountPaymentEntity parentPayment) throws AccountException {
    try {
        PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
        this.setUpdatedBy(personnelId);
        this.setUpdatedDate(paymentDto.getTransactionDate());
        AccountPaymentEntity accountPaymentEntity;
        if (this.isGroupLoanAccount() && null != this.getParentAccount()) {
            accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate(), parentPayment);
        } else {
            accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate());
        }
        if (savingsPaymentId != null) {
            AccountPaymentEntity withdrawal = legacyAccountDao.findPaymentById(savingsPaymentId);
            accountPaymentEntity.setOtherTransferPayment(withdrawal);
        }
        addAccountPayment(accountPaymentEntity);
        makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
        makeEarlyRepaymentForNextInstallment(currentUser, accountPaymentEntity, waiveInterest, interestDue);
        makeEarlyRepaymentForFutureInstallments(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
        if (getPerformanceHistory() != null) {
            getPerformanceHistory().setNoOfPayments(getPerformanceHistory().getNoOfPayments() + 1);
        }
        LoanActivityEntity loanActivity = buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_REPAYMENT, paymentDto.getTransactionDate());
        addLoanActivity(loanActivity);
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
        AccountStateEntity newAccountState = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET);
        addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(getAccountState(), newAccountState, legacyPersonnelDao.getPersonnel(personnelId), this));
        setAccountState(legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET));
        changeStateForAllFees(FeeStatus.INACTIVE);
        setClosedDate(paymentDto.getTransactionDate());
        // Client performance entry
        updateCustomerHistoryOnRepayment();
        this.delete(loanArrearsAgingEntity);
        loanArrearsAgingEntity = null;
        // GLIM
        if (this.isGroupLoanAccountParent()) {
            for (Entry<String, AmountWithInterest> entry : paymentDto.getMemberNumWithAmount().entrySet()) {
                AccountPaymentDto memberPayment = new AccountPaymentDto(entry.getValue().getAmount(), paymentDto.getTransactionDate(), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), paymentDto.getPaymentTypeId());
                legacyLoanDao.getAccount(Integer.valueOf(entry.getKey())).makeEarlyRepayment(memberPayment, personnelId, waiveInterest, new Money(this.getCurrency(), entry.getValue().getInterest()), null, accountPaymentEntity);
            }
        } else if (hasMemberAccounts() && !this.isGroupLoanAccount()) {
            for (LoanBO memberAccount : this.memberAccounts) {
                BigDecimal fraction = memberAccount.calcFactorOfEntireLoan();
                paymentDto.setTotalAmount(new BigDecimal(paymentDto.getTotalAmount()).divide(fraction, RoundingMode.HALF_UP).doubleValue());
                memberAccount.makeEarlyRepayment(paymentDto, personnelId, waiveInterest, interestDue, null, null);
            }
        }
        this.legacyAccountDao.createOrUpdate(accountPaymentEntity);
        this.legacyAccountDao.createOrUpdate(this);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AmountWithInterest(org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) BigDecimal(java.math.BigDecimal) Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto)

Aggregations

BigDecimal (java.math.BigDecimal)2 AmountWithInterest (org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)1 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 AccountPaymentDto (org.mifos.dto.domain.AccountPaymentDto)1 AccountPaymentDto (org.mifos.dto.screen.AccountPaymentDto)1 RepayLoanDto (org.mifos.dto.screen.RepayLoanDto)1 RepayLoanInfoDto (org.mifos.dto.screen.RepayLoanInfoDto)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 Money (org.mifos.framework.util.helpers.Money)1