Subversion Repositories SmartDukaan

Rev

Rev 37471 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
26299 amit.gupta 1
package com.spice.profitmandi.dao.entity.fofo;
2
 
30213 amit.gupta 3
import javax.persistence.*;
26299 amit.gupta 4
import java.time.LocalDateTime;
30896 amit.gupta 5
import java.util.Objects;
26299 amit.gupta 6
 
7
@Entity
36255 vikas 8
@Table(name = "fofo.activated_imei")
28825 tejbeer 9
 
10
@NamedQueries({
11
 
12
		@NamedQuery(name = "ActivatedImei.selectActivatedModelGroupByBrand", query = "select new com.spice.profitmandi.dao.model.BrandWiseActivatedModel(li.brand, "
35464 amit 13
				+ "sum(case when ai.activationTimestamp >= :lmsStartDate and ai.activationTimestamp < :mtdStartDate then 1 else 0 end),"
14
				+ "sum(case when ai.activationTimestamp >= :lmsStartDate and ai.activationTimestamp < :mtdStartDate then CAST(li.unitPrice AS int) else 0 end),"
15
				+ "sum(case when ai.activationTimestamp >= :mtdStartDate then 1 else 0 end),"
16
				+ "sum(case when ai.activationTimestamp >= :mtdStartDate then CAST(li.unitPrice AS int) else 0 end), "
17
				+ "sum(case when ai.activationTimestamp >= :lmtdStartDate and ai.activationTimestamp < :lmtdEndDate then 1 else 0 end), "
36255 vikas 18
				+ "sum(case when ai.activationTimestamp >= :lmtdStartDate and ai.activationTimestamp < :lmtdEndDate then CAST(li.unitPrice AS int) else 0 end))"
28825 tejbeer 19
				+ " from ActivatedImei ai join LineItemImeiView lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
35464 amit 20
				+ "	join FofoStore fs on fs.id = o.retailerId where ai.activationTimestamp >= :lmsStartDate and (fs.fofoType = 'FRANCHISE' or fs.fofoType = 'THIRD_PARTY') and fs.id in :fofoIds group by li.brand"),
28825 tejbeer 21
 
29475 amit.gupta 22
		@NamedQuery(name = "ActivatedImei.selectActivatedModelGroupByWarehouse", query = "select new com.spice.profitmandi.dao.model.WarehouseWiseActivatedModel(o.warehouseId, "
35464 amit 23
				+ "sum(case when ai.activationTimestamp >= :lmsStartDate and ai.activationTimestamp < :mtdStartDate then 1 else 0 end),"
24
				+ "sum(case when ai.activationTimestamp >= :lmsStartDate and ai.activationTimestamp < :mtdStartDate then CAST(li.unitPrice AS int) else 0 end),"
25
				+ "sum(case when ai.activationTimestamp >= :mtdStartDate then 1 else 0 end),"
26
				+ "sum(case when ai.activationTimestamp >= :mtdStartDate then CAST(li.unitPrice AS int) else 0 end), "
27
				+ "sum(case when ai.activationTimestamp >= :lmtdStartDate and ai.activationTimestamp < :lmtdEndDate then 1 else 0 end), "
28
				+ "sum(case when ai.activationTimestamp >= :lmtdStartDate and ai.activationTimestamp < :lmtdEndDate then CAST(li.unitPrice AS int) else 0 end))"
28825 tejbeer 29
				+ " from ActivatedImei ai join LineItemImeiView lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
35464 amit 30
				+ " join FofoStore fs on fs.id = o.retailerId where ai.activationTimestamp >= :lmsStartDate and (fs.fofoType = 'FRANCHISE' or fs.fofoType = 'THIRD_PARTY') and li.brand = :brand and fs.id in :fofoIds"
29474 amit.gupta 31
				+ " group by o.warehouseId"),
28825 tejbeer 32
 
33
		@NamedQuery(name = "ActivatedImei.selectWarehouseBrandActivatedItem", query = "select new com.spice.profitmandi.dao.model.WarehouseBrandWiseItemActivatedModel(fs.warehouseId, li.itemId, li.brand,li.modelName,"
34
				+ " li.modelNumber, li.color,"
35464 amit 35
				+ "sum(case when ai.activationTimestamp >= :lmsStartDate and ai.activationTimestamp < :mtdStartDate then 1 else 0 end),"
36
				+ "sum(case when ai.activationTimestamp >= :lmsStartDate and ai.activationTimestamp < :mtdStartDate then CAST(li.unitPrice AS int) else 0 end),"
37
				+ "sum(case when ai.activationTimestamp >= :mtdStartDate then 1 else 0 end),"
38
				+ "sum(case when ai.activationTimestamp >= :mtdStartDate then CAST(li.unitPrice AS int) else 0 end), "
39
				+ "sum(case when ai.activationTimestamp >= :lmtdStartDate and ai.activationTimestamp < :lmtdEndDate then 1 else 0 end), "
40
				+ "sum(case when ai.activationTimestamp >= :lmtdStartDate and ai.activationTimestamp < :lmtdEndDate then CAST(li.unitPrice AS int) else 0 end))"
28825 tejbeer 41
				+ " from ActivatedImei ai join LineItemImeiView lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
35464 amit 42
				+ " join FofoStore fs on fs.id = o.retailerId where ai.activationTimestamp >= :lmsStartDate and (fs.fofoType = 'FRANCHISE' or fs.fofoType = 'THIRD_PARTY') and fs.warehouseId in :warehouseId and li.brand = :brand and fs.id in :fofoIds "
28825 tejbeer 43
				+ " group by li.itemId"),
44
 
45
		@NamedQuery(name = "ActivatedImei.selectActivatedUpdationDate", query = "select new com.spice.profitmandi.dao.model.ActivationImeiUpdationModel(fs.warehouseId,li.brand, "
46
				+ " Max(ai.createTimestamp))"
35466 amit 47
				+ " from ActivatedImei ai join LineItemImei lim on ai.serialNumber = lim.serialNumber join LineItem li on li.id = lim.lineItemId join Order o on o.id = li.orderId "
48
				+ "	join FofoStore fs on fs.id = o.retailerId where ai.createTimestamp >= :startDate group by li.brand,fs.warehouseId"),
28825 tejbeer 49
 
30344 amit.gupta 50
		@NamedQuery(name = "ActivatedImei.selectImeiActivationByBrand", query = "select new com.spice.profitmandi.dao.model.ImeiActivationTimestampModel(limei.serialNumber, ai.activationTimestamp) "
36261 amit 51
				+ " from Order o join LineItem  li on o.id=li.orderId join LineItemImei  limei on li.id=limei.lineItemId join FofoStore fs on fs.id=o.retailerId left join ActivatedImei ai on limei.serialNumber = ai.serialNumber "
52
				+ "	where (ai.createTimestamp is null or ai.createTimestamp < :daysBeforeToday) and li.brand = :brand and ai.activationTimestamp is null and fs.internal = false and o.billingTimestamp > :billingStartDate"
37471 amit 53
				+ " and o.billingTimestamp < :billedBefore"
37408 amit 54
				+ " and not exists (select 1 from FofoLineItem fli where fli.serialNumber = limei.serialNumber)"
55
				+ " and limei.serialNumber is not null and limei.serialNumber <> ''"),
29452 manish 56
 
36259 amit 57
		@NamedQuery(name = "ActivatedImei.selectImeiActivationByBrandTertiary", query = "select new com.spice.profitmandi.dao.model.ImeiActivationTimestampModel(fli.serialNumber, ai.activationTimestamp) "
36261 amit 58
				+ " from FofoOrder fo join FofoOrderItem  foi on fo.id=foi.orderId join FofoLineItem  fli on fli.fofoOrderItemId=foi.id "
36259 amit 59
				+ " join Item ci on ci.id=foi.itemId join FofoStore fs on fs.id=fo.fofoId left join ActivatedImei ai on fli.serialNumber = ai.serialNumber "
37408 amit 60
				+ "	where (ai.createTimestamp is null or ai.createTimestamp < :daysBeforeToday) and ci.brand = :brand and ai.activationTimestamp is null and fo.cancelledTimestamp is null and fs.internal = false and fo.createTimestamp > :billingStartDate"
37471 amit 61
				+ " and fo.createTimestamp < :billedBefore"
37408 amit 62
				+ " and fli.serialNumber is not null and fli.serialNumber <> ''"),
36259 amit 63
 
30449 amit.gupta 64
		@NamedQuery(name = "ActivatedImei.selectActivatedImeisByOrders", query = "select new com.spice.profitmandi.dao.model.ImeiActivationTimestampModel(o.id, o.lineItem.unitPrice, limei.serialNumber, ai.activationTimestamp) "
65
				+ " from Order o join LineItem  li on o.id=li.orderId join LineItemImei  limei on li.id=limei.lineItemId join FofoStore fs on fs.id=o.retailerId left join ActivatedImei ai on limei.serialNumber = ai.serialNumber "
66
				+ "	where o.id in :orderIds and ai.activationTimestamp is not null"),
67
 
30505 amit.gupta 68
		@NamedQuery(name = "ActivatedImei.selectActivatedGrnPendingAmount", query = "select cast(sum(o.lineItem.unitPrice) as float )"
30479 amit.gupta 69
				+ " from Order o join LineItemImei  limei on o.lineItem.id=limei.lineItemId join FofoStore fs on fs.id=o.retailerId left join ActivatedImei ai on limei.serialNumber = ai.serialNumber "
30484 amit.gupta 70
				+ "	where o.status in (12, 9) and ai.activationTimestamp is not null and o.partnerGrnTimestamp is null and o.retailerId=:fofoId group by o.retailerId"),
30479 amit.gupta 71
 
35536 amit 72
		@NamedQuery(name = "ActivatedImei.selectActivatedGrnPendingAmountByFofoIds", query = "select o.retailerId, cast(sum(o.lineItem.unitPrice) as float )"
73
				+ " from Order o join LineItemImei  limei on o.lineItem.id=limei.lineItemId join FofoStore fs on fs.id=o.retailerId left join ActivatedImei ai on limei.serialNumber = ai.serialNumber "
74
				+ "	where o.status in (12, 9) and ai.activationTimestamp is not null and o.partnerGrnTimestamp is null and o.retailerId in :fofoIds group by o.retailerId"),
75
 
34641 ranu 76
		@NamedQuery(name = "ActivatedImei.getMonthlyUnbilledTertiaryPrice", query = "select new com.spice.profitmandi.dao.model.PartnerWiseActivatedNotBilledTotal(ii.fofoId, sum((tl.mop)), DATE_FORMAT(ai.activationTimestamp, '%Y-%m')) "
77
				+" from InventoryItem ii" +
78
				" join Item i on i.id=ii.itemId" +
79
				" join TagListing tl on tl.itemId=i.id" +
80
				" join ActivatedImei ai on ai.serialNumber=ii.serialNumber" +
81
				" WHERE ii.goodQuantity=1 and ai.activationTimestamp is not null and ai.activationTimestamp >= :startDate " +
82
				" and ii.fofoId= :fofoId group by DATE_FORMAT(ai.activationTimestamp, '%Y-%m')"),
36972 ranu 83
 
84
		@NamedQuery(name = "ActivatedImei.getMonthlyUnbilledTertiaryPriceForFofoIds", query = "select new com.spice.profitmandi.dao.model.PartnerWiseActivatedNotBilledTotal(ii.fofoId, sum((tl.mop)), DATE_FORMAT(ai.activationTimestamp, '%Y-%m')) "
85
				+" from InventoryItem ii" +
86
				" join Item i on i.id=ii.itemId" +
87
				" join TagListing tl on tl.itemId=i.id" +
88
				" join ActivatedImei ai on ai.serialNumber=ii.serialNumber" +
89
				" WHERE ii.goodQuantity=1 and ai.activationTimestamp is not null and ai.activationTimestamp >= :startDate " +
90
				" and ii.fofoId in :fofoIds group by ii.fofoId, DATE_FORMAT(ai.activationTimestamp, '%Y-%m')"),
28825 tejbeer 91
})
26299 amit.gupta 92
public class ActivatedImei {
26309 amit.gupta 93
	@Id
94
	@Column(name = "serial_number", unique = true)
95
	private String serialNumber;
28825 tejbeer 96
 
26309 amit.gupta 97
	@Column(name = "activation_timestamp")
98
	private LocalDateTime activationTimestamp;
26299 amit.gupta 99
 
26309 amit.gupta 100
	@Column(name = "create_timestamp")
101
	private LocalDateTime createTimestamp;
28825 tejbeer 102
 
36768 amit 103
	@Column
104
	private boolean checked = false;
105
 
33952 aman.kumar 106
	@Column(name = "auth_id")
107
	private int authId;
108
 
26299 amit.gupta 109
	public ActivatedImei() {
110
		super();
111
	}
28825 tejbeer 112
 
26299 amit.gupta 113
	public ActivatedImei(String serialNumber, LocalDateTime activationTimestamp) {
114
		this.activationTimestamp = activationTimestamp;
115
		this.serialNumber = serialNumber;
116
	}
117
 
118
	public String getSerialNumber() {
119
		return serialNumber;
120
	}
121
 
122
	public void setSerialNumber(String serialNumber) {
123
		this.serialNumber = serialNumber;
124
	}
125
 
126
	public LocalDateTime getActivationTimestamp() {
127
		return activationTimestamp;
128
	}
129
 
130
	public void setActivationTimestamp(LocalDateTime activationTimestamp) {
131
		this.activationTimestamp = activationTimestamp;
132
	}
133
 
26309 amit.gupta 134
	public LocalDateTime getCreateTimestamp() {
135
		return createTimestamp;
136
	}
137
 
138
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
139
		this.createTimestamp = createTimestamp;
140
	}
