2 * Copyright (C) 2016, 2017 Roland Häder<roland@mxchange.org>
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;
19 import java.util.Calendar;
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.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
36 import org.mxchange.jcontactsbusiness.BusinessContact;
37 import org.mxchange.jcontactsbusiness.CompanyContact;
38 import org.mxchange.jproduct.model.payment.PaymentType;
39 import org.mxchange.jusercore.model.user.LoginUser;
40 import org.mxchange.jusercore.model.user.User;
44 * @author Roland Häder<roland@mxchange.org>
46 @Entity (name = "receipts")
50 @SuppressWarnings ("PersistenceUnitPresent")
51 public class FinancialReceipt implements BillableReceipt {
57 private static final long serialVersionUID = 185_867_217_461L;
60 * When this receipt has been created
62 @Basic (optional = false)
63 @Temporal (TemporalType.TIMESTAMP)
64 @Column (name = "receipt_created", nullable = false)
65 private Calendar receiptCreated;
71 @GeneratedValue (strategy = GenerationType.IDENTITY)
72 @Column (name = "receipt_id", nullable = false, updatable = false)
73 private Long receiptId;
76 * Payment type (cash, credit card, EC card ...)
78 @Basic (optional = false)
79 @Column (name = "receipt_payment_type", nullable = false)
80 @Enumerated (EnumType.STRING)
81 private PaymentType receiptPaymentType;
86 @JoinColumn (name = "receipt_seller_id", referencedColumnName = "company_id", nullable = false, updatable = false)
87 @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.REFRESH, optional = false)
88 private BusinessContact receiptSeller;
91 * Which user this receipt belongs to
93 @JoinColumn (name = "receipt_user_id", referencedColumnName = "user_id", nullable = false, updatable = false)
94 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
95 private User receiptUser;
100 public FinancialReceipt () {
104 * Constructor with payment type, seller and user
106 * @param receiptPaymentType Payment type
107 * @param receiptSeller Seller instance
108 * @param receiptUser User instance
110 public FinancialReceipt (final PaymentType receiptPaymentType, final BusinessContact receiptSeller, final User receiptUser) {
111 // Call other constructor first
115 this.receiptPaymentType = receiptPaymentType;
116 this.receiptSeller = receiptSeller;
117 this.receiptUser = receiptUser;
121 public boolean equals (final Object object) {
122 if (this == object) {
125 if (null == object) {
127 } else if (this.getClass() != object.getClass()) {
131 final BillableReceipt receipt = (BillableReceipt) object;
133 if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) {
135 } else if (this.getReceiptPaymentType() != receipt.getReceiptPaymentType()) {
137 } else if (!Objects.equals(this.getReceiptSeller(), receipt.getReceiptSeller())) {
139 } else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) {
147 @SuppressWarnings ("ReturnOfDateField")
148 public Calendar getReceiptCreated () {
149 return this.receiptCreated;
153 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
154 public void setReceiptCreated (final Calendar receiptCreated) {
155 this.receiptCreated = receiptCreated;
159 public Long getReceiptId () {
160 return this.receiptId;
164 public void setReceiptId (final Long receiptId) {
165 this.receiptId = receiptId;
169 public PaymentType getReceiptPaymentType () {
170 return this.receiptPaymentType;
174 public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
175 this.receiptPaymentType = receiptPaymentType;
179 public BusinessContact getReceiptSeller () {
180 return this.receiptSeller;
184 public void setReceiptSeller (final BusinessContact receiptSeller) {
185 this.receiptSeller = receiptSeller;
189 public User getReceiptUser () {
190 return this.receiptUser;
194 public void setReceiptUser (final User receiptUser) {
195 this.receiptUser = receiptUser;
199 public int hashCode () {
202 hash = 89 * hash + Objects.hashCode(this.getReceiptId());
203 hash = 89 * hash + Objects.hashCode(this.getReceiptPaymentType());
204 hash = 89 * hash + Objects.hashCode(this.getReceiptSeller());
205 hash = 89 * hash + Objects.hashCode(this.getReceiptUser());