Skip to content

Commit

Permalink
FINERACT-2090: Accruals rework
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchiD committed Jul 9, 2024
1 parent 67440c4 commit 80f1727
Show file tree
Hide file tree
Showing 26 changed files with 1,695 additions and 1,485 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ LoanTransaction makeRefundForActiveLoan(Long accountId, CommandProcessingResultB

void updateLoanCollateralStatus(Set<LoanCollateralManagement> loanCollateralManagementSet, boolean isReleased);

/**
* This method is to recalculate and accrue the income till the last accrued date. this method is used when the
* schedule changes due to interest recalculation
*
* @param loan
*/
void recalculateAccruals(Loan loan);

/**
* This method is to set a Delinquency Tag If the loan is overdue, If the loan after the repayment transaction is
* not overdue and It has a Delinquency Tag, It is removed
Expand Down Expand Up @@ -98,10 +90,7 @@ LoanTransaction foreCloseLoan(Loan loan, LocalDate foreClourseDate, String noteT
*/
void disableStandingInstructionsLinkedToClosedLoan(Loan loan);

void recalculateAccruals(Loan loan, boolean isInterestCalcualtionHappened);

LoanTransaction creditBalanceRefund(Loan loan, LocalDate transactionDate, BigDecimal transactionAmount, String noteText,
ExternalId externalId, PaymentDetail paymentDetail);

void applyFinalIncomeAccrualTransaction(Loan loan);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.fineract.portfolio.loanaccount.jobs.addperiodicaccrualentries;

import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualPlatformService;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualsProcessingService;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.builder.JobBuilder;
Expand All @@ -39,7 +39,7 @@ public class AddPeriodicAccrualEntriesConfig {
@Autowired
private PlatformTransactionManager transactionManager;
@Autowired
private LoanAccrualPlatformService loanAccrualPlatformService;
private LoanAccrualsProcessingService loanAccrualsProcessingService;

@Bean
protected Step addPeriodicAccrualEntriesStep() {
Expand All @@ -55,6 +55,6 @@ public Job addPeriodicAccrualEntriesJob() {

@Bean
public AddPeriodicAccrualEntriesTasklet addPeriodicAccrualEntriesTasklet() {
return new AddPeriodicAccrualEntriesTasklet(loanAccrualPlatformService);
return new AddPeriodicAccrualEntriesTasklet(loanAccrualsProcessingService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.fineract.infrastructure.core.exception.MultiException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualPlatformService;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualsProcessingService;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
Expand All @@ -34,7 +34,7 @@
@RequiredArgsConstructor
public class AddPeriodicAccrualEntriesTasklet implements Tasklet {

private final LoanAccrualPlatformService loanAccrualPlatformService;
private final LoanAccrualsProcessingService loanAccrualsProcessingService;

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
Expand All @@ -47,6 +47,6 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
}

private void addPeriodicAccruals(final LocalDate tilldate) throws MultiException {
loanAccrualPlatformService.addPeriodicAccruals(tilldate);
loanAccrualsProcessingService.addPeriodicAccruals(tilldate);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@
import org.apache.fineract.infrastructure.core.exception.MultiException;
import org.apache.fineract.portfolio.loanaccount.data.LoanScheduleAccrualData;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;

public interface LoanAccrualPlatformService {
public interface LoanAccrualsProcessingService {

void addPeriodicAccruals(LocalDate tilldate) throws MultiException;

void addPeriodicAccruals(LocalDate tilldate, Loan loan) throws MultiException;

void addPeriodicAccruals(LocalDate tilldate, Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas) throws MultiException;
void addAccrualAccounting(Long loanId, Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas) throws Exception;

void addIncomeAndAccrualTransactions(Long loanId) throws Exception;

void reprocessExistingAccruals(Loan loan);

void processAccrualsForInterestRecalculation(Loan loan, boolean isInterestRecalculationEnabled);

void processIncomePostingAndAccruals(Loan loan);

void processAccrualsForLoanClosure(Loan loan);

void processAccrualsForLoanForeClosure(Loan loan, LocalDate foreClosureDate, Collection<LoanTransaction> newAccrualTransactions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@
import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
import org.apache.fineract.infrastructure.core.exception.MultiException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualPlatformService;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualsProcessingService;

@RequiredArgsConstructor
public class AccrualAccountingWritePlatformServiceImpl implements AccrualAccountingWritePlatformService {

private final LoanAccrualPlatformService loanAccrualPlatformService;
private final LoanAccrualsProcessingService loanAccrualsProcessingService;
private final AccrualAccountingDataValidator accountingDataValidator;

@Override
public CommandProcessingResult executeLoansPeriodicAccrual(JsonCommand command) {
this.accountingDataValidator.validateLoanPeriodicAccrualData(command.json());
LocalDate tillDate = command.localDateValueOfParameterNamed(accrueTillParamName);
try {
this.loanAccrualPlatformService.addPeriodicAccruals(tillDate);
this.loanAccrualsProcessingService.addPeriodicAccruals(tillDate);
} catch (MultiException e) {
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.fineract.accounting.accrual.serialization.AccrualAccountingDataValidator;
import org.apache.fineract.accounting.accrual.service.AccrualAccountingWritePlatformService;
import org.apache.fineract.accounting.accrual.service.AccrualAccountingWritePlatformServiceImpl;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualPlatformService;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualsProcessingService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -32,7 +32,7 @@ public class AccountingAccrualConfiguration {
@Bean
@ConditionalOnMissingBean(AccrualAccountingWritePlatformService.class)
public AccrualAccountingWritePlatformService accrualAccountingWritePlatformService(
LoanAccrualPlatformService loanAccrualPlatformService, AccrualAccountingDataValidator accountingDataValidator) {
return new AccrualAccountingWritePlatformServiceImpl(loanAccrualPlatformService, accountingDataValidator);
LoanAccrualsProcessingService loanAccrualsProcessingService, AccrualAccountingDataValidator accountingDataValidator) {
return new AccrualAccountingWritePlatformServiceImpl(loanAccrualsProcessingService, accountingDataValidator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
import org.apache.fineract.infrastructure.core.exception.MultiException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualPlatformService;
import org.apache.fineract.portfolio.loanaccount.service.LoanAccrualsProcessingService;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class AddPeriodicAccrualEntriesBusinessStep implements LoanCOBBusinessStep {

private final LoanAccrualPlatformService loanAccrualPlatformService;
private final LoanAccrualsProcessingService loanAccrualsProcessingService;

@Override
public Loan execute(Loan loan) {
log.debug("start processing period accrual business step for loan with Id [{}]", loan.getId());
try {
loanAccrualPlatformService.addPeriodicAccruals(DateUtils.getBusinessLocalDate(), loan);
loanAccrualsProcessingService.addPeriodicAccruals(DateUtils.getBusinessLocalDate(), loan);
} catch (MultiException e) {
throw new BusinessStepException(String.format("Fail to process period accrual for loan id [%s]", loan.getId()), e);
}
Expand Down
Loading

0 comments on commit 80f1727

Please sign in to comment.