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