Subversion Repositories SmartDukaan

Rev

Rev 24264 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21714 ashik.ali 1
package com.spice.profitmandi.dao.entity.fofo;
21552 ashik.ali 2
 
3
import java.time.LocalDateTime;
4
 
22522 ashik.ali 5
import javax.persistence.CascadeType;
21552 ashik.ali 6
import javax.persistence.Column;
21633 ashik.ali 7
import javax.persistence.Convert;
21552 ashik.ali 8
import javax.persistence.Entity;
9
import javax.persistence.EnumType;
10
import javax.persistence.Enumerated;
22522 ashik.ali 11
import javax.persistence.FetchType;
21552 ashik.ali 12
import javax.persistence.GeneratedValue;
13
import javax.persistence.GenerationType;
14
import javax.persistence.Id;
22522 ashik.ali 15
import javax.persistence.JoinColumn;
21552 ashik.ali 16
import javax.persistence.NamedQueries;
17
import javax.persistence.NamedQuery;
22522 ashik.ali 18
import javax.persistence.OneToOne;
21552 ashik.ali 19
import javax.persistence.Table;
20
 
21633 ashik.ali 21
import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
21714 ashik.ali 22
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
21552 ashik.ali 23
 
24
@Entity
25
@Table(name="fofo.scan_record", schema = "fofo")
26
@NamedQueries({
22522 ashik.ali 27
	@NamedQuery(
28
			name = "ScanRecord.selectOpeningByFofoId",
29
			query = "select "
30
					+"new com.spice.profitmandi.dao.model.ItemLedgerRow("
31
					+ "ii.itemId, "
32
					+"sum("
33
						+ "case "
24220 amit.gupta 34
							+ "when (sr.type in('SALE', 'PURCHASE_RET', 'PURCHASE_RET_BAD')) then "
22522 ashik.ali 35
								+ "-sr.quantity "
24220 amit.gupta 36
							+ "when (sr.type in('PURCHASE','SALE_RET_UNUSABLE')) then "
22522 ashik.ali 37
							+ "sr.quantity end), "
38
					+ "sum("
39
						+ "case "
23796 amit.gupta 40
							+ "when (sr.type in ('SALE', 'PURCHASE_RET')) then "
23110 ashik.ali 41
								+ "(-sr.quantity * (ii.unitPrice - ii.priceDropAmount)) "
22522 ashik.ali 42
							+ "when (sr.type in('PURCHASE')) then "
23110 ashik.ali 43
								+ "(sr.quantity * (ii.unitPrice - ii.priceDropAmount)) end) "
22522 ashik.ali 44
							+ "/ "
45
					+"sum("
46
					+ "case "
24220 amit.gupta 47
						+ "when (sr.type in('SALE', 'PURCHASE_RET', 'PURCHASE_RET_BAD')) then "
22522 ashik.ali 48
							+ "-sr.quantity "
24220 amit.gupta 49
						+ "when (sr.type in('PURCHASE', 'SALE_RET_UNUSABLE')) then "
22522 ashik.ali 50
						+ "sr.quantity end)"
51
					+ ") "
52
					//+ "ii.unitPrice "
53
					+ "from ScanRecord sr join InventoryItem ii on sr.inventoryItemId = ii.id "
54
					+ "where sr.createTimestamp < :createTimestamp and sr.fofoId = :fofoId "
55
					+ "group by ii.itemId"),
56
	@NamedQuery(
57
			name = "ScanRecord.selectClosingByFofoId",
58
			query = "select "
59
					+"new com.spice.profitmandi.dao.model.ItemLedgerRow("
60
					+ "ii.itemId, "
61
					+"sum("
62
						+ "case "
24220 amit.gupta 63
							+ "when (sr.type in('SALE','PURCHASE_RET','PURCHASE_RET_BAD')) then "
22522 ashik.ali 64
								+ "-sr.quantity "
24220 amit.gupta 65
							+ "when (sr.type in('PURCHASE', 'SALE_RET_UNUSABLE')) then "
22522 ashik.ali 66
							+ "sr.quantity end), "
67
					+ "sum("
68
						+ "case "
24220 amit.gupta 69
							+ "when (sr.type in ('SALE', 'PURCHASE_RET','PURCHASE_RET_BAD')) then "
23110 ashik.ali 70
								+ "(-sr.quantity * (ii.unitPrice - ii.priceDropAmount)) "
24220 amit.gupta 71
							+ "when (sr.type in('PURCHASE','SALE_RET_UNUSABLE')) then "
23110 ashik.ali 72
								+ "(sr.quantity * (ii.unitPrice - ii.priceDropAmount)) end) "
22522 ashik.ali 73
							+ "/ "
74
					+"sum("
75
					+ "case "
24220 amit.gupta 76
						+ "when (sr.type in('SALE', 'PURCHASE_RET', 'PURCHASE_RET_BAD')) then "
22522 ashik.ali 77
							+ "-sr.quantity "
24220 amit.gupta 78
						+ "when (sr.type in('PURCHASE', 'SALE_RET_UNUSABLE')) then "
22522 ashik.ali 79
						+ "sr.quantity end)"
80
					+ ") "
81
					//+ "ii.unitPrice "
82
					+ "from ScanRecord sr join InventoryItem ii on sr.inventoryItemId = ii.id "
24220 amit.gupta 83
					+ "where sr.createTimestamp < :createTimestamp and sr.fofoId = :fofoId "
22522 ashik.ali 84
					+ "group by ii.itemId"),
85
	@NamedQuery(
86
			name = "ScanRecord.selectPurchaseByFofoId",
24220 amit.gupta 87
			query = "select new com.spice.profitmandi.dao.model.ItemLedgerRow(ii.itemId, sum(sr.quantity), avg(ii.unitPrice - ii.priceDropAmount)) from ScanRecord sr join InventoryItem ii on ii.id = sr.inventoryItemId where sr.type in ('PURCHASE', 'SALE_RET_UNUSABLE') and sr.createTimestamp >= :startDateTime and sr.createTimestamp <= :endDateTime and sr.fofoId = :fofoId group by ii.itemId"),
22522 ashik.ali 88
 
89
	@NamedQuery(
90
			name = "ScanRecord.selectSaleByFofoId",
24220 amit.gupta 91
			query = "select new com.spice.profitmandi.dao.model.ItemLedgerRow(ii.itemId, sum(sr.quantity), avg(ii.unitPrice - ii.priceDropAmount)) from ScanRecord sr join InventoryItem ii on ii.id = sr.inventoryItemId where sr.type in ('SALE', 'PURCHASE_RET', 'PURCHASE_RET_BAD') and sr.createTimestamp >= :startDateTime and sr.createTimestamp <= :endDateTime and sr.fofoId = :fofoId group by ii.itemId")
21552 ashik.ali 92
})
93
public class ScanRecord {
94
 
95
	@Id
96
	@Column(name="id", unique=true, updatable=false)
97
	@GeneratedValue(strategy = GenerationType.IDENTITY)
98
	private int id;
99
 
100
	@Column(name = "fofo_id")
101
	private int fofoId;
102
 
21573 ashik.ali 103
	@Column(name = "inventory_item_id")
104
	private int inventoryItemId;
105
 
106
	@Column(name = "quantity")
107
	private int quantity;
108
 
21552 ashik.ali 109
	@Column(name = "type")
110
	@Enumerated(EnumType.STRING)
111
	private ScanType type;
112
 
21633 ashik.ali 113
	@Convert(converter = LocalDateTimeAttributeConverter.class)
21552 ashik.ali 114
	@Column(name = "create_timestamp")
21633 ashik.ali 115
	private LocalDateTime createTimestamp = LocalDateTime.now();
22522 ashik.ali 116
 
26762 amit.gupta 117
	@OneToOne(fetch=FetchType.LAZY)
22522 ashik.ali 118
	@JoinColumn(name="inventory_item_id",insertable=false,updatable=false,nullable=false, referencedColumnName = "id")
119
	private InventoryItem inventoryItem;
24264 amit.gupta 120
 
121
	@Column(name = "order_id")
122
	private int orderId;
21552 ashik.ali 123
 
24264 amit.gupta 124
	public int getOrderId() {
125
		return orderId;
126
	}
127
 
128
	public void setOrderId(int orderId) {
129
		this.orderId = orderId;
130
	}
131
 
21552 ashik.ali 132
	public int getId() {
133
		return id;
134
	}
135
 
136
	public void setId(int id) {
137
		this.id = id;
138
	}
139
 
140
	public int getFofoId() {
141
		return fofoId;
142
	}
143
 
144
	public void setFofoId(int fofoId) {
145
		this.fofoId = fofoId;
146
	}
21573 ashik.ali 147
 
148
	public int getInventoryItemId() {
149
		return inventoryItemId;
150
	}
151
	public void setInventoryItemId(int inventoryItemId) {
152
		this.inventoryItemId = inventoryItemId;
153
	}
154
 
155
	public int getQuantity() {
156
		return quantity;
157
	}
158
	public void setQuantity(int quantity) {
159
		this.quantity = quantity;
160
	}
21552 ashik.ali 161
 
162
	public ScanType getType() {
163
		return type;
164
	}
165
 
166
	public void setType(ScanType type) {
167
		this.type = type;
168
	}
169
 
170
	public LocalDateTime getCreateTimestamp() {
171
		return createTimestamp;
172
	}
173
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
174
		this.createTimestamp = createTimestamp;
175
	}
