You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "somasorosdpc (via GitHub)" <gi...@apache.org> on 2025/01/30 16:06:14 UTC
[PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
somasorosdpc opened a new pull request, #4294:
URL: https://github.com/apache/fineract/pull/4294
## Description
[FINERACT-2162](https://issues.apache.org/jira/browse/FINERACT-2162):
Chargeback implementation for progressive interest recalculation enabled loan when no payment allocation set.
## Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
- [ ] Write the commit message as per https://github.com/apache/fineract/#pull-requests
- [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
- [ ] Create/update unit or integration tests for verifying the changes made.
- [ ] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
- [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
- [ ] Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)
FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949781097
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
+ ? ctx.getInstallments().stream().filter(i -> i.getDueDate().isEqual(loanTransaction.getDateOf())).findAny()
+ .orElseThrow()
+ : ctx.getInstallments().stream().filter(i -> !loanTransaction.getTransactionDate().isBefore(i.getFromDate())
+ && i.getDueDate().isAfter(loanTransaction.getTransactionDate())).findAny().orElseThrow();
+ // special because principal and interest dues are already updated.
+ recognizeAmountsAfterChargebackWithInterestRecalculation(ctx, instalment, chargebackAllocation);
+ } else {
+ // N+1
+ LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
Review Comment:
What if there is no additional installment yet?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949813572
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/ProgressiveLoanInterestScheduleModel.java:
##########
@@ -212,10 +215,14 @@ private Consumer<RepaymentPeriod> updateInterestPeriodOnRepaymentPeriod(final Lo
}
private Optional<InterestPeriod> findInterestPeriodForBalanceChange(final RepaymentPeriod repaymentPeriod,
- final LocalDate balanceChangeDate) {
+ final LocalDate balanceChangeDate, final boolean isChangeOnMaturityDate) {
if (repaymentPeriod == null || balanceChangeDate == null) {
return Optional.empty();
}
+ if (isChangeOnMaturityDate) {
Review Comment:
Can you help me understand this logic better?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949781097
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
+ ? ctx.getInstallments().stream().filter(i -> i.getDueDate().isEqual(loanTransaction.getDateOf())).findAny()
+ .orElseThrow()
+ : ctx.getInstallments().stream().filter(i -> !loanTransaction.getTransactionDate().isBefore(i.getFromDate())
+ && i.getDueDate().isAfter(loanTransaction.getTransactionDate())).findAny().orElseThrow();
+ // special because principal and interest dues are already updated.
+ recognizeAmountsAfterChargebackWithInterestRecalculation(ctx, instalment, chargebackAllocation);
+ } else {
+ // N+1
+ LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
Review Comment:
What if there is no additional installment yet?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "somasorosdpc (via GitHub)" <gi...@apache.org>.
somasorosdpc commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1950832431
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -540,8 +644,39 @@ private Map<AllocationType, Money> adjustOriginalAllocationWithFormerChargebacks
return allocation;
}
- private void recognizeAmountsAfterChargeback(final TransactionCtx ctx, final LocalDate transactionDate,
- final LoanRepaymentScheduleInstallment installment, final Map<AllocationType, Money> chargebackAllocation) {
+ private void recognizeFeePenaltiesAmountsAfterChargeback(TransactionCtx ctx, LoanRepaymentScheduleInstallment installment,
+ Map<AllocationType, Money> chargebackAllocation) {
+ MonetaryCurrency currency = ctx.getCurrency();
+ Money fee = chargebackAllocation.get(FEE);
+ if (fee.isGreaterThanZero()) {
+ installment.addToCreditedFee(fee.getAmount());
+ installment.addToChargePortion(fee, Money.zero(currency), Money.zero(currency), Money.zero(currency), Money.zero(currency),
+ Money.zero(currency));
+ }
+
+ Money penalty = chargebackAllocation.get(PENALTY);
+ if (penalty.isGreaterThanZero()) {
+ installment.addToCreditedPenalty(penalty.getAmount());
+ installment.addToChargePortion(Money.zero(currency), Money.zero(currency), Money.zero(currency), penalty, Money.zero(currency),
+ Money.zero(currency));
+ }
+ }
+
+ private void recognizeAmountsAfterChargebackWithInterestRecalculation(TransactionCtx ctx, LoanRepaymentScheduleInstallment installment,
+ Map<AllocationType, Money> chargebackAllocation) {
+ Money principal = chargebackAllocation.get(PRINCIPAL);
+ if (principal.isGreaterThanZero()) {
+ installment.addToCreditedPrincipal(principal.getAmount());
Review Comment:
refactored. It was not needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949807660
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -327,19 +390,20 @@ private void calculateLastUnpaidRepaymentPeriodEMI(ProgressiveLoanInterestSchedu
MathContext mc = scheduleModel.mc();
Money totalDueInterest = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getDueInterest).reduce(scheduleModel.zero(),
(m1, m2) -> m1.plus(m2, mc)); // 1.46
- Money totalEMI = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getEmi).reduce(scheduleModel.zero(),
+ Money totalEMI = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getCalculatedEmi).reduce(scheduleModel.zero(),
(m1, m2) -> m1.plus(m2, mc)); // 101.48
Money totalDisbursedAmount = scheduleModel.repaymentPeriods().stream()
.flatMap(rp -> rp.getInterestPeriods().stream().map(InterestPeriod::getDisbursementAmount))
- .reduce(scheduleModel.zero(), (m1, m2) -> m1.plus(m2, mc)); // 100
+ .reduce(scheduleModel.zero(), (m1, m2) -> m1.plus(m2, mc)) // 100
+ .plus(scheduleModel.getTotalChargebackPrincipal(), mc); //
Money diff = totalDisbursedAmount.plus(totalDueInterest, mc).minus(totalEMI, mc);
Optional<RepaymentPeriod> findLastUnpaidRepaymentPeriod = scheduleModel.repaymentPeriods().stream().filter(rp -> !rp.isFullyPaid())
.reduce((first, second) -> second);
findLastUnpaidRepaymentPeriod.ifPresent(repaymentPeriod -> {
repaymentPeriod.setEmi(repaymentPeriod.getEmi().add(diff, mc));
- if (repaymentPeriod.getEmi().isLessThan(repaymentPeriod.getTotalPaidAmount())) {
- repaymentPeriod.setEmi(repaymentPeriod.getTotalPaidAmount());
+ if (repaymentPeriod.getEmi().isLessThan(repaymentPeriod.getTotalCountablePaidAmount())) {
+ repaymentPeriod.setEmi(repaymentPeriod.getTotalPaidAmount().minus(repaymentPeriod.getTotalChargebackAmount(), mc));
Review Comment:
Why to remove the chargeback?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949788640
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
+ ? ctx.getInstallments().stream().filter(i -> i.getDueDate().isEqual(loanTransaction.getDateOf())).findAny()
+ .orElseThrow()
+ : ctx.getInstallments().stream().filter(i -> !loanTransaction.getTransactionDate().isBefore(i.getFromDate())
+ && i.getDueDate().isAfter(loanTransaction.getTransactionDate())).findAny().orElseThrow();
+ // special because principal and interest dues are already updated.
+ recognizeAmountsAfterChargebackWithInterestRecalculation(ctx, instalment, chargebackAllocation);
+ } else {
+ // N+1
+ LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
+ .filter(LoanRepaymentScheduleInstallment::isAdditional).findAny()
+ .or(() -> createAdditionalInstalment(loanTransaction, ctx)).orElseThrow();
+ // generic
+ recognizeAmountsAfterChargeback(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
+ if (instalment.getDueDate().isBefore(loanTransaction.getTransactionDate())) {
+ instalment.updateDueDate(loanTransaction.getTransactionDate());
+ }
+ }
+
+ allocateOverpayment(loanTransaction, ctx);
+ }
+
+ private Optional<LoanRepaymentScheduleInstallment> createAdditionalInstalment(LoanTransaction loanTransaction,
+ ProgressiveTransactionCtx ctx) {
+ LoanRepaymentScheduleInstallment installment = new LoanRepaymentScheduleInstallment(loanTransaction.getLoan(),
+ (ctx.getInstallments().size() + 1), ctx.getModel().getMaturityDate(), loanTransaction.getTransactionDate(), ZERO, ZERO,
+ ZERO, ZERO, false, null);
+ installment.markAsAdditional();
+ loanTransaction.getLoan().addLoanRepaymentScheduleInstallment(installment);
+ return Optional.of(installment);
+ }
+
+ private Map<AllocationType, Money> calculateChargebackAllocationMapByCreditAllocationRule(LoanTransaction loanTransaction,
+ ProgressiveTransactionCtx ctx) {
+ MonetaryCurrency currency = ctx.getCurrency();
+ LoanTransaction originalTransaction = findChargebackOriginalTransaction(loanTransaction, ctx);
+ // get the original allocation from the opriginal transaction
+ Map<AllocationType, Money> originalAllocationNotAdjusted = getOriginalAllocation(originalTransaction, currency);
+ LoanCreditAllocationRule chargeBackAllocationRule = getChargebackAllocationRules(loanTransaction);
+
+ // if there were earlier chargebacks then let's calculate the remaining amounts for each portion
+ Map<AllocationType, Money> originalAllocation = adjustOriginalAllocationWithFormerChargebacks(originalTransaction,
+ originalAllocationNotAdjusted, loanTransaction, ctx, chargeBackAllocationRule);
+
+ // calculate the current chargeback allocation
+ return calculateChargebackAllocationMap(originalAllocation, loanTransaction.getAmount(currency).getAmount(),
+ chargeBackAllocationRule.getAllocationTypes(), currency);
+ }
+
+ protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ // TODO refactor if needed
+ if (loanTransaction.getLoan().isInterestBearing()
Review Comment:
You can use the `isInterestBearingAndInterestRecalculationEnabled` instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949793899
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -540,8 +644,39 @@ private Map<AllocationType, Money> adjustOriginalAllocationWithFormerChargebacks
return allocation;
}
- private void recognizeAmountsAfterChargeback(final TransactionCtx ctx, final LocalDate transactionDate,
- final LoanRepaymentScheduleInstallment installment, final Map<AllocationType, Money> chargebackAllocation) {
+ private void recognizeFeePenaltiesAmountsAfterChargeback(TransactionCtx ctx, LoanRepaymentScheduleInstallment installment,
+ Map<AllocationType, Money> chargebackAllocation) {
+ MonetaryCurrency currency = ctx.getCurrency();
+ Money fee = chargebackAllocation.get(FEE);
+ if (fee.isGreaterThanZero()) {
+ installment.addToCreditedFee(fee.getAmount());
+ installment.addToChargePortion(fee, Money.zero(currency), Money.zero(currency), Money.zero(currency), Money.zero(currency),
+ Money.zero(currency));
+ }
+
+ Money penalty = chargebackAllocation.get(PENALTY);
+ if (penalty.isGreaterThanZero()) {
+ installment.addToCreditedPenalty(penalty.getAmount());
+ installment.addToChargePortion(Money.zero(currency), Money.zero(currency), Money.zero(currency), penalty, Money.zero(currency),
+ Money.zero(currency));
+ }
+ }
+
+ private void recognizeAmountsAfterChargebackWithInterestRecalculation(TransactionCtx ctx, LoanRepaymentScheduleInstallment installment,
+ Map<AllocationType, Money> chargebackAllocation) {
+ Money principal = chargebackAllocation.get(PRINCIPAL);
+ if (principal.isGreaterThanZero()) {
+ installment.addToCreditedPrincipal(principal.getAmount());
Review Comment:
You need to increase the Principal as well, no? (`addToPrincipal`)
Also why do we need `recognizeAmountsAfterChargeback` and `recognizeAmountsAfterChargebackWithInterestRecalculation`? It should be the same...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949779474
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
Review Comment:
This looks a little bit complicated. Isnt there an easier or more straightforward way to get the current?? installment?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "somasorosdpc (via GitHub)" <gi...@apache.org>.
somasorosdpc commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1950642181
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
Review Comment:
it is not the current installment in general meaning. before maturity we need the installment from inclusive due exclusive interval. On maturity date we need last installment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "somasorosdpc (via GitHub)" <gi...@apache.org>.
somasorosdpc commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1950734154
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/InterestPeriod.java:
##########
@@ -116,6 +146,13 @@ public void updateOutstandingLoanBalance() {
}
}
+ /**
+ * Include principal like amounts (all disbursement amount + chargeback principal)
+ */
+ public Money getDisbursedAmounts() {
Review Comment:
renamed - refactored
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949782805
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
+ ? ctx.getInstallments().stream().filter(i -> i.getDueDate().isEqual(loanTransaction.getDateOf())).findAny()
+ .orElseThrow()
+ : ctx.getInstallments().stream().filter(i -> !loanTransaction.getTransactionDate().isBefore(i.getFromDate())
+ && i.getDueDate().isAfter(loanTransaction.getTransactionDate())).findAny().orElseThrow();
+ // special because principal and interest dues are already updated.
+ recognizeAmountsAfterChargebackWithInterestRecalculation(ctx, instalment, chargebackAllocation);
+ } else {
+ // N+1
+ LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
+ .filter(LoanRepaymentScheduleInstallment::isAdditional).findAny()
+ .or(() -> createAdditionalInstalment(loanTransaction, ctx)).orElseThrow();
Review Comment:
This would never throw anything, no? Does `orElseThrow` needed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949801618
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -188,13 +191,60 @@ public void payPrincipal(ProgressiveLoanInterestScheduleModel scheduleModel, Loc
repaymentPeriod.ifPresent(rp -> {
// If any period total paid > calculated EMI, then set EMI to total paid -> effectively it is marked as
// fully paid
- if (rp.getTotalPaidAmount().compareTo(rp.getEmi()) > 0) {
- rp.setEmi(rp.getTotalPaidAmount());
+ if (rp.getTotalPaidAmount().isGreaterThan(rp.getCalculatedEmi())) {
+ rp.setEmi(rp.getTotalCountablePaidAmount());
calculateLastUnpaidRepaymentPeriodEMI(scheduleModel);
}
});
}
+ private void addChargebackAmountsToInterestPeriod(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate transactionDate,
+ Money chargebackPrincipalAmount, Money chargeBackInterestAmount) {
+ scheduleModel.repaymentPeriods().stream().filter(checkRepaymentPeriodIsInChargebackRange(scheduleModel, transactionDate))
+ .findFirst()
+ .flatMap(repaymentPeriod -> repaymentPeriod.getInterestPeriods().stream()
+ .filter(interestPeriod -> interestPeriod.getFromDate().equals(transactionDate)).reduce((v1, v2) -> v2))
Review Comment:
Can multiple interest period has the same from date?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #4294:
URL: https://github.com/apache/fineract/pull/4294
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "somasorosdpc (via GitHub)" <gi...@apache.org>.
somasorosdpc commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1950489725
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/ProgressiveLoanInterestScheduleModel.java:
##########
@@ -212,10 +215,14 @@ private Consumer<RepaymentPeriod> updateInterestPeriodOnRepaymentPeriod(final Lo
}
private Optional<InterestPeriod> findInterestPeriodForBalanceChange(final RepaymentPeriod repaymentPeriod,
- final LocalDate balanceChangeDate) {
+ final LocalDate balanceChangeDate, final boolean isChangeOnMaturityDate) {
if (repaymentPeriod == null || balanceChangeDate == null) {
return Optional.empty();
}
+ if (isChangeOnMaturityDate) {
Review Comment:
If we have a pre maturity chargeback, we should display it on the "next day's" installment. If we are on maturity date, we should add chargeback to the current (last) installment ( after maturity we create N+1th installment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949805103
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -327,19 +390,20 @@ private void calculateLastUnpaidRepaymentPeriodEMI(ProgressiveLoanInterestSchedu
MathContext mc = scheduleModel.mc();
Money totalDueInterest = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getDueInterest).reduce(scheduleModel.zero(),
(m1, m2) -> m1.plus(m2, mc)); // 1.46
- Money totalEMI = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getEmi).reduce(scheduleModel.zero(),
+ Money totalEMI = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getCalculatedEmi).reduce(scheduleModel.zero(),
(m1, m2) -> m1.plus(m2, mc)); // 101.48
Money totalDisbursedAmount = scheduleModel.repaymentPeriods().stream()
.flatMap(rp -> rp.getInterestPeriods().stream().map(InterestPeriod::getDisbursementAmount))
- .reduce(scheduleModel.zero(), (m1, m2) -> m1.plus(m2, mc)); // 100
+ .reduce(scheduleModel.zero(), (m1, m2) -> m1.plus(m2, mc)) // 100
+ .plus(scheduleModel.getTotalChargebackPrincipal(), mc); //
Review Comment:
Can we separate disbursements amount and chargedback amounts? It might lead to misunderstandings...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949812986
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/ProgressiveLoanInterestScheduleModel.java:
##########
@@ -201,7 +201,10 @@ Optional<RepaymentPeriod> findRepaymentPeriodForBalanceChange(final LocalDate ba
private Consumer<RepaymentPeriod> updateInterestPeriodOnRepaymentPeriod(final LocalDate balanceChangeDate, final Money disbursedAmount,
final Money correctionAmount) {
return repaymentPeriod -> {
- final Optional<InterestPeriod> interestPeriodOptional = findInterestPeriodForBalanceChange(repaymentPeriod, balanceChangeDate);
+ final boolean isChangeOnMaturityDate = isLastRepaymentPeriod(repaymentPeriod)
+ && balanceChangeDate.isEqual(repaymentPeriod.getDueDate());
+ final Optional<InterestPeriod> interestPeriodOptional = findInterestPeriodForBalanceChange(repaymentPeriod, balanceChangeDate,
+ isChangeOnMaturityDate);
Review Comment:
What is this new flag?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949815303
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/ProgressiveLoanInterestScheduleModel.java:
##########
@@ -283,37 +285,81 @@ private InterestPeriod findPreviousInterestPeriod(final RepaymentPeriod repaymen
}
}
+ /**
+ * Gives back the total due interest amount in the whole repayment schedule. Also includes chargeback interest
+ * amount.
+ *
+ * @return
+ */
public Money getTotalDueInterest() {
return repaymentPeriods().stream().flatMap(rp -> rp.getInterestPeriods().stream().map(InterestPeriod::getCalculatedDueInterest))
.reduce(zero(), Money::plus);
}
+ /**
+ * Gives back the total due principal amount in the whole repayment schedule based on disbursements. Do not contain
+ * chargeback principal amount.
+ *
+ * @return
+ */
public Money getTotalDuePrincipal() {
- return repaymentPeriods.stream().flatMap(rp -> rp.getInterestPeriods().stream().map(InterestPeriod::getDisbursementAmount))
- .reduce(zero(), Money::plus);
+ return repaymentPeriods.stream().map(RepaymentPeriod::getDisbursedAmounts).reduce(zero(), Money::plus);
}
+ /**
+ * Gives back the total paid interest amount in the whole repayment schedule.
+ *
+ * @return
+ */
public Money getTotalPaidInterest() {
return repaymentPeriods().stream().map(RepaymentPeriod::getPaidInterest).reduce(zero, Money::plus);
}
+ /**
+ * Gives back the total paid principal amount in the whole repayment schedule.
+ *
+ * @return
+ */
public Money getTotalPaidPrincipal() {
return repaymentPeriods().stream().map(RepaymentPeriod::getPaidPrincipal).reduce(zero, Money::plus);
}
+ /**
+ * Gives back the total chargeback principal amount in the whole repayment schedule.
+ *
+ * @return
+ */
+ public Money getTotalChargebackPrincipal() {
+ return repaymentPeriods().stream().map(RepaymentPeriod::getChargebackPrincipal).reduce(zero, Money::plus);
+ }
+
public Optional<RepaymentPeriod> findRepaymentPeriod(@NotNull LocalDate transactionDate) {
return repaymentPeriods.stream() //
.filter(period -> isInPeriod(transactionDate, period.getFromDate(), period.getDueDate(), period.isFirstRepaymentPeriod()))//
.findFirst();
}
+ /**
+ * Check if there is a disbursement in the model.
+ *
+ * @return
+ */
public boolean isEmpty() {
return repaymentPeriods.stream() //
.filter(rp -> !rp.getEmi().isZero()) //
.findFirst() //
.isEmpty(); //
}
+ @NotNull
+ public RepaymentPeriod getLastRepaymentPeriod() {
+ return repaymentPeriods.get(repaymentPeriods.size() - 1);
+ }
+
+ public boolean isLastRepaymentPeriod(@NotNull RepaymentPeriod repaymentPeriod) {
+ return getLastRepaymentPeriod().getDueDate().equals(repaymentPeriod.getDueDate());
Review Comment:
reference equality?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949806911
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -327,19 +390,20 @@ private void calculateLastUnpaidRepaymentPeriodEMI(ProgressiveLoanInterestSchedu
MathContext mc = scheduleModel.mc();
Money totalDueInterest = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getDueInterest).reduce(scheduleModel.zero(),
(m1, m2) -> m1.plus(m2, mc)); // 1.46
- Money totalEMI = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getEmi).reduce(scheduleModel.zero(),
+ Money totalEMI = scheduleModel.repaymentPeriods().stream().map(RepaymentPeriod::getCalculatedEmi).reduce(scheduleModel.zero(),
(m1, m2) -> m1.plus(m2, mc)); // 101.48
Money totalDisbursedAmount = scheduleModel.repaymentPeriods().stream()
.flatMap(rp -> rp.getInterestPeriods().stream().map(InterestPeriod::getDisbursementAmount))
- .reduce(scheduleModel.zero(), (m1, m2) -> m1.plus(m2, mc)); // 100
+ .reduce(scheduleModel.zero(), (m1, m2) -> m1.plus(m2, mc)) // 100
+ .plus(scheduleModel.getTotalChargebackPrincipal(), mc); //
Money diff = totalDisbursedAmount.plus(totalDueInterest, mc).minus(totalEMI, mc);
Optional<RepaymentPeriod> findLastUnpaidRepaymentPeriod = scheduleModel.repaymentPeriods().stream().filter(rp -> !rp.isFullyPaid())
.reduce((first, second) -> second);
findLastUnpaidRepaymentPeriod.ifPresent(repaymentPeriod -> {
repaymentPeriod.setEmi(repaymentPeriod.getEmi().add(diff, mc));
- if (repaymentPeriod.getEmi().isLessThan(repaymentPeriod.getTotalPaidAmount())) {
- repaymentPeriod.setEmi(repaymentPeriod.getTotalPaidAmount());
+ if (repaymentPeriod.getEmi().isLessThan(repaymentPeriod.getTotalCountablePaidAmount())) {
Review Comment:
Again this `total countable paid amount`....
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949812399
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/InterestPeriod.java:
##########
@@ -116,6 +146,13 @@ public void updateOutstandingLoanBalance() {
}
}
+ /**
+ * Include principal like amounts (all disbursement amount + chargeback principal)
+ */
+ public Money getDisbursedAmounts() {
Review Comment:
Again... if it is called "disbursed" amounts, than it cannot contains chargebacks... either keep this elsewhere or you can have a "getCreditedAmounts" which contains disbursed amounts and charged back amounts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949786664
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
+ ? ctx.getInstallments().stream().filter(i -> i.getDueDate().isEqual(loanTransaction.getDateOf())).findAny()
+ .orElseThrow()
+ : ctx.getInstallments().stream().filter(i -> !loanTransaction.getTransactionDate().isBefore(i.getFromDate())
+ && i.getDueDate().isAfter(loanTransaction.getTransactionDate())).findAny().orElseThrow();
+ // special because principal and interest dues are already updated.
+ recognizeAmountsAfterChargebackWithInterestRecalculation(ctx, instalment, chargebackAllocation);
+ } else {
+ // N+1
+ LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
+ .filter(LoanRepaymentScheduleInstallment::isAdditional).findAny()
+ .or(() -> createAdditionalInstalment(loanTransaction, ctx)).orElseThrow();
+ // generic
+ recognizeAmountsAfterChargeback(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
+ if (instalment.getDueDate().isBefore(loanTransaction.getTransactionDate())) {
Review Comment:
Its minor, but transaction date would never be earlier than the due date, so it would always update the additional installment due date, except if it is equal, but anyway it cause no issue...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949801618
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -188,13 +191,60 @@ public void payPrincipal(ProgressiveLoanInterestScheduleModel scheduleModel, Loc
repaymentPeriod.ifPresent(rp -> {
// If any period total paid > calculated EMI, then set EMI to total paid -> effectively it is marked as
// fully paid
- if (rp.getTotalPaidAmount().compareTo(rp.getEmi()) > 0) {
- rp.setEmi(rp.getTotalPaidAmount());
+ if (rp.getTotalPaidAmount().isGreaterThan(rp.getCalculatedEmi())) {
+ rp.setEmi(rp.getTotalCountablePaidAmount());
calculateLastUnpaidRepaymentPeriodEMI(scheduleModel);
}
});
}
+ private void addChargebackAmountsToInterestPeriod(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate transactionDate,
+ Money chargebackPrincipalAmount, Money chargeBackInterestAmount) {
+ scheduleModel.repaymentPeriods().stream().filter(checkRepaymentPeriodIsInChargebackRange(scheduleModel, transactionDate))
+ .findFirst()
+ .flatMap(repaymentPeriod -> repaymentPeriod.getInterestPeriods().stream()
+ .filter(interestPeriod -> interestPeriod.getFromDate().equals(transactionDate)).reduce((v1, v2) -> v2))
Review Comment:
Can multiple interest period has the same from date?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949803822
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -290,7 +342,18 @@ private ProgressiveLoanInterestScheduleModel recalculateScheduleModelTillDate(
.ifPresent(ip -> ip.setDueDate(targetDate)); //
interestPeriod.setDueDate(adjustedTargetDate);
int index = repaymentPeriod.getInterestPeriods().indexOf(interestPeriod);
- repaymentPeriod.getInterestPeriods().subList(index + 1, repaymentPeriod.getInterestPeriods().size()).clear();
+ int nextIdx = index + 1;
Review Comment:
Can you please elaborate on this logic? It is not clear to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949786664
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
+ ? ctx.getInstallments().stream().filter(i -> i.getDueDate().isEqual(loanTransaction.getDateOf())).findAny()
+ .orElseThrow()
+ : ctx.getInstallments().stream().filter(i -> !loanTransaction.getTransactionDate().isBefore(i.getFromDate())
+ && i.getDueDate().isAfter(loanTransaction.getTransactionDate())).findAny().orElseThrow();
+ // special because principal and interest dues are already updated.
+ recognizeAmountsAfterChargebackWithInterestRecalculation(ctx, instalment, chargebackAllocation);
+ } else {
+ // N+1
+ LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
+ .filter(LoanRepaymentScheduleInstallment::isAdditional).findAny()
+ .or(() -> createAdditionalInstalment(loanTransaction, ctx)).orElseThrow();
+ // generic
+ recognizeAmountsAfterChargeback(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
+ if (instalment.getDueDate().isBefore(loanTransaction.getTransactionDate())) {
Review Comment:
Its minor, but transaction date would never be earlier than the due date, so it would always update the additional installment due date, except if it is equal, but anyway it cause no issue...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949798811
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/EMICalculator.java:
##########
@@ -27,49 +27,98 @@
import org.apache.fineract.organisation.monetary.domain.Money;
import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OutstandingDetails;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.PeriodDueDetails;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.ProgressiveLoanInterestScheduleModel;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.RepaymentPeriod;
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleModelRepaymentPeriod;
+import org.apache.fineract.portfolio.loanproduct.calc.data.OutstandingDetails;
+import org.apache.fineract.portfolio.loanproduct.calc.data.PeriodDueDetails;
+import org.apache.fineract.portfolio.loanproduct.calc.data.ProgressiveLoanInterestScheduleModel;
+import org.apache.fineract.portfolio.loanproduct.calc.data.RepaymentPeriod;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductMinimumRepaymentScheduleRelatedDetail;
public interface EMICalculator {
+ /**
+ * This method creates an Interest model with repayment periods from the schedule periods which generated by
+ * schedule generator.
+ */
@NotNull
ProgressiveLoanInterestScheduleModel generatePeriodInterestScheduleModel(@NotNull List<LoanScheduleModelRepaymentPeriod> periods,
@NotNull LoanProductMinimumRepaymentScheduleRelatedDetail loanProductRelatedDetail,
List<LoanTermVariationsData> loanTermVariations, Integer installmentAmountInMultiplesOf, MathContext mc);
+ /**
+ * This method creates an Interest model with repayment periods from the installments which retrieved from the
+ * database.
+ */
@NotNull
ProgressiveLoanInterestScheduleModel generateInstallmentInterestScheduleModel(
@NotNull List<LoanRepaymentScheduleInstallment> installments,
@NotNull LoanProductMinimumRepaymentScheduleRelatedDetail loanProductRelatedDetail,
List<LoanTermVariationsData> loanTermVariations, Integer installmentAmountInMultiplesOf, MathContext mc);
+ /**
+ * Find repayment period based on Due Date.
+ */
Optional<RepaymentPeriod> findRepaymentPeriod(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate dueDate);
+ /**
+ * Applies the Bank disbursement on the interest model. This method recalculates the EMI amounts from the action
+ * date.
+ */
void addDisbursement(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate disbursementDueDate, Money disbursedAmount);
+ /**
+ * Applies the interest rate change on the interest model. This method recalculates the EMI amounts from the action
+ * date.
+ */
void changeInterestRate(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate newInterestSubmittedOnDate,
BigDecimal newInterestRate);
+ /**
+ * This method applies outstanding balance correction on the interest model. Negative amount decreases the
+ * outstanding balance while positive amounts are increasing that. Typically used for late repayment or to count
+ * repayments.
+ */
void addBalanceCorrection(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate balanceCorrectionDate,
Money balanceCorrectionAmount);
+ /**
+ * This method used for pay interest portion during the repayment transaction.
+ */
void payInterest(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate repaymentPeriodDueDate, LocalDate transactionDate,
Money interestAmount);
+ /**
+ * This method used for pay principal portion during the repayment transaction.
+ */
void payPrincipal(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate repaymentPeriodDueDate, LocalDate transactionDate,
Money principalAmount);
+ /**
+ * This method used for charge back principal portion. This method increases the outstanding balance. This method
+ * creates a calculated "virtual" EMI for the applied period.
+ */
+ void chargebackPrincipal(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate transactionDate,
+ Money chargebackPrincipalAmount);
+
+ /**
+ * This method used for charge back interest portion. This method adds extra interest due. This method creates a
+ * calculated "virtual" EMI for the applied period.
+ */
+ void chargebackInterest(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate transactionDate, Money chargebackInterestAmount);
+
+ /**
+ * This method gives back the maximum of the due principal and maximum of the due interest for a requested day.
+ */
@NotNull
PeriodDueDetails getDueAmounts(@NotNull ProgressiveLoanInterestScheduleModel scheduleModel, @NotNull LocalDate periodDueDate,
@NotNull LocalDate targetDate);
+ /**
+ * Gives back the sum of the interest from the whole model on the given date.
+ */
@NotNull
Money getPeriodInterestTillDate(@NotNull ProgressiveLoanInterestScheduleModel scheduleModel, @NotNull LocalDate periodDueDate,
- @NotNull LocalDate targetDate);
+ @NotNull LocalDate targetDate, boolean includeChargebackInterest);
Review Comment:
Do we need the new flag? We should always return all interest (calculated + charged back), no?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949800497
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java:
##########
@@ -188,13 +191,60 @@ public void payPrincipal(ProgressiveLoanInterestScheduleModel scheduleModel, Loc
repaymentPeriod.ifPresent(rp -> {
// If any period total paid > calculated EMI, then set EMI to total paid -> effectively it is marked as
// fully paid
- if (rp.getTotalPaidAmount().compareTo(rp.getEmi()) > 0) {
- rp.setEmi(rp.getTotalPaidAmount());
+ if (rp.getTotalPaidAmount().isGreaterThan(rp.getCalculatedEmi())) {
+ rp.setEmi(rp.getTotalCountablePaidAmount());
Review Comment:
What is `total countable paid amount`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949816662
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/data/RepaymentPeriod.java:
##########
@@ -138,27 +150,101 @@ public Money getDueInterest() {
return dueInterestCalculation.get();
}
+ /**
+ * Gives back an EMI amount which includes chargeback amounts as well
+ *
+ * @return
+ */
+ public Money getCalculatedEmi() {
+ return getEmi().plus(getTotalChargebackAmount(), mc); //
+ }
+
+ /**
+ * Gives back principal due + charge back principal based on (EMI - Calculated Due Interest)
+ *
+ * @return
+ */
public Money getCalculatedDuePrincipal() {
- return getEmi().minus(getCalculatedDueInterest(), mc);
+ return getCalculatedEmi().minus(getCalculatedDueInterest(), mc);
+ }
+
+ /**
+ * Sum of chargeback principals
+ *
+ * @return
+ */
+ public Money getChargebackPrincipal() {
+ return interestPeriods.stream() //
+ .map(InterestPeriod::getChargebackPrincipal) //
+ .reduce(getZero(mc), (value, previous) -> value.plus(previous, mc)); //
}
+ /**
+ * Sum of chargeback interests
+ *
+ * @return
+ */
+ public Money getChargebackInterest() {
+ return interestPeriods.stream() //
+ .map(InterestPeriod::getChargebackInterest) //
+ .reduce(getZero(mc), (value, previous) -> value.plus(previous, mc)); //
+ }
+
+ /**
+ * Gives back due principal + chargeback principal or paid principal
+ *
+ * @return
+ */
public Money getDuePrincipal() {
// Due principal might be the maximum paid if there is pay-off or early repayment
- return MathUtil.max(getEmi().minus(getDueInterest(), mc), getPaidPrincipal(), false);
+ return MathUtil.max(getCalculatedEmi().minus(getDueInterest(), mc), getPaidPrincipal(), false);
}
+ /**
+ * Gives back sum of all chargeback principal + chargeback interest
+ *
+ * @return
+ */
+ public Money getTotalChargebackAmount() {
+ return getChargebackPrincipal().plus(getChargebackInterest(), mc);
+ }
+
+ /**
+ * Total paid amounts has everything: paid principal + paid interest + paid charge principal + paid charge interest
+ *
+ * @return
+ */
public Money getTotalPaidAmount() {
return getPaidPrincipal().plus(getPaidInterest());
}
+ /**
+ * These contain all (principal + interest) amounts except chargeback amounts
+ *
+ * @return
+ */
+ public Money getTotalCountablePaidAmount() {
Review Comment:
Why do we need this distinction?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "somasorosdpc (via GitHub)" <gi...@apache.org>.
somasorosdpc commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1950478748
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/EMICalculator.java:
##########
@@ -27,49 +27,98 @@
import org.apache.fineract.organisation.monetary.domain.Money;
import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OutstandingDetails;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.PeriodDueDetails;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.ProgressiveLoanInterestScheduleModel;
-import org.apache.fineract.portfolio.loanaccount.loanschedule.data.RepaymentPeriod;
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleModelRepaymentPeriod;
+import org.apache.fineract.portfolio.loanproduct.calc.data.OutstandingDetails;
+import org.apache.fineract.portfolio.loanproduct.calc.data.PeriodDueDetails;
+import org.apache.fineract.portfolio.loanproduct.calc.data.ProgressiveLoanInterestScheduleModel;
+import org.apache.fineract.portfolio.loanproduct.calc.data.RepaymentPeriod;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductMinimumRepaymentScheduleRelatedDetail;
public interface EMICalculator {
+ /**
+ * This method creates an Interest model with repayment periods from the schedule periods which generated by
+ * schedule generator.
+ */
@NotNull
ProgressiveLoanInterestScheduleModel generatePeriodInterestScheduleModel(@NotNull List<LoanScheduleModelRepaymentPeriod> periods,
@NotNull LoanProductMinimumRepaymentScheduleRelatedDetail loanProductRelatedDetail,
List<LoanTermVariationsData> loanTermVariations, Integer installmentAmountInMultiplesOf, MathContext mc);
+ /**
+ * This method creates an Interest model with repayment periods from the installments which retrieved from the
+ * database.
+ */
@NotNull
ProgressiveLoanInterestScheduleModel generateInstallmentInterestScheduleModel(
@NotNull List<LoanRepaymentScheduleInstallment> installments,
@NotNull LoanProductMinimumRepaymentScheduleRelatedDetail loanProductRelatedDetail,
List<LoanTermVariationsData> loanTermVariations, Integer installmentAmountInMultiplesOf, MathContext mc);
+ /**
+ * Find repayment period based on Due Date.
+ */
Optional<RepaymentPeriod> findRepaymentPeriod(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate dueDate);
+ /**
+ * Applies the Bank disbursement on the interest model. This method recalculates the EMI amounts from the action
+ * date.
+ */
void addDisbursement(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate disbursementDueDate, Money disbursedAmount);
+ /**
+ * Applies the interest rate change on the interest model. This method recalculates the EMI amounts from the action
+ * date.
+ */
void changeInterestRate(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate newInterestSubmittedOnDate,
BigDecimal newInterestRate);
+ /**
+ * This method applies outstanding balance correction on the interest model. Negative amount decreases the
+ * outstanding balance while positive amounts are increasing that. Typically used for late repayment or to count
+ * repayments.
+ */
void addBalanceCorrection(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate balanceCorrectionDate,
Money balanceCorrectionAmount);
+ /**
+ * This method used for pay interest portion during the repayment transaction.
+ */
void payInterest(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate repaymentPeriodDueDate, LocalDate transactionDate,
Money interestAmount);
+ /**
+ * This method used for pay principal portion during the repayment transaction.
+ */
void payPrincipal(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate repaymentPeriodDueDate, LocalDate transactionDate,
Money principalAmount);
+ /**
+ * This method used for charge back principal portion. This method increases the outstanding balance. This method
+ * creates a calculated "virtual" EMI for the applied period.
+ */
+ void chargebackPrincipal(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate transactionDate,
+ Money chargebackPrincipalAmount);
+
+ /**
+ * This method used for charge back interest portion. This method adds extra interest due. This method creates a
+ * calculated "virtual" EMI for the applied period.
+ */
+ void chargebackInterest(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate transactionDate, Money chargebackInterestAmount);
+
+ /**
+ * This method gives back the maximum of the due principal and maximum of the due interest for a requested day.
+ */
@NotNull
PeriodDueDetails getDueAmounts(@NotNull ProgressiveLoanInterestScheduleModel scheduleModel, @NotNull LocalDate periodDueDate,
@NotNull LocalDate targetDate);
+ /**
+ * Gives back the sum of the interest from the whole model on the given date.
+ */
@NotNull
Money getPeriodInterestTillDate(@NotNull ProgressiveLoanInterestScheduleModel scheduleModel, @NotNull LocalDate periodDueDate,
- @NotNull LocalDate targetDate);
+ @NotNull LocalDate targetDate, boolean includeChargebackInterest);
Review Comment:
Accrual calculation will use it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2162: Chargeback Support for Progressive Interest Recalculating Loan When no Payment Allocation Set. [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4294:
URL: https://github.com/apache/fineract/pull/4294#discussion_r1949784294
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -413,16 +415,119 @@ protected LoanTransaction findChargebackOriginalTransaction(LoanTransaction char
Long toId = chargebackId;
// if the original transaction is not in the ctx, then it means that it has not changed during reverse replay
Optional<LoanTransaction> fromTransaction = chargebackTransaction.getLoan().getLoanTransactions().stream()
- .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK)))
+ .filter(tr -> tr.getLoanTransactionRelations().stream().anyMatch(this.hasMatchingToLoanTransaction(toId, CHARGEBACK))
+ || tr.getLoanTransactionRelations().stream()
+ .anyMatch(this.hasMatchingToLoanTransaction(chargebackTransaction, CHARGEBACK)))
.findFirst();
if (fromTransaction.isEmpty()) {
throw new RuntimeException("Chargeback transaction must have an original transaction");
}
return fromTransaction.get();
}
- protected void processCreditTransaction(LoanTransaction loanTransaction, TransactionCtx ctx) {
+ private Map<AllocationType, Money> calculateChargebackAllocationMapPrincipalOnly(Money transactionAmount, MonetaryCurrency currency) {
+ Map<AllocationType, Money> chargebackAllocation = new HashMap<>();
+ chargebackAllocation.put(PRINCIPAL, transactionAmount);
+ chargebackAllocation.put(INTEREST, Money.zero(currency));
+ chargebackAllocation.put(PENALTY, Money.zero(currency));
+ chargebackAllocation.put(FEE, Money.zero(currency));
+ return chargebackAllocation;
+ }
+
+ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTransaction, ProgressiveTransactionCtx ctx) {
+
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ MonetaryCurrency currency = ctx.getCurrency();
+ loanTransaction.resetDerivedComponents();
+ Money transactionAmount = loanTransaction.getAmount(currency);
+ Money totalOverpaid = ctx.getOverpaymentHolder().getMoneyObject();
+ loanTransaction.setOverPayments(totalOverpaid);
+ if (!transactionAmount.isGreaterThanZero()) {
+ return;
+ }
+ if (!loanTransaction.isChargeback()) {
+ throw new RuntimeException("Unsupported transaction " + loanTransaction.getTypeOf().name());
+ }
+ Map<AllocationType, Money> chargebackAllocation;
+
if (hasNoCustomCreditAllocationRule(loanTransaction)) {
+ // whole amount should allocate as principal no need to check previous chargebacks.
+ chargebackAllocation = calculateChargebackAllocationMapPrincipalOnly(transactionAmount, currency);
+ } else {
+ chargebackAllocation = calculateChargebackAllocationMapByCreditAllocationRule(loanTransaction, ctx);
+ }
+
+ loanTransaction.updateComponents(chargebackAllocation.get(PRINCIPAL), chargebackAllocation.get(INTEREST),
+ chargebackAllocation.get(FEE), chargebackAllocation.get(PENALTY));
+
+ LocalDate lastInstallmentDueDate = model.getMaturityDate();
+ if (!loanTransaction.getTransactionDate().isAfter(lastInstallmentDueDate)) {
+ if (chargebackAllocation.get(PRINCIPAL).isGreaterThanZero()) {
+ emiCalculator.chargebackPrincipal(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(PRINCIPAL));
+ }
+
+ // interest
+ if (chargebackAllocation.get(INTEREST).isGreaterThanZero()) {
+ emiCalculator.chargebackInterest(model, loanTransaction.getTransactionDate(), chargebackAllocation.get(INTEREST));
+ }
+ // update repayment periods until maturity date, for principal and interest portions
+ updateRepaymentPeriods(loanTransaction, ctx);
+
+ LoanRepaymentScheduleInstallment instalment = lastInstallmentDueDate.isEqual(loanTransaction.getDateOf())
+ ? ctx.getInstallments().stream().filter(i -> i.getDueDate().isEqual(loanTransaction.getDateOf())).findAny()
+ .orElseThrow()
+ : ctx.getInstallments().stream().filter(i -> !loanTransaction.getTransactionDate().isBefore(i.getFromDate())
+ && i.getDueDate().isAfter(loanTransaction.getTransactionDate())).findAny().orElseThrow();
+ // special because principal and interest dues are already updated.
+ recognizeAmountsAfterChargebackWithInterestRecalculation(ctx, instalment, chargebackAllocation);
+ } else {
+ // N+1
+ LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
+ .filter(LoanRepaymentScheduleInstallment::isAdditional).findAny()
+ .or(() -> createAdditionalInstalment(loanTransaction, ctx)).orElseThrow();
+ // generic
+ recognizeAmountsAfterChargeback(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
+ if (instalment.getDueDate().isBefore(loanTransaction.getTransactionDate())) {
+ instalment.updateDueDate(loanTransaction.getTransactionDate());
+ }
+ }
+
+ allocateOverpayment(loanTransaction, ctx);
+ }
+
+ private Optional<LoanRepaymentScheduleInstallment> createAdditionalInstalment(LoanTransaction loanTransaction,
Review Comment:
Why to wrap with Optional?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org