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 entry 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 * When this receipt has been issued
78 @Basic (optional = false)
79 @Temporal (TemporalType.DATE)
80 @Column (name = "receipt_issued", nullable = false)
81 private Calendar receiptIssued;
84 * Payment type (cash, credit card, EC card ...)
86 @Basic (optional = false)
87 @Column (name = "receipt_payment_type", nullable = false)
88 @Enumerated (EnumType.STRING)
89 private PaymentType receiptPaymentType;
94 @JoinColumn (name = "receipt_seller_id", referencedColumnName = "company_id", nullable = false, updatable = false)
95 @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.REFRESH, optional = false)
96 private BusinessContact receiptSeller;
99 * Which user this receipt belongs to
101 @JoinColumn (name = "receipt_user_id", referencedColumnName = "user_id", nullable = false, updatable = false)
102 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
103 private User receiptUser;
106 * Default constructor
108 public FinancialReceipt () {
112 * Constructor with payment type, seller and user
114 * @param receiptPaymentType Payment type
115 * @param receiptSeller Seller instance
116 * @param receiptUser User instance
117 * @param receiptIssued When this receipt has been issued
119 public FinancialReceipt (final PaymentType receiptPaymentType, final BusinessContact receiptSeller, final User receiptUser, final Calendar receiptIssued) {
120 // Call other constructor first
124 this.receiptPaymentType = receiptPaymentType;
125 this.receiptSeller = receiptSeller;
126 this.receiptUser = receiptUser;
127 this.receiptIssued = receiptIssued;
131 public boolean equals (final Object object) {
132 if (this == object) {
135 if (null == object) {
137 } else if (this.getClass() != object.getClass()) {
141 final BillableReceipt receipt = (BillableReceipt) object;
143 if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) {
145 } else if (this.getReceiptPaymentType() != receipt.getReceiptPaymentType()) {
147 } else if (!Objects.equals(this.getReceiptSeller(), receipt.getReceiptSeller())) {
149 } else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) {
151 } else if (!Objects.equals(this.getReceiptIssued(), receipt.getReceiptIssued())) {
159 @SuppressWarnings ("ReturnOfDateField")
160 public Calendar getReceiptCreated () {
161 return this.receiptCreated;
165 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
166 public void setReceiptCreated (final Calendar receiptCreated) {
167 this.receiptCreated = receiptCreated;
171 public Long getReceiptId () {
172 return this.receiptId;
176 public void setReceiptId (final Long receiptId) {
177 this.receiptId = receiptId;
181 @SuppressWarnings ("ReturnOfDateField")
182 public Calendar getReceiptIssued () {
183 return this.receiptIssued;
187 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
188 public void setReceiptIssued (final Calendar receiptIssued) {
189 this.receiptIssued = receiptIssued;
193 public PaymentType getReceiptPaymentType () {
194 return this.receiptPaymentType;
198 public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
199 this.receiptPaymentType = receiptPaymentType;
203 public BusinessContact getReceiptSeller () {
204 return this.receiptSeller;
208 public void setReceiptSeller (final BusinessContact receiptSeller) {
209 this.receiptSeller = receiptSeller;
213 public User getReceiptUser () {
214 return this.receiptUser;
218 public void setReceiptUser (final User receiptUser) {
219 this.receiptUser = receiptUser;
223 public int hashCode () {
226 hash = 89 * hash + Objects.hashCode(this.getReceiptId());
227 hash = 89 * hash + Objects.hashCode(this.getReceiptPaymentType());
228 hash = 89 * hash + Objects.hashCode(this.getReceiptSeller());
229 hash = 89 * hash + Objects.hashCode(this.getReceiptUser());