*/
package org.mxchange.jfinancials.model.receipt;
-import java.util.Calendar;
+import java.text.MessageFormat;
+import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
-import org.mxchange.jcontactsbusiness.BusinessBasicData;
-import org.mxchange.jcontactsbusiness.CompanyBasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice;
import org.mxchange.jproduct.model.payment.PaymentType;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
@Table (
name = "receipts"
)
+@NamedQueries (
+ {
+ @NamedQuery (name = "AllReceipts", query = "SELECT r FROM receipts AS r ORDER BY r.receiptId ASC"),
+ @NamedQuery (name = "SearchAllUserReceipts", query = "SELECT r FROM receipts AS r WHERE r.receiptUser = :receiptUser ORDER BY r.receiptId ASC")
+ }
+)
@SuppressWarnings ("PersistenceUnitPresent")
public class FinancialReceipt implements BillableReceipt {
@Transient
private static final long serialVersionUID = 185_867_217_461L;
+ /**
+ * Seller instance
+ */
+ @JoinColumn (name = "receipt_branch_id", referencedColumnName = "branch_id", nullable = false, updatable = false)
+ @OneToOne (targetEntity = CompanyBranchOffice.class, cascade = CascadeType.REFRESH, optional = false)
+ private BranchOffice receiptBranchOffice;
+
/**
* When this receipt entry has been created
*/
@Basic (optional = false)
@Temporal (TemporalType.TIMESTAMP)
@Column (name = "receipt_created", nullable = false)
- private Calendar receiptCreated;
+ private Date receiptCreated;
/**
* Primary key
@Basic (optional = false)
@Temporal (TemporalType.DATE)
@Column (name = "receipt_issued", nullable = false)
- private Calendar receiptIssued;
+ private Date receiptIssued;
+
+ /**
+ * Receipt number
+ */
+ @Column (name = "receipt_number")
+ private Long receiptNumber;
/**
* Payment type (cash, credit card, EC card ...)
@Enumerated (EnumType.STRING)
private PaymentType receiptPaymentType;
- /**
- * Seller instance
- */
- @JoinColumn (name = "receipt_seller_id", referencedColumnName = "business_data_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = CompanyBasicData.class, cascade = CascadeType.REFRESH, optional = false)
- private BusinessBasicData receiptSeller;
-
/**
* Which user this receipt belongs to
*/
- @JoinColumn (name = "receipt_user_id", referencedColumnName = "user_id", nullable = false, updatable = false)
- @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
+ @JoinColumn (name = "receipt_user_id", referencedColumnName = "user_id")
+ @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH)
private User receiptUser;
/**
}
/**
- * Constructor with payment type, seller and user
+ * Constructor with payment type, seller (branch office) and user
* <p>
- * @param receiptPaymentType Payment type
- * @param receiptSeller Seller instance
- * @param receiptUser User instance
- * @param receiptIssued When this receipt has been issued
+ * @param receiptPaymentType Payment type
+ * @param receiptBranchOffice Branch office instance
+ * @param receiptUser User instance
+ * @param receiptIssued When this receipt has been issued
+ *
+ * @throws NullPointerException If user instance is not set
+ * @throws IllegalArgumentException If user instance's userId is invalid
*/
- public FinancialReceipt (final PaymentType receiptPaymentType, final BusinessBasicData receiptSeller, final User receiptUser, final Calendar receiptIssued) {
+ public FinancialReceipt (final PaymentType receiptPaymentType, final BranchOffice receiptBranchOffice, final User receiptUser, final Date receiptIssued) {
+ // Call other constructor first
+ this(receiptPaymentType, receiptBranchOffice, receiptIssued);
+
+ // Validate parameter
+ if (null == receiptUser) {
+ // Throw NPE
+ throw new NullPointerException("user is null"); //NOI18N
+ } else if (receiptUser.getUserId() == null) {
+ // Throw it again
+ throw new NullPointerException("user.userId is null"); //NOI18N
+ } else if (receiptUser.getUserId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", receiptUser.getUserId())); //NOI18N
+ }
+
+ // Set user instance
+ this.receiptUser = receiptUser;
+ }
+
+ /**
+ * Constructor with payment type, branch office and when it has been issued
+ * <p>
+ * @param receiptPaymentType Payment type
+ * @param receiptBranchOffice Branch office instance
+ * @param receiptIssued When this receipt has been issued
+ * <p>
+ * @throws NullPointerException If user instance is not set
+ * @throws IllegalArgumentException If branchId is invalid
+ */
+ public FinancialReceipt (final PaymentType receiptPaymentType, final BranchOffice receiptBranchOffice, final Date receiptIssued) {
// Call other constructor first
this();
+ // Validate all parameter
+ if (null == receiptPaymentType) {
+ // Throw NPE
+ throw new NullPointerException("receiptPaymentType is null"); //NOI18N
+ } else if (null == receiptBranchOffice) {
+ // Throw NPE
+ throw new NullPointerException("receiptBranchOffice is null"); //NOI18N
+ } else if (receiptBranchOffice.getBranchId() == null) {
+ // Throw NPE
+ throw new NullPointerException("receiptBranchOffice.branchId is null"); //NOI18N
+ } else if (receiptBranchOffice.getBranchId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receiptBranchOffice.branchId={0} is invalid", receiptBranchOffice.getBranchId())); //NOI18N
+ } else if (null == receiptIssued) {
+ // Throw NPE
+ throw new NullPointerException("receiptIssued is null"); //NOI18N
+ }
+
// Set all values
this.receiptPaymentType = receiptPaymentType;
- this.receiptSeller = receiptSeller;
- this.receiptUser = receiptUser;
+ this.receiptBranchOffice = receiptBranchOffice;
this.receiptIssued = receiptIssued;
}
if (!Objects.equals(this.getReceiptId(), receipt.getReceiptId())) {
return false;
+ } else if (!Objects.equals(this.getReceiptNumber(), receipt.getReceiptNumber())) {
+ return false;
} else if (this.getReceiptPaymentType() != receipt.getReceiptPaymentType()) {
return false;
- } else if (!Objects.equals(this.getReceiptSeller(), receipt.getReceiptSeller())) {
+ } else if (!Objects.equals(this.getReceiptBranchOffice(), receipt.getReceiptBranchOffice())) {
return false;
} else if (!Objects.equals(this.getReceiptUser(), receipt.getReceiptUser())) {
return false;
return true;
}
+ @Override
+ public BranchOffice getReceiptBranchOffice () {
+ return this.receiptBranchOffice;
+ }
+
+ @Override
+ public void setReceiptBranchOffice (final BranchOffice receiptBranchOffice) {
+ this.receiptBranchOffice = receiptBranchOffice;
+ }
+
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Calendar getReceiptCreated () {
+ public Date getReceiptCreated () {
return this.receiptCreated;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setReceiptCreated (final Calendar receiptCreated) {
+ public void setReceiptCreated (final Date receiptCreated) {
this.receiptCreated = receiptCreated;
}
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Calendar getReceiptIssued () {
+ public Date getReceiptIssued () {
return this.receiptIssued;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setReceiptIssued (final Calendar receiptIssued) {
+ public void setReceiptIssued (final Date receiptIssued) {
this.receiptIssued = receiptIssued;
}
@Override
- public PaymentType getReceiptPaymentType () {
- return this.receiptPaymentType;
+ public Long getReceiptNumber () {
+ return this.receiptNumber;
}
@Override
- public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
- this.receiptPaymentType = receiptPaymentType;
+ public void setReceiptNumber (final Long receiptNumber) {
+ this.receiptNumber = receiptNumber;
}
@Override
- public BusinessBasicData getReceiptSeller () {
- return this.receiptSeller;
+ public PaymentType getReceiptPaymentType () {
+ return this.receiptPaymentType;
}
@Override
- public void setReceiptSeller (final BusinessBasicData receiptSeller) {
- this.receiptSeller = receiptSeller;
+ public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
+ this.receiptPaymentType = receiptPaymentType;
}
@Override
int hash = 5;
hash = 89 * hash + Objects.hashCode(this.getReceiptId());
+ hash = 89 * hash + Objects.hashCode(this.getReceiptNumber());
hash = 89 * hash + Objects.hashCode(this.getReceiptPaymentType());
- hash = 89 * hash + Objects.hashCode(this.getReceiptSeller());
+ hash = 89 * hash + Objects.hashCode(this.getReceiptBranchOffice());
hash = 89 * hash + Objects.hashCode(this.getReceiptUser());
return hash;