X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Forg%2Fmxchange%2Fjfinancials%2Fmodel%2Freceipt%2FFinancialReceipt.java;h=7993c96a9f41d7a9fa58494715d57c98bd21f29c;hb=97c1c3882d48478d41c6987fbf8125a6dceaa60c;hp=f689bc59c835045a658271d3ba43a222e5203453;hpb=0eb54d7b30f3010c15daac1baf04f3dc38cbe713;p=jfinancials-core.git diff --git a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java index f689bc5..7993c96 100644 --- a/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java +++ b/src/org/mxchange/jfinancials/model/receipt/FinancialReceipt.java @@ -16,7 +16,8 @@ */ 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; @@ -28,13 +29,15 @@ import javax.persistence.GeneratedValue; 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; @@ -47,6 +50,12 @@ 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 { @@ -56,13 +65,20 @@ 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 @@ -78,7 +94,13 @@ public class FinancialReceipt implements BillableReceipt { @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 ...) @@ -88,18 +110,11 @@ public class FinancialReceipt implements BillableReceipt { @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; /** @@ -109,21 +124,71 @@ public class FinancialReceipt implements BillableReceipt { } /** - * Constructor with payment type, seller and user + * Constructor with payment type, seller (branch office) and user *

- * @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 + *

+ * @param receiptPaymentType Payment type + * @param receiptBranchOffice Branch office instance + * @param receiptIssued When this receipt has been issued + *

+ * @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; } @@ -142,9 +207,11 @@ public class FinancialReceipt implements BillableReceipt { 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; @@ -155,15 +222,25 @@ public class FinancialReceipt implements BillableReceipt { 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; } @@ -179,34 +256,34 @@ public class FinancialReceipt implements BillableReceipt { @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 @@ -224,8 +301,9 @@ public class FinancialReceipt implements BillableReceipt { 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;