Subversion Repositories SmartDukaan

Rev

Rev 31170 | Rev 31651 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22600 ashik.ali 1
package com.spice.profitmandi.dao.entity.catalog;
2
 
30121 amit.gupta 3
import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
4
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
5
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
6
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
7
 
8
import javax.persistence.*;
22600 ashik.ali 9
import java.io.Serializable;
10
import java.time.LocalDateTime;
22859 ashik.ali 11
import java.time.format.DateTimeFormatter;
30454 amit.gupta 12
import java.util.*;
22600 ashik.ali 13
 
14
/**
15
 * This class basically contains scheme details
30896 amit.gupta 16
 *
22600 ashik.ali 17
 * @author ashikali
18
 */
31170 amit.gupta 19
@NamedQueries({
20
		@NamedQuery(name = "scheme.selectSchemesByRetailerIdsSchemeIds", query = "select sr.schemeId from" +
21
				" SchemeRegion sr join PartnerRegion pr on pr.regionId=sr.regionId where pr.fofoId in :fofoIds and sr.schemeId in :schemeIds"),
30896 amit.gupta 22
 
31170 amit.gupta 23
		@NamedQuery(name = "Scheme.selectSchemeByModelsPartnerTypeFofoId", query = "select s from Scheme s" +
24
				" join SchemeItem si on si.schemeId = s.id" +
25
				" join SchemeRegion sr on sr.schemeId = s.id" +
26
				" join PartnerRegion pr on pr.regionId=sr.regionId" +
27
				" where pr.fofoId in :fofoIds and s.partnerType in :partnerTypes" +
28
				" and si.catalogId in :catalogIds" +
29
				" and :onDate between s.startDateTime and s.endDateTime" +
30
				//" and s.endDateTime >= :onDate" +
31441 amit.gupta 31
				" and s.activeTimestamp is not null")
32
 
33
		/*,
34
		@NamedQuery(name="scheme.getImeiMarginsPaidOnBillingMonth", query= "select new com.spice.profitmandi.dao.repository.catalog.ImeiMarginModel(" +
35
                ") from LineItemImei li1" +
36
                "         left join LineItemImei li2 on (li1.serialNumber = li2.serialNumber and li1.id < li2.id)" +
37
                "         join LineItem li on li.id = li1.lineItemId" +
38
                "         join Order o on o.id = li.orderId" +
39
                "         join Item ci on li.itemId = ci.id" +
40
                "         join SchemeItem si on si.catalogId = ci.catalogItemId" +
41
                "         join Scheme s1 on s1.id = si.schemeId" +
42
                "         join SchemeRegion sr on sr.schemeId = s1.id" +
43
                "         join PartnerRegion pr on (pr.regionId = sr.regionId and pr.fofoId in (0, o.id))" +
44
                "         left join PartnerTypeChange ptc on ptc.fofoId = o.retailerId" +
45
                "         left join PartnerTypeChange ptc2 on (ptc2.fofoId = ptc.fofoId and ptc.createTimestamp < ptc2.createTimestamp)" +
46
                "where li2.id is null" +
47
                "  and ptc2.createTimestamp is null" +
48
                "  and o.billing_timestamp between :startDate and :endDate" +
49
                "  and '2022-12-01' between s1.start_date_time and s1.end_date_time" +
50
                "  and ((ptc.partnerType is null and s1.partner_type in ('ALL', 'NEW'))" +
51
                "    or s1.partnerType in (ptc.partnerType, 'ALL'))" +
52
                "  and s1.activeTimestamp is not null" +
53
                "  and s1.amountType = 'PERCENTAGE'" +
54
                "group by li.serial_number) as set1\n" +
55
				"")*/
56
 
57
 
31170 amit.gupta 58
})
59
 
