Subversion Repositories SmartDukaan

Rev

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