FINERACT-2311: Add buy down fee balance entity and db table, create balance on transaction

This commit is contained in:
mark.vituska
2025-07-04 14:23:28 +02:00
committed by Adam Saghy
parent 71e763115e
commit 4feee70a7a
7 changed files with 230 additions and 2 deletions
@@ -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<Long> {
@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;
}
@@ -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<LoanBuyDownFeeBalance, Long>, JpaSpecificationExecutor<LoanBuyDownFeeBalance> {}
@@ -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);
}
}
@@ -144,6 +144,7 @@
<class>org.apache.fineract.portfolio.floatingrates.domain.FloatingRatePeriod</class>
<!-- Progressive Loan Module Entities -->
<class>org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance</class>
<class>org.apache.fineract.portfolio.loanaccount.domain.LoanCapitalizedIncomeBalance</class>
<class>org.apache.fineract.portfolio.loanaccount.domain.ProgressiveLoanModel</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>