Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
33772 amit.gupta 1
package com.spice.profitmandi.dao.entity.catalog;
2
 
3
import javax.persistence.*;
4
import java.time.LocalDateTime;
5
import java.util.Objects;
6
 
35343 ranu 7
 
8
@NamedQueries({
9
        @NamedQuery(name = "Catalog.findOtherORNullCategoryAndInStock", query = "select i.catalogItemId "
10
                + " from WarehouseInventoryItem wi "
11
                + " join Item i on i.id = wi.itemId"
12
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
35356 ranu 13
                + " where ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) and i.brand= :brand group by i.catalogItemId having sum(wi.currentQuantity) > 0"),
35343 ranu 14
 
15
        @NamedQuery(name = "Catalog.findOtherORNullCategoryAndPartnerInStock", query = "select i.catalogItemId "
16
                + " from CurrentInventorySnapshot cis "
17
                + " join Item i on i.id = cis.itemId"
18
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
35356 ranu 19
                + " where  ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) and i.brand= :brand and cis.fofoId = :fofoId group by i.catalogItemId having sum(cis.availability) > 0"),
35357 ranu 20
 
35365 ranu 21
        @NamedQuery(name = "Catalog.findAllWithEOLWithOutStock", query = "select i.catalogItemId "
35359 ranu 22
                + " from Item i "
23
                + " left join  WarehouseInventoryItem wi on i.id = wi.itemId"
35357 ranu 24
                + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
35426 ranu 25
                + " where ((cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING')) and i.categoryId in (10006,10009,10010) group by i.catalogItemId having (sum(wi.currentQuantity) = 0 OR sum(wi.currentQuantity) IS NULL)"),
35357 ranu 26
 
35487 ranu 27
        @NamedQuery(name = "Catalog.selectAllStatusAndBrandWise", query = "select c.id" +
28
                " from Catalog c " +
29
                " join CategorisedCatalog cc on c.id = cc.catalogId and cc.endDate is null" +
30
                " where cc.status in  (:statuses) and c.brand in :brands"),
35426 ranu 31
 
35501 ranu 32
        @NamedQuery(name = "Catalog.selectAllGoodStockBrandWise", query = "SELECT DISTINCT c " +
33
                "FROM Catalog c " +
34
                "         JOIN Item i ON i.catalogItemId = c.id " +
35
                "         JOIN CategorisedCatalog cc ON c.id = cc.catalogId and cc.endDate is null " +
36
                "         JOIN WarehouseInventoryItem wi ON wi.itemId = i.id " +
37
                " WHERE " +
38
                "        i.categoryId IN (10006) " +
39
                "  AND (wi.lastScanType NOT IN (:scanTypes) OR wi.lastScanType IS NULL) " +
40
                " " +
41
                "  AND ( " +
42
                "        (cc.status NOT IN (:movingStatus) AND cc.status IS NOT NULL) " +
43
                "        OR " +
44
                "        wi.currentQuantity > 0 " +
45
                "    ) " +
46
                " and c.brand = :brand " +
47
                " GROUP BY c.id"),
35487 ranu 48
 
35501 ranu 49
 
35426 ranu 50
        @NamedQuery(
51
                name = "Catalog.findAllWithNoGoodStock",
52
                query = "select i.catalogItemId "
53
                        + " from Item i "
54
                        + " left join WarehouseInventoryItem wi on i.id = wi.itemId "
55
                        + " left join CategorisedCatalog cc on cc.catalogId = i.catalogItemId and cc.endDate is null "
56
                        + " where (cc.status is null OR cc.status = 'OTHER' OR cc.status = 'SLOWMOVING') "
57
                        + " and i.categoryId in (10006, 10009, 10010) "
58
                        + " group by i.catalogItemId "
59
                        + " having "
60
                        + "   sum(case when (wi.lastScanType is null OR wi.lastScanType NOT IN (:scanTypes)) "
61
                        + "            then wi.currentQuantity else 0 end) = 0 "
62
                        + "   OR sum(wi.currentQuantity) IS NULL"
63
        )
64
 
35343 ranu 65
})
66
 
