Subversion Repositories SmartDukaan

Rev

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