30896 amit.gupta 60
@NamedNativeQueries({
61
		@NamedNativeQuery(name = "scheme.selectMissedActivationSale",
62
				query = "select cs.id as scheme_id, ai.serial_number, sr.order_id, ii.id as inventory_item_id, ai.activation_timestamp" +
63
						" from fofo.activated_imei ai " +
64
						"   join fofo.inventory_item ii on ai.serial_number = ii.serial_number " +
65
						"   join catalog.item i on i.id = ii.item_id " +
66
						"   join catalog.scheme cs on (date(ai.activation_timestamp) between cs.start_date_time and cs.end_date_time) " +
67
						"   join fofo.scheme_item si on (si.scheme_id = cs.id and i.catalog_item_id = si.catalog_id) " +
68
						"	join fofo.scan_record sr on (sr.inventory_item_id = ii.id)" +
69
						"	left join fofo.scheme_in_out sio on (sio.scheme_id = cs.id and sio.inventory_item_id = ii.id) " +
70
						" where cs.active_timestamp is not null " +
71
						" and cs.type in ('SPECIAL_SUPPORT', 'ACTIVATION')" +
72
						" and sr.type = 'SALE'" +
73
						" and (sio.id is null or sio.status='REJECTED') " +
74
						" and ai.checked = false", resultSetMapping = "missedActivationSaleMapping")
75
})
76
 
77
@SqlResultSetMappings({
78
		@SqlResultSetMapping(name = "missedActivationSaleMapping", classes = {
79
				@ConstructorResult(targetClass = SchemesImeisModel.class, columns = {
80
						@ColumnResult(name = "serial_number", type = String.class),
81
						@ColumnResult(name = "activation_timestamp", type = LocalDateTime.class),
82
						@ColumnResult(name = "order_id", type = Integer.class),
83
						@ColumnResult(name = "inventory_item_id", type = Integer.class),
84
						@ColumnResult(name = "scheme_id", type = Integer.class),
85
				})
86
		})})
