| 33873 |
ranu |
1 |
package com.spice.profitmandi.dao.entity.fofo;
|
|
|
2 |
|
| 34163 |
ranu |
3 |
import com.spice.profitmandi.dao.model.HidAllocationModel;
|
|
|
4 |
|
| 33873 |
ranu |
5 |
import javax.persistence.*;
|
|
|
6 |
import java.io.Serializable;
|
|
|
7 |
import java.time.LocalDate;
|
|
|
8 |
import java.util.Objects;
|
|
|
9 |
|
|
|
10 |
@Entity
|
|
|
11 |
@Table(name = "fofo.fofo_opening_stock",
|
|
|
12 |
uniqueConstraints = {@UniqueConstraint(columnNames = {"fofo_id", "catalog_id"})})
|
|
|
13 |
|
| 34163 |
ranu |
14 |
|
|
|
15 |
@NamedNativeQueries({
|
|
|
16 |
@NamedNativeQuery(name = "Stock.PartnerHidAllocation",
|
|
|
17 |
query = "SELECT" +
|
|
|
18 |
" COALESCE(os.fofo_id,0) as fofo_id," +
|
|
|
19 |
" cc.catalog_id," +
|
|
|
20 |
" c.model_number," +
|
|
|
21 |
" c.brand," +
|
|
|
22 |
" COALESCE(SUM(os.current_qty), 0) AS available_stock," +
|
|
|
23 |
" COALESCE(sale1.last2daysSale, 0) AS last2DaysSoldQtySum," +
|
|
|
24 |
" (CASE" +
|
| 34256 |
ranu |
25 |
" WHEN ((COALESCE(sale1.last2daysSale, 0) * :allocationConst) = 0)" +
|
| 34163 |
ranu |
26 |
" OR (COALESCE(SUM(os.current_qty), 0) = 0) THEN 2" +
|
| 34256 |
ranu |
27 |
" ELSE ROUND((COALESCE(sale1.last2daysSale, 0) * :allocationConst))" +
|
|
|
28 |
" END) AS allocation" +
|
| 34163 |
ranu |
29 |
" FROM catalog.catagoriesd_catalog cc" +
|
|
|
30 |
" LEFT JOIN fofo.fofo_opening_stock os ON os.catalog_id = cc.catalog_id AND os.fofo_id = :fofoId" +
|
|
|
31 |
" LEFT JOIN (" +
|
|
|
32 |
" SELECT o.fofo_id, ci.catalog_item_id, SUM(oi.quantity) AS last2daysSale" +
|
|
|
33 |
" FROM fofo.fofo_order o" +
|
|
|
34 |
" JOIN fofo.fofo_order_item oi ON o.id = oi.order_id" +
|
|
|
35 |
" JOIN catalog.item ci ON oi.item_id = ci.id" +
|
|
|
36 |
" WHERE DATE(o.create_timestamp) BETWEEN (CURDATE() - INTERVAL 2 DAY) AND CURDATE()" +
|
|
|
37 |
" GROUP BY o.fofo_id, ci.catalog_item_id" +
|
|
|
38 |
") sale1 ON sale1.catalog_item_id = os.catalog_id AND os.fofo_id = sale1.fofo_id" +
|
|
|
39 |
" JOIN catalog.catalog c ON c.id = cc.catalog_id" +
|
|
|
40 |
" WHERE cc.end_date IS NULL AND cc.status = 'HID'" +
|
|
|
41 |
"GROUP BY cc.catalog_id",
|
|
|
42 |
resultSetMapping = "HidAllocation"),
|
|
|
43 |
|
|
|
44 |
})
|
|
|
45 |
|
|
|
46 |
@SqlResultSetMappings({
|
|
|
47 |
|
|
|
48 |
@SqlResultSetMapping(name = "HidAllocation",
|
|
|
49 |
classes = {@ConstructorResult(targetClass = HidAllocationModel.class,
|
|
|
50 |
columns = {
|
|
|
51 |
@ColumnResult(name = "fofo_id", type = Integer.class),
|
|
|
52 |
@ColumnResult(name = "catalog_id", type = Integer.class),
|
|
|
53 |
@ColumnResult(name = "model_number", type = String.class),
|
|
|
54 |
@ColumnResult(name = "brand ", type = String.class),
|
|
|
55 |
@ColumnResult(name = "available_stock ", type = Integer.class),
|
|
|
56 |
@ColumnResult(name = "last2DaysSoldQtySum ", type = Integer.class),
|
| 34256 |
ranu |
57 |
@ColumnResult(name = "allocation ", type = Integer.class)
|
| 34163 |
ranu |
58 |
}
|
|
|
59 |
)}
|
|
|
60 |
)
|
|
|
61 |
|
|
|
62 |
})
|
|
|
63 |
|
| 33873 |
ranu |
64 |
public class FofoOpeningStock implements Serializable {
|
|
|
65 |
|
|
|
66 |
@Id
|
|
|
67 |
@Column(name = "id")
|
|
|
68 |
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
69 |
private int id;
|
|
|
70 |
|
|
|
71 |
@Column(name = "fofo_id")
|
|
|
72 |
private int fofoId;
|
|
|
73 |
|
|
|
74 |
@Column(name = "catalog_id")
|
|
|
75 |
private int catalogId;
|
|
|
76 |
|
|
|
77 |
@Column(name = "opening_date")
|
|
|
78 |
private LocalDate openingDate;
|
|
|
79 |
|
|
|
80 |
@Column(name = "opening_qty")
|
|
|
81 |
private int openingQty;
|
|
|
82 |
|
|
|
83 |
@Column(name = "current_qty")
|
|
|
84 |
private int currentQty;
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
public int getId() {
|
|
|
89 |
return id;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
public void setId(int id) {
|
|
|
93 |
this.id = id;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public int getFofoId() {
|
|
|
97 |
return fofoId;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public void setFofoId(int fofoId) {
|
|
|
101 |
this.fofoId = fofoId;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
public int getCatalogId() {
|
|
|
105 |
return catalogId;
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
public void setCatalogId(int catalogId) {
|
|
|
109 |
this.catalogId = catalogId;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public LocalDate getOpeningDate() {
|
|
|
113 |
return openingDate;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
public void setOpeningDate(LocalDate openingDate) {
|
|
|
117 |
this.openingDate = openingDate;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public int getOpeningQty() {
|
|
|
121 |
return openingQty;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public void setOpeningQty(int openingQty) {
|
|
|
125 |
this.openingQty = openingQty;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public int getCurrentQty() {
|
|
|
129 |
return currentQty;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
public void setCurrentQty(int currentQty) {
|
|
|
133 |
this.currentQty = currentQty;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
@Override
|
|
|
137 |
public String toString() {
|
|
|
138 |
return "FofoOpeningStock{" +
|
|
|
139 |
"id=" + id +
|
|
|
140 |
", fofoId=" + fofoId +
|
|
|
141 |
", catalogId=" + catalogId +
|
|
|
142 |
", openingDate=" + openingDate +
|
|
|
143 |
", openingQty=" + openingQty +
|
|
|
144 |
", currentQty=" + currentQty +
|
|
|
145 |
'}';
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
@Override
|
|
|
149 |
public boolean equals(Object o) {
|
|
|
150 |
if (this == o) return true;
|
|
|
151 |
if (o == null || getClass() != o.getClass()) return false;
|
|
|
152 |
FofoOpeningStock that = (FofoOpeningStock) o;
|
|
|
153 |
return id == that.id && fofoId == that.fofoId && catalogId == that.catalogId && openingQty == that.openingQty && currentQty == that.currentQty && Objects.equals(openingDate, that.openingDate);
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
@Override
|
|
|
157 |
public int hashCode() {
|
|
|
158 |
return Objects.hash(id, fofoId, catalogId, openingDate, openingQty, currentQty);
|
|
|
159 |
}
|
|
|
160 |
}
|