+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.model.receipt.item;
+
+import java.util.Date;
+import java.util.Objects;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Index;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+import org.mxchange.jfinancials.model.receipt.BillableReceipt;
+import org.mxchange.jfinancials.model.receipt.FinancialReceipt;
+import org.mxchange.jproduct.model.product.GenericProduct;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * A POJO for receipt items
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Entity (name = "receipt_items")
+@Table (
+ name = "receipt_items",
+ indexes = {
+ @Index (name = "item_receipt_product", columnList = "item_receipt_id,item_product_id", unique = true)
+ }
+)
+@SuppressWarnings ("PersistenceUnitPresent")
+public class FinancialReceiptItem implements BillableReceiptItem {
+
+ /**
+ * Serial number
+ */
+ @Transient
+ private static final long serialVersionUID = 126_498_698_378_571L;
+
+ /**
+ * When this item has been created in database
+ */
+ @Basic (optional = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "item_created", nullable = false)
+ private Date itemCreated;
+
+ /**
+ * Discount on item
+ */
+ @Column (name = "item_product_discount")
+ private Float itemDiscount;
+
+ /**
+ * Primary key
+ */
+ @Id
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ @Column (name = "item_id", nullable = false, updatable = false)
+ private Long itemId;
+
+ /**
+ * Product being linked in this itemReceipt item
+ */
+ @JoinColumn (name = "item_product_id", referencedColumnName = "product_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = GenericProduct.class, cascade = CascadeType.REFRESH, optional = false)
+ private Product itemProduct;
+
+ /**
+ * Single product price (being copied here from GenericProduct)
+ */
+ @Basic (optional = false)
+ @Column (name = "item_product_price", nullable = false)
+ private Float itemProductPrice;
+
+ /**
+ * Product quantity
+ */
+ @Basic (optional = false)
+ @Column (name = "item_product_quantity", nullable = false)
+ private Long itemProductQuantity;
+
+ /**
+ * Connected itemReceipt item
+ */
+ @JoinColumn (name = "item_receipt_id", referencedColumnName = "receipt_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = FinancialReceipt.class, cascade = CascadeType.REFRESH, optional = false)
+ private BillableReceipt itemReceipt;
+
+ /**
+ * Default constructor
+ */
+ public FinancialReceiptItem () {
+ }
+
+ /**
+ * Constructor with product, price, quantity and receipt instance
+ * <p>
+ * @param itemProduct Product instance
+ * @param itemProductPrice Product price (copied)
+ * @param itemProductQuantity Product quantity
+ * @param itemReceipt FinancialReceipt instance
+ */
+ public FinancialReceiptItem (final Product itemProduct, final Float itemProductPrice, final Long itemProductQuantity, final BillableReceipt itemReceipt) {
+ // Call other constructor
+ this();
+
+ // Set all values
+ this.itemProduct = itemProduct;
+ this.itemProductPrice = itemProductPrice;
+ this.itemProductQuantity = itemProductQuantity;
+ this.itemReceipt = itemReceipt;
+ }
+
+ @Override
+ public boolean equals (final Object object) {
+ if (this == object) {
+ return true;
+ } else if (null == object) {
+ return false;
+ } else if (this.getClass() != object.getClass()) {
+ return false;
+ }
+
+ final BillableReceiptItem receiptItem = (BillableReceiptItem) object;
+
+ if (!Objects.equals(this.getItemId(), receiptItem.getItemId())) {
+ return false;
+ } else if (!Objects.equals(this.getItemProduct(), receiptItem.getItemProduct())) {
+ return false;
+ } else if (!Objects.equals(this.getItemProductPrice(), receiptItem.getItemProductPrice())) {
+ return false;
+ } else if (!Objects.equals(this.getItemProductQuantity(), receiptItem.getItemProductQuantity())) {
+ return false;
+ } else if (!Objects.equals(this.getItemReceipt(), receiptItem.getItemReceipt())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getItemCreated () {
+ return this.itemCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setItemCreated (final Date itemCreated) {
+ this.itemCreated = itemCreated;
+ }
+
+ @Override
+ public Float getItemDiscount () {
+ return this.itemDiscount;
+ }
+
+ @Override
+ public void setItemDiscount (final Float itemDiscount) {
+ this.itemDiscount = itemDiscount;
+ }
+
+ @Override
+ public Long getItemId () {
+ return this.itemId;
+ }
+
+ @Override
+ public void setItemId (final Long itemId) {
+ this.itemId = itemId;
+ }
+
+ @Override
+ public Product getItemProduct () {
+ return this.itemProduct;
+ }
+
+ @Override
+ public void setItemProduct (final Product itemProduct) {
+ this.itemProduct = itemProduct;
+ }
+
+ @Override
+ public Float getItemProductPrice () {
+ return this.itemProductPrice;
+ }
+
+ @Override
+ public void setItemProductPrice (final Float itemProductPrice) {
+ this.itemProductPrice = itemProductPrice;
+ }
+
+ @Override
+ public Long getItemProductQuantity () {
+ return this.itemProductQuantity;
+ }
+
+ @Override
+ public void setItemProductQuantity (final Long itemProductQuantity) {
+ this.itemProductQuantity = itemProductQuantity;
+ }
+
+ @Override
+ public BillableReceipt getItemReceipt () {
+ return this.itemReceipt;
+ }
+
+ @Override
+ public void setItemReceipt (final BillableReceipt itemReceipt) {
+ this.itemReceipt = itemReceipt;
+ }
+
+ @Override
+ public int hashCode () {
+ int hash = 5;
+
+ hash = 53 * hash + Objects.hashCode(this.getItemId());
+ hash = 53 * hash + Objects.hashCode(this.getItemProduct());
+ hash = 53 * hash + Objects.hashCode(this.getItemProductPrice());
+ hash = 53 * hash + Objects.hashCode(this.getItemProductQuantity());
+ hash = 53 * hash + Objects.hashCode(this.getItemReceipt());
+
+ return hash;
+ }
+
+}