Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FSF-37 #1187

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = ? ";
Expand Down Expand Up @@ -447,7 +448,7 @@ private static final class PrequalificationsGroupMapper implements RowMapper<Gro
greenValidCount AS greenValidationCount,
yellowValidCount AS yellowValidationCount,
orangeValidCount AS orangeValidationCount,
redValidCount AS redValidationCount
redValidCount AS redValidationCount
FROM
m_prequalification_group g
INNER JOIN m_appuser au ON au.id = g.added_by
Expand All @@ -456,19 +457,19 @@ LEFT JOIN (
SELECT
mpgm.group_id AS prequalification_id,
SUM( mpgm.requested_amount ) total_requested_amount,
SUM( mpgm.approved_amount ) total_approved_amount
SUM( mpgm.approved_amount ) total_approved_amount
FROM
m_prequalification_group_members mpgm
m_prequalification_group_members mpgm
GROUP BY
mpgm.group_id
) prequalification_numbers ON prequalification_numbers.prequalification_id = g.id
mpgm.group_id
) prequalification_numbers ON prequalification_numbers.prequalification_id = g.id
LEFT JOIN (
SELECT DISTINCT
mc.office_id,
ms.agency_id,
mag.NAME AS agency_name,
mpgm.group_id,
ms.linked_office_id AS supervision_office
ms.linked_office_id AS supervision_office
FROM
m_prequalification_group_members mpgm
INNER JOIN m_client mc ON mc.dpi = mpgm.dpi
Expand All @@ -477,7 +478,7 @@ LEFT JOIN (
INNER JOIN m_group center ON center.id = mg.parent_id
INNER JOIN m_portfolio mp ON mp.id = center.portfolio_id
INNER JOIN m_supervision ms ON ms.id = mp.supervision_id
INNER JOIN m_agency mag ON mag.id = ms.agency_id
INNER JOIN m_agency mag ON mag.id = ms.agency_id
) individualOffice ON individualOffice.group_id = g.id
LEFT JOIN m_agency ma ON g.agency_id = ma.id
LEFT JOIN ( SELECT agency_id, linked_office_id FROM m_supervision GROUP BY agency_id ) supv ON supv.agency_id = ma.id
Expand All @@ -489,24 +490,24 @@ LEFT JOIN (
COUNT( CASE WHEN mcvr.validation_color_enum = 1 THEN 1 END ) AS greenValidCount,
COUNT( CASE WHEN mcvr.validation_color_enum = 2 THEN 1 END ) AS yellowValidCount,
COUNT( CASE WHEN mcvr.validation_color_enum = 3 THEN 1 END ) AS orangeValidCount,
COUNT( CASE WHEN mcvr.validation_color_enum = 4 THEN 1 END ) AS redValidCount
COUNT( CASE WHEN mcvr.validation_color_enum = 4 THEN 1 END ) AS redValidCount
FROM
m_checklist_validation_result mcvr
m_checklist_validation_result mcvr
GROUP BY
mcvr.prequalification_id
mcvr.prequalification_id
) validations ON validations.prequalification_id = g.id
LEFT JOIN m_group cg ON cg.id = g.group_id
LEFT JOIN m_group linkedGroup ON linkedGroup.prequalification_id = g.id
LEFT JOIN m_group pc ON pc.id = g.center_id
LEFT JOIN m_prequalification_status_log sl ON sl.prequalification_id = g.id
AND sl.to_status = g.STATUS
LEFT JOIN m_prequalification_status_log sl ON sl.prequalification_id = g.id
AND sl.to_status = g.STATUS
AND sl.id = ( SELECT MAX( id ) FROM m_prequalification_status_log WHERE prequalification_id = g.id AND sl.to_status = g.STATUS )
LEFT JOIN m_appuser assigned ON assigned.id = sl.assigned_to
LEFT JOIN m_appuser mu ON mu.id = sl.updatedby_id
LEFT JOIN m_appuser fa ON fa.id = g.facilitator
LEFT JOIN ( SELECT count(*) AS reprocess_count, prequalification_id, to_status FROM
m_prequalification_status_log GROUP BY prequalification_id, to_status )
mpsl ON mpsl.prequalification_id = g.id
LEFT JOIN ( SELECT count(*) AS reprocess_count, prequalification_id, to_status FROM
m_prequalification_status_log GROUP BY prequalification_id, to_status )
mpsl ON mpsl.prequalification_id = g.id
""";

this.grpSchema = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ public CommandProcessingResult undoLoanDisbursal(final Long loanId, final JsonCo
final Map<String, Object> 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();
Expand All @@ -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);
Expand All @@ -953,6 +954,33 @@ public CommandProcessingResult undoLoanDisbursal(final Long loanId, final JsonCo
this.noteRepository.save(note);
}
}
List<SavingsAccountTransaction> 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<String, Object> accountingBridgeData = loan.deriveAccountingBridgeData(applicationCurrency.toData(),
existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
Expand Down
Loading