]> git.mxchange.org Git - jbonuscard-core.git/blob - src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java
Contined a bit:
[jbonuscard-core.git] / src / org / mxchange / jfinancials / model / receipt / FinancialReceipt.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
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 entry 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          * When this receipt has been issued
77          */
78         @Basic (optional = false)
79         @Temporal (TemporalType.DATE)
80         @Column (name = "receipt_issued", nullable = false)
81         private Calendar receiptIssued;
82
83         /**
84          * Payment type (cash, credit card, EC card ...)
85          */
86         @Basic (optional = false)
87         @Column (name = "receipt_payment_type", nullable = false)
88         @Enumerated (EnumType.STRING)
89         private PaymentType receiptPaymentType;
90
91         /**
92          * Seller instance
93          */
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;
97
98         /**
99          * Which user this receipt belongs to
100          */
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;
104
105         /**
106          * Default constructor
107          */
108         public FinancialReceipt () {
109         }
110
111         /**
112          * Constructor with payment type, seller and user
113          * <p>
114          * @param receiptPaymentType Payment type
115          * @param receiptSeller      Seller instance
116          * @param receiptUser        User instance
117          * @param receiptIssued      When this receipt has been issued
118          */
119         public FinancialReceipt (final PaymentType receiptPaymentType, final BusinessContact receiptSeller, final User receiptUser, final Calendar receiptIssued) {
120                 // Call other constructor first
121                 this();
122
123                 // Set all values
124                 this.receiptPaymentType = receiptPaymentType;
125                 this.receiptSeller = receiptSeller;
126                 this.receiptUser = receiptUser;
127                 this.receiptIssued = receiptIssued;
128         }
129
130         @Override
131         public boolean equals (final Object object) {
132                 if (this == object) {
133                         return true;
134                 }
135                 if (null == object) {
136                         return false;
137                 } else if (this.getClass() != object.getClass()) {
138                         return false;
139                 }
140
141                 final BillableReceipt receipt = (BillableReceipt) object;
142
143                 if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) {
144                         return false;
145                 } else if (this.getReceiptPaymentType() != receipt.getReceiptPaymentType()) {
146                         return false;
147                 } else if (!Objects.equals(this.getReceiptSeller(), receipt.getReceiptSeller())) {
148                         return false;
149                 } else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) {
150                         return false;
151                 } else if (!Objects.equals(this.getReceiptIssued(), receipt.getReceiptIssued())) {
152                         return false;
153                 }
154
155                 return true;
156         }
157
158         @Override
159         @SuppressWarnings ("ReturnOfDateField")
160         public Calendar getReceiptCreated () {
161                 return this.receiptCreated;
162         }
163
164         @Override
165         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
166         public void setReceiptCreated (final Calendar receiptCreated) {
167                 this.receiptCreated = receiptCreated;
168         }
169
170         @Override
171         public Long getReceiptId () {
172                 return this.receiptId;
173         }
174
175         @Override
176         public void setReceiptId (final Long receiptId) {
177                 this.receiptId = receiptId;
178         }
179
180         @Override
181         @SuppressWarnings ("ReturnOfDateField")
182         public Calendar getReceiptIssued () {
183                 return this.receiptIssued;
184         }
185
186         @Override
187         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
188         public void setReceiptIssued (final Calendar receiptIssued) {
189                 this.receiptIssued = receiptIssued;
190         }
191
192         @Override
193         public PaymentType getReceiptPaymentType () {
194                 return this.receiptPaymentType;
195         }
196
197         @Override
198         public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
199                 this.receiptPaymentType = receiptPaymentType;
200         }
201
202         @Override
203         public BusinessContact getReceiptSeller () {
204                 return this.receiptSeller;
205         }
206
207         @Override
208         public void setReceiptSeller (final BusinessContact receiptSeller) {
209                 this.receiptSeller = receiptSeller;
210         }
211
212         @Override
213         public User getReceiptUser () {
214                 return this.receiptUser;
215         }
216
217         @Override
218         public void setReceiptUser (final User receiptUser) {
219                 this.receiptUser = receiptUser;
220         }
221
222         @Override
223         public int hashCode () {
224                 int hash = 5;
225
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());
230
231                 return hash;
232         }
233
234 }