Skip to content

Commit

Permalink
SU-530 (#1434)
Browse files Browse the repository at this point in the history
* SU-503
  • Loading branch information
faheem205 authored Dec 24, 2024
1 parent 017ef75 commit 6045929
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1207,7 +1207,8 @@ public BigDecimal calculatePerInstallmentChargeAmount(final ChargeCalculationTyp
this.outstandingBalance = this.loanRepaymentScheduleDetail.getPrincipal();
List<LoanRepaymentScheduleInstallment> 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();
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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<LoanRepaymentScheduleInstallment> graceInstallments = this.getRepaymentScheduleInstallments().stream()
Expand Down Expand Up @@ -5834,7 +5839,7 @@ public List<LoanInstallmentCharge> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 6045929

Please sign in to comment.