*/
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
*/
private static final long serialVersionUID = 595_754_280_374_171L;
- /**
- * Event being fired when administrator has added a new receipt
- */
- @Inject
- @Any
- private Event<ObservableReceiptAddedEvent> 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
*/
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.
- * <p>
- */
- 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
- * <p>
- * @return Receipt's bar-code number
- */
- public String getReceiptBarCodeNumber () {
- return this.receiptBarCodeNumber;
- }
-
- /**
- * Setter for receipt's bar-code number
- * <p>
- * @param receiptBarCodeNumber Receipt's bar-code number
- */
- public void setReceiptBarCodeNumber (final String receiptBarCodeNumber) {
- this.receiptBarCodeNumber = receiptBarCodeNumber;
- }
-
- /**
- * Getter for receipt issuing branch office
- * <p>
- * @return Receipt issuing branch office
- */
- public BranchOffice getReceiptBranchOffice () {
- return this.receiptBranchOffice;
- }
-
- /**
- * Setter for receipt issuing branch office
- * <p>
- * @param receiptBranchOffice Receipt issuing branch office
- */
- public void setReceiptBranchOffice (final BranchOffice receiptBranchOffice) {
- this.receiptBranchOffice = receiptBranchOffice;
- }
-
- /**
- * Getter for receipt issue date and time
- * <p>
- * @return Receipt issue date and time
- */
- @SuppressWarnings ("ReturnOfDateField")
- public Date getReceiptIssued () {
- return this.receiptIssued;
- }
-
- /**
- * Setter for receipt issue date and time
- * <p>
- * @param receiptIssued Receipt issue date and time
- */
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setReceiptIssued (final Date receiptIssued) {
- this.receiptIssued = receiptIssued;
- }
-
- /**
- * Getter for receipt number
- * <p>
- * @return Receipt number
- */
- public String getReceiptNumber () {
- return this.receiptNumber;
- }
-
- /**
- * Setter for receipt number
- * <p>
- * @param receiptNumber Receipt number
- */
- public void setReceiptNumber (final String receiptNumber) {
- this.receiptNumber = receiptNumber;
- }
-
- /**
- * Getter for payment type
- * <p>
- * @return Payment type
- */
- public PaymentType getReceiptPaymentType () {
- return this.receiptPaymentType;
- }
-
- /**
- * Setter for payment type
- * <p>
- * @param receiptPaymentType Payment type
- */
- public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
- this.receiptPaymentType = receiptPaymentType;
- }
-
- /**
- * Getter for receipt register's number
- * <p>
- * @return Receipt register's number
- */
- public Long getReceiptRegisterNumber () {
- return this.receiptRegisterNumber;
- }
-
- /**
- * Setter for receipt register's number
- * <p>
- * @param receiptRegisterNumber Receipt register's number
- */
- public void setReceiptRegisterNumber (final Long receiptRegisterNumber) {
- this.receiptRegisterNumber = receiptRegisterNumber;
- }
-
- /**
- * Getter for receipt seller employee
- * <p>
- * @return Receipt seller employee
- */
- public Employable getReceiptSellerEmployee () {
- return this.receiptSellerEmployee;
- }
-
- /**
- * Setter for receipt seller employee
- * <p>
- * @param receiptSellerEmployee Receipt seller employee
- */
- public void setReceiptSellerEmployee (final Employable receiptSellerEmployee) {
- this.receiptSellerEmployee = receiptSellerEmployee;
- }
-
- /**
- * Getter for receipt sequence number
- * <p>
- * @return Receipt sequence number
- */
- public Long getReceiptSequenceNumber () {
- return this.receiptSequenceNumber;
- }
-
- /**
- * Setter for receipt sequence number
- * <p>
- * @param receiptSequenceNumber Receipt sequence number
- */
- public void setReceiptSequenceNumber (final Long receiptSequenceNumber) {
- this.receiptSequenceNumber = receiptSequenceNumber;
- }
-
- /**
- * Getter for receipt transaction number
- * <p>
- * @return Receipt transaction number
- */
- public Long getReceiptTransactionNumber () {
- return this.receiptTransactionNumber;
- }
-
- /**
- * Setter for receipt transaction number
- * <p>
- * @param receiptTransactionNumber Receipt transaction number
- */
- public void setReceiptTransactionNumber (final Long receiptTransactionNumber) {
- this.receiptTransactionNumber = receiptTransactionNumber;
- }
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- public User getReceiptUser () {
- return this.receiptUser;
- }
-
- /**
- * Setter for user instance
- * <p>
- * @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.
- * <p>
- * @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;
- }
-
}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@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<ObservableReceiptAddedEvent> 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<ObservableReceiptUpdatedEvent> 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.
+ * <p>
+ */
+ 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
+ * <p>
+ * @return Current receipt
+ */
+ public BillableReceipt getCurrentReceipt () {
+ return this.currentReceipt;
+ }
+
+ /**
+ * Setter for current receipt
+ * <p>
+ * @param currentReceipt Current receipt
+ */
+ public void setCurrentReceipt (final BillableReceipt currentReceipt) {
+ this.currentReceipt = currentReceipt;
+ }
+
+ /**
+ * Getter for receipt's bar-code number
+ * <p>
+ * @return Receipt's bar-code number
+ */
+ public String getReceiptBarCodeNumber () {
+ return this.receiptBarCodeNumber;
+ }
+
+ /**
+ * Setter for receipt's bar-code number
+ * <p>
+ * @param receiptBarCodeNumber Receipt's bar-code number
+ */
+ public void setReceiptBarCodeNumber (final String receiptBarCodeNumber) {
+ this.receiptBarCodeNumber = receiptBarCodeNumber;
+ }
+
+ /**
+ * Getter for bonus card
+ * <p>
+ * @return Bonus card
+ */
+ public BonusCard getReceiptBonusCard () {
+ return this.receiptBonusCard;
+ }
+
+ /**
+ * Setter for bonus card
+ * <p>
+ * @param receiptBonusCard Bonus card
+ */
+ public void setReceiptBonusCard (final BonusCard receiptBonusCard) {
+ this.receiptBonusCard = receiptBonusCard;
+ }
+
+ /**
+ * Getter for receipt issuing branch office
+ * <p>
+ * @return Receipt issuing branch office
+ */
+ public BranchOffice getReceiptBranchOffice () {
+ return this.receiptBranchOffice;
+ }
+
+ /**
+ * Setter for receipt issuing branch office
+ * <p>
+ * @param receiptBranchOffice Receipt issuing branch office
+ */
+ public void setReceiptBranchOffice (final BranchOffice receiptBranchOffice) {
+ this.receiptBranchOffice = receiptBranchOffice;
+ }
+
+ /**
+ * Getter for receipt id
+ * <p>
+ * @return Receipt it
+ */
+ public Long getReceiptId () {
+ return this.receiptId;
+ }
+
+ /**
+ * Setter for receipt id
+ * <p>
+ * @param receiptId Receipt id
+ */
+ public void setReceiptId (final Long receiptId) {
+ this.receiptId = receiptId;
+ }
+
+ /**
+ * Getter for receipt issue date and time
+ * <p>
+ * @return Receipt issue date and time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getReceiptIssued () {
+ return this.receiptIssued;
+ }
+
+ /**
+ * Setter for receipt issue date and time
+ * <p>
+ * @param receiptIssued Receipt issue date and time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setReceiptIssued (final Date receiptIssued) {
+ this.receiptIssued = receiptIssued;
+ }
+
+ /**
+ * Getter for receipt number
+ * <p>
+ * @return Receipt number
+ */
+ public String getReceiptNumber () {
+ return this.receiptNumber;
+ }
+
+ /**
+ * Setter for receipt number
+ * <p>
+ * @param receiptNumber Receipt number
+ */
+ public void setReceiptNumber (final String receiptNumber) {
+ this.receiptNumber = receiptNumber;
+ }
+
+ /**
+ * Getter for payment type
+ * <p>
+ * @return Payment type
+ */
+ public PaymentType getReceiptPaymentType () {
+ return this.receiptPaymentType;
+ }
+
+ /**
+ * Setter for payment type
+ * <p>
+ * @param receiptPaymentType Payment type
+ */
+ public void setReceiptPaymentType (final PaymentType receiptPaymentType) {
+ this.receiptPaymentType = receiptPaymentType;
+ }
+
+ /**
+ * Getter for receipt register's number
+ * <p>
+ * @return Receipt register's number
+ */
+ public Long getReceiptRegisterNumber () {
+ return this.receiptRegisterNumber;
+ }
+
+ /**
+ * Setter for receipt register's number
+ * <p>
+ * @param receiptRegisterNumber Receipt register's number
+ */
+ public void setReceiptRegisterNumber (final Long receiptRegisterNumber) {
+ this.receiptRegisterNumber = receiptRegisterNumber;
+ }
+
+ /**
+ * Getter for receipt seller employee
+ * <p>
+ * @return Receipt seller employee
+ */
+ public Employable getReceiptSellerEmployee () {
+ return this.receiptSellerEmployee;
+ }
+
+ /**
+ * Setter for receipt seller employee
+ * <p>
+ * @param receiptSellerEmployee Receipt seller employee
+ */
+ public void setReceiptSellerEmployee (final Employable receiptSellerEmployee) {
+ this.receiptSellerEmployee = receiptSellerEmployee;
+ }
+
+ /**
+ * Getter for receipt sequence number
+ * <p>
+ * @return Receipt sequence number
+ */
+ public Long getReceiptSequenceNumber () {
+ return this.receiptSequenceNumber;
+ }
+
+ /**
+ * Setter for receipt sequence number
+ * <p>
+ * @param receiptSequenceNumber Receipt sequence number
+ */
+ public void setReceiptSequenceNumber (final Long receiptSequenceNumber) {
+ this.receiptSequenceNumber = receiptSequenceNumber;
+ }
+
+ /**
+ * Getter for receipt transaction number
+ * <p>
+ * @return Receipt transaction number
+ */
+ public Long getReceiptTransactionNumber () {
+ return this.receiptTransactionNumber;
+ }
+
+ /**
+ * Setter for receipt transaction number
+ * <p>
+ * @param receiptTransactionNumber Receipt transaction number
+ */
+ public void setReceiptTransactionNumber (final Long receiptTransactionNumber) {
+ this.receiptTransactionNumber = receiptTransactionNumber;
+ }
+
+ /**
+ * Getter for user instance
+ * <p>
+ * @return User instance
+ */
+ public User getReceiptUser () {
+ return this.receiptUser;
+ }
+
+ /**
+ * Setter for user instance
+ * <p>
+ * @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.
+ * <p>
+ * @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;
+ }
+
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.financial.model.receipt.action;
+
+import java.io.Serializable;
+
+/**
+ * An interface for administrative receipt beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialAdminReceiptActionWebViewController extends Serializable {
+
+}
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;
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
this.getAllReceipts().add(event.getReceipt());
}
+ /**
+ * Observes events being fired when a receipt has been updated
+ * <p>
+ * @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
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);
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.
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.
<p:outputLabel for="branchOffice" value="#{msg.ADMIN_SELECT_BRANCH_OFFICE}" />
<p:selectOneMenu
id="branchOffice"
- value="#{adminReceiptController.receiptBranchOffice}"
+ value="#{adminReceiptActionController.receiptBranchOffice}"
filter="true"
filterMatchMode="contains"
required="true"
<p:outputLabel for="receiptIssued" value="#{project.ENTER_RECEIPT_ISSUE_DATE}" />
<p:calendar
id="receiptIssued"
- value="#{adminReceiptController.receiptIssued}"
+ value="#{adminReceiptActionController.receiptIssued}"
required="true"
requiredMessage="#{project.ADMIN_RECEIPT_ISSUE_DATE_REQUIRED}"
pattern="#{msg.DATE_TIME_PATTERN}"
<p:outputLabel for="receiptPaymentType" value="#{msg.ADMIN_SELECT_PAYMENT_TYPE}" />
<p:selectOneMenu
id="receiptPaymentType"
- value="#{adminReceiptController.receiptPaymentType}"
+ value="#{adminReceiptActionController.receiptPaymentType}"
filter="true"
filterMatchMode="contains"
required="true"
<p:outputLabel for="receiptSellerEmployee" value="#{msg.ADMIN_SELECT_SELLER_EMPLOYEE}" />
<p:selectOneMenu
id="receiptSellerEmployee"
- value="#{adminReceiptController.receiptSellerEmployee}"
+ value="#{adminReceiptActionController.receiptSellerEmployee}"
filter="true"
filterMatchMode="contains"
>
<p:outputLabel for="receiptUser" value="#{project.ADMIN_SELECT_RECEIPT_USER_OWNER}" />
<p:selectOneMenu
id="receiptUser"
- value="#{adminReceiptController.receiptUser}"
+ value="#{adminReceiptActionController.receiptUser}"
filter="true"
filterMatchMode="contains"
>
<p:inputText
id="receiptNumber"
size="20"
- value="#{adminReceiptController.receiptNumber}"
+ value="#{adminReceiptActionController.receiptNumber}"
validatorMessage="#{project.ENTERED_RECEIPT_NUMBER_INVALID}" />
<p:outputLabel for="receiptRegisterNumber" value="#{project.ENTER_RECEIPT_REGISTER_NUMBER}" />
- <p:inputText id="receiptRegisterNumber" size="3" maxlength="10" value="#{adminReceiptController.receiptRegisterNumber}" validatorMessage="#{project.ENTERED_RECEIPT_REGISTER_NUMBER_INVALID}">
+ <p:inputText id="receiptRegisterNumber" size="3" maxlength="10" value="#{adminReceiptActionController.receiptRegisterNumber}" validatorMessage="#{project.ENTERED_RECEIPT_REGISTER_NUMBER_INVALID}">
<f:validateLongRange minimum="1" maximum="999" />
</p:inputText>
<p:outputLabel for="receiptBarCodeNumber" value="#{project.ENTER_RECEIPT_BARCODE_NUMBER}" />
- <p:inputText id="receiptBarCodeNumber" size="20" maxlength="255" value="#{adminReceiptController.receiptBarCodeNumber}" />
+ <p:inputText id="receiptBarCodeNumber" size="20" maxlength="255" value="#{adminReceiptActionController.receiptBarCodeNumber}" />
<p:outputLabel for="receiptSequenceNumber" value="#{project.ENTER_RECEIPT_SEQUENCE_NUMBER}" />
- <p:inputText id="receiptSequenceNumber" size="10" maxlength="20" value="#{adminReceiptController.receiptSequenceNumber}" />
+ <p:inputText id="receiptSequenceNumber" size="10" maxlength="20" value="#{adminReceiptActionController.receiptSequenceNumber}" />
<p:outputLabel for="receiptTransactionNumber" value="#{project.ENTER_RECEIPT_TRANSACTION_NUMBER}" />
- <p:inputText id="receiptTransactionNumber" size="10" maxlength="20" value="#{adminReceiptController.receiptTransactionNumber}" />
+ <p:inputText id="receiptTransactionNumber" size="10" maxlength="20" value="#{adminReceiptActionController.receiptTransactionNumber}" />
</p:panelGrid>
</p:fieldset>
</ui:composition>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition
+ template="/WEB-INF/templates/admin/admin_base.tpl"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:f="http://xmlns.jcp.org/jsf/core"
+ xmlns:p="http://primefaces.org/ui"
+ >
+
+ <ui:define name="metadata">
+ <f:metadata>
+ <f:viewParam
+ name="receiptId"
+ value="#{adminReceiptActionController.currentReceipt}"
+ converter="ReceiptConverter"
+ required="true"
+ requiredMessage="#{project.ERROR_PARAMETER_RECEIPT_ID_NOT_SET}"
+ converterMessage="#{project.PARAMETER_RECEIPT_ID_INVALID}"
+ />
+
+ <f:viewAction
+ action="#{adminReceiptActionController.copyAllReceiptProperties()}"
+ />
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="document_admin_title">
+ <h:outputText value="#{project.PAGE_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT}" />
+ </ui:define>
+
+ <ui:define name="content_header">
+ <h:outputText value="#{project.CONTENT_TITLE_ADMIN_FINANCIALS_EDIT_RECEIPT}" />
+ </ui:define>
+
+ <ui:define name="content">
+ <h:form
+ id="form-edit-receipt"
+ rendered="#{not empty adminReceiptActionController.currentReceipt}"
+ >
+ <h:inputHidden value="#{adminReceiptActionController.receiptId}" />
+
+ <p:panelGrid
+ columns="1"
+ layout="grid"
+ >
+ <f:facet name="header">
+ <h:outputFormat
+ value="#{project.ADMIN_EDIT_RECEIPT_NUMBER_TITLE}"
+ rendered="#{not empty adminReceiptActionController.receiptNumber}"
+ >
+ <f:param value="#{adminReceiptActionController.receiptNumber}" />
+ <f:param value="#{adminReceiptActionController.receiptId}" />
+ </h:outputFormat>
+
+ <h:outputFormat
+ value="#{project.ADMIN_EDIT_RECEIPT_TITLE}"
+ rendered="#{empty adminReceiptActionController.receiptNumber}"
+ >
+ <f:param value="#{adminReceiptActionController.receiptId}" />
+ </h:outputFormat>
+ </f:facet>
+
+ <h:panelGroup styleClass="para" layout="block">
+ <h:outputText value="#{project.ADMIN_EDIT_RECEIPT_MINIMUM_DATA}" />
+ </h:panelGroup>
+
+ <ui:include src="/WEB-INF/templates/admin/financial/receipt/admin_form_financial_receipt.tpl" />
+
+ <f:facet name="footer">
+ <p:panelGrid columns="2" layout="grid">
+ <p:commandButton
+ type="reset"
+ value="#{msg.BUTTON_RESET_FORM}"
+ />
+
+ <p:commandButton
+ type="submit"
+ value="#{project.BUTTON_ADMIN_EDIT_RECEIPT}"
+ action="#{adminReceiptActionController.updateReceipt()}"
+ />
+ </p:panelGrid>
+ </f:facet>
+ </p:panelGrid>
+ </h:form>
+ </ui:define>
+</ui:composition>
>
<f:facet name="header">
- <p:panelGrid columns="3" layout="grid" columnClasses="ui-grid-col-4,ui-grid-col-6,ui-grid-col-2">
+ <p:panelGrid
+ columns="3"
+ layout="grid"
+ columnClasses="ui-grid-col-4,ui-grid-col-6,ui-grid-col-2"
+ >
<p:spacer />
<p:panelGrid
layout="grid"
styleClass="ui-noborder"
>
- <p:outputLabel for="globalFilter" value="#{msg.SEARCH_ALL_FIELDS}" style="float: right" />
- <p:inputText id="globalFilter" onkeyup="PF('receiptList').filter()" placeholder="#{msg.ENTER_KEYWORD}"/>
+ <p:outputLabel
+ for="globalFilter"
+ value="#{msg.SEARCH_ALL_FIELDS}"
+ style="float: right"
+ />
+
+ <p:inputText
+ id="globalFilter"
+ onkeyup="PF('receiptList').filter()"
+ placeholder="#{msg.ENTER_KEYWORD}"
+ />
</p:panelGrid>
<p:outputPanel>
<p:commandButton
type="submit"
value="#{project.BUTTON_ADMIN_ADD_RECEIPT}"
- action="#{adminReceiptController.addReceipt()}"
+ action="#{adminReceiptActionController.addReceipt()}"
update=":master:form-list-financial-receipts:receiptList"
/>
</p:panelGrid>
>
<f:facet name="header">
- <p:panelGrid columns="3" layout="grid" columnClasses="ui-grid-col-4,ui-grid-col-6,ui-grid-col-2">
+ <p:panelGrid
+ columns="3"
+ layout="grid"
+ columnClasses="ui-grid-col-4,ui-grid-col-6,ui-grid-col-2"
+ >
<p:spacer />
<p:panelGrid
layout="grid"
styleClass="ui-noborder"
>
- <p:outputLabel for="globalFilter" value="#{msg.SEARCH_ALL_FIELDS}" style="float: right" />
- <p:inputText id="globalFilter" onkeyup="PF('receiptItemList').filter()" placeholder="#{msg.ENTER_KEYWORD}"/>
+ <p:outputLabel
+ for="globalFilter"
+ value="#{msg.SEARCH_ALL_FIELDS}"
+ style="float: right"
+ />
+
+ <p:inputText
+ id="globalFilter"
+ onkeyup="PF('departmentList').filter()"
+ placeholder="#{msg.ENTER_KEYWORD}"
+ />
</p:panelGrid>
<p:outputPanel>