Search in sources :

Example 1 with LoanScheduleGenerationDto

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);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) LoanScheduleGenerationDto(org.mifos.accounts.loan.business.service.LoanScheduleGenerationDto) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Aggregations

Date (java.util.Date)1 LocalDate (org.joda.time.LocalDate)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 LoanScheduleGenerationDto (org.mifos.accounts.loan.business.service.LoanScheduleGenerationDto)1 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)1 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)1 Money (org.mifos.framework.util.helpers.Money)1