Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SU-529 #1404

Merged
merged 8 commits into from
Dec 18, 2024
Merged

SU-529 #1404

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,9 @@ public void setCustomChargeHonorarioMaps(Set<CustomChargeHonorarioMap> customCha

public boolean isVatChargeOfHonoCharge() {
for (LoanCharge parentCharge : this.loan.getCharges()) {
return parentCharge.isFlatHono() && parentCharge.getCharge().getId().equals(this.getCharge().getParentChargeId());
if (parentCharge.isFlatHono() && parentCharge.getCharge().getId().equals(this.getCharge().getParentChargeId())) {
return true;
}
}
return false;
}
Expand All @@ -1664,7 +1666,7 @@ public BigDecimal getVatAmountOfHonoCharge(Integer installmentNumber) {
for (LoanCharge parentCharge : this.loan.getCharges()) {
if (parentCharge.isFlatHono() && parentCharge.getCharge().getId().equals(this.getCharge().getParentChargeId())) {
if (!parentCharge.getCustomChargeHonorarioMaps().isEmpty()) {
for (CustomChargeHonorarioMap customCharge : this.getCustomChargeHonorarioMaps()) {
for (CustomChargeHonorarioMap customCharge : parentCharge.getCustomChargeHonorarioMaps()) {
if (customCharge.getLoanInstallmentNr().equals(installmentNumber)) {
customAmout = customAmout.add(customCharge.getFeeVatAmount());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ private Money cumulativeFeeChargesDueWithin(final LocalDate periodStart, final L
cumulative = cumulative.plus(loanCharge.calculateCustomFeeChargeToInstallment(period.getInstallmentNumber(),
totalPrincipal, totalInstallments, outstandingBalance));
} else {
cumulative = cumulative.plus(getInstallmentFee(monetaryCurrency, period, loanCharge));
if (loanCharge.getChargeCalculation().isFlatHono()) {
cumulative = Money.zero(monetaryCurrency);
} else {
cumulative = cumulative.plus(getInstallmentFee(monetaryCurrency, period, loanCharge));
}
}
} else if (loanCharge.isOverdueInstallmentCharge() && isDue && loanCharge.getChargeCalculation().isPercentageBased()) {
cumulative = cumulative.plus(loanCharge.chargeAmount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ private Money processAllocationsHorizontally(LoanTransaction loanTransaction, Mo
}
LoanRepaymentScheduleInstallment dueInstallment = installments.stream()
.filter(LoanRepaymentScheduleInstallment::isNotFullyPaidOff)
.filter(e -> loanTransaction.isOnOrBetween(e.getFromDate(), e.getDueDate()))
.filter(e -> loanTransaction.isOnOrBetween(e.getFromDate(), e.getDueDate()) || loanTransaction.isOn(e.getDueDate()))
.min(Comparator.comparing(LoanRepaymentScheduleInstallment::getInstallmentNumber)).orElse(null);

found = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,16 @@ public void updateRepaymentInstalmentCharge(LoanRepaymentScheduleInstallment loa
@Override
public FeeCalculationHonorario calculateFeeHonorario(LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment,
BigDecimal repaymentAmount) {
Integer ageOverdue = loanRepaymentScheduleInstallment.getLoan().getAgeOfOverdueDays(DateUtils.getBusinessLocalDate()).intValue();
// SU-529 Get maximum age of any of the client's loan
List<Loan> clientActiveLoans = this.loanRepositoryWrapper
.findActiveLoansByClientId(loanRepaymentScheduleInstallment.getLoan().getClientId());
Integer ageOverdue = 0;
for (Loan loan : clientActiveLoans) {
int overdue = loan.getAgeOfOverdueDays(DateUtils.getBusinessLocalDate()).intValue();
if (overdue > ageOverdue) {
ageOverdue = overdue;
}
}
BigDecimal delinquencyValue = BigDecimal.ZERO;

// Retrieve VAT configuration and percentage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ public List<Loan> findByGroupOfficeIdsAndLoanStatus(@Param("officeIds") Collecti
return loans;
}

public List<Loan> findActiveLoansByClientId(@Param("clientId") Long clientId) {
List<Loan> loans = this.repository.findActiveLoansByClientId(clientId);
if (loans != null && loans.size() > 0) {
for (Loan loan : loans) {
loan.initializeRepaymentSchedule();
}
}
return loans;
}

public List<Long> findActiveLoansLoanProductIdsByClient(@Param("clientId") Long clientId, @Param("loanStatus") Integer loanStatus) {
return this.repository.findActiveLoansLoanProductIdsByClient(clientId, loanStatus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,9 @@ private Money calculateInstallmentCharge(final PrincipalInterest principalIntere
numberOfRepayments, outstandingBalance);
cumulative = cumulative.plus(calculatedAmount);
} else {
if (loanCharge.defaultFromInstallment() != null && installmentNumber >= loanCharge.defaultFromInstallment()) {
if (loanCharge.isFlatHono()) {
calculatedAmount = BigDecimal.ZERO;
} else if (loanCharge.defaultFromInstallment() != null && installmentNumber >= loanCharge.defaultFromInstallment()) {
calculatedAmount = BigDecimal.ZERO;
} else {
calculatedAmount = loanCharge.amountOrPercentage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,17 @@ public LoanAccountData retrieveLoanByLoanAccount(String loanAccountNumber) {

private FeeCalculationHonorario calculateFeeDetails(LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment,
BigDecimal repaymentAmount) {
Integer ageOverdue = loanRepaymentScheduleInstallment.getLoan().getAgeOfOverdueDays(DateUtils.getBusinessLocalDate()).intValue();
// SU-529 Get maximum age of any of the client's loan
List<Loan> clientActiveLoans = this.loanRepositoryWrapper
.findActiveLoansByClientId(loanRepaymentScheduleInstallment.getLoan().getClientId());
Integer ageOverdue = 0;
for (Loan loan : clientActiveLoans) {
int overdue = loan.getAgeOfOverdueDays(DateUtils.getBusinessLocalDate()).intValue();
if (overdue > ageOverdue) {
ageOverdue = overdue;
}
}

BigDecimal delinquencyValue = BigDecimal.ZERO;
// Retrieve VAT configuration and percentage
Integer vatConfig = configurationDomainService.retriveIvaConfiguration();
Expand Down Expand Up @@ -3992,6 +4002,7 @@ private BigDecimal calculateHonoChargeAmount(Loan loan, LocalDate transactionDat
remainingAmount = remainingAmount.minus(installmentOutstandingAmount);
} else {
feeCalculationHonorario = this.calculateFeeDetails(installment, remainingAmount.getAmount());
remainingAmount = remainingAmount.zero();
}
feeHono = feeHono.add(feeCalculationHonorario.getFeeBasis());
if (vatHono.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,10 +1170,15 @@ public CommandProcessingResult makeLoanRepayment(final LoanTransactionType repay
fee = this.loanAccountDomainService.updateCalculationHonoLoanChargeOverDueVat(installmentOutstandingAmount,
installment, installmentNumber, version);
remainingAmount = remainingAmount.minus(installmentOutstandingAmount);
remainingAmount = remainingAmount.minus(fee.getFeeBasis());
if (vatChargeOptional.isPresent()) {
remainingAmount = remainingAmount.minus(fee.getFeeVat());
}

} else {
fee = this.loanAccountDomainService.updateCalculationHonoLoanChargeOverDueVat(remainingAmount.getAmount(),
installment, installmentNumber, version);
remainingAmount = remainingAmount.zero();
}

remainingAmount = remainingAmount.minus(fee.getFeeBasis());
Expand Down Expand Up @@ -1543,6 +1548,10 @@ public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Lo
}
remove.forEach(chargePaidBy.getLoanCharge().getCustomChargeHonorarioMaps()::remove);
customChargeHonorarioMapRepository.deleteLatestVersionMapEntryOnReversal(loanId, versionToBeDeleted);
transactionToAdjust.getLoanTransactionToRepaymentScheduleMappings().clear();
final LoanRepaymentScheduleProcessingWrapper wrapper = new LoanRepaymentScheduleProcessingWrapper();
wrapper.reprocess(loan.getCurrency(), loan.getDisbursementDate(), loan.getRepaymentScheduleInstallments(),
loan.getActiveCharges());
break;
}
}
Expand Down
Loading