Subversion Repositories SmartDukaan

Rev

Rev 23329 | Rev 23823 | 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 "
23796 amit.gupta 34
							+ "when (sr.type in('SALE', 'PURCHASE_RET')) then "
22522 ashik.ali 35
								+ "-sr.quantity "
36
							+ "when (sr.type in('PURCHASE')) then "
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 "
23796 amit.gupta 47
						+ "when (sr.type in('SALE', 'PURCHASE_RET')) then "
22522 ashik.ali 48
							+ "-sr.quantity "
49
						+ "when (sr.type in('PURCHASE')) then "
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 "
23796 amit.gupta 63
							+ "when (sr.type in('SALE','PURCHASE_RET')) then "
22522 ashik.ali 64
								+ "-sr.quantity "
65
							+ "when (sr.type in('PURCHASE')) then "
66
							+ "sr.quantity end), "
67
					+ "sum("
68
						+ "case "
23796 amit.gupta 69
							+ "when (sr.type in ('SALE', 'PURCHASE_RET')) then "
23110 ashik.ali 70
								+ "(-sr.quantity * (ii.unitPrice - ii.priceDropAmount)) "
22522 ashik.ali 71
							+ "when (sr.type in('PURCHASE')) then "
23110 ashik.ali 72
								+ "(sr.quantity * (ii.unitPrice - ii.priceDropAmount)) end) "
22522 ashik.ali 73
							+ "/ "
74
					+"sum("
75
					+ "case "
23796 amit.gupta 76
						+ "when (sr.type in('SALE', 'PURCHASE_RET')) then "
22522 ashik.ali 77
							+ "-sr.quantity "
78
						+ "when (sr.type in('PURCHASE')) then "
79
						+ "sr.quantity end)"
80
					+ ") "
81
					//+ "ii.unitPrice "
82
					+ "from ScanRecord sr join InventoryItem ii on sr.inventoryItemId = ii.id "
83
					+ "where sr.createTimestamp > :createTimestamp and sr.fofoId = :fofoId "
84
					+ "group by ii.itemId"),
85
	@NamedQuery(
86
			name = "ScanRecord.selectPurchaseByFofoId",
23110 ashik.ali 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='PURCHASE' 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",
23110 ashik.ali 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='SALE' 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
 
117
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
118
	@JoinColumn(name="inventory_item_id",insertable=false,updatable=false,nullable=false, referencedColumnName = "id")
119
	private InventoryItem inventoryItem;
21552 ashik.ali 120
 
121
	public int getId() {
122
		return id;
123
	}
124
 
125
	public void setId(int id) {
126
		this.id = id;
127
	}
128
 
129
	public int getFofoId() {
130
		return fofoId;
131
	}
132
 
133
	public void setFofoId(int fofoId) {
134
		this.fofoId = fofoId;
135
	}
21573 ashik.ali 136
 
137
	public int getInventoryItemId() {
138
		return inventoryItemId;
139
	}
140
	public void setInventoryItemId(int inventoryItemId) {
141
		this.inventoryItemId = inventoryItemId;
142
	}
143
 
144
	public int getQuantity() {
145
		return quantity;
146
	}
147
	public void setQuantity(int quantity) {
148
		this.quantity = quantity;
149
	}
21552 ashik.ali 150
 
151
	public ScanType getType() {
152
		return type;
153
	}
154
 
155
	public void setType(ScanType type) {
156
		this.type = type;
157
	}
158
 
159
	public LocalDateTime getCreateTimestamp() {
160
		return createTimestamp;
161
	}
162
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
163
		this.createTimestamp = createTimestamp;
164
	}
21924 ashik.ali 165
 
22522 ashik.ali 166
	public InventoryItem getInventoryItem() {
167
		return inventoryItem;
168
	}
169
 
170
	public void setInventoryItem(InventoryItem inventoryItem) {
171
		this.inventoryItem = inventoryItem;
172
	}
21602 ashik.ali 173
 
174
	@Override
21924 ashik.ali 175
	public int hashCode() {
176
		final int prime = 31;
177
		int result = 1;
178
		result = prime * result + id;
179
		return result;
180
	}
181
 
182
	@Override
183
	public boolean equals(Object obj) {
184
		if (this == obj)
185
			return true;
186
		if (obj == null)
187
			return false;
188
		if (getClass() != obj.getClass())
189
			return false;
190
		ScanRecord other = (ScanRecord) obj;
191
		if (id != other.id)
192
			return false;
193
		return true;
194
	}
195
 
196
	@Override
21602 ashik.ali 197
	public String toString() {
198
		return "ScanRecord [id=" + id + ", fofoId=" + fofoId + ", inventoryItemId=" + inventoryItemId + ", quantity="
22522 ashik.ali 199
				+ quantity + ", type=" + type + ", createTimestamp=" + createTimestamp + ", inventoryItem="
200
				+ inventoryItem + "]";
21602 ashik.ali 201
	}
202
 
21573 ashik.ali 203
}