Subversion Repositories SmartDukaan

Rev

Rev 35856 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21714 ashik.ali 1
package com.spice.profitmandi.dao.entity.fofo;
21552 ashik.ali 2
 
36518 aman 3
import com.fasterxml.jackson.annotation.JsonIgnore;
21639 kshitij.so 4
import com.spice.profitmandi.dao.convertor.LocalDateTimeAttributeConverter;
21714 ashik.ali 5
import com.spice.profitmandi.dao.entity.catalog.Item;
6
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
30523 amit.gupta 7
import org.hibernate.annotations.UpdateTimestamp;
21552 ashik.ali 8
 
30523 amit.gupta 9
import javax.persistence.*;
10
import java.time.LocalDateTime;
11
import java.time.format.DateTimeFormatter;
12
import java.util.Objects;
13
 
21552 ashik.ali 14
@NamedQueries({
33115 shampa 15
        @NamedQuery(name = "InventoryItem.selectScannedCount", query = "select ii.itemId, sum(ii.initialQuantity) from InventoryItem ii "
16
                + "where ii.itemId in :itemIds and ii.fofoId = :fofoId and ii.purchaseId = :purchaseId group by ii.itemId"),
17
        //For Serialized models
18
        @NamedQuery(name = "InventoryItem.selectAllLineItemIdsByInventoryIds", query = "select new com.spice.profitmandi.dao.model.InventoryItemSaleModel(ii.id, lii.id)   from InventoryItem ii" +
19
                " join Purchase p on p.id = ii.purchaseId join Order o on o.invoiceNumber = p.purchaseReference" +
20
                " join LineItem li on li.orderId = o.id join LineItemImei lii on (lii.id=li.id and lii.serialNumber=ii.serialNumber)" +
33182 shampa 21
                "where ii.id in :inventoryItemIds"),
22
 
23
 
35856 amit 24
        @NamedQuery(name = "InventoryItem.selectActivatedStockAmount",
25
                query = "select coalesce(sum(tl.sellingPrice), 0) from InventoryItem ii" +
26
                        " join Item i on i.id = ii.itemId" +
27
                        " join TagListing tl on tl.itemId = i.id" +
28
                        " join ActivatedImei ai on ai.serialNumber = ii.serialNumber" +
29
                        " where ii.goodQuantity = 1 and ai.activationTimestamp is not null" +
30
                        " and i.brand != 'Live Demo' and ii.fofoId = :fofoId"),
31
 
33306 amit.gupta 32
        @NamedQuery(name = "InventoryItem.selectPurchaseSummary",
33
                query = "select new com.spice.profitmandi.dao.model.ItemPurchaseSummaryModel(" +
34
                        "ii.id, o.billingTimestamp,o.invoiceNumber, cast(li.unitPrice as float), li.item)" +
33182 shampa 35
                        "from InventoryItem ii " +
36
                        "join Purchase p on p.id = ii.purchaseId " +
37
                        "join Order o on o.invoiceNumber = p.purchaseReference " +
38
                        "join LineItem li on li.orderId = o.id " +
39
                        "join LineItemImei lii on (lii.lineItemId=li.id and lii.serialNumber=ii.serialNumber) " +
33306 amit.gupta 40
                        "where ii.id in :inventoryItemIds")
33182 shampa 41
 
42
 
31163 amit.gupta 43
})
21552 ashik.ali 44
@Entity
31860 tejbeer 45
@Table(name = "fofo.inventory_item")
23983 amit.gupta 46
public class InventoryItem implements Comparable {
26213 amit.gupta 47
 
33115 shampa 48
    public InventoryItem(String serialNumber) {
49
        this.serialNumber = serialNumber;
50
    }
26213 amit.gupta 51
 
33115 shampa 52
    public InventoryItem() {
26213 amit.gupta 53
 
33115 shampa 54
    }
26213 amit.gupta 55
 
33115 shampa 56
    @Id
57
    @Column(name = "id", unique = true, updatable = false)
58
    @GeneratedValue(strategy = GenerationType.IDENTITY)
59
    private int id;
26213 amit.gupta 60
 
33115 shampa 61
    @Column(name = "item_id")
62
    private int itemId;
26213 amit.gupta 63
 
33115 shampa 64
    @Column(name = "fofo_id")
65
    private int fofoId;
26213 amit.gupta 66
 
33115 shampa 67
    @Column(name = "serial_number", length = 100)
68
    private String serialNumber;
26213 amit.gupta 69
 
33115 shampa 70
    @Column(name = "initial_quantity")
71
    private int initialQuantity;
26213 amit.gupta 72
 
33115 shampa 73
    @Column(name = "good_quantity")
74
    private int goodQuantity;
26213 amit.gupta 75
 
33115 shampa 76
    @Column(name = "bad_quantity")
77
    private int badQuantity;
31163 amit.gupta 78
 
33115 shampa 79
    @Column(name = "activation_timestamp")
80
    private LocalDateTime activationTimestamp;
26213 amit.gupta 81
 
33115 shampa 82
    @Column(name = "last_scan_type")
83
    @Enumerated(EnumType.STRING)
84
    private ScanType lastScanType;
26213 amit.gupta 85
 
33115 shampa 86
    @Column(name = "purchase_id")
87
    private int purchaseId;
26213 amit.gupta 88
 
33115 shampa 89
    @Column(name = "unit_price")
90
    private float unitPrice;
26213 amit.gupta 91
 
33115 shampa 92
    @Column(name = "price_drop_amount")
93
    private float priceDropAmount;
26213 amit.gupta 94
 
33115 shampa 95
    @Column(name = "buy_back", columnDefinition = "tinyint(1) default 1")
96
    private boolean buyBack;
26213 amit.gupta 97
 
33115 shampa 98
    @Column(name = "igst_rate")
99
    private float igstRate;
26213 amit.gupta 100
 
33115 shampa 101
    @Column(name = "cgst_rate")
102
    private float cgstRate;
26213 amit.gupta 103
 
33115 shampa 104
    @Column(name = "sgst_rate")
105
    private float sgstRate;
26213 amit.gupta 106
 
33115 shampa 107
    @Column(name = "hsn_code")
108
    private String hsnCode;
26213 amit.gupta 109
 
33115 shampa 110
    @Convert(converter = LocalDateTimeAttributeConverter.class)
111
    @Column(name = "create_timestamp")
112
    private LocalDateTime createTimestamp = LocalDateTime.now();
26213 amit.gupta 113
 
33115 shampa 114
    @Convert(converter = LocalDateTimeAttributeConverter.class)
115
    @Column(name = "update_timestamp")
116
    @UpdateTimestamp
117
    private LocalDateTime updateTimestamp = LocalDateTime.now();
26213 amit.gupta 118
 
36518 aman 119
    @JsonIgnore
33115 shampa 120
    @OneToOne(fetch = FetchType.LAZY)
121
    @JoinColumn(name = "item_id", insertable = false, updatable = false, nullable = false, referencedColumnName = "id")
122
    private Item item;
26213 amit.gupta 123
 
36518 aman 124
    @JsonIgnore
33115 shampa 125
    @OneToOne(fetch = FetchType.LAZY)
126
    @JoinColumn(name = "purchase_id", insertable = false, updatable = false, nullable = false, referencedColumnName = "id")
127
    private Purchase purchase;
26213 amit.gupta 128
 
33115 shampa 129
    public void setUnitPrice(float unitPrice) {
130
        this.unitPrice = unitPrice;
131
    }
26213 amit.gupta 132
 
33115 shampa 133
    @Transient
134
    private String itemDescription;
21552 ashik.ali 135
 
33115 shampa 136
    @Transient
137
    private LocalDateTime activatedTimestamp;
30523 amit.gupta 138
 
33115 shampa 139
    @Transient
140
    private boolean priceDropValidated = true;
30523 amit.gupta 141
 
33115 shampa 142
    @Transient
143
    private String pdValidationFailedReason = null;
30523 amit.gupta 144
 
33115 shampa 145
    @Override
146
    public boolean equals(Object o) {
147
        if (this == o) return true;
148
        if (o == null || getClass() != o.getClass()) return false;
149
        InventoryItem that = (InventoryItem) o;
150
        return id == that.id && itemId == that.itemId && fofoId == that.fofoId && initialQuantity == that.initialQuantity && goodQuantity == that.goodQuantity && badQuantity == that.badQuantity && purchaseId == that.purchaseId && Float.compare(that.unitPrice, unitPrice) == 0 && Float.compare(that.priceDropAmount, priceDropAmount) == 0 && buyBack == that.buyBack && Float.compare(that.igstRate, igstRate) == 0 && Float.compare(that.cgstRate, cgstRate) == 0 && Float.compare(that.sgstRate, sgstRate) == 0 && priceDropValidated == that.priceDropValidated && pdValidationFailedReason == that.pdValidationFailedReason && Objects.equals(serialNumber, that.serialNumber) && Objects.equals(activationTimestamp, that.activationTimestamp) && lastScanType == that.lastScanType && Objects.equals(hsnCode, that.hsnCode) && Objects.equals(createTimestamp, that.createTimestamp) && Objects.equals(updateTimestamp, that.updateTimestamp) && Objects.equals(item, that.item) && Objects.equals(purchase, that.purchase) && Objects.equals(itemDescription, that.itemDescription) && Objects.equals(activatedTimestamp, that.activatedTimestamp);
151
    }
30523 amit.gupta 152
 
33115 shampa 153
    @Override
154
    public int hashCode() {
155
        return Objects.hash(id, itemId, fofoId, serialNumber, initialQuantity, goodQuantity, badQuantity, activationTimestamp, lastScanType, purchaseId, unitPrice, priceDropAmount, buyBack, igstRate, cgstRate, sgstRate, hsnCode, createTimestamp, updateTimestamp, item, purchase, itemDescription, activatedTimestamp, priceDropValidated, pdValidationFailedReason);
156
    }
30523 amit.gupta 157
 
33115 shampa 158
    public String getPdValidationFailedReason() {
159
        return pdValidationFailedReason;
160
    }
30523 amit.gupta 161
 
33115 shampa 162
    public void setPdValidationFailedReason(String pdValidationFailedReason) {
163
        this.pdValidationFailedReason = pdValidationFailedReason;
164
    }
30523 amit.gupta 165
 
33115 shampa 166
    @Override
167
    public String toString() {
168
        return "InventoryItem{" +
169
                "id=" + id +
170
                ", itemId=" + itemId +
171
                ", fofoId=" + fofoId +
172
                ", serialNumber='" + serialNumber + '\'' +
173
                ", initialQuantity=" + initialQuantity +
174
                ", goodQuantity=" + goodQuantity +
175
                ", badQuantity=" + badQuantity +
176
                ", activationTimestamp=" + activationTimestamp +
177
                ", lastScanType=" + lastScanType +
178
                ", purchaseId=" + purchaseId +
179
                ", unitPrice=" + unitPrice +
180
                ", priceDropAmount=" + priceDropAmount +
181
                ", buyBack=" + buyBack +
182
                ", igstRate=" + igstRate +
183
                ", cgstRate=" + cgstRate +
184
                ", sgstRate=" + sgstRate +
185
                ", hsnCode='" + hsnCode + '\'' +
186
                ", createTimestamp=" + createTimestamp +
187
                ", updateTimestamp=" + updateTimestamp +
188
                ", item=" + item +
189
                ", purchase=" + purchase +
190
                ", itemDescription='" + itemDescription + '\'' +
191
                ", activatedTimestamp=" + activatedTimestamp +
192
                ", priceDropValidated=" + priceDropValidated +
193
                ", pdValidationFailedReason='" + pdValidationFailedReason + '\'' +
194
                '}';
195
    }
30523 amit.gupta 196
 
33115 shampa 197
    public LocalDateTime getActivatedTimestamp() {
198
        return activatedTimestamp;
199
    }
26304 amit.gupta 200
 
33115 shampa 201
    public void setActivatedTimestamp(LocalDateTime activatedTimestamp) {
202
        this.activatedTimestamp = activatedTimestamp;
203
    }
26304 amit.gupta 204
 
33115 shampa 205
    public int getId() {
206
        return id;
207
    }
21552 ashik.ali 208
 
33115 shampa 209
    public void setId(int id) {
210
        this.id = id;
211
    }
21552 ashik.ali 212
 
33115 shampa 213
    public int getItemId() {
214
        return itemId;
215
    }
21552 ashik.ali 216
 
33115 shampa 217
    public void setItemId(int itemId) {
218
        this.itemId = itemId;
219
    }
26213 amit.gupta 220
 
33115 shampa 221
    public void setFofoId(int fofoId) {
222
        this.fofoId = fofoId;
223
    }
21552 ashik.ali 224
 
33115 shampa 225
    public int getFofoId() {
226
        return fofoId;
227
    }
21552 ashik.ali 228
 
33115 shampa 229
    public String getSerialNumber() {
230
        return serialNumber == null ? serialNumber : serialNumber.toLowerCase();
231
    }
26213 amit.gupta 232
 
33115 shampa 233
    public void setSerialNumber(String serialNumber) {
234
        this.serialNumber = serialNumber == null ? serialNumber : serialNumber.toLowerCase();
235
    }
26213 amit.gupta 236
 
33115 shampa 237
    public int getInitialQuantity() {
238
        return initialQuantity;
239
    }
21552 ashik.ali 240
 
33115 shampa 241
    public float getUnitPrice() {
242
        return unitPrice;
243
    }
21984 kshitij.so 244
 
33115 shampa 245
    public void setUnitPrice(Float unitPrice) {
246
        this.unitPrice = unitPrice;
247
    }
21984 kshitij.so 248
 
33115 shampa 249
    public void setInitialQuantity(int initialQuantity) {
250
        this.initialQuantity = initialQuantity;
251
    }
26213 amit.gupta 252
 
33115 shampa 253
    public float getNetPrice() {
254
        return unitPrice - priceDropAmount;
255
    }
21552 ashik.ali 256
 
33115 shampa 257
    public int getGoodQuantity() {
258
        return goodQuantity;
259
    }
21552 ashik.ali 260
 
33115 shampa 261
    public void setGoodQuantity(int goodQuantity) {
262
        this.goodQuantity = goodQuantity;
263
    }
21552 ashik.ali 264
 
33115 shampa 265
    public int getBadQuantity() {
266
        return badQuantity;
267
    }
21552 ashik.ali 268
 
33115 shampa 269
    public void setBadQuantity(int badQuantity) {
270
        this.badQuantity = badQuantity;
271
    }
21552 ashik.ali 272
 
33115 shampa 273
    public ScanType getLastScanType() {
274
        return lastScanType;
275
    }
21552 ashik.ali 276
 
33115 shampa 277
    public void setLastScanType(ScanType lastScanType) {
278
        this.lastScanType = lastScanType;
279
    }
26213 amit.gupta 280
 
33115 shampa 281
    public int getPurchaseId() {
282
        return purchaseId;
283
    }
26213 amit.gupta 284
 
33115 shampa 285
    public void setPurchaseId(int purchaseId) {
286
        this.purchaseId = purchaseId;
287
    }
26213 amit.gupta 288
 
33115 shampa 289
    public float getPriceDropAmount() {
290
        return priceDropAmount;
291
    }
26213 amit.gupta 292
 
33115 shampa 293
    public void setPriceDropAmount(float priceDropAmount) {
294
        this.priceDropAmount = priceDropAmount;
295
    }
26213 amit.gupta 296
 
33115 shampa 297
    public float getIgstRate() {
298
        return igstRate;
299
    }
26213 amit.gupta 300
 
33115 shampa 301
    public void setIgstRate(float igstRate) {
302
        this.igstRate = igstRate;
303
    }
26213 amit.gupta 304
 
33115 shampa 305
    public float getCgstRate() {
306
        return cgstRate;
307
    }
26213 amit.gupta 308
 
33115 shampa 309
    public void setCgstRate(float cgstRate) {
310
        this.cgstRate = cgstRate;
311
    }
26213 amit.gupta 312
 
33115 shampa 313
    public float getSgstRate() {
314
        return sgstRate;
315
    }
26213 amit.gupta 316
 
33115 shampa 317
    public void setSgstRate(float sgstRate) {
318
        this.sgstRate = sgstRate;
319
    }
26213 amit.gupta 320
 
33115 shampa 321
    public String getHsnCode() {
322
        return hsnCode;
323
    }
26213 amit.gupta 324
 
33115 shampa 325
    public void setHsnCode(String hsnCode) {
326
        this.hsnCode = hsnCode;
327
    }
21552 ashik.ali 328
 
33115 shampa 329
    public LocalDateTime getCreateTimestamp() {
330
        return createTimestamp;
331
    }
21552 ashik.ali 332
 
33115 shampa 333
    public void setCreateTimestamp(LocalDateTime createTimestamp) {
334
        this.createTimestamp = createTimestamp;
335
    }
26213 amit.gupta 336
 
33115 shampa 337
    public LocalDateTime getUpdateTimestamp() {
338
        return updateTimestamp;
339
    }
26213 amit.gupta 340
 
33115 shampa 341
    public void setUpdateTimestamp(LocalDateTime updateTimestamp) {
342
        this.updateTimestamp = updateTimestamp;
343
    }
26213 amit.gupta 344
 
33115 shampa 345
    public Item getItem() {
346
        return item;
347
    }
26213 amit.gupta 348
 
33115 shampa 349
    public void setItem(Item item) {
350
        this.item = item;
351
    }
21602 ashik.ali 352
 
33115 shampa 353
    public boolean isBuyBack() {
354
        return buyBack;
355
    }
26213 amit.gupta 356
 
33115 shampa 357
    public void setBuyBack(boolean buyBack) {
358
        this.buyBack = buyBack;
359
    }
26213 amit.gupta 360
 
33115 shampa 361
    public Purchase getPurchase() {
362
        return purchase;
363
    }
26213 amit.gupta 364
 
33115 shampa 365
    public double getMarginPercentage(double amount) {
366
        return amount / this.getNetPrice() * (100 + this.getCgstRate() + this.getIgstRate() + this.getSgstRate());
367
    }
30652 amit.gupta 368
 
33115 shampa 369
    public void setPurchase(Purchase purchase) {
370
        this.purchase = purchase;
371
    }
26213 amit.gupta 372
 
33115 shampa 373
    public String getFormattedCreateTimestamp() {
374
        if (createTimestamp == null) {
375
            return null;
376
        }
377
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
378
        return createTimestamp.format(formatter);
379
    }
26213 amit.gupta 380
 
33115 shampa 381
    public String getItemDescription() {
382
        return itemDescription;
383
    }
26213 amit.gupta 384
 
33115 shampa 385
    public void setItemDescription(String itemDescription) {
386
        this.itemDescription = itemDescription;
387
    }
26213 amit.gupta 388
 
33115 shampa 389
    public LocalDateTime getActivationTimestamp() {
390
        return activationTimestamp;
391
    }
29093 amit.gupta 392
 
33115 shampa 393
    public void setActivationTimestamp(LocalDateTime activationTimestamp) {
394
        this.activationTimestamp = activationTimestamp;
395
    }
29093 amit.gupta 396
 
33115 shampa 397
    public boolean isPriceDropValidated() {
398
        return priceDropValidated;
399
    }
29093 amit.gupta 400
 
33115 shampa 401
    public void setPriceDropValidated(boolean priceDropValidated) {
402
        this.priceDropValidated = priceDropValidated;
403
    }
29093 amit.gupta 404
 
33115 shampa 405
    @Override
406
    public int compareTo(Object o) {
407
        return o.hashCode() - this.hashCode();
408
    }
26213 amit.gupta 409
 
21552 ashik.ali 410
}