From ee3143c752030bcbf85093936e6d9126e096d248 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 24 Sep 2017 14:15:06 +0200 Subject: [PATCH] Don't cherry-pick: - added general backing bean for receipts which has an exposed (interface) method isReceiptAdded() which will check if receipt is already added - added missing i18n strings - added template for login (user) area for adding new receipts - fixed mess of choosing wrong language bundle - changed template towards p:panelGrid which is responsive and the correct way in modern JSF (no need for table-XXXYYY) - fixed wrong usage of controllers: admin versus general MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialsIncomeWebRequestBean.java | 6 +- .../FinancialsIncomeWebRequestController.java | 2 +- .../FinancialAdminReceiptWebRequestBean.java} | 253 +++++---- ...ncialAdminReceiptWebRequestController.java | 28 + .../FinancialsReceiptWebRequestBean.java | 496 ++++++++++++++++++ ...FinancialsReceiptWebRequestController.java | 10 + .../localization/project_de_DE.properties | 15 +- .../localization/project_en_US.properties | 13 +- .../receipt/admin_form_financial_receipt.tpl | 184 +++---- .../receipt/login_form_financial_receipt.tpl | 98 ++++ .../receipts/admin_receipt_list.xhtml | 31 +- .../login_financials_add_receipt.xhtml | 104 +--- 12 files changed, 932 insertions(+), 308 deletions(-) rename src/java/org/mxchange/jfinancials/beans/financial/{ => model}/income/FinancialsIncomeWebRequestBean.java (96%) rename src/java/org/mxchange/jfinancials/beans/financial/{ => model}/income/FinancialsIncomeWebRequestController.java (96%) rename src/java/org/mxchange/jfinancials/beans/financial/{receipt/FinancialsReceiptWebRequestBean.java => model/receipt/FinancialAdminReceiptWebRequestBean.java} (50%) create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestController.java create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java rename src/java/org/mxchange/jfinancials/beans/financial/{ => model}/receipt/FinancialsReceiptWebRequestController.java (76%) create mode 100644 web/WEB-INF/templates/user/financial/receipt/login_form_financial_receipt.tpl diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java similarity index 96% rename from src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java rename to src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java index c2edf3ff..20c6795c 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java @@ -14,7 +14,7 @@ * 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.income; +package org.mxchange.jfinancials.beans.financial.model.income; import java.text.MessageFormat; import java.util.Arrays; @@ -23,7 +23,7 @@ import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jfinancials.beans.BaseFinancialsController; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; import org.mxchange.jfinancials.model.income.BillableIncome; import org.mxchange.jfinancials.model.income.FinancialIncome; @@ -37,7 +37,7 @@ import org.mxchange.jfinancials.model.income.interval.FinancialInterval; */ @Named ("financialIncomeController") @RequestScoped -public class FinancialsIncomeWebRequestBean extends BaseFinancialsController implements FinancialsIncomeWebRequestController { +public class FinancialsIncomeWebRequestBean extends BaseFinancialsBean implements FinancialsIncomeWebRequestController { /** * Serial number diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestController.java similarity index 96% rename from src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java rename to src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestController.java index e25f954e..e885949a 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestController.java @@ -14,7 +14,7 @@ * 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.income; +package org.mxchange.jfinancials.beans.financial.model.income; import java.io.Serializable; import java.util.List; diff --git a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java similarity index 50% rename from src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java rename to src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java index 3e9c128f..00af46b6 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017 Roland Häder + * Copyright (C) 2017 Roland Häder * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -17,60 +17,73 @@ package org.mxchange.jfinancials.beans.financial.model.receipt; import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.List; +import java.util.Date; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Observes; +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.jfinancials.beans.BaseFinancialsController; -import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; +import org.mxchange.jcontactsbusiness.model.employee.Employee; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; +import org.mxchange.jfinancials.events.receipt.added.ReceiptAddedEvent; import org.mxchange.jfinancials.exceptions.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.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote; import org.mxchange.jproduct.model.payment.PaymentType; -import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; +import org.mxchange.jusercore.model.user.User; /** - * An administrative financial receipt bean (controller) + * An administrative backing bean for receipts *

