FINERACT-2210: Fix journal entries creation issue when amount is null
This commit is contained in:
committed by
Adam Saghy
parent
a1d51e1e34
commit
a11c567413
+30
-21
@@ -1400,20 +1400,25 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
|
||||
if (!installments.isEmpty() && transactionDate.isBefore(loan.getMaturityDate())) {
|
||||
if (transactionCtx instanceof ProgressiveTransactionCtx progressiveTransactionCtx
|
||||
&& loanTransaction.getLoan().isInterestBearingAndInterestRecalculationEnabled()) {
|
||||
final BigDecimal interestOutstanding = currentInstallment.getInterestOutstanding(loan.getCurrency()).getAmount();
|
||||
final BigDecimal newInterest = emiCalculator.getPeriodInterestTillDate(progressiveTransactionCtx.getModel(),
|
||||
currentInstallment.getDueDate(), transactionDate, true).getAmount();
|
||||
currentInstallment.updateInterestCharged(newInterest);
|
||||
if (interestOutstanding.compareTo(BigDecimal.ZERO) > 0 || newInterest.compareTo(BigDecimal.ZERO) > 0) {
|
||||
currentInstallment.updateInterestCharged(newInterest);
|
||||
}
|
||||
} else {
|
||||
final BigDecimal totalInterest = currentInstallment.getInterestOutstanding(transactionCtx.getCurrency()).getAmount();
|
||||
final long totalDaysInPeriod = ChronoUnit.DAYS.between(currentInstallment.getFromDate(), currentInstallment.getDueDate());
|
||||
final long daysTillChargeOff = ChronoUnit.DAYS.between(currentInstallment.getFromDate(), transactionDate);
|
||||
if (totalInterest.compareTo(BigDecimal.ZERO) > 0) {
|
||||
final long totalDaysInPeriod = ChronoUnit.DAYS.between(currentInstallment.getFromDate(),
|
||||
currentInstallment.getDueDate());
|
||||
final long daysTillChargeOff = ChronoUnit.DAYS.between(currentInstallment.getFromDate(), transactionDate);
|
||||
|
||||
final MathContext mc = MoneyHelper.getMathContext();
|
||||
final Money interestTillChargeOff = Money.of(transactionCtx.getCurrency(),
|
||||
totalInterest.divide(BigDecimal.valueOf(totalDaysInPeriod), mc).multiply(BigDecimal.valueOf(daysTillChargeOff), mc),
|
||||
mc);
|
||||
final MathContext mc = MoneyHelper.getMathContext();
|
||||
final Money interestTillChargeOff = Money.of(transactionCtx.getCurrency(), totalInterest
|
||||
.divide(BigDecimal.valueOf(totalDaysInPeriod), mc).multiply(BigDecimal.valueOf(daysTillChargeOff), mc), mc);
|
||||
|
||||
currentInstallment.updateInterestCharged(interestTillChargeOff.getAmount());
|
||||
currentInstallment.updateInterestCharged(interestTillChargeOff.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
currentInstallment.updateDueDate(transactionDate);
|
||||
@@ -1478,25 +1483,27 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
|
||||
private void handleZeroInterestChargeOff(final LoanTransaction loanTransaction, final TransactionCtx transactionCtx) {
|
||||
final LocalDate transactionDate = loanTransaction.getTransactionDate();
|
||||
final List<LoanRepaymentScheduleInstallment> installments = transactionCtx.getInstallments();
|
||||
final MonetaryCurrency currency = loanTransaction.getLoan().getCurrency();
|
||||
|
||||
if (!installments.isEmpty()) {
|
||||
if (transactionCtx instanceof ProgressiveTransactionCtx progressiveTransactionCtx
|
||||
&& loanTransaction.getLoan().isInterestBearingAndInterestRecalculationEnabled()) {
|
||||
installments.stream().filter(installment -> !installment.getFromDate().isAfter(transactionDate)
|
||||
&& installment.getDueDate().isAfter(transactionDate)).forEach(installment -> {
|
||||
final BigDecimal interestOutstanding = installment.getInterestOutstanding(currency).getAmount();
|
||||
final BigDecimal newInterest = emiCalculator.getPeriodInterestTillDate(progressiveTransactionCtx.getModel(),
|
||||
installment.getDueDate(), transactionDate, true).getAmount();
|
||||
final BigDecimal interestRemoved = installment.getInterestCharged().subtract(newInterest);
|
||||
installment.updatePrincipal(MathUtil.nullToZero(installment.getPrincipal()).add(interestRemoved));
|
||||
installment.updateInterestCharged(newInterest);
|
||||
if (interestOutstanding.compareTo(BigDecimal.ZERO) > 0 || newInterest.compareTo(BigDecimal.ZERO) > 0) {
|
||||
final BigDecimal interestRemoved = installment.getInterestCharged().subtract(newInterest);
|
||||
installment.updatePrincipal(MathUtil.nullToZero(installment.getPrincipal()).add(interestRemoved));
|
||||
installment.updateInterestCharged(newInterest);
|
||||
}
|
||||
});
|
||||
progressiveTransactionCtx.setChargedOff(true);
|
||||
} else {
|
||||
calculatePartialPeriodInterest(transactionCtx, transactionDate);
|
||||
}
|
||||
|
||||
final MonetaryCurrency currency = loanTransaction.getLoan().getCurrency();
|
||||
|
||||
installments.stream()
|
||||
.filter(installment -> installment.getFromDate().isAfter(transactionDate) && !installment.isObligationsMet())
|
||||
.forEach(installment -> {
|
||||
@@ -1538,16 +1545,18 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
|
||||
.filter(installment -> !installment.getFromDate().isAfter(chargeOffDate) && installment.getDueDate().isAfter(chargeOffDate))
|
||||
.forEach(installment -> {
|
||||
final BigDecimal totalInterest = installment.getInterestOutstanding(transactionCtx.getCurrency()).getAmount();
|
||||
final long totalDaysInPeriod = ChronoUnit.DAYS.between(installment.getFromDate(), installment.getDueDate());
|
||||
final long daysTillChargeOff = ChronoUnit.DAYS.between(installment.getFromDate(), chargeOffDate);
|
||||
if (totalInterest.compareTo(BigDecimal.ZERO) > 0) {
|
||||
final long totalDaysInPeriod = ChronoUnit.DAYS.between(installment.getFromDate(), installment.getDueDate());
|
||||
final long daysTillChargeOff = ChronoUnit.DAYS.between(installment.getFromDate(), chargeOffDate);
|
||||
|
||||
final MathContext mc = MoneyHelper.getMathContext();
|
||||
final Money interestTillChargeOff = Money.of(transactionCtx.getCurrency(), totalInterest
|
||||
.divide(BigDecimal.valueOf(totalDaysInPeriod), mc).multiply(BigDecimal.valueOf(daysTillChargeOff), mc), mc);
|
||||
final MathContext mc = MoneyHelper.getMathContext();
|
||||
final Money interestTillChargeOff = Money.of(transactionCtx.getCurrency(), totalInterest
|
||||
.divide(BigDecimal.valueOf(totalDaysInPeriod), mc).multiply(BigDecimal.valueOf(daysTillChargeOff), mc), mc);
|
||||
|
||||
final BigDecimal interestRemoved = totalInterest.subtract(interestTillChargeOff.getAmount());
|
||||
installment.updatePrincipal(MathUtil.nullToZero(installment.getPrincipal()).add(interestRemoved));
|
||||
installment.updateInterestCharged(interestTillChargeOff.getAmount());
|
||||
final BigDecimal interestRemoved = totalInterest.subtract(interestTillChargeOff.getAmount());
|
||||
installment.updatePrincipal(MathUtil.nullToZero(installment.getPrincipal()).add(interestRemoved));
|
||||
installment.updateInterestCharged(interestTillChargeOff.getAmount());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user