janez89 commented on code in PR #4099:
URL: https://github.com/apache/fineract/pull/4099#discussion_r1801353567
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -1527,6 +1507,74 @@ private Money
processAllocationsHorizontally(LoanTransaction loanTransaction, Tr
return transactionAmountUnprocessed;
}
+ private Money
handlingPaymentAllocationForInterestBearingProgressiveLoan(LoanTransaction
loanTransaction,
+ Money transactionAmountUnprocessed, Balances balances,
PaymentAllocationType paymentAllocationType,
+ LoanRepaymentScheduleInstallment inAdvanceInstallment,
ProgressiveTransactionCtx ctx,
+ LoanTransactionToRepaymentScheduleMapping
loanTransactionToRepaymentScheduleMapping,
+ Set<LoanCharge> inAdvanceInstallmentCharges) {
+ Money paidPortion;
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ LocalDate payDate = loanTransaction.getTransactionDate();
+ if (DueType.IN_ADVANCE.equals(paymentAllocationType.getDueType())) {
+ payDate =
calculateNewPayDateInCaseOfInAdvancePayment(loanTransaction,
inAdvanceInstallment);
+ updateRepaymentPeriodBalances(paymentAllocationType,
inAdvanceInstallment, model, payDate);
+ }
+
+ paidPortion = processPaymentAllocation(paymentAllocationType,
inAdvanceInstallment, loanTransaction, transactionAmountUnprocessed,
+ loanTransactionToRepaymentScheduleMapping,
inAdvanceInstallmentCharges, balances,
+ LoanRepaymentScheduleInstallment.PaymentAction.PAY);
+
+ if (PRINCIPAL.equals(paymentAllocationType.getAllocationType())) {
+ emiCalculator.payPrincipal(model,
inAdvanceInstallment.getDueDate(), payDate, paidPortion);
+ updateRepaymentPeriods(loanTransaction, ctx, model);
+ } else if (INTEREST.equals(paymentAllocationType.getAllocationType()))
{
+ emiCalculator.payInterest(model,
inAdvanceInstallment.getDueDate(), payDate, paidPortion);
+ updateRepaymentPeriods(loanTransaction, ctx, model);
+ }
+ return paidPortion;
+ }
+
+ private static void updateRepaymentPeriods(LoanTransaction
loanTransaction, ProgressiveTransactionCtx ctx,
Review Comment:
Yes, I didn't see this, thanks.
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java:
##########
@@ -1527,6 +1507,74 @@ private Money
processAllocationsHorizontally(LoanTransaction loanTransaction, Tr
return transactionAmountUnprocessed;
}
+ private Money
handlingPaymentAllocationForInterestBearingProgressiveLoan(LoanTransaction
loanTransaction,
+ Money transactionAmountUnprocessed, Balances balances,
PaymentAllocationType paymentAllocationType,
+ LoanRepaymentScheduleInstallment inAdvanceInstallment,
ProgressiveTransactionCtx ctx,
+ LoanTransactionToRepaymentScheduleMapping
loanTransactionToRepaymentScheduleMapping,
+ Set<LoanCharge> inAdvanceInstallmentCharges) {
+ Money paidPortion;
+ ProgressiveLoanInterestScheduleModel model = ctx.getModel();
+ LocalDate payDate = loanTransaction.getTransactionDate();
+ if (DueType.IN_ADVANCE.equals(paymentAllocationType.getDueType())) {
+ payDate =
calculateNewPayDateInCaseOfInAdvancePayment(loanTransaction,
inAdvanceInstallment);
+ updateRepaymentPeriodBalances(paymentAllocationType,
inAdvanceInstallment, model, payDate);
+ }
+
+ paidPortion = processPaymentAllocation(paymentAllocationType,
inAdvanceInstallment, loanTransaction, transactionAmountUnprocessed,
+ loanTransactionToRepaymentScheduleMapping,
inAdvanceInstallmentCharges, balances,
+ LoanRepaymentScheduleInstallment.PaymentAction.PAY);
+
+ if (PRINCIPAL.equals(paymentAllocationType.getAllocationType())) {
+ emiCalculator.payPrincipal(model,
inAdvanceInstallment.getDueDate(), payDate, paidPortion);
+ updateRepaymentPeriods(loanTransaction, ctx, model);
+ } else if (INTEREST.equals(paymentAllocationType.getAllocationType()))
{
+ emiCalculator.payInterest(model,
inAdvanceInstallment.getDueDate(), payDate, paidPortion);
+ updateRepaymentPeriods(loanTransaction, ctx, model);
+ }
+ return paidPortion;
+ }
+
+ private static void updateRepaymentPeriods(LoanTransaction
loanTransaction, ProgressiveTransactionCtx ctx,
+ ProgressiveLoanInterestScheduleModel model) {
+ model.repaymentPeriods().forEach(rm -> {
+ LoanRepaymentScheduleInstallment installment =
ctx.getInstallments().stream()
+ .filter(ri -> ri.getDueDate().equals(rm.getDueDate()) &&
!ri.isDownPayment()).findFirst().orElse(null);
+ if (installment != null) {
+ installment.updatePrincipal(rm.getDuePrincipal().getAmount());
+
installment.updateInterestCharged(rm.getDueInterest().getAmount());
+ installment.updateObligationsMet(ctx.getCurrency(),
loanTransaction.getTransactionDate());
+ }
+ });
+ }
+
+ private void updateRepaymentPeriodBalances(PaymentAllocationType
paymentAllocationType,
+ LoanRepaymentScheduleInstallment inAdvanceInstallment,
ProgressiveLoanInterestScheduleModel model, LocalDate payDate) {
+ PayableDetails payableDetails = emiCalculator.getPayableDetails(model,
inAdvanceInstallment.getDueDate(), payDate);
+
+ switch (paymentAllocationType) {
+ case IN_ADVANCE_INTEREST ->
inAdvanceInstallment.updateInterestCharged(payableDetails.getPayableInterest().getAmount());
+ case IN_ADVANCE_PRINCIPAL ->
inAdvanceInstallment.updatePrincipal(payableDetails.getPayablePrincipal().getAmount());
+ default -> {
+ }
+ }
+ }
+
+ private static LocalDate
calculateNewPayDateInCaseOfInAdvancePayment(LoanTransaction loanTransaction,
Review Comment:
I didn't see this, thanks.
--
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]