2 * Copyright (C) 2016 - 2018 Free Software Foundation
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.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;
47 * A POJO for receipt items
49 * @author Roland Häder<roland@mxchange.org>
51 @Entity (name = "receipt_items")
53 name = "receipt_items"
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")
62 @SuppressWarnings ("PersistenceUnitPresent")
63 public class FinancialReceiptItem implements BillableReceiptItem {
69 private static final long serialVersionUID = 126_498_698_378_571L;
74 @Column (name = "item_brand_name")
75 private String itemBrandName;
78 * Category being assigned to item's product
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;
85 * Item 's coupon number
87 @Column (name = "item_coupon_number")
88 private String itemCouponNumber;
91 * When this item has been created in database
93 @Basic (optional = false)
94 @Temporal (TemporalType.TIMESTAMP)
95 @Column (name = "item_created", nullable = false)
96 private Date itemCreated;
101 @Basic (optional = false)
102 @Column (name = "item_gross_price", nullable = false, precision = 10, scale = 2)
103 private BigDecimal itemGrossPrice;
109 @GeneratedValue (strategy = GenerationType.IDENTITY)
110 @Column (name = "item_id", nullable = false, updatable = false)
114 * Whether the item is a discount on whole receipt or single item
116 @Basic (optional = false)
117 @Column (name = "item_is_discount", nullable = false)
118 private Boolean itemIsDiscount;
121 * Whether the item is a refund
123 @Basic (optional = false)
124 @Column (name = "item_is_refund", nullable = false)
125 private Boolean itemIsRefund;
128 * Manufacturer/producer of this item
130 @JoinColumn (name = "item_manufacturer_id", referencedColumnName = "company_data_id")
131 @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH)
132 private BasicData itemManufacturer;
137 @Column (name = "item_net_price", precision = 10, scale = 2)
138 private BigDecimal itemNetPrice;
143 @Column (name = "item_number")
144 private Long itemNumber;
147 * Product being linked in this itemReceipt item
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;
156 @Basic (optional = false)
157 @Column (name = "item_product_quantity", nullable = false, precision = 3)
158 private BigDecimal itemProductQuantity;
161 * Connected itemReceipt item
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;
170 @Column (name = "item_tax_rate", precision = 2)
171 private BigDecimal itemTaxRate;
174 * Default constructor
176 public FinancialReceiptItem () {
180 * Constructor with product, price, quantity and receipt instance
182 * @param itemProduct Product instance
183 * @param itemProductQuantity Product quantity
184 * @param itemReceipt FinancialReceipt instance
186 public FinancialReceiptItem (final Product itemProduct, final BigDecimal itemProductQuantity, final BillableReceipt itemReceipt) {
187 // Call other constructor
191 this.itemCategory = itemProduct.getProductCategory();
192 this.itemProduct = itemProduct;
193 this.itemProductQuantity = itemProductQuantity;
194 this.itemReceipt = itemReceipt;
198 public boolean equals (final Object object) {
199 if (this == object) {
201 } else if (null == object) {
203 } else if (this.getClass() != object.getClass()) {
207 final BillableReceiptItem receiptItem = (BillableReceiptItem) object;
209 if (!Objects.equals(this.getItemId(), receiptItem.getItemId())) {
211 } else if (!Objects.equals(this.getItemProduct(), receiptItem.getItemProduct())) {
213 } else if (!Objects.equals(this.getItemProductQuantity(), receiptItem.getItemProductQuantity())) {
215 } else if (!Objects.equals(this.getItemReceipt(), receiptItem.getItemReceipt())) {
223 public String getItemBrandName () {
224 return this.itemBrandName;
228 public void setItemBrandName (final String itemBrandName) {
229 this.itemBrandName = itemBrandName;
233 public Category getItemCategory () {
234 return this.itemCategory;
238 public void setItemCategory (final Category itemCategory) {
239 this.itemCategory = itemCategory;
243 public String getItemCouponNumber () {
244 return this.itemCouponNumber;
248 public void setItemCouponNumber (final String itemCouponNumber) {
249 this.itemCouponNumber = itemCouponNumber;
253 @SuppressWarnings ("ReturnOfDateField")
254 public Date getItemCreated () {
255 return this.itemCreated;
259 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
260 public void setItemCreated (final Date itemCreated) {
261 this.itemCreated = itemCreated;
265 public BigDecimal getItemGrossPrice () {
266 return this.itemGrossPrice;
270 public void setItemGrossPrice (final BigDecimal itemGrossPrice) {
271 this.itemGrossPrice = itemGrossPrice;
275 public Long getItemId () {
280 public void setItemId (final Long itemId) {
281 this.itemId = itemId;
285 public Boolean getItemIsDiscount () {
286 return this.itemIsDiscount;
290 public void setItemIsDiscount (final Boolean itemIsDiscount) {
291 this.itemIsDiscount = itemIsDiscount;
295 public Boolean getItemIsRefund () {
296 return this.itemIsRefund;
300 public void setItemIsRefund (final Boolean itemIsRefund) {
301 this.itemIsRefund = itemIsRefund;
305 public BasicData getItemManufacturer () {
306 return this.itemManufacturer;
310 public void setItemManufacturer (final BasicData itemManufacturer) {
311 this.itemManufacturer = itemManufacturer;
315 public BigDecimal getItemNetPrice () {
316 return this.itemNetPrice;
320 public void setItemNetPrice (final BigDecimal itemNetPrice) {
321 this.itemNetPrice = itemNetPrice;
325 public Long getItemNumber () {
326 return this.itemNumber;
330 public void setItemNumber (final Long itemNumber) {
331 this.itemNumber = itemNumber;
335 public Product getItemProduct () {
336 return this.itemProduct;
340 public void setItemProduct (final Product itemProduct) {
341 this.itemProduct = itemProduct;
345 public BigDecimal getItemProductQuantity () {
346 return this.itemProductQuantity;
350 public void setItemProductQuantity (final BigDecimal itemProductQuantity) {
351 this.itemProductQuantity = itemProductQuantity;
355 public BillableReceipt getItemReceipt () {
356 return this.itemReceipt;
360 public void setItemReceipt (final BillableReceipt itemReceipt) {
361 this.itemReceipt = itemReceipt;
365 public BigDecimal getItemTaxRate () {
366 return this.itemTaxRate;
370 public void setItemTaxRate (final BigDecimal itemTaxRate) {
371 this.itemTaxRate = itemTaxRate;
375 public int hashCode () {
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());