Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FBR-104 #200

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.fineract.accounting.glaccount.data.GLAccountData;
import org.apache.fineract.accounting.glaccount.domain.GLAccount;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
Expand Down Expand Up @@ -826,14 +828,14 @@ public void setChargeRanges(List<ChargeRange> chargeRanges) {
this.chargeRanges = chargeRanges;
}

public BigDecimal getAddOnDisbursementChargeRate(LocalDate disbursementDate, LocalDate firstRepaymentDate) {
public Pair<Integer, BigDecimal> getAddOnDisbursementChargeRate(LocalDate disbursementDate, LocalDate firstRepaymentDate) {
BigDecimal addOnDisbursementChargeRate = BigDecimal.ZERO;
int defaultDays = LoanProductConstants.DEFAULT_LIMIT_OF_DAYS_FOR_ADDON;
int daysAddOnApplicable = 0;

if (isDisbursementCharge() && isAddOnDisbursementType() && this.chargeRanges != null && !this.chargeRanges.isEmpty()) {
// calculate days since disbursement date
int numberOfDays = Math.toIntExact(daysBetween(disbursementDate, firstRepaymentDate));
int daysAddOnApplicable = 0;
if (numberOfDays > defaultDays) {
daysAddOnApplicable = numberOfDays - defaultDays;
}
Expand All @@ -846,7 +848,7 @@ public BigDecimal getAddOnDisbursementChargeRate(LocalDate disbursementDate, Loc
}
}

return addOnDisbursementChargeRate;
return Pair.of(daysAddOnApplicable, addOnDisbursementChargeRate);
}

private static long daysBetween(LocalDate d1, LocalDate d2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
Expand Down Expand Up @@ -424,16 +426,19 @@ public void update(final BigDecimal amount, final LocalDate dueDate, final BigDe
if (this.loan != null && isDisbursementCharge() && this.isAddOnDisbursementType()) {
LocalDate disbursementDate = this.loan.getDisbursementDate();
LocalDate firstRepaymentDate = this.loan.fetchRepaymentScheduleInstallment(1).getDueDate();
BigDecimal feeRate = this.charge.getAddOnDisbursementChargeRate(disbursementDate, firstRepaymentDate);
Pair<Integer, BigDecimal> addOnDaysAndRate = this.charge.getAddOnDisbursementChargeRate(disbursementDate, firstRepaymentDate);
Integer daysToApplyAddOn = addOnDaysAndRate.getLeft();
BigDecimal feeRate = addOnDaysAndRate.getRight();
this.percentage = feeRate;
updatedAmount = feeRate;
loanCharge = percentageOf(this.amountPercentageAppliedTo).multiply(BigDecimal.valueOf(daysToApplyAddOn), MoneyHelper.getMathContext());
} else {
this.percentage = amount;
if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
loanCharge = percentageOf(this.amountPercentageAppliedTo);
}
}
this.amountPercentageAppliedTo = loanPrincipal;
if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
loanCharge = percentageOf(this.amountPercentageAppliedTo);
}
this.amount = minimumAndMaximumCap(loanCharge);
break;
}
Expand Down