22600 ashik.ali 87
@Entity
25503 amit.gupta 88
@Table(name = "catalog.scheme", schema = "catalog")
89
public class Scheme implements Serializable {
90
 
91
	public PartnerType getPartnerType() {
92
		return partnerType;
93
	}
94
 
95
	public void setPartnerType(PartnerType partnerType) {
96
		this.partnerType = partnerType;
97
	}
98
 
22600 ashik.ali 99
	private static final long serialVersionUID = 1L;
25503 amit.gupta 100
 
22600 ashik.ali 101
	public Scheme() {
102
	}
25503 amit.gupta 103
 
22600 ashik.ali 104
	@Id
25503 amit.gupta 105
	@Column(name = "id")
22600 ashik.ali 106
	@GeneratedValue(strategy = GenerationType.IDENTITY)
107
	private int id;
25503 amit.gupta 108
 
22653 ashik.ali 109
	@Column(name = "name")
110
	private String name;
25503 amit.gupta 111
 
22653 ashik.ali 112
	@Column(name = "description")
113
	private String description;
25503 amit.gupta 114
 
22653 ashik.ali 115
	@Column(name = "type")
23297 ashik.ali 116
	@Enumerated(EnumType.STRING)
22653 ashik.ali 117
	private SchemeType type;
25503 amit.gupta 118
 
22600 ashik.ali 119
	@Column(name = "amount_type")
23297 ashik.ali 120
	@Enumerated(EnumType.STRING)
23527 ashik.ali 121
	private AmountType amountType;
25503 amit.gupta 122
 
30454 amit.gupta 123
	@Column(name = "base_plus_gst_calc")
124
	private boolean basePlusGstCalc;
125
 
22600 ashik.ali 126
	@Column(name = "amount")
127
	private float amount;
25503 amit.gupta 128
 
22600 ashik.ali 129
	@Convert(converter = LocalDateTimeAttributeConverter.class)
23019 ashik.ali 130
	@Column(name = "start_date_time")
131
	private LocalDateTime startDateTime = LocalDateTime.now();
25503 amit.gupta 132
 
22600 ashik.ali 133
	@Convert(converter = LocalDateTimeAttributeConverter.class)
23019 ashik.ali 134
	@Column(name = "end_date_time")
135
	private LocalDateTime endDateTime = LocalDateTime.now();
25503 amit.gupta 136
 
22608 ashik.ali 137
	@Convert(converter = LocalDateTimeAttributeConverter.class)
22600 ashik.ali 138
	@Column(name = "create_timestamp")
22859 ashik.ali 139
	private LocalDateTime createTimestamp = LocalDateTime.now();
25503 amit.gupta 140
 
22653 ashik.ali 141
	@Convert(converter = LocalDateTimeAttributeConverter.class)
142
	@Column(name = "active_timestamp")
143
	private LocalDateTime activeTimestamp = null;
25503 amit.gupta 144
 
22653 ashik.ali 145
	@Convert(converter = LocalDateTimeAttributeConverter.class)
22702 ashik.ali 146
	@Column(name = "expire_timestamp")
22653 ashik.ali 147
	private LocalDateTime expireTimestamp = null;
25503 amit.gupta 148
 
22600 ashik.ali 149
	@Column(name = "created_by")
150
	private int createdBy;
25503 amit.gupta 151
 
26679 amit.gupta 152
	@Column
26685 amit.gupta 153
	private boolean cashback;
26679 amit.gupta 154
 
22859 ashik.ali 155
	@Transient
156
	private Set<Integer> retailerIds = new HashSet<>();
30896 amit.gupta 157
 
27388 amit.gupta 158
	@Transient
159
	private String amountModel;
30896 amit.gupta 160
 
28653 amit.gupta 161
	@Transient
162
	private float schemeValue;
25503 amit.gupta 163
 
30896 amit.gupta 164
 
28653 amit.gupta 165
	public float getSchemeValue() {
166
		return schemeValue;
167
	}
168
 
169
	public void setSchemeValue(float schemeValue) {
170
		this.schemeValue = schemeValue;
171
	}
172
 
30454 amit.gupta 173
	@Column(name = "partner_type")
25503 amit.gupta 174
	@Enumerated(EnumType.STRING)
175
	private PartnerType partnerType;
176
 
30454 amit.gupta 177
 
178
	@Override
179
	public String toString() {
180
		return "Scheme{" +
181
				"id=" + id +
182
				", name='" + name + '\'' +
183
				", description='" + description + '\'' +
184
				", type=" + type +
185
				", amountType=" + amountType +
186
				", gstReversal=" + basePlusGstCalc +
187
				", amount=" + amount +
188
				", startDateTime=" + startDateTime +
189
				", endDateTime=" + endDateTime +
190
				", createTimestamp=" + createTimestamp +
191
				", activeTimestamp=" + activeTimestamp +
192
				", expireTimestamp=" + expireTimestamp +
193
				", createdBy=" + createdBy +
194
				", cashback=" + cashback +
195
				", retailerIds=" + retailerIds +
196
				", amountModel='" + amountModel + '\'' +
197
				", schemeValue=" + schemeValue +
198
				", partnerType=" + partnerType +
199
				", catalogStringMap=" + catalogStringMap +
200
				'}';
201
	}
202
 
203
	@Override
204
	public boolean equals(Object o) {
205
		if (this == o) return true;
206
		if (o == null || getClass() != o.getClass()) return false;
207
		Scheme scheme = (Scheme) o;
208
		return id == scheme.id && basePlusGstCalc == scheme.basePlusGstCalc && Float.compare(scheme.amount, amount) == 0 && createdBy == scheme.createdBy && cashback == scheme.cashback && Float.compare(scheme.schemeValue, schemeValue) == 0 && Objects.equals(name, scheme.name) && Objects.equals(description, scheme.description) && type == scheme.type && amountType == scheme.amountType && Objects.equals(startDateTime, scheme.startDateTime) && Objects.equals(endDateTime, scheme.endDateTime) && Objects.equals(createTimestamp, scheme.createTimestamp) && Objects.equals(activeTimestamp, scheme.activeTimestamp) && Objects.equals(expireTimestamp, scheme.expireTimestamp) && Objects.equals(retailerIds, scheme.retailerIds) && Objects.equals(amountModel, scheme.amountModel) && partnerType == scheme.partnerType && Objects.equals(catalogStringMap, scheme.catalogStringMap);
209
	}
210
 
211
	@Override
212
	public int hashCode() {
213
		return Objects.hash(id, name, description, type, amountType, basePlusGstCalc, amount, startDateTime, endDateTime, createTimestamp, activeTimestamp, expireTimestamp, createdBy, cashback, retailerIds, amountModel, schemeValue, partnerType, catalogStringMap);
214
	}
215
 
22859 ashik.ali 216
	@Transient
30121 amit.gupta 217
	private Map<Integer, String> catalogStringMap = new HashMap<>();
25503 amit.gupta 218
 
22600 ashik.ali 219
	public int getId() {
220
		return id;
221
	}
25503 amit.gupta 222
 
22600 ashik.ali 223
	public void setId(int id) {
224
		this.id = id;
225
	}
25503 amit.gupta 226
 
30896 amit.gupta 227
 
27388 amit.gupta 228
	public String getAmountModel() {
229
		return amountModel;
230
	}
231
 
232
	public void setAmountModel(String amountModel) {
233
		this.amountModel = amountModel;
234
	}
235
 
22653 ashik.ali 236
	public String getName() {
237
		return name;
22600 ashik.ali 238
	}
25503 amit.gupta 239
 
22653 ashik.ali 240
	public void setName(String name) {
241
		this.name = name;
22600 ashik.ali 242
	}
25503 amit.gupta 243
 
22653 ashik.ali 244
	public String getDescription() {
245
		return description;
22600 ashik.ali 246
	}
25503 amit.gupta 247
 
22653 ashik.ali 248
	public void setDescription(String description) {
249
		this.description = description;
22600 ashik.ali 250
	}
25503 amit.gupta 251
 
26685 amit.gupta 252
	public boolean isCashback() {
253
		return cashback;
26679 amit.gupta 254
	}
255
 
26685 amit.gupta 256
	public void setCashback(boolean cashback) {
257
		this.cashback = cashback;
26679 amit.gupta 258
	}
259
 
22653 ashik.ali 260
	public SchemeType getType() {
261
		return type;
262
	}
25503 amit.gupta 263
 
22653 ashik.ali 264
	public void setType(SchemeType type) {
265
		this.type = type;
266
	}
25503 amit.gupta 267
 
23527 ashik.ali 268
	public AmountType getAmountType() {
22600 ashik.ali 269
		return amountType;
270
	}
25503 amit.gupta 271
 
23527 ashik.ali 272
	public void setAmountType(AmountType amountType) {
22600 ashik.ali 273
		this.amountType = amountType;
274
	}
25503 amit.gupta 275
 
22600 ashik.ali 276
	public float getAmount() {
277
		return amount;
278
	}
25503 amit.gupta 279
 
22600 ashik.ali 280
	public void setAmount(float amount) {
281
		this.amount = amount;
282
	}
25503 amit.gupta 283
 
23019 ashik.ali 284
	public LocalDateTime getStartDateTime() {
285
		return startDateTime;
22600 ashik.ali 286
	}
25503 amit.gupta 287
 
23019 ashik.ali 288
	public void setStartDateTime(LocalDateTime startDateTime) {
289
		this.startDateTime = startDateTime;
22600 ashik.ali 290
	}
25503 amit.gupta 291
 
23019 ashik.ali 292
	public LocalDateTime getEndDateTime() {
293
		return endDateTime;
22653 ashik.ali 294
	}
25503 amit.gupta 295
 
23019 ashik.ali 296
	public void setEndDateTime(LocalDateTime endDateTime) {
297
		this.endDateTime = endDateTime;
22653 ashik.ali 298
	}
25503 amit.gupta 299
 
22859 ashik.ali 300
	public LocalDateTime getCreateTimestamp() {
301
		return createTimestamp;
22600 ashik.ali 302
	}
25503 amit.gupta 303
 
22859 ashik.ali 304
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
305
		this.createTimestamp = createTimestamp;
22600 ashik.ali 306
	}
