Subversion Repositories SmartDukaan

Rev

Rev 35320 | Rev 35876 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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