Subversion Repositories SmartDukaan

Rev

Rev 31860 | Rev 34697 | 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
31860 tejbeer 83
@Table(name = "catalog.scheme")
25503 amit.gupta 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
 
32310 amit.gupta 147
	//Dummy hardcode
148
	@Transient
149
	private int target;
150
 
151
	public int getTarget() {
152
		return target;
153
	}
154
 
155
	public void setTarget(int target) {
156
		this.target = target;
157
	}
158
 
26679 amit.gupta 159
	@Column
26685 amit.gupta 160
	private boolean cashback;
26679 amit.gupta 161
 
22859 ashik.ali 162
	@Transient
163
	private Set<Integer> retailerIds = new HashSet<>();
30896 amit.gupta 164
 
27388 amit.gupta 165
	@Transient
166
	private String amountModel;
30896 amit.gupta 167
 
28653 amit.gupta 168
	@Transient
169
	private float schemeValue;
25503 amit.gupta 170
 
28653 amit.gupta 171
	public float getSchemeValue() {
172
		return schemeValue;
173
	}
174
 
175
	public void setSchemeValue(float schemeValue) {
176
		this.schemeValue = schemeValue;
177
	}
178
 
30454 amit.gupta 179
	@Column(name = "partner_type")
25503 amit.gupta 180
	@Enumerated(EnumType.STRING)
181
	private PartnerType partnerType;
182
 
30454 amit.gupta 183
	@Override
184
	public String toString() {
31651 tejbeer 185
		return "Scheme{" + "id=" + id + ", name='" + name + '\'' + ", description='" + description + '\'' + ", type="
186
				+ type + ", amountType=" + amountType + ", gstReversal=" + basePlusGstCalc + ", amount=" + amount
187
				+ ", startDateTime=" + startDateTime + ", endDateTime=" + endDateTime + ", createTimestamp="
188
				+ createTimestamp + ", activeTimestamp=" + activeTimestamp + ", expireTimestamp=" + expireTimestamp
189
				+ ", createdBy=" + createdBy + ", cashback=" + cashback + ", retailerIds=" + retailerIds
190
				+ ", amountModel='" + amountModel + '\'' + ", schemeValue=" + schemeValue + ", partnerType="
191
				+ partnerType + ", catalogStringMap=" + catalogStringMap + '}';
30454 amit.gupta 192
	}
193
 
194
	@Override
195
	public boolean equals(Object o) {
31651 tejbeer 196
		if (this == o)
197
			return true;
198
		if (o == null || getClass() != o.getClass())
199
			return false;
30454 amit.gupta 200
		Scheme scheme = (Scheme) o;
31651 tejbeer 201
		return id == scheme.id && basePlusGstCalc == scheme.basePlusGstCalc && Float.compare(scheme.amount, amount) == 0
202
				&& createdBy == scheme.createdBy && cashback == scheme.cashback
203
				&& Float.compare(scheme.schemeValue, schemeValue) == 0 && Objects.equals(name, scheme.name)
204
				&& Objects.equals(description, scheme.description) && type == scheme.type
205
				&& amountType == scheme.amountType && Objects.equals(startDateTime, scheme.startDateTime)
206
				&& Objects.equals(endDateTime, scheme.endDateTime)
207
				&& Objects.equals(createTimestamp, scheme.createTimestamp)
208
				&& Objects.equals(activeTimestamp, scheme.activeTimestamp)
209
				&& Objects.equals(expireTimestamp, scheme.expireTimestamp)
210
				&& Objects.equals(retailerIds, scheme.retailerIds) && Objects.equals(amountModel, scheme.amountModel)
211
				&& partnerType == scheme.partnerType && Objects.equals(catalogStringMap, scheme.catalogStringMap);
30454 amit.gupta 212
	}
213
 
214
	@Override
215
	public int hashCode() {
31651 tejbeer 216
		return Objects.hash(id, name, description, type, amountType, basePlusGstCalc, amount, startDateTime,
217
				endDateTime, createTimestamp, activeTimestamp, expireTimestamp, createdBy, cashback, retailerIds,
218
				amountModel, schemeValue, partnerType, catalogStringMap);
30454 amit.gupta 219
	}
