Subversion Repositories SmartDukaan

Rev

Rev 22009 | Rev 23110 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22009 Rev 22522
Line 1... Line 1...
1
package com.spice.profitmandi.dao.entity.fofo;
1
package com.spice.profitmandi.dao.entity.fofo;
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
4
 
4
 
-
 
5
import javax.persistence.CascadeType;
5
import javax.persistence.Column;
6
import javax.persistence.Column;
6
import javax.persistence.Convert;
7
import javax.persistence.Convert;
7
import javax.persistence.Entity;
8
import javax.persistence.Entity;
8
import javax.persistence.EnumType;
9
import javax.persistence.EnumType;
9
import javax.persistence.Enumerated;
10
import javax.persistence.Enumerated;
-
 
11
import javax.persistence.FetchType;
10
import javax.persistence.GeneratedValue;
12
import javax.persistence.GeneratedValue;
11
import javax.persistence.GenerationType;
13
import javax.persistence.GenerationType;
12
import javax.persistence.Id;
14
import javax.persistence.Id;
-
 
15
import javax.persistence.JoinColumn;
13
import javax.persistence.NamedQueries;
16
import javax.persistence.NamedQueries;
14
import javax.persistence.NamedQuery;
17
import javax.persistence.NamedQuery;
-
 
18
import javax.persistence.OneToOne;
15
import javax.persistence.Table;
19
import javax.persistence.Table;
16
 
20
 
17
import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
21
import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
18
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
22
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
19
 
23
 
20
@Entity
24
@Entity
21
@Table(name="fofo.scan_record", schema = "fofo")
25
@Table(name="fofo.scan_record", schema = "fofo")
22
@NamedQueries({
26
@NamedQueries({
23
	@NamedQuery(name = "ScanRecord.selectCount", query = "select count(sr) from ScanRecord sr"),
27
	@NamedQuery(name = "ScanRecord.selectCount", query = "select count(sr) from ScanRecord sr"),
24
	@NamedQuery(name = "ScanRecord.selectByFofoId", query = "select sr from ScanRecord sr where sr.fofoId = :fofoId")
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 "
-
 
43
								+ "(-sr.quantity * ii.unitPrice) "
-
 
44
							+ "when (sr.type in('PURCHASE')) then "
-
 
45
								+ "(sr.quantity * ii.unitPrice) end) "
-
 
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 "
-
 
72
								+ "(-sr.quantity * ii.unitPrice) "
-
 
73
							+ "when (sr.type in('PURCHASE')) then "
-
 
74
								+ "(sr.quantity * ii.unitPrice) end) "
-
 
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",
-
 
89
			query = "select new com.spice.profitmandi.dao.model.ItemLedgerRow(ii.itemId, sum(sr.quantity), avg(ii.unitPrice)) 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"),
-
 
90
	
-
 
91
	@NamedQuery(
-
 
92
			name = "ScanRecord.selectSaleByFofoId",
-
 
93
			query = "select new com.spice.profitmandi.dao.model.ItemLedgerRow(ii.itemId, sum(sr.quantity), avg(ii.unitPrice)) 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")
25
})
94
})
26
public class ScanRecord {
95
public class ScanRecord {
27
	
96
	
28
	@Id
97
	@Id
29
	@Column(name="id", unique=true, updatable=false)
98
	@Column(name="id", unique=true, updatable=false)
Line 44... Line 113...
44
	private ScanType type;
113
	private ScanType type;
45
	
114
	
46
	@Convert(converter = LocalDateTimeAttributeConverter.class)
115
	@Convert(converter = LocalDateTimeAttributeConverter.class)
47
	@Column(name = "create_timestamp")
116
	@Column(name = "create_timestamp")
48
	private LocalDateTime createTimestamp = LocalDateTime.now();
117
	private LocalDateTime createTimestamp = LocalDateTime.now();
-
 
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;
49
 
122
 
50
	public int getId() {
123
	public int getId() {
51
		return id;
124
		return id;
52
	}
125
	}
53
 
126
 
Line 90... Line 163...
90
	}
163
	}
91
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
164
	public void setCreateTimestamp(LocalDateTime createTimestamp) {
92
		this.createTimestamp = createTimestamp;
165
		this.createTimestamp = createTimestamp;
93
	}
166
	}
94
	
167
	
-
 
168
	public InventoryItem getInventoryItem() {
-
 
169
		return inventoryItem;
-
 
170
	}
-
 
171
	
-
 
172
	public void setInventoryItem(InventoryItem inventoryItem) {
-
 
173
		this.inventoryItem = inventoryItem;
-
 
174
	}
95
 
175
 
96
	@Override
176
	@Override
97
	public int hashCode() {
177
	public int hashCode() {
98
		final int prime = 31;
178
		final int prime = 31;
99
		int result = 1;
179
		int result = 1;
Line 116... Line 196...
116
	}
196
	}
117
 
197
 
118
	@Override
198
	@Override
119
	public String toString() {
199
	public String toString() {
120
		return "ScanRecord [id=" + id + ", fofoId=" + fofoId + ", inventoryItemId=" + inventoryItemId + ", quantity="
200
		return "ScanRecord [id=" + id + ", fofoId=" + fofoId + ", inventoryItemId=" + inventoryItemId + ", quantity="
121
				+ quantity + ", type=" + type + ", createTimestamp=" + createTimestamp + "]";
201
				+ quantity + ", type=" + type + ", createTimestamp=" + createTimestamp + ", inventoryItem="
-
 
202
				+ inventoryItem + "]";
122
	}
203
	}
123
	
204
	
124
	
-
 
125
		
-
 
126
}
205
}
127
206