]> git.mxchange.org Git - jbonuscard-core.git/blob - src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java
Continued a bit:
[jbonuscard-core.git] / src / org / mxchange / jfinancials / model / receipt / FinancialReceipt.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder<roland@mxchange.org>
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jfinancials.model.receipt;
18
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;
41
42 /**
43  *
44  * @author Roland Häder<roland@mxchange.org>
45  */
46 @Entity (name = "receipts")
47 @Table (
48                 name = "receipts"
49 )
50 @SuppressWarnings ("PersistenceUnitPresent")
51 public class FinancialReceipt implements BillableReceipt {
52
53         /**
54          * Serial number
55          */
56         @Transient
57         private static final long serialVersionUID = 185_867_217_461L;
58
59         /**
60          * When this receipt has been created
61          */
62         @Basic (optional = false)
63         @Temporal (TemporalType.TIMESTAMP)
64         @Column (name = "receipt_created", nullable = false)
65         private Calendar receiptCreated;
66
67         /**
68          * Primary key
69          */
70         @Id
71         @GeneratedValue (strategy = GenerationType.IDENTITY)
72         @Column (name = "receipt_id", nullable = false, updatable = false)
73         private Long receiptId;
74
75         /**
76          * Payment type (cash, credit card, EC card ...)
77          */
78         @Basic (optional = false)
79         @Column (name = "receipt_payment_type", nullable = false)
80         @Enumerated (EnumType.STRING)
81         private PaymentType receiptPaymentType;
82
83         /**
84          * Seller instance
85          */
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;
89
90         /**
91          * Which user this receipt belongs to
92          */
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;
96
97         /**
98          * Default constructor
99          */
100         public FinancialReceipt () {
101         }
102
103         /**
104          * Constructor with payment type, seller and user
105          * <p>
106          * @param receiptPaymentType Payment type
107          * @param receiptSeller      Seller instance
108          * @param receiptUser        User instance
109          */
110         public FinancialReceipt (final PaymentType receiptPaymentType, final BusinessContact receiptSeller, final User receiptUser) {
111                 // Call other constructor first
112                 this();
113
114                 // Set all
115                 this.receiptPaymentType = receiptPaymentType;
116                 this.receiptSeller = receiptSeller;
117                 this.receiptUser = receiptUser;
118         }
119
120         @Override
121         public boolean equals (final Object object) {
122                 if (this == object) {
123                         return true;
124                 }
125                 if (null == object) {
126                         return false;
127                 } else if (this.getClass() != object.getClass()) {
128                         return false;
129                 }
130
131                 final BillableReceipt receipt = (BillableReceipt) object;
132
133                 if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) {
134                         return false;
135                 } else if (this.getReceiptPaymentType() != receipt.getReceiptPaymentType()) {
136                         return false;
137                 } else if (!Objects.equals(this.getReceiptSeller(), receipt.getReceiptSeller())) {
138                         return false;
139                 } else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) {
140                         return false;
141                 }
142
143                 return true;
144         }
145
146         @Override
147         @SuppressWarnings ("ReturnOfDateField")
148         public Calendar getReceiptCreated () {
149                 return this.receiptCreated;
150         }
151
152         @Override
153         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
154         public void setReceiptCreated (final Calendar receiptCreated) {
155                 this.receiptCreated = receiptCreated;
156         }
157
158         @Override
159         public Long getReceiptId () {
160                 return this.receiptId;
161         }
162
163         @Override
164         public void setReceiptId (final Long receiptId) {
165                 this.receiptId = receiptId;
166         }
167
168         @Override
169         public PaymentType getReceiptPaymentType () {
170                 return this.receiptPaymentType;
171         }
172
173         @Override
174         public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
175                 this.receiptPaymentType = receiptPaymentType;
176         }
177
178         @Override
179         public BusinessContact getReceiptSeller () {
180                 return this.receiptSeller;
181         }
182
183         @Override
184         public void setReceiptSeller (final BusinessContact receiptSeller) {
185                 this.receiptSeller = receiptSeller;
186         }
187
188         @Override
189         public User getReceiptUser () {
190                 return this.receiptUser;
191         }
192
193         @Override
194         public void setReceiptUser (final User receiptUser) {
195                 this.receiptUser = receiptUser;
196         }
197
198         @Override
199         public int hashCode () {
200                 int hash = 5;
201
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());
206
207                 return hash;
208         }
209
210 }