Skip to content

Commit

Permalink
Merge pull request #1207 from fiterlatam/fix/FSF-37-MAIN
Browse files Browse the repository at this point in the history
Fix/fsf 37 main
  • Loading branch information
BrianMuhimbura authored Oct 15, 2024
2 parents c2360ef + efbc17b commit de437b3
Show file tree
Hide file tree
Showing 16 changed files with 497 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4000,4 +4000,13 @@ public CommandWrapperBuilder assigntoPrequalificationSelf(Long prequalificationI
this.href = "/prequalification/assign/" + prequalificationId;
return this;
}

public CommandWrapperBuilder recalculateSavingsAccountBalances(Long accountId) {
this.actionName = "REBALANCE";
this.entityName = "SAVINGSACCOUNT";
this.entityId = accountId;
this.savingsId = accountId;
this.href = "/savingsaccounts/" + accountId + "rebalance";
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public BatchData mapRow(final ResultSet rs, final int rowNum) throws SQLExceptio

@Override
public Page<ChequeData> retrieveAll(final ChequeSearchParams chequeSearchParams, PaginationParameters parameters) {
final Set<String> supportedOrderByValues = new HashSet<>(List.of("chequeNo"));
final Set<String> supportedOrderByValues = new HashSet<>(List.of("chequeNo", "batchNo", "batchNo, chequeNo", "chequeNo, batchNo"));
this.paginationParametersDataValidator.validateParameterValues(parameters, supportedOrderByValues, "cheques");
final StringBuilder sqlBuilder = new StringBuilder(200);
sqlBuilder.append("SELECT ").append(this.sqlGenerator.calcFoundRows()).append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.data.PaginationParameters;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.infrastructure.core.serialization.JsonParserHelper;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.organisation.agency.domain.Agency;
import org.apache.fineract.organisation.bankAccount.domain.BankAccount;
Expand All @@ -57,7 +55,6 @@
import org.apache.fineract.organisation.bankcheque.command.UpdateChequeCommand;
import org.apache.fineract.organisation.bankcheque.command.VoidChequeCommand;
import org.apache.fineract.organisation.bankcheque.data.ChequeData;
import org.apache.fineract.organisation.bankcheque.data.ChequeSearchParams;
import org.apache.fineract.organisation.bankcheque.domain.BankChequeStatus;
import org.apache.fineract.organisation.bankcheque.domain.Batch;
import org.apache.fineract.organisation.bankcheque.domain.Cheque;
Expand Down Expand Up @@ -221,17 +218,12 @@ public CommandProcessingResult reassignCheque(final Long chequeId, JsonCommand c
throw new BankChequeException("status", "invalid.loan.status.for.cheque.reassignment");
}

final PaginationParameters parameters = PaginationParameters.instance(null, null, null, null, null);
final ChequeSearchParams chequeSearchParams = ChequeSearchParams.builder().chequeId(reassignChequeCommand.getOldChequeId()).build();
final Page<ChequeData> cheques = this.chequeReadPlatformService.retrieveAll(chequeSearchParams, parameters);
if (!CollectionUtils.isEmpty(cheques.getPageItems())) {
final ChequeData chequeData = cheques.getPageItems().get(0);
if (chequeData.getId().equals(reassignChequeCommand.getOldChequeId()) && chequeData.getLoanAccId() != null) {
final Long loanId = chequeData.getLoanAccId();
final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId);
loan.setCheque(newCheque);
this.loanRepositoryWrapper.saveAndFlush(loan);
}
final ChequeData chequeData = this.chequeReadPlatformService.retrieveChequeById(oldCheque.getId());
if (chequeData != null && chequeData.getLoanAccId() != null) {
final Long loanId = chequeData.getLoanAccId();
final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId);
loan.setCheque(newCheque);
this.loanRepositoryWrapper.saveAndFlush(loan);
}
final String newChequeDescription = "Emitido por sustitución de Desembolso cheque " + oldCheque.getChequeNo();
final String oldChequeDescription = "Cheque anulado por proceso de Reasignación, cheque nuevo " + newCheque.getChequeNo();
Expand Down Expand Up @@ -259,6 +251,7 @@ public CommandProcessingResult reassignCheque(final Long chequeId, JsonCommand c
newCheque.setIssuanceApprovedBy(oldCheque.getIssuanceApprovedBy());
newCheque.setIssuanceAuthorizeBy(oldCheque.getIssuanceAuthorizeBy());
newCheque.setIssuanceAuthorizeOnDate(oldCheque.getIssuanceAuthorizeOnDate());
newCheque.setNumeroCliente(oldCheque.getNumeroCliente());
newCheque.setIsReassigned(true);
this.chequeJpaRepository.saveAll(List.of(oldCheque, newCheque));
return new CommandProcessingResultBuilder().withCommandId(command.commandId())
Expand Down Expand Up @@ -490,49 +483,53 @@ public CommandProcessingResult printCheques(JsonCommand command) {
throw new BankChequeException("guarantee.savings.account.not.found",
"Guarantee savings is not found for client ID" + numeroCliente);
}
BigDecimal availableBalance = BigDecimal.ZERO;
final SavingsAccountData savingsAccountData = savingsAccountDataOptional.get();
final Long savingsAccountId = savingsAccountData.getId();
if (savingsAccountData.getSummary() != null) {
availableBalance = savingsAccountData.getSummary().getAvailableBalance();
}
if (guaranteeAmount.compareTo(availableBalance) > 0) {
throw new BankChequeException("guarantee.amount.greater.than.available.savings.account.balance",
"Guarantee amount is greater than savings account balance of" + availableBalance);
}
final String localeAsString = "en";
final String dateFormat = "dd MMMM yyyy";
final JsonObject jsonObject = new JsonObject();
final LocalDate localDate = DateUtils.getBusinessLocalDate();
Locale locale = JsonParserHelper.localeFromString(localeAsString);
final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat).withLocale(locale);
final String localDateString = localDate.format(dateTimeFormatter);
jsonObject.addProperty("locale", localeAsString);
jsonObject.addProperty("dateFormat", dateFormat);
jsonObject.addProperty("transactionAmount", guaranteeAmount);
jsonObject.addProperty("transactionDate", localDateString);
if (!CollectionUtils.isEmpty(paymentTypeOptions)) {
Optional<PaymentTypeData> paymentTypeOptional = new ArrayList<>(paymentTypeOptions).stream()
.filter(pt -> BankChequeApiConstants.BANK_CHEQUE_PAYMENT_TYPE.equalsIgnoreCase(pt.getName())).findFirst();
if (paymentTypeOptional.isPresent()) {
PaymentTypeData paymentType = paymentTypeOptional.get();
jsonObject.addProperty("paymentTypeId", paymentType.getId());

if (!chequeData.getReassingedCheque()) {
BigDecimal availableBalance = BigDecimal.ZERO;
final SavingsAccountData savingsAccountData = savingsAccountDataOptional.get();
final Long savingsAccountId = savingsAccountData.getId();
if (savingsAccountData.getSummary() != null) {
availableBalance = savingsAccountData.getSummary().getAvailableBalance();
}
if (guaranteeAmount.compareTo(availableBalance) > 0) {
throw new BankChequeException("guarantee.amount.greater.than.available.savings.account.balance",
"Guarantee amount is greater than savings account balance of" + availableBalance);
}
final String localeAsString = "en";
final String dateFormat = "dd MMMM yyyy";
final JsonObject jsonObject = new JsonObject();
final LocalDate localDate = DateUtils.getBusinessLocalDate();
Locale locale = JsonParserHelper.localeFromString(localeAsString);
final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat).withLocale(locale);
final String localDateString = localDate.format(dateTimeFormatter);
jsonObject.addProperty("locale", localeAsString);
jsonObject.addProperty("dateFormat", dateFormat);
jsonObject.addProperty("transactionAmount", guaranteeAmount);
jsonObject.addProperty("transactionDate", localDateString);
if (!CollectionUtils.isEmpty(paymentTypeOptions)) {
Optional<PaymentTypeData> paymentTypeOptional = new ArrayList<>(paymentTypeOptions).stream()
.filter(pt -> BankChequeApiConstants.BANK_CHEQUE_PAYMENT_TYPE.equalsIgnoreCase(pt.getName())).findFirst();
if (paymentTypeOptional.isPresent()) {
PaymentTypeData paymentType = paymentTypeOptional.get();
jsonObject.addProperty("paymentTypeId", paymentType.getId());
}
}
jsonObject.addProperty("accountNumber", bankAccNo);
jsonObject.addProperty("checkNumber", chequeData.getChequeNo());
jsonObject.addProperty("receiptNumber", chequeData.getGuaranteeId());
jsonObject.addProperty("bankNumber", chequeData.getBankName());
jsonObject.addProperty("glAccountId", chequeData.getGlAccountId());
jsonObject.addProperty("routingCode", "");
final String note = "Retiro de garantía por ID de garantía " + guaranteeId;
jsonObject.addProperty("note", note);
final JsonCommand withdrawalJsonCommand = JsonCommand.fromJsonElement(savingsAccountId, jsonObject,
this.fromApiJsonHelper);
withdrawalJsonCommand.setJsonCommand(jsonObject.toString());
CommandProcessingResult result = this.savingsAccountWritePlatformService.withdrawal(savingsAccountId,
withdrawalJsonCommand);
if (result != null) {
log.info("Guarantee withdrawal is successful for savings account ID {}", result.getSavingsId());
}
}
jsonObject.addProperty("accountNumber", bankAccNo);
jsonObject.addProperty("checkNumber", chequeData.getChequeNo());
jsonObject.addProperty("receiptNumber", chequeData.getGuaranteeId());
jsonObject.addProperty("bankNumber", chequeData.getBankName());
jsonObject.addProperty("glAccountId", chequeData.getGlAccountId());
jsonObject.addProperty("routingCode", "");
final String note = "Retiro de garantía por ID de garantía " + guaranteeId;
jsonObject.addProperty("note", note);
final JsonCommand withdrawalJsonCommand = JsonCommand.fromJsonElement(savingsAccountId, jsonObject, this.fromApiJsonHelper);
withdrawalJsonCommand.setJsonCommand(jsonObject.toString());
CommandProcessingResult result = this.savingsAccountWritePlatformService.withdrawal(savingsAccountId,
withdrawalJsonCommand);
if (result != null) {
log.info("Guarantee withdrawal is successful for savings account ID {}", result.getSavingsId());
}
}
if (chequeAmount != null) {
Expand Down
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
Loading

0 comments on commit de437b3

Please sign in to comment.