Skip to content

Commit 6cd3d6b

Browse files
author
Jose Alberto Hernandez
committed
FINERACT-2311: Add Buy Down Fees transaction support
1 parent b2bce4a commit 6cd3d6b

File tree

17 files changed

+244
-49
lines changed

17 files changed

+244
-49
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.test.messaging.event.loan.transaction;
20+
21+
public class LoanTransactionBuyDownFeeAdjustmentPostBusinessEvent extends AbstractLoanTransactionEvent {
22+
23+
@Override
24+
public String getEventName() {
25+
return "LoanTransactionBuyDownFeeAdjustmentPostBusinessEvent";
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.test.messaging.event.loan.transaction;
20+
21+
public class LoanTransactionBuyDownFeePostBusinessEvent extends AbstractLoanTransactionEvent {
22+
23+
@Override
24+
public String getEventName() {
25+
return "LoanTransactionBuyDownFeePostBusinessEvent";
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.infrastructure.event.business.domain.loan.transaction;
20+
21+
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
22+
23+
public class LoanTransactionBuyDownFeeAdjustmentPostBusinessEvent extends LoanTransactionBusinessEvent {
24+
25+
private static final String TYPE = "LoanTransactionBuyDownFeeAdjustmentPostBusinessEvent";
26+
27+
public LoanTransactionBuyDownFeeAdjustmentPostBusinessEvent(LoanTransaction value) {
28+
super(value);
29+
}
30+
31+
@Override
32+
public String getType() {
33+
return TYPE;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.infrastructure.event.business.domain.loan.transaction;
20+
21+
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
22+
23+
public class LoanTransactionBuyDownFeePostBusinessEvent extends LoanTransactionBusinessEvent {
24+
25+
private static final String TYPE = "LoanTransactionBuyDownFeePostBusinessEvent";
26+
27+
public LoanTransactionBuyDownFeePostBusinessEvent(LoanTransaction value) {
28+
super(value);
29+
}
30+
31+
@Override
32+
public String getType() {
33+
return TYPE;
34+
}
35+
}

fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransactionType.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ public enum LoanTransactionType {
7070
CAPITALIZED_INCOME(35, "loanTransactionType.capitalizedIncome"), //
7171
CAPITALIZED_INCOME_AMORTIZATION(36, "loanTransactionType.capitalizedIncomeAmortization"), //
7272
CAPITALIZED_INCOME_ADJUSTMENT(37, "loanTransactionType.capitalizedIncomeAdjustment"), //
73-
CAPITALIZED_INCOME_AMORTIZATION_ADJUSTMENT(39, "loanTransactionType.capitalizedIncomeAmortizationAdjustment"), //
74-
// Kind of Final Transactions
7573
CONTRACT_TERMINATION(38, "loanTransactionType.contractTermination"), //
76-
74+
CAPITALIZED_INCOME_AMORTIZATION_ADJUSTMENT(39, "loanTransactionType.capitalizedIncomeAmortizationAdjustment"), //
7775
BUY_DOWN_FEE(40, "loanTransactionType.buyDownFee"), //
7876
BUY_DOWN_FEE_ADJUSTMENT(41, "loanTransactionType.buyDownFeeAdjustment"), //
7977
;

fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanBuyDownFeeBalance.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ public class LoanBuyDownFeeBalance extends AbstractAuditableWithUTCDateTimeCusto
6161

6262
@Column(name = "amount_adjustment", scale = 6, precision = 19)
6363
private BigDecimal amountAdjustment;
64+
6465
}

fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/repository/LoanBuyDownFeesBalanceRepository.java renamed to fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/repository/LoanBuyDownFeeBalanceRepository.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@
2121
import java.math.BigDecimal;
2222
import java.util.List;
2323
import org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance;
24-
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepaymentPeriodData;
2524
import org.springframework.data.jpa.repository.JpaRepository;
2625
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
2726
import org.springframework.data.jpa.repository.Query;
27+
import org.springframework.data.repository.query.Param;
28+
import org.springframework.stereotype.Repository;
2829

29-
public interface LoanBuyDownFeesBalanceRepository
30+
@Repository
31+
public interface LoanBuyDownFeeBalanceRepository
3032
extends JpaRepository<LoanBuyDownFeeBalance, Long>, JpaSpecificationExecutor<LoanBuyDownFeeBalance> {
3133

32-
String FIND_BALANCE_REPAYMENT_SCHEDULE_DATA = "SELECT new org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepaymentPeriodData(lbfb.loanTransaction.id, lbfb.loan.id, lbfb.loanTransaction.dateOf, lbfb.loanTransaction.reversed, lbfb.amount, lbfb.unrecognizedAmount, lbfb.loanTransaction.feeChargesPortion) FROM LoanBuyDownFeeBalance lbfb ";
33-
3434
List<LoanBuyDownFeeBalance> findAllByLoanId(Long loanId);
3535

3636
LoanBuyDownFeeBalance findByLoanIdAndLoanTransactionId(Long loanId, Long transactionId);
3737

38-
@Query(FIND_BALANCE_REPAYMENT_SCHEDULE_DATA + " WHERE lbfb.loan.id = :loanId")
39-
List<LoanTransactionRepaymentPeriodData> findRepaymentPeriodDataByLoanId(Long loanId);
38+
@Query("SELECT lbfb FROM LoanBuyDownFeeBalance lbfb WHERE lbfb.loan.id = :loanId ORDER BY lbfb.date ASC")
39+
List<LoanBuyDownFeeBalance> findRepaymentPeriodDataByLoanId(@Param("loanId") Long loanId);
4040

41-
@Query("SELECT SUM(lbfb.amount) FROM LoanBuyDownFeeBalance lbfb WHERE lbfb.loan.id = :loanId")
42-
BigDecimal calculateBuydownFeeAmount(Long loanId);
41+
@Query("SELECT COALESCE(SUM(lbfb.amount), 0) FROM LoanBuyDownFeeBalance lbfb WHERE lbfb.loan.id = :loanId")
42+
BigDecimal calculateBuyDownFee(@Param("loanId") Long loanId);
4343

44-
@Query("SELECT SUM(lbfb.amountAdjustment) FROM LoanBuyDownFeeBalance lbfb WHERE lbfb.loan.id = :loanId")
45-
BigDecimal calculateBuydownFeeAdjustment(Long loanId);
44+
@Query("SELECT COALESCE(SUM(lbfb.amountAdjustment), 0) FROM LoanBuyDownFeeBalance lbfb WHERE lbfb.loan.id = :loanId")
45+
BigDecimal calculateBuyDownFeeAdjustment(@Param("loanId") Long loanId);
4646

47-
@Query("SELECT lbfb FROM LoanBuyDownFeeBalance lbfb, LoanTransaction lt, LoanTransactionRelation ltr WHERE lt.loan.id = lbfb.loan.id AND ltr.fromTransaction.id =:transactionId AND ltr.toTransaction.id=lt.id AND lbfb.loanTransaction.id = lt.id")
48-
LoanBuyDownFeeBalance findBalanceForAdjustment(Long transactionId);
47+
@Query("SELECT lbfb FROM LoanBuyDownFeeBalance lbfb WHERE lbfb.loan.id = :loanId AND lbfb.amountAdjustment IS NULL ORDER BY lbfb.date DESC")
48+
List<LoanBuyDownFeeBalance> findBalanceForAdjustment(@Param("loanId") Long loanId);
4949
}

fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/BuyDownFeeWritePlatformServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRelation;
5252
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRelationTypeEnum;
5353
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
54-
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeesBalanceRepository;
54+
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeeBalanceRepository;
5555
import org.apache.fineract.portfolio.note.service.NoteWritePlatformService;
5656
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
5757
import org.apache.fineract.portfolio.paymentdetail.service.PaymentDetailWritePlatformService;
@@ -68,7 +68,7 @@ public class BuyDownFeeWritePlatformServiceImpl implements BuyDownFeePlatformSer
6868
private final LoanJournalEntryPoster loanJournalEntryPoster;
6969
private final NoteWritePlatformService noteWritePlatformService;
7070
private final ExternalIdFactory externalIdFactory;
71-
private final LoanBuyDownFeesBalanceRepository loanBuyDownFeesBalanceRepository;
71+
private final LoanBuyDownFeeBalanceRepository loanBuyDownFeeBalanceRepository;
7272
private final ReprocessLoanTransactionsService reprocessLoanTransactionsService;
7373
private final LoanBalanceService loanBalanceService;
7474
private final LoanLifecycleStateMachine loanLifecycleStateMachine;
@@ -177,13 +177,13 @@ public CommandProcessingResult buyDownFeeAdjustment(final Long loanId, final Lon
177177
LoanTransaction savedBuyDownFeeAdjustment = loanTransactionRepository.saveAndFlush(buyDownFeeAdjustment);
178178

179179
// Update buy down fee balance
180-
LoanBuyDownFeeBalance buydownFeeBalance = loanBuyDownFeesBalanceRepository.findByLoanIdAndLoanTransactionId(loanId,
180+
LoanBuyDownFeeBalance buydownFeeBalance = loanBuyDownFeeBalanceRepository.findByLoanIdAndLoanTransactionId(loanId,
181181
buyDownFeeTransactionId);
182182
if (buydownFeeBalance != null) {
183183
buydownFeeBalance.setAmountAdjustment(MathUtil.nullToZero(buydownFeeBalance.getAmountAdjustment()).add(transactionAmount));
184184
buydownFeeBalance
185185
.setUnrecognizedAmount(MathUtil.negativeToZero(buydownFeeBalance.getUnrecognizedAmount().subtract(transactionAmount)));
186-
loanBuyDownFeesBalanceRepository.save(buydownFeeBalance);
186+
loanBuyDownFeeBalanceRepository.save(buydownFeeBalance);
187187
}
188188

189189
// Update outstanding loan balances
@@ -236,6 +236,6 @@ private void createBuyDownFeeBalance(final LoanTransaction buyDownFeeTransaction
236236
buyDownFeeBalance.setDate(buyDownFeeTransaction.getTransactionDate());
237237
buyDownFeeBalance.setAmount(buyDownFeeTransaction.getAmount());
238238
buyDownFeeBalance.setUnrecognizedAmount(buyDownFeeTransaction.getAmount());
239-
loanBuyDownFeesBalanceRepository.saveAndFlush(buyDownFeeBalance);
239+
loanBuyDownFeeBalanceRepository.saveAndFlush(buyDownFeeBalance);
240240
}
241241
}

fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/ProgressiveLoanTransactionValidatorImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
5959
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
6060
import org.apache.fineract.portfolio.loanaccount.exception.LoanTransactionProcessingException;
61-
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeesBalanceRepository;
61+
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeeBalanceRepository;
6262
import org.apache.fineract.portfolio.loanaccount.repository.LoanCapitalizedIncomeBalanceRepository;
6363
import org.apache.fineract.portfolio.loanaccount.serialization.LoanTransactionValidator;
6464
import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct;
@@ -71,7 +71,7 @@ public class ProgressiveLoanTransactionValidatorImpl implements ProgressiveLoanT
7171
private final LoanTransactionValidator loanTransactionValidator;
7272
private final LoanRepositoryWrapper loanRepositoryWrapper;
7373
private final LoanCapitalizedIncomeBalanceRepository loanCapitalizedIncomeBalanceRepository;
74-
private final LoanBuyDownFeesBalanceRepository loanBuydownFeeBalanceRepository;
74+
private final LoanBuyDownFeeBalanceRepository loanBuydownFeeBalanceRepository;
7575
private final LoanTransactionRepository loanTransactionRepository;
7676

7777
@Override

fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/starter/ProgressiveLoanAccountConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.apache.fineract.portfolio.loanaccount.domain.LoanLifecycleStateMachine;
2525
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
2626
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
27-
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeesBalanceRepository;
27+
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeeBalanceRepository;
2828
import org.apache.fineract.portfolio.loanaccount.repository.LoanCapitalizedIncomeBalanceRepository;
2929
import org.apache.fineract.portfolio.loanaccount.serialization.LoanTransactionValidator;
3030
import org.apache.fineract.portfolio.loanaccount.service.CapitalizedIncomeBalanceService;
@@ -66,9 +66,9 @@ public CapitalizedIncomePlatformService capitalizedIncomePlatformService(Progres
6666
public ProgressiveLoanTransactionValidator progressiveLoanTransactionValidator(FromJsonHelper fromApiJsonHelper,
6767
LoanTransactionValidator loanTransactionValidator, LoanRepositoryWrapper loanRepositoryWrapper,
6868
LoanCapitalizedIncomeBalanceRepository loanCapitalizedIncomeBalanceRepository,
69-
LoanBuyDownFeesBalanceRepository loanBuydownFeesBalanceRepository, LoanTransactionRepository loanTransactionRepository) {
69+
LoanBuyDownFeeBalanceRepository loanBuydownFeeBalanceRepository, LoanTransactionRepository loanTransactionRepository) {
7070
return new ProgressiveLoanTransactionValidatorImpl(fromApiJsonHelper, loanTransactionValidator, loanRepositoryWrapper,
71-
loanCapitalizedIncomeBalanceRepository, loanBuydownFeesBalanceRepository, loanTransactionRepository);
71+
loanCapitalizedIncomeBalanceRepository, loanBuydownFeeBalanceRepository, loanTransactionRepository);
7272
}
7373

7474
@Bean

0 commit comments

Comments
 (0)