| 30859 |
tejbeer |
1 |
package com.spice.profitmandi.dao.entity.transaction;
|
|
|
2 |
|
| 32681 |
amit.gupta |
3 |
import com.spice.profitmandi.dao.model.DailyStatementModel;
|
|
|
4 |
|
|
|
5 |
import javax.persistence.*;
|
| 30859 |
tejbeer |
6 |
import java.math.BigDecimal;
|
| 33528 |
amit.gupta |
7 |
import java.time.LocalDate;
|
| 30859 |
tejbeer |
8 |
import java.time.LocalDateTime;
|
| 33528 |
amit.gupta |
9 |
import java.time.temporal.ChronoUnit;
|
| 30859 |
tejbeer |
10 |
import java.util.List;
|
| 32681 |
amit.gupta |
11 |
import java.util.Objects;
|
| 30859 |
tejbeer |
12 |
|
|
|
13 |
@Entity
|
| 32074 |
tejbeer |
14 |
@Table(name = "transaction.loan")
|
| 33827 |
ranu |
15 |
@NamedQueries({
|
|
|
16 |
@NamedQuery(name = "Loan.getLoansCountWithFofoID", query = "select new com.spice.profitmandi.dao.model.LoanCountByFofoIdModel(" +
|
|
|
17 |
" cast(fofoId as int), count(id))" +
|
|
|
18 |
" from Loan " +
|
|
|
19 |
" where fofoId in (:fofoIds) " +
|
|
|
20 |
" group by fofoId "),
|
| 34212 |
ranu |
21 |
|
| 34453 |
amit.gupta |
22 |
@NamedQuery(name = "Loan.findBlockedLoans", query = "SELECT l FROM Loan l WHERE l.freeDays > 364"),
|
|
|
23 |
|
|
|
24 |
@NamedQuery(name= "Loan.getDueLoansByFofoId", query = "SELECT new com.spice.profitmandi.dao.model.loan.TotalLoanAmountDueModel(ls.id, l.pendingAmount, SUM(ls.amount)) " +
|
|
|
25 |
"FROM Loan l JOIN LoanStatement ls on ls.loanId=l.id " +
|
|
|
26 |
"WHERE l.fofoId = :fofoId AND l.pendingAmount > 0 " +
|
|
|
27 |
"GROUP BY ls.loanId")
|
| 33827 |
ranu |
28 |
})
|
|
|
29 |
|
| 30859 |
tejbeer |
30 |
public class Loan {
|
|
|
31 |
|
|
|
32 |
@Id
|
|
|
33 |
@Column(name = "id", unique = true, updatable = false)
|
|
|
34 |
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
35 |
private int id;
|
|
|
36 |
|
|
|
37 |
@Column(name = "fofo_id")
|
|
|
38 |
private int fofoId;
|
|
|
39 |
|
|
|
40 |
@Column(name = "interest_rate")
|
|
|
41 |
private BigDecimal interestRate;
|
|
|
42 |
|
|
|
43 |
@Column(name = "intial_amount")
|
|
|
44 |
private BigDecimal intialAmount;
|
|
|
45 |
|
|
|
46 |
@Column(name = "pending_amount")
|
|
|
47 |
private BigDecimal pendingAmount;
|
|
|
48 |
|
|
|
49 |
@Column(name = "created_on")
|
|
|
50 |
private LocalDateTime createdOn;
|
|
|
51 |
|
| 32681 |
amit.gupta |
52 |
@Column(name = "settled_on")
|
|
|
53 |
private LocalDateTime settledOn;
|
|
|
54 |
|
| 30859 |
tejbeer |
55 |
@Column(name = "due_date")
|
|
|
56 |
private LocalDateTime dueDate;
|
|
|
57 |
|
|
|
58 |
@Column(name = "interest_accured")
|
|
|
59 |
private BigDecimal interestAccrued;
|
|
|
60 |
|
|
|
61 |
@Column(name = "interest_paid")
|
|
|
62 |
private BigDecimal interestPaid;
|
|
|
63 |
|
|
|
64 |
@Column(name = "free_days")
|
|
|
65 |
private int freeDays;
|
|
|
66 |
|
|
|
67 |
@Transient
|
| 30929 |
tejbeer |
68 |
private boolean loanStatus;
|
|
|
69 |
|
|
|
70 |
@Transient
|
| 31159 |
tejbeer |
71 |
private BigDecimal totalPending;
|
|
|
72 |
|
| 33528 |
amit.gupta |
73 |
public long getDays() {
|
|
|
74 |
return ChronoUnit.DAYS.between(this.getCreatedOn().toLocalDate(), LocalDateTime.now()) + 1;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
public boolean isDue() {
|
| 33532 |
amit.gupta |
78 |
return this.getSettledOn()==null && !this.getDueDate().toLocalDate().isBefore(LocalDate.now());
|
| 33528 |
amit.gupta |
79 |
}
|
|
|
80 |
|
| 33529 |
amit.gupta |
81 |
public boolean isOverdue() {
|
| 33532 |
amit.gupta |
82 |
return this.getSettledOn()==null && this.getDueDate().toLocalDate().isBefore(LocalDate.now()) &&
|
|
|
83 |
!this.getDueDate().plusDays(15).toLocalDate().isBefore(LocalDate.now());
|
| 33528 |
amit.gupta |
84 |
}
|
|
|
85 |
|
| 33529 |
amit.gupta |
86 |
public boolean isDefault() {
|
| 33532 |
amit.gupta |
87 |
return this.getSettledOn()==null && this.getDueDate().plusDays(15).toLocalDate().isBefore(LocalDate.now());
|
| 33528 |
amit.gupta |
88 |
}
|
|
|
89 |
|
| 31159 |
tejbeer |
90 |
@Transient
|
| 30859 |
tejbeer |
91 |
private List<DailyStatementModel> dailyStatementModel;
|
|
|
92 |
|
|
|
93 |
public int getId() {
|
|
|
94 |
return id;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public void setId(int id) {
|
|
|
98 |
this.id = id;
|
|
|
99 |
}
|
|
|
100 |
|
| 31159 |
tejbeer |
101 |
public BigDecimal getTotalPending() {
|
|
|
102 |
return totalPending;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public void setTotalPending(BigDecimal totalPending) {
|
|
|
106 |
this.totalPending = totalPending;
|
|
|
107 |
}
|
|
|
108 |
|
| 30859 |
tejbeer |
109 |
public int getFofoId() {
|
|
|
110 |
return fofoId;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
public void setFofoId(int fofoId) {
|
|
|
114 |
this.fofoId = fofoId;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
public BigDecimal getInterestRate() {
|
|
|
118 |
return interestRate;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
public void setInterestRate(BigDecimal interestRate) {
|
|
|
122 |
this.interestRate = interestRate;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public BigDecimal getIntialAmount() {
|
|
|
126 |
return intialAmount;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
public void setIntialAmount(BigDecimal intialAmount) {
|
|
|
130 |
this.intialAmount = intialAmount;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
public BigDecimal getPendingAmount() {
|
|
|
134 |
return pendingAmount;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
public void setPendingAmount(BigDecimal pendingAmount) {
|
|
|
138 |
this.pendingAmount = pendingAmount;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
public LocalDateTime getCreatedOn() {
|
|
|
142 |
return createdOn;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public void setCreatedOn(LocalDateTime createdOn) {
|
|
|
146 |
this.createdOn = createdOn;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
public LocalDateTime getDueDate() {
|
|
|
150 |
return dueDate;
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
public void setDueDate(LocalDateTime dueDate) {
|
|
|
154 |
this.dueDate = dueDate;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
public BigDecimal getInterestAccrued() {
|
|
|
158 |
return interestAccrued;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
public void setInterestAccrued(BigDecimal interestAccrued) {
|
|
|
162 |
this.interestAccrued = interestAccrued;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
public BigDecimal getInterestPaid() {
|
|
|
166 |
return interestPaid;
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public void setInterestPaid(BigDecimal interestPaid) {
|
|
|
170 |
this.interestPaid = interestPaid;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
public int getFreeDays() {
|
|
|
174 |
return freeDays;
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
public void setFreeDays(int freeDays) {
|
|
|
178 |
this.freeDays = freeDays;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
public List<DailyStatementModel> getDailyStatementModel() {
|
|
|
182 |
return dailyStatementModel;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
public void setDailyStatementModel(List<DailyStatementModel> dailyStatementModel) {
|
|
|
186 |
this.dailyStatementModel = dailyStatementModel;
|
|
|
187 |
}
|
|
|
188 |
|
| 33696 |
amit.gupta |
189 |
public boolean isLimit() {
|
|
|
190 |
return this.getFreeDays() >= 365;
|
|
|
191 |
}
|
|
|
192 |
|
| 32681 |
amit.gupta |
193 |
@Override
|
|
|
194 |
public String toString() {
|
|
|
195 |
return "Loan{" +
|
|
|
196 |
"id=" + id +
|
|
|
197 |
", fofoId=" + fofoId +
|
|
|
198 |
", interestRate=" + interestRate +
|
|
|
199 |
", intialAmount=" + intialAmount +
|
|
|
200 |
", pendingAmount=" + pendingAmount +
|
|
|
201 |
", createdOn=" + createdOn +
|
|
|
202 |
", settledOn=" + settledOn +
|
|
|
203 |
", dueDate=" + dueDate +
|
|
|
204 |
", interestAccrued=" + interestAccrued +
|
|
|
205 |
", interestPaid=" + interestPaid +
|
|
|
206 |
", freeDays=" + freeDays +
|
|
|
207 |
", loanStatus=" + loanStatus +
|
|
|
208 |
", totalPending=" + totalPending +
|
|
|
209 |
", dailyStatementModel=" + dailyStatementModel +
|
|
|
210 |
'}';
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
@Override
|
|
|
214 |
public boolean equals(Object o) {
|
|
|
215 |
if (this == o) return true;
|
|
|
216 |
if (o == null || getClass() != o.getClass()) return false;
|
|
|
217 |
Loan loan = (Loan) o;
|
|
|
218 |
return id == loan.id && fofoId == loan.fofoId && freeDays == loan.freeDays && loanStatus == loan.loanStatus && Objects.equals(interestRate, loan.interestRate) && Objects.equals(intialAmount, loan.intialAmount) && Objects.equals(pendingAmount, loan.pendingAmount) && Objects.equals(createdOn, loan.createdOn) && Objects.equals(settledOn, loan.settledOn) && Objects.equals(dueDate, loan.dueDate) && Objects.equals(interestAccrued, loan.interestAccrued) && Objects.equals(interestPaid, loan.interestPaid) && Objects.equals(totalPending, loan.totalPending) && Objects.equals(dailyStatementModel, loan.dailyStatementModel);
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
@Override
|
|
|
222 |
public int hashCode() {
|
|
|
223 |
return Objects.hash(id, fofoId, interestRate, intialAmount, pendingAmount, createdOn, settledOn, dueDate, interestAccrued, interestPaid, freeDays, loanStatus, totalPending, dailyStatementModel);
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public LocalDateTime getSettledOn() {
|
|
|
227 |
return settledOn;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
public void setSettledOn(LocalDateTime settledOn) {
|
|
|
231 |
this.settledOn = settledOn;
|
|
|
232 |
}
|
|
|
233 |
|
| 30929 |
tejbeer |
234 |
public boolean isLoanStatus() {
|
|
|
235 |
return loanStatus;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
public void setLoanStatus(boolean loanStatus) {
|
|
|
239 |
this.loanStatus = loanStatus;
|
|
|
240 |
}
|
|
|
241 |
|
| 30859 |
tejbeer |
242 |
}
|