From 6045929bbafa4860d0867b334cf0f02e5ae2e29f Mon Sep 17 00:00:00 2001 From: Faheem Ahmad Date: Tue, 24 Dec 2024 17:52:05 +0500 Subject: [PATCH] SU-530 (#1434) * SU-503 --- .../portfolio/loanaccount/domain/Loan.java | 17 +++++++++++------ .../loanaccount/domain/LoanCharge.java | 2 +- .../service/LoanChargeAssembler.java | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java index a1d43c507b..e234aa405a 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java @@ -1179,11 +1179,11 @@ public BigDecimal getTotalInterest() { private BigDecimal calculatePerInstallmentChargeAmount(final LoanCharge loanCharge) { return calculatePerInstallmentChargeAmount(loanCharge.getChargeCalculation(), loanCharge.getPercentage(), - loanCharge.amountOrPercentage(), loanCharge.getCharge().getParentChargeId()); + loanCharge.amountOrPercentage(), loanCharge.getCharge().getParentChargeId(), loanCharge); } public BigDecimal calculatePerInstallmentChargeAmount(final ChargeCalculationType calculationType, final BigDecimal percentage, - BigDecimal chargeAmount, Long parentChargeId) { + BigDecimal chargeAmount, Long parentChargeId, LoanCharge loanCharge) { Money amount = Money.zero(getCurrency()); if (calculationType.isCustomPercentageBasedDistributedCharge()) { // Disbursement based mandatory insurance or // aval @@ -1207,7 +1207,8 @@ public BigDecimal calculatePerInstallmentChargeAmount(final ChargeCalculationTyp this.outstandingBalance = this.loanRepaymentScheduleDetail.getPrincipal(); List installments = getRepaymentScheduleInstallmentsIgnoringTotalGrace(); for (final LoanRepaymentScheduleInstallment installment : installments) { - amount = amount.plus(calculateInstallmentChargeAmount(calculationType, percentage, installment, chargeAmount, parentChargeId)); + amount = amount.plus( + calculateInstallmentChargeAmount(calculationType, percentage, installment, chargeAmount, parentChargeId, loanCharge)); } return amount.getAmount(); } @@ -1226,7 +1227,7 @@ public BigDecimal getTotalWrittenOff() { private Money outstandingBalance = null; private Money calculateInstallmentChargeAmount(final ChargeCalculationType calculationType, final BigDecimal percentage, - final LoanRepaymentScheduleInstallment installment, BigDecimal chargeAmount, Long parentChargeId) { + final LoanRepaymentScheduleInstallment installment, BigDecimal chargeAmount, Long parentChargeId, LoanCharge loanCharge) { Money amount = Money.zero(getCurrency()); Money percentOf = Money.zero(getCurrency()); switch (calculationType) { @@ -1279,7 +1280,11 @@ private Money calculateInstallmentChargeAmount(final ChargeCalculationType calcu } else if (calculationType.isPercentageOfAnotherCharge() && calculationType.equals(ChargeCalculationType.ACHG)) { // Term/VAT // on // insurance - amount = amount.plus(percentOf.getAmount().multiply(percentage).divide(BigDecimal.valueOf(100), 0, RoundingMode.HALF_UP)); + if (loanCharge != null && loanCharge.isVatChargeOfHonoCharge()) { + amount = amount.plus(Money.of(getCurrency(), loanCharge.getVatAmountOfHonoCharge(installment.getInstallmentNumber()))); + } else { + amount = amount.plus(percentOf.getAmount().multiply(percentage).divide(BigDecimal.valueOf(100), 0, RoundingMode.HALF_UP)); + } } else if (calculationType.isCustomPercentageOfOutstandingPrincipalCharge()) { Integer numberOfRepayments = this.getLoanProductRelatedDetail().getNumberOfRepayments(); List graceInstallments = this.getRepaymentScheduleInstallments().stream() @@ -5834,7 +5839,7 @@ public List generateInstallmentLoanCharges(final LoanChar } } else { amount = calculateInstallmentChargeAmount(loanCharge.getChargeCalculation(), loanCharge.getPercentage(), installment, - loanCharge.amountOrPercentage(), loanCharge.getCharge().getParentChargeId()).getAmount(); + loanCharge.amountOrPercentage(), loanCharge.getCharge().getParentChargeId(), loanCharge).getAmount(); } if (((loanCharge.isCustomFlatDistributedCharge() || loanCharge.isCustomPercentageBasedDistributedCharge() || loanCharge.isCustomPercentageOfOutstandingPrincipalCharge()) diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java index 715ed3e770..58ad1a3777 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java @@ -641,7 +641,7 @@ public Map update(final JsonCommand command, final BigDecimal am loanCharge = BigDecimal.ZERO; if (isInstalmentFee()) { loanCharge = this.loan.calculatePerInstallmentChargeAmount(ChargeCalculationType.fromInt(this.chargeCalculation), - this.percentage, this.amountOrPercentage, this.getCharge().getParentChargeId()); + this.percentage, this.amountOrPercentage, this.getCharge().getParentChargeId(), this); } if (loanCharge.compareTo(BigDecimal.ZERO) == 0) { loanCharge = percentageOf(this.amountPercentageAppliedTo); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeAssembler.java index c5133c8320..6fc099b5eb 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeAssembler.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeAssembler.java @@ -493,7 +493,7 @@ public LoanCharge createNewFromJson(final Loan loan, final Charge chargeDefiniti } else { loanCharge = loan.calculatePerInstallmentChargeAmount( ChargeCalculationType.fromInt(chargeDefinition.getChargeCalculation()), percentage, null, - chargeDefinition.getParentChargeId()); + chargeDefinition.getParentChargeId(), null); } }