Subversion Repositories SmartDukaan

Rev

Rev 36489 | Rev 36525 | Go to most recent revision | 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
 
31380 amit.gupta 43
        @NamedQuery(name = "OfferPayout.getTotalPayoutsByImei", query = "select new com.spice.profitmandi.common.model.OfferPayoutImeiIncomeModel(" +
44
                " ii.id, ii.serialNumber, " +
45
                " max(case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then sr.createTimestamp end)," +
46
                " max(case when (sr.type='SALE' and o.schemeType != 'SELLIN') then sr.createTimestamp  end), " +
47
                " sum(case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then op.amount  else 0 end), " +
48
                " sum(case when (sr.type='SALE' and o.schemeType!='SELLIN') then op.amount else 0 end), " +
49
                " i.catalogItemId, i.brand, i.modelName, i.modelNumber" +
50
                ") from OfferPayout op join Offer o on o.id=op.offerId join InventoryItem ii on ii.serialNumber=op.serialNumber and op.fofoId=ii.fofoId" +
51
                " join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
52
                " and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
53
                " where op.rejectTimestamp is null and ii.serialNumber in :serialNumbers" +
36508 ranu 54
                " group by ii.id "),
55
        /*,
31380 amit.gupta 56
        @NamedQuery(name = "OfferPayout.selectMarginsByYearMonth", query = "select com.spice.profitmandi.common.model.MarginModel(" +
57
                " " +
58
                ") 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" +
59
                " join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
60
                " and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
61
                " join  " +
62
                " where op.rejectTimestamp is null and ii.serialNumber in :serialNumbers" +
31382 amit.gupta 63
                " group by ii.id ")*/
36508 ranu 64
 
65
        @NamedQuery(name = "OfferPayout.selectOfferEarningsByFofoId",
66
                query = "select new com.spice.profitmandi.dao.model.OfferEarningModel("
67
                        + " op.offerId, o.name, o.offerNotes,"
68
                        + " count(distinct op.serialNumber), sum(op.amount))"
69
                        + " from OfferPayout op join Offer o on o.id=op.offerId"
70
                        + " where op.fofoId=:fofoId"
71
                        + " and op.createTimestamp >= :startDate and op.createTimestamp <= :endDate"
72
                        + " and op.rejectTimestamp is null"
73
                        + " group by op.offerId, o.name, o.offerNotes")
31008 amit.gupta 74
})
30652 amit.gupta 75
public class OfferPayout {
31380 amit.gupta 76
        @Id
77
        @GeneratedValue(strategy = GenerationType.IDENTITY)
78
        private long id;
79
        @Column(name = "fofo_id", nullable = false)
80
        private long fofoId;
81
        @Column(name = "offer_id", nullable = false)
82
        private long offerId;
83
        @Column(name = "criteria_id", nullable = false)
84
        private long criteriaId;
85
        @Column(name = "slab_amount", nullable = false)
86
        private double slabAmount;
87
        @Column(name = "serial_number", nullable = false)
88
        private String serialNumber;
89
        @Column(name = "amount", nullable = false)
90
        private double amount;
91
        @Column(name = "status", nullable = false)
92
        @Enumerated(EnumType.STRING)
93
        private SchemePayoutStatus status;
94
        @Column(name = "description", nullable = false)
95
        private String description;
96
        @Column(name = "inventory_item_id", nullable = false)
97
        private int inventoryItemId;
98
        @Column(name = "create_timestamp", nullable = false)
99
        private LocalDateTime createTimestamp;
100
        @Column(name = "reject_timestamp")
101
        private LocalDateTime rejectTimestamp;
30652 amit.gupta 102
 
31380 amit.gupta 103
        public OfferPayout() {
30996 amit.gupta 104
 
31380 amit.gupta 105
        }
30996 amit.gupta 106
 
31380 amit.gupta 107
        public OfferPayout(long fofoId, long offerId, long criteriaId, double slabAmount, String serialNumber, double amount, SchemePayoutStatus status, String description, LocalDateTime createTimestamp) {
108
                this.fofoId = fofoId;
109
                this.offerId = offerId;
110
                this.criteriaId = criteriaId;
111
                this.slabAmount = slabAmount;
112
                this.serialNumber = serialNumber;
113
                this.amount = amount;
114
                this.status = status;
115
                this.description = description;
116
                this.createTimestamp = createTimestamp;
117
        }
31008 amit.gupta 118
 
31380 amit.gupta 119
        @Override
120
        public String toString() {
121
                return "OfferPayout{" +
122
                        "id=" + id +
123
                        ", fofoId=" + fofoId +
124
                        ", offerId=" + offerId +
125
                        ", criteriaId=" + criteriaId +
126
                        ", slabAmount=" + slabAmount +
127
                        ", serialNumber='" + serialNumber + '\'' +
128
                        ", amount=" + amount +
129
                        ", status=" + status +
130
                        ", description='" + description + '\'' +
131
                        ", inventoryItemId=" + inventoryItemId +
132
                        ", createTimestamp=" + createTimestamp +
133
                        ", rejectTimestamp=" + rejectTimestamp +
134
                        '}';
135
        }
30996 amit.gupta 136
 
31380 amit.gupta 137
        public int getInventoryItemId() {
138
                return inventoryItemId;
139
        }
31008 amit.gupta 140
 
31380 amit.gupta 141
        public void setInventoryItemId(int inventoryItemId) {
142
                this.inventoryItemId = inventoryItemId;
143
        }
31008 amit.gupta 144
 
31380 amit.gupta 145
        @Override
146
        public boolean equals(Object o) {
147
                if (this == o) return true;
148
                if (o == null || getClass() != o.getClass()) return false;
149
                OfferPayout that = (OfferPayout) o;
150
                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);
151
        }
