Subversion Repositories SmartDukaan

Rev

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