21924 ashik.ali 176
 
22522 ashik.ali 177
	public InventoryItem getInventoryItem() {
178
		return inventoryItem;
179
	}
180
 
181
	public void setInventoryItem(InventoryItem inventoryItem) {
182
		this.inventoryItem = inventoryItem;
183
	}
21602 ashik.ali 184
 
185
	@Override
21924 ashik.ali 186
	public int hashCode() {
187
		final int prime = 31;
188
		int result = 1;
24264 amit.gupta 189
		result = prime * result + ((createTimestamp == null) ? 0 : createTimestamp.hashCode());
190
		result = prime * result + fofoId;
21924 ashik.ali 191
		result = prime * result + id;
24264 amit.gupta 192
		result = prime * result + ((inventoryItem == null) ? 0 : inventoryItem.hashCode());
193
		result = prime * result + inventoryItemId;
194
		result = prime * result + orderId;
195
		result = prime * result + quantity;
196
		result = prime * result + ((type == null) ? 0 : type.hashCode());
21924 ashik.ali 197
		return result;
198
	}
199
 
200
	@Override
201
	public boolean equals(Object obj) {
202
		if (this == obj)
203
			return true;
204
		if (obj == null)
205
			return false;
206
		if (getClass() != obj.getClass())
207
			return false;
208
		ScanRecord other = (ScanRecord) obj;
24264 amit.gupta 209
		if (createTimestamp == null) {
210
			if (other.createTimestamp != null)
211
				return false;
212
		} else if (!createTimestamp.equals(other.createTimestamp))
213
			return false;
214
		if (fofoId != other.fofoId)
215
			return false;
21924 ashik.ali 216
		if (id != other.id)
217
			return false;
24264 amit.gupta 218
		if (inventoryItem == null) {
219
			if (other.inventoryItem != null)
220
				return false;
221
		} else if (!inventoryItem.equals(other.inventoryItem))
222
			return false;
223
		if (inventoryItemId != other.inventoryItemId)
224
			return false;
225
		if (orderId != other.orderId)
226
			return false;
227
		if (quantity != other.quantity)
228
			return false;
229
		if (type != other.type)
230
			return false;
21924 ashik.ali 231
		return true;
232
	}
233
 
234
	@Override
21602 ashik.ali 235
	public String toString() {
236
		return "ScanRecord [id=" + id + ", fofoId=" + fofoId + ", inventoryItemId=" + inventoryItemId + ", quantity="
22522 ashik.ali 237
				+ quantity + ", type=" + type + ", createTimestamp=" + createTimestamp + ", inventoryItem="
24264 amit.gupta 238
				+ inventoryItem + ", orderId=" + orderId + "]";
21602 ashik.ali 239
	}
240
 
21573 ashik.ali 241
}