Subversion Repositories SmartDukaan

Rev

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