Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
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
                        "    COALESCE(sale2.last3rddaysale, 0) AS lastThirdDaySoldQty," +
25
                        "   (CASE" +
26
                        "         WHEN ((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0) = 0)" +
27
                        "             OR (COALESCE(SUM(os.current_qty), 0) = 0) THEN 2" +
28
                        "         ELSE ROUND((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0))" +
29
                        "        END) AS allocation ," +
30
                        "    (CASE" +
31
                        "         WHEN ROUND((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0)) > 0" +
32
                        "             THEN ROUND((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0))" +
33
                        "             - COALESCE(SUM(os.current_qty), 0)" +
34
                        "         WHEN ((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0) = 0)" +
35
                        "             OR (COALESCE(SUM(os.current_qty), 0) = 0) THEN 2" +
36
                        "         ELSE 0" +
37
                        "        END) AS purchase_limit" +
38
                        " FROM catalog.catagoriesd_catalog cc" +
39
                        "         LEFT JOIN fofo.fofo_opening_stock os ON os.catalog_id = cc.catalog_id AND os.fofo_id = :fofoId" +
40
                        "         LEFT JOIN (" +
41
                        "    SELECT o.fofo_id, ci.catalog_item_id, SUM(oi.quantity) AS last2daysSale" +
42
                        "    FROM fofo.fofo_order o" +
43
                        "             JOIN fofo.fofo_order_item oi ON o.id = oi.order_id" +
44
                        "             JOIN catalog.item ci ON oi.item_id = ci.id" +
45
                        "    WHERE DATE(o.create_timestamp) BETWEEN (CURDATE() - INTERVAL 2 DAY) AND CURDATE()" +
46
                        "    GROUP BY o.fofo_id, ci.catalog_item_id" +
47
                        ") sale1 ON sale1.catalog_item_id = os.catalog_id AND os.fofo_id = sale1.fofo_id" +
48
                        "         LEFT JOIN (" +
49
                        "    SELECT o.fofo_id, ci.catalog_item_id, SUM(oi.quantity) AS last3rddaysale" +
50
                        "    FROM fofo.fofo_order o" +
51
                        "             JOIN fofo.fofo_order_item oi ON o.id = oi.order_id" +
52
                        "             JOIN catalog.item ci ON oi.item_id = ci.id" +
53
                        "    WHERE DATE(o.create_timestamp) = CURDATE() - INTERVAL 3 DAY" +
54
                        "    GROUP BY o.fofo_id, ci.catalog_item_id" +
55
                        ") sale2 ON sale2.catalog_item_id = os.catalog_id AND os.fofo_id = sale2.fofo_id" +
56
                        "         JOIN catalog.catalog c ON c.id = cc.catalog_id" +
57
                        " WHERE cc.end_date IS NULL AND cc.status = 'HID'" +
58
                        "GROUP BY cc.catalog_id",
59
                resultSetMapping = "HidAllocation"),
60
 
61
})
62
 
63
@SqlResultSetMappings({
64
 
65
        @SqlResultSetMapping(name = "HidAllocation",
66
                classes = {@ConstructorResult(targetClass = HidAllocationModel.class,
67
                        columns = {
68
                                @ColumnResult(name = "fofo_id", type = Integer.class),
69
                                @ColumnResult(name = "catalog_id", type = Integer.class),
70
                                @ColumnResult(name = "model_number", type = String.class),
71
                                @ColumnResult(name = "brand ", type = String.class),
72
                                @ColumnResult(name = "available_stock ", type = Integer.class),
73
                                @ColumnResult(name = "last2DaysSoldQtySum ", type = Integer.class),
74
                                @ColumnResult(name = "lastThirdDaySoldQty ", type = Integer.class),
75
                                @ColumnResult(name = "allocation ", type = Integer.class),
76
                                @ColumnResult(name = "purchase_limit ", type = Integer.class),
77
                        }
78
                )}
79
        )
80
 
81
})
82
 
33873 ranu 83
public class FofoOpeningStock implements Serializable {
84
 
85
    @Id
86
    @Column(name = "id")
87
    @GeneratedValue(strategy = GenerationType.IDENTITY)
88
    private int id;
89
 
90
    @Column(name = "fofo_id")
91
    private int fofoId;
92
 
93
    @Column(name = "catalog_id")
94
    private int catalogId;
95
 
96
    @Column(name = "opening_date")
97
    private LocalDate openingDate;
98
 
99
    @Column(name = "opening_qty")
100
    private int openingQty;
101
 
102
    @Column(name = "current_qty")
103
    private int currentQty;
104
 
105
 
106
 
107
    public int getId() {
108
        return id;
109
    }
110
 
111
    public void setId(int id) {
112
        this.id = id;
113
    }
114
 
115
    public int getFofoId() {
116
        return fofoId;
117
    }
118
 
119
    public void setFofoId(int fofoId) {
120
        this.fofoId = fofoId;
121
    }
122
 
123
    public int getCatalogId() {
124
        return catalogId;
125
    }
126
 
127
    public void setCatalogId(int catalogId) {
128
        this.catalogId = catalogId;
129
    }
130
 
131
    public LocalDate getOpeningDate() {
132
        return openingDate;
133
    }
134
 
135
    public void setOpeningDate(LocalDate openingDate) {
136
        this.openingDate = openingDate;
137
    }
138
 
139
    public int getOpeningQty() {
140
        return openingQty;
141
    }
142
 
143
    public void setOpeningQty(int openingQty) {
144
        this.openingQty = openingQty;
145
    }
146
 
147
    public int getCurrentQty() {
148
        return currentQty;
149
    }
150
 
151
    public void setCurrentQty(int currentQty) {
152
        this.currentQty = currentQty;
153
    }
154
 
155
    @Override
156
    public String toString() {
157
        return "FofoOpeningStock{" +
158
                "id=" + id +
159
                ", fofoId=" + fofoId +
160
                ", catalogId=" + catalogId +
161
                ", openingDate=" + openingDate +
162
                ", openingQty=" + openingQty +
163
                ", currentQty=" + currentQty +
164
                '}';
165
    }
166
 
167
    @Override
168
    public boolean equals(Object o) {
169
        if (this == o) return true;
170
        if (o == null || getClass() != o.getClass()) return false;
171
        FofoOpeningStock that = (FofoOpeningStock) o;
172
        return id == that.id && fofoId == that.fofoId && catalogId == that.catalogId && openingQty == that.openingQty && currentQty == that.currentQty && Objects.equals(openingDate, that.openingDate);
173
    }
174
 
175
    @Override
176
    public int hashCode() {
177
        return Objects.hash(id, fofoId, catalogId, openingDate, openingQty, currentQty);
178
    }
179
}