Subversion Repositories SmartDukaan

Rev

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