From 1325016b3d4c816a1fe1745ba7514bb533c44de1 Mon Sep 17 00:00:00 2001 From: fiter-julius-oketayot <140818859+fiter-julius-oketayot@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:05:14 +0300 Subject: [PATCH] Bug/SU-480: Fix bulk import Cupo validation (#1368) --- .../ClientCupoDecrementImportHandler.java | 36 ++++++++++++------ .../ClientCupoIncrementImportHandler.java | 37 +++++++------------ .../data/ClientAdditionalFieldsData.java | 1 + .../service/ClientAdditionalFieldsMapper.java | 6 ++- 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/clientcupodecrement/ClientCupoDecrementImportHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/clientcupodecrement/ClientCupoDecrementImportHandler.java index cffc0872c72..895089216ac 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/clientcupodecrement/ClientCupoDecrementImportHandler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/clientcupodecrement/ClientCupoDecrementImportHandler.java @@ -29,6 +29,7 @@ import lombok.Data; import org.apache.commons.collections4.CollectionUtils; import org.apache.fineract.infrastructure.bulkimport.constants.ClientCupoDecrementConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.ClientCupoIncrementConstants; import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.bulkimport.data.Count; import org.apache.fineract.infrastructure.bulkimport.importhandler.ImportHandler; @@ -202,14 +203,25 @@ private Count importEntity(final Workbook workbook, final List 0) { + if (maximumCupoAmount.compareTo(totalOutstandingPrincipalAmount) < 0) { errorCount++; - errorMessage = "No puede modificarse ya que el nuevo cupo que sugiere es mayor al actual"; + errorMessage = "No se puede modificar ya que la nueva cuota sugerida es menor al capital pendiente actual: " + + totalOutstandingPrincipalAmount; + ImportHandlerUtils.writeErrorMessage(clientCupDecrementSheet, clientCupoDecrementData.getRowIndex(), errorMessage, + ClientCupoIncrementConstants.STATUS_COL); + clientCupDecrementSheet.setColumnWidth(ClientCupoIncrementConstants.STATUS_COL, + TemplatePopulateImportConstants.EXTRALARGE_COL_SIZE); + continue; + } + if (maximumCupoAmount.compareTo(previousMaximumCupoAmount) >= 0) { + errorCount++; + errorMessage = "No se puede modificar ya que la nueva cuota sugerida es mayor o igual a la actual."; ImportHandlerUtils.writeErrorMessage(clientCupDecrementSheet, clientCupoDecrementData.getRowIndex(), errorMessage, ClientCupoDecrementConstants.STATUS_COL); clientCupDecrementSheet.setColumnWidth(ClientCupoDecrementConstants.STATUS_COL, @@ -281,15 +293,17 @@ private Count importEntity(final Workbook workbook, final List errMesg; String errorMessage; final GsonBuilder gsonBuilder = GoogleGsonSerializerHelper.createGsonBuilder(); gsonBuilder.registerTypeAdapter(LocalDate.class, new DateSerializer(dateFormat, locale)); @@ -202,35 +201,27 @@ private Count importEntity(final Workbook workbook, final List 0) { - if (maximumCupoAmount.compareTo(totalOutstandingPrincipalAmount) < 0) { - errorCount++; - errorMessage = "No puede modificarse ya que el nuevo cupo que sugiere es menor al actual " - + totalOutstandingPrincipalAmount; - ImportHandlerUtils.writeErrorMessage(clientCupoIncrementSheet, clientCupoIncrementData.getRowIndex(), errorMessage, - ClientCupoIncrementConstants.STATUS_COL); - clientCupoIncrementSheet.setColumnWidth(ClientCupoIncrementConstants.STATUS_COL, - TemplatePopulateImportConstants.EXTRALARGE_COL_SIZE); - continue; - } + if (maximumCupoAmount.compareTo(totalOutstandingPrincipalAmount) < 0) { + errorCount++; + errorMessage = "No se puede modificar ya que la nueva cuota sugerida es menor al capital pendiente actual: " + + totalOutstandingPrincipalAmount; + ImportHandlerUtils.writeErrorMessage(clientCupoIncrementSheet, clientCupoIncrementData.getRowIndex(), errorMessage, + ClientCupoIncrementConstants.STATUS_COL); + clientCupoIncrementSheet.setColumnWidth(ClientCupoIncrementConstants.STATUS_COL, + TemplatePopulateImportConstants.EXTRALARGE_COL_SIZE); + continue; } - - if (maximumCupoAmount.compareTo(previousMaximumCupoAmount) < 0) { + if (maximumCupoAmount.compareTo(previousMaximumCupoAmount) <= 0) { errorCount++; - errorMessage = "No puede modificarse ya que el nuevo cupo que sugiere es menor al actual"; + errorMessage = "No se puede modificar ya que la nueva cuota sugerida es menor o igual a la actual."; ImportHandlerUtils.writeErrorMessage(clientCupoIncrementSheet, clientCupoIncrementData.getRowIndex(), errorMessage, ClientCupoIncrementConstants.STATUS_COL); clientCupoIncrementSheet.setColumnWidth(ClientCupoIncrementConstants.STATUS_COL, @@ -303,7 +294,7 @@ private Count importEntity(final Workbook workbook, final List 0) { final int affectedRows = jdbcTemplate.update(sql, maximumCupoAmount, clientId, documentNumber); if (affectedRows == 0) { errorCount++; diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAdditionalFieldsData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAdditionalFieldsData.java index a8bd128f53a..9f47f30a0f8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAdditionalFieldsData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAdditionalFieldsData.java @@ -43,6 +43,7 @@ public class ClientAdditionalFieldsData { private String clientName; private Integer legalForm; private BigDecimal totalOutstandingPrincipalAmount; + private BigDecimal otherTotalOutstandingPrincipalAmount; public boolean isPerson() { LegalForm legalForm = LegalForm.fromInt(this.legalForm); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAdditionalFieldsMapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAdditionalFieldsMapper.java index bf73520e87e..21e69d0c9fe 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAdditionalFieldsMapper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAdditionalFieldsMapper.java @@ -44,7 +44,8 @@ public String schema() { COALESCE(ccp."Cupo otros prestamos", cce."Cupo otros prestamos") AS otherLoansCupo, mc.legal_form_enum AS legalForm, mc.blocking_reason_id AS blockingReasonId, - (select COALESCE(SUM(ml.principal_outstanding_derived), 0) FROM m_loan ml WHERE ml.loan_status_id = 300 and client_id =mc.id) AS totalOutstandingPrincipalAmount + (SELECT COALESCE(SUM(ml.principal_outstanding_derived), 0) FROM m_loan ml INNER JOIN m_product_loan mpl ON mpl.id = ml.product_id WHERE ml.loan_status_id = 300 and ml.client_id = mc.id AND mpl.use_other_loans_cupo = FALSE) AS totalOutstandingPrincipalAmount, + (SELECT COALESCE(SUM(ml.principal_outstanding_derived), 0) FROM m_loan ml INNER JOIN m_product_loan mpl ON mpl.id = ml.product_id WHERE ml.loan_status_id = 300 and ml.client_id = mc.id AND mpl.use_other_loans_cupo = TRUE) AS otherTotalOutstandingPrincipalAmount FROM m_client mc LEFT JOIN campos_cliente_empresas cce ON cce.client_id = mc.id LEFT JOIN m_code_value tipo ON tipo.id = cce."Tipo ID_cd_Tipo ID" @@ -63,6 +64,7 @@ public ClientAdditionalFieldsData mapRow(@NotNull ResultSet rs, int rowNum) thro final int statusInt = rs.getInt("status"); final Long blockingReasonId = JdbcSupport.getLong(rs, "blockingReasonId"); final BigDecimal totalOutstandingPrincipalAmount = rs.getBigDecimal("totalOutstandingPrincipalAmount"); + final BigDecimal otherTotalOutstandingPrincipalAmount = rs.getBigDecimal("otherTotalOutstandingPrincipalAmount"); EnumOptionData statusData; if (blockingReasonId != null) { statusData = ClientEnumerations.status(ClientStatus.BLOCKED); @@ -72,6 +74,6 @@ public ClientAdditionalFieldsData mapRow(@NotNull ResultSet rs, int rowNum) thro final String clientName = rs.getString("clientName"); final Integer legalForm = JdbcSupport.getInteger(rs, "legalForm"); return new ClientAdditionalFieldsData(clientId, tipo, nit, cedula, cupo, otherLoansCupo, statusData, clientName, legalForm, - totalOutstandingPrincipalAmount); + totalOutstandingPrincipalAmount, otherTotalOutstandingPrincipalAmount); } }