Subversion Repositories SmartDukaan

Rev

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