Skip to content

Commit

Permalink
Merge pull request #1352 from fiterlatam/bug/SU-476
Browse files Browse the repository at this point in the history
SU-476: Daily Compensation not being generated properly on date and a…
  • Loading branch information
tabrez-fiter authored Dec 8, 2024
2 parents cdde6d9 + d5f188f commit fef8d68
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,6 +31,12 @@ public class CompensationOfSettlementConfig {
@Autowired
AllyCompensationRepository allyCompensationRepository;

@Autowired
ClientAllyRepository allyRepository;

@Autowired
CodeValueRepository codeValueRepository;

@Bean
public Step CompensationOfSettlementStep() {

Expand All @@ -45,6 +53,7 @@ public Job CompensationOfSettlementJob() {

@Bean
public CompensationOfSettlementTasklet compensationOfSettlementTasklet() {
return new CompensationOfSettlementTasklet(allyCompensationReadWritePlatformService, allyCompensationRepository);
return new CompensationOfSettlementTasklet(allyCompensationReadWritePlatformService, allyCompensationRepository, allyRepository,
codeValueRepository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -97,19 +105,65 @@ 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());
exisiting.setNetOutstandingAmount(allySettlementCompansationData.get().getCompensationAmount());
exisiting.setSettlementStatus(exisiting.getSettlementStatus());
allyCompensationRepository.save(exisiting);
}
} else {
this.getAllyCompensationCheck();
}
}
}
}

return RepeatStatus.FINISHED;
}

public void getAllyCompensationCheck() {
List<AllyCompensation> compensations = allyCompensationRepository.findBySettlementStatus();
for (AllyCompensation allyCompensation : compensations) {
Optional<ClientAlly> clientAlly = allyRepository.findById(allyCompensation.getClientAllyId());

if (clientAlly.isPresent()) {
Optional<CodeValue> 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<AllySettlementCompansationCollectionData> allySettlementCompansationData = allyCompensationReadWritePlatformService
.getCompensationSettlementByNit(allyCompensation.getNit(), startDate, endDate);
if (allySettlementCompansationData.isPresent()) {
allyCompensation.setStartDate(startDate);
allyCompensation.setEndDate(endDate);
allyCompensation.setComissionAmount(allySettlementCompansationData.get().getComissionAmount());
allyCompensationRepository.save(allyCompensation);
}
}

}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fef8d68

Please sign in to comment.