Subversion Repositories SmartDukaan

Rev

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