Skip to content

Commit

Permalink
FINERACT-1971: Down payment (auto) transaction using installment mult…
Browse files Browse the repository at this point in the history
…iples of setting
  • Loading branch information
Jose Alberto Hernandez authored and adamsaghy committed May 7, 2024
1 parent 7499859 commit 849790e
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static BigDecimal roundToMultiplesOf(final BigDecimal existingVal, final
BigDecimal amountScaled = existingVal;
BigDecimal inMultiplesOfValue = BigDecimal.valueOf(inMultiplesOf.intValue());
if (inMultiplesOfValue.compareTo(BigDecimal.ZERO) > 0) {
amountScaled = existingVal.divide(inMultiplesOfValue, 0, RoundingMode.HALF_UP).multiply(inMultiplesOfValue);
amountScaled = existingVal.divide(inMultiplesOfValue, 0, MoneyHelper.getRoundingMode()).multiply(inMultiplesOfValue);
}
return amountScaled;
}
Expand All @@ -133,7 +133,7 @@ public static Money roundToMultiplesOf(final Money existingVal, final Integer in
BigDecimal amountScaled = existingVal.getAmount();
BigDecimal inMultiplesOfValue = BigDecimal.valueOf(inMultiplesOf.intValue());
if (inMultiplesOfValue.compareTo(BigDecimal.ZERO) > 0) {
amountScaled = amountScaled.divide(inMultiplesOfValue, 0, RoundingMode.HALF_UP).multiply(inMultiplesOfValue);
amountScaled = amountScaled.divide(inMultiplesOfValue, 0, MoneyHelper.getRoundingMode()).multiply(inMultiplesOfValue);
}
return Money.of(existingVal.getCurrency(), amountScaled);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import jakarta.annotation.PostConstruct;
import java.math.MathContext;
import java.math.RoundingMode;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MoneyHelper {

Expand Down Expand Up @@ -59,4 +61,10 @@ public static MathContext getMathContext() {
}
return mathContext;
}

public static void fetchRoundingModeFromGlobalConfig() {
roundingMode = RoundingMode.valueOf(staticConfigurationDomainService.getRoundingMode());
log.info("Fetch Rounding Mode from Global Config {}", roundingMode.name());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1581,23 +1581,23 @@ Feature: LoanCharge
Then Loan Transactions tab has the following data:
| Transaction date | Transaction Type | Amount | Principal | Interest | Fees | Penalties | Loan Balance |
| 01 January 2023 | Disbursement | 750.0 | 0.0 | 0.0 | 0.0 | 0.0 | 750.0 |
| 01 January 2023 | Down Payment | 187.5 | 187.5 | 0.0 | 0.0 | 0.0 | 562.5 |
| 01 February 2023 | Repayment | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 312.5 |
| 01 March 2023 | Repayment | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 62.5 |
| 01 April 2023 | Repayment | 250.0 | 62.5 | 0.0 | 0.0 | 0.0 | 0.0 |
| 05 April 2023 | Waive loan charges | 10.0 | 0.0 | 0.0 | 0.0 | 0.0 | 62.5 |
| 01 January 2023 | Down Payment | 188.0 | 188.0 | 0.0 | 0.0 | 0.0 | 562.0 |
| 01 February 2023 | Repayment | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 312.0 |
| 01 March 2023 | Repayment | 250.0 | 250.0 | 0.0 | 0.0 | 0.0 | 62.0 |
| 01 April 2023 | Repayment | 250.0 | 62.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 05 April 2023 | Waive loan charges | 10.0 | 0.0 | 0.0 | 0.0 | 0.0 | 62.0 |
Then On Loan Transactions tab the "Repayment" Transaction with date "01 April 2023" is reverted
Then Loan Repayment schedule has 5 periods, with the following data for periods:
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Waived | Outstanding |
| | | 01 January 2023 | | 750.0 | | | 0.0 | | 0.0 | 0.0 | | | | |
| 1 | 0 | 01 January 2023 | 01 February 2023 | 562.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 188.0 | 0.0 | 0.5 | 0.0 | 0.0 |
| 1 | 0 | 01 January 2023 | 01 January 2023 | 562.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 188.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 2 | 15 | 16 January 2023 | 01 February 2023 | 375.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 187.0 | 0.0 | 187.0 | 0.0 | 0.0 |
| 3 | 15 | 31 January 2023 | 01 March 2023 | 188.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 187.0 | 0.0 | 187.0 | 0.0 | 0.0 |
| 4 | 15 | 15 February 2023 | | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 125.5 | 0.0 | 125.5 | 0.0 | 62.5 |
| 4 | 15 | 15 February 2023 | | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 126.0 | 0.0 | 126.0 | 0.0 | 62.0 |
| 5 | 49 | 05 April 2023 | 05 April 2023 | 0.0 | 0.0 | 0.0 | 0.0 | 10.0 | 10.0 | 0.0 | 0.0 | 0.0 | 10.0 | 0.0 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Waived | Outstanding |
| 750 | 0 | 0 | 10 | 760 | 687.5 | 0 | 500 | 10 | 62.5 |
| 750 | 0 | 0 | 10 | 760 | 688.0 | 0 | 500 | 10 | 62.0 |

@TestRailId:C2994
Scenario: Waive charge on PIN4 progressive loan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2032,10 +2032,10 @@ Feature: Loan DownPayment
Then Loan Repayment schedule has 4 periods, with the following data for periods:
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| | | 01 January 2022 | | 1250.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 0 | 01 January 2022 | | 937.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 |
| 2 | 31 | 01 February 2022 | | 625.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 |
| 3 | 28 | 01 March 2022 | | 313.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 |
| 4 | 31 | 01 April 2022 | | 0.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 |
| 1 | 0 | 01 January 2022 | | 938.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 |
| 2 | 31 | 01 February 2022 | | 625.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 |
| 3 | 28 | 01 March 2022 | | 312.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 | 0.0 | 0.0 | 0.0 | 313.0 |
| 4 | 31 | 01 April 2022 | | 0.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 | 0.0 | 0.0 | 0.0 | 312.0 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 1250.0 | 0 | 0 | 0 | 1250.0 | 0.0 | 0 | 0 | 1250 |
Expand Down Expand Up @@ -2446,8 +2446,8 @@ Feature: Loan DownPayment
| 2 | 15 | 16 February 2024 | 16 February 2024 | 250.0 | 125.0 | 0.0 | 0.0 | 0.0 | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 |
| | | 20 February 2024 | | 625.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 3 | 0 | 20 February 2024 | 20 February 2024 | 719.0 | 156.0 | 0.0 | 0.0 | 0.0 | 156.0 | 156.0 | 0.0 | 0.0 | 0.0 |
| 4 | 15 | 02 March 2024 | 20 February 2024 | 359.0 | 360.0 | 0.0 | 0.0 | 0.0 | 360.0 | 360.0 | 360.0 | 0.0 | 0.0 |
| 5 | 15 | 17 March 2024 | 20 February 2024 | 0.0 | 359.0 | 0.0 | 0.0 | 0.0 | 359.0 | 359.0 | 359.0 | 0.0 | 0.0 |
| 4 | 15 | 02 March 2024 | 20 February 2024 | 360.0 | 359.0 | 0.0 | 0.0 | 0.0 | 359.0 | 359.0 | 359.0 | 0.0 | 0.0 |
| 5 | 15 | 17 March 2024 | 20 February 2024 | 0.0 | 360.0 | 0.0 | 0.0 | 0.0 | 360.0 | 360.0 | 360.0 | 0.0 | 0.0 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 1125.0 | 0.0 | 0.0 | 0.0 | 1125.0 | 1125.0 | 719.0 | 0.0 | 0.0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Feature: LoanReAmortization
| | | 01 January 2024 | | 500.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 0 | 01 January 2024 | 01 January 2024 | 375.0 | 125.0 | 0.0 | 0.0 | 0.0 | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 |
| 2 | 15 | 16 January 2024 | 25 January 2024 | 375.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 3 | 15 | 31 January 2024 | | 187.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 3 | 15 | 31 January 2024 | | 188.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 125.0 | 0.0 | 0.0 | 375.0 |
Expand Down Expand Up @@ -74,8 +74,8 @@ Feature: LoanReAmortization
| | | 01 January 2024 | | 500.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 0 | 01 January 2024 | 01 January 2024 | 375.0 | 125.0 | 0.0 | 0.0 | 0.0 | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 |
| 2 | 15 | 16 January 2024 | 25 January 2024 | 375.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 3 | 15 | 31 January 2024 | | 187.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 3 | 15 | 31 January 2024 | | 188.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 125.0 | 0.0 | 0.0 | 375.0 |
Expand All @@ -102,8 +102,8 @@ Feature: LoanReAmortization
| | | 01 January 2024 | | 500.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 0 | 01 January 2024 | 01 January 2024 | 375.0 | 125.0 | 0.0 | 0.0 | 0.0 | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 |
| 2 | 15 | 16 January 2024 | 25 January 2024 | 375.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 3 | 15 | 31 January 2024 | | 187.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 3 | 15 | 31 January 2024 | | 188.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 500.0 | 0.0 | 0.0 | 0.0 | 500.0 | 125.0 | 0.0 | 0.0 | 375.0 |
Expand Down Expand Up @@ -167,8 +167,8 @@ Feature: LoanReAmortization
| | | 01 January 2024 | | 500.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 0 | 01 January 2024 | 01 January 2024 | 375.0 | 125.0 | 0.0 | 0.0 | 0.0 | 125.0 | 125.0 | 0.0 | 0.0 | 0.0 |
| 2 | 15 | 16 January 2024 | | 375.0 | 0.0 | 0.0 | 0.0 | 10.0 | 10.0 | 0.0 | 0.0 | 0.0 | 10.0 |
| 3 | 15 | 31 January 2024 | | 187.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 3 | 15 | 31 January 2024 | | 188.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 | 0.0 | 0.0 | 0.0 | 187.0 |
| 4 | 15 | 15 February 2024 | | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 | 0.0 | 0.0 | 0.0 | 188.0 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 500.0 | 0.0 | 0.0 | 10.0 | 510.0 | 125.0 | 0.0 | 0.0 | 385.0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3139,10 +3139,10 @@ Feature: LoanRepayment
Then Loan Repayment schedule has 4 periods, with the following data for periods:
| Nr | Days | Date | Paid date | Balance of loan | Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| | | 01 September 2023 | | 1250.0 | | | 0.0 | | 0.0 | 0.0 | | | |
| 1 | 30 | 01 October 2023 | | 936.62 | 313.38 | 15.62 | 0.0 | 0.0 | 329.0 | 0.0 | 0.0 | 0.0 | 329.0 |
| 2 | 31 | 01 November 2023 | | 623.24 | 313.38 | 15.62 | 0.0 | 0.0 | 329.0 | 0.0 | 0.0 | 0.0 | 329.0 |
| 3 | 30 | 01 December 2023 | | 309.86 | 313.38 | 15.62 | 0.0 | 0.0 | 329.0 | 0.0 | 0.0 | 0.0 | 329.0 |
| 4 | 31 | 01 January 2024 | | 0.0 | 309.86 | 15.64 | 0.0 | 0.0 | 325.5 | 0.0 | 0.0 | 0.0 | 325.5 |
| 1 | 30 | 01 October 2023 | | 937.62 | 312.38 | 15.62 | 0.0 | 0.0 | 328.0 | 0.0 | 0.0 | 0.0 | 328.0 |
| 2 | 31 | 01 November 2023 | | 625.24 | 312.38 | 15.62 | 0.0 | 0.0 | 328.0 | 0.0 | 0.0 | 0.0 | 328.0 |
| 3 | 30 | 01 December 2023 | | 312.86 | 312.38 | 15.62 | 0.0 | 0.0 | 328.0 | 0.0 | 0.0 | 0.0 | 328.0 |
| 4 | 31 | 01 January 2024 | | 0.0 | 312.86 | 15.64 | 0.0 | 0.0 | 328.5 | 0.0 | 0.0 | 0.0 | 328.5 |
Then Loan Repayment schedule has the following data in Total row:
| Principal due | Interest | Fees | Penalties | Due | Paid | In advance | Late | Outstanding |
| 1250.0 | 62.50 | 0.0 | 0.0 | 1312.50 | 0.0 | 0.0 | 0.0 | 1312.50 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,9 @@ public LoanTransaction handleDownPayment(final LoanTransaction disbursementTrans
}
Money downPaymentMoney = Money.of(getCurrency(),
MathUtil.percentageOf(disbursementTransaction.getAmount(), disbursedAmountPercentageForDownPayment, 19));

if (getLoanProduct().getInstallmentAmountInMultiplesOf() != null) {
downPaymentMoney = Money.roundToMultiplesOf(downPaymentMoney, getLoanProduct().getInstallmentAmountInMultiplesOf());
}
Money adjustedDownPaymentMoney = switch (getLoanProductRelatedDetail().getLoanScheduleType()) {
// For Cumulative loan: To check whether the loan was overpaid when the disbursement happened and to get the
// proper amount after the disbursement we are using two balances:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,10 +1206,11 @@ private double paymentPerPeriod(final BigDecimal periodicInterestRate, final Mon
double installmentAmount = FinanicalFunctions.pmt(periodicInterestRate.doubleValue(), periodsRemaining.doubleValue(),
principalDouble, futureValue, false);

BigDecimal fixedEmiAmount = BigDecimal.valueOf(installmentAmount);
if (this.installmentAmountInMultiplesOf != null) {
installmentAmount = Money.roundToMultiplesOf(installmentAmount, this.installmentAmountInMultiplesOf);
fixedEmiAmount = Money.roundToMultiplesOf(fixedEmiAmount, this.installmentAmountInMultiplesOf);
}
setFixedEmiAmount(BigDecimal.valueOf(installmentAmount));
setFixedEmiAmount(fixedEmiAmount);
}
return getFixedEmiAmount().doubleValue();
}
Expand Down
Loading

0 comments on commit 849790e

Please sign in to comment.