From: Roland Häder Date: Sat, 25 Apr 2020 16:54:17 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=99a33d25072f76d55f044f33b7497667cdbfd6c2;p=jfinancials-war.git Don't cherry-pick: - introduced administrative action backing bean for receipt items - introduced converter for receipt items - introduced uniqueAddReceiptItem() and CDI observers for updating cache/lists - introduced findReceiptItemById() - let's distinguish between administrative and user events - updateReceipt returns now a redirection outcome (back to admin-list-receipts view) - reformatted Java code a bit for having all parameter of huge constructors in a separate line - added missing navigation rules from edit -> list views - added missing i18n strings Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java index 504056df..d8ebc52b 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java @@ -325,7 +325,12 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen */ private BillableReceipt createReceiptInstance () { // Init receipt instance - final BillableReceipt receipt = new FinancialReceipt(this.getReceiptPaymentType(), this.getReceiptBranchOffice(), this.userLoginController.getLoggedInUser(), this.getReceiptIssued()); + final BillableReceipt receipt = new FinancialReceipt( + this.getReceiptPaymentType(), + this.getReceiptBranchOffice(), + this.userLoginController.getLoggedInUser(), + this.getReceiptIssued() + ); // Set optional fields receipt.setReceiptNumber(this.getReceiptNumber()); diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewBean.java index 22ea399c..2332e2a2 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewBean.java @@ -222,7 +222,7 @@ public class FinancialAdminReceiptActionWebViewBean extends BaseFinancialsBean i // Is current receipt instance valid? if (this.getCurrentReceipt() == null) { // Not set - throw new NullPointerException("this.currentReceipt is null"); + throw new NullPointerException("this.currentReceipt is null"); //NOI18N } // Copy all fields @@ -480,14 +480,14 @@ public class FinancialAdminReceiptActionWebViewBean extends BaseFinancialsBean i * Updates receipt instance with new data. This copies all fields from this * backing bean into currentReceipt instance which should be still there. */ - public void updateReceipt () { + public String updateReceipt () { // Is current instance still there? if (this.getCurrentReceipt() == null) { // Throw NPE - throw new NullPointerException("this.currentReceipt is null"); + throw new NullPointerException("this.currentReceipt is null"); //NOI18N } else if (this.getCurrentReceipt().getReceiptId() == null) { // Throw NPE again - throw new NullPointerException("this.currentReceipt.receiptId is null"); + throw new NullPointerException("this.currentReceipt.receiptId is null"); //NOI18N } // Create new instance @@ -496,8 +496,8 @@ public class FinancialAdminReceiptActionWebViewBean extends BaseFinancialsBean i // Is it the same? if (Objects.equals(receipt, this.getCurrentReceipt())) { // Yes, then abort here with message to user - this.showFacesMessage("form-edit-receipt", "ADMIN_ERROR_FINANCIAL_RECEIPT_NOT_CHANGED", FacesMessage.SEVERITY_ERROR); - return; + this.showFacesMessage("form-edit-receipt", "ADMIN_ERROR_FINANCIAL_RECEIPT_NOT_CHANGED", FacesMessage.SEVERITY_WARN); //NOI18N + return ""; //NOI18N } // Copy all data @@ -519,6 +519,9 @@ public class FinancialAdminReceiptActionWebViewBean extends BaseFinancialsBean i // Clear bean this.clear(); + + // Redirect to list view + return "admin_list_receipts"; //NOI18N } /** diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java index aff6b0a0..c5d0baa9 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java @@ -16,26 +16,9 @@ */ package org.mxchange.jfinancials.beans.financial.model.receipt_item; -import java.math.BigDecimal; -import java.text.MessageFormat; -import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.inject.Any; -import javax.faces.FacesException; -import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; -import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; -import org.mxchange.jfinancials.events.receipt_item.added.ReceiptItemAddedEvent; -import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedException; -import org.mxchange.jfinancials.model.receipt.BillableReceipt; -import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; -import org.mxchange.jfinancials.model.receipt_item.FinancialAdminReceiptItemSessionBeanRemote; -import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItem; -import org.mxchange.jproduct.model.product.Product; /** * An administrative backing bean for receipt items @@ -51,90 +34,6 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean */ private static final long serialVersionUID = 595_754_280_374_172L; - /** - * Event being fired when administrator has added a new receipt item - */ - @Inject - @Any - private Event adminAddedReceiptItemEvent; - - /** - * EJB for general financial receipt item purposes - */ - @EJB (lookup = "java:global/jfinancials-ejb/adminFinancialReceiptItem!org.mxchange.jfinancials.model.receipt_item.FinancialAdminReceiptItemSessionBeanRemote") - private FinancialAdminReceiptItemSessionBeanRemote adminReceiptItemBean; - - /** - * Item brand name - */ - private String itemBrandName; - - /** - * Coupon number assigned with item - */ - private String itemCouponNumber; - - /** - * Whether the item is a discount on whole receipt or item - */ - private Boolean itemIsDiscount; - - /** - * Whether the item is a refund - */ - private Boolean itemIsRefund; - - /** - * Item manufacturer/producer - */ - private BasicData itemManufacturer; - - /** - * Item's number - */ - private Long itemNumber; - - /** - * Item product - */ - private Product itemProduct; - - /** - * Quantity of item - */ - private BigDecimal itemQuantity; - - /** - * Assigned receipt - */ - private BillableReceipt itemReceipt; - - /** - * Currency code like EUR or USD - */ - private String productCurrencyCode; - - /** - * Product's gross price - */ - private BigDecimal productGrossPrice; - - /** - * Product's net price - */ - private BigDecimal productNetPrice; - - /** - * Tax rate for this item - */ - private BigDecimal productTaxRate; - - /** - * Receipt item list controller - */ - @Inject - private FinancialsReceiptItemListWebViewController receiptItemListController; - /** * Default constructor */ @@ -143,320 +42,4 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean super(); } - /** - * Adds the completed receipt item to database by calling an EJB business - * method. If not all required fields are set, a proper exception is being - * thrown. - *

- */ - public void addReceiptItem () { - // Are all required fields set? - - // Prepare receipt item instance - final BillableReceiptItem receiptItem = this.createReceiptItemInstance(); - - // Is the receipt already there? - if (this.receiptItemListController.isReceiptItemAdded(receiptItem)) { - // Receipt has already been added - throw new FacesException(MessageFormat.format("Receipt for itemReceipt.receiptId={0},itemProduct.productId={1},itemProductQuantity={2} has already been added.", receiptItem.getItemReceipt().getReceiptId(), receiptItem.getItemProduct().getProductId(), receiptItem.getItemProductQuantity())); //NOI18N - } - - // Init variable - final BillableReceiptItem updatedReceiptItem; - - // All is set, then try to call EJB - try { - // Add it - updatedReceiptItem = this.adminReceiptItemBean.addReceiptItem(receiptItem); - } catch (final ReceiptItemAlreadyAddedException ex) { - // Throw it again - throw new FacesException(ex); - } - - // Fire event with updated instance - this.adminAddedReceiptItemEvent.fire(new ReceiptItemAddedEvent(updatedReceiptItem)); - - // Clear bean - this.clear(); - } - - /** - * Getter for item brand name - *

- * @return Item brand name - */ - public String getItemBrandName () { - return this.itemBrandName; - } - - /** - * Setter for item brand name - *

- * @param itemBrandName Item brand name - */ - public void setItemBrandName (final String itemBrandName) { - this.itemBrandName = itemBrandName; - } - - /** - * Getter for item's coupon number - *

- * @return Item's coupon number - */ - public String getItemCouponNumber () { - return this.itemCouponNumber; - } - - /** - * Setter for item's coupon number - *

- * @param itemCouponNumber Item's coupon number - */ - public void setItemCouponNumber (final String itemCouponNumber) { - this.itemCouponNumber = itemCouponNumber; - } - - /** - * Getter for whether the item is a discount on whole receipt or item - *

- * @return Whether the item is a discount on whole receipt or item - */ - public Boolean getItemIsDiscount () { - return this.itemIsDiscount; - } - - /** - * Setter for whether the item is a discount on whole receipt or item - *

- * @param itemIsDiscount Whether the item is a discount on whole receipt or - * item - */ - public void setItemIsDiscount (final Boolean itemIsDiscount) { - this.itemIsDiscount = itemIsDiscount; - } - - /** - * Getter for whether the item is a refund - *

- * @return Whether the item is a refund - */ - public Boolean getItemIsRefund () { - return this.itemIsRefund; - } - - /** - * Setter for whether the item is a refund - *

- * @param itemIsRefund Whether the item is a refund - */ - public void setItemIsRefund (final Boolean itemIsRefund) { - this.itemIsRefund = itemIsRefund; - } - - /** - * Getter for item manufacturer/producer - *

- * @return Item manufacturer/producer - */ - public BasicData getItemManufacturer () { - return this.itemManufacturer; - } - - /** - * Setter for item manufacturer/producer - *

- * @param itemManufacturer Item manufacturer/producer - */ - public void setItemManufacturer (final BasicData itemManufacturer) { - this.itemManufacturer = itemManufacturer; - } - - /** - * Getter for item's number - *

- * @return Item's number - */ - public Long getItemNumber () { - return this.itemNumber; - } - - /** - * Setter for item's number - *

- * @param itemNumber Item's number - */ - public void setItemNumber (final Long itemNumber) { - this.itemNumber = itemNumber; - } - - /** - * Getter for assigned product - *

- * @return Assigned product - */ - public Product getItemProduct () { - return this.itemProduct; - } - - /** - * Setter for assigned product - *

- * @param itemProduct Assigned product - */ - public void setItemProduct (final Product itemProduct) { - this.itemProduct = itemProduct; - } - - /** - * Getter for item quantity - *

- * @return Item quantity - */ - public BigDecimal getItemQuantity () { - return this.itemQuantity; - } - - /** - * Setter for item quantity - *

- * @param itemQuantity Item quantity - */ - public void setItemQuantity (final BigDecimal itemQuantity) { - this.itemQuantity = itemQuantity; - } - - /** - * Getter for assigned receipt - *

- * @return Assigned receipt - */ - public BillableReceipt getItemReceipt () { - return this.itemReceipt; - } - - /** - * Setter for assigned receipt - *

- * @param itemReceipt Assigned receipt - */ - public void setItemReceipt (final BillableReceipt itemReceipt) { - this.itemReceipt = itemReceipt; - } - - /** - * Getter for product's currency symbol - *

- * @return Product's currency symbol - */ - public String getProductCurrencyCode () { - return this.productCurrencyCode; - } - - /** - * Setter for product's currency symbol - *

- * @param productCurrencyCode Product's currency symbol - */ - public void setProductCurrencyCode (final String productCurrencyCode) { - this.productCurrencyCode = productCurrencyCode; - } - - /** - * Getter for product's gross price - *

- * @return Product's gross price - */ - public BigDecimal getProductGrossPrice () { - return this.productGrossPrice; - } - - /** - * Setter for product's gross price - *

- * @param productGrossPrice Product's gross price - */ - public void setProductGrossPrice (final BigDecimal productGrossPrice) { - this.productGrossPrice = productGrossPrice; - } - - /** - * Getter for product's net price - *

- * @return Product's net price - */ - public BigDecimal getProductNetPrice () { - return this.productNetPrice; - } - - /** - * Setter for product's net price - *

- * @param productNetPrice Product's net price - */ - public void setProductNetPrice (final BigDecimal productNetPrice) { - this.productNetPrice = productNetPrice; - } - - /** - * Getter for product's tax rate - *

- * @return Product's tax rate - */ - public BigDecimal getProductTaxRate () { - return this.productTaxRate; - } - - /** - * Setter for product's tax rate - *

- * @param productTaxRate Product's tax rate - */ - public void setProductTaxRate (final BigDecimal productTaxRate) { - this.productTaxRate = productTaxRate; - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all fields - this.setItemBrandName(null); - this.setItemCouponNumber(null); - this.setItemIsDiscount(null); - this.setItemIsRefund(null); - this.setItemManufacturer(null); - this.setItemNumber(null); - this.setItemProduct(null); - this.setItemQuantity(null); - this.setItemReceipt(null); - this.setProductCurrencyCode(null); - this.setProductGrossPrice(null); - this.setProductNetPrice(null); - this.setProductTaxRate(null); - } - - /** - * Creates a new instance from all available data of this bean. - *

- * @return Receipt item instance - */ - private BillableReceiptItem createReceiptItemInstance () { - // Create new instance with minimum required data - final BillableReceiptItem receiptItem = new FinancialReceiptItem(this.getItemProduct(), this.getItemQuantity(), this.getItemReceipt()); - - // Set optional data - receiptItem.setItemBrandName(this.getItemBrandName()); - receiptItem.setItemCouponNumber(this.getItemCouponNumber()); - receiptItem.setItemIsDiscount(this.getItemIsDiscount()); - receiptItem.setItemIsRefund(this.getItemIsRefund()); - receiptItem.setItemManufacturer(this.getItemManufacturer()); - receiptItem.setItemNumber(this.getItemNumber()); - receiptItem.setItemGrossPrice(this.getProductGrossPrice()); - receiptItem.setItemNetPrice(this.getProductNetPrice()); - receiptItem.setItemTaxRate(this.getProductTaxRate()); - - // Return prepared instance - return receiptItem; - } - } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java index aebad4b0..dc8c4738 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java @@ -27,8 +27,8 @@ import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; -import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; -import org.mxchange.jfinancials.events.receipt_item.added.ReceiptItemAddedEvent; +import org.mxchange.jfinancials.events.receipt_item.added.AdminReceiptItemAddedEvent; +import org.mxchange.jfinancials.events.receipt_item.added.ObservableAdminReceiptItemAddedEvent; import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedException; import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItem; @@ -53,7 +53,7 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl */ @Inject @Any - private Event addedReceiptItemEvent; + private Event addedReceiptItemEvent; /** * EJB for general financial receipt purposes @@ -117,7 +117,7 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl } // Fire event with updated instance - this.addedReceiptItemEvent.fire(new ReceiptItemAddedEvent(updatedReceiptItem)); + this.addedReceiptItemEvent.fire(new AdminReceiptItemAddedEvent(updatedReceiptItem)); // Clear bean this.clear(); diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/action/FinancialAdminReceiptItemActionWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/action/FinancialAdminReceiptItemActionWebRequestBean.java new file mode 100644 index 00000000..f6d515d2 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/action/FinancialAdminReceiptItemActionWebRequestBean.java @@ -0,0 +1,595 @@ +/* + * Copyright (C) 2017 - 2020 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 + * 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 . + */ +package org.mxchange.jfinancials.beans.financial.model.receipt_item.action; + +import java.math.BigDecimal; +import java.text.MessageFormat; +import java.util.Objects; +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.faces.FacesException; +import javax.faces.application.FacesMessage; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; +import org.mxchange.jfinancials.events.receipt_item.added.AdminReceiptItemAddedEvent; +import org.mxchange.jfinancials.events.receipt_item.added.ObservableAdminReceiptItemAddedEvent; +import org.mxchange.jfinancials.events.receipt_item.updated.AdminReceiptItemUpdatedEvent; +import org.mxchange.jfinancials.events.receipt_item.updated.ObservableAdminReceiptItemUpdatedEvent; +import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedException; +import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemNotFoundException; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; +import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; +import org.mxchange.jfinancials.model.receipt_item.FinancialAdminReceiptItemSessionBeanRemote; +import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItem; +import org.mxchange.jfinancials.model.receipt_item.ReceiptItems; +import org.mxchange.jproduct.model.product.Product; + +/** + * An administrative action backing bean for receipt items + *

+ * @author Roland Häder + */ +@Named ("adminReceiptItemActionController") +@RequestScoped +public class FinancialAdminReceiptItemActionWebRequestBean extends BaseFinancialsBean implements FinancialAdminReceiptItemActionWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 595_754_280_374_173L; + + /** + * Event being fired when administrator has added a new receipt item + */ + @Inject + @Any + private Event adminAddedReceiptItemEvent; + + /** + * EJB for general financial receipt item purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/adminFinancialReceiptItem!org.mxchange.jfinancials.model.receipt_item.FinancialAdminReceiptItemSessionBeanRemote") + private FinancialAdminReceiptItemSessionBeanRemote adminReceiptItemBean; + + /** + * Event being fired when an administrator has updated a receipt item + * instance + */ + @Any + @Inject + private Event adminUpdatedReceiptItemEvent; + + /** + * Currently worked on receipt item + */ + private BillableReceiptItem currentReceiptItem; + + /** + * Item brand name + */ + private String itemBrandName; + + /** + * Coupon number assigned with item + */ + private String itemCouponNumber; + + /** + * Product's gross price + */ + private BigDecimal itemGrossPrice; + + /** + * Item's primary key + */ + private Long itemId; + + /** + * Whether the item is a discount on whole receipt or item + */ + private Boolean itemIsDiscount; + + /** + * Whether the item is a refund + */ + private Boolean itemIsRefund; + + /** + * Item manufacturer/producer + */ + private BasicData itemManufacturer; + + /** + * Product's net price + */ + private BigDecimal itemNetPrice; + + /** + * Item's number + */ + private Long itemNumber; + + /** + * Item product + */ + private Product itemProduct; + + /** + * Quantity of item + */ + private BigDecimal itemProductQuantity; + + /** + * Assigned receipt + */ + private BillableReceipt itemReceipt; + + /** + * Tax rate for this item + */ + private BigDecimal itemTaxRate; + + /** + * Receipt item list controller + */ + @Inject + private FinancialsReceiptItemListWebViewController receiptItemListController; + + /** + * Default constructor + */ + public FinancialAdminReceiptItemActionWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Adds the completed receipt item to database by calling an EJB business + * method. If not all required fields are set, a proper exception is being + * thrown. + *

+ */ + public void addReceiptItem () { + // Are all required fields set? + + // Prepare receipt item instance + final BillableReceiptItem receiptItem = this.createReceiptItemInstance(); + + // Is the receipt already there? + if (this.receiptItemListController.isReceiptItemAdded(receiptItem)) { + // Receipt has already been added + throw new FacesException(MessageFormat.format("Receipt for itemReceipt.receiptId={0},itemProduct.productId={1},itemProductQuantity={2} has already been added.", receiptItem.getItemReceipt().getReceiptId(), receiptItem.getItemProduct().getProductId(), receiptItem.getItemProductQuantity())); //NOI18N + } + + // Init variable + final BillableReceiptItem updatedReceiptItem; + + // All is set, then try to call EJB + try { + // Add it + updatedReceiptItem = this.adminReceiptItemBean.addReceiptItem(receiptItem); + } catch (final ReceiptItemAlreadyAddedException ex) { + // Throw it again + throw new FacesException(ex); + } + + // Fire event with updated instance + this.adminAddedReceiptItemEvent.fire(new AdminReceiptItemAddedEvent(updatedReceiptItem)); + + // Clear bean + this.clear(); + } + + /** + * Copies all receipt item properties from currentReceiptItem instance + */ + public void copyAllReceiptItemProperties () { + // Is the instance set? + if (this.getCurrentReceiptItem() == null) { + // Throw NPE + throw new NullPointerException("this.currrentReceiptItem is null"); //NOI18N + } else if (this.getCurrentReceiptItem().getItemId() == null) { + // Throw NPE again + throw new NullPointerException("this.currrentReceiptItem.itemId is null"); //NOI18N + } else if (this.getCurrentReceiptItem().getItemId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("this.currrentReceiptItem.itemId={0} is invalid", this.getCurrentReceiptItem().getItemId())); //NOI18N + } + + // Copy all item fields + this.setItemBrandName(this.getCurrentReceiptItem().getItemBrandName()); + this.setItemCouponNumber(this.getCurrentReceiptItem().getItemCouponNumber()); + this.setItemGrossPrice(this.getCurrentReceiptItem().getItemGrossPrice()); + this.setItemId(this.getCurrentReceiptItem().getItemId()); + this.setItemIsDiscount(this.getCurrentReceiptItem().getItemIsDiscount()); + this.setItemIsRefund(this.getCurrentReceiptItem().getItemIsRefund()); + this.setItemManufacturer(this.getCurrentReceiptItem().getItemManufacturer()); + this.setItemNetPrice(this.getCurrentReceiptItem().getItemNetPrice()); + this.setItemNumber(this.getCurrentReceiptItem().getItemNumber()); + this.setItemProduct(this.getCurrentReceiptItem().getItemProduct()); + this.setItemProductQuantity(this.getCurrentReceiptItem().getItemProductQuantity()); + this.setItemReceipt(this.getCurrentReceiptItem().getItemReceipt()); + this.setItemTaxRate(this.getCurrentReceiptItem().getItemTaxRate()); + } + + /** + * Getter for current receipt item + *

+ * @return Current receipt item + */ + public BillableReceiptItem getCurrentReceiptItem () { + return this.currentReceiptItem; + } + + /** + * Setter for current receipt item + *

+ * @param currentReceiptItem Current receipt item + */ + public void setCurrentReceiptItem (final BillableReceiptItem currentReceiptItem) { + this.currentReceiptItem = currentReceiptItem; + } + + /** + * Getter for item brand name + *

+ * @return Item brand name + */ + public String getItemBrandName () { + return this.itemBrandName; + } + + /** + * Setter for item brand name + *

+ * @param itemBrandName Item brand name + */ + public void setItemBrandName (final String itemBrandName) { + this.itemBrandName = itemBrandName; + } + + /** + * Getter for item's coupon number + *

+ * @return Item's coupon number + */ + public String getItemCouponNumber () { + return this.itemCouponNumber; + } + + /** + * Setter for item's coupon number + *

+ * @param itemCouponNumber Item's coupon number + */ + public void setItemCouponNumber (final String itemCouponNumber) { + this.itemCouponNumber = itemCouponNumber; + } + + /** + * Getter for product's gross price + *

+ * @return Product's gross price + */ + public BigDecimal getItemGrossPrice () { + return this.itemGrossPrice; + } + + /** + * Setter for product's gross price + *

+ * @param itemGrossPrice Product's gross price + */ + public void setItemGrossPrice (final BigDecimal itemGrossPrice) { + this.itemGrossPrice = itemGrossPrice; + } + + /** + * Getter for item's primary key + *

+ * @return Item's primary key + */ + public Long getItemId () { + return this.itemId; + } + + /** + * Setter for item's primary key + *

+ * @param itemId Item's primary key + */ + public void setItemId (final Long itemId) { + this.itemId = itemId; + } + + /** + * Getter for whether the item is a discount on whole receipt or item + *

+ * @return Whether the item is a discount on whole receipt or item + */ + public Boolean getItemIsDiscount () { + return this.itemIsDiscount; + } + + /** + * Setter for whether the item is a discount on whole receipt or item + *

+ * @param itemIsDiscount Whether the item is a discount on whole receipt or + * item + */ + public void setItemIsDiscount (final Boolean itemIsDiscount) { + this.itemIsDiscount = itemIsDiscount; + } + + /** + * Getter for whether the item is a refund + *

+ * @return Whether the item is a refund + */ + public Boolean getItemIsRefund () { + return this.itemIsRefund; + } + + /** + * Setter for whether the item is a refund + *

+ * @param itemIsRefund Whether the item is a refund + */ + public void setItemIsRefund (final Boolean itemIsRefund) { + this.itemIsRefund = itemIsRefund; + } + + /** + * Getter for item manufacturer/producer + *

+ * @return Item manufacturer/producer + */ + public BasicData getItemManufacturer () { + return this.itemManufacturer; + } + + /** + * Setter for item manufacturer/producer + *

+ * @param itemManufacturer Item manufacturer/producer + */ + public void setItemManufacturer (final BasicData itemManufacturer) { + this.itemManufacturer = itemManufacturer; + } + + /** + * Getter for product's net price + *

+ * @return Product's net price + */ + public BigDecimal getItemNetPrice () { + return this.itemNetPrice; + } + + /** + * Setter for product's net price + *

+ * @param itemNetPrice Product's net price + */ + public void setItemNetPrice (final BigDecimal itemNetPrice) { + this.itemNetPrice = itemNetPrice; + } + + /** + * Getter for item's number + *

+ * @return Item's number + */ + public Long getItemNumber () { + return this.itemNumber; + } + + /** + * Setter for item's number + *

+ * @param itemNumber Item's number + */ + public void setItemNumber (final Long itemNumber) { + this.itemNumber = itemNumber; + } + + /** + * Getter for assigned product + *

+ * @return Assigned product + */ + public Product getItemProduct () { + return this.itemProduct; + } + + /** + * Setter for assigned product + *

+ * @param itemProduct Assigned product + */ + public void setItemProduct (final Product itemProduct) { + this.itemProduct = itemProduct; + } + + /** + * Getter for item product quantity + *

+ * @return Item product quantity + */ + public BigDecimal getItemProductQuantity () { + return this.itemProductQuantity; + } + + /** + * Setter for item product quantity + *

+ * @param itemProductQuantity Item product quantity + */ + public void setItemProductQuantity (final BigDecimal itemProductQuantity) { + this.itemProductQuantity = itemProductQuantity; + } + + /** + * Getter for assigned receipt + *

+ * @return Assigned receipt + */ + public BillableReceipt getItemReceipt () { + return this.itemReceipt; + } + + /** + * Setter for assigned receipt + *

+ * @param itemReceipt Assigned receipt + */ + public void setItemReceipt (final BillableReceipt itemReceipt) { + this.itemReceipt = itemReceipt; + } + + /** + * Getter for product's tax rate + *

+ * @return Product's tax rate + */ + public BigDecimal getItemTaxRate () { //NOI18N + return this.itemTaxRate; + } + + /** + * Setter for product's tax rate + *

+ * @param itemTaxRate Product's tax rate + */ + public void setItemTaxRate (final BigDecimal itemTaxRate) { //NOI18N + this.itemTaxRate = itemTaxRate; + } + + /** + * Updates currently worked on receipt item instance. + *

+ * @return Redirection outcome + */ + public String updateReceiptItem () { + // Is current instance set? + if (this.getCurrentReceiptItem() == null) { + // Throw NPE + throw new NullPointerException("this.currentReceiptItem is null"); //NOI18N + } else if (this.getCurrentReceiptItem().getItemId() == null) { + // Throw NPE again + throw new NullPointerException("this.currentReceiptItem.itemId is null"); //NOI18N + } else if (this.getCurrentReceiptItem().getItemId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("this.currentReceiptItem.itemId={0} is null", this.getCurrentReceiptItem().getItemId())); //NOI18N + } + + // Init instance + final BillableReceiptItem receiptItem = this.createReceiptItemInstance(); + + // Is it the same? + if (Objects.equals(receiptItem, this.getCurrentReceiptItem())) { + // Yes, then abort here with message to user + this.showFacesMessage("form-edit-receipt-item", "ADMIN_ERROR_FINANCIAL_RECEIPT_ITEM_NOT_CHANGED", FacesMessage.SEVERITY_WARN); //NOI18N + return ""; //NOI18N + } + + // Copy all data + System.out.println("receiptItem.itemEntryCreated=" + receiptItem.getItemEntryCreated()); + ReceiptItems.copyReceiptItemData(receiptItem, this.getCurrentReceiptItem()); + + // Create updated receipt instance + final BillableReceiptItem updatedReceiptItem; + + try { + // Invoke EJB method + updatedReceiptItem = this.adminReceiptItemBean.updateReceiptItem(this.getCurrentReceiptItem()); + } catch (final ReceiptItemNotFoundException ex) { + // Throw as cause + throw new FacesException(ex); + } + + // Fire event + this.adminUpdatedReceiptItemEvent.fire(new AdminReceiptItemUpdatedEvent(updatedReceiptItem)); + + // Clear bean + this.clear(); + + // Redirect to list view + return "admin_list_receipt_items"; //NOI18N + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all fields + this.setItemBrandName(null); + this.setItemCouponNumber(null); + this.setItemGrossPrice(null); + this.setItemIsDiscount(null); + this.setItemIsRefund(null); + this.setItemManufacturer(null); + this.setItemNetPrice(null); + this.setItemNumber(null); + this.setItemProduct(null); + this.setItemProductQuantity(null); + this.setItemReceipt(null); + this.setItemTaxRate(null); + } + + /** + * Creates a new instance from all available data of this bean. + *

+ * @return Receipt item instance + */ + private BillableReceiptItem createReceiptItemInstance () { + // Create new instance with minimum required data + final BillableReceiptItem receiptItem = new FinancialReceiptItem( + this.getItemProduct(), + this.getItemProductQuantity(), + this.getItemReceipt() + ); + + // Set optional data + receiptItem.setItemBrandName(this.getItemBrandName()); + receiptItem.setItemCouponNumber(this.getItemCouponNumber()); + receiptItem.setItemGrossPrice(this.getItemGrossPrice()); + receiptItem.setItemId(this.getItemId()); + receiptItem.setItemIsDiscount(this.getItemIsDiscount()); + receiptItem.setItemIsRefund(this.getItemIsRefund()); + receiptItem.setItemManufacturer(this.getItemManufacturer()); + receiptItem.setItemNetPrice(this.getItemNetPrice()); + receiptItem.setItemNumber(this.getItemNumber()); + receiptItem.setItemTaxRate(this.getItemTaxRate()); + + // Is current instance given? + if (this.getCurrentReceiptItem() instanceof BillableReceiptItem) { + // Yes, copy created/updated instances + receiptItem.setItemEntryCreated(this.getCurrentReceiptItem().getItemEntryCreated()); + receiptItem.setItemEntryUpdated(this.getCurrentReceiptItem().getItemEntryUpdated()); + } + + // Return prepared instance + return receiptItem; + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/action/FinancialAdminReceiptItemActionWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/action/FinancialAdminReceiptItemActionWebRequestController.java new file mode 100644 index 00000000..29309c27 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/action/FinancialAdminReceiptItemActionWebRequestController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2017 - 2020 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 + * 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 . + */ +package org.mxchange.jfinancials.beans.financial.model.receipt_item.action; + +import java.io.Serializable; + +/** + * An interface for administrative receipt item beans + *

+ * @author Roland Häder + */ +public interface FinancialAdminReceiptItemActionWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java index 9da906a0..0d935b70 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java @@ -19,6 +19,7 @@ package org.mxchange.jfinancials.beans.financial.model.receipt_item.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; import java.util.Comparator; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -31,7 +32,9 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; -import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; +import org.mxchange.jfinancials.events.receipt_item.added.ObservableAdminReceiptItemAddedEvent; +import org.mxchange.jfinancials.events.receipt_item.updated.ObservableAdminReceiptItemUpdatedEvent; +import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemNotFoundException; import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote; import org.mxchange.jfinancials.model.receipt_item.ReceiptItems; @@ -104,26 +107,57 @@ public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean imp } /** - * Observes events being fired when a new receipt item has been added + * Observes events being fired when an administrator has added a new receipt + * item. *

* @param event Event being fired */ - public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) { + public void afterAdminAddedReceiptItemEvent (@Observes final ObservableAdminReceiptItemAddedEvent event) { // Validate parameter if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedReceiptItem() == null) { + //Throw NPE again + throw new NullPointerException("event.addedReceiptItem is null"); //NOI18N + } else if (event.getAddedReceiptItem().getItemId() == null) { + //Throw NPE again + throw new NullPointerException("event.addedReceiptItem.itemId is null"); //NOI18N + } else if (event.getAddedReceiptItem().getItemId() < 1) { + //Throw IAE + throw new IllegalArgumentException(MessageFormat.format("event.addedReceiptItem.itemId={0} is not valid", event.getAddedReceiptItem().getItemId())); //NOI18N } // Add to cache and general list - this.receiptItemCache.put(event.getReceiptItem().getItemId(), event.getReceiptItem()); - this.getAllReceiptItems().add(event.getReceiptItem()); + this.receiptItemCache.put(event.getAddedReceiptItem().getItemId(), event.getAddedReceiptItem()); + this.uniqueAddReceiptItem(event.getAddedReceiptItem()); + } - // Is same user? - if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { - // Same user, then add it - this.userReceiptItems.add(event.getReceiptItem()); + /** + * Observes events being fired when an administrator has updated a receipt + * item instance. + *

+ * @param event Event being fired + */ + public void afterAdminUpdatedReceiptItemEvent (final @Observes ObservableAdminReceiptItemUpdatedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedReceiptItem() == null) { + //Throw NPE again + throw new NullPointerException("event.updatedReceiptItem is null"); //NOI18N + } else if (event.getUpdatedReceiptItem().getItemId() == null) { + //Throw NPE again + throw new NullPointerException("event.updatedReceiptItem.itemId is null"); //NOI18N + } else if (event.getUpdatedReceiptItem().getItemId() < 1) { + //Throw IAE + throw new IllegalArgumentException(MessageFormat.format("event.updatedReceiptItem.itemId={0} is not valid", event.getUpdatedReceiptItem().getItemId())); //NOI18N } + + // Add to cache and general list + this.receiptItemCache.put(event.getUpdatedReceiptItem().getItemId(), event.getUpdatedReceiptItem()); + this.uniqueAddReceiptItem(event.getUpdatedReceiptItem()); } /** @@ -157,6 +191,40 @@ public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean imp } } + @Override + public BillableReceiptItem findReceiptItemById (final Long receiptItemId) throws ReceiptItemNotFoundException { + // Validate parameter + if (null == receiptItemId) { + // Throw NPE + throw new NullPointerException("receiptItemId is null"); + } else if (receiptItemId < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("receiptItemId={0} is not valid.", receiptItemId)); + } + + // Init instance + BillableReceiptItem receiptItem = null; + + // Iterate over whole list + for (final BillableReceiptItem currentReceiptItem : this.getAllReceiptItems()) { + // Is the primary key matching? + if (Objects.equals(currentReceiptItem.getItemId(), receiptItemId)) { + // Yes, then remember and exit iteration + receiptItem = currentReceiptItem; + break; + } + } + + // Is found? + if (null == receiptItem) { + // Not found + throw new ReceiptItemNotFoundException(receiptItemId); + } + + // Return it + return receiptItem; + } + @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List getAllReceiptItems () { @@ -256,4 +324,51 @@ public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean imp return alreadyAdded; } + /** + * Uniquely add a receipt item instance. + *

+ * @param receiptItem To be added/updated receipt item instance + */ + private void uniqueAddReceiptItem (final BillableReceiptItem receiptItem) { + // Get iterator + final Iterator allIterator = this.getAllReceiptItems().iterator(); + + // Iterate over all entries + while (allIterator.hasNext()) { + // Get current item + final BillableReceiptItem currentReceiptItem = allIterator.next(); + + // It the id matching? + if (Objects.equals(receiptItem.getItemId(), currentReceiptItem.getItemId())) { + // Yes, then remove it and stop iterating + allIterator.remove(); + break; + } + } + + // Re-add it + this.getAllReceiptItems().add(receiptItem); + + // Is same user? + if (this.userLoginController.isUserLoggedIn() && Objects.equals(receiptItem.getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { + // Get iterator + final Iterator userIterator = this.userReceiptItems.iterator(); + + // Iterate over all entries + while (userIterator.hasNext()) { + // Get current item + final BillableReceiptItem currentReceiptItem = userIterator.next(); + + // It the id matching? + if (Objects.equals(receiptItem.getItemId(), currentReceiptItem.getItemId())) { + // Yes, then remove it and stop iterating + userIterator.remove(); + break; + } + } + + // Re-add it + this.userReceiptItems.add(receiptItem); + } + } } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewController.java index c0458468..2be532f8 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewController.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewController.java @@ -18,6 +18,7 @@ package org.mxchange.jfinancials.beans.financial.model.receipt_item.list; import java.io.Serializable; import java.util.List; +import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemNotFoundException; import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; /** @@ -27,6 +28,17 @@ import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; */ public interface FinancialsReceiptItemListWebViewController extends Serializable { + /** + * Returns the receipt item by given primary key + *

+ * @param receiptItemId Receipt item's primary key + *

+ * @return Receipt item instance + *

+ * @throws ReceiptItemNotFoundException If the receipt item cannot be found + */ + BillableReceiptItem findReceiptItemById (final Long receiptItemId) throws ReceiptItemNotFoundException; + /** * Checks if receipt item has already been added to database *

diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionBean.java index 26af5364..e00d0115 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionBean.java @@ -27,9 +27,9 @@ import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; -import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; +import org.mxchange.jfinancials.events.receipt_item.added.ObservableAdminReceiptItemAddedEvent; /** * A list financial receipt item bean (controller) @@ -79,7 +79,7 @@ public class FinancialsReceiptItemUserWebSessionBean extends BaseFinancialsBean *

* @param event Event being fired */ - public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) { + public void afterAddedReceiptItemEvent (@Observes final ObservableAdminReceiptItemAddedEvent event) { // Validate parameter if (null == event) { // Throw NPE @@ -87,9 +87,9 @@ public class FinancialsReceiptItemUserWebSessionBean extends BaseFinancialsBean } // Is same user? - if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { + if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getAddedReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { // Same user, then add it - this.userReceiptItems.add(event.getReceiptItem()); + this.userReceiptItems.add(event.getAddedReceiptItem()); } } diff --git a/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java b/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java index 37686d9f..a915952b 100644 --- a/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java @@ -28,7 +28,7 @@ import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; import org.mxchange.jfinancials.model.receipt.BillableReceipt; /** - * Converter for category id <-> valid category instance + * Converter for receipt id <-> valid receipt instance *

* @author Roland Häder */ diff --git a/src/java/org/mxchange/jfinancials/converter/financial/receipt_item/FinancialsReceiptItemConverter.java b/src/java/org/mxchange/jfinancials/converter/financial/receipt_item/FinancialsReceiptItemConverter.java new file mode 100644 index 00000000..e289b02c --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/financial/receipt_item/FinancialsReceiptItemConverter.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2016 - 2020 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 + * 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 . + */ +package org.mxchange.jfinancials.converter.financial.receipt_item; + +import javax.enterprise.inject.spi.CDI; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewBean; +import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; +import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemNotFoundException; +import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; + +/** + * Converter for receipt item id <-> valid receipt item instance + *

+ * @author Roland Häder + */ +@FacesConverter ("ReceiptItemConverter") +public class FinancialsReceiptItemConverter implements Converter { + + /** + * Receipt backing bean + */ + private static FinancialsReceiptItemListWebViewController RECEIPT_ITEM_LIST_CONTROLLER; + + @Override + public BillableReceiptItem getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + BillableReceiptItem receiptItem = null; + + // Is the instance there? + if (null == RECEIPT_ITEM_LIST_CONTROLLER) { + // Get bean from CDI directly + RECEIPT_ITEM_LIST_CONTROLLER = CDI.current().select(FinancialsReceiptItemListWebViewBean.class).get(); + } + + try { + // Try to parse the value as long + final Long receiptItemId = Long.valueOf(submittedValue); + + // Try to get user instance from it + receiptItem = RECEIPT_ITEM_LIST_CONTROLLER.findReceiptItemById(receiptItemId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final ReceiptItemNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N + } + + // Return it + return receiptItem; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final BillableReceiptItem value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getItemId()); + } + +} diff --git a/src/java/org/mxchange/localization/project_de_DE.properties b/src/java/org/mxchange/localization/project_de_DE.properties index f33359ca..b55de5ed 100644 --- a/src/java/org/mxchange/localization/project_de_DE.properties +++ b/src/java/org/mxchange/localization/project_de_DE.properties @@ -167,13 +167,28 @@ AGE_GROUP_SENIOR=Altersgruppe "Senior" #@TODO Please fix German umlauts! SELECT_RECEIPT_ITEM_PRODUCT=Waehle Produkt zum Kassenboneintrag aus: ADMIN_EDIT_RECEIPT_NUMBER_TITLE=Kassenbonnummer {0} (Id {1}) bearbeiten: -BUTTON_ADMIN_EDIT_RECEIPT=Kassenbon bearbeiten +#@TODO Please fix German umlauts! +BUTTON_ADMIN_EDIT_RECEIPT=Kassenbon aendern CONTENT_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT=Kassenbon bearbeiten: PAGE_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT=Kassenbon bearbeiten ADMIN_EDIT_RECEIPT_TITLE=Kassenbon mit Id {0} bearbeiten: #@TODO Please fix German umlauts! -ADMIN_ERROR_FINANCIAL_RECEIPT_NOT_CHANGED=Fehler: Keine Aenderungen am Kassenbon vorgenommen! -PARAMETER_RECEIPT_ID_INVALID=Parameter "receiptId" ung\u00fcltig. +ADMIN_ERROR_FINANCIAL_RECEIPT_NOT_CHANGED=Fehler: Sie haben den Kassenbon nicht geaendert. +PARAMETER_RECEIPT_ID_INVALID=Kassenbon mit Id-Nummer "receiptId" nicht gefunden. ERROR_PARAMETER_RECEIPT_ID_NOT_SET=Fehler: Parameter "receiptId" nicht gesetzt. #@TODO Please fix German umlauts! ADMIN_EDIT_RECEIPT_MINIMUM_DATA=Bitte waehlen Sie aus bzw. geben Sie die mit (*) markierten Daten mindestens ein. +ERROR_PARAMETER_RECEIPT_ITEM_ID_NOT_SET=Fehler: Parameter "receiptItemId" nicht gesetzt. +PARAMETER_RECEIPT_ITEM_ID_INVALID=Kassenboneintrag mit Id-Nummer "receiptItemId" nicht gefunden. +PAGE_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT_ITEM=Kassenboneintrag editieren +CONTENT_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT_ITEM=Kassenboneintrag editieren: +ADMIN_EDIT_RECEIPT_ITEM_NUMBER_TITLE=Kassenboneintrag mit Bonummer {0} (Id {1}) bearbeiten: +ADMIN_EDIT_RECEIPT_ITEM_TITLE=Kassenboneintrag Id {0} bearbeiten: +#@TODO Please fix German umlauts! +ADMIN_EDIT_RECEIPT_ITEM_MINIMUM_DATA=Geben Sie mindestens die mit * markierten Daten fuer diesen Kassenboneintrag an. +#@TODO Please fix German umlauts! +BUTTON_ADMIN_EDIT_RECEIPT_ITEM=Kassenboneintrag aendern +#@TODO Please fix German umlauts! +RECEIPT_ITEM_UPDATED_TITLE=Wann dieser Kassenboneintrag als letztes geaendert wurde. +#@TODO Please fix German umlauts! +ADMIN_ERROR_FINANCIAL_RECEIPT_ITEM_NOT_CHANGED=Fehler: Sie haben den Kassenboneintrag nicht geaendert. diff --git a/src/java/org/mxchange/localization/project_en_US.properties b/src/java/org/mxchange/localization/project_en_US.properties index 67c73555..1140fa17 100644 --- a/src/java/org/mxchange/localization/project_en_US.properties +++ b/src/java/org/mxchange/localization/project_en_US.properties @@ -141,11 +141,21 @@ AGE_GROUP_YOUTH=Age group "Youth" AGE_GROUP_ADULT=Age group "Adult" AGE_GROUP_SENIOR=Age group "Senior" ADMIN_EDIT_RECEIPT_NUMBER_TITLE=Edit receipt number {0} (Id {1}): -BUTTON_ADMIN_EDIT_RECEIPT=Edit receipt +BUTTON_ADMIN_EDIT_RECEIPT=Change receipt CONTENT_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT=Edit receipt: PAGE_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT=Edit receipt ADMIN_EDIT_RECEIPT_TITLE=Edit receipt with id {0}: -ADMIN_ERROR_FINANCIAL_RECEIPT_NOT_CHANGED=Error: No change on receipt done. -PARAMETER_RECEIPT_ID_INVALID=Parameter "receiptId" invalid. +ADMIN_ERROR_FINANCIAL_RECEIPT_NOT_CHANGED=Error: You did not change the receipt. +PARAMETER_RECEIPT_ID_INVALID=Receipt with given receiptId not found. ERROR_PARAMETER_RECEIPT_ID_NOT_SET=Error: Parameter "receiptId" not set. ADMIN_EDIT_RECEIPT_MINIMUM_DATA=Please select or enter at least the marked fields. +ERROR_PARAMETER_RECEIPT_ITEM_ID_NOT_SET=Error: Parameter "receiptItemId" is not set. +PARAMETER_RECEIPT_ITEM_ID_INVALID=Receipt item with given receiptItemId not found. +PAGE_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT_ITEM=Edit receipt item +CONTENT_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT_ITEM=Edit receipt item: +ADMIN_EDIT_RECEIPT_ITEM_NUMBER_TITLE=Edit receipt item with number {0} (Id {1}): +ADMIN_EDIT_RECEIPT_ITEM_TITLE=Edit receipt item id {0}: +ADMIN_EDIT_RECEIPT_ITEM_MINIMUM_DATA=Enter minimum data, marked with (*) for this receipt item. +BUTTON_ADMIN_EDIT_RECEIPT_ITEM=Change receipt item +RECEIPT_ITEM_UPDATED_TITLE=Then this receipt item has been recently updated. +ADMIN_ERROR_FINANCIAL_RECEIPT_ITEM_NOT_CHANGED=Error: You did not change the receipt item. diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index 9245b550..532c3a14 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -1037,6 +1037,14 @@ /admin/financial/receipt/admin_assign_receipt_seller.xhtml + + /admin/financial/receipt/admin_receipt_edit.xhtml + + admin_list_receipts + /admin/financial/receipt/admin_receipt_list.xhtml + + + /admin/financial/receipt_item/admin_receipt_item_list.xhtml @@ -1068,6 +1076,14 @@ /admin/product_category/admin_product_category_show.xhtml + + /admin/financial/receipt_item/admin_receipt_item_edit.xhtml + + admin_list_receipt_items + /admin/financial/receipt_item/admin_receipt_item_list.xhtml + + + - + @@ -32,14 +30,14 @@ maxlength="20" decimalPlaces="0" thousandSeparator="," - value="#{adminReceiptItemController.itemNumber}" + value="#{adminReceiptItemActionController.itemNumber}" title="#{project.ENTER_RECEIPT_ITEM_NUMBER_TITLE}" /> - + @@ -81,17 +84,21 @@ - + @@ -99,10 +106,14 @@ - + @@ -115,14 +126,14 @@ id="itemCouponNumber" size="20" maxlength="255" - value="#{adminReceiptItemController.itemCouponNumber}" + value="#{adminReceiptItemActionController.itemCouponNumber}" title="#{project.ENTER_RECEIPT_ITEM_COUPON_NUMBER_TITLE}" /> - + - + diff --git a/web/WEB-INF/templates/admin/financial/receipt_item/admin_receipt_item_price_input_panel_grid.tpl b/web/WEB-INF/templates/admin/financial/receipt_item/admin_receipt_item_price_input_panel_grid.tpl new file mode 100644 index 00000000..f3827140 --- /dev/null +++ b/web/WEB-INF/templates/admin/financial/receipt_item/admin_receipt_item_price_input_panel_grid.tpl @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + diff --git a/web/admin/financial/receipt/admin_receipt_list.xhtml b/web/admin/financial/receipt/admin_receipt_list.xhtml index 01c19fe9..787225ec 100644 --- a/web/admin/financial/receipt/admin_receipt_list.xhtml +++ b/web/admin/financial/receipt/admin_receipt_list.xhtml @@ -388,7 +388,12 @@ - + + + + + + diff --git a/web/admin/financial/receipt_item/admin_receipt_item_edit.xhtml b/web/admin/financial/receipt_item/admin_receipt_item_edit.xhtml new file mode 100644 index 00000000..ab1855df --- /dev/null +++ b/web/admin/financial/receipt_item/admin_receipt_item_edit.xhtml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml b/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml index d0680bb1..546c4669 100644 --- a/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml +++ b/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml @@ -215,10 +215,20 @@ - + + + + + + + @@ -233,7 +243,7 @@ value="#{msg.ADMIN_LINK_SHOW_SHORT}" title="#{project.ADMIN_LINK_SHOW_RECEIPT_ITEM_TITLE}" > - + - + @@ -345,7 +355,12 @@ - + + + + + + @@ -376,7 +391,7 @@