diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanBuyDownFeeBalance.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanBuyDownFeeBalance.java new file mode 100644 index 000000000..ed6ce482e --- /dev/null +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanBuyDownFeeBalance.java @@ -0,0 +1,64 @@ +/** + * 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.loanaccount.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import jakarta.persistence.Version; +import java.math.BigDecimal; +import java.time.LocalDate; +import lombok.Getter; +import lombok.Setter; +import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom; + +@Entity +@Table(name = "m_loan_buy_down_fee_balance") +@Getter +@Setter +public class LoanBuyDownFeeBalance extends AbstractAuditableWithUTCDateTimeCustom { + + @Version + private Long version; + + @ManyToOne + @JoinColumn(name = "loan_id", nullable = false) + private Loan loan; + + @ManyToOne + @JoinColumn(name = "loan_transaction_id", nullable = false) + private LoanTransaction loanTransaction; + + @Column(name = "amount", scale = 6, precision = 19, nullable = false) + private BigDecimal amount; + + @Column(name = "date", nullable = false) + private LocalDate date; + + @Column(name = "unrecognized_amount", scale = 6, precision = 19, nullable = false) + private BigDecimal unrecognizedAmount; + + @Column(name = "charged_off_amount", scale = 6, precision = 19) + private BigDecimal chargedOffAmount; + + @Column(name = "amount_adjustment", scale = 6, precision = 19) + private BigDecimal amountAdjustment; +} diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/repository/LoanBuyDownFeesBalanceRepository.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/repository/LoanBuyDownFeesBalanceRepository.java new file mode 100644 index 000000000..5c160ece4 --- /dev/null +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/repository/LoanBuyDownFeesBalanceRepository.java @@ -0,0 +1,26 @@ +/** + * 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.loanaccount.repository; + +import org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface LoanBuyDownFeesBalanceRepository + extends JpaRepository, JpaSpecificationExecutor {} diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/BuyDownFeeWritePlatformServiceImpl.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/BuyDownFeeWritePlatformServiceImpl.java index fdcc56aa1..b54c18de2 100644 --- a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/BuyDownFeeWritePlatformServiceImpl.java +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/BuyDownFeeWritePlatformServiceImpl.java @@ -38,8 +38,10 @@ import org.apache.fineract.portfolio.client.exception.ClientNotActiveException; import org.apache.fineract.portfolio.group.domain.Group; import org.apache.fineract.portfolio.group.exception.GroupNotActiveException; import org.apache.fineract.portfolio.loanaccount.domain.Loan; +import org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction; import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository; +import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeesBalanceRepository; import org.apache.fineract.portfolio.note.service.NoteWritePlatformService; import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail; import org.apache.fineract.portfolio.paymentdetail.service.PaymentDetailWritePlatformService; @@ -56,6 +58,7 @@ public class BuyDownFeeWritePlatformServiceImpl implements BuyDownFeePlatformSer private final LoanJournalEntryPoster loanJournalEntryPoster; private final NoteWritePlatformService noteWritePlatformService; private final ExternalIdFactory externalIdFactory; + private final LoanBuyDownFeesBalanceRepository loanBuyDownFeesBalanceRepository; @Transactional @Override @@ -89,6 +92,9 @@ public class BuyDownFeeWritePlatformServiceImpl implements BuyDownFeePlatformSer // Save transaction loanTransactionRepository.saveAndFlush(buyDownFeeTransaction); + // Create Buy Down Fee balances + createBuyDownFeeBalance(buyDownFeeTransaction); + // Update loan derived fields loan.updateLoanScheduleDependentDerivedFields(); @@ -120,4 +126,14 @@ public class BuyDownFeeWritePlatformServiceImpl implements BuyDownFeePlatformSer throw new GroupNotActiveException(group.getId()); } } + + private void createBuyDownFeeBalance(final LoanTransaction buyDownFeeTransaction) { + LoanBuyDownFeeBalance buyDownFeeBalance = new LoanBuyDownFeeBalance(); + buyDownFeeBalance.setLoan(buyDownFeeTransaction.getLoan()); + buyDownFeeBalance.setLoanTransaction(buyDownFeeTransaction); + buyDownFeeBalance.setDate(buyDownFeeTransaction.getTransactionDate()); + buyDownFeeBalance.setAmount(buyDownFeeTransaction.getAmount()); + buyDownFeeBalance.setUnrecognizedAmount(buyDownFeeTransaction.getAmount()); + loanBuyDownFeesBalanceRepository.saveAndFlush(buyDownFeeBalance); + } } diff --git a/fineract-progressive-loan/src/main/resources/jpa/static-weaving/module/fineract-progressive-loan/persistence.xml b/fineract-progressive-loan/src/main/resources/jpa/static-weaving/module/fineract-progressive-loan/persistence.xml index 9020127fa..8146f21db 100644 --- a/fineract-progressive-loan/src/main/resources/jpa/static-weaving/module/fineract-progressive-loan/persistence.xml +++ b/fineract-progressive-loan/src/main/resources/jpa/static-weaving/module/fineract-progressive-loan/persistence.xml @@ -144,6 +144,7 @@ org.apache.fineract.portfolio.floatingrates.domain.FloatingRatePeriod + org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance org.apache.fineract.portfolio.loanaccount.domain.LoanCapitalizedIncomeBalance org.apache.fineract.portfolio.loanaccount.domain.ProgressiveLoanModel false diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/starter/LoanAccountConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/starter/LoanAccountConfiguration.java index 0e1fafb38..7e1a619d5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/starter/LoanAccountConfiguration.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/starter/LoanAccountConfiguration.java @@ -88,6 +88,7 @@ import org.apache.fineract.portfolio.loanaccount.mapper.LoanChargeMapper; import org.apache.fineract.portfolio.loanaccount.mapper.LoanCollateralManagementMapper; import org.apache.fineract.portfolio.loanaccount.mapper.LoanMapper; import org.apache.fineract.portfolio.loanaccount.mapper.LoanTransactionMapper; +import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeesBalanceRepository; import org.apache.fineract.portfolio.loanaccount.repository.LoanCapitalizedIncomeBalanceRepository; import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanTermVariationsRepository; import org.apache.fineract.portfolio.loanaccount.serialization.LoanApplicationTransitionValidator; @@ -381,9 +382,11 @@ public class LoanAccountConfiguration { public BuyDownFeePlatformService buyDownFeePlatformService(ProgressiveLoanTransactionValidator loanTransactionValidator, LoanAssembler loanAssembler, LoanTransactionRepository loanTransactionRepository, PaymentDetailWritePlatformService paymentDetailWritePlatformService, LoanJournalEntryPoster loanJournalEntryPoster, - NoteWritePlatformService noteWritePlatformService, ExternalIdFactory externalIdFactory) { + NoteWritePlatformService noteWritePlatformService, ExternalIdFactory externalIdFactory, + LoanBuyDownFeesBalanceRepository loanBuyDownFeesBalanceRepository) { return new BuyDownFeeWritePlatformServiceImpl(loanTransactionValidator, loanAssembler, loanTransactionRepository, - paymentDetailWritePlatformService, loanJournalEntryPoster, noteWritePlatformService, externalIdFactory); + paymentDetailWritePlatformService, loanJournalEntryPoster, noteWritePlatformService, externalIdFactory, + loanBuyDownFeesBalanceRepository); } @Bean diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml index ac4f001cc..28ddd5e82 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml @@ -206,4 +206,5 @@ + diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0188_create_loan_buy_down_fee_balance.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0188_create_loan_buy_down_fee_balance.xml new file mode 100644 index 000000000..f320ee2ee --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0188_create_loan_buy_down_fee_balance.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + create unique index concurrently if not exists m_loan_buy_down_fee_balance_idx_1 on m_loan_buy_down_fee_balance(loan_id,loan_transaction_id); + create index concurrently if not exists m_loan_buy_down_fee_balance_idx_2 on m_loan_buy_down_fee_balance(loan_id); + + + + + create unique index m_loan_buy_down_fee_balance_idx_1 on m_loan_buy_down_fee_balance(loan_id,loan_transaction_id); + create index m_loan_buy_down_fee_balance_idx_2 on m_loan_buy_down_fee_balance(loan_id); + + +