*/
package org.mxchange.jfinancials.exceptions;
+import java.text.MessageFormat;
+import org.mxchange.jfinancials.model.receipt.BillableReceipt;
+
/**
* This exception is thrown when a receipt was already added
* <p>
*/
private static final long serialVersionUID = 19_065_867_127_647_624L;
+ /**
+ * Default constructor
+ */
+ public ReceiptAlreadyAddedException () {
+ super();
+ }
+
+ /**
+ * Constructor with receipt instance
+ * <p>
+ * @param receipt Receipt instance
+ */
+ public ReceiptAlreadyAddedException (final BillableReceipt receipt) {
+ // Call super constructor
+ super(MessageFormat.format("Receipt with id {0} and number {1} has already been added.", receipt.getReceiptId(), receipt.getReceiptNumber()));
+ }
+
}
import java.io.Serializable;
import java.util.Calendar;
-import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
import org.mxchange.jproduct.model.payment.PaymentType;
import org.mxchange.jusercore.model.user.User;
void setReceiptId (final Long receiptId);
/**
+ * Getter for receipt number
+ * <p>
+ * @return Receipt number
+ */
+ Long getReceiptNumber ();
+
+ /**
+ * Setter for receipt number
+ * <p>
+ * @param receiptNumber Receipt number
+ */
+ void setReceiptNumber (final Long receiptNumber);
+
+ /**
* Getter for receipt's user
* <p>
* @return Receipt's user
void setReceiptUser (final User receiptUser);
/**
- * Getter for seller instance
+ * Getter for branch office instance
* <p>
- * @return Seller instance
+ * @return Branch office instance
*/
- BusinessBasicData getReceiptSeller ();
+ BranchOffice getReceiptBranchOffice ();
/**
- * Setter for seller instance
+ * Setter for branch office instance
* <p>
- * @param receiptSeller Seller instance
+ * @param receiptBranch Branch office instance
*/
- void setReceiptSeller (final BusinessBasicData receiptSeller);
+ void setReceiptBranchOffice (final BranchOffice receiptBranch);
/**
* Getter for payment type
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.basicdata.BusinessBasicData;
-import org.mxchange.jcontactsbusiness.basicdata.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
*/
@Column (name = "receipt_issued", nullable = false)
private Calendar 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
* <p>
* @param receiptPaymentType Payment type
- * @param receiptSeller Seller instance
+ * @param branchOffice Branch office instance
* @param receiptUser User instance
* @param receiptIssued When this receipt has been issued
*/
- public FinancialReceipt (final PaymentType receiptPaymentType, final BusinessBasicData receiptSeller, final User receiptUser, final Calendar receiptIssued) {
+ public FinancialReceipt (final PaymentType receiptPaymentType, final BranchOffice branchOffice, final User receiptUser, final Calendar receiptIssued) {
// Call other constructor first
this();
// Set all values
this.receiptPaymentType = receiptPaymentType;
- this.receiptSeller = receiptSeller;
+ this.receiptBranchOffice = branchOffice;
this.receiptUser = receiptUser;
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 () {
}
@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;
--- /dev/null
+/*
+ * Copyright (C) 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.model.receipt;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.Objects;
+
+/**
+ * A utilities class for receipts
+ *
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class Receipts implements Serializable {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 2_867_938_676_165_401L;
+
+ public static boolean isSameReceipt (final BillableReceipt receipt1, final BillableReceipt receipt2) {
+ // Pre-compare both as entities (same id)
+ if (Objects.equals(receipt1, receipt2)) {
+ // Same entity (with id number)
+ return true;
+ }
+
+ // Validate parameter
+ if (null == receipt1) {
+ // Throw NPE
+ throw new NullPointerException("receipt1 is null");
+ } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId()));
+ } else if (receipt1.getReceiptNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("receipt1.receiptNumber is null");
+ } else if (receipt1.getReceiptNumber() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptNumber={0} is not valid", receipt1.getReceiptNumber()));
+ } else if (receipt1.getReceiptBranchOffice() == null) {
+ // Throw NPE
+ throw new NullPointerException("receipt1.receiptBranchOffice is null");
+ } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
+ // Throw NPE
+ throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null");
+ } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId()));
+ } else if (receipt1.getReceiptPaymentType()== null) {
+ // Throw NPE
+ throw new NullPointerException("receipt1.receiptPaymentType is null");
+ } else if (null == receipt2) {
+ // Throw NPE
+ throw new NullPointerException("receipt2 is null");
+ } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId()));
+ } else if (receipt2.getReceiptNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("receipt2.receiptNumber is null");
+ } else if (receipt2.getReceiptNumber() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptNumber={0} is not valid", receipt2.getReceiptNumber()));
+ } else if (receipt2.getReceiptBranchOffice() == null) {
+ // Throw NPE
+ throw new NullPointerException("receipt2.receiptBranchOffice is null");
+ } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
+ // Throw NPE
+ throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null");
+ } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) {
+ // Throw NPE
+ throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId()));
+ } else if (receipt2.getReceiptPaymentType()== null) {
+ // Throw NPE
+ throw new NullPointerException("receipt2.receiptPaymentType is null");
+ }
+
+ // Now check all individually
+ if (!Objects.equals(receipt1.getReceiptBranchOffice(), receipt2.getReceiptBranchOffice())) {
+ // Other branch offices
+ return false;
+ } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) {
+ // Other receipt number
+ return false;
+ } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) {
+ // Other user (unlikely to happen
+ return false;
+ }
+
+ // Maybe same receipt!
+ return true;
+ }
+
+ /**
+ * Private default constructor
+ */
+ private Receipts () {
+ // Utilities don't have instances
+ }
+
+}