Skip to content

Commit 1bd3505

Browse files
committed
FINERACT-2311: Add buy down fee balance entity and db table, create balance on transaction
1 parent 570f44a commit 1bd3505

File tree

7 files changed

+230
-2
lines changed

7 files changed

+230
-2
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.portfolio.loanaccount.domain;
20+
21+
import jakarta.persistence.Column;
22+
import jakarta.persistence.Entity;
23+
import jakarta.persistence.JoinColumn;
24+
import jakarta.persistence.ManyToOne;
25+
import jakarta.persistence.Table;
26+
import jakarta.persistence.Version;
27+
import java.math.BigDecimal;
28+
import java.time.LocalDate;
29+
import lombok.Getter;
30+
import lombok.Setter;
31+
import org.apache.fineract.infrastructure.core.domain.AbstractAuditableWithUTCDateTimeCustom;
32+
33+
@Entity
34+
@Table(name = "m_loan_buy_down_fee_balance")
35+
@Getter
36+
@Setter
37+
public class LoanBuyDownFeeBalance extends AbstractAuditableWithUTCDateTimeCustom<Long> {
38+
39+
@Version
40+
private Long version;
41+
42+
@ManyToOne
43+
@JoinColumn(name = "loan_id", nullable = false)
44+
private Loan loan;
45+
46+
@ManyToOne
47+
@JoinColumn(name = "loan_transaction_id", nullable = false)
48+
private LoanTransaction loanTransaction;
49+
50+
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
51+
private BigDecimal amount;
52+
53+
@Column(name = "date", nullable = false)
54+
private LocalDate date;
55+
56+
@Column(name = "unrecognized_amount", scale = 6, precision = 19, nullable = false)
57+
private BigDecimal unrecognizedAmount;
58+
59+
@Column(name = "charged_off_amount", scale = 6, precision = 19)
60+
private BigDecimal chargedOffAmount;
61+
62+
@Column(name = "amount_adjustment", scale = 6, precision = 19)
63+
private BigDecimal amountAdjustment;
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.portfolio.loanaccount.repository;
20+
21+
import org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance;
22+
import org.springframework.data.jpa.repository.JpaRepository;
23+
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
24+
25+
public interface LoanBuyDownFeesBalanceRepository
26+
extends JpaRepository<LoanBuyDownFeeBalance, Long>, JpaSpecificationExecutor<LoanBuyDownFeeBalance> {}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import org.apache.fineract.portfolio.group.domain.Group;
3939
import org.apache.fineract.portfolio.group.exception.GroupNotActiveException;
4040
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
41+
import org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance;
4142
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
4243
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
44+
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeesBalanceRepository;
4345
import org.apache.fineract.portfolio.note.service.NoteWritePlatformService;
4446
import org.apache.fineract.portfolio.paymentdetail.domain.PaymentDetail;
4547
import org.apache.fineract.portfolio.paymentdetail.service.PaymentDetailWritePlatformService;
@@ -56,6 +58,7 @@ public class BuyDownFeeWritePlatformServiceImpl implements BuyDownFeePlatformSer
5658
private final LoanJournalEntryPoster loanJournalEntryPoster;
5759
private final NoteWritePlatformService noteWritePlatformService;
5860
private final ExternalIdFactory externalIdFactory;
61+
private final LoanBuyDownFeesBalanceRepository loanBuyDownFeesBalanceRepository;
5962

6063
@Transactional
6164
@Override
@@ -89,6 +92,9 @@ public CommandProcessingResult makeLoanBuyDownFee(final Long loanId, final JsonC
8992
// Save transaction
9093
loanTransactionRepository.saveAndFlush(buyDownFeeTransaction);
9194

95+
// Create Buy Down Fee balances
96+
createBuyDownFeeBalance(buyDownFeeTransaction);
97+
9298
// Update loan derived fields
9399
loan.updateLoanScheduleDependentDerivedFields();
94100

@@ -120,4 +126,14 @@ private void checkClientOrGroupActive(final Loan loan) {
120126
throw new GroupNotActiveException(group.getId());
121127
}
122128
}
129+
130+
private void createBuyDownFeeBalance(final LoanTransaction buyDownFeeTransaction) {
131+
LoanBuyDownFeeBalance buyDownFeeBalance = new LoanBuyDownFeeBalance();
132+
buyDownFeeBalance.setLoan(buyDownFeeTransaction.getLoan());
133+
buyDownFeeBalance.setLoanTransaction(buyDownFeeTransaction);
134+
buyDownFeeBalance.setDate(buyDownFeeTransaction.getTransactionDate());
135+
buyDownFeeBalance.setAmount(buyDownFeeTransaction.getAmount());
136+
buyDownFeeBalance.setUnrecognizedAmount(buyDownFeeTransaction.getAmount());
137+
loanBuyDownFeesBalanceRepository.saveAndFlush(buyDownFeeBalance);
138+
}
123139
}