33772 amit.gupta 67
@Entity
68
@Table(name = "catalog.catalog")
69
public class Catalog {
70
    @Id
71
    @GeneratedValue(strategy = GenerationType.IDENTITY)
72
    @Column(name = "id", columnDefinition = "int(11)")
73
    private int id;
74
 
75
    @Column(name="brand_id")
76
    private int brandId;
77
 
78
    @Column
79
    private String brand;
80
 
81
    @Column(name="model_number")
82
    private String modelNumber;
83
 
84
    @Column(name="model_name")
85
    private String modelName;
86
 
33888 ranu 87
    @Column(name = "category_id")
88
    private int categoryId;
89
 
33772 amit.gupta 90
    @Column(name="created_by")
91
    private String createdBy;
92
 
93
    @Column
94
    private LocalDateTime created;
95
 
36557 amit 96
    @Column(name = "is_flagship")
97
    private boolean flagship;
98
 
33772 amit.gupta 99
    public int getId() {
100
        return id;
101
    }
102
 
103
    public void setId(int id) {
104
        this.id = id;
105
    }
106
 
107
    public int getBrandId() {
108
        return brandId;
109
    }
110
 
111
    public void setBrandId(int brandId) {
112
        this.brandId = brandId;
113
    }
114
 
115
    public String getBrand() {
116
        return brand;
117
    }
118
 
119
    public void setBrand(String brand) {
120
        this.brand = brand;
121
    }
122
 
123
    public String getModelNumber() {
124
        return modelNumber;
125
    }
126
 
127
    public void setModelNumber(String modelNumber) {
128
        this.modelNumber = modelNumber;
129
    }
130
 
131
    public String getModelName() {
132
        return modelName;
133
    }
134
 
135
    public void setModelName(String modelName) {
136
        this.modelName = modelName;
137
    }
138
 
139
    public String getCreatedBy() {
140
        return createdBy;
141
    }
142
 
143
    public void setCreatedBy(String createdBy) {
144
        this.createdBy = createdBy;
145
    }
146
 
147
    public LocalDateTime getCreated() {
148
        return created;
149
    }
150
 
151
    public void setCreated(LocalDateTime created) {
152
        this.created = created;
153
    }
154
 
36557 amit 155
    public boolean isFlagship() {
156
        return flagship;
157
    }
158
 
159
    public void setFlagship(boolean flagship) {
160
        this.flagship = flagship;
161
    }
162
 
33888 ranu 163
    public int getCategoryId() {
164
        return categoryId;
165
    }
166
 
167
    public void setCategoryId(int categoryId) {
168
        this.categoryId = categoryId;
169
    }
170
 
33772 amit.gupta 171
    @Override
172
    public boolean equals(Object o) {
173
        if (this == o) return true;
174
        if (o == null || getClass() != o.getClass()) return false;
175
        Catalog catalog = (Catalog) o;
33888 ranu 176
        return id == catalog.id && brandId == catalog.brandId && categoryId == catalog.categoryId && Objects.equals(brand, catalog.brand) && Objects.equals(modelNumber, catalog.modelNumber) && Objects.equals(modelName, catalog.modelName) && Objects.equals(createdBy, catalog.createdBy) && Objects.equals(created, catalog.created);
33772 amit.gupta 177
    }
178
 
179
    @Override
33888 ranu 180
    public int hashCode() {
181
        return Objects.hash(id, brandId, brand, modelNumber, modelName, categoryId, createdBy, created);
182
    }
183
 
33916 amit.gupta 184
    public String getDescription() {
185
        StringBuilder itemString = new StringBuilder();
186
        if (this.getBrand() != null && !this.getBrand().isEmpty()) {
187
            itemString.append(this.getBrand().trim());
188
        }
189
        itemString.append(" ");
190
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
191
            itemString.append(this.getModelName().trim());
192
        }
193
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
194
            itemString.append(" ");
195
            itemString.append(this.getModelNumber().trim());
196
        }
197
 
198
        return itemString.toString().replaceAll("\\s+", " ").trim();
199
    }
200
 
35188 amit 201
    public String getDescriptionNoBrand() {
202
        StringBuilder itemString = new StringBuilder();
203
        itemString.append(" ");
204
        if (this.getModelName() != null && !this.getModelName().isEmpty()) {
205
            itemString.append(this.getModelName().trim());
206
        }
207
        if (this.getModelNumber() != null && !this.getModelNumber().isEmpty()) {
208
            itemString.append(" ");
209
            itemString.append(this.getModelNumber().trim());
210
        }
211
 
212
        return itemString.toString().replaceAll("\\s+", " ").trim();
213
    }
214
 
33888 ranu 215
    @Override
33772 amit.gupta 216
    public String toString() {
217
        return "Catalog{" +
218
                "id=" + id +
219
                ", brandId=" + brandId +
220
                ", brand='" + brand + '\'' +
221
                ", modelNumber='" + modelNumber + '\'' +
222
                ", modelName='" + modelName + '\'' +
33888 ranu 223
                ", categoryId=" + categoryId +
33772 amit.gupta 224
                ", createdBy='" + createdBy + '\'' +
225
                ", created=" + created +
226
                '}';
227
    }
228
 
229
}
230