Subversion Repositories SmartDukaan

Rev

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