FINERACT-1840: Fee income is not realised if the loan got fully repaid (#2902)
Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
4479196c3e
commit
f3d7c042a4
+49
-40
@@ -547,50 +547,59 @@ public class LoanAccountDomainServiceJpa implements LoanAccountDomainService {
|
|||||||
@Override
|
@Override
|
||||||
public void recalculateAccruals(Loan loan, boolean isInterestCalculationHappened) {
|
public void recalculateAccruals(Loan loan, boolean isInterestCalculationHappened) {
|
||||||
LocalDate accruedTill = loan.getAccruedTill();
|
LocalDate accruedTill = loan.getAccruedTill();
|
||||||
if (!loan.isPeriodicAccrualAccountingEnabledOnLoanProduct() || !isInterestCalculationHappened || accruedTill == null || loan.isNpa()
|
final LocalDate businessDate = DateUtils.getBusinessLocalDate();
|
||||||
|| !loan.getStatus().isActive()) {
|
if (loan.isPeriodicAccrualAccountingEnabledOnLoanProduct() // Loan Product with Accrual Accounting
|
||||||
return;
|
&& isInterestCalculationHappened // Loan Product with Interest Recalculation enabled
|
||||||
}
|
// Loan Account accrued till is not equal to the Business Date
|
||||||
|
&& (accruedTill == null || !accruedTill.equals(businessDate)) && !loan.isNpa() // Loan Account is not
|
||||||
|
// NPA
|
||||||
|
) {
|
||||||
|
// Loan Account is Active OR is Recently Closed with Obligations Met
|
||||||
|
if (loan.getStatus().isActive() || (loan.getStatus().isClosedObligationsMet() && loan.getClosedOnDate().equals(businessDate))) {
|
||||||
|
if (accruedTill == null) {
|
||||||
|
accruedTill = businessDate;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isOrganisationDateEnabled = this.configurationDomainService.isOrganisationstartDateEnabled();
|
boolean isOrganisationDateEnabled = this.configurationDomainService.isOrganisationstartDateEnabled();
|
||||||
LocalDate organisationStartDate = DateUtils.getBusinessLocalDate();
|
LocalDate organisationStartDate = businessDate;
|
||||||
if (isOrganisationDateEnabled) {
|
if (isOrganisationDateEnabled) {
|
||||||
organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate();
|
organisationStartDate = this.configurationDomainService.retrieveOrganisationStartDate();
|
||||||
}
|
}
|
||||||
Collection<LoanScheduleAccrualData> loanScheduleAccrualList = new ArrayList<>();
|
Collection<LoanScheduleAccrualData> loanScheduleAccrualList = new ArrayList<>();
|
||||||
List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments();
|
List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments();
|
||||||
Long loanId = loan.getId();
|
Long loanId = loan.getId();
|
||||||
Long officeId = loan.getOfficeId();
|
Long officeId = loan.getOfficeId();
|
||||||
LocalDate accrualStartDate = null;
|
LocalDate accrualStartDate = null;
|
||||||
PeriodFrequencyType repaymentFrequency = loan.repaymentScheduleDetail().getRepaymentPeriodFrequencyType();
|
PeriodFrequencyType repaymentFrequency = loan.repaymentScheduleDetail().getRepaymentPeriodFrequencyType();
|
||||||
Integer repayEvery = loan.repaymentScheduleDetail().getRepayEvery();
|
Integer repayEvery = loan.repaymentScheduleDetail().getRepayEvery();
|
||||||
LocalDate interestCalculatedFrom = loan.getInterestChargedFromDate();
|
LocalDate interestCalculatedFrom = loan.getInterestChargedFromDate();
|
||||||
Long loanProductId = loan.productId();
|
Long loanProductId = loan.productId();
|
||||||
MonetaryCurrency currency = loan.getCurrency();
|
MonetaryCurrency currency = loan.getCurrency();
|
||||||
ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
|
ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneWithNotFoundDetection(currency);
|
||||||
CurrencyData currencyData = applicationCurrency.toData();
|
CurrencyData currencyData = applicationCurrency.toData();
|
||||||
Set<LoanCharge> loanCharges = loan.getActiveCharges();
|
Set<LoanCharge> loanCharges = loan.getActiveCharges();
|
||||||
|
|
||||||
for (LoanRepaymentScheduleInstallment installment : installments) {
|
for (LoanRepaymentScheduleInstallment installment : installments) {
|
||||||
if (installment.getDueDate().isAfter(loan.getMaturityDate())) {
|
if (installment.getDueDate().isAfter(loan.getMaturityDate())) {
|
||||||
accruedTill = DateUtils.getBusinessLocalDate();
|
accruedTill = businessDate;
|
||||||
}
|
}
|
||||||
if (!isOrganisationDateEnabled || organisationStartDate.isBefore(installment.getDueDate())) {
|
if (!isOrganisationDateEnabled || organisationStartDate.isBefore(installment.getDueDate())) {
|
||||||
generateLoanScheduleAccrualData(accruedTill, loanScheduleAccrualList, loanId, officeId, accrualStartDate,
|
generateLoanScheduleAccrualData(accruedTill, loanScheduleAccrualList, loanId, officeId, accrualStartDate,
|
||||||
repaymentFrequency, repayEvery, interestCalculatedFrom, loanProductId, currency, currencyData, loanCharges,
|
repaymentFrequency, repayEvery, interestCalculatedFrom, loanProductId, currency, currencyData, loanCharges,
|
||||||
installment);
|
installment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!loanScheduleAccrualList.isEmpty()) {
|
||||||
|
try {
|
||||||
|
this.loanAccrualPlatformService.addPeriodicAccruals(accruedTill, loanScheduleAccrualList);
|
||||||
|
} catch (MultiException e) {
|
||||||
|
String globalisationMessageCode = "error.msg.accrual.exception";
|
||||||
|
throw new GeneralPlatformDomainRuleException(globalisationMessageCode, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loanScheduleAccrualList.isEmpty()) {
|
|
||||||
try {
|
|
||||||
this.loanAccrualPlatformService.addPeriodicAccruals(accruedTill, loanScheduleAccrualList);
|
|
||||||
} catch (MultiException e) {
|
|
||||||
String globalisationMessageCode = "error.msg.accrual.exception";
|
|
||||||
throw new GeneralPlatformDomainRuleException(globalisationMessageCode, e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateLoanScheduleAccrualData(final LocalDate accruedTill,
|
private void generateLoanScheduleAccrualData(final LocalDate accruedTill,
|
||||||
|
|||||||
Reference in New Issue
Block a user