Subversion Repositories SmartDukaan

Rev

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