220
 
22859 ashik.ali 221
	@Transient
30121 amit.gupta 222
	private Map<Integer, String> catalogStringMap = new HashMap<>();
25503 amit.gupta 223
 
22600 ashik.ali 224
	public int getId() {
225
		return id;
226
	}
25503 amit.gupta 227
 
22600 ashik.ali 228
	public void setId(int id) {
229
		this.id = id;
230
	}
25503 amit.gupta 231
 
27388 amit.gupta 232
	public String getAmountModel() {
233
		return amountModel;
234
	}
235
 
236
	public void setAmountModel(String amountModel) {
237
		this.amountModel = amountModel;
238
	}
239
 
22653 ashik.ali 240
	public String getName() {
241
		return name;
22600 ashik.ali 242
	}
25503 amit.gupta 243
 
22653 ashik.ali 244
	public void setName(String name) {
245
		this.name = name;
22600 ashik.ali 246
	}
25503 amit.gupta 247
 
22653 ashik.ali 248
	public String getDescription() {
249
		return description;
22600 ashik.ali 250
	}
25503 amit.gupta 251
 
22653 ashik.ali 252
	public void setDescription(String description) {
253
		this.description = description;
22600 ashik.ali 254
	}
25503 amit.gupta 255
 
26685 amit.gupta 256
	public boolean isCashback() {
257
		return cashback;
26679 amit.gupta 258
	}
259
 
26685 amit.gupta 260
	public void setCashback(boolean cashback) {
261
		this.cashback = cashback;
26679 amit.gupta 262
	}
263
 
22653 ashik.ali 264
	public SchemeType getType() {
265
		return type;
266
	}
25503 amit.gupta 267
 
22653 ashik.ali 268
	public void setType(SchemeType type) {
269
		this.type = type;
270
	}
25503 amit.gupta 271
 
23527 ashik.ali 272
	public AmountType getAmountType() {
22600 ashik.ali 273
		return amountType;
274
	}
25503 amit.gupta 275
 
23527 ashik.ali 276
	public void setAmountType(AmountType amountType) {
22600 ashik.ali 277
		this.amountType = amountType;
278
	}
25503 amit.gupta 279
 
22600 ashik.ali 280
	public float getAmount() {
281
		return amount;
282
	}
25503 amit.gupta 283
 
22600 ashik.ali 284
	public void setAmount(float amount) {
285
		this.amount = amount;
286
	}
25503 amit.gupta 287
 
23019 ashik.ali 288
	public LocalDateTime getStartDateTime() {
289
		return startDateTime;
22600 ashik.ali 290
	}
25503 amit.gupta 291
 
23019 ashik.ali 292
	public void setStartDateTime(LocalDateTime startDateTime) {
293
		this.startDateTime = startDateTime;
22600 ashik.ali 294
	}
25503 amit.gupta 295
 
23019 ashik.ali 296
	public LocalDateTime getEndDateTime() {
297
		return endDateTime;
22653 ashik.ali 298
	}
25503 amit.gupta 299
 
23019 ashik.ali 300
	public void setEndDateTime(LocalDateTime endDateTime) {
301
		this.endDateTime = endDateTime;
22653 ashik.ali 302
	}
25503 amit.gupta 303
 
22859 ashik.ali 304
	public LocalDateTime getCreateTimestamp() {
305
		return createTimestamp;
22600 ashik.ali 306
	}
25503 amit.gupta 307
 
22859 ashik.ali 308
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
309
		this.createTimestamp = createTimestamp;
22600 ashik.ali 310
	}
25503 amit.gupta 311
 
22600 ashik.ali 312
	public int getCreatedBy() {
313
		return createdBy;
314
	}
25503 amit.gupta 315
 
22600 ashik.ali 316
	public void setCreatedBy(int createdBy) {
317
		this.createdBy = createdBy;
318
	}
25503 amit.gupta 319
 
