Subversion Repositories SmartDukaan

Rev

Rev 36525 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30652 amit.gupta 1
package com.spice.profitmandi.dao.entity.fofo;
2
 
3
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
4
 
5
import javax.persistence.*;
6
import java.time.LocalDateTime;
7
import java.util.Objects;
8
 
31008 amit.gupta 9
@Entity
31860 tejbeer 10
@Table(name = "fofo.offer_payout")
31008 amit.gupta 11
@NamedQueries({
31380 amit.gupta 12
        @NamedQuery(name = "OfferPayout.selectPaidOffers", query = "select new com.spice.profitmandi.service.transaction.InventoryMarginModel("
13
                + " o.retailerId, li.sgstRate, li.cgstRate, li.igstRate," +
36485 amit 14
                " cast(case when op.createTimestamp >= :startDate and op.createTimestamp <= :endDate then op.amount " +
15
                "			when op.rejectTimestamp >= :startDate and op.rejectTimestamp <= :endDate then -op.amount" +
33459 amit.gupta 16
                "			else 0 end as float),  op.inventoryItemId,  lii.serialNumber, op.description, o.invoiceNumber, " +
36485 amit 17
                " case when op.rejectTimestamp >= :startDate and op.rejectTimestamp <= :endDate then op.rejectTimestamp else op.createTimestamp end, ii.hsnCode)  from "
36184 amit 18
                + " OfferPayout op join InventoryItem ii on ii.id=op.inventoryItemId join LineItemImei lii on (op.serialNumber=lii.serialNumber) join LineItem li on li.id=lii.lineItemId "
31380 amit.gupta 19
                + " join Order o on (o.retailerId=op.fofoId and o.billingTimestamp is not null and o.id=li.orderId) "
36485 amit 20
                + " where op.createTimestamp >= :cnDate and ((op.createTimestamp >= :startDate and op.createTimestamp <= :endDate) or (op.rejectTimestamp >= :startDate and op.rejectTimestamp <= :endDate))"
36489 amit 21
                + " and not (op.rejectTimestamp is not null and op.createTimestamp >= :startDate and op.createTimestamp <= :endDate and op.rejectTimestamp >= :startDate and op.rejectTimestamp <= :endDate)"
34256 ranu 22
                + " and lii.id=(select max(lii2.id) from LineItemImei lii2 join LineItem li2 on li2.id=lii2.lineItemId join Order o2 on o2.id=li2.orderId where lii2.serialNumber=lii.serialNumber and o2.retailerId=op.fofoId) "
23
                + " AND (:fofoId IS NULL OR o.retailerId = :fofoId)"),
31352 amit.gupta 24
 
34256 ranu 25
 
26
 
31380 amit.gupta 27
        @NamedQuery(name = "OfferPayout.getTotalPayoutsByPartnerPeriod", query = "select new com.spice.profitmandi.common.model.OfferPayoutImeiIncomeModel(" +
28
                " ii.id, ii.serialNumber, " +
29
                " case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then max(sr.createTimestamp) end," +
30
                " case when (sr.type='SALE' and o.schemeType != 'SELLIN') then max(sr.createTimestamp)  end, " +
31
                " case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then sum(op.amount)  else 0 end, " +
32
                " case when (sr.type='SALE' and o.schemeType!='SELLIN') then sum(op.amount) else 0 end, " +
33
                " i.catalogItemId, i.brand, i.modelName, i.modelNumber" +
34
                ") from OfferPayout op join Offer o on o.id=op.offerId join InventoryItem ii on ii.serialNumber=op.serialNumber and op.fofoId=ii.fofoId" +
35
                " join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
36
                " and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
37
                " where op.rejectTimestamp is null and sr.createTimestamp between :startDate and :endDate" +
38
                " and (:brand is null or i.brand=:brand)" +
39
                " and (:catalogId is null or i.catalogItemId=:catalogId)" +
40
                " and op.fofoId=:fofoId" +
32234 amit.gupta 41
                " group by ii.id, sr.type "),
31352 amit.gupta 42
 
37089 amit 43
        @NamedQuery(name = "OfferPayout.getTotalPayoutsByPartnerPeriodByMonth", query = "select new com.spice.profitmandi.dao.model.MonthlyOfferPayoutModel(" +
44
                " (year(sr.createTimestamp)*100 + month(sr.createTimestamp))," +
45
                " i.brand," +
46
                " sum(case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then op.amount else 0 end)," +
47
                " sum(case when (sr.type='SALE' and o.schemeType!='SELLIN') then op.amount else 0 end)" +
48
                ") from OfferPayout op join Offer o on o.id=op.offerId join InventoryItem ii on ii.serialNumber=op.serialNumber and op.fofoId=ii.fofoId" +
49
                " join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
50
                " and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
51
                " where op.rejectTimestamp is null and sr.createTimestamp between :startDate and :endDate" +
52
                " and op.fofoId=:fofoId" +
53
                " group by (year(sr.createTimestamp)*100 + month(sr.createTimestamp)), i.brand "),
54
 
31380 amit.gupta 55
        @NamedQuery(name = "OfferPayout.getTotalPayoutsByImei", query = "select new com.spice.profitmandi.common.model.OfferPayoutImeiIncomeModel(" +
56
                " ii.id, ii.serialNumber, " +
57
                " max(case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then sr.createTimestamp end)," +
58
                " max(case when (sr.type='SALE' and o.schemeType != 'SELLIN') then sr.createTimestamp  end), " +
59
                " sum(case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then op.amount  else 0 end), " +
60
                " sum(case when (sr.type='SALE' and o.schemeType!='SELLIN') then op.amount else 0 end), " +
61
                " i.catalogItemId, i.brand, i.modelName, i.modelNumber" +
62
                ") from OfferPayout op join Offer o on o.id=op.offerId join InventoryItem ii on ii.serialNumber=op.serialNumber and op.fofoId=ii.fofoId" +
63
                " join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
64
                " and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
65
                " where op.rejectTimestamp is null and ii.serialNumber in :serialNumbers" +
36508 ranu 66
                " group by ii.id "),
67
        /*,
31380 amit.gupta 68
        @NamedQuery(name = "OfferPayout.selectMarginsByYearMonth", query = "select com.spice.profitmandi.common.model.MarginModel(" +
69
                " " +
70
                ") from Order ord join    OfferPayout op join Offer on o.id=op.offerId join InventoryItem ii on ii.serialNumber=op.serialNumber and op.fofoId=ii.fofoId" +
71
                " join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
72
                " and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
73
                " join  " +
74
                " where op.rejectTimestamp is null and ii.serialNumber in :serialNumbers" +
31382 amit.gupta 75
                " group by ii.id ")*/
36508 ranu 76
 
77
        @NamedQuery(name = "OfferPayout.selectOfferEarningsByFofoId",
78
                query = "select new com.spice.profitmandi.dao.model.OfferEarningModel("
79
                        + " op.offerId, o.name, o.offerNotes,"
80
                        + " count(distinct op.serialNumber), sum(op.amount))"
81
                        + " from OfferPayout op join Offer o on o.id=op.offerId"
82
                        + " where op.fofoId=:fofoId"
83
                        + " and op.createTimestamp >= :startDate and op.createTimestamp <= :endDate"
84
                        + " and op.rejectTimestamp is null"
36525 ranu 85
                        + " and op.status = 'CREDITED'"
36508 ranu 86
                        + " group by op.offerId, o.name, o.offerNotes")
31008 amit.gupta 87
})
30652 amit.gupta 88
public class OfferPayout {
31380 amit.gupta 89
        @Id
90
        @GeneratedValue(strategy = GenerationType.IDENTITY)
91
        private long id;
92
        @Column(name = "fofo_id", nullable = false)
93
        private long fofoId;
94
        @Column(name = "offer_id", nullable = false)
95
        private long offerId;
96
        @Column(name = "criteria_id", nullable = false)
97
        private long criteriaId;
98
        @Column(name = "slab_amount", nullable = false)
99
        private double slabAmount;
100
        @Column(name = "serial_number", nullable = false)
101
        private String serialNumber;
102
        @Column(name = "amount", nullable = false)
103
        private double amount;
104
        @Column(name = "status", nullable = false)
105
        @Enumerated(EnumType.STRING)
106
        private SchemePayoutStatus status;
107
        @Column(name = "description", nullable = false)
108
        private String description;
109
        @Column(name = "inventory_item_id", nullable = false)
110
        private int inventoryItemId;
111
        @Column(name = "create_timestamp", nullable = false)
112
        private LocalDateTime createTimestamp;
113
        @Column(name = "reject_timestamp")
114
        private LocalDateTime rejectTimestamp;
30652 amit.gupta 115
 
31380 amit.gupta 116
        public OfferPayout() {
30996 amit.gupta 117
 
31380 amit.gupta 118
        }
30996 amit.gupta 119
 
31380 amit.gupta 120
        public OfferPayout(long fofoId, long offerId, long criteriaId, double slabAmount, String serialNumber, double amount, SchemePayoutStatus status, String description, LocalDateTime createTimestamp) {
121
                this.fofoId = fofoId;
122
                this.offerId = offerId;
123
                this.criteriaId = criteriaId;
124
                this.slabAmount = slabAmount;
125
                this.serialNumber = serialNumber;
126
                this.amount = amount;
127
                this.status = status;
128
                this.description = description;
129
                this.createTimestamp = createTimestamp;
130
        }
31008 amit.gupta 131
 
31380 amit.gupta 132
        @Override
133
        public String toString() {
134
                return "OfferPayout{" +
135
                        "id=" + id +
136
                        ", fofoId=" + fofoId +
137
                        ", offerId=" + offerId +
138
                        ", criteriaId=" + criteriaId +
139
                        ", slabAmount=" + slabAmount +
140
                        ", serialNumber='" + serialNumber + '\'' +
141
                        ", amount=" + amount +
142
                        ", status=" + status +
143
                        ", description='" + description + '\'' +
144
                        ", inventoryItemId=" + inventoryItemId +
145
                        ", createTimestamp=" + createTimestamp +
146
                        ", rejectTimestamp=" + rejectTimestamp +
147
                        '}';
148
        }
30996 amit.gupta 149
 
31380 amit.gupta 150
        public int getInventoryItemId() {
151
                return inventoryItemId;
152
        }
31008 amit.gupta 153
 
31380 amit.gupta 154
        public void setInventoryItemId(int inventoryItemId) {
155
                this.inventoryItemId = inventoryItemId;
156
        }
31008 amit.gupta 157
 
31380 amit.gupta 158
        @Override
159
        public boolean equals(Object o) {
160
                if (this == o) return true;
161
                if (o == null || getClass() != o.getClass()) return false;
162
                OfferPayout that = (OfferPayout) o;
163
                return id == that.id && fofoId == that.fofoId && offerId == that.offerId && criteriaId == that.criteriaId && Double.compare(that.slabAmount, slabAmount) == 0 && Double.compare(that.amount, amount) == 0 && inventoryItemId == that.inventoryItemId && Objects.equals(serialNumber, that.serialNumber) && status == that.status && Objects.equals(description, that.description) && Objects.equals(createTimestamp, that.createTimestamp) && Objects.equals(rejectTimestamp, that.rejectTimestamp);
164
        }
31008 amit.gupta 165
 
31380 amit.gupta 166
        @Override
167
        public int hashCode() {
168
                return Objects.hash(id, fofoId, offerId, criteriaId, slabAmount, serialNumber, amount, status, description, inventoryItemId, createTimestamp, rejectTimestamp);
169
        }
31008 amit.gupta 170
 
31380 amit.gupta 171
        public LocalDateTime getCreateTimestamp() {
172
                return createTimestamp;
173
        }
30652 amit.gupta 174
 
31380 amit.gupta 175
        public void setCreateTimestamp(LocalDateTime createTimestamp) {
176
                this.createTimestamp = createTimestamp;
177
        }
30652 amit.gupta 178
 
31380 amit.gupta 179
        public LocalDateTime getRejectTimestamp() {
180
                return rejectTimestamp;
181
        }
30996 amit.gupta 182
 
31380 amit.gupta 183
        public void setRejectTimestamp(LocalDateTime rejectTimestamp) {
184
                this.rejectTimestamp = rejectTimestamp;
185
        }
30996 amit.gupta 186
 
31380 amit.gupta 187
        public long getId() {
188
                return id;
189
        }
30996 amit.gupta 190
 
31380 amit.gupta 191
        public void setId(long id) {
192
                this.id = id;
193
        }
30652 amit.gupta 194
 
31380 amit.gupta 195
        public long getFofoId() {
196
                return fofoId;
197
        }
30652 amit.gupta 198
 
31380 amit.gupta 199
        public void setFofoId(long fofoId) {
200
                this.fofoId = fofoId;
201
        }
30652 amit.gupta 202
 
31380 amit.gupta 203
        public long getOfferId() {
204
                return offerId;
205
        }
30652 amit.gupta 206
 
31380 amit.gupta 207
        public void setOfferId(long offerId) {
208
                this.offerId = offerId;
209
        }
30652 amit.gupta 210
 
31380 amit.gupta 211
        public long getCriteriaId() {
212
                return criteriaId;
213
        }
30652 amit.gupta 214
 
31380 amit.gupta 215
        public void setCriteriaId(long criteriaId) {
216
                this.criteriaId = criteriaId;
217
        }
30652 amit.gupta 218
 
31380 amit.gupta 219
        public double getSlabAmount() {
220
                return slabAmount;
221
        }
30652 amit.gupta 222
 
31380 amit.gupta 223
        public void setSlabAmount(double slabAmount) {
224
                this.slabAmount = slabAmount;
225
        }
30652 amit.gupta 226
 
31380 amit.gupta 227
        public String getSerialNumber() {
228
                return serialNumber;
229
        }
30652 amit.gupta 230
 
31380 amit.gupta 231
        public void setSerialNumber(String serialNumber) {
232
                this.serialNumber = serialNumber;
233
        }
30652 amit.gupta 234
 
31380 amit.gupta 235
        public double getAmount() {
236
                return amount;
237
        }
30652 amit.gupta 238
 
31380 amit.gupta 239
        public void setAmount(double amount) {
240
                this.amount = amount;
241
        }
30652 amit.gupta 242
 
31380 amit.gupta 243
        public SchemePayoutStatus getStatus() {
244
                return status;
245
        }
30652 amit.gupta 246
 
31380 amit.gupta 247
        public void setStatus(SchemePayoutStatus status) {
248
                this.status = status;
249
        }
30652 amit.gupta 250
 
31380 amit.gupta 251
        public String getDescription() {
252
                return description;
253
        }
30652 amit.gupta 254
 
31380 amit.gupta 255
        public void setDescription(String description) {
256
                this.description = description;
257
        }
30652 amit.gupta 258
}