You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@fineract.apache.org by Vishwa1311 <gi...@git.apache.org> on 2016/06/07 10:47:24 UTC
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
GitHub user Vishwa1311 opened a pull request:
https://github.com/apache/incubator-fineract/pull/130
[FINERACT-167] Loan foreclosure implementation and integration test cases for the same.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/Vishwa1311/incubator-fineract FINERACT-167
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-fineract/pull/130.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #130
----
commit 4f7680f986559d7513d72fb8dcbb6e8c1d0f38f6
Author: Vishwa <vi...@confluxtechnologies.com>
Date: 2016-06-07T08:41:38Z
[FINERACT-167] Loan foreclosure implementation and integration test cases for the same.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66404578
--- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java ---
@@ -5972,4 +5986,204 @@ public BigDecimal getDerivedAmountForCharge(LoanCharge loanCharge) {
return amount;
}
+ public LoanRepaymentScheduleInstallment fetchLoanForeclosureDetail(final LocalDate closureDate) {
+ Money totalPrincipal = Money.of(getCurrency(), this.getSummary().getTotalPrincipalOutstanding());
+ Money[] receivables = retriveIncomeOutstandingTillDate(closureDate);
+ final List<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails = null;
+ return new LoanRepaymentScheduleInstallment(null, 0, LocalDate.now(), LocalDate.now(), totalPrincipal.getAmount(),
--- End diff --
Use DateUtils to get the tenant date
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66409509
--- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java ---
@@ -5972,4 +5986,204 @@ public BigDecimal getDerivedAmountForCharge(LoanCharge loanCharge) {
return amount;
}
+ public LoanRepaymentScheduleInstallment fetchLoanForeclosureDetail(final LocalDate closureDate) {
+ Money totalPrincipal = Money.of(getCurrency(), this.getSummary().getTotalPrincipalOutstanding());
+ Money[] receivables = retriveIncomeOutstandingTillDate(closureDate);
+ final List<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails = null;
+ return new LoanRepaymentScheduleInstallment(null, 0, LocalDate.now(), LocalDate.now(), totalPrincipal.getAmount(),
+ receivables[0].getAmount(), receivables[1].getAmount(), receivables[2].getAmount(), false, compoundingDetails);
+ }
+
+ public Money[] retriveIncomeOutstandingTillDate(final LocalDate paymentDate) {
+ Money[] balances = new Money[3];
+ final MonetaryCurrency currency = getCurrency();
+ Money interest = Money.zero(currency);
+ Money fee = Money.zero(currency);
+ Money penalty = Money.zero(currency);
+ boolean isArrearsPresent = false;
+ for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
+ if (installment.isNotFullyPaidOff()) {
+ if (!isArrearsPresent || !installment.getDueDate().isAfter(paymentDate)) {
+ interest = interest.plus(installment.getInterestOutstanding(currency));
+ fee = fee.plus(installment.getFeeChargesOutstanding(currency));
+ penalty = penalty.plus(installment.getPenaltyChargesOutstanding(currency));
+ isArrearsPresent = true;
+ } else if (installment.getFromDate().isBefore(paymentDate)) {
+ int totalPeriodDays = Days.daysBetween(installment.getFromDate(), installment.getDueDate()).getDays();
+ int tillDays = Days.daysBetween(installment.getFromDate(), paymentDate).getDays();
+ interest = interest.plus(calculateInterestForDays(totalPeriodDays, installment.getInterestOutstanding(currency)
+ .getAmount(), tillDays));
+ for (LoanCharge loanCharge : this.charges) {
+ if (loanCharge.isActive()
+ && loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), paymentDate)) {
+ if (loanCharge.isPenaltyCharge()) {
+ penalty = penalty.plus(loanCharge.getAmountOutstanding(currency));
+ } else {
+ fee = fee.plus(loanCharge.getAmountOutstanding(currency));
+ }
+ }
+ }
+ }
+ }
+ }
+ balances[0] = interest;
+ balances[1] = fee;
+ balances[2] = penalty;
+ return balances;
+ }
+
+ private double calculateInterestForDays(int daysInPeriod, BigDecimal interest, int days) {
+ if (interest.doubleValue() == 0) { return 0; }
+ return ((interest.doubleValue()) / daysInPeriod) * days;
+ }
+
+ public boolean canForecloseLoan() {
+ boolean canForecloseLoan = false;
+ if (isOpen()) {
+ canForecloseLoan = true;
+ }
+ return canForecloseLoan;
+ }
+
+ public Money[] getReceivableIncome(final LocalDate tillDate) {
+ MonetaryCurrency currency = getCurrency();
+ Money receivableInterest = Money.zero(currency);
+ Money receivableFee = Money.zero(currency);
+ Money receivablePenalty = Money.zero(currency);
+ Money[] receivables = new Money[3];
+ for (final LoanTransaction transaction : this.loanTransactions) {
+ if (transaction.isNotReversed() && !transaction.isRepaymentAtDisbursement() && !transaction.isDisbursement()
+ && !transaction.getTransactionDate().isAfter(tillDate)) {
+ if (transaction.isAccrual()) {
+ receivableInterest = receivableInterest.plus(transaction.getInterestPortion(currency));
+ receivableFee = receivableFee.plus(transaction.getFeeChargesPortion(currency));
+ receivablePenalty = receivablePenalty.plus(transaction.getPenaltyChargesPortion(currency));
+ } else if (transaction.isRepayment() || transaction.isChargePayment()) {
+ receivableInterest = receivableInterest.minus(transaction.getInterestPortion(currency));
+ receivableFee = receivableFee.minus(transaction.getFeeChargesPortion(currency));
+ receivablePenalty = receivablePenalty.minus(transaction.getPenaltyChargesPortion(currency));
+ }
+ }
+ if (receivableInterest.isLessThanZero()) {
+ receivableInterest = receivableInterest.zero();
+ }
+ if (receivableFee.isLessThanZero()) {
+ receivableFee = receivableFee.zero();
+ }
+ if (receivablePenalty.isLessThanZero()) {
+ receivablePenalty = receivablePenalty.zero();
+ }
+ }
+ receivables[0] = receivableInterest;
+ receivables[1] = receivableFee;
+ receivables[2] = receivablePenalty;
+ return receivables;
+ }
+
+ public void handleForeClosureTransactions(final List<LoanTransaction> repaymentTransaction,
+ final LoanForeClosureDetailDTO foreClosureDetailDTO, final LoanLifecycleStateMachine loanLifecycleStateMachine) {
+
+ LoanEvent event = LoanEvent.LOAN_FORECLOSURE;
+
+ validateAccountStatus(event);
+
+ MonetaryCurrency currency = getCurrency();
+
+ final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
+ .determineProcessor(this.transactionProcessingStrategy);
+
+ loanRepaymentScheduleTransactionProcessor.processTransactionsFromDerivedFields(repaymentTransaction, currency,
+ this.repaymentScheduleInstallments, charges());
+ this.loanTransactions.addAll(repaymentTransaction);
+ this.loanSubStatus = LoanSubStatus.FORECLOSED.getValue();
+ updateLoanSummaryDerivedFields();
+ doPostLoanTransactionChecks(foreClosureDetailDTO.getTransactionDate(), loanLifecycleStateMachine);
--- End diff --
foreClosureDetailDTO is not required to pass only date.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66404831
--- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java ---
@@ -5972,4 +5986,204 @@ public BigDecimal getDerivedAmountForCharge(LoanCharge loanCharge) {
return amount;
}
+ public LoanRepaymentScheduleInstallment fetchLoanForeclosureDetail(final LocalDate closureDate) {
+ Money totalPrincipal = Money.of(getCurrency(), this.getSummary().getTotalPrincipalOutstanding());
+ Money[] receivables = retriveIncomeOutstandingTillDate(closureDate);
+ final List<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails = null;
+ return new LoanRepaymentScheduleInstallment(null, 0, LocalDate.now(), LocalDate.now(), totalPrincipal.getAmount(),
+ receivables[0].getAmount(), receivables[1].getAmount(), receivables[2].getAmount(), false, compoundingDetails);
+ }
+
+ public Money[] retriveIncomeOutstandingTillDate(final LocalDate paymentDate) {
+ Money[] balances = new Money[3];
+ final MonetaryCurrency currency = getCurrency();
+ Money interest = Money.zero(currency);
+ Money fee = Money.zero(currency);
+ Money penalty = Money.zero(currency);
+ boolean isArrearsPresent = false;
+ for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
+ if (installment.isNotFullyPaidOff()) {
+ if (!isArrearsPresent || !installment.getDueDate().isAfter(paymentDate)) {
+ interest = interest.plus(installment.getInterestOutstanding(currency));
+ fee = fee.plus(installment.getFeeChargesOutstanding(currency));
+ penalty = penalty.plus(installment.getPenaltyChargesOutstanding(currency));
+ isArrearsPresent = true;
+ } else if (installment.getFromDate().isBefore(paymentDate)) {
+ int totalPeriodDays = Days.daysBetween(installment.getFromDate(), installment.getDueDate()).getDays();
+ int tillDays = Days.daysBetween(installment.getFromDate(), paymentDate).getDays();
+ interest = interest.plus(calculateInterestForDays(totalPeriodDays, installment.getInterestOutstanding(currency)
+ .getAmount(), tillDays));
+ for (LoanCharge loanCharge : this.charges) {
+ if (loanCharge.isActive()
+ && loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), paymentDate)) {
+ if (loanCharge.isPenaltyCharge()) {
+ penalty = penalty.plus(loanCharge.getAmountOutstanding(currency));
+ } else {
+ fee = fee.plus(loanCharge.getAmountOutstanding(currency));
+ }
+ }
+ }
+ }
+ }
+ }
+ balances[0] = interest;
+ balances[1] = fee;
+ balances[2] = penalty;
+ return balances;
+ }
+
+ private double calculateInterestForDays(int daysInPeriod, BigDecimal interest, int days) {
+ if (interest.doubleValue() == 0) { return 0; }
+ return ((interest.doubleValue()) / daysInPeriod) * days;
+ }
+
+ public boolean canForecloseLoan() {
--- End diff --
This method is not required as already validation is done
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66403640
--- Diff: fineract-provider/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java ---
@@ -193,6 +193,8 @@ private NewCommandSourceHandler findCommandHandler(final CommandWrapper wrapper)
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}
+ } else if (wrapper.isLoanForeclosure()) {
--- End diff --
Use CommandHandlerProvider to get the handler
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66408640
--- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransaction.java ---
@@ -212,17 +214,25 @@ public static LoanTransaction accrueInterest(final Office office, final Loan loa
principalPortion, interestPortion, feesPortion, penaltiesPortion, overPaymentPortion, reversed, paymentDetail, externalId,
createdDate, appUser);
}
+
+ public static LoanTransaction accrual(final Loan loan, final Office office, final Money amount, final Money interest,
--- End diff --
This method is not required.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66403775
--- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/domain/ChargeTimeType.java ---
@@ -131,7 +131,7 @@ public static ChargeTimeType fromInt(final Integer chargeTime) {
chargeTimeType = SHARE_REDEEM;
break;
case 16:
- chargeTimeType = SAVINGS_NOACTIVITY_FEE;
+ chargeTimeType = SAVINGS_NOACTIVITY_FEE;
--- End diff --
formatting issues should not come in pull request
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66407606
--- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanAccountDomainServiceJpa.java ---
@@ -574,9 +576,118 @@ public LoanTransaction makeRefundForActiveLoan(Long accountId, CommandProcessing
return newRefundTransaction;
}
+ @Override
+ public Map<String, Object> foreCloseLoan(LoanForeClosureDetailDTO foreClosureDetailDTO) {
+ Loan loan = foreClosureDetailDTO.getLoan();
+ MonetaryCurrency currency = loan.getCurrency();
+ LocalDateTime createdDate = DateUtils.getLocalDateTimeOfTenant();
+ final Map<String, Object> changes = new LinkedHashMap<>();
+ List<LoanTransaction> newTransactions = new ArrayList<>();
+
+ final List<Long> existingTransactionIds = new ArrayList<>();
+ final List<Long> existingReversedTransactionIds = new ArrayList<>();
+ existingTransactionIds.addAll(loan.findExistingTransactionIds());
+ existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
+ final LoanRepaymentScheduleInstallment foreCloseDetail = loan.fetchLoanForeclosureDetail(foreClosureDetailDTO.getTransactionDate());
+ if (loan.isPeriodicAccrualAccountingEnabledOnLoanProduct()
+ && (loan.getAccruedTill() == null || !foreClosureDetailDTO.getTransactionDate().isEqual(loan.getAccruedTill()))) {
+ Money[] accruedReceivables = loan.getReceivableIncome(foreClosureDetailDTO.getTransactionDate());
+ Money interestPortion = foreCloseDetail.getInterestCharged(currency).minus(accruedReceivables[0]);
+ Money feePortion = foreCloseDetail.getFeeChargesCharged(currency).minus(accruedReceivables[1]);
+ Money penaltyPortion = foreCloseDetail.getPenaltyChargesCharged(currency).minus(accruedReceivables[2]);
+ Money total = interestPortion.plus(feePortion).plus(penaltyPortion);
+ if (total.isGreaterThanZero()) {
--- End diff --
You need to update all installments accrual portions.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by Vishwa1311 <gi...@git.apache.org>.
Github user Vishwa1311 closed the pull request at:
https://github.com/apache/incubator-fineract/pull/130
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66403503
--- Diff: fineract-provider/src/main/java/org/apache/fineract/commands/domain/CommandWrapper.java ---
@@ -319,4 +319,8 @@ public boolean addAndDeleteDisbursementDetails() {
return this.actionName.equalsIgnoreCase("UPDATE") && this.entityName.equalsIgnoreCase("DISBURSEMENTDETAIL")
&& this.entityId == null;
}
+
+ public boolean isLoanForeclosure() {
--- End diff --
This method is not required.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-fineract pull request #130: [FINERACT-167] Loan foreclosure implem...
Posted by nazeer1100126 <gi...@git.apache.org>.
Github user nazeer1100126 commented on a diff in the pull request:
https://github.com/apache/incubator-fineract/pull/130#discussion_r66409263
--- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java ---
@@ -5972,4 +5986,204 @@ public BigDecimal getDerivedAmountForCharge(LoanCharge loanCharge) {
return amount;
}
+ public LoanRepaymentScheduleInstallment fetchLoanForeclosureDetail(final LocalDate closureDate) {
+ Money totalPrincipal = Money.of(getCurrency(), this.getSummary().getTotalPrincipalOutstanding());
+ Money[] receivables = retriveIncomeOutstandingTillDate(closureDate);
+ final List<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails = null;
+ return new LoanRepaymentScheduleInstallment(null, 0, LocalDate.now(), LocalDate.now(), totalPrincipal.getAmount(),
+ receivables[0].getAmount(), receivables[1].getAmount(), receivables[2].getAmount(), false, compoundingDetails);
+ }
+
+ public Money[] retriveIncomeOutstandingTillDate(final LocalDate paymentDate) {
+ Money[] balances = new Money[3];
+ final MonetaryCurrency currency = getCurrency();
+ Money interest = Money.zero(currency);
+ Money fee = Money.zero(currency);
+ Money penalty = Money.zero(currency);
+ boolean isArrearsPresent = false;
+ for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
+ if (installment.isNotFullyPaidOff()) {
+ if (!isArrearsPresent || !installment.getDueDate().isAfter(paymentDate)) {
+ interest = interest.plus(installment.getInterestOutstanding(currency));
+ fee = fee.plus(installment.getFeeChargesOutstanding(currency));
+ penalty = penalty.plus(installment.getPenaltyChargesOutstanding(currency));
+ isArrearsPresent = true;
+ } else if (installment.getFromDate().isBefore(paymentDate)) {
+ int totalPeriodDays = Days.daysBetween(installment.getFromDate(), installment.getDueDate()).getDays();
+ int tillDays = Days.daysBetween(installment.getFromDate(), paymentDate).getDays();
+ interest = interest.plus(calculateInterestForDays(totalPeriodDays, installment.getInterestOutstanding(currency)
+ .getAmount(), tillDays));
+ for (LoanCharge loanCharge : this.charges) {
+ if (loanCharge.isActive()
+ && loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), paymentDate)) {
+ if (loanCharge.isPenaltyCharge()) {
+ penalty = penalty.plus(loanCharge.getAmountOutstanding(currency));
+ } else {
+ fee = fee.plus(loanCharge.getAmountOutstanding(currency));
+ }
+ }
+ }
+ }
+ }
+ }
+ balances[0] = interest;
+ balances[1] = fee;
+ balances[2] = penalty;
+ return balances;
+ }
+
+ private double calculateInterestForDays(int daysInPeriod, BigDecimal interest, int days) {
+ if (interest.doubleValue() == 0) { return 0; }
+ return ((interest.doubleValue()) / daysInPeriod) * days;
+ }
+
+ public boolean canForecloseLoan() {
+ boolean canForecloseLoan = false;
+ if (isOpen()) {
+ canForecloseLoan = true;
+ }
+ return canForecloseLoan;
+ }
+
+ public Money[] getReceivableIncome(final LocalDate tillDate) {
+ MonetaryCurrency currency = getCurrency();
+ Money receivableInterest = Money.zero(currency);
+ Money receivableFee = Money.zero(currency);
+ Money receivablePenalty = Money.zero(currency);
+ Money[] receivables = new Money[3];
+ for (final LoanTransaction transaction : this.loanTransactions) {
+ if (transaction.isNotReversed() && !transaction.isRepaymentAtDisbursement() && !transaction.isDisbursement()
+ && !transaction.getTransactionDate().isAfter(tillDate)) {
+ if (transaction.isAccrual()) {
+ receivableInterest = receivableInterest.plus(transaction.getInterestPortion(currency));
+ receivableFee = receivableFee.plus(transaction.getFeeChargesPortion(currency));
+ receivablePenalty = receivablePenalty.plus(transaction.getPenaltyChargesPortion(currency));
+ } else if (transaction.isRepayment() || transaction.isChargePayment()) {
+ receivableInterest = receivableInterest.minus(transaction.getInterestPortion(currency));
+ receivableFee = receivableFee.minus(transaction.getFeeChargesPortion(currency));
+ receivablePenalty = receivablePenalty.minus(transaction.getPenaltyChargesPortion(currency));
+ }
+ }
+ if (receivableInterest.isLessThanZero()) {
+ receivableInterest = receivableInterest.zero();
+ }
+ if (receivableFee.isLessThanZero()) {
+ receivableFee = receivableFee.zero();
+ }
+ if (receivablePenalty.isLessThanZero()) {
+ receivablePenalty = receivablePenalty.zero();
+ }
+ }
+ receivables[0] = receivableInterest;
+ receivables[1] = receivableFee;
+ receivables[2] = receivablePenalty;
+ return receivables;
+ }
+
+ public void handleForeClosureTransactions(final List<LoanTransaction> repaymentTransaction,
+ final LoanForeClosureDetailDTO foreClosureDetailDTO, final LoanLifecycleStateMachine loanLifecycleStateMachine) {
+
+ LoanEvent event = LoanEvent.LOAN_FORECLOSURE;
+
+ validateAccountStatus(event);
+
+ MonetaryCurrency currency = getCurrency();
+
+ final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
+ .determineProcessor(this.transactionProcessingStrategy);
+
+ loanRepaymentScheduleTransactionProcessor.processTransactionsFromDerivedFields(repaymentTransaction, currency,
+ this.repaymentScheduleInstallments, charges());
+ this.loanTransactions.addAll(repaymentTransaction);
+ this.loanSubStatus = LoanSubStatus.FORECLOSED.getValue();
+ updateLoanSummaryDerivedFields();
+ doPostLoanTransactionChecks(foreClosureDetailDTO.getTransactionDate(), loanLifecycleStateMachine);
+ }
+
+ public Money retrieveAccruedAmountAfterDate(final LocalDate tillDate) {
+ Money totalAmountAccrued = Money.zero(getCurrency());
+ Money actualAmountTobeAccrued = Money.zero(getCurrency());
+ for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
+ totalAmountAccrued = totalAmountAccrued.plus(installment.getInterestAccrued(getCurrency()));
+
+ if (tillDate.isAfter(installment.getFromDate()) && tillDate.isBefore(installment.getDueDate())) {
+ int daysInPeriod = Days.daysBetween(installment.getFromDate(), installment.getDueDate()).getDays();
+ int tillDays = Days.daysBetween(installment.getFromDate(), tillDate).getDays();
+ double interest = calculateInterestForDays(daysInPeriod, installment.getInterestCharged(getCurrency()).getAmount(),
+ tillDays);
+ actualAmountTobeAccrued = actualAmountTobeAccrued.plus(interest);
+ } else if ((tillDate.isAfter(installment.getFromDate()) && tillDate.isEqual(installment.getDueDate()))
+ || (tillDate.isEqual(installment.getFromDate()) && tillDate.isEqual(installment.getDueDate()))
+ || (tillDate.isAfter(installment.getFromDate()) && tillDate.isAfter(installment.getDueDate()))) {
+ actualAmountTobeAccrued = actualAmountTobeAccrued.plus(installment.getInterestAccrued(getCurrency()));
+ }
+ }
+ Money accredAmountAfterDate = totalAmountAccrued.minus(actualAmountTobeAccrued);
+ if (accredAmountAfterDate.isLessThanZero()) {
+ accredAmountAfterDate = Money.zero(getCurrency());
+ }
+ return accredAmountAfterDate;
+ }
+
+ public void validateForForeclosure(final LocalDate transactionDate) {
+
+ if (isInterestRecalculationEnabledForProduct()) {
+ final String defaultUserMessage = "The loan with interest recalculation enabled cannot be foreclosed.";
+ throw new LoanForeclosureException("loan.with.interest.recalculation.enabled.cannot.be.foreclosured", defaultUserMessage,
+ getId());
+ }
+
+ LocalDate lastUserTransactionDate = getLastUserTransactionDate();
+
+ if (DateUtils.isDateInTheFuture(transactionDate)) {
+ final String defaultUserMessage = "The transactionDate cannot be in the future.";
+ throw new LoanForeclosureException("loan.foreclosure.transaction.date.is.in.future", defaultUserMessage, transactionDate);
+ }
+
+ if (lastUserTransactionDate.isAfter(transactionDate)) {
+ final String defaultUserMessage = "The transactionDate cannot be in the future.";
+ throw new LoanForeclosureException("loan.foreclosure.transaction.date.cannot.before.the.last.transaction.date",
+ defaultUserMessage, transactionDate);
+ }
+ }
+
+ public void updateInstallmentsPostDate(LocalDate transactionDate) {
+ List<LoanRepaymentScheduleInstallment> newInstallments = new ArrayList<>(this.repaymentScheduleInstallments);
+ final MonetaryCurrency currency = getCurrency();
+ Money totalPrincipal = Money.zero(currency);
+ Money totalInterest = Money.zero(currency);
+
+ for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
+ if (installment.getDueDate().isAfter(transactionDate)) {
+ totalPrincipal = totalPrincipal.plus(installment.getPrincipalOutstanding(currency));
+ totalInterest = totalInterest.plus(installment.getInterestOutstanding(currency));
+ newInstallments.remove(installment);
+ }
+ }
+
+ LoanRepaymentScheduleInstallment newInstallment = new LoanRepaymentScheduleInstallment(null, newInstallments.size() + 1,
+ newInstallments.get((newInstallments.size() - 1)).getDueDate(), transactionDate, totalPrincipal.getAmount(),
+ totalInterest.getAmount(), BigDecimal.ZERO, BigDecimal.ZERO, true, null);
--- End diff --
Here the interest should be till that foreclosure date and also you need to check charges till that date.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---