fineract-progressive-loan/src/main/resources/jpa/static-weaving/module/fineract-progressive-loan/persistence.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<class>org.apache.fineract.portfolio.floatingrates.domain.FloatingRatePeriod</class>
145145

146146
<!-- Progressive Loan Module Entities -->
147+
<class>org.apache.fineract.portfolio.loanaccount.domain.LoanBuyDownFeeBalance</class>
147148
<class>org.apache.fineract.portfolio.loanaccount.domain.LoanCapitalizedIncomeBalance</class>
148149
<class>org.apache.fineract.portfolio.loanaccount.domain.ProgressiveLoanModel</class>
149150
<exclude-unlisted-classes>false</exclude-unlisted-classes>

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/starter/LoanAccountConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import org.apache.fineract.portfolio.loanaccount.mapper.LoanCollateralManagementMapper;
8989
import org.apache.fineract.portfolio.loanaccount.mapper.LoanMapper;
9090
import org.apache.fineract.portfolio.loanaccount.mapper.LoanTransactionMapper;
91+
import org.apache.fineract.portfolio.loanaccount.repository.LoanBuyDownFeesBalanceRepository;
9192
import org.apache.fineract.portfolio.loanaccount.repository.LoanCapitalizedIncomeBalanceRepository;
9293
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.domain.LoanTermVariationsRepository;
9394
import org.apache.fineract.portfolio.loanaccount.serialization.LoanApplicationTransitionValidator;
@@ -381,9 +382,11 @@ public LoanUtilService loanUtilService(ApplicationCurrencyRepositoryWrapper appl
381382
public BuyDownFeePlatformService buyDownFeePlatformService(ProgressiveLoanTransactionValidator loanTransactionValidator,
382383
LoanAssembler loanAssembler, LoanTransactionRepository loanTransactionRepository,
383384
PaymentDetailWritePlatformService paymentDetailWritePlatformService, LoanJournalEntryPoster loanJournalEntryPoster,
384-
NoteWritePlatformService noteWritePlatformService, ExternalIdFactory externalIdFactory) {
385+
NoteWritePlatformService noteWritePlatformService, ExternalIdFactory externalIdFactory,
386+
LoanBuyDownFeesBalanceRepository loanBuyDownFeesBalanceRepository) {
385387
return new BuyDownFeeWritePlatformServiceImpl(loanTransactionValidator, loanAssembler, loanTransactionRepository,
386-
paymentDetailWritePlatformService, loanJournalEntryPoster, noteWritePlatformService, externalIdFactory);
388+
paymentDetailWritePlatformService, loanJournalEntryPoster, noteWritePlatformService, externalIdFactory,
389+
loanBuyDownFeesBalanceRepository);
387390
}
388391

389392
@Bean

fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,5 @@
205205
<include file="parts/0184_add_document_event_configuration.xml" relativeToChangelogFile="true" />
206206
<include file="parts/0185_loan_buy_down_fee.xml" relativeToChangelogFile="true" />
207207
<include file="parts/0186_add_buy_down_fee_to_loan_product.xml" relativeToChangelogFile="true" />
208+
<include file="parts/0187_create_loan_buy_down_fee_balance.xml" relativeToChangelogFile="true" />
208209
</databaseChangeLog>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">
25+
<changeSet author="fineract" id="1" context="postgresql">
26+
<createTable tableName="m_loan_buy_down_fee_balance">
27+
<column autoIncrement="true" name="id" type="BIGINT">
28+
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_m_loan_buy_down_fee_balance"/>
29+
</column>
30+
<column name="version" type="BIGINT">
31+
<constraints nullable="false"/>
32+
</column>
33+
<column name="loan_id" type="BIGINT">
34+
<constraints nullable="false"/>
35+
</column>
36+
<column name="loan_transaction_id" type="BIGINT">
37+
<constraints nullable="false"/>
38+
</column>
39+
<column name="amount" type="DECIMAL(19, 6)">
40+
<constraints nullable="false"/>
41+
</column>
42+
<column name="date" type="DATE">
43+
<constraints nullable="false"/>
44+
</column>
45+
<column name="unrecognized_amount" type="DECIMAL(19, 6)">
46+
<constraints nullable="false"/>
47+
</column>
48+
<column name="charged_off_amount" type="DECIMAL(19, 6)" />
49+
<column name="amount_adjustment" type="DECIMAL(19, 6)" />
50+
<column name="created_by" type="BIGINT"/>
51+
<column name="created_on_utc" type="timestamp with time zone"/>
52+
<column name="last_modified_by" type="BIGINT"/>
53+
<column name="last_modified_on_utc" type="timestamp with time zone"/>
54+
</createTable>
55+
</changeSet>
56+
<changeSet author="fineract" id="2" context="mysql">
57+
<createTable tableName="m_loan_buy_down_fee_balance">
58+
<column autoIncrement="true" name="id" type="BIGINT">
59+
<constraints nullable="false" primaryKey="true" primaryKeyName="pk_m_loan_buy_down_fee_balance"/>
60+
</column>
61+
<column name="version" type="BIGINT">
62+
<constraints nullable="false"/>
63+
</column>
64+
<column name="loan_id" type="BIGINT">
65+
<constraints nullable="false"/>
66+
</column>
67+
<column name="loan_transaction_id" type="BIGINT">
68+
<constraints nullable="false"/>
69+
</column>
70+
<column name="amount" type="DECIMAL(19, 6)">
71+
<constraints nullable="false"/>
72+
</column>
73+
<column name="date" type="DATE">
74+
<constraints nullable="false"/>
75+
</column>
76+
<column name="unrecognized_amount" type="DECIMAL(19, 6)">
77+
<constraints nullable="false"/>
78+
</column>
79+
<column name="charged_off_amount" type="DECIMAL(19, 6)" />
80+
<column name="amount_adjustment" type="DECIMAL(19, 6)" />
81+
<column name="created_by" type="BIGINT"/>
82+
<column name="created_on_utc" type="DATETIME"/>
83+
<column name="last_modified_by" type="BIGINT"/>
84+
<column name="last_modified_on_utc" type="DATETIME"/>
85+
</createTable>
86+
</changeSet>
87+
<changeSet author="fineract" id="3">
88+
<addForeignKeyConstraint baseColumnNames="created_by" baseTableName="m_loan_buy_down_fee_balance"
89+
constraintName="FK_loan_buy_down_fees_balance_created_by" deferrable="false" initiallyDeferred="false"
90+
onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="id"
91+
referencedTableName="m_appuser" validate="true"/>
92+
<addForeignKeyConstraint baseColumnNames="last_modified_by" baseTableName="m_loan_buy_down_fee_balance"
93+
constraintName="FK_loan_buy_down_fees_balance_last_modified_by" deferrable="false" initiallyDeferred="false"
94+
onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="id"
95+
referencedTableName="m_appuser" validate="true"/>
96+
<addForeignKeyConstraint baseColumnNames="loan_id" baseTableName="m_loan_buy_down_fee_balance"
97+
constraintName="FK_loan_buy_down_fees_balance_loan_id" deferrable="false" initiallyDeferred="false"
98+
onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="id"
99+
referencedTableName="m_loan" validate="true"/>
100+
<addForeignKeyConstraint baseColumnNames="loan_transaction_id" baseTableName="m_loan_buy_down_fee_balance"
101+
constraintName="FK_loan_buy_down_fees_balance_transaction_id" deferrable="false" initiallyDeferred="false"
102+
onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="id"
103+
referencedTableName="m_loan_transaction" validate="true"/>
104+
</changeSet>
105+
<changeSet author="fineract" id="4" runInTransaction="false" context="postgresql">
106+
<sql>
107+
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);
108+
create index concurrently if not exists m_loan_buy_down_fee_balance_idx_2 on m_loan_buy_down_fee_balance(loan_id);
109+
</sql>
110+
</changeSet>
111+
<changeSet author="fineract" id="5" context="mysql">
112+
<sql>
113+
create unique index m_loan_buy_down_fee_balance_idx_1 on m_loan_buy_down_fee_balance(loan_id,loan_transaction_id);
114+
create index m_loan_buy_down_fee_balance_idx_2 on m_loan_buy_down_fee_balance(loan_id);
115+
</sql>
116+
</changeSet>
117+
</databaseChangeLog>

0 commit comments

Comments
 (0)