]> git.mxchange.org Git - jfinancials-ejb.git/commitdiff
Don't cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 24 Apr 2020 19:49:31 +0000 (21:49 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 24 Apr 2020 19:59:05 +0000 (21:59 +0200)
- avoided local copy of List instance
- if a receiptItem is updated, no matter if discount or refund, check it. Also
  then only rely on the primary key

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/enterprise/financial/receipt_item/BaseFinancialsReceiptItemEnterpriseBean.java
src/java/org/mxchange/jfinancials/model/receipt_item/FinancialAdminReceiptItemSessionBean.java
src/java/org/mxchange/jfinancials/model/receipt_item/FinancialReceiptItemSessionBean.java

index c09aa9d16e20f5c0e1ff43ff4a40f8daf0c3c714..ad06ce1efd5d27471b57c2158c0dab849af954c2 100644 (file)
@@ -85,7 +85,7 @@ public abstract class BaseFinancialsReceiptItemEnterpriseBean extends BaseFinanc
                managedReceiptItem.setItemEntryUpdated(new Date());
 
                // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceipt: managedReceiptItem={0} - EXIT!", managedReceiptItem)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeReceiptItem: managedReceiptItem={0} - EXIT!", managedReceiptItem)); //NOI18N
 
                // Return detached receipt
                return managedReceiptItem;
index 3c361f44677e8256e12f35377a8598917a77b0bb..61a239c19d5fd6992dce1188860aab2603a73263 100644 (file)
@@ -18,7 +18,7 @@ package org.mxchange.jfinancials.model.receipt_item;
 
 import java.text.MessageFormat;
 import java.util.Date;
-import java.util.List;
+import java.util.Objects;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
@@ -81,7 +81,7 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsReceiptI
                } else if (receiptItem.getItemReceipt().getReceiptId() < 1) {
                        // Throw NPE
                        throw new NullPointerException(MessageFormat.format("receiptItem.itemReceipt.receiptId={0} is invalid.", receiptItem.getItemReceipt().getReceiptId())); //NOI18N
-               } else if (this.isReceiptItemRegistered(receiptItem)) {
+               } else if (this.isReceiptItemRegistered(receiptItem, false, false)) {
                        // Is already registered
                        throw new ReceiptItemAlreadyAddedException(receiptItem);
                }
@@ -129,8 +129,8 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsReceiptI
                } else if (receiptItem.getItemId() < 1) {
                        // Throw IAE
                        throw new IllegalArgumentException(MessageFormat.format("receiptItem.itemId={0} is invalid", receiptItem.getItemId())); //NOI18N
-               } else if (!this.isReceiptItemRegistered(receiptItem)) {
-                       // Not found
+               } else if (!this.isReceiptItemRegistered(receiptItem, true, true)) {
+                       // No discount and not found
                        throw new ReceiptItemNotFoundException(receiptItem);
                }
 
@@ -147,16 +147,18 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsReceiptI
        /**
         * Checks if given receipt item has already been added to receipt.
         * <p>
-        * @param receiptItem Receipt item
+        * @param receiptItem         Receipt item
+        * @param checkDiscountRefund Whether to check discounts and refunds
+        * @param checkOnlyPrimaryKey Whether to check only primary key
         * <p>
         * @return Whether item has already been added to receipt item's receipt
         */
-       private boolean isReceiptItemRegistered (final BillableReceiptItem receiptItem) {
+       private boolean isReceiptItemRegistered (final BillableReceiptItem receiptItem, final boolean checkDiscountRefund, final boolean checkOnlyPrimaryKey) {
                // Default is not found
                boolean isFound = false;
 
                // Is the item type a discount?
-               if (receiptItem.getItemIsDiscount()) {
+               if (!checkDiscountRefund && receiptItem.getItemIsDiscount()) {
                        // Yes, then allow it multiple items
                        return false;
                }
@@ -165,12 +167,9 @@ public class FinancialAdminReceiptItemSessionBean extends BaseFinancialsReceiptI
                 * Get all receipt's receipt items. No need to look global as people may
                 * buy the same item again and again ... ;-)
                 */
-               final List<BillableReceiptItem> receiptItems = this.receiptItemBean.fetchReceiptItemsByReceipt(receiptItem.getItemReceipt());
-
-               // Loop through all entries
-               for (final BillableReceiptItem item : receiptItems) {
+               for (final BillableReceiptItem currentReceiptItem : this.receiptItemBean.fetchReceiptItemsByReceipt(receiptItem.getItemReceipt())) {
                        // Is it the same item?
-                       if (ReceiptItems.isSameReceiptItem(item, receiptItem) && (!item.getItemIsRefund())) {
+                       if (((checkOnlyPrimaryKey && Objects.equals(currentReceiptItem.getItemId(), receiptItem.getItemId())) || ReceiptItems.isSameReceiptItem(currentReceiptItem, receiptItem)) && (checkDiscountRefund || !currentReceiptItem.getItemIsRefund())) {
                                // Found it
                                isFound = true;
                                break;
index 5b5d4e2a71ab9ed902002e8ef740514e46cac9a0..b566b841675b34768d1947879426bb754312ee89 100644 (file)
@@ -168,10 +168,7 @@ public class FinancialReceiptItemSessionBean extends BaseFinancialsEnterpriseBea
                 * Get all receipt's receipt items. No need to look global as people may
                 * buy the same item again and again ... ;-)
                 */
-               final List<BillableReceiptItem> receiptItems = this.fetchReceiptItemsByReceipt(receiptItem.getItemReceipt());
-
-               // Loop through all entries
-               for (final BillableReceiptItem item : receiptItems) {
+               for (final BillableReceiptItem item : this.fetchReceiptItemsByReceipt(receiptItem.getItemReceipt())) {
                        // Is it the same item?
                        if (ReceiptItems.isSameReceiptItem(item, receiptItem)) {
                                // Found it