2 * Copyright (C) 2016, 2017 Roland Häder
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.
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.
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/>.
17 package org.mxchange.jfinancials.model.receipt.item;
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.Index;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.mxchange.jfinancials.model.receipt.BillableReceipt;
36 import org.mxchange.jfinancials.model.receipt.FinancialReceipt;
37 import org.mxchange.jproduct.model.product.GenericProduct;
38 import org.mxchange.jproduct.model.product.Product;
41 * A POJO for receipt items
43 * @author Roland Häder<roland@mxchange.org>
45 @Entity (name = "receipt_items")
47 name = "receipt_items",
49 @Index (name = "item_receipt_product", columnList = "item_receipt_id,item_product_id", unique = true)
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class ReceiptItem implements BillableReceiptItem {
59 private static final long serialVersionUID = 126_498_698_378_571L;
62 * When this item has been created in database
64 @Basic (optional = false)
65 @Temporal (TemporalType.TIMESTAMP)
66 @Column (name = "item_created", nullable = false)
67 private Date itemCreated;
72 @Column (name = "item_product_discount")
73 private Float itemDiscount;
79 @GeneratedValue (strategy = GenerationType.IDENTITY)
80 @Column (name = "item_id", nullable = false, updatable = false)
84 * Product being linked in this itemReceipt item
86 @JoinColumn (name = "item_product_id", referencedColumnName = "product_id", nullable = false, updatable = false)
87 @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH, optional = false)
88 private Product itemProduct;
91 * Single product price (being copied here from GenericProduct)
93 @Basic (optional = false)
94 @Column (name = "item_product_price", nullable = false)
95 private Float itemProductPrice;
100 @Basic (optional = false)
101 @Column (name = "item_product_quantity", nullable = false)
102 private Long itemProductQuantity;
105 * Connected itemReceipt item
107 @JoinColumn (name = "item_receipt_id", referencedColumnName = "receipt_id", nullable = false, updatable = false)
108 @OneToOne (targetEntity = FinancialReceipt.class, cascade = CascadeType.REFRESH, optional = false)
109 private BillableReceipt itemReceipt;
112 * Default constructor
114 public ReceiptItem () {
118 * Constructor with product, price, quantity and receipt instance
120 * @param itemProduct Product instance
121 * @param itemProductPrice Product price (copied)
122 * @param itemProductQuantity Product quantity
123 * @param itemReceipt FinancialReceipt instance
125 public ReceiptItem (final Product itemProduct, final Float itemProductPrice, final Long itemProductQuantity, final BillableReceipt itemReceipt) {
126 // Call other constructor
130 this.itemProduct = itemProduct;
131 this.itemProductPrice = itemProductPrice;
132 this.itemProductQuantity = itemProductQuantity;
133 this.itemReceipt = itemReceipt;
137 public boolean equals (final Object object) {
138 if (this == object) {
140 } else if (null == object) {
142 } else if (this.getClass() != object.getClass()) {
146 final BillableReceiptItem receiptItem = (BillableReceiptItem) object;
148 if (!Objects.equals(this.getItemId(), receiptItem.getItemId())) {
150 } else if (!Objects.equals(this.getItemProduct(), receiptItem.getItemProduct())) {
152 } else if (!Objects.equals(this.getItemProductPrice(), receiptItem.getItemProductPrice())) {
154 } else if (!Objects.equals(this.getItemProductQuantity(), receiptItem.getItemProductQuantity())) {
156 } else if (!Objects.equals(this.getItemReceipt(), receiptItem.getItemReceipt())) {
164 @SuppressWarnings ("ReturnOfDateField")
165 public Date getItemCreated () {
166 return this.itemCreated;
170 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
171 public void setItemCreated (final Date itemCreated) {
172 this.itemCreated = itemCreated;
176 public Float getItemDiscount () {
177 return this.itemDiscount;
181 public void setItemDiscount (final Float itemDiscount) {
182 this.itemDiscount = itemDiscount;
186 public Long getItemId () {
191 public void setItemId (final Long itemId) {
192 this.itemId = itemId;
196 public Product getItemProduct () {
197 return this.itemProduct;
201 public void setItemProduct (final Product itemProduct) {
202 this.itemProduct = itemProduct;
206 public Float getItemProductPrice () {
207 return this.itemProductPrice;
211 public void setItemProductPrice (final Float itemProductPrice) {
212 this.itemProductPrice = itemProductPrice;
216 public Long getItemProductQuantity () {
217 return this.itemProductQuantity;
221 public void setItemProductQuantity (final Long itemProductQuantity) {
222 this.itemProductQuantity = itemProductQuantity;
226 public BillableReceipt getItemReceipt () {
227 return this.itemReceipt;
231 public void setItemReceipt (final BillableReceipt itemReceipt) {
232 this.itemReceipt = itemReceipt;
236 public int hashCode () {
239 hash = 53 * hash + Objects.hashCode(this.getItemId());
240 hash = 53 * hash + Objects.hashCode(this.getItemProduct());
241 hash = 53 * hash + Objects.hashCode(this.getItemProductPrice());
242 hash = 53 * hash + Objects.hashCode(this.getItemProductQuantity());
243 hash = 53 * hash + Objects.hashCode(this.getItemReceipt());