Subversion Repositories SmartDukaan

Rev

Rev 37408 | Go to most recent revision | 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
 
31170 amit.gupta 64
		@NamedQuery(name = "ActivatedImei.selectImeiSoldNotActivatedByBrand", query = "select new com.spice.profitmandi.dao.model.ImeiActivationTimestampModel(fli.serialNumber, ai.activationTimestamp) "
36261 amit 65
				+ " from FofoOrder fo join FofoOrderItem  foi on fo.id=foi.orderId join FofoLineItem  fli on fli.fofoOrderItemId=foi.id "
31170 amit.gupta 66
				+ " 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 "
36261 amit 67
				+ "	where ai.createTimestamp is null and ci.brand = :brand and ai.activationTimestamp is null and fo.cancelledTimestamp is null and fs.internal = false and fo.createTimestamp > :billingStartDate"),
31170 amit.gupta 68
 
30449 amit.gupta 69
		@NamedQuery(name = "ActivatedImei.selectActivatedImeisByOrders", query = "select new com.spice.profitmandi.dao.model.ImeiActivationTimestampModel(o.id, o.lineItem.unitPrice, limei.serialNumber, ai.activationTimestamp) "
70
				+ " 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 "
71
				+ "	where o.id in :orderIds and ai.activationTimestamp is not null"),
72
 
30505 amit.gupta 73
		@NamedQuery(name = "ActivatedImei.selectActivatedGrnPendingAmount", query = "select cast(sum(o.lineItem.unitPrice) as float )"
30479 amit.gupta 74
				+ " 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 75
				+ "	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 76
 
35536 amit 77
		@NamedQuery(name = "ActivatedImei.selectActivatedGrnPendingAmountByFofoIds", query = "select o.retailerId, cast(sum(o.lineItem.unitPrice) as float )"
78
				+ " 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 "
79
				+ "	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"),
80
 
34641 ranu 81
		@NamedQuery(name = "ActivatedImei.getMonthlyUnbilledTertiaryPrice", query = "select new com.spice.profitmandi.dao.model.PartnerWiseActivatedNotBilledTotal(ii.fofoId, sum((tl.mop)), DATE_FORMAT(ai.activationTimestamp, '%Y-%m')) "
82
				+" from InventoryItem ii" +
83
				" join Item i on i.id=ii.itemId" +
84
				" join TagListing tl on tl.itemId=i.id" +
85
				" join ActivatedImei ai on ai.serialNumber=ii.serialNumber" +
86
				" WHERE ii.goodQuantity=1 and ai.activationTimestamp is not null and ai.activationTimestamp >= :startDate " +
87
				" and ii.fofoId= :fofoId group by DATE_FORMAT(ai.activationTimestamp, '%Y-%m')"),
36972 ranu 88
 
89
		@NamedQuery(name = "ActivatedImei.getMonthlyUnbilledTertiaryPriceForFofoIds", query = "select new com.spice.profitmandi.dao.model.PartnerWiseActivatedNotBilledTotal(ii.fofoId, sum((tl.mop)), DATE_FORMAT(ai.activationTimestamp, '%Y-%m')) "
90
				+" from InventoryItem ii" +
91
				" join Item i on i.id=ii.itemId" +
92
				" join TagListing tl on tl.itemId=i.id" +
93
				" join ActivatedImei ai on ai.serialNumber=ii.serialNumber" +
94
				" WHERE ii.goodQuantity=1 and ai.activationTimestamp is not null and ai.activationTimestamp >= :startDate " +
95
				" and ii.fofoId in :fofoIds group by ii.fofoId, DATE_FORMAT(ai.activationTimestamp, '%Y-%m')"),
28825 tejbeer 96
})
26299 amit.gupta 97
public class ActivatedImei {
26309 amit.gupta 98
	@Id
99
	@Column(name = "serial_number", unique = true)
100
	private String serialNumber;
28825 tejbeer 101
 
26309 amit.gupta 102
	@Column(name = "activation_timestamp")
103
	private LocalDateTime activationTimestamp;
26299 amit.gupta 104
 
26309 amit.gupta 105
	@Column(name = "create_timestamp")
106
	private LocalDateTime createTimestamp;
28825 tejbeer 107
 
36768 amit 108
	@Column
109
	private boolean checked = false;
110
 
33952 aman.kumar 111
	@Column(name = "auth_id")
112
	private int authId;
113
 
26299 amit.gupta 114
	public ActivatedImei() {
115
		super();
116
	}
28825 tejbeer 117
 
26299 amit.gupta 118
	public ActivatedImei(String serialNumber, LocalDateTime activationTimestamp) {
119
		this.activationTimestamp = activationTimestamp;
120
		this.serialNumber = serialNumber;
121
	}
122
 
123
	public String getSerialNumber() {
124
		return serialNumber;
125
	}
126
 
127
	public void setSerialNumber(String serialNumber) {
128
		this.serialNumber = serialNumber;
129
	}
130
 
131
	public LocalDateTime getActivationTimestamp() {
132
		return activationTimestamp;
133
	}
134
 
135
	public void setActivationTimestamp(LocalDateTime activationTimestamp) {
136
		this.activationTimestamp = activationTimestamp;
137
	}
138
 
26309 amit.gupta 139
	public LocalDateTime getCreateTimestamp() {
140
		return createTimestamp;
141
	}
142
 
143
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
144
		this.createTimestamp = createTimestamp;
145
	}
146
 
33952 aman.kumar 147
	public int getAuthId() {
148
		return authId;
149
	}
150
 
151
	public void setAuthId(int authId) {
152
		this.authId = authId;
153
	}
154
 
26299 amit.gupta 155
	@Override
30896 amit.gupta 156
	public String toString() {
157
		return "ActivatedImei{" +
158
				"serialNumber='" + serialNumber + '\'' +
159
				", activationTimestamp=" + activationTimestamp +
160
				", createTimestamp=" + createTimestamp +
36768 amit 161
				", checked=" + checked +
33952 aman.kumar 162
				", authId=" + authId +
30896 amit.gupta 163
				'}';
26299 amit.gupta 164
	}
165
 
166
	@Override
30896 amit.gupta 167
	public boolean equals(Object o) {
168
		if (this == o) return true;
169
		if (o == null || getClass() != o.getClass()) return false;
170
		ActivatedImei that = (ActivatedImei) o;
36768 amit 171
		return checked == that.checked && Objects.equals(serialNumber, that.serialNumber) && Objects.equals(activationTimestamp, that.activationTimestamp) && Objects.equals(createTimestamp, that.createTimestamp);
26299 amit.gupta 172
	}
173
 
30896 amit.gupta 174
	@Override
175
	public int hashCode() {
36768 amit 176
		return Objects.hash(serialNumber, activationTimestamp, createTimestamp, checked);
30896 amit.gupta 177
	}
178
 
36768 amit 179
	public boolean isChecked() {
180
		return checked;
181
	}
182
 
183
	public void setChecked(boolean checked) {
184
		this.checked = checked;
185
	}
186
 
26299 amit.gupta 187
}