adamsaghy commented on code in PR #4273:
URL: https://github.com/apache/fineract/pull/4273#discussion_r1930374707
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualActivityProcessingServiceImpl.java:
##########
@@ -92,42 +92,94 @@ public void processAccrualActivityForLoanClosure(@NotNull
Loan loan) {
if
(!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting()) {
return;
}
+
LocalDate transactionDate = loan.isOverPaid() ?
loan.getOverpaidOnDate() : loan.getClosedOnDate();
- // reverse after closure activities
+
+ // Reverse accrual activities posted after the closure date
loan.getLoanTransactions(t -> t.isAccrualActivity() && !t.isReversed()
&& t.getDateOf().isAfter(transactionDate))
.forEach(this::reverseAccrualActivityTransaction);
- // calculate activity amounts
BigDecimal feeChargesPortion = BigDecimal.ZERO;
BigDecimal penaltyChargesPortion = BigDecimal.ZERO;
BigDecimal interestPortion = BigDecimal.ZERO;
- // collect installment amounts
+
+ // Calculate total portions from all installments
for (LoanRepaymentScheduleInstallment installment :
loan.getRepaymentScheduleInstallments()) {
- feeChargesPortion = MathUtil.add(feeChargesPortion,
installment.getFeeChargesCharged());
- penaltyChargesPortion = MathUtil.add(penaltyChargesPortion,
installment.getPenaltyCharges());
- interestPortion = MathUtil.add(interestPortion,
installment.getInterestCharged());
+ if (!installment.isDownPayment()) { // Exclude downpayment
installments
+ feeChargesPortion = MathUtil.add(feeChargesPortion,
installment.getFeeChargesCharged());
+ penaltyChargesPortion = MathUtil.add(penaltyChargesPortion,
installment.getPenaltyCharges());
+ interestPortion = MathUtil.add(interestPortion,
installment.getInterestCharged());
+ }
}
+
+ // Subtract already posted accrual activities
List<LoanTransaction> accrualActivities = loan.getLoanTransactions(t
-> t.isAccrualActivity() && !t.isReversed());
- // subtract already posted activities
for (LoanTransaction accrualActivity : accrualActivities) {
- if (MathUtil.isLessThan(feeChargesPortion,
accrualActivity.getFeeChargesPortion())
- || MathUtil.isLessThan(penaltyChargesPortion,
accrualActivity.getPenaltyChargesPortion())
- || MathUtil.isLessThan(interestPortion,
accrualActivity.getInterestPortion())) {
- reverseAccrualActivityTransaction(accrualActivity);
- } else {
- feeChargesPortion = MathUtil.subtract(feeChargesPortion,
accrualActivity.getFeeChargesPortion());
- penaltyChargesPortion =
MathUtil.subtract(penaltyChargesPortion,
accrualActivity.getPenaltyChargesPortion());
- interestPortion = MathUtil.subtract(interestPortion,
accrualActivity.getInterestPortion());
+ feeChargesPortion = MathUtil.subtract(feeChargesPortion,
accrualActivity.getFeeChargesPortion());
+ penaltyChargesPortion = MathUtil.subtract(penaltyChargesPortion,
accrualActivity.getPenaltyChargesPortion());
+ interestPortion = MathUtil.subtract(interestPortion,
accrualActivity.getInterestPortion());
+ }
+
+ // Check each past installment for accrual activity
+ for (LoanRepaymentScheduleInstallment installment :
loan.getRepaymentScheduleInstallments()) {
+ if (!installment.isDownPayment()) {
Review Comment:
Same as above. We dont need to create Accrual Activity for "additional"
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]