use of org.mifos.accounts.loan.business.service.LoanScheduleGenerationDto in project head by mifos.
the class StandardAccountService method handleLoanDisbursal.
public void handleLoanDisbursal(Locale locale, LoanBO loan, PersonnelBO personnelBO, BigDecimal paymentAmount, PaymentTypeDto paymentType, LocalDate receiptLocalDate, LocalDate paymentLocalDate, String receiptId, Short paymentTypeIdForFees, Integer accountForTransferId) throws PersistenceException, AccountException {
if ("MPESA".equals(paymentType.getName())) {
paymentAmount = computeWithdrawnForMPESA(paymentAmount, loan);
}
PaymentTypeEntity paymentTypeEntity = legacyMasterDao.getPersistentObject(PaymentTypeEntity.class, paymentType.getValue());
Money amount = new Money(loan.getCurrency(), paymentAmount);
Date receiptDate = null;
if (null != receiptLocalDate) {
receiptDate = receiptLocalDate.toDateMidnight().toDate();
}
Date transactionDate = paymentLocalDate.toDateMidnight().toDate();
AccountPaymentEntity disbursalPayment = new AccountPaymentEntity(loan, amount, receiptId, receiptDate, paymentTypeEntity, transactionDate);
disbursalPayment.setCreatedByUser(personnelBO);
Double interestRate = loan.getInterestRate();
Date oldDisbursementDate = loan.getDisbursementDate();
List<RepaymentScheduleInstallment> originalInstallments = loan.toRepaymentScheduleDto(locale);
loan.disburseLoan(disbursalPayment, paymentTypeIdForFees, accountForTransferId);
if (!loan.isVariableInstallmentsAllowed()) {
originalInstallments = loan.toRepaymentScheduleDto(locale);
}
Date newDisbursementDate = loan.getDisbursementDate();
boolean variableInstallmentsAllowed = loan.isVariableInstallmentsAllowed();
loanBusinessService.adjustDatesForVariableInstallments(variableInstallmentsAllowed, loan.isFixedRepaymentSchedule(), originalInstallments, oldDisbursementDate, newDisbursementDate, loan.getOfficeId());
Date today = new LocalDate().toDateMidnight().toDate();
Date disburseDay = new LocalDate(oldDisbursementDate).toDateMidnight().toDate();
if (!today.equals(disburseDay)) {
loanBusinessService.applyDailyInterestRatesWhereApplicable(new LoanScheduleGenerationDto(newDisbursementDate, loan, variableInstallmentsAllowed, amount, interestRate), originalInstallments);
}
loanBusinessService.persistOriginalSchedule(loan);
}
Aggregations