Subversion Repositories SmartDukaan

Rev

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