From b0c70fa9e0a8608fadc930c51b6eb249da9b7156 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Fri, 24 Apr 2020 17:02:04 +0200
Subject: [PATCH] Continued: - added utilities method copyReceiptItemData()
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder <roland@mxchange.org>
---
 .../model/receipt_item/ReceiptItems.java      | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/org/mxchange/jfinancials/model/receipt_item/ReceiptItems.java b/src/org/mxchange/jfinancials/model/receipt_item/ReceiptItems.java
index 3783c02..9668012 100644
--- a/src/org/mxchange/jfinancials/model/receipt_item/ReceiptItems.java
+++ b/src/org/mxchange/jfinancials/model/receipt_item/ReceiptItems.java
@@ -21,7 +21,7 @@ import java.text.MessageFormat;
 import java.util.Objects;
 
 /**
- * A utilities class for receipts
+ * A utilities class for receipt items
  *
  * @author Roland Häder<roland@mxchange.org>
  */
@@ -32,6 +32,44 @@ public class ReceiptItems implements Serializable {
 	 */
 	private static final long serialVersionUID = 2_867_938_676_165_402L;
 
+	/**
+	 * Copies all fields from source entity to target entity. An exception might
+	 * be thrown when both instances are the same.
+	 * <p>
+	 * @param sourceReceiptItem Source receipt item instance
+	 * @param targetReceiptItem Target receipt item instance
+	 */
+	public static void copyReceiptItemData (final BillableReceiptItem sourceReceiptItem, final BillableReceiptItem targetReceiptItem) {
+		// Check parameter
+		if (null == sourceReceiptItem) {
+			// Throw NPE
+			throw new NullPointerException("sourceReceiptItem is null"); //NOI18N
+		} else if (null == targetReceiptItem) {
+			// Throw NPE
+			throw new NullPointerException("targetReceiptItem is null"); //NOI18N
+		} else if (Objects.equals(sourceReceiptItem, targetReceiptItem)) {
+			// Throw IAE
+			throw new IllegalArgumentException("sourceReceiptItem and targetReceiptItem are the same."); //NOI18N
+		}
+
+		// Copy all fields
+		sourceReceiptItem.setItemBrandName(targetReceiptItem.getItemBrandName());
+		sourceReceiptItem.setItemCouponNumber(targetReceiptItem.getItemCouponNumber());
+		sourceReceiptItem.setItemEntryCreated(targetReceiptItem.getItemEntryCreated());
+		sourceReceiptItem.setItemEntryUpdated(targetReceiptItem.getItemEntryUpdated());
+		sourceReceiptItem.setItemGrossPrice(targetReceiptItem.getItemGrossPrice());
+		sourceReceiptItem.setItemId(targetReceiptItem.getItemId());
+		sourceReceiptItem.setItemIsDiscount(targetReceiptItem.getItemIsDiscount());
+		sourceReceiptItem.setItemIsRefund(targetReceiptItem.getItemIsRefund());
+		sourceReceiptItem.setItemManufacturer(targetReceiptItem.getItemManufacturer());
+		sourceReceiptItem.setItemNetPrice(targetReceiptItem.getItemNetPrice());
+		sourceReceiptItem.setItemNumber(targetReceiptItem.getItemNumber());
+		sourceReceiptItem.setItemProduct(targetReceiptItem.getItemProduct());
+		sourceReceiptItem.setItemProductQuantity(targetReceiptItem.getItemProductQuantity());
+		sourceReceiptItem.setItemReceipt(targetReceiptItem.getItemReceipt());
+		sourceReceiptItem.setItemTaxRate(targetReceiptItem.getItemTaxRate());
+	}
+
 	/**
 	 * Checks if both receipt items are the same by assigned receipt, product
 	 * and quantity.
-- 
2.39.5