31008 amit.gupta 152
 
31380 amit.gupta 153
        @Override
154
        public int hashCode() {
155
                return Objects.hash(id, fofoId, offerId, criteriaId, slabAmount, serialNumber, amount, status, description, inventoryItemId, createTimestamp, rejectTimestamp);
156
        }
31008 amit.gupta 157
 
31380 amit.gupta 158
        public LocalDateTime getCreateTimestamp() {
159
                return createTimestamp;
160
        }
30652 amit.gupta 161
 
31380 amit.gupta 162
        public void setCreateTimestamp(LocalDateTime createTimestamp) {
163
                this.createTimestamp = createTimestamp;
164
        }
30652 amit.gupta 165
 
31380 amit.gupta 166
        public LocalDateTime getRejectTimestamp() {
167
                return rejectTimestamp;
168
        }
30996 amit.gupta 169
 
31380 amit.gupta 170
        public void setRejectTimestamp(LocalDateTime rejectTimestamp) {
171
                this.rejectTimestamp = rejectTimestamp;
172
        }
30996 amit.gupta 173
 
31380 amit.gupta 174
        public long getId() {
175
                return id;
176
        }
30996 amit.gupta 177
 
31380 amit.gupta 178
        public void setId(long id) {
179
                this.id = id;
180
        }
30652 amit.gupta 181
 
31380 amit.gupta 182
        public long getFofoId() {
183
                return fofoId;
184
        }
30652 amit.gupta 185
 
31380 amit.gupta 186
        public void setFofoId(long fofoId) {
187
                this.fofoId = fofoId;
188
        }
30652 amit.gupta 189
 
31380 amit.gupta 190
        public long getOfferId() {
191
                return offerId;
192
        }
30652 amit.gupta 193
 
31380 amit.gupta 194
        public void setOfferId(long offerId) {
195
                this.offerId = offerId;
196
        }
30652 amit.gupta 197
 
31380 amit.gupta 198
        public long getCriteriaId() {
199
                return criteriaId;
200
        }
30652 amit.gupta 201
 
31380 amit.gupta 202
        public void setCriteriaId(long criteriaId) {
203
                this.criteriaId = criteriaId;
204
        }
30652 amit.gupta 205
 
31380 amit.gupta 206
        public double getSlabAmount() {
207
                return slabAmount;
208
        }
30652 amit.gupta 209
 
31380 amit.gupta 210
        public void setSlabAmount(double slabAmount) {
211
                this.slabAmount = slabAmount;
212
        }
30652 amit.gupta 213
 
31380 amit.gupta 214
        public String getSerialNumber() {
215
                return serialNumber;
216
        }
30652 amit.gupta 217
 
31380 amit.gupta 218
        public void setSerialNumber(String serialNumber) {
219
                this.serialNumber = serialNumber;
220
        }
30652 amit.gupta 221
 
31380 amit.gupta 222
        public double getAmount() {
223
                return amount;
224
        }
30652 amit.gupta 225
 
31380 amit.gupta 226
        public void setAmount(double amount) {
227
                this.amount = amount;
228
        }
30652 amit.gupta 229
 
31380 amit.gupta 230
        public SchemePayoutStatus getStatus() {
231
                return status;
232
        }
30652 amit.gupta 233
 
31380 amit.gupta 234
        public void setStatus(SchemePayoutStatus status) {
235
                this.status = status;
236
        }
30652 amit.gupta 237
 
31380 amit.gupta 238
        public String getDescription() {
239
                return description;
240
        }
30652 amit.gupta 241
 
31380 amit.gupta 242
        public void setDescription(String description) {
243
                this.description = description;
244
        }
30652 amit.gupta 245
}