Subversion Repositories SmartDukaan

Rev

Rev 31139 | Rev 31380 | 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
10
@Table(name = "fofo.offer_payout", schema = "fofo")
11
@NamedQueries({
12
		@NamedQuery(name = "OfferPayout.selectPaidOffers", query = "select new com.spice.profitmandi.service.transaction.InventoryMarginModel("
13
				+ " o.retailerId, li.sgstRate, li.cgstRate, li.igstRate," +
14
				" cast(case when op.createTimestamp between :startDate and :endDate and op.rejectTimestamp is null then op.amount " +
15
				" 			when op.createTimestamp between :startDate and :endDate and op.rejectTimestamp between :startDate and :endDate then 0" +
16
				"			when op.rejectTimestamp between :startDate and :endDate then -op.amount" +
17
				"			else 0 end as float), lii.serialNumber, op.description, o.invoiceNumber, " +
18
				" case when op.rejectTimestamp between :startDate and :endDate then op.rejectTimestamp else op.createTimestamp end)  from "
19
				+ " OfferPayout op join LineItemImei lii on (op.serialNumber=lii.serialNumber) join LineItem li on li.id=lii.lineItemId "
20
				+ " join Order o on (o.retailerId=op.fofoId and o.billingTimestamp is not null and o.id=li.orderId) "
21
				+ " where op.createTimestamp >= :cnDate and ((op.createTimestamp between :startDate and :endDate) or (op.rejectTimestamp between :startDate and :endDate))"
31352 amit.gupta 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
 
24
		@NamedQuery(name = "OfferPayout.getTotalPayoutsByPartnerPeriod", query = "select new com.spice.profitmandi.common.model.OfferPayoutImeiIncomeModel(" +
25
				" ii.id, ii.serialNumber, " +
26
				" case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then max(sr.createTimestamp) end," +
27
				" case when (sr.type='SALE' and o.schemeType != 'SELLIN') then max(sr.createTimestamp)  end, " +
28
				" case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then sum(op.amount)  else 0 end, " +
29
				" case when (sr.type='SALE' and o.schemeType!='SELLIN') then sum(op.amount) else 0 end, " +
30
				" i.catalogItemId, i.brand, i.modelName, i.modelNumber" +
31
				") from OfferPayout op join Offer o on o.id=op.offerId join InventoryItem ii on ii.serialNumber=op.serialNumber and op.fofoId=ii.fofoId" +
32
				" join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
33
				" and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
34
				" where op.rejectTimestamp is null and sr.createTimestamp between :startDate and :endDate" +
35
				" and (:brand is null or i.brand=:brand)" +
36
				" and (:catalogId is null or i.catalogItemId=:catalogId)" +
37
				" and op.fofoId=:fofoId" +
38
				" group by ii.id "),
39
 
40
		@NamedQuery(name = "OfferPayout.getTotalPayoutsByImei", query = "select new com.spice.profitmandi.common.model.OfferPayoutImeiIncomeModel(" +
41
				" ii.id, ii.serialNumber, " +
42
				" max(case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then sr.createTimestamp end)," +
43
				" max(case when (sr.type='SALE' and o.schemeType != 'SELLIN') then sr.createTimestamp  end), " +
44
				" sum(case when (sr.type='PURCHASE' and o.schemeType='SELLIN') then op.amount  else 0 end), " +
45
				" sum(case when (sr.type='SALE' and o.schemeType!='SELLIN') then op.amount else 0 end), " +
46
				" i.catalogItemId, i.brand, i.modelName, i.modelNumber" +
47
				") from OfferPayout op join Offer o on o.id=op.offerId join InventoryItem ii on ii.serialNumber=op.serialNumber and op.fofoId=ii.fofoId" +
48
				" join Item i on i.id=ii.itemId join ScanRecord  sr on sr.inventoryItemId=ii.id " +
49
				" and ((sr.type='PURCHASE' and o.schemeType='SELLIN') or (sr.type='SALE' and o.schemeType!='SELLIN'))" +
50
				" where op.rejectTimestamp is null and ii.serialNumber in :serialNumbers" +
51
				" group by ii.id ")
31008 amit.gupta 52
})
30652 amit.gupta 53
public class OfferPayout {
54
	@Id
55
	@GeneratedValue(strategy = GenerationType.IDENTITY)
56
	private long id;
57
	@Column(name = "fofo_id", nullable = false)
58
	private long fofoId;
59
	@Column(name = "offer_id", nullable = false)
60
	private long offerId;
61
	@Column(name = "criteria_id", nullable = false)
62
	private long criteriaId;
63
	@Column(name = "slab_amount", nullable = false)
64
	private double slabAmount;
65
	@Column(name = "serial_number", nullable = false)
66
	private String serialNumber;
67
	@Column(name = "amount", nullable = false)
68
	private double amount;
69
	@Column(name = "status", nullable = false)
70
	@Enumerated(EnumType.STRING)
71
	private SchemePayoutStatus status;
72
	@Column(name = "description", nullable = false)
73
	private String description;
31008 amit.gupta 74
	@Column(name = "inventory_item_id", nullable = false)
75
	private int inventoryItemId;
30652 amit.gupta 76
 
31008 amit.gupta 77
	@Override
78
	public String toString() {
79
		return "OfferPayout{" +
80
				"id=" + id +
81
				", fofoId=" + fofoId +
82
				", offerId=" + offerId +
83
				", criteriaId=" + criteriaId +
84
				", slabAmount=" + slabAmount +
85
				", serialNumber='" + serialNumber + '\'' +
86
				", amount=" + amount +
87
				", status=" + status +
88
				", description='" + description + '\'' +
89
				", inventoryItemId=" + inventoryItemId +
90
				", createTimestamp=" + createTimestamp +
91
				", rejectTimestamp=" + rejectTimestamp +
92
				'}';
93
	}
30996 amit.gupta 94
 
31008 amit.gupta 95
	public int getInventoryItemId() {
96
		return inventoryItemId;
30996 amit.gupta 97
	}
98
 
31008 amit.gupta 99
	public void setInventoryItemId(int inventoryItemId) {
100
		this.inventoryItemId = inventoryItemId;
101
	}
102
 
30996 amit.gupta 103
	@Override
104
	public boolean equals(Object o) {
105
		if (this == o) return true;
106
		if (o == null || getClass() != o.getClass()) return false;
107
		OfferPayout that = (OfferPayout) o;
31008 amit.gupta 108
		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);
30996 amit.gupta 109
	}
110
 
31008 amit.gupta 111
	@Override
112
	public int hashCode() {
113
		return Objects.hash(id, fofoId, offerId, criteriaId, slabAmount, serialNumber, amount, status, description, inventoryItemId, createTimestamp, rejectTimestamp);
114
	}
115
 
116
	@Column(name = "create_timestamp", nullable = false)
117
	private LocalDateTime createTimestamp;
118
	@Column(name = "reject_timestamp")
119
	private LocalDateTime rejectTimestamp;
120
 
121
	public OfferPayout() {
122
 
123
	}
124
 
30652 amit.gupta 125
	public OfferPayout(long fofoId, long offerId, long criteriaId, double slabAmount, String serialNumber, double amount, SchemePayoutStatus status, String description, LocalDateTime createTimestamp) {
126
		this.fofoId = fofoId;
127
		this.offerId = offerId;
128
		this.criteriaId = criteriaId;
129
		this.slabAmount = slabAmount;
130
		this.serialNumber = serialNumber;
131
		this.amount = amount;
132
		this.status = status;
133
		this.description = description;
134
		this.createTimestamp = createTimestamp;
135
	}
136
 
30996 amit.gupta 137
	public LocalDateTime getCreateTimestamp() {
138
		return createTimestamp;
30652 amit.gupta 139
	}
140
 
30996 amit.gupta 141
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
142
		this.createTimestamp = createTimestamp;
143
	}
