Subversion Repositories SmartDukaan

Rev

Rev 22522 | Rev 23329 | 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({
27
	@NamedQuery(name = "ScanRecord.selectCount", query = "select count(sr) from ScanRecord sr"),
22522 ashik.ali 28
	@NamedQuery(name = "ScanRecord.selectByFofoId", query = "select sr from ScanRecord sr where sr.fofoId = :fofoId"),
29
	@NamedQuery(
30
			name = "ScanRecord.selectOpeningByFofoId",
31
			query = "select "
32
					+"new com.spice.profitmandi.dao.model.ItemLedgerRow("
33
					+ "ii.itemId, "
34
					+"sum("
35
						+ "case "
36
							+ "when (sr.type in('SALE')) then "
37
								+ "-sr.quantity "
38
							+ "when (sr.type in('PURCHASE')) then "
39
							+ "sr.quantity end), "
40
					+ "sum("
41
						+ "case "
42
							+ "when (sr.type in ('SALE')) then "
23110 ashik.ali 43
								+ "(-sr.quantity * (ii.unitPrice - ii.priceDropAmount)) "
22522 ashik.ali 44
							+ "when (sr.type in('PURCHASE')) then "
23110 ashik.ali 45
								+ "(sr.quantity * (ii.unitPrice - ii.priceDropAmount)) end) "
22522 ashik.ali 46
							+ "/ "
47
					+"sum("
48
					+ "case "
49
						+ "when (sr.type in('SALE')) then "
50
							+ "-sr.quantity "
51
						+ "when (sr.type in('PURCHASE')) then "
52
						+ "sr.quantity end)"
53
					+ ") "
54
					//+ "ii.unitPrice "
55
					+ "from ScanRecord sr join InventoryItem ii on sr.inventoryItemId = ii.id "
56
					+ "where sr.createTimestamp < :createTimestamp and sr.fofoId = :fofoId "
57
					+ "group by ii.itemId"),
58
	@NamedQuery(
59
			name = "ScanRecord.selectClosingByFofoId",
60
			query = "select "
61
					+"new com.spice.profitmandi.dao.model.ItemLedgerRow("
62
					+ "ii.itemId, "
63
					+"sum("
64
						+ "case "
65
							+ "when (sr.type in('SALE')) then "
66
								+ "-sr.quantity "
67
							+ "when (sr.type in('PURCHASE')) then "
68
							+ "sr.quantity end), "
69
					+ "sum("
70
						+ "case "
71
							+ "when (sr.type in ('SALE')) then "
23110 ashik.ali 72
								+ "(-sr.quantity * (ii.unitPrice - ii.priceDropAmount)) "
22522 ashik.ali 73
							+ "when (sr.type in('PURCHASE')) then "
23110 ashik.ali 74
								+ "(sr.quantity * (ii.unitPrice - ii.priceDropAmount)) end) "
22522 ashik.ali 75
							+ "/ "
76
					+"sum("
77
					+ "case "
78
						+ "when (sr.type in('SALE')) then "
79
							+ "-sr.quantity "
80
						+ "when (sr.type in('PURCHASE')) then "
81
						+ "sr.quantity end)"
82
					+ ") "
83
					//+ "ii.unitPrice "
84
					+ "from ScanRecord sr join InventoryItem ii on sr.inventoryItemId = ii.id "
85
					+ "where sr.createTimestamp > :createTimestamp and sr.fofoId = :fofoId "
86
					+ "group by ii.itemId"),
87
	@NamedQuery(
88
			name = "ScanRecord.selectPurchaseByFofoId",
23110 ashik.ali 89
			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='PURCHASE' and sr.createTimestamp >= :startDateTime and sr.createTimestamp <= :endDateTime and sr.fofoId = :fofoId group by ii.itemId"),
22522 ashik.ali 90
 
91
	@NamedQuery(
92
			name = "ScanRecord.selectSaleByFofoId",
23110 ashik.ali 93
			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='SALE' and sr.createTimestamp >= :startDateTime and sr.createTimestamp <= :endDateTime and sr.fofoId = :fofoId group by ii.itemId")
21552 ashik.ali 94
})
95
public class ScanRecord {
96
 
97
	@Id
98
	@Column(name="id", unique=true, updatable=false)
99
	@GeneratedValue(strategy = GenerationType.IDENTITY)
100
	private int id;
101
 
102
	@Column(name = "fofo_id")
103
	private int fofoId;
104
 
21573 ashik.ali 105
	@Column(name = "inventory_item_id")
106
	private int inventoryItemId;
107
 
108
	@Column(name = "quantity")
109
	private int quantity;
110
 
21552 ashik.ali 111
	@Column(name = "type")
112
	@Enumerated(EnumType.STRING)
113
	private ScanType type;
114
 
21633 ashik.ali 115
	@Convert(converter = LocalDateTimeAttributeConverter.class)
21552 ashik.ali 116
	@Column(name = "create_timestamp")
21633 ashik.ali 117
	private LocalDateTime createTimestamp = LocalDateTime.now();
22522 ashik.ali 118
 
119
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
120
	@JoinColumn(name="inventory_item_id",insertable=false,updatable=false,nullable=false, referencedColumnName = "id")
121
	private InventoryItem inventoryItem;
21552 ashik.ali 122
 
123
	public int getId() {
124
		return id;
125
	}
126
 
127
	public void setId(int id) {
128
		this.id = id;
129
	}
130
 
131
	public int getFofoId() {
132
		return fofoId;
133
	}
134
 
135
	public void setFofoId(int fofoId) {
136
		this.fofoId = fofoId;
137
	}
21573 ashik.ali 138
 
139
	public int getInventoryItemId() {
140
		return inventoryItemId;
141
	}
142
	public void setInventoryItemId(int inventoryItemId) {
143
		this.inventoryItemId = inventoryItemId;
144
	}
145
 
146
	public int getQuantity() {
147
		return quantity;
148
	}
149
	public void setQuantity(int quantity) {
150
		this.quantity = quantity;
151
	}
21552 ashik.ali 152
 
153
	public ScanType getType() {
154
		return type;
155
	}
156
 
157
	public void setType(ScanType type) {
158
		this.type = type;
159
	}
160
 
161
	public LocalDateTime getCreateTimestamp() {
162
		return createTimestamp;
163
	}
164
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
165
		this.createTimestamp = createTimestamp;
166
	}
21924 ashik.ali 167
 
22522 ashik.ali 168
	public InventoryItem getInventoryItem() {
169
		return inventoryItem;
170
	}
171
 
172
	public void setInventoryItem(InventoryItem inventoryItem) {
173
		this.inventoryItem = inventoryItem;
174
	}
21602 ashik.ali 175
 
176
	@Override
21924 ashik.ali 177
	public int hashCode() {
178
		final int prime = 31;
179
		int result = 1;
180
		result = prime * result + id;
181
		return result;
182
	}
183
 
184
	@Override
185
	public boolean equals(Object obj) {
186
		if (this == obj)
187
			return true;
188
		if (obj == null)
189
			return false;
190
		if (getClass() != obj.getClass())
191
			return false;
192
		ScanRecord other = (ScanRecord) obj;
193
		if (id != other.id)
194
			return false;
195
		return true;
196
	}
197
 
198
	@Override
21602 ashik.ali 199
	public String toString() {
200
		return "ScanRecord [id=" + id + ", fofoId=" + fofoId + ", inventoryItemId=" + inventoryItemId + ", quantity="
22522 ashik.ali 201
				+ quantity + ", type=" + type + ", createTimestamp=" + createTimestamp + ", inventoryItem="
202
				+ inventoryItem + "]";
21602 ashik.ali 203
	}
204
 
21573 ashik.ali 205
}