25503 amit.gupta 307
 
22600 ashik.ali 308
	public int getCreatedBy() {
309
		return createdBy;
310
	}
25503 amit.gupta 311
 
22600 ashik.ali 312
	public void setCreatedBy(int createdBy) {
313
		this.createdBy = createdBy;
314
	}
25503 amit.gupta 315
 
22653 ashik.ali 316
	public LocalDateTime getActiveTimestamp() {
317
		return activeTimestamp;
22600 ashik.ali 318
	}
25503 amit.gupta 319
 
22653 ashik.ali 320
	public void setActiveTimestamp(LocalDateTime activeTimestamp) {
321
		this.activeTimestamp = activeTimestamp;
22600 ashik.ali 322
	}
25503 amit.gupta 323
 
22653 ashik.ali 324
	public LocalDateTime getExpireTimestamp() {
325
		return expireTimestamp;
326
	}
25503 amit.gupta 327
 
22653 ashik.ali 328
	public void setExpireTimestamp(LocalDateTime expireTimestamp) {
329
		this.expireTimestamp = expireTimestamp;
330
	}
25503 amit.gupta 331
 
332
	public String getFormattedStartDateTime() {
333
		if (startDateTime == null) {
22859 ashik.ali 334
			return null;
335
		}
24402 amit.gupta 336
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
23019 ashik.ali 337
		return startDateTime.format(formatter);
25503 amit.gupta 338
	}
