From c97ed04d016082377ab621214c842fc4b00322b5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 8 Apr 2020 20:59:27 +0200 Subject: [PATCH] Don't cherry-pick: - created "admin-receipt-action" controller for add/edit (later delete, too) actions - this change made the "admin-generic-receipt" controller empty for now, but that is so far okay here. - added admin-receipt-edit view - reformatted p:panelGrid/p:outputLabel/p:inputText to have each attribute in a separate line - added missing i18n strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialAdminReceiptWebRequestBean.java | 366 ----------- ...inancialAdminReceiptActionWebViewBean.java | 571 ++++++++++++++++++ ...alAdminReceiptActionWebViewController.java | 28 + .../FinancialsReceiptListWebViewBean.java | 55 +- .../localization/project_de_DE.properties | 11 + .../localization/project_en_US.properties | 9 + .../receipt/admin_form_financial_receipt.tpl | 20 +- .../receipt/admin_receipt_edit.xhtml | 87 +++ .../receipt/admin_receipt_list.xhtml | 21 +- .../admin_receipt_item_list.xhtml | 19 +- 10 files changed, 803 insertions(+), 384 deletions(-) create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewBean.java create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewController.java create mode 100644 web/admin/financial/receipt/admin_receipt_edit.xhtml diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java index b9e1cac3..c21acc60 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java @@ -16,27 +16,9 @@ */ package org.mxchange.jfinancials.beans.financial.model.receipt; -import java.text.MessageFormat; -import java.util.Date; -import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.inject.Any; -import javax.faces.view.facelets.FaceletException; -import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.financial.model.receipt.list.FinancialsReceiptListWebViewController; -import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; -import org.mxchange.jfinancials.events.receipt.added.ReceiptAddedEvent; -import org.mxchange.jfinancials.exceptions.receipt.ReceiptAlreadyAddedException; -import org.mxchange.jfinancials.model.receipt.BillableReceipt; -import org.mxchange.jfinancials.model.receipt.FinancialAdminReceiptSessionBeanRemote; -import org.mxchange.jfinancials.model.receipt.FinancialReceipt; -import org.mxchange.jproduct.model.payment.PaymentType; -import org.mxchange.jusercore.model.user.User; /** * An administrative backing bean for receipts @@ -52,81 +34,6 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl */ private static final long serialVersionUID = 595_754_280_374_171L; - /** - * Event being fired when administrator has added a new receipt - */ - @Inject - @Any - private Event adminAddedReceiptEvent; - - /** - * EJB for general financial receipt purposes - */ - @EJB (lookup = "java:global/jfinancials-ejb/adminFinancialReceipt!org.mxchange.jfinancials.model.receipt.FinancialAdminReceiptSessionBeanRemote") - private FinancialAdminReceiptSessionBeanRemote adminReceiptBean; - - /** - * Bar-code number - */ - private String receiptBarCodeNumber; - - /** - * Recipient issuing company (for example where the user went shopping to) - */ - private BranchOffice receiptBranchOffice; - - /** - * General receipt controller - */ - @Inject - private FinancialsReceiptWebRequestController receiptController; - - /** - * Date/time the receipt has been issued - */ - private Date receiptIssued; - - /** - * Receipt list controller - */ - @Inject - private FinancialsReceiptListWebViewController receiptListController; - - /** - * Receipt number (only numbers) - */ - private String receiptNumber; - - /** - * Payment type being used for this receipt - */ - private PaymentType receiptPaymentType; - - /** - * Register number - */ - private Long receiptRegisterNumber; - - /** - * Selling employee - */ - private Employable receiptSellerEmployee; - - /** - * Sequence number - */ - private Long receiptSequenceNumber; - - /** - * Transaction number - */ - private Long receiptTransactionNumber; - - /** - * User who "owns" this receipt - */ - private User receiptUser; - /** * Default constructor */ @@ -135,277 +42,4 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl super(); } - /** - * Adds the completed receipt to database by calling an EJB business method. - * If not all required fields are set, a proper exception is being thrown. - *