* @author Roland Häder */ -@Named ("receiptController") +@Named ("adminReceiptController") @RequestScoped -public class FinancialsReceiptWebRequestBean extends BaseFinancialsController implements FinancialsReceiptWebRequestController { +public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean implements FinancialAdminReceiptWebRequestController { /** * Serial number */ - private static final long serialVersionUID = 56_189_028_928_371L; + 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/financialReceipt!org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote") - private FinancialReceiptSessionBeanRemote financialBean; + @EJB (lookup = "java:global/jfinancials-ejb/adminFinancialReceipt!org.mxchange.jfinancials.model.receipt.FinancialAdminReceiptSessionBeanRemote") + private FinancialAdminReceiptSessionBeanRemote adminFinancialBean; /** - * Payment type being used for this receipt + * Bar-code number */ - private PaymentType paymentType; + private Long 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 Calendar receiptIssued; + private Date receiptIssued; /** * Receipt number (only numbers) @@ -78,26 +91,31 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsController im private Long receiptNumber; /** - * Cached receipts + * Payment type being used for this receipt + */ + private PaymentType receiptPaymentType; + + /** + * Register number */ - private final List receipts; + private Long receiptRegisterNumber; /** - * User instance + * Selling employee */ - @Inject - private FinancialsUserLoginWebSessionController userLoginController; + private Employee receiptSellerEmployee; + + /** + * User who "owns" this receipt + */ + private User receiptUser; /** - * Constructor + * Default constructor */ - @SuppressWarnings ("CollectionWithoutInitialCapacity") - public FinancialsReceiptWebRequestBean () { + public FinancialAdminReceiptWebRequestBean () { // Call super constructor super(); - - // Init cache - this.receipts = new ArrayList<>(); } /** @@ -107,20 +125,8 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsController im * @return Link outcome */ public String addReceipt () { - // Pre-check if receipt number is set - if (this.getReceiptNumber() == null || this.getReceiptNumber() == 0) { - // Generate one randomly - final Long randomNumber = Math.round(Math.random() * 1_000_000); - - // And set it here - this.setReceiptNumber(randomNumber); - } - // Are all required fields set? - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged-in - throw new IllegalStateException("User is not logged-in"); //NOI18N - } else if (this.getReceiptBranchOffice() == null) { + if (this.getReceiptBranchOffice() == null) { // Is not set throw new NullPointerException("this.receiptBranchOffice is not set."); //NOI18N } else if (this.getReceiptBranchOffice().getBranchId() == null) { @@ -129,18 +135,19 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsController im } 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.getPaymentType() == null) { + } else if (this.getReceiptPaymentType() == null) { // Is not set - throw new NullPointerException("this.paymentType is not set."); //NOI18N + 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 = new FinancialReceipt(this.getPaymentType(), this.getReceiptBranchOffice(), this.userLoginController.getLoggedInUser(), this.getReceiptIssued()); + final BillableReceipt receipt = this.createReceiptInstance(); - if (this.isReceiptAdded(receipt)) { + // Is the receipt already there? + if (this.receiptController.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 } @@ -151,67 +158,35 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsController im // All is set, then try to call EJB try { // Add it - updatedReceipt = this.financialBean.addReceipt(receipt); + updatedReceipt = this.adminFinancialBean.addReceipt(receipt); } catch (final ReceiptAlreadyAddedException ex) { // Throw it again throw new FaceletException(ex); } - // @TODO Maybe fire event here? + // Fire event with updated instance + this.adminAddedReceiptEvent.fire(new ReceiptAddedEvent(updatedReceipt)); + // Return redirect outcome return "add_receipt_item?faces-redirect=true"; //NOI18N } /** - * Event observer for logged-in user - *

- * @param event Event instance - */ - public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getLoggedInUser() == null) { - // Throw NPE again - throw new NullPointerException("event.loggedInUser is null"); //NOI18N - } else if (event.getLoggedInUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N - } else if (event.getLoggedInUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N - } - - // Fill cache with all found user's receipts - this.receipts.addAll(this.financialBean.allUsersReceipts(this.userLoginController.getLoggedInUser())); - } - - /** - * Returns a list of all payment types - *

- * @return A list of all payment types - */ - public List allPaymentTypes () { - return Arrays.asList(PaymentType.values()); - } - - /** - * Getter for payment type + * Getter for receipt's bar-code number *

- * @return Payment type + * @return Receipt's bar-code number */ - public PaymentType getPaymentType () { - return this.paymentType; + public Long getReceiptBarCodeNumber () { + return this.receiptBarCodeNumber; } /** - * Setter for payment type + * Setter for receipt's bar-code number *

- * @param paymentType Payment type + * @param receiptBarCodeNumber Receipt's bar-code number */ - public void setPaymentType (final PaymentType paymentType) { - this.paymentType = paymentType; + public void setReceiptBarCodeNumber (final Long receiptBarCodeNumber) { + this.receiptBarCodeNumber = receiptBarCodeNumber; } /** @@ -238,7 +213,7 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsController im * @return Receipt issue date and time */ @SuppressWarnings ("ReturnOfDateField") - public Calendar getReceiptIssued () { + public Date getReceiptIssued () { return this.receiptIssued; } @@ -248,7 +223,7 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsController im * @param receiptIssued Receipt issue date and time */ @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setReceiptIssued (final Calendar receiptIssued) { + public void setReceiptIssued (final Date receiptIssued) { this.receiptIssued = receiptIssued; } @@ -271,15 +246,95 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsController im } /** - * Checks if receipt has already been added to database + * Getter for payment type *

- * @param receipt Prepared receipt instance + * @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 Employee getReceiptSellerEmployee () { + return this.receiptSellerEmployee; + } + + /** + * Setter for receipt seller employee + *

+ * @param receiptSellerEmployee Receipt seller employee + */ + public void setReceiptSellerEmployee (final Employee receiptSellerEmployee) { + this.receiptSellerEmployee = receiptSellerEmployee; + } + + /** + * 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; + } + + /** + * Creates a new instance from all available data of this bean. *

- * @return Whether the receipt has already been added + * @return Receipt instance */ - private boolean isReceiptAdded (final BillableReceipt receipt) { - // Always trust the cache - return this.receipts.contains(receipt); + 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()); + + // Return prepared instance + return receipt; } } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestController.java new file mode 100644 index 00000000..6ae4ff0d --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * 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; + +import java.io.Serializable; + +/** + * An interface for administrative receipt beans + *

+ * @author Roland Häder + */ +public interface FinancialAdminReceiptWebRequestController extends Serializable { + +} 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 new file mode 100644 index 00000000..46a90a6d --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java @@ -0,0 +1,496 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * 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; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +import java.util.Date; +import java.util.Iterator; +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.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.event.Observes; +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.Employee; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; +import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; +import org.mxchange.jfinancials.events.receipt.added.ReceiptAddedEvent; +import org.mxchange.jfinancials.exceptions.ReceiptAlreadyAddedException; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; +import org.mxchange.jfinancials.model.receipt.FinancialReceipt; +import org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote; +import org.mxchange.jproduct.model.payment.PaymentType; +import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; + +/** + * An administrative financial receipt bean (controller) + *

+ * @author Roland Häder + */ +@Named ("receiptController") +@RequestScoped +public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implements FinancialsReceiptWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_189_028_928_371L; + + /** + * Event being fired when user has added a new receipt + */ + @Inject + @Any + private Event addedReceiptEvent; + + /** + * All receipts list + */ + private final List allReceipts; + + /** + * Filtered receipts list + */ + private List filteredReceipts; + + /** + * Bar-code number + */ + private Long receiptBarCodeNumber; + + /** + * EJB for general financial receipt purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/financialReceipt!org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote") + private FinancialReceiptSessionBeanRemote receiptBean; + + /** + * Recipient issuing company (for example where the user went shopping to) + */ + private BranchOffice receiptBranchOffice; + + /** + * A list of all branch offices (globally) + */ + @Inject + @NamedCache (cacheName = "receiptCache") + private Cache receiptCache; + + /** + * Date/time the receipt has been issued + */ + private Date receiptIssued; + + /** + * Receipt number (only numbers) + */ + private Long receiptNumber; + + /** + * Payment type being used for this receipt + */ + private PaymentType receiptPaymentType; + + /** + * Register number + */ + private Long receiptRegisterNumber; + + /** + * Selling employee + */ + private Employee receiptSellerEmployee; + + /** + * User instance + */ + @Inject + private FinancialsUserLoginWebSessionController userLoginController; + + /** + * User's receipts + */ + private final List userReceipts; + + /** + * Constructor + */ + @SuppressWarnings ("CollectionWithoutInitialCapacity") + public FinancialsReceiptWebRequestBean () { + // Call super constructor + super(); + + // Init lists + this.allReceipts = new LinkedList<>(); + this.userReceipts = new LinkedList<>(); + } + + /** + * 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. + *

+ * @return Link outcome + */ + public String addReceipt () { + // Are all required fields set? + if (!this.userLoginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else 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.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.receiptBean.addReceipt(receipt); + } catch (final ReceiptAlreadyAddedException ex) { + // Throw it again + throw new FaceletException(ex); + } + + // Fire event with updated instance + this.addedReceiptEvent.fire(new ReceiptAddedEvent(updatedReceipt)); + + // Return redirect outcome + return "add_receipt_item?faces-redirect=true"; //NOI18N + } + + /** + * Observes events being fired when a new receipt has been added + *

+ * @param event Event being fired + */ + public void afterAddedReceiptEvent (@Observes final ObservableReceiptAddedEvent 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 + } + + // Add to cache and general list + this.receiptCache.put(event.getReceipt().getReceiptId(), event.getReceipt()); + this.allReceipts.add(event.getReceipt()); + + // Is same user? + if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { + // Same user, then add it + this.userReceipts.add(event.getReceipt()); + } + } + + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ + public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLoggedInUser() == null) { + // Throw NPE again + throw new NullPointerException("event.loggedInUser is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N + } + + // Fill cache with all found user's receipts + for (final BillableReceipt receipt : this.allReceipts) { + // Is same user? + if (Objects.equals(receipt.getReceiptUser(), event.getLoggedInUser())) { + // Yes, then add it + this.userReceipts.add(receipt); + } + } + } + + /** + * Returns all receipts + *

+ * @return All receipts + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List allReceipts () { + return this.allReceipts; + } + + /** + * Getter for filtered receipts + *

+ * @return Filtered receipts + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredReceipts () { + return this.filteredReceipts; + } + + /** + * Setter for filtered receipts + *

+ * @param filteredReceipts Filtered receipts + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredReceipts (final List filteredReceipts) { + this.filteredReceipts = filteredReceipts; + } + + /** + * Getter for receipt's bar-code number + *

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

+ * @param receiptBarCodeNumber Receipt's bar-code number + */ + public void setReceiptBarCodeNumber (final Long 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 Long getReceiptNumber () { + return this.receiptNumber; + } + + /** + * Setter for receipt number + *

+ * @param receiptNumber Receipt number + */ + public void setReceiptNumber (final Long 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 Employee getReceiptSellerEmployee () { + return this.receiptSellerEmployee; + } + + /** + * Setter for receipt seller employee + *

+ * @param receiptSellerEmployee Receipt seller employee + */ + public void setReceiptSellerEmployee (final Employee receiptSellerEmployee) { + this.receiptSellerEmployee = receiptSellerEmployee; + } + + @PostConstruct + public void initCache () { + // Is cache there? + if (!this.receiptCache.iterator().hasNext()) { + // Get whole list + final List list = this.receiptBean.allReceipts(); + + // Add all + for (final Iterator iterator = list.iterator(); iterator.hasNext();) { + // Get next element + final BillableReceipt next = iterator.next(); + + // Add it to cache + this.receiptCache.put(next.getReceiptId(), next); + } + } + + // Is the list empty, but filled cache? + if (this.allReceipts.isEmpty() && this.receiptCache.iterator().hasNext()) { + // Get iterator + final Iterator> iterator = this.receiptCache.iterator(); + + // Build up list + while (iterator.hasNext()) { + // GEt next element + final Cache.Entry next = iterator.next(); + + // Add to list + this.allReceipts.add(next.getValue()); + } + + // Sort list + this.allReceipts.sort(new Comparator() { + @Override + public int compare (final BillableReceipt o1, final BillableReceipt o2) { + return o1.getReceiptId() > o2.getReceiptId() ? 1 : o1.getReceiptId() < o2.getReceiptId() ? -1 : 0; + } + } + ); + } + } + + @Override + public boolean isReceiptAdded (final BillableReceipt receipt) { + // Always trust the cache + return this.allReceipts.contains(receipt); + } + + /** + * Returns a fully created receipt instance (except primary key, of course) + *

+ * @return Receipt instance + */ + private BillableReceipt createReceiptInstance () { + // Init receipt instance + final BillableReceipt receipt = new FinancialReceipt(this.getReceiptPaymentType(), this.getReceiptBranchOffice(), this.userLoginController.getLoggedInUser(), this.getReceiptIssued()); + + // Set optional fields + receipt.setReceiptNumber(this.getReceiptNumber()); + receipt.setReceiptBarCodeNumber(this.getReceiptBarCodeNumber()); + receipt.setReceiptRegisterNumber(this.getReceiptRegisterNumber()); + receipt.setReceiptSellerEmployee(this.getReceiptSellerEmployee()); + + // Return it + return receipt; + } +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java similarity index 76% rename from src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java rename to src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java index e5c331cc..a79d5549 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java @@ -17,6 +17,7 @@ package org.mxchange.jfinancials.beans.financial.model.receipt; import java.io.Serializable; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; /** * An administrative interface for financial receipt beans @@ -25,4 +26,13 @@ import java.io.Serializable; */ public interface FinancialsReceiptWebRequestController extends Serializable { + /** + * Checks if receipt has already been added to database + *

+ * @param receipt Prepared receipt instance + *

+ * @return Whether the receipt has already been added + */ + boolean isReceiptAdded (final BillableReceipt receipt); + } diff --git a/src/java/org/mxchange/localization/project_de_DE.properties b/src/java/org/mxchange/localization/project_de_DE.properties index d79d2a29..dd5c1590 100644 --- a/src/java/org/mxchange/localization/project_de_DE.properties +++ b/src/java/org/mxchange/localization/project_de_DE.properties @@ -48,5 +48,16 @@ ADMIN_ADD_FINANCIAL_RECEIPT_TITLE=Neuen Kassenbon hinzufuegen BUTTON_ADMIN_ADD_FINANCIAL_RECEIPT=Kassenbon hinzufuegen ADMIN_FINANCIAL_RECEIPT_ISSUE_DATE_REQUIRED=Bitte geben Sie das Ausstellungsdatum des Kassenbons ein. ADMIN_MENU_FINANCIAL_RECEIPTS_TITLE=Kassenbons -LINK_ADMIN_LIST_FINANCIAL_RECEIPTS_TITLE=Lists all registered receipts. -LINK_ADMIN_LIST_FINANCIAL_RECEIPTS=Kassenbons auflisten +LINK_ADMIN_LIST_FINANCIAL_RECEIPTS_TITLE=Listet alle registrierten Kassenbos/Rechnungen auf.. +LINK_ADMIN_LIST_FINANCIAL_RECEIPTS=Kassenbons/Rechnungen auflisten +ADMIN_LIST_FINANCIAL_RECEIPTS_HEADER=Alle Kassenbons/Rechnungen auflisten +ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND=Grunddaten des Kassenbons +ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND_TITLE=Geben Sie hier die Grunddaten des neuen Kassenbons einn. +ENTER_FINANCIAL_RECEIPT_ISSUE_DATE=Ausstellungsdatum des Kassenbons eingeben: +ENTER_FINANCIAL_RECEIPT_NUMBER=Rechnungsnummer eingeben: +ENTERED_RECEIPT_NUMBER_INVALID=Die eingegebene Bonnummer/Rechnungsnummer ist kleiner 1 oder groesser 9999999999. +ADMIN_SELECT_FINANCIAL_RECEIPT_USER_OWNER=Kassenbon einem Benutzer zuweisen: +ENTER_FINANCIAL_RECEIPT_REGISTER_NUMBER=Kassennummer eingeben: +ENTER_FINANCIAL_RECEIPT_BARCODE_NUMBER=Barcode-Nummer eingeben: +ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND=Sonstige Daten des Kassenbons eingeben: +ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND_TITLE=Geben Sie hier weitere Daten an, die Sie auf dem Kassenbon finden koennen. diff --git a/src/java/org/mxchange/localization/project_en_US.properties b/src/java/org/mxchange/localization/project_en_US.properties index 3f05e723..839e4222 100644 --- a/src/java/org/mxchange/localization/project_en_US.properties +++ b/src/java/org/mxchange/localization/project_en_US.properties @@ -36,5 +36,16 @@ ADMIN_ADD_FINANCIAL_RECEIPT_TITLE=Add new receipt BUTTON_ADMIN_ADD_FINANCIAL_RECEIPT=Add receipt ADMIN_FINANCIAL_RECEIPT_ISSUE_DATE_REQUIRED=Please enter date of issue of receipt. ADMIN_MENU_FINANCIAL_RECEIPTS_TITLE=Receipts -LINK_ADMIN_LIST_FINANCIAL_RECEIPTS_TITLE=Listet alle registrierten Kassenbons auf. +LINK_ADMIN_LIST_FINANCIAL_RECEIPTS_TITLE=Lists all registered receipts. LINK_ADMIN_LIST_FINANCIAL_RECEIPTS=List receipts +ADMIN_LIST_FINANCIAL_RECEIPTS_HEADER=List all receipts +ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND=Basic data of receipt: +ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND_TITLE=Enter here basic data of the new receipt. +ENTER_FINANCIAL_RECEIPT_ISSUE_DATE=Enter date of issue of receipt: +ENTER_FINANCIAL_RECEIPT_NUMBER=Enter receipt number: +ENTERED_RECEIPT_NUMBER_INVALID=Your entered receipt number is smaller than 1 or larger than 9999999999. +ADMIN_SELECT_FINANCIAL_RECEIPT_USER_OWNER=Assign receipt to user: +ENTER_FINANCIAL_RECEIPT_REGISTER_NUMBER=Enter cash register number: +ENTER_FINANCIAL_RECEIPT_BARCODE_NUMBER=Enter bar code number: +ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND=Enter other data of receipt: +ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND_TITLE=Enter other additional data you can find on the receipt. 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 58b9c114..a9bb9e50 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 @@ -7,105 +7,105 @@ xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://primefaces.org/ui"> - -

- - - +
+ + + - -
- -
+ + + + + + + + -
- - - - - -
-
+ + + - - - + + + + + + + - -
- -
+ + + + + + + -
- -
-
+ + + + + + + + +
- - - +
+ + + - -
- -
+ + + + + + -
- - - -
-
+ + + + + - - - - - -
- -
- -
- - - - -
-
- - - - -
- - - + + + + +
diff --git a/web/WEB-INF/templates/user/financial/receipt/login_form_financial_receipt.tpl b/web/WEB-INF/templates/user/financial/receipt/login_form_financial_receipt.tpl new file mode 100644 index 00000000..848a92b3 --- /dev/null +++ b/web/WEB-INF/templates/user/financial/receipt/login_form_financial_receipt.tpl @@ -0,0 +1,98 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/web/admin/financials/receipts/admin_receipt_list.xhtml b/web/admin/financials/receipts/admin_receipt_list.xhtml index ad042f81..e24fff89 100644 --- a/web/admin/financials/receipts/admin_receipt_list.xhtml +++ b/web/admin/financials/receipts/admin_receipt_list.xhtml @@ -19,9 +19,9 @@ + emptyMessage="#{project.ADMIN_FINANCIAL_RECEIPT_LIST_EMPTY}"> @@ -41,26 +41,21 @@ - - -
+ + + -
+ - + + + - -
- - - -
    -
  • -
-
+ +
diff --git a/web/user/financials/login_financials_add_receipt.xhtml b/web/user/financials/login_financials_add_receipt.xhtml index 1dc91df5..fe029289 100644 --- a/web/user/financials/login_financials_add_receipt.xhtml +++ b/web/user/financials/login_financials_add_receipt.xhtml @@ -15,101 +15,21 @@ - - -
- -
+ + + + + - -
- -
+ + + -
- - - - - -
-
- - -
- -
- -
- -
-
- - - - - - -
- -
- -
- - - -
-
- - - - - - - - - - - -
- -
- -
- - - - -
-
- - -
+ + +
-- 2.39.5