339
 
340
	public String getFormattedEndDateTime() {
341
		if (endDateTime == null) {
22859 ashik.ali 342
			return null;
343
		}
24402 amit.gupta 344
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
23019 ashik.ali 345
		return endDateTime.format(formatter);
25503 amit.gupta 346
	}
347
 
348
	public String getFormattedCreateTimestamp() {
349
		if (createTimestamp == null) {
22859 ashik.ali 350
			return null;
351
		}
24402 amit.gupta 352
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 353
		return createTimestamp.format(formatter);
25503 amit.gupta 354
	}
355
 
356
	public String getFormattedActiveTimestamp() {
357
		if (activeTimestamp == null) {
22859 ashik.ali 358
			return null;
359
		}
24402 amit.gupta 360
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 361
		return activeTimestamp.format(formatter);
25503 amit.gupta 362
	}
363
 
364
	public String getFormattedExpireTimestamp() {
365
		if (expireTimestamp == null) {
22859 ashik.ali 366
			return null;
367
		}
24402 amit.gupta 368
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 369
		return expireTimestamp.format(formatter);
25503 amit.gupta 370
	}
371
 
22859 ashik.ali 372
	public Set<Integer> getRetailerIds() {
373
		return retailerIds;
374
	}
25503 amit.gupta 375
 
22859 ashik.ali 376
	public void setRetailerIds(Set<Integer> retailerIds) {
377
		this.retailerIds = retailerIds;
378
	}
25503 amit.gupta 379
 
380
	public String getRetailerIdsString() {
22859 ashik.ali 381
		Set<String> stringRetailerIds = new HashSet<>();
25503 amit.gupta 382
		if (!retailerIds.isEmpty()) {
383
			for (int retailerId : retailerIds) {
22859 ashik.ali 384
				stringRetailerIds.add(String.valueOf(retailerId));
385
			}
386
		}
387
		return String.join(", ", stringRetailerIds);
388
	}
25503 amit.gupta 389
 
30454 amit.gupta 390
 
391
	public boolean isBasePlusGstCalc() {
392
		return basePlusGstCalc;
393
	}
394
 
395
	public void setBasePlusGstCalc(boolean gstReversal) {
396
		this.basePlusGstCalc = gstReversal;
397
	}
398
 
399
 
30121 amit.gupta 400
	public Map<Integer, String> getCatalogStringMap() {
401
		return catalogStringMap;
22859 ashik.ali 402
	}
25503 amit.gupta 403
 
30121 amit.gupta 404
	public void setCatalogStringMap(Map<Integer, String> catalogStringMap) {
405
		this.catalogStringMap = catalogStringMap;
22859 ashik.ali 406
	}
25503 amit.gupta 407
 
30640 amit.gupta 408
	public boolean isWithinRange(LocalDateTime testDate) {
409
		return !(testDate.isBefore(this.startDateTime) || testDate.isAfter(endDateTime));
410
	}
22600 ashik.ali 411
}