Subversion Repositories SmartDukaan

Rev

Rev 34498 | Rev 34765 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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