From a571dc0f2bdbe22f52c1bec5d3665aafaeebca77 Mon Sep 17 00:00:00 2001 From: tabrez-fiter Date: Tue, 10 Dec 2024 14:47:00 +0800 Subject: [PATCH 1/2] SU-488 : Archivo de Cartera - Departamento --- .../codes/domain/CodeValueRepository.java | 27 +++++++++++ .../ArchiveLoansHistoryTasklet.java | 47 +++++++++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java index 60ba58e5447..d85e3074696 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java @@ -18,12 +18,39 @@ */ package org.apache.fineract.infrastructure.codes.domain; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface CodeValueRepository extends JpaRepository, JpaSpecificationExecutor { CodeValue findByCodeNameAndId(String codeName, Long id); CodeValue findByCodeNameAndLabel(String codeName, String label); + + @Query(value = """ + SELECT + mv2.code_score AS ciudad_code_score, + mv2.code_value AS ciudad_code_value, + mcv.code_score AS departamento_code_score, + mcv.code_id AS departamento_code_id, + mcv.code_value AS departamento_code_value + FROM m_code_value mcv + INNER JOIN ( + SELECT *, + CASE + WHEN LEFT(LPAD(code_score::TEXT, 5, '0'), 2)::INTEGER < 10 THEN + LEFT(LPAD(code_score::TEXT, 5, '0'), 2)::INTEGER::VARCHAR + ELSE + LEFT(LPAD(code_score::TEXT, 5, '0'), 2) + END AS ciudadCoderScore + FROM m_code_value mcv2 + WHERE code_id = 41 + ) mv2 + ON mv2.ciudadCoderScore = mcv.code_score + WHERE mcv.code_id = 40 AND mv2.code_score = :codeScore + """, nativeQuery = true) + Optional findCiudadAndDepartamentoData(@Param("codeScore") String codeScore); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/archiveloanhistory/ArchiveLoansHistoryTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/archiveloanhistory/ArchiveLoansHistoryTasklet.java index 236d8994d81..7e4c3970993 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/archiveloanhistory/ArchiveLoansHistoryTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/jobs/archiveloanhistory/ArchiveLoansHistoryTasklet.java @@ -10,12 +10,14 @@ import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException; +import org.apache.fineract.portfolio.client.domain.ClientStatus; import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; import org.apache.fineract.portfolio.delinquency.service.DelinquencyReadPlatformService; import org.apache.fineract.portfolio.loanaccount.data.CollectionData; import org.apache.fineract.portfolio.loanaccount.data.LoanArchiveHistoryData; import org.apache.fineract.portfolio.loanaccount.domain.*; import org.apache.fineract.portfolio.loanaccount.rescheduleloan.service.LoanArchiveHistoryReadWritePlatformService; +import org.apache.fineract.portfolio.loanproduct.domain.LoanCustomizationDetail; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; @@ -206,9 +208,43 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon actividadLaboral = actividadLaboralCode.getLabel(); } } + + if (actividadLaboral.equals("PENSIONADO")) { + if (dataLoan.getCiudadPuntoCredito() != null) { + Optional getDepartamento = codeValueRepository + .findById(Long.valueOf(dataLoan.getCiudadPuntoCredito())); + if (getDepartamento.isPresent()) { + CodeValue departamento = getDepartamento.get(); + String departamentoScore = departamento.getScore(); + Optional personalDepartemento = codeValueRepository + .findCiudadAndDepartamentoData(departamentoScore); + if (personalDepartemento.isPresent()) { + departamentoCity = personalDepartemento.get().getLabel(); + } + } + } + } final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment = loan .fetchLoanForeclosureDetail(LocalDate.now()); BigDecimal creSaldo = loanRepaymentScheduleInstallment.getTotalOutstanding(loan.getCurrency()).getAmount(); + + String creEstad = ClientStatus.fromInt(loan.getClient().getStatus()).name(); + if (loan.getLoanCustomizationDetail() != null) { + LoanCustomizationDetail loanCustomizationDetail = loan.getLoanCustomizationDetail(); + if (loanCustomizationDetail.getBlockStatus() != null) { + creEstad = "BLOCKING"; + } + } + + String cuoEstado = dataLoan.getCuoEstado(); + if (cuoEstado == null || cuoEstado.equals("CASTIGO")) { + cuoEstado = loan.getStatus().name(); + } + + String estadoCliente = dataLoan.getEstadoCliente(); + if (estadoCliente == null || estadoCliente.equals("CASTIGO")) { + estadoCliente = ClientStatus.fromInt(loan.getClient().getStatus()).name(); + } if (existingLoanArchive.isPresent()) { LoanArchiveHistory existingEntry = existingLoanArchive.get(); @@ -217,7 +253,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon existingEntry.setSegundoNombre(dataLoan.getSegundoNombre()); existingEntry.setPrimerApellido(dataLoan.getPrimerApellido()); existingEntry.setSegundoApellido(dataLoan.getSegundoApellido()); - existingEntry.setEstadoCliente(dataLoan.getEstadoCliente()); + existingEntry.setEstadoCliente(estadoCliente); existingEntry .setNumeroObligacion(dataLoan.getNumeroObligacion() + "+" + currentInstallment.getInstallmentNumber()); existingEntry.setNitEmpresa("800139398"); @@ -257,10 +293,11 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon existingEntry.setCreSaldo(creSaldo); existingEntry.setCuoSaldo(currentInstallment.getTotalOutstanding(loan.getCurrency()).getAmount()); existingEntry.setMontoInicial(loan.getApprovedPrincipal()); - existingEntry.setCuoEstado(dataLoan.getCuoEstado()); + existingEntry.setCuoEstado(cuoEstado); if (dataLoan.getFechaNacimiento() != null) { existingEntry.setFechaNacimiento(LocalDate.parse(dataLoan.getFechaNacimiento())); } + existingEntry.setEmpresa(ally); existingEntry.setMarca(brand); existingEntry.setCiudadPuntoCredito(cityPoinfsales); @@ -272,6 +309,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon existingEntry.setParentescoFamiliar(parentescoFamiliar); existingEntry.setEstadoCivil(estadoCivil); existingEntry.setNitEmpresaAliada(dataLoan.getNitEmpresaAliada()); + existingEntry.setCreEstado(creEstad); loanArchiveHistoryRepository.save(existingEntry); } else { LoanArchiveHistory loanArchiveHistory = new LoanArchiveHistory(); @@ -281,7 +319,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon loanArchiveHistory.setSegundoNombre(dataLoan.getSegundoNombre()); loanArchiveHistory.setPrimerApellido(dataLoan.getPrimerApellido()); loanArchiveHistory.setSegundoApellido(dataLoan.getSegundoApellido()); - loanArchiveHistory.setEstadoCliente(dataLoan.getEstadoCliente()); + loanArchiveHistory.setEstadoCliente(estadoCliente); loanArchiveHistory .setNumeroObligacion(dataLoan.getNumeroObligacion() + "+" + currentInstallment.getInstallmentNumber()); loanArchiveHistory.setNitEmpresa("800139398"); @@ -320,7 +358,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon loanArchiveHistory.setNumeroDeReprogramaciones(numberReschedule); loanArchiveHistory.setCreSaldo(creSaldo); loanArchiveHistory.setCuoSaldo(currentInstallment.getTotalOutstanding(loan.getCurrency()).getAmount()); - loanArchiveHistory.setCuoEstado(dataLoan.getCuoEstado()); + loanArchiveHistory.setCuoEstado(cuoEstado); if (dataLoan.getFechaNacimiento() != null) { loanArchiveHistory.setFechaNacimiento(LocalDate.parse(dataLoan.getFechaNacimiento())); } @@ -334,6 +372,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon loanArchiveHistory.setTipoDocumento(dataLoan.getTipoDocumento()); loanArchiveHistory.setEstadoCivil(estadoCivil); loanArchiveHistory.setNitEmpresaAliada(dataLoan.getNitEmpresaAliada()); + loanArchiveHistory.setCreEstado(creEstad); loanArchiveHistoryRepository.save(loanArchiveHistory); } if (!currentInstallment.isObligationsMet()) { From c3a4ff02dae0d57093aa45ca0b79fee189ec070f Mon Sep 17 00:00:00 2001 From: tabrez-fiter Date: Tue, 10 Dec 2024 17:11:42 +0800 Subject: [PATCH 2/2] SU-488 : Archivo de Cartera - Departamento --- .../infrastructure/codes/domain/CodeValueRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java index d85e3074696..e1d7a2b0f5b 100644 --- a/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/codes/domain/CodeValueRepository.java @@ -47,10 +47,10 @@ WHEN LEFT(LPAD(code_score::TEXT, 5, '0'), 2)::INTEGER < 10 THEN LEFT(LPAD(code_score::TEXT, 5, '0'), 2) END AS ciudadCoderScore FROM m_code_value mcv2 - WHERE code_id = 41 + WHERE code_id = (select * from m_code mc where mc.code_name ='Ciudad') ) mv2 ON mv2.ciudadCoderScore = mcv.code_score - WHERE mcv.code_id = 40 AND mv2.code_score = :codeScore + WHERE mcv.code_id = (select * from m_code mc where mc.code_name ='Departamento') AND mv2.code_score = :codeScore """, nativeQuery = true) Optional findCiudadAndDepartamentoData(@Param("codeScore") String codeScore); }