FINERACT-1971

- fix undo last disbursal with auto down payment enabled and repayment between the two disbursements
This commit is contained in:
Peter Bagrij
2023-10-04 13:54:54 +02:00
committed by Arnold Gálovics
parent 80bcb27b0a
commit be7c419b24
2 changed files with 157 additions and 28 deletions
@@ -6485,11 +6485,10 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
Money downPaymentMoney = Money.of(getCurrency(),
MathUtil.percentageOf(lastDisbursalTransaction.getAmount(), disbursedAmountPercentageForDownPayment, 19));
// find the matching down-payment transaction based on date, amount and it also must have downpayment
// installment linked
// find the latest matching down-payment transaction based on date, amount and transaction type
Optional<LoanTransaction> downPaymentTransaction = this.loanTransactions.stream()
.filter(tr -> tr.getTransactionDate().equals(lastDisbursalTransaction.getTransactionDate())
&& hasAnInstallmentWithDownPayment(tr, downPaymentMoney.getAmount()))
&& tr.getTypeOf().isDownPayment() && tr.getAmount().compareTo(downPaymentMoney.getAmount()) == 0)
.max(Comparator.comparing(LoanTransaction::getId));
// reverse the down-payment transaction
@@ -6497,11 +6496,6 @@ public class Loan extends AbstractAuditableWithUTCDateTimeCustom {
}
}
private boolean hasAnInstallmentWithDownPayment(LoanTransaction tr, BigDecimal amount) {
return tr.getAmount().compareTo(amount) == 0 && tr.getLoanTransactionToRepaymentScheduleMappings().stream()
.anyMatch(mapping -> mapping.getLoanRepaymentScheduleInstallment().isDownPayment());
}
private void updateLoanToLastDisbursalState(LoanDisbursementDetails disbursementDetail) {
for (final LoanCharge charge : getActiveCharges()) {
if (charge.isOverdueInstallmentCharge()) {