-
Notifications
You must be signed in to change notification settings - Fork 2.5k
FINERACT-2421: Working Capital loan details extended #5859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adamsaghy
merged 1 commit into
apache:develop
from
openMF:FINERACT-2421/working-capital-loan-extend-details
May 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../org/apache/fineract/portfolio/workingcapitalloan/data/WorkingCapitalLoanSummaryData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.fineract.portfolio.workingcapitalloan.data; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.math.BigDecimal; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.apache.fineract.organisation.monetary.data.CurrencyData; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class WorkingCapitalLoanSummaryData implements Serializable { | ||
|
|
||
| private CurrencyData currency; | ||
|
|
||
| // Principal | ||
| private BigDecimal principalDisbursed; | ||
| private BigDecimal principalPaid; | ||
| private BigDecimal principalOutstanding; | ||
|
|
||
| // Discount fee | ||
| private BigDecimal discountCharged; | ||
| private BigDecimal discountPaid; | ||
| private BigDecimal discountOutstanding; | ||
|
|
||
| // Income recognition | ||
| private BigDecimal realizedIncome; | ||
| private BigDecimal unrealizedIncome; | ||
|
|
||
| // Overpayment | ||
| private BigDecimal overpaymentAmount; | ||
|
|
||
| // Aggregates | ||
| private BigDecimal totalExpectedRepayment; | ||
| private BigDecimal totalRepayment; | ||
| private BigDecimal totalOutstanding; | ||
|
|
||
| // Transaction summaries | ||
| private BigDecimal totalDisbursement; | ||
| private BigDecimal totalRepaymentTransaction; | ||
| private BigDecimal totalDiscountFee; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...che/fineract/portfolio/workingcapitalloan/mapper/WorkingCapitalLoanSummaryDataMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.fineract.portfolio.workingcapitalloan.mapper; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.function.Function; | ||
| import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig; | ||
| import org.apache.fineract.infrastructure.core.service.MathUtil; | ||
| import org.apache.fineract.organisation.monetary.data.CurrencyData; | ||
| import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType; | ||
| import org.apache.fineract.portfolio.workingcapitalloan.data.WorkingCapitalLoanSummaryData; | ||
| import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoan; | ||
| import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanTransaction; | ||
| import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanTransactionAllocation; | ||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
| import org.mapstruct.Named; | ||
|
|
||
| @Mapper(config = MapstructMapperConfig.class) | ||
| public interface WorkingCapitalLoanSummaryDataMapper { | ||
|
adamsaghy marked this conversation as resolved.
|
||
|
|
||
| @Named("toSummaryData") | ||
| @Mapping(target = "currency", source = ".", qualifiedByName = "toCurrency") | ||
| // Principal | ||
| @Mapping(target = "principalDisbursed", source = "transactions", qualifiedByName = "toPrincipalDisbursed") | ||
| @Mapping(target = "principalPaid", source = "balance.totalPaidPrincipal", qualifiedByName = "nullToZero") | ||
| @Mapping(target = "principalOutstanding", source = "balance.principalOutstanding", qualifiedByName = "nullToZero") | ||
| // Discount fee | ||
| @Mapping(target = "discountCharged", source = "transactions", qualifiedByName = "toDiscountCharged") | ||
| @Mapping(target = "discountPaid", source = "transactions", qualifiedByName = "toDiscountPaid") | ||
| @Mapping(target = "discountOutstanding", source = "transactions", qualifiedByName = "toDiscountOutstanding") | ||
| // Income recognition | ||
| @Mapping(target = "realizedIncome", source = "balance.realizedIncome", qualifiedByName = "nullToZero") | ||
| @Mapping(target = "unrealizedIncome", source = "balance.unrealizedIncome", qualifiedByName = "nullToZero") | ||
| // Overpayment | ||
| @Mapping(target = "overpaymentAmount", source = "balance.overpaymentAmount", qualifiedByName = "nullToZero") | ||
| // Aggregates | ||
| @Mapping(target = "totalExpectedRepayment", source = "transactions", qualifiedByName = "toTotalExpectedRepayment") | ||
| @Mapping(target = "totalRepayment", source = "balance.totalPayment", qualifiedByName = "nullToZero") | ||
| @Mapping(target = "totalOutstanding", source = ".", qualifiedByName = "toTotalOutstanding") | ||
| // Transaction summaries | ||
| @Mapping(target = "totalDisbursement", source = "transactions", qualifiedByName = "toPrincipalDisbursed") | ||
| @Mapping(target = "totalRepaymentTransaction", source = "transactions", qualifiedByName = "toTotalRepaymentTransaction") | ||
| @Mapping(target = "totalDiscountFee", source = "transactions", qualifiedByName = "toDiscountCharged") | ||
| WorkingCapitalLoanSummaryData toData(WorkingCapitalLoan loan); | ||
|
|
||
| @Named("toCurrency") | ||
| default CurrencyData toCurrency(final WorkingCapitalLoan loan) { | ||
| return loan.getLoanProduct().getCurrency().toData(); | ||
| } | ||
|
|
||
| @Named("nullToZero") | ||
| default BigDecimal nullToZero(final BigDecimal value) { | ||
| return MathUtil.nullToZero(value); | ||
| } | ||
|
|
||
| @Named("toPrincipalDisbursed") | ||
| default BigDecimal toPrincipalDisbursed(final List<WorkingCapitalLoanTransaction> transactions) { | ||
| return sumActive(transactions, LoanTransactionType.DISBURSEMENT); | ||
| } | ||
|
|
||
| @Named("toDiscountCharged") | ||
| default BigDecimal toDiscountCharged(final List<WorkingCapitalLoanTransaction> transactions) { | ||
| return sumActive(transactions, LoanTransactionType.DISCOUNT_FEE); | ||
| } | ||
|
|
||
| @Named("toDiscountPaid") | ||
| default BigDecimal toDiscountPaid(final List<WorkingCapitalLoanTransaction> transactions) { | ||
| return sumActiveAllocationField(transactions, WorkingCapitalLoanTransactionAllocation::getFeeChargesPortion); | ||
| } | ||
|
|
||
| @Named("toDiscountOutstanding") | ||
| default BigDecimal toDiscountOutstanding(final List<WorkingCapitalLoanTransaction> transactions) { | ||
| return toDiscountCharged(transactions).subtract(toDiscountPaid(transactions)); | ||
| } | ||
|
|
||
| @Named("toTotalExpectedRepayment") | ||
| default BigDecimal toTotalExpectedRepayment(final List<WorkingCapitalLoanTransaction> transactions) { | ||
| return toPrincipalDisbursed(transactions).add(toDiscountCharged(transactions)); | ||
| } | ||
|
|
||
| @Named("toTotalOutstanding") | ||
| default BigDecimal toTotalOutstanding(final WorkingCapitalLoan loan) { | ||
| return nullToZero(loan.getBalance() != null ? loan.getBalance().getPrincipalOutstanding() : null) | ||
| .add(toDiscountOutstanding(loan.getTransactions())); | ||
| } | ||
|
|
||
| @Named("toTotalRepaymentTransaction") | ||
| default BigDecimal toTotalRepaymentTransaction(final List<WorkingCapitalLoanTransaction> transactions) { | ||
| return sumActive(transactions, LoanTransactionType.REPAYMENT); | ||
| } | ||
|
|
||
| private BigDecimal sumActive(final List<WorkingCapitalLoanTransaction> transactions, final LoanTransactionType type) { | ||
| return transactions.stream().filter(t -> t.getTypeOf() == type && !t.isReversed()) | ||
| .map(WorkingCapitalLoanTransaction::getTransactionAmount).reduce(BigDecimal.ZERO, BigDecimal::add); | ||
| } | ||
|
|
||
| private BigDecimal sumActiveAllocationField(final List<WorkingCapitalLoanTransaction> transactions, | ||
| final Function<WorkingCapitalLoanTransactionAllocation, BigDecimal> extractor) { | ||
| return transactions.stream().filter(t -> !t.isReversed() && t.getAllocation() != null).map(t -> extractor.apply(t.getAllocation())) | ||
| .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.