]> git.mxchange.org Git - jfinancials-core.git/blobdiff - src/org/mxchange/jfinancials/model/receipt/Receipts.java
Updated JAR(s)
[jfinancials-core.git] / src / org / mxchange / jfinancials / model / receipt / Receipts.java
index a2f6d8a317f78d5951f292616b8215ca269d3184..ba8f72f343adbbc8e7ead0ffd5b821e25f2edb53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017, 2018 Free Software Foundation
+ * Copyright (C) 2017 - 2022 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -42,7 +42,7 @@ public class Receipts implements Serializable {
         * @return Comparison value
         */
        public static int compare (final BillableReceipt receipt1, final BillableReceipt receipt2) {
-               // Check euqality, then at least first must be given
+               // Check equality, then at least first must be given
                if (Objects.equals(receipt1, receipt2)) {
                        // Both are same
                        return 0;
@@ -58,6 +58,41 @@ public class Receipts implements Serializable {
                return receipt1.compareTo(receipt2);
        }
 
+       /**
+        * Copies all fields from source receipt to target receipt.
+        * <p>
+        * @param sourceReceipt Source receipt instance
+        * @param targetReceipt Target Receipt instance
+        */
+       public static void copyReceiptData (final BillableReceipt sourceReceipt, final BillableReceipt targetReceipt) {
+               // Both should not be null
+               if (null == sourceReceipt) {
+                       // Throw NPE
+                       throw new NullPointerException("sourceReceipt is null"); //NOI18N
+               } else if (null == targetReceipt) {
+                       // Throw NPE
+                       throw new NullPointerException("targetReceipt is null"); //NOI18N
+               } else if (Objects.equals(sourceReceipt, targetReceipt)) {
+                       // Is exactly the same!
+                       throw new IllegalArgumentException("sourcerReceipt and targetReceipt are the same."); //NOI18N
+               }
+
+               // Copy all fields
+               targetReceipt.setReceiptBarCodeNumber(sourceReceipt.getReceiptBarCodeNumber());
+               targetReceipt.setReceiptBonusCard(sourceReceipt.getReceiptBonusCard());
+               targetReceipt.setReceiptBranchOffice(sourceReceipt.getReceiptBranchOffice());
+               targetReceipt.setReceiptId(sourceReceipt.getReceiptId());
+               targetReceipt.setReceiptIssued(sourceReceipt.getReceiptIssued());
+               targetReceipt.setReceiptNumber(sourceReceipt.getReceiptNumber());
+               targetReceipt.setReceiptPaymentType(sourceReceipt.getReceiptPaymentType());
+               targetReceipt.setReceiptQrCode(sourceReceipt.getReceiptQrCode());
+               targetReceipt.setReceiptRegisterNumber(sourceReceipt.getReceiptRegisterNumber());
+               targetReceipt.setReceiptSellerEmployee(sourceReceipt.getReceiptSellerEmployee());
+               targetReceipt.setReceiptSequenceNumber(sourceReceipt.getReceiptSequenceNumber());
+               targetReceipt.setReceiptTransactionNumber(sourceReceipt.getReceiptTransactionNumber());
+               targetReceipt.setReceiptUser(sourceReceipt.getReceiptUser());
+       }
+
        /**
         * Checks whether both receipts are the same, means not true entity equality
         * but if the receipt in general terms does already exist. A pre-check on
@@ -78,46 +113,46 @@ public class Receipts implements Serializable {
                // Validate parameter
                if (null == receipt1) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1 is null");
+                       throw new NullPointerException("receipt1 is null"); //NOI18N
                } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId()));
+                       throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId())); //NOI18N
                } else if (receipt1.getReceiptBranchOffice() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1.receiptBranchOffice is null");
+                       throw new NullPointerException("receipt1.receiptBranchOffice is null"); //NOI18N
                } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null");
+                       throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null"); //NOI18N
                } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) {
                        // Throw NPE
-                       throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId()));
+                       throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId())); //NOI18N
                } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) {
                        // Throw IAE
-                       throw new IllegalArgumentException("receipt1.receiptNumber is empty.");
+                       throw new IllegalArgumentException("receipt1.receiptNumber is empty."); //NOI18N
                } else if (receipt1.getReceiptPaymentType() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt1.receiptPaymentType is null");
+                       throw new NullPointerException("receipt1.receiptPaymentType is null"); //NOI18N
                } else if (null == receipt2) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2 is null");
+                       throw new NullPointerException("receipt2 is null"); //NOI18N
                } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) {
                        // Throw IAE
-                       throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId()));
+                       throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId())); //NOI18N
                } else if (receipt2.getReceiptBranchOffice() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2.receiptBranchOffice is null");
+                       throw new NullPointerException("receipt2.receiptBranchOffice is null"); //NOI18N
                } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null");
+                       throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null"); //NOI18N
                } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) {
                        // Throw NPE
-                       throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId()));
+                       throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId())); //NOI18N
                } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) {
                        // Throw IAE
-                       throw new IllegalArgumentException("receipt2.receiptNumber is empty.");
+                       throw new IllegalArgumentException("receipt2.receiptNumber is empty."); //NOI18N
                } else if (receipt2.getReceiptPaymentType() == null) {
                        // Throw NPE
-                       throw new NullPointerException("receipt2.receiptPaymentType is null");
+                       throw new NullPointerException("receipt2.receiptPaymentType is null"); //NOI18N
                }
 
                // Now check all individually
@@ -127,6 +162,9 @@ public class Receipts implements Serializable {
                } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) {
                        // Other receipt number
                        return false;
+               } else if (!Objects.equals(receipt1.getReceiptIssued(), receipt2.getReceiptIssued())) {
+                       // Other issue date
+                       return false;
                } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) {
                        // Other user (unlikely to happen
                        return false;