Subversion Repositories SmartDukaan

Rev

Rev 31352 | Rev 31382 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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