Subversion Repositories SmartDukaan

Rev

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