Subversion Repositories SmartDukaan

Rev

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