Skip to content

Commit

Permalink
Merge pull request #1366 from fiterlatam/bug/SU-488
Browse files Browse the repository at this point in the history
SU-488 : Archivo de Cartera - Departamento
  • Loading branch information
tabrez-fiter authored Dec 10, 2024
2 parents 9a71d6c + c3a4ff0 commit eee5b0d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeValue, Long>, JpaSpecificationExecutor<CodeValue> {

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 = (select * from m_code mc where mc.code_name ='Ciudad')
) mv2
ON mv2.ciudadCoderScore = mcv.code_score
WHERE mcv.code_id = (select * from m_code mc where mc.code_name ='Departamento') AND mv2.code_score = :codeScore
""", nativeQuery = true)
Optional<CodeValue> findCiudadAndDepartamentoData(@Param("codeScore") String codeScore);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,9 +208,43 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
actividadLaboral = actividadLaboralCode.getLabel();
}
}

if (actividadLaboral.equals("PENSIONADO")) {
if (dataLoan.getCiudadPuntoCredito() != null) {
Optional<CodeValue> getDepartamento = codeValueRepository
.findById(Long.valueOf(dataLoan.getCiudadPuntoCredito()));
if (getDepartamento.isPresent()) {
CodeValue departamento = getDepartamento.get();
String departamentoScore = departamento.getScore();
Optional<CodeValue> 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();
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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");
Expand Down Expand Up @@ -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()));
}
Expand All @@ -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()) {
Expand Down

0 comments on commit eee5b0d

Please sign in to comment.