From 8fc0f732389fe854efd04d206b50987b82d0697f Mon Sep 17 00:00:00 2001 From: Kristof Jozsa Date: Thu, 6 Jun 2024 11:42:33 +0200 Subject: [PATCH] fix expectedDisbursementDate --- ...WritePlatformServiceJpaRepositoryImpl.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java index ba1dd77c50e..36752b7a634 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java @@ -574,19 +574,23 @@ public CommandProcessingResult approveApplication(final Long loanId, final JsonC } } - loanScheduleAssembler.validateDisbursementDateWithMeetingDates(expectedDisbursementDate, getCalendarInstance(loan), isSkipRepaymentOnFirstMonth, numberOfDays); + loanScheduleAssembler.validateDisbursementDateWithMeetingDates(expectedDisbursementDate, getCalendarInstance(loan), + isSkipRepaymentOnFirstMonth, numberOfDays); - final Map changes = loan.loanApplicationApproval(currentUser, command, disbursementDataArray, defaultLoanLifecycleStateMachine); + final Map changes = loan.loanApplicationApproval(currentUser, command, disbursementDataArray, + defaultLoanLifecycleStateMachine); - entityDatatableChecksWritePlatformService.runTheCheckForProduct(loanId, EntityTables.LOAN.getName(), StatusEnum.APPROVE.getCode().longValue(), EntityTables.LOAN.getForeignKeyColumnNameOnDatatable(), loan.productId()); + entityDatatableChecksWritePlatformService.runTheCheckForProduct(loanId, EntityTables.LOAN.getName(), + StatusEnum.APPROVE.getCode().longValue(), EntityTables.LOAN.getForeignKeyColumnNameOnDatatable(), loan.productId()); if (!changes.isEmpty()) { - if (changes.containsKey(LoanApiConstants.approvedLoanAmountParameterName) || changes.containsKey("recalculateLoanSchedule") || changes.containsKey("expectedDisbursementDate")) { + if (changes.containsKey(LoanApiConstants.approvedLoanAmountParameterName) || changes.containsKey("recalculateLoanSchedule") + || changes.containsKey("expectedDisbursementDate")) { loan.regenerateRepaymentSchedule(loanUtilService.buildScheduleGeneratorDTO(loan, null)); } if (loan.isTopup() && loan.getClientId() != null) { - validateTopupLoan(loan); + validateTopupLoan(loan, expectedDisbursementDate); } loan = this.loanRepository.saveAndFlush(loan); @@ -614,29 +618,34 @@ public CommandProcessingResult approveApplication(final Long loanId, final JsonC } private Calendar getCalendarInstance(Loan loan) { - CalendarInstance calendarInstance = calendarInstanceRepository.findCalendarInstaneByEntityId(loan.getId(), CalendarEntityType.LOANS.getValue()); + CalendarInstance calendarInstance = calendarInstanceRepository.findCalendarInstaneByEntityId(loan.getId(), + CalendarEntityType.LOANS.getValue()); return calendarInstance != null ? calendarInstance.getCalendar() : null; } private boolean isLoanRepaymentsSyncWithMeeting(Loan loan, Calendar calendar) { - return configurationDomainService.isSkippingMeetingOnFirstDayOfMonthEnabled() && loanUtilService.isLoanRepaymentsSyncWithMeeting(loan.group(), calendar); + return configurationDomainService.isSkippingMeetingOnFirstDayOfMonthEnabled() + && loanUtilService.isLoanRepaymentsSyncWithMeeting(loan.group(), calendar); } - private void validateTopupLoan(Loan loan) { + private void validateTopupLoan(Loan loan, LocalDate expectedDisbursementDate) { final Long loanIdToClose = loan.getTopupLoanDetails().getLoanIdToClose(); final Loan loanToClose = loanRepositoryWrapper.findNonClosedLoanThatBelongsToClient(loanIdToClose, loan.getClientId()); if (loanToClose == null) { - throw new GeneralPlatformDomainRuleException("error.msg.loan.to.be.closed.with.topup.is.not.active", "Loan to be closed with this topup is not active."); + throw new GeneralPlatformDomainRuleException("error.msg.loan.to.be.closed.with.topup.is.not.active", + "Loan to be closed with this topup is not active."); } final LocalDate lastUserTransactionOnLoanToClose = loanToClose.getLastUserTransactionDate(); if (DateUtils.isBefore(loan.getDisbursementDate(), lastUserTransactionOnLoanToClose)) { throw new GeneralPlatformDomainRuleException( "error.msg.loan.disbursal.date.should.be.after.last.transaction.date.of.loan.to.be.closed", - "Disbursal date of this loan application " + loan.getDisbursementDate() + " should be after last transaction date of loan to be closed " + lastUserTransactionOnLoanToClose); + "Disbursal date of this loan application " + loan.getDisbursementDate() + + " should be after last transaction date of loan to be closed " + lastUserTransactionOnLoanToClose); } - BigDecimal loanOutstanding = loanReadPlatformService.retrieveLoanPrePaymentTemplate(LoanTransactionType.REPAYMENT, loanIdToClose, expectedDisbursementDate).getAmount(); + BigDecimal loanOutstanding = loanReadPlatformService + .retrieveLoanPrePaymentTemplate(LoanTransactionType.REPAYMENT, loanIdToClose, expectedDisbursementDate).getAmount(); final BigDecimal firstDisbursalAmount = loan.getFirstDisbursalAmount(); if (loanOutstanding.compareTo(firstDisbursalAmount) > 0) { throw new GeneralPlatformDomainRuleException("error.msg.loan.amount.less.than.outstanding.of.loan.to.be.closed",