144
 
145
	public LocalDateTime getRejectTimestamp() {
146
		return rejectTimestamp;
147
	}
148
 
149
	public void setRejectTimestamp(LocalDateTime rejectTimestamp) {
150
		this.rejectTimestamp = rejectTimestamp;
151
	}
152
 
30652 amit.gupta 153
	public long getId() {
154
		return id;
155
	}
156
 
157
	public void setId(long id) {
158
		this.id = id;
159
	}
160
 
161
	public long getFofoId() {
162
		return fofoId;
163
	}
164
 
165
	public void setFofoId(long fofoId) {
166
		this.fofoId = fofoId;
167
	}
168
 
169
	public long getOfferId() {
170
		return offerId;
171
	}
172
 
173
	public void setOfferId(long offerId) {
174
		this.offerId = offerId;
175
	}
176
 
177
	public long getCriteriaId() {
178
		return criteriaId;
179
	}
180
 
181
	public void setCriteriaId(long criteriaId) {
182
		this.criteriaId = criteriaId;
183
	}
184
 
185
	public double getSlabAmount() {
186
		return slabAmount;
187
	}
188
 
189
	public void setSlabAmount(double slabAmount) {
190
		this.slabAmount = slabAmount;
191
	}
192
 
193
	public String getSerialNumber() {
194
		return serialNumber;
195
	}
196
 
197
	public void setSerialNumber(String serialNumber) {
198
		this.serialNumber = serialNumber;
199
	}
200
 
201
	public double getAmount() {
202
		return amount;
203
	}
204
 
205
	public void setAmount(double amount) {
206
		this.amount = amount;
207
	}
208
 
209
	public SchemePayoutStatus getStatus() {
210
		return status;
211
	}
212
 
213
	public void setStatus(SchemePayoutStatus status) {
214
		this.status = status;
215
	}
216
 
217
	public String getDescription() {
218
		return description;
219
	}
220
 
221
	public void setDescription(String description) {
222
		this.description = description;
223
	}
224
}