Subversion Repositories SmartDukaan

Rev

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