141
 
33952 aman.kumar 142
	public int getAuthId() {
143
		return authId;
144
	}
145
 
146
	public void setAuthId(int authId) {
147
		this.authId = authId;
148
	}
149
 
26299 amit.gupta 150
	@Override
30896 amit.gupta 151
	public String toString() {
152
		return "ActivatedImei{" +
153
				"serialNumber='" + serialNumber + '\'' +
154
				", activationTimestamp=" + activationTimestamp +
155
				", createTimestamp=" + createTimestamp +
36768 amit 156
				", checked=" + checked +
33952 aman.kumar 157
				", authId=" + authId +
30896 amit.gupta 158
				'}';
26299 amit.gupta 159
	}
160
 
161
	@Override
30896 amit.gupta 162
	public boolean equals(Object o) {
163
		if (this == o) return true;
164
		if (o == null || getClass() != o.getClass()) return false;
165
		ActivatedImei that = (ActivatedImei) o;
36768 amit 166
		return checked == that.checked && Objects.equals(serialNumber, that.serialNumber) && Objects.equals(activationTimestamp, that.activationTimestamp) && Objects.equals(createTimestamp, that.createTimestamp);
26299 amit.gupta 167
	}
168
 
30896 amit.gupta 169
	@Override
170
	public int hashCode() {
36768 amit 171
		return Objects.hash(serialNumber, activationTimestamp, createTimestamp, checked);
30896 amit.gupta 172
	}
173
 
36768 amit 174
	public boolean isChecked() {
175
		return checked;
176
	}
177
 
178
	public void setChecked(boolean checked) {
179
		this.checked = checked;
180
	}
181
 
26299 amit.gupta 182
}