Subversion Repositories SmartDukaan

Rev

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