From d5f188fbddd92905342414fa9b69ae78e2a52c65 Mon Sep 17 00:00:00 2001 From: tabrez-fiter Date: Sun, 8 Dec 2024 00:55:06 +0800 Subject: [PATCH] SU-476: Daily Compensation not being generated properly on date and amounts / Compensacion diar --- .../CompensationOfSettlementConfig.java | 11 +++- .../CompensationOfSettlementTasklet.java | 64 +++++++++++++++++-- .../ArchiveLoansHistoryTasklet.java | 10 ++- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementConfig.java b/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementConfig.java index e1b74cb453d..34f8260b256 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementConfig.java +++ b/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementConfig.java @@ -1,7 +1,9 @@ package org.apache.fineract.custom.portfolio.ally.jobs.compensationsettlement; import org.apache.fineract.custom.portfolio.ally.domain.AllyCompensationRepository; +import org.apache.fineract.custom.portfolio.ally.domain.ClientAllyRepository; import org.apache.fineract.custom.portfolio.ally.service.AllyCompensationReadWritePlatformService; +import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository; import org.apache.fineract.infrastructure.jobs.service.JobName; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; @@ -29,6 +31,12 @@ public class CompensationOfSettlementConfig { @Autowired AllyCompensationRepository allyCompensationRepository; + @Autowired + ClientAllyRepository allyRepository; + + @Autowired + CodeValueRepository codeValueRepository; + @Bean public Step CompensationOfSettlementStep() { @@ -45,6 +53,7 @@ public Job CompensationOfSettlementJob() { @Bean public CompensationOfSettlementTasklet compensationOfSettlementTasklet() { - return new CompensationOfSettlementTasklet(allyCompensationReadWritePlatformService, allyCompensationRepository); + return new CompensationOfSettlementTasklet(allyCompensationReadWritePlatformService, allyCompensationRepository, allyRepository, + codeValueRepository); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementTasklet.java index fba78be51c0..def68b573c8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/custom/portfolio/ally/jobs/compensationsettlement/CompensationOfSettlementTasklet.java @@ -8,7 +8,11 @@ import org.apache.fineract.custom.portfolio.ally.data.ClientAllySettlementData; import org.apache.fineract.custom.portfolio.ally.domain.AllyCompensation; import org.apache.fineract.custom.portfolio.ally.domain.AllyCompensationRepository; +import org.apache.fineract.custom.portfolio.ally.domain.ClientAlly; +import org.apache.fineract.custom.portfolio.ally.domain.ClientAllyRepository; import org.apache.fineract.custom.portfolio.ally.service.AllyCompensationReadWritePlatformService; +import org.apache.fineract.infrastructure.codes.domain.CodeValue; +import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; @@ -19,11 +23,16 @@ public class CompensationOfSettlementTasklet implements Tasklet { private AllyCompensationReadWritePlatformService allyCompensationReadWritePlatformService; private AllyCompensationRepository allyCompensationRepository; + private ClientAllyRepository allyRepository; + private CodeValueRepository codeValueRepository; public CompensationOfSettlementTasklet(AllyCompensationReadWritePlatformService allyCompensationReadWritePlatformService, - AllyCompensationRepository allyCompensationRepository) { + AllyCompensationRepository allyCompensationRepository, ClientAllyRepository allyRepository, + CodeValueRepository codeValueRepository) { this.allyCompensationReadWritePlatformService = allyCompensationReadWritePlatformService; this.allyCompensationRepository = allyCompensationRepository; + this.allyRepository = allyRepository; + this.codeValueRepository = codeValueRepository; } @Override @@ -48,11 +57,10 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon break; case "QUINCENAL": startDate = endDate.minusWeeks(2).plusDays(1); - System.out.println(" QUINCENAL " + startDate); + break; case "MENSUAL": startDate = endDate.minusMonths(1).plusDays(1); - System.out.println(" MENSUAL " + startDate); break; default: startDate = endDate; @@ -84,7 +92,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon allyCompensation.setAccountNumber(allySettlementCompansationData.get().getAccountNumber()); allyCompensation.setPurchaseAmount(allySettlementCompansationData.get().getPurchaseAmount()); allyCompensation.setCollectionAmount(allySettlementCompansationData.get().getCollectionAmount()); - allyCompensation.setComissionAmount(allySettlementCompansationData.get().getCollectionAmount()); + allyCompensation.setComissionAmount(allySettlementCompansationData.get().getComissionAmount()); allyCompensation.setVaComissionAmount(allySettlementCompansationData.get().getVaComissionAmount()); allyCompensation.setNetPurchaseAmount(allySettlementCompansationData.get().getNetPurchaseAmount()); allyCompensation.setNetOutstandingAmount(allySettlementCompansationData.get().getCompensationAmount()); @@ -97,7 +105,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon if (!exisiting.getSettlementStatus()) { exisiting.setPurchaseAmount(allySettlementCompansationData.get().getPurchaseAmount()); exisiting.setCollectionAmount(allySettlementCompansationData.get().getCollectionAmount()); - exisiting.setComissionAmount(allySettlementCompansationData.get().getCollectionAmount()); + exisiting.setComissionAmount(allySettlementCompansationData.get().getComissionAmount()); exisiting.setVaComissionAmount(allySettlementCompansationData.get().getVaComissionAmount()); exisiting.setNetPurchaseAmount(allySettlementCompansationData.get().getNetPurchaseAmount()); exisiting.setNetOutstandingAmount(allySettlementCompansationData.get().getCompensationAmount()); @@ -105,6 +113,8 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon exisiting.setSettlementStatus(exisiting.getSettlementStatus()); allyCompensationRepository.save(exisiting); } + } else { + this.getAllyCompensationCheck(); } } } @@ -112,4 +122,48 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon return RepeatStatus.FINISHED; } + + public void getAllyCompensationCheck() { + List compensations = allyCompensationRepository.findBySettlementStatus(); + for (AllyCompensation allyCompensation : compensations) { + Optional clientAlly = allyRepository.findById(allyCompensation.getClientAllyId()); + + if (clientAlly.isPresent()) { + Optional codeValue = codeValueRepository.findById(clientAlly.get().getLiquidationFrequencyCodeValueId()); + if (codeValue.isPresent()) { + CodeValue codeValue1 = codeValue.get(); + String frequency = codeValue1.getLabel(); + frequency = frequency.replaceAll("\\s", ""); + LocalDate startDate; + LocalDate endDate = allyCompensation.getCompensationDate(); + switch (frequency.toUpperCase()) { + case "SEMANAL": + startDate = endDate.minusWeeks(1).plusDays(1); + System.out.println("SEMANAL " + startDate); + break; + case "QUINCENAL": + startDate = endDate.minusWeeks(2).plusDays(1); + + break; + case "MENSUAL": + startDate = endDate.minusMonths(1).plusDays(1); + break; + default: + startDate = endDate; + } + + Optional allySettlementCompansationData = allyCompensationReadWritePlatformService + .getCompensationSettlementByNit(allyCompensation.getNit(), startDate, endDate); + if (allySettlementCompansationData.isPresent()) { + allyCompensation.setStartDate(startDate); + allyCompensation.setEndDate(endDate); + allyCompensation.setComissionAmount(allySettlementCompansationData.get().getComissionAmount()); + allyCompensationRepository.save(allyCompensation); + } + } + + } + + } + } } 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 8195ef31055..236d8994d81 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 @@ -206,8 +206,11 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon actividadLaboral = actividadLaboralCode.getLabel(); } } - + final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment = loan + .fetchLoanForeclosureDetail(LocalDate.now()); + BigDecimal creSaldo = loanRepaymentScheduleInstallment.getTotalOutstanding(loan.getCurrency()).getAmount(); if (existingLoanArchive.isPresent()) { + LoanArchiveHistory existingEntry = existingLoanArchive.get(); existingEntry.setIdentificacion(dataLoan.getNitEmpresa()); existingEntry.setPrimerNombre(dataLoan.getPrimerNombre()); @@ -251,7 +254,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon existingEntry.setAbono(BigDecimal.ZERO); existingEntry.setActividadLaboral(actividadLaboral); existingEntry.setNumeroDeReprogramaciones(numberReschedule); - existingEntry.setCreSaldo(loan.getLoanSummary().getTotalOutstanding()); + existingEntry.setCreSaldo(creSaldo); existingEntry.setCuoSaldo(currentInstallment.getTotalOutstanding(loan.getCurrency()).getAmount()); existingEntry.setMontoInicial(loan.getApprovedPrincipal()); existingEntry.setCuoEstado(dataLoan.getCuoEstado()); @@ -269,6 +272,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon existingEntry.setParentescoFamiliar(parentescoFamiliar); existingEntry.setEstadoCivil(estadoCivil); existingEntry.setNitEmpresaAliada(dataLoan.getNitEmpresaAliada()); + loanArchiveHistoryRepository.save(existingEntry); } else { LoanArchiveHistory loanArchiveHistory = new LoanArchiveHistory(); loanArchiveHistory.setTitle("Archive Loan " + loan.getId()); @@ -314,7 +318,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon loanArchiveHistory.setAbono(BigDecimal.ZERO); loanArchiveHistory.setActividadLaboral(actividadLaboral); loanArchiveHistory.setNumeroDeReprogramaciones(numberReschedule); - loanArchiveHistory.setCreSaldo(loan.getLoanSummary().getTotalOutstanding()); + loanArchiveHistory.setCreSaldo(creSaldo); loanArchiveHistory.setCuoSaldo(currentInstallment.getTotalOutstanding(loan.getCurrency()).getAmount()); loanArchiveHistory.setCuoEstado(dataLoan.getCuoEstado()); if (dataLoan.getFechaNacimiento() != null) {