Skip to content

Commit

Permalink
fix expectedDisbursementDate
Browse files Browse the repository at this point in the history
  • Loading branch information
kjozsa committed Jun 6, 2024
1 parent dbd256c commit 8fc0f73
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> changes = loan.loanApplicationApproval(currentUser, command, disbursementDataArray, defaultLoanLifecycleStateMachine);
final Map<String, Object> 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);
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 8fc0f73

Please sign in to comment.