]> git.mxchange.org Git - jbonuscard-core.git/blob - src/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItem.java
Continued:
[jbonuscard-core.git] / src / org / mxchange / jfinancials / model / receipt_item / FinancialReceiptItem.java
1 /*
2  * Copyright (C) 2016 - 2018 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jfinancials.model.receipt_item;
18
19 import java.math.BigDecimal;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
37 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
38 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
39 import org.mxchange.jfinancials.model.receipt.BillableReceipt;
40 import org.mxchange.jfinancials.model.receipt.FinancialReceipt;
41 import org.mxchange.jproduct.model.category.Category;
42 import org.mxchange.jproduct.model.category.ProductCategory;
43 import org.mxchange.jproduct.model.product.GenericProduct;
44 import org.mxchange.jproduct.model.product.Product;
45
46 /**
47  * A POJO for receipt items
48  * <p>
49  * @author Roland Häder<roland@mxchange.org>
50  */
51 @Entity (name = "receipt_items")
52 @Table (
53                 name = "receipt_items"
54 )
55 @NamedQueries (
56                 {
57                         @NamedQuery (name = "AllReceiptItems", query = "SELECT ri FROM receipt_items AS ri ORDER BY ri.itemId ASC"),
58                         @NamedQuery (name = "SearchAssignedReceiptItems", query = "SELECT ri FROM receipt_items AS ri WHERE ri.itemReceipt = :itemReceipt ORDER BY ri.itemId ASC"),
59                         @NamedQuery (name = "SearchAllUserReceiptItems", query = "SELECT ri FROM receipt_items AS ri JOIN receipts AS r ON ri.itemReceipt=r WHERE r.receiptUser = :receiptUser ORDER BY ri.itemId ASC")
60                 }
61 )
62 @SuppressWarnings ("PersistenceUnitPresent")
63 public class FinancialReceiptItem implements BillableReceiptItem {
64
65         /**
66          * Serial number
67          */
68         @Transient
69         private static final long serialVersionUID = 126_498_698_378_571L;
70
71         /**
72          * Item branding
73          */
74         @Column (name = "item_brand_name")
75         private String itemBrandName;
76
77         /**
78          * Category being assigned to item's product
79          */
80         @JoinColumn (name = "item_category_id", referencedColumnName = "category_id", updatable = false)
81         @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
82         private Category itemCategory;
83
84         /**
85          * Item 's coupon number
86          */
87         @Column (name = "item_coupon_number")
88         private String itemCouponNumber;
89
90         /**
91          * When this item has been created in database
92          */
93         @Basic (optional = false)
94         @Temporal (TemporalType.TIMESTAMP)
95         @Column (name = "item_created", nullable = false)
96         private Date itemCreated;
97
98         /**
99          * Gross price of item
100          */
101         @Basic (optional = false)
102         @Column (name = "item_gross_price", nullable = false, precision = 10, scale = 2)
103         private BigDecimal itemGrossPrice;
104
105         /**
106          * Primary key
107          */
108         @Id
109         @GeneratedValue (strategy = GenerationType.IDENTITY)
110         @Column (name = "item_id", nullable = false, updatable = false)
111         private Long itemId;
112
113         /**
114          * Whether the item is a discount on whole receipt or single item
115          */
116         @Basic (optional = false)
117         @Column (name = "item_is_discount", nullable = false)
118         private Boolean itemIsDiscount;
119
120         /**
121          * Whether the item is a refund
122          */
123         @Basic (optional = false)
124         @Column (name = "item_is_refund", nullable = false)
125         private Boolean itemIsRefund;
126
127         /**
128          * Manufacturer/producer of this item
129          */
130         @JoinColumn (name = "item_manufacturer_id", referencedColumnName = "company_data_id")
131         @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH)
132         private BasicData itemManufacturer;
133
134         /**
135          * Net price of item
136          */
137         @Column (name = "item_net_price", precision = 10, scale = 2)
138         private BigDecimal itemNetPrice;
139
140         /**
141          * Item's number
142          */
143         @Column (name = "item_number")
144         private Long itemNumber;
145
146         /**
147          * Product being linked in this itemReceipt item
148          */
149         @JoinColumn (name = "item_product_id", referencedColumnName = "product_id", nullable = false, updatable = false)
150         @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH, optional = false)
151         private Product itemProduct;
152
153         /**
154          * Product quantity
155          */
156         @Basic (optional = false)
157         @Column (name = "item_product_quantity", nullable = false, precision = 3)
158         private BigDecimal itemProductQuantity;
159
160         /**
161          * Connected itemReceipt item
162          */
163         @JoinColumn (name = "item_receipt_id", referencedColumnName = "receipt_id", nullable = false, updatable = false)
164         @OneToOne (targetEntity = FinancialReceipt.class, cascade = CascadeType.REFRESH, optional = false)
165         private BillableReceipt itemReceipt;
166
167         /**
168          * Tax rate
169          */
170         @Column (name = "item_tax_rate", precision = 2)
171         private BigDecimal itemTaxRate;
172
173         /**
174          * Default constructor
175          */
176         public FinancialReceiptItem () {
177         }
178
179         /**
180          * Constructor with product, price, quantity and receipt instance
181          * <p>
182          * @param itemProduct         Product instance
183          * @param itemProductQuantity Product quantity
184          * @param itemReceipt         FinancialReceipt instance
185          */
186         public FinancialReceiptItem (final Product itemProduct, final BigDecimal itemProductQuantity, final BillableReceipt itemReceipt) {
187                 // Call other constructor
188                 this();
189
190                 // Set all values
191                 this.itemCategory = itemProduct.getProductCategory();
192                 this.itemProduct = itemProduct;
193                 this.itemProductQuantity = itemProductQuantity;
194                 this.itemReceipt = itemReceipt;
195         }
196
197         @Override
198         public boolean equals (final Object object) {
199                 if (this == object) {
200                         return true;
201                 } else if (null == object) {
202                         return false;
203                 } else if (this.getClass() != object.getClass()) {
204                         return false;
205                 }
206
207                 final BillableReceiptItem receiptItem = (BillableReceiptItem) object;
208
209                 if (!Objects.equals(this.getItemId(), receiptItem.getItemId())) {
210                         return false;
211                 } else if (!Objects.equals(this.getItemProduct(), receiptItem.getItemProduct())) {
212                         return false;
213                 } else if (!Objects.equals(this.getItemProductQuantity(), receiptItem.getItemProductQuantity())) {
214                         return false;
215                 } else if (!Objects.equals(this.getItemReceipt(), receiptItem.getItemReceipt())) {
216                         return false;
217                 }
218
219                 return true;
220         }
221
222         @Override
223         public String getItemBrandName () {
224                 return this.itemBrandName;
225         }
226
227         @Override
228         public void setItemBrandName (final String itemBrandName) {
229                 this.itemBrandName = itemBrandName;
230         }
231
232         @Override
233         public Category getItemCategory () {
234                 return this.itemCategory;
235         }
236
237         @Override
238         public void setItemCategory (final Category itemCategory) {
239                 this.itemCategory = itemCategory;
240         }
241
242         @Override
243         public String getItemCouponNumber () {
244                 return this.itemCouponNumber;
245         }
246
247         @Override
248         public void setItemCouponNumber (final String itemCouponNumber) {
249                 this.itemCouponNumber = itemCouponNumber;
250         }
251
252         @Override
253         @SuppressWarnings ("ReturnOfDateField")
254         public Date getItemCreated () {
255                 return this.itemCreated;
256         }
257
258         @Override
259         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
260         public void setItemCreated (final Date itemCreated) {
261                 this.itemCreated = itemCreated;
262         }
263
264         @Override
265         public BigDecimal getItemGrossPrice () {
266                 return this.itemGrossPrice;
267         }
268
269         @Override
270         public void setItemGrossPrice (final BigDecimal itemGrossPrice) {
271                 this.itemGrossPrice = itemGrossPrice;
272         }
273
274         @Override
275         public Long getItemId () {
276                 return this.itemId;
277         }
278
279         @Override
280         public void setItemId (final Long itemId) {
281                 this.itemId = itemId;
282         }
283
284         @Override
285         public Boolean getItemIsDiscount () {
286                 return this.itemIsDiscount;
287         }
288
289         @Override
290         public void setItemIsDiscount (final Boolean itemIsDiscount) {
291                 this.itemIsDiscount = itemIsDiscount;
292         }
293
294         @Override
295         public Boolean getItemIsRefund () {
296                 return this.itemIsRefund;
297         }
298
299         @Override
300         public void setItemIsRefund (final Boolean itemIsRefund) {
301                 this.itemIsRefund = itemIsRefund;
302         }
303
304         @Override
305         public BasicData getItemManufacturer () {
306                 return this.itemManufacturer;
307         }
308
309         @Override
310         public void setItemManufacturer (final BasicData itemManufacturer) {
311                 this.itemManufacturer = itemManufacturer;
312         }
313
314         @Override
315         public BigDecimal getItemNetPrice () {
316                 return this.itemNetPrice;
317         }
318
319         @Override
320         public void setItemNetPrice (final BigDecimal itemNetPrice) {
321                 this.itemNetPrice = itemNetPrice;
322         }
323
324         @Override
325         public Long getItemNumber () {
326                 return this.itemNumber;
327         }
328
329         @Override
330         public void setItemNumber (final Long itemNumber) {
331                 this.itemNumber = itemNumber;
332         }
333
334         @Override
335         public Product getItemProduct () {
336                 return this.itemProduct;
337         }
338
339         @Override
340         public void setItemProduct (final Product itemProduct) {
341                 this.itemProduct = itemProduct;
342         }
343
344         @Override
345         public BigDecimal getItemProductQuantity () {
346                 return this.itemProductQuantity;
347         }
348
349         @Override
350         public void setItemProductQuantity (final BigDecimal itemProductQuantity) {
351                 this.itemProductQuantity = itemProductQuantity;
352         }
353
354         @Override
355         public BillableReceipt getItemReceipt () {
356                 return this.itemReceipt;
357         }
358
359         @Override
360         public void setItemReceipt (final BillableReceipt itemReceipt) {
361                 this.itemReceipt = itemReceipt;
362         }
363
364         @Override
365         public BigDecimal getItemTaxRate () {
366                 return this.itemTaxRate;
367         }
368
369         @Override
370         public void setItemTaxRate (final BigDecimal itemTaxRate) {
371                 this.itemTaxRate = itemTaxRate;
372         }
373
374         @Override
375         public int hashCode () {
376                 int hash = 5;
377
378                 hash = 53 * hash + Objects.hashCode(this.getItemId());
379                 hash = 53 * hash + Objects.hashCode(this.getItemProduct());
380                 hash = 53 * hash + Objects.hashCode(this.getItemProductQuantity());
381                 hash = 53 * hash + Objects.hashCode(this.getItemReceipt());
382
383                 return hash;
384         }
385
386 }