Subversion Repositories SmartDukaan

Rev

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