You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by "budaidev (via GitHub)" <gi...@apache.org> on 2025/06/17 07:59:07 UTC
[PR] FINEARCT-2311: Add buydown fees to loan [fineract]
budaidev opened a new pull request, #4775:
URL: https://github.com/apache/fineract/pull/4775
## 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!
- [ ] 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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4775:
URL: https://github.com/apache/fineract/pull/4775#discussion_r2174767429
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java:
##########
@@ -269,6 +273,69 @@ public void validateContractTerminationUndo(final JsonCommand command, final Lon
});
}
+ private static final List<String> BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS = List
+ .of(new String[] { "transactionDate", "dateFormat", "locale", "transactionAmount", "paymentTypeId", "note", "externalId" });
+
+ @Override
+ public void validateBuyDownFee(JsonCommand command, Long loanId) {
+ final String json = command.json();
+ final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
+ this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS);
+
+ final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+ final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
+ .resource("loan.transaction.buyDownFee");
+
+ final JsonElement element = this.fromApiJsonHelper.parse(json);
+ final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
+
+ // Validate buy down fee is enabled on loan product
+ if (!loan.getLoanProductRelatedDetail().isEnableBuyDownFee()) {
+ baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("buy.down.fee.not.enabled",
+ "Buy down fee is not enabled for this loan product");
+ }
+
+ // Basic validation
+ validateBuyDownFeeEligibility(loan);
+
+ final LocalDate transactionDate = this.fromApiJsonHelper.extractLocalDateNamed("transactionDate", element);
+ baseDataValidator.reset().parameter("transactionDate").value(transactionDate).notNull();
+
+ // Validate transaction date is on or after first disbursement
+ if (transactionDate != null) {
+ final LocalDate firstDisbursementDate = loan.getDisbursementDate();
+ if (firstDisbursementDate != null && transactionDate.isBefore(firstDisbursementDate)) {
+ baseDataValidator.reset().parameter("transactionDate").failWithCode("cannot.be.before.first.disbursement.date");
+ }
+ }
+
+ final BigDecimal transactionAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("transactionAmount", element);
+ baseDataValidator.reset().parameter("transactionAmount").value(transactionAmount).notNull().positiveAmount();
+
+ throwExceptionIfValidationWarningsExist(dataValidationErrors);
+ }
+
+ public void validateBuyDownFeeEligibility(Loan loan) {
+ if (!loan.getLoanProduct().getLoanProductRelatedDetail().isEnableBuyDownFee()) {
Review Comment:
We should validate against the loan, not the loan product:
`loan.getLoanProductRelatedDetail()...`
Please do the same for all the below!
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java:
##########
@@ -269,6 +273,69 @@ public void validateContractTerminationUndo(final JsonCommand command, final Lon
});
}
+ private static final List<String> BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS = List
+ .of(new String[] { "transactionDate", "dateFormat", "locale", "transactionAmount", "paymentTypeId", "note", "externalId" });
+
+ @Override
+ public void validateBuyDownFee(JsonCommand command, Long loanId) {
+ final String json = command.json();
+ final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
+ this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS);
+
+ final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+ final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
+ .resource("loan.transaction.buyDownFee");
+
+ final JsonElement element = this.fromApiJsonHelper.parse(json);
+ final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
+
+ // Validate buy down fee is enabled on loan product
+ if (!loan.getLoanProductRelatedDetail().isEnableBuyDownFee()) {
Review Comment:
We should validate against the loan, not the loan product:
`loan.getLoanProductRelatedDetail()...`
Please do the same for all the below!
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4775:
URL: https://github.com/apache/fineract/pull/4775#discussion_r2174721746
##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java:
##########
@@ -556,6 +556,10 @@ public boolean isPeriodicAccrualAccountingEnabled() {
return AccountingRuleType.ACCRUAL_PERIODIC.equals(this.accountingRule);
}
+ public boolean isProgressiveLoanProduct() {
Review Comment:
Not needed. We should validate the loan, not the loan product!
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "magyari-adam (via GitHub)" <gi...@apache.org>.
magyari-adam commented on code in PR #4775:
URL: https://github.com/apache/fineract/pull/4775#discussion_r2166662244
##########
fineract-core/src/main/java/org/apache/fineract/accounting/common/AccountingConstants.java:
##########
@@ -110,8 +110,10 @@ public enum AccrualAccountsForLoan {
INCOME_FROM_GOODWILL_CREDIT_INTEREST(19), //
INCOME_FROM_GOODWILL_CREDIT_FEES(20), //
INCOME_FROM_GOODWILL_CREDIT_PENALTY(21), //
- INCOME_FROM_CAPITALIZATION(22), //
- DEFERRED_INCOME_LIABILITY(23); //
+ INCOME_FROM_BUY_DOWN_FEES(22), //
+ INCOME_FROM_CAPITALIZATION(23), //
+ DEFERRED_INCOME_LIABILITY(24), //
+ BUY_DOWN_EXPENSE(25); //
Review Comment:
I don't think we should move existing constant values for accounting mappings.
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #4775:
URL: https://github.com/apache/fineract/pull/4775#issuecomment-3000466900
@budaidev Please rebase
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4775:
URL: https://github.com/apache/fineract/pull/4775#discussion_r2174732437
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java:
##########
@@ -269,6 +273,69 @@ public void validateContractTerminationUndo(final JsonCommand command, final Lon
});
}
+ private static final List<String> BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS = List
+ .of(new String[] { "transactionDate", "dateFormat", "locale", "transactionAmount", "paymentTypeId", "note", "externalId" });
+
+ @Override
+ public void validateBuyDownFee(JsonCommand command, Long loanId) {
+ final String json = command.json();
+ final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
+ this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS);
+
+ final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+ final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
+ .resource("loan.transaction.buyDownFee");
+
+ final JsonElement element = this.fromApiJsonHelper.parse(json);
+ final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
+
+ // Validate buy down fee is enabled on loan product
+ if (!loan.getLoanProductRelatedDetail().isEnableBuyDownFee()) {
Review Comment:
We should validate against the loan, not the loan product:
`loan.getLoanProductRelatedDetail()...`
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "magyari-adam (via GitHub)" <gi...@apache.org>.
magyari-adam commented on code in PR #4775:
URL: https://github.com/apache/fineract/pull/4775#discussion_r2156545640
##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/AccrualBasedAccountingProcessorForLoan.java:
##########
@@ -412,6 +416,28 @@ private void createJournalEntriesForCapitalizedIncomeAmortizationAdjustment(fina
}
}
+ private void createJournalEntriesForBuyDownFee(final LoanDTO loanDTO, final LoanTransactionDTO loanTransactionDTO,
+ final Office office) {
+ // loan properties
+ final Long loanProductId = loanDTO.getLoanProductId();
+ final Long loanId = loanDTO.getLoanId();
+ final String currencyCode = loanDTO.getCurrencyCode();
+
+ // transaction properties
+ final String transactionId = loanTransactionDTO.getTransactionId();
+ final LocalDate transactionDate = loanTransactionDTO.getTransactionDate();
+ final BigDecimal amount = loanTransactionDTO.getAmount();
+ final Long paymentTypeId = loanTransactionDTO.getPaymentTypeId();
+
+ // Create journal entries for Buy Down Fee
+ // DR: Fund Source (cash account), CR: Income from Buy Down Fees
+ if (MathUtil.isGreaterThanZero(amount)) {
+ this.helper.createJournalEntriesForLoan(office, currencyCode, AccrualAccountsForLoan.FUND_SOURCE.getValue(),
+ AccrualAccountsForLoan.INCOME_FROM_BUY_DOWN_FEES.getValue(), loanProductId, paymentTypeId, loanId, transactionId,
+ transactionDate, amount);
Review Comment:
I believe this should debit buy down expense and credit Deferred income liability.
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #4775:
URL: https://github.com/apache/fineract/pull/4775#discussion_r2174732437
##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java:
##########
@@ -269,6 +273,69 @@ public void validateContractTerminationUndo(final JsonCommand command, final Lon
});
}
+ private static final List<String> BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS = List
+ .of(new String[] { "transactionDate", "dateFormat", "locale", "transactionAmount", "paymentTypeId", "note", "externalId" });
+
+ @Override
+ public void validateBuyDownFee(JsonCommand command, Long loanId) {
+ final String json = command.json();
+ final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
+ this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, BUY_DOWN_FEE_TRANSACTION_SUPPORTED_PARAMETERS);
+
+ final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+ final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
+ .resource("loan.transaction.buyDownFee");
+
+ final JsonElement element = this.fromApiJsonHelper.parse(json);
+ final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
+
+ // Validate buy down fee is enabled on loan product
+ if (!loan.getLoanProductRelatedDetail().isEnableBuyDownFee()) {
Review Comment:
We should validate against the loan, not the loan product:
`loan.getLoanProductRelatedDetail()...`
Please do the same for all the below!
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #4775:
URL: https://github.com/apache/fineract/pull/4775
--
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] FINEARCT-2311: Add buydown fees to loan [fineract]
Posted by "magyari-adam (via GitHub)" <gi...@apache.org>.
magyari-adam commented on code in PR #4775:
URL: https://github.com/apache/fineract/pull/4775#discussion_r2156548397
##########
fineract-provider/src/main/java/org/apache/fineract/accounting/journalentry/service/CashBasedAccountingProcessorForLoan.java:
##########
@@ -117,6 +117,10 @@ else if (transactionType.isRefundForActiveLoans()) {
else if (transactionType.isChargeback()) {
createJournalEntriesForChargeback(loanDTO, loanTransactionDTO, office);
}
+ // Logic for Buy Down Fees
+ else if (transactionType.isBuyDownFee()) {
+ createJournalEntriesForBuyDownFee(loanDTO, loanTransactionDTO, office);
+ }
Review Comment:
I don't think we planned for cash based accounting on this transaction type.
--
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