22653 ashik.ali 320
	public LocalDateTime getActiveTimestamp() {
321
		return activeTimestamp;
22600 ashik.ali 322
	}
25503 amit.gupta 323
 
22653 ashik.ali 324
	public void setActiveTimestamp(LocalDateTime activeTimestamp) {
325
		this.activeTimestamp = activeTimestamp;
22600 ashik.ali 326
	}
25503 amit.gupta 327
 
22653 ashik.ali 328
	public LocalDateTime getExpireTimestamp() {
329
		return expireTimestamp;
330
	}
25503 amit.gupta 331
 
22653 ashik.ali 332
	public void setExpireTimestamp(LocalDateTime expireTimestamp) {
333
		this.expireTimestamp = expireTimestamp;
334
	}
25503 amit.gupta 335
 
336
	public String getFormattedStartDateTime() {
337
		if (startDateTime == null) {
22859 ashik.ali 338
			return null;
339
		}
24402 amit.gupta 340
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
23019 ashik.ali 341
		return startDateTime.format(formatter);
25503 amit.gupta 342
	}
343
 
344
	public String getFormattedEndDateTime() {
345
		if (endDateTime == null) {
22859 ashik.ali 346
			return null;
347
		}
24402 amit.gupta 348
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
23019 ashik.ali 349
		return endDateTime.format(formatter);
25503 amit.gupta 350
	}
351
 
352
	public String getFormattedCreateTimestamp() {
353
		if (createTimestamp == null) {
22859 ashik.ali 354
			return null;
355
		}
24402 amit.gupta 356
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 357
		return createTimestamp.format(formatter);
25503 amit.gupta 358
	}
359
 
360
	public String getFormattedActiveTimestamp() {
361
		if (activeTimestamp == null) {
22859 ashik.ali 362
			return null;
363
		}
24402 amit.gupta 364
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 365
		return activeTimestamp.format(formatter);
25503 amit.gupta 366
	}
367
 
368
	public String getFormattedExpireTimestamp() {
369
		if (expireTimestamp == null) {
22859 ashik.ali 370
			return null;
371
		}
24402 amit.gupta 372
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
22859 ashik.ali 373
		return expireTimestamp.format(formatter);
25503 amit.gupta 374
	}
375
 
22859 ashik.ali 376
	public Set<Integer> getRetailerIds() {
377
		return retailerIds;
378
	}
25503 amit.gupta 379
 
22859 ashik.ali 380
	public void setRetailerIds(Set<Integer> retailerIds) {
381
		this.retailerIds = retailerIds;
382
	}
25503 amit.gupta 383
 
384
	public String getRetailerIdsString() {
22859 ashik.ali 385
		Set<String> stringRetailerIds = new HashSet<>();
25503 amit.gupta 386
		if (!retailerIds.isEmpty()) {
387
			for (int retailerId : retailerIds) {
22859 ashik.ali 388
				stringRetailerIds.add(String.valueOf(retailerId));
389
			}
390
		}
391
		return String.join(", ", stringRetailerIds);
392
	}
25503 amit.gupta 393
 
30454 amit.gupta 394
	public boolean isBasePlusGstCalc() {
395
		return basePlusGstCalc;
396
	}
397
 
398
	public void setBasePlusGstCalc(boolean gstReversal) {
399
		this.basePlusGstCalc = gstReversal;
400
	}
401
 
30121 amit.gupta 402
	public Map<Integer, String> getCatalogStringMap() {
403
		return catalogStringMap;
22859 ashik.ali 404
	}
25503 amit.gupta 405
 
30121 amit.gupta 406
	public void setCatalogStringMap(Map<Integer, String> catalogStringMap) {
407
		this.catalogStringMap = catalogStringMap;
22859 ashik.ali 408
	}
25503 amit.gupta 409
 
30640 amit.gupta 410
	public boolean isWithinRange(LocalDateTime testDate) {
411
		return !(testDate.isBefore(this.startDateTime) || testDate.isAfter(endDateTime));
412
	}
22600 ashik.ali 413
}