You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "magyari-adam (via GitHub)" <gi...@apache.org> on 2025/06/08 10:31:28 UTC
[PR] FINERACT-2232: Capitalized income - Amortization rework [fineract]
magyari-adam opened a new pull request, #4750:
URL: https://github.com/apache/fineract/pull/4750
## Description
Describe the changes made and why they were made.
Ignore if these details are present on the associated [Apache Fineract JIRA ticket](https://github.com/apache/fineract/pull/1284).
## Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
- [x] Write the commit message as per https://github.com/apache/fineract/#pull-requests
- [x] 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.
- [x] Create/update unit or integration tests for verifying the changes made.
- [x] Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.
- [x] 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
- [x] 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-2232: Capitalized income - Amortization rework [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4750:
URL: https://github.com/apache/fineract/pull/4750#discussion_r2137232486
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/adjustment/LoanAdjustmentServiceImpl.java:
##########
@@ -213,14 +217,16 @@ public CommandProcessingResult adjustLoanTransaction(Loan loan, LoanTransaction
this.loanTransactionRepository.saveAndFlush(newTransactionDetail);
}
- if (capitalizedIncomeAmortizationAdjustmentTransaction != null && capitalizedIncomeAmortizationAdjustmentTransaction.isNotZero()) {
- LoanTransaction savedCapitalizedIncomeAmortizationAdjustmentTransaction = loanTransactionRepository
- .saveAndFlush(capitalizedIncomeAmortizationAdjustmentTransaction);
- loan.addLoanTransaction(savedCapitalizedIncomeAmortizationAdjustmentTransaction);
- businessEventNotifierService
- .notifyPostBusinessEvent(new LoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent(
- capitalizedIncomeAmortizationAdjustmentTransaction));
- }
+ // TODO remove
Review Comment:
Remove if not needed
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/adjustment/LoanAdjustmentServiceImpl.java:
##########
@@ -156,9 +155,13 @@ public CommandProcessingResult adjustLoanTransaction(Loan loan, LoanTransaction
throw new InvalidLoanTransactionTypeException("transaction", "capitalizedIncome.cannot.be.reversed.when.adjusted",
"Capitalized income transaction cannot be reversed when non-reversed adjustment exists for it.");
}
- BigDecimal recognizedAmount = capitalizedIncomeBalance.getAmount().subtract(capitalizedIncomeBalance.getUnrecognizedAmount());
- capitalizedIncomeAmortizationAdjustmentTransaction = LoanTransaction.capitalizedIncomeAmortizationAdjustment(loan,
- Money.of(loan.getCurrency(), recognizedAmount), DateUtils.getBusinessLocalDate(), externalIdFactory.create());
+ // TODO nem kell realtime amortization adjustment
Review Comment:
Remove if 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-2232: Capitalized income - Amortization rework [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4750:
URL: https://github.com/apache/fineract/pull/4750#issuecomment-2958124988
@magyari-adam Please rebase your PR!
--
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-2232: Capitalized income - Amortization rework [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4750:
URL: https://github.com/apache/fineract/pull/4750#discussion_r2137233029
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanCapitalizedIncomeTest.java:
##########
@@ -683,4 +683,135 @@ public void testLoanCapitalizedIncomeOnLoanClosed() {
});
}
+ @Test
+ public void testSummarizedAmortization() {
+ final AtomicReference<Long> loanIdRef = new AtomicReference<>();
+ final AtomicReference<Long> capitalizedIncomeIdRef = new AtomicReference<>();
+
+ final PostClientsResponse client = clientHelper.createClient(ClientHelper.defaultClientCreationRequest());
+
+ final PostLoanProductsResponse loanProductsResponse = loanProductHelper
+ .createLoanProduct(create4IProgressive().enableIncomeCapitalization(true)
+ .capitalizedIncomeCalculationType(PostLoanProductsRequest.CapitalizedIncomeCalculationTypeEnum.FLAT)
+ .capitalizedIncomeStrategy(PostLoanProductsRequest.CapitalizedIncomeStrategyEnum.EQUAL_AMORTIZATION)
+ .deferredIncomeLiabilityAccountId(deferredIncomeLiabilityAccount.getAccountID().longValue())
+ .incomeFromCapitalizationAccountId(feeIncomeAccount.getAccountID().longValue())
+ .capitalizedIncomeType(PostLoanProductsRequest.CapitalizedIncomeTypeEnum.FEE));
+
+ runAt("2 January 2024", () -> {
+ Long loanId = applyAndApproveProgressiveLoan(client.getClientId(), loanProductsResponse.getResourceId(), "1 January 2024",
+ 500.0, 7.0, 3, null);
+ loanIdRef.set(loanId);
+
+ disburseLoan(loanId, BigDecimal.valueOf(100), "1 January 2024");
+ PostLoansLoanIdTransactionsResponse capitalizedIncomeResponse = loanTransactionHelper.addCapitalizedIncome(loanId,
+ "1 January 2024", 100.0);
+ capitalizedIncomeIdRef.set(capitalizedIncomeResponse.getResourceId());
+
+ executeInlineCOB(loanId);
+ });
+ runAt("10 January 2024", () -> {
+ Long loanId = loanIdRef.get();
+ executeInlineCOB(loanId);
+ loanTransactionHelper.capitalizedIncomeAdjustment(loanId, capitalizedIncomeIdRef.get(), "4 January 2024", 60.0);
+ });
+ runAt("11 January 2024", () -> {
+ Long loanId = loanIdRef.get();
+ executeInlineCOB(loanId);
+ // loanTransactionHelper.capitalizedIncomeAdjustment(loanId, capitalizedIncomeIdRef.get(), "4 January 2024",
+ // 60.0);
+ });
+ runAt("12 January 2024", () -> {
+ Long loanId = loanIdRef.get();
+ executeInlineCOB(loanId);
+ });
+ }
+
+ @Test
+ public void testCapitalizedIncomeEvents() {
+ final AtomicReference<Long> loanIdRef = new AtomicReference<>();
+ final AtomicReference<Long> capitalizedIncomeTransactionIdRef = new AtomicReference<>();
+ final AtomicReference<Long> capitalizedIncomeAdjustmentTransactionIdRef = new AtomicReference<>();
+
+ final PostClientsResponse client = clientHelper.createClient(ClientHelper.defaultClientCreationRequest());
+
+ final PostLoanProductsResponse loanProductsResponse = loanProductHelper
+ .createLoanProduct(create4IProgressive().enableIncomeCapitalization(true)
+ .capitalizedIncomeCalculationType(PostLoanProductsRequest.CapitalizedIncomeCalculationTypeEnum.FLAT)
+ .capitalizedIncomeStrategy(PostLoanProductsRequest.CapitalizedIncomeStrategyEnum.EQUAL_AMORTIZATION)
+ .deferredIncomeLiabilityAccountId(deferredIncomeLiabilityAccount.getAccountID().longValue())
+ .incomeFromCapitalizationAccountId(feeIncomeAccount.getAccountID().longValue())
+ .capitalizedIncomeType(PostLoanProductsRequest.CapitalizedIncomeTypeEnum.FEE));
+
+ runAt("1 January 2024", () -> {
+ Long loanId = applyAndApproveProgressiveLoan(client.getClientId(), loanProductsResponse.getResourceId(), "1 January 2024",
+ 500.0, 7.0, 3, null);
+ loanIdRef.set(loanId);
+
+ disburseLoan(loanId, BigDecimal.valueOf(100), "1 January 2024");
+
+ Long capitalizedIncomeTransactionId = loanTransactionHelper.addCapitalizedIncome(loanId, "1 January 2024", 100.0)
+ .getResourceId();
+ capitalizedIncomeTransactionIdRef.set(capitalizedIncomeTransactionId);
+ });
+ runAt("2 January 2024", () -> {
+ Long loanId = loanIdRef.get();
+ executeInlineCOB(loanId);
+
+ // verifyTransactions(loanId, //
+ // transaction(100.0, "Disbursement", "01 January 2024"), //
+ // transaction(100.0, "Capitalized Income", "01 January 2024"), //
+ // transaction(1.10, "Capitalized Income Amortization", "01 January 2024") //
+ // );
+ });
+ runAt("3 January 2024", () -> {
+ Long loanId = loanIdRef.get();
+ executeInlineCOB(loanId);
+
+ Long capitalizedIncomeAdjustmentTransactionId = loanTransactionHelper
+ .capitalizedIncomeAdjustment(loanId, capitalizedIncomeTransactionIdRef.get(), "3 January 2024", 100.0).getResourceId();
+ capitalizedIncomeAdjustmentTransactionIdRef.set(capitalizedIncomeAdjustmentTransactionId);
+ // verifyTransactions(loanId, //
Review Comment:
REmove if 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-2232: Capitalized income - Amortization rework [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #4750:
URL: https://github.com/apache/fineract/pull/4750
--
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-2232: Capitalized income - Amortization rework [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4750:
URL: https://github.com/apache/fineract/pull/4750#discussion_r2137231911
##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -246,46 +237,53 @@ private void createJournalEntriesForCapitalizedIncomeAdjustment(final LoanDTO lo
}
// Resolve Debit
- GLAccount accountIncomeFromCapitalization = this.helper.getLinkedGLAccountForLoanProduct(loanProductId,
- AccrualAccountsForLoan.INCOME_FROM_CAPITALIZATION.getValue(), paymentTypeId);
GLAccount accountDeferredIncome = this.helper.getLinkedGLAccountForLoanProduct(loanProductId,
AccrualAccountsForLoan.DEFERRED_INCOME_LIABILITY.getValue(), paymentTypeId);
- Optional<LoanTransaction> transactionOpt = loanTransactionRepository.findById(Long.parseLong(transactionId));
- if (transactionOpt.isEmpty()) {
- throw new PlatformDataIntegrityException("transaction.for.accounting.not.found", "Transaction for accounting not found");
- }
- Optional<LoanTransactionRelation> relationToOriginalTransactionOpt = transactionOpt.get().getLoanTransactionRelations().stream()//
- .filter(rel -> LoanTransactionRelationTypeEnum.REPLAYED.equals(rel.getRelationType()))//
- .min(Comparator.comparing(AbstractPersistableCustom::getId));
- if (relationToOriginalTransactionOpt.isPresent()) {
- // Reverse-replay case
- final LoanTransaction originalTransaction = relationToOriginalTransactionOpt.get().getToTransaction();
- final List<JournalEntry> originalJournalEntries = this.journalEntryRepository.findJournalEntries(
- AccountingProcessorHelper.LOAN_TRANSACTION_IDENTIFIER + originalTransaction.getId(),
- PortfolioProductType.LOAN.getValue());
-
- for (JournalEntry originalJournalEntry : originalJournalEntries) {
- if (originalJournalEntry.isDebitEntry()) {
- if (accountIncomeFromCapitalization.getId().equals(originalJournalEntry.getGlAccount().getId())) {
- glAccountBalanceHolder.addToDebit(accountIncomeFromCapitalization, originalJournalEntry.getAmount());
- } else if (accountDeferredIncome.getId().equals(originalJournalEntry.getGlAccount().getId())) {
- glAccountBalanceHolder.addToDebit(accountDeferredIncome, originalJournalEntry.getAmount());
- }
- }
- }
- } else {
- LoanCapitalizedIncomeBalance capitalizedIncomeBalance = loanCapitalizedIncomeBalanceRepository
- .findBalanceForAdjustment(Long.parseLong(loanTransactionDTO.getTransactionId()));
- if (MathUtil.isGreaterThan(transactionAmount, capitalizedIncomeBalance.getUnrecognizedAmount())) {
- BigDecimal amortizedAmount = transactionAmount.subtract(capitalizedIncomeBalance.getUnrecognizedAmount());
-
- glAccountBalanceHolder.addToDebit(accountIncomeFromCapitalization, amortizedAmount);
- glAccountBalanceHolder.addToDebit(accountDeferredIncome, transactionAmount.subtract(amortizedAmount));
- } else {
- glAccountBalanceHolder.addToDebit(accountDeferredIncome, transactionAmount);
- }
- }
+ glAccountBalanceHolder.addToDebit(accountDeferredIncome, transactionAmount);
+
+ // GLAccount accountIncomeFromCapitalization = this.helper.getLinkedGLAccountForLoanProduct(loanProductId,
Review Comment:
Remove if 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