- */ - public void addReceipt () { - // Are all required fields set? - if (this.getReceiptBranchOffice() == null) { - // Is not set - throw new NullPointerException("this.receiptBranchOffice is not set."); //NOI18N - } else if (this.getReceiptBranchOffice().getBranchId() == null) { - // It must be an already peristed instance - throw new NullPointerException("this.receiptBranchOffice.businessContactId is not set."); //NOI18N - } else if (this.getReceiptBranchOffice().getBranchId() < 1) { - // It must be an already peristed instance - throw new IllegalArgumentException(MessageFormat.format("this.receiptBranchOffice.businessContactId={0} is not valid.", this.getReceiptBranchOffice().getBranchId())); //NOI18N - } else if (this.getReceiptPaymentType() == null) { - // Is not set - throw new NullPointerException("this.receiptPaymentType is not set."); //NOI18N - } else if (this.getReceiptIssued() == null) { - // Is not set - throw new NullPointerException("this.receiptIssued is not set."); //NOI18N - } - - // Prepare receipt instance - final BillableReceipt receipt = this.createReceiptInstance(); - - // Is the receipt already there? - if (this.receiptListController.isReceiptAdded(receipt)) { - // Receipt has already been added - throw new FaceletException(MessageFormat.format("Receipt for receiptBranchOffice={0},receiptIssued={1},receiptNumber={2} has already been added.", this.getReceiptBranchOffice().getBranchId(), this.getReceiptIssued().toString(), this.getReceiptNumber())); //NOI18N - } - - // Init variable - final BillableReceipt updatedReceipt; - - // All is set, then try to call EJB - try { - // Add it - updatedReceipt = this.adminReceiptBean.addReceipt(receipt); - } catch (final ReceiptAlreadyAddedException ex) { - // Throw it again - throw new FaceletException(ex); - } - - // Fire event with updated instance - this.adminAddedReceiptEvent.fire(new ReceiptAddedEvent(updatedReceipt)); - - // Clear bean - this.clear(); - } - - /** - * Getter for receipt's bar-code number - *

- * @return Receipt's bar-code number - */ - public String getReceiptBarCodeNumber () { - return this.receiptBarCodeNumber; - } - - /** - * Setter for receipt's bar-code number - *

- * @param receiptBarCodeNumber Receipt's bar-code number - */ - public void setReceiptBarCodeNumber (final String receiptBarCodeNumber) { - this.receiptBarCodeNumber = receiptBarCodeNumber; - } - - /** - * Getter for receipt issuing branch office - *

- * @return Receipt issuing branch office - */ - public BranchOffice getReceiptBranchOffice () { - return this.receiptBranchOffice; - } - - /** - * Setter for receipt issuing branch office - *

- * @param receiptBranchOffice Receipt issuing branch office - */ - public void setReceiptBranchOffice (final BranchOffice receiptBranchOffice) { - this.receiptBranchOffice = receiptBranchOffice; - } - - /** - * Getter for receipt issue date and time - *

- * @return Receipt issue date and time - */ - @SuppressWarnings ("ReturnOfDateField") - public Date getReceiptIssued () { - return this.receiptIssued; - } - - /** - * Setter for receipt issue date and time - *

- * @param receiptIssued Receipt issue date and time - */ - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setReceiptIssued (final Date receiptIssued) { - this.receiptIssued = receiptIssued; - } - - /** - * Getter for receipt number - *

- * @return Receipt number - */ - public String getReceiptNumber () { - return this.receiptNumber; - } - - /** - * Setter for receipt number - *

- * @param receiptNumber Receipt number - */ - public void setReceiptNumber (final String receiptNumber) { - this.receiptNumber = receiptNumber; - } - - /** - * Getter for payment type - *

- * @return Payment type - */ - public PaymentType getReceiptPaymentType () { - return this.receiptPaymentType; - } - - /** - * Setter for payment type - *

- * @param receiptPaymentType Payment type - */ - public void setReceiptPaymentType (final PaymentType receiptPaymentType) { - this.receiptPaymentType = receiptPaymentType; - } - - /** - * Getter for receipt register's number - *

- * @return Receipt register's number - */ - public Long getReceiptRegisterNumber () { - return this.receiptRegisterNumber; - } - - /** - * Setter for receipt register's number - *

- * @param receiptRegisterNumber Receipt register's number - */ - public void setReceiptRegisterNumber (final Long receiptRegisterNumber) { - this.receiptRegisterNumber = receiptRegisterNumber; - } - - /** - * Getter for receipt seller employee - *

- * @return Receipt seller employee - */ - public Employable getReceiptSellerEmployee () { - return this.receiptSellerEmployee; - } - - /** - * Setter for receipt seller employee - *

- * @param receiptSellerEmployee Receipt seller employee - */ - public void setReceiptSellerEmployee (final Employable receiptSellerEmployee) { - this.receiptSellerEmployee = receiptSellerEmployee; - } - - /** - * Getter for receipt sequence number - *

- * @return Receipt sequence number - */ - public Long getReceiptSequenceNumber () { - return this.receiptSequenceNumber; - } - - /** - * Setter for receipt sequence number - *

- * @param receiptSequenceNumber Receipt sequence number - */ - public void setReceiptSequenceNumber (final Long receiptSequenceNumber) { - this.receiptSequenceNumber = receiptSequenceNumber; - } - - /** - * Getter for receipt transaction number - *

- * @return Receipt transaction number - */ - public Long getReceiptTransactionNumber () { - return this.receiptTransactionNumber; - } - - /** - * Setter for receipt transaction number - *

- * @param receiptTransactionNumber Receipt transaction number - */ - public void setReceiptTransactionNumber (final Long receiptTransactionNumber) { - this.receiptTransactionNumber = receiptTransactionNumber; - } - - /** - * Getter for user instance - *

- * @return User instance - */ - public User getReceiptUser () { - return this.receiptUser; - } - - /** - * Setter for user instance - *

- * @param receiptUser User instance - */ - public void setReceiptUser (final User receiptUser) { - this.receiptUser = receiptUser; - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all fields - this.setReceiptBarCodeNumber(null); - this.setReceiptBranchOffice(null); - this.setReceiptIssued(null); - this.setReceiptNumber(null); - this.setReceiptPaymentType(null); - this.setReceiptRegisterNumber(null); - this.setReceiptSellerEmployee(null); - this.setReceiptSequenceNumber(null); - this.setReceiptTransactionNumber(null); - this.setReceiptUser(null); - } - - /** - * Creates a new instance from all available data of this bean. - *

- * @return Receipt instance - */ - private BillableReceipt createReceiptInstance () { - // Create new instance with minimum required data - final BillableReceipt receipt = new FinancialReceipt(this.getReceiptPaymentType(), this.getReceiptBranchOffice(), this.getReceiptIssued()); - - // Set optional data - receipt.setReceiptUser(this.getReceiptUser()); - receipt.setReceiptNumber(this.getReceiptNumber()); - receipt.setReceiptBarCodeNumber(this.getReceiptBarCodeNumber()); - receipt.setReceiptRegisterNumber(this.getReceiptRegisterNumber()); - receipt.setReceiptSellerEmployee(this.getReceiptSellerEmployee()); - receipt.setReceiptSequenceNumber(this.getReceiptSequenceNumber()); - receipt.setReceiptTransactionNumber(this.getReceiptTransactionNumber()); - - // Return prepared instance - return receipt; - } - } 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 new file mode 100644 index 00000000..4a34c0a0 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewBean.java @@ -0,0 +1,571 @@ +/* + * 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.action; + +import java.text.MessageFormat; +import java.util.Date; +import java.util.Objects; +import javax.ejb.EJB; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.faces.application.FacesMessage; +import javax.faces.view.ViewScoped; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.financial.model.receipt.list.FinancialsReceiptListWebViewController; +import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; +import org.mxchange.jfinancials.events.receipt.added.ReceiptAddedEvent; +import org.mxchange.jfinancials.events.receipt.updated.ObservableReceiptUpdatedEvent; +import org.mxchange.jfinancials.events.receipt.updated.ReceiptUpdatedEvent; +import org.mxchange.jfinancials.exceptions.receipt.ReceiptAlreadyAddedException; +import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; +import org.mxchange.jfinancials.model.bonus_card.BonusCard; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; +import org.mxchange.jfinancials.model.receipt.FinancialAdminReceiptSessionBeanRemote; +import org.mxchange.jfinancials.model.receipt.FinancialReceipt; +import org.mxchange.jfinancials.model.receipt.Receipts; +import org.mxchange.jproduct.model.payment.PaymentType; +import org.mxchange.jusercore.model.user.User; + +/** + * An administrative backing bean for receipts + *

+ * @author Roland Häder + */ +@Named ("adminReceiptActionController") +@ViewScoped +public class FinancialAdminReceiptActionWebViewBean extends BaseFinancialsBean implements FinancialAdminReceiptActionWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 595_754_280_374_172L; + + /** + * Event being fired when administrator has added a new receipt + */ + @Inject + @Any + private Event adminAddedReceiptEvent; + + /** + * EJB for general financial receipt purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/adminFinancialReceipt!org.mxchange.jfinancials.model.receipt.FinancialAdminReceiptSessionBeanRemote") + private FinancialAdminReceiptSessionBeanRemote adminReceiptBean; + + /** + * Event being fired when administrator has added a new receipt + */ + @Inject + @Any + private Event adminUpdatedReceiptEvent; + + /** + * Current receipt + */ + private BillableReceipt currentReceipt; + + /** + * Bar-code number + */ + private String receiptBarCodeNumber; + + /** + * Bonus card assigned with receipt + */ + private BonusCard receiptBonusCard; + + /** + * Recipient issuing company (for example where the user went shopping to) + */ + private BranchOffice receiptBranchOffice; + + /** + * Receipt id number + */ + private Long receiptId; + + /** + * Date/time the receipt has been issued + */ + private Date receiptIssued; + + /** + * Receipt list controller + */ + @Inject + private FinancialsReceiptListWebViewController receiptListController; + + /** + * Receipt number (only numbers) + */ + private String receiptNumber; + + /** + * Payment type being used for this receipt + */ + private PaymentType receiptPaymentType; + + /** + * Register number + */ + private Long receiptRegisterNumber; + + /** + * Selling employee + */ + private Employable receiptSellerEmployee; + + /** + * Sequence number + */ + private Long receiptSequenceNumber; + + /** + * Transaction number + */ + private Long receiptTransactionNumber; + + /** + * User who "owns" this receipt + */ + private User receiptUser; + + /** + * Default constructor + */ + public FinancialAdminReceiptActionWebViewBean () { + // Call super constructor + super(); + } + + /** + * Adds the completed receipt to database by calling an EJB business method. + * If not all required fields are set, a proper exception is being thrown. + *

+ */ + public void addReceipt () { + // Are all required fields set? + if (this.getReceiptBranchOffice() == null) { + // Is not set + throw new NullPointerException("this.receiptBranchOffice is not set."); //NOI18N + } else if (this.getReceiptBranchOffice().getBranchId() == null) { + // It must be an already peristed instance + throw new NullPointerException("this.receiptBranchOffice.businessContactId is not set."); //NOI18N + } else if (this.getReceiptBranchOffice().getBranchId() < 1) { + // It must be an already peristed instance + throw new IllegalArgumentException(MessageFormat.format("this.receiptBranchOffice.businessContactId={0} is not valid.", this.getReceiptBranchOffice().getBranchId())); //NOI18N + } else if (this.getReceiptPaymentType() == null) { + // Is not set + throw new NullPointerException("this.receiptPaymentType is not set."); //NOI18N + } else if (this.getReceiptIssued() == null) { + // Is not set + throw new NullPointerException("this.receiptIssued is not set."); //NOI18N + } + + // Prepare receipt instance + final BillableReceipt receipt = this.createReceiptInstance(); + + // Is the receipt already there? + if (this.receiptListController.isReceiptAdded(receipt)) { + // Receipt has already been added + throw new FaceletException(MessageFormat.format( + "Receipt for receiptBranchOffice={0},receiptIssued={1},receiptNumber={2} has already been added.", //NOI18N + this.getReceiptBranchOffice().getBranchId(), + this.getReceiptIssued().toString(), + this.getReceiptNumber() + )); + } + + // Init variable + final BillableReceipt updatedReceipt; + + // All is set, then try to call EJB + try { + // Add it + updatedReceipt = this.adminReceiptBean.addReceipt(receipt); + } catch (final ReceiptAlreadyAddedException ex) { + // Throw it again + throw new FaceletException(ex); + } + + // Fire event with updated instance + this.adminAddedReceiptEvent.fire(new ReceiptAddedEvent(updatedReceipt)); + + // Clear bean + this.clear(); + } + + /** + * Copies all fields from current receipt instance to local bean properties. + */ + public void copyAllReceiptProperties () { + // Is current receipt instance valid? + if (this.getCurrentReceipt() == null) { + // Not set + throw new NullPointerException("this.currentReceipt is null"); + } + + // Copy all fields + this.setReceiptBarCodeNumber(this.getCurrentReceipt().getReceiptBarCodeNumber()); + this.setReceiptBonusCard(this.getCurrentReceipt().getReceiptBonusCard()); + this.setReceiptBranchOffice(this.getCurrentReceipt().getReceiptBranchOffice()); + this.setReceiptId(this.getCurrentReceipt().getReceiptId()); + this.setReceiptIssued(this.getCurrentReceipt().getReceiptIssued()); + this.setReceiptNumber(this.getCurrentReceipt().getReceiptNumber()); + this.setReceiptPaymentType(this.getCurrentReceipt().getReceiptPaymentType()); + this.setReceiptRegisterNumber(this.getCurrentReceipt().getReceiptRegisterNumber()); + this.setReceiptSellerEmployee(this.getCurrentReceipt().getReceiptSellerEmployee()); + this.setReceiptSequenceNumber(this.getCurrentReceipt().getReceiptSequenceNumber()); + this.setReceiptTransactionNumber(this.getCurrentReceipt().getReceiptTransactionNumber()); + this.setReceiptUser(this.getCurrentReceipt().getReceiptUser()); + } + + /** + * Getter for current receipt + *

+ * @return Current receipt + */ + public BillableReceipt getCurrentReceipt () { + return this.currentReceipt; + } + + /** + * Setter for current receipt + *

+ * @param currentReceipt Current receipt + */ + public void setCurrentReceipt (final BillableReceipt currentReceipt) { + this.currentReceipt = currentReceipt; + } + + /** + * Getter for receipt's bar-code number + *

+ * @return Receipt's bar-code number + */ + public String getReceiptBarCodeNumber () { + return this.receiptBarCodeNumber; + } + + /** + * Setter for receipt's bar-code number + *

+ * @param receiptBarCodeNumber Receipt's bar-code number + */ + public void setReceiptBarCodeNumber (final String receiptBarCodeNumber) { + this.receiptBarCodeNumber = receiptBarCodeNumber; + } + + /** + * Getter for bonus card + *

+ * @return Bonus card + */ + public BonusCard getReceiptBonusCard () { + return this.receiptBonusCard; + } + + /** + * Setter for bonus card + *

+ * @param receiptBonusCard Bonus card + */ + public void setReceiptBonusCard (final BonusCard receiptBonusCard) { + this.receiptBonusCard = receiptBonusCard; + } + + /** + * Getter for receipt issuing branch office + *

+ * @return Receipt issuing branch office + */ + public BranchOffice getReceiptBranchOffice () { + return this.receiptBranchOffice; + } + + /** + * Setter for receipt issuing branch office + *

+ * @param receiptBranchOffice Receipt issuing branch office + */ + public void setReceiptBranchOffice (final BranchOffice receiptBranchOffice) { + this.receiptBranchOffice = receiptBranchOffice; + } + + /** + * Getter for receipt id + *

+ * @return Receipt it + */ + public Long getReceiptId () { + return this.receiptId; + } + + /** + * Setter for receipt id + *

+ * @param receiptId Receipt id + */ + public void setReceiptId (final Long receiptId) { + this.receiptId = receiptId; + } + + /** + * Getter for receipt issue date and time + *

+ * @return Receipt issue date and time + */ + @SuppressWarnings ("ReturnOfDateField") + public Date getReceiptIssued () { + return this.receiptIssued; + } + + /** + * Setter for receipt issue date and time + *

+ * @param receiptIssued Receipt issue date and time + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setReceiptIssued (final Date receiptIssued) { + this.receiptIssued = receiptIssued; + } + + /** + * Getter for receipt number + *

+ * @return Receipt number + */ + public String getReceiptNumber () { + return this.receiptNumber; + } + + /** + * Setter for receipt number + *

+ * @param receiptNumber Receipt number + */ + public void setReceiptNumber (final String receiptNumber) { + this.receiptNumber = receiptNumber; + } + + /** + * Getter for payment type + *

+ * @return Payment type + */ + public PaymentType getReceiptPaymentType () { + return this.receiptPaymentType; + } + + /** + * Setter for payment type + *

+ * @param receiptPaymentType Payment type + */ + public void setReceiptPaymentType (final PaymentType receiptPaymentType) { + this.receiptPaymentType = receiptPaymentType; + } + + /** + * Getter for receipt register's number + *

+ * @return Receipt register's number + */ + public Long getReceiptRegisterNumber () { + return this.receiptRegisterNumber; + } + + /** + * Setter for receipt register's number + *

+ * @param receiptRegisterNumber Receipt register's number + */ + public void setReceiptRegisterNumber (final Long receiptRegisterNumber) { + this.receiptRegisterNumber = receiptRegisterNumber; + } + + /** + * Getter for receipt seller employee + *

+ * @return Receipt seller employee + */ + public Employable getReceiptSellerEmployee () { + return this.receiptSellerEmployee; + } + + /** + * Setter for receipt seller employee + *

+ * @param receiptSellerEmployee Receipt seller employee + */ + public void setReceiptSellerEmployee (final Employable receiptSellerEmployee) { + this.receiptSellerEmployee = receiptSellerEmployee; + } + + /** + * Getter for receipt sequence number + *

+ * @return Receipt sequence number + */ + public Long getReceiptSequenceNumber () { + return this.receiptSequenceNumber; + } + + /** + * Setter for receipt sequence number + *

+ * @param receiptSequenceNumber Receipt sequence number + */ + public void setReceiptSequenceNumber (final Long receiptSequenceNumber) { + this.receiptSequenceNumber = receiptSequenceNumber; + } + + /** + * Getter for receipt transaction number + *

+ * @return Receipt transaction number + */ + public Long getReceiptTransactionNumber () { + return this.receiptTransactionNumber; + } + + /** + * Setter for receipt transaction number + *

+ * @param receiptTransactionNumber Receipt transaction number + */ + public void setReceiptTransactionNumber (final Long receiptTransactionNumber) { + this.receiptTransactionNumber = receiptTransactionNumber; + } + + /** + * Getter for user instance + *

+ * @return User instance + */ + public User getReceiptUser () { + return this.receiptUser; + } + + /** + * Setter for user instance + *

+ * @param receiptUser User instance + */ + public void setReceiptUser (final User receiptUser) { + this.receiptUser = receiptUser; + } + + /** + * 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 () { + // Is current instance still there? + if (this.getCurrentReceipt() == null) { + // Throw NPE + throw new NullPointerException("this.currentReceipt is null"); + } else if (this.getCurrentReceipt().getReceiptId() == null) { + // Throw NPE again + throw new NullPointerException("this.currentReceipt.receiptId is null"); + } + + // Create new instance + final BillableReceipt receipt = this.createReceiptInstance(); + + // 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; + } + + // Copy all data + Receipts.copyAll(receipt, this.getCurrentReceipt()); + + // Create updated receipt instance + final BillableReceipt updatedReceipt; + + try { + // Invoke EJB method + updatedReceipt = this.adminReceiptBean.updateReceipt(this.getCurrentReceipt()); + } catch (final ReceiptNotFoundException ex) { + // Throw as cause + throw new FaceletException(ex); + } + + // Fire event + this.adminUpdatedReceiptEvent.fire(new ReceiptUpdatedEvent(updatedReceipt)); + + // Clear bean + this.clear(); + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all fields + this.setReceiptBarCodeNumber(null); + this.setReceiptBonusCard(null); + this.setReceiptBranchOffice(null); + this.setReceiptId(null); + this.setReceiptIssued(null); + this.setReceiptNumber(null); + this.setReceiptPaymentType(null); + this.setReceiptRegisterNumber(null); + this.setReceiptSellerEmployee(null); + this.setReceiptSequenceNumber(null); + this.setReceiptTransactionNumber(null); + this.setReceiptUser(null); + } + + /** + * Creates a new instance from all available data of this bean. + *

+ * @return Receipt instance + */ + private BillableReceipt createReceiptInstance () { + // Create new instance with minimum required data + final BillableReceipt receipt = new FinancialReceipt( + this.getReceiptPaymentType(), + this.getReceiptBranchOffice(), + this.getReceiptIssued() + ); + + // Set optional data + receipt.setReceiptBarCodeNumber(this.getReceiptBarCodeNumber()); + receipt.setReceiptBonusCard(this.getReceiptBonusCard()); + receipt.setReceiptId(this.getReceiptId()); + receipt.setReceiptNumber(this.getReceiptNumber()); + receipt.setReceiptRegisterNumber(this.getReceiptRegisterNumber()); + receipt.setReceiptSellerEmployee(this.getReceiptSellerEmployee()); + receipt.setReceiptSequenceNumber(this.getReceiptSequenceNumber()); + receipt.setReceiptTransactionNumber(this.getReceiptTransactionNumber()); + receipt.setReceiptUser(this.getReceiptUser()); + + // Return prepared instance + return receipt; + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewController.java new file mode 100644 index 00000000..79a7240f --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/action/FinancialAdminReceiptActionWebViewController.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.action; + +import java.io.Serializable; + +/** + * An interface for administrative receipt beans + *

+ * @author Roland Häder + */ +public interface FinancialAdminReceiptActionWebViewController extends Serializable { + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java index bef24c59..1afa4fbe 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java @@ -21,6 +21,7 @@ import java.text.MessageFormat; import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import javax.annotation.PostConstruct; import javax.cache.Cache; import javax.ejb.EJB; @@ -30,9 +31,11 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; +import org.mxchange.jfinancials.events.receipt.updated.ObservableReceiptUpdatedEvent; import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; import org.mxchange.jfinancials.model.receipt.BillableReceipt; import org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote; +import org.mxchange.jfinancials.model.receipt.Receipts; /** * A view-scoped bean for receipt lists @@ -113,6 +116,56 @@ public class FinancialsReceiptListWebViewBean extends BaseFinancialsBean impleme this.getAllReceipts().add(event.getReceipt()); } + /** + * Observes events being fired when a receipt has been updated + *

+ * @param event Event being fired + */ + public void afterUpdatedReceiptEvent (@Observes final ObservableReceiptUpdatedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getReceipt() == null) { + // Throw NPE again + throw new NullPointerException("event.receipt is null"); //NOI18N + } else if (event.getReceipt().getReceiptId() == null) { + // Throw it again + throw new NullPointerException("event.receipt.receiptId is null"); //NOI18N + } else if (event.getReceipt().getReceiptId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("event.receipt.receiptId={0} is invalid", event.getReceipt().getReceiptId())); //NOI18N + } else if (this.getAllReceipts().isEmpty()) { + // Receipt list is empty + throw new IllegalStateException("this.allReceipts cannot be empty."); //NOI18N + } + + // Add to cache and general list + this.receiptCache.put(event.getReceipt().getReceiptId(), event.getReceipt()); + + // Default is not found + boolean isFound = false; + + // Update instance + for (final BillableReceipt receipt : this.getAllReceipts()) { + // Is the same id? + if (Objects.equals(receipt.getReceiptId(), event.getReceipt().getReceiptId())) { + // Yes, same primary key found, then copy all elements + Receipts.copyAll(event.getReceipt(), receipt); + + // Mark as found, break loop + isFound = true; + break; + } + } + + // Has not been found? + if (!isFound) { + // Receipt list does not contain receipt instance + throw new IllegalStateException("this.allReceipts does not contain the receipt."); //NOI18N + } + } + @Override public BillableReceipt findReceiptById (final Long receiptId) throws ReceiptNotFoundException { // Validate parameter @@ -121,7 +174,7 @@ public class FinancialsReceiptListWebViewBean extends BaseFinancialsBean impleme throw new NullPointerException("receiptId is null"); //NOI18N } else if (receiptId < 1) { // Throw IAE - throw new IllegalArgumentException("receiptId=" + receiptId + " is invalid."); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("receiptId={0} is invalid.", receiptId)); //NOI18N } else if (!this.receiptCache.containsKey(receiptId)) { // Not found throw new ReceiptNotFoundException(receiptId); diff --git a/src/java/org/mxchange/localization/project_de_DE.properties b/src/java/org/mxchange/localization/project_de_DE.properties index 20503b15..f33359ca 100644 --- a/src/java/org/mxchange/localization/project_de_DE.properties +++ b/src/java/org/mxchange/localization/project_de_DE.properties @@ -166,3 +166,14 @@ AGE_GROUP_ADULT=Altersgruppe "Erwachsen" 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 +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. +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. diff --git a/src/java/org/mxchange/localization/project_en_US.properties b/src/java/org/mxchange/localization/project_en_US.properties index 3a471c51..67c73555 100644 --- a/src/java/org/mxchange/localization/project_en_US.properties +++ b/src/java/org/mxchange/localization/project_en_US.properties @@ -140,3 +140,12 @@ AGE_GROUP_CHILD=Age group "Child" 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 +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. +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. diff --git a/web/WEB-INF/templates/admin/financial/receipt/admin_form_financial_receipt.tpl b/web/WEB-INF/templates/admin/financial/receipt/admin_form_financial_receipt.tpl index 8ae98f77..c2adafd7 100644 --- a/web/WEB-INF/templates/admin/financial/receipt/admin_form_financial_receipt.tpl +++ b/web/WEB-INF/templates/admin/financial/receipt/admin_form_financial_receipt.tpl @@ -19,7 +19,7 @@ @@ -99,7 +99,7 @@ @@ -132,22 +132,22 @@ - + - + - + - + diff --git a/web/admin/financial/receipt/admin_receipt_edit.xhtml b/web/admin/financial/receipt/admin_receipt_edit.xhtml new file mode 100644 index 00000000..6b2ce982 --- /dev/null +++ b/web/admin/financial/receipt/admin_receipt_edit.xhtml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/financial/receipt/admin_receipt_list.xhtml b/web/admin/financial/receipt/admin_receipt_list.xhtml index f2e9ef04..5a543a81 100644 --- a/web/admin/financial/receipt/admin_receipt_list.xhtml +++ b/web/admin/financial/receipt/admin_receipt_list.xhtml @@ -43,7 +43,11 @@ > - + - - + + + @@ -381,7 +394,7 @@ 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 41553d33..efcba2bd 100644 --- a/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml +++ b/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml @@ -43,7 +43,11 @@ > - + - - + + + -- 2.39.5