diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java index 44881edfc59..b81b218f16d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationReadPlatformServiceImpl.java @@ -81,9 +81,9 @@ public class PrequalificationReadPlatformServiceImpl implements Prequalification @Autowired public PrequalificationReadPlatformServiceImpl(final PlatformSecurityContext context, final PaginationHelper paginationHelper, - final DatabaseSpecificSQLGenerator sqlGenerator, final ColumnValidator columnValidator, - final CodeValueReadPlatformService codeValueReadPlatformService, final JdbcTemplate jdbcTemplate, - GenericDataService genericDataService) { + final DatabaseSpecificSQLGenerator sqlGenerator, final ColumnValidator columnValidator, + final CodeValueReadPlatformService codeValueReadPlatformService, final JdbcTemplate jdbcTemplate, + GenericDataService genericDataService) { this.context = context; this.codeValueReadPlatformService = codeValueReadPlatformService; this.jdbcTemplate = jdbcTemplate; @@ -311,7 +311,8 @@ private String buildSqlStringFromBlacklistCriteria(final SearchParameters search } if (agencyId != null) { - if (StringUtils.equals(searchParameters.getGroupingType(), "group") || StringUtils.equals(searchParameters.getType(), "checked")) { + if (StringUtils.equals(searchParameters.getGroupingType(), "group") + || StringUtils.equals(searchParameters.getType(), "checked")) { extraCriteria += " and ma.id = ? "; } else { extraCriteria += " and individualOffice.agency_id = ? "; @@ -447,7 +448,7 @@ private static final class PrequalificationsGroupMapper implements RowMapper changes = loan.undoDisbursal(scheduleGeneratorDTO, existingTransactionIds, existingReversedTransactionIds); + LocalDate localDate = DateUtils.getBusinessLocalDate(); + if (!changes.isEmpty()) { if (loan.isTopup() && loan.getClientId() != null) { final Long loanIdToClose = loan.getTopupLoanDetails().getLoanIdToClose(); @@ -933,7 +935,6 @@ public CommandProcessingResult undoLoanDisbursal(final Long loanId, final JsonCo Long userId = currentUser.getId(); if (loan.getCheque() != null) { final LocalDateTime localDateTime = DateUtils.getLocalDateTimeOfSystem(); - LocalDate localDate = DateUtils.getBusinessLocalDate(); Cheque cheque = loan.getCheque(); cheque.setStatus(BankChequeStatus.PENDING_VOIDANCE.getValue()); cheque.stampAudit(userId, localDateTime); @@ -953,6 +954,33 @@ public CommandProcessingResult undoLoanDisbursal(final Long loanId, final JsonCo this.noteRepository.save(note); } } + List savingsAccountTransactions = this.savingsAccountTransactionRepository + .findAllTransactionByLoanId(loanId); + + SavingsAccountTransaction holdTransaction = savingsAccountTransactions.stream().filter(sa -> sa.isAmountOnHoldNotReleased()) + .findFirst().orElse(null); + + if (holdTransaction != null) { + + SavingsAccount fromSavingsAccount = holdTransaction.getSavingsAccount(); + JsonObject requestData = command.parsedJson().getAsJsonObject(); + requestData.addProperty(fromOfficeIdParamName, fromSavingsAccount.officeId()); + requestData.addProperty(fromClientIdParamName, fromSavingsAccount.getClient().getId()); + requestData.addProperty(toClientIdParamName, loan.getClient().getId()); + requestData.addProperty(toOfficeIdParamName, loan.getOfficeId()); + final String dateFormat = "dd MMMM yyyy"; + final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat); + requestData.addProperty(transferDateParamName, localDate.format(dateTimeFormatter)); + requestData.addProperty(transferAmountParamName, holdTransaction.getAmount()); + requestData.addProperty(transferDescriptionParamName, noteText); + final JsonCommand assemblerCommand = JsonCommand.fromJsonElement(loanId, requestData, this.fromApiJsonHelper); + assemblerCommand.setJsonCommand(requestData.toString()); + + // release loan guarantee to make payment + if (holdTransaction.getAmount().compareTo(BigDecimal.ZERO) > 0) + this.savingsAccountWritePlatformService.releaseLoanGuarantee(loanId, command, localDate, holdTransaction); + + } boolean isAccountTransfer = false; final Map accountingBridgeData = loan.deriveAccountingBridgeData(applicationCurrency.toData(), existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);