From 670513ada5a47de6c5fc45b4a5b57671ee4bf804 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 31 Mar 2018 16:36:43 +0200 Subject: [PATCH] Don't cherry-pick: - added view-scoped backing bean for receipt lists which helps pagination + filter + sorting - it is now the new receiptListController and no allReceipts() (method) but only allReceipts (bean property) - addded missing i18n strings, removed no longer used MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialAdminReceiptWebRequestBean.java | 9 +- .../FinancialsReceiptWebRequestBean.java | 203 +--------------- ...FinancialsReceiptWebRequestController.java | 24 -- .../FinancialsReceiptListWebViewBean.java | 227 ++++++++++++++++++ ...inancialsReceiptListWebViewController.java | 60 +++++ .../FinancialsReceiptUserWebSessionBean.java | 145 +++++++++++ ...ncialsReceiptUserWebSessionController.java | 28 +++ .../receipt/FinancialsReceiptConverter.java | 12 +- .../localization/project_de_DE.properties | 24 +- .../localization/project_en_US.properties | 20 +- .../admin_form_financial_receipt_item.tpl | 2 +- .../receipt/admin_receipt_list.xhtml | 114 +++++++-- .../admin_receipt_item_list.xhtml | 4 +- .../login_financials_add_income.xhtml | 1 - 14 files changed, 619 insertions(+), 254 deletions(-) create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewController.java create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionBean.java create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionController.java 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 fa714108..150cc03b 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 @@ -28,6 +28,7 @@ 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; @@ -85,6 +86,12 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl */ private Date receiptIssued; + /** + * Receipt list controller + */ + @Inject + private FinancialsReceiptListWebViewController receiptListController; + /** * Receipt number (only numbers) */ @@ -152,7 +159,7 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl final BillableReceipt receipt = this.createReceiptInstance(); // Is the receipt already there? - if (this.receiptController.isReceiptAdded(receipt)) { + 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 } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java index dd67e95f..f829942b 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java @@ -16,20 +16,11 @@ */ 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; @@ -37,16 +28,15 @@ 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.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.receipt.ReceiptAlreadyAddedException; -import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; 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; /** * A general financial receipt bean (controller) @@ -69,16 +59,6 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen @Any private Event addedReceiptEvent; - /** - * All receipts list - */ - private final List allReceipts; - - /** - * Filtered receipts list - */ - private List filteredReceipts; - /** * Bar-code number */ @@ -96,16 +76,15 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen private BranchOffice receiptBranchOffice; /** - * A list of all branch offices (globally) + * Date/time the receipt has been issued */ - @Inject - @NamedCache (cacheName = "receiptCache") - private Cache receiptCache; + private Date receiptIssued; /** - * Date/time the receipt has been issued + * Receipt list controller */ - private Date receiptIssued; + @Inject + private FinancialsReceiptListWebViewController receiptListController; /** * Receipt number (only numbers) @@ -133,11 +112,6 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen @Inject private FinancialsUserLoginWebSessionController userLoginController; - /** - * User's receipts - */ - private final List userReceipts; - /** * Constructor */ @@ -145,10 +119,6 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen public FinancialsReceiptWebRequestBean () { // Call super constructor super(); - - // Init lists - this.allReceipts = new LinkedList<>(); - this.userReceipts = new LinkedList<>(); } /** @@ -183,7 +153,7 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen final BillableReceipt receipt = this.createReceiptInstance(); // Is the receipt already there? - if (this.isReceiptAdded(receipt)) { + 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 } @@ -210,120 +180,6 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen return "admin_list_receipts?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; - } - - @Override - public BillableReceipt findReceiptById (final Long receiptId) throws ReceiptNotFoundException { - // Validate parameter - if (null == receiptId) { - // Throw NPE - throw new NullPointerException("receiptId is null"); //NOI18N - } else if (receiptId < 1) { - // Throw IAE - throw new IllegalArgumentException("receiptId=" + receiptId + " is invalid."); //NOI18N - } else if (!this.receiptCache.containsKey(receiptId)) { - // Not found - throw new ReceiptNotFoundException(receiptId); - } - - // Get it from cache - final BillableReceipt receipt = this.receiptCache.get(receiptId); - - // Return it - return receipt; - } - - /** - * 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 *

@@ -452,51 +308,6 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen this.receiptSellerEmployee = receiptSellerEmployee; } - @PostConstruct - public void initCache () { - // Is cache there? - if (!this.receiptCache.iterator().hasNext()) { - // Get whole list - final List receipts = this.receiptBean.allReceipts(); - - // Add all - for (final BillableReceipt receipt : receipts) { - // Add it to cache - this.receiptCache.put(receipt.getReceiptId(), receipt); - } - } - - // 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); - } - /** * Clears this bean */ diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java index 23a72051..9192bb1d 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java @@ -17,8 +17,6 @@ package org.mxchange.jfinancials.beans.financial.model.receipt; import java.io.Serializable; -import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; -import org.mxchange.jfinancials.model.receipt.BillableReceipt; /** * An administrative interface for financial receipt beans @@ -27,26 +25,4 @@ import org.mxchange.jfinancials.model.receipt.BillableReceipt; */ public interface FinancialsReceiptWebRequestController extends Serializable { - /** - * Returns a receipt instance (entity) for given primary key. If not found, - * a proper exception is thrown. - *

- * @param receiptId Receipt id (primary key) - *

- * @return Receipt entity matching to primary key - *

- * @throws ReceiptNotFoundException If a receipt with given primary key - * could not be found - */ - BillableReceipt findReceiptById (final Long receiptId) throws ReceiptNotFoundException; - - /** - * 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/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java new file mode 100644 index 00000000..65a41276 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewBean.java @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2017, 2018 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.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.cache.Cache; +import javax.ejb.EJB; +import javax.enterprise.event.Observes; +import javax.faces.view.ViewScoped; +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.exceptions.receipt.ReceiptNotFoundException; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; +import org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote; + +/** + * A view-scoped bean for receipt lists + *

+ * @author Roland Haeder + */ +@Named ("receiptListController") +@ViewScoped +public class FinancialsReceiptListWebViewBean extends BaseFinancialsBean implements FinancialsReceiptListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 34_869_872_672_653L; + + /** + * All receipts list + */ + private final List allReceipts; + + /** + * Filtered receipts list + */ + private List filteredReceipts; + + /** + * EJB for general financial receipt purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/financialReceipt!org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote") + private FinancialReceiptSessionBeanRemote receiptBean; + + /** + * A list of all branch offices (globally) + */ + @Inject + @NamedCache (cacheName = "receiptCache") + private transient Cache receiptCache; + + /** + * Selected receipt + */ + private BillableReceipt selectedReceipt; + + /** + * Default constructor + */ + public FinancialsReceiptListWebViewBean () { + // Call super constructor + super(); + + // Init lists + this.allReceipts = new LinkedList<>(); + } + + /** + * 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.getAllReceipts().add(event.getReceipt()); + } + + @Override + public BillableReceipt findReceiptById (final Long receiptId) throws ReceiptNotFoundException { + // Validate parameter + if (null == receiptId) { + // Throw NPE + throw new NullPointerException("receiptId is null"); //NOI18N + } else if (receiptId < 1) { + // Throw IAE + throw new IllegalArgumentException("receiptId=" + receiptId + " is invalid."); //NOI18N + } else if (!this.receiptCache.containsKey(receiptId)) { + // Not found + throw new ReceiptNotFoundException(receiptId); + } + + // Get it from cache + final BillableReceipt receipt = this.receiptCache.get(receiptId); + + // Return it + return receipt; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllReceipts () { + 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 selected receipt + *

+ * @return Selected receipt + */ + public BillableReceipt getSelectedReceipt () { + return this.selectedReceipt; + } + + /** + * Setter for selected receipt + *

+ * @param selectedReceipt Selected receipt + */ + public void setSelectedReceipt (final BillableReceipt selectedReceipt) { + this.selectedReceipt = selectedReceipt; + } + + @PostConstruct + public void initCache () { + // Is cache there? + if (!this.receiptCache.iterator().hasNext()) { + // Get whole list + final List receipts = this.receiptBean.allReceipts(); + + // Add all + for (final BillableReceipt receipt : receipts) { + // Add it to cache + this.receiptCache.put(receipt.getReceiptId(), receipt); + } + } + + // Is the list empty, but filled cache? + if (this.getAllReceipts().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.getAllReceipts().add(next.getValue()); + } + + // Sort list + this.getAllReceipts().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.getAllReceipts().contains(receipt); + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewController.java new file mode 100644 index 00000000..aed38e96 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/list/FinancialsReceiptListWebViewController.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2018 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.list; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; + +/** + * An interface of receipt list backing beans + *

+ * @author Roland Häder + */ +public interface FinancialsReceiptListWebViewController extends Serializable { + + /** + * Returns a receipt instance (entity) for given primary key. If not found, + * a proper exception is thrown. + *

+ * @param receiptId Receipt id (primary key) + *

+ * @return Receipt entity matching to primary key + *

+ * @throws ReceiptNotFoundException If a receipt with given primary key + * could not be found + */ + BillableReceipt findReceiptById (final Long receiptId) throws ReceiptNotFoundException; + + /** + * 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); + + /** + * Returns all receipts + *

+ * @return All receipts + */ + public List getAllReceipts (); + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionBean.java new file mode 100644 index 00000000..a0a00b1d --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionBean.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2017, 2018 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.user; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import javax.enterprise.context.SessionScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.financial.model.receipt.list.FinancialsReceiptListWebViewController; +import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; +import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; +import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; + +/** + * A view-scoped bean for receipt lists + *

+ * @author Roland Haeder + */ +@Named ("userReceiptController") +@SessionScoped +public class FinancialsReceiptUserWebSessionBean extends BaseFinancialsBean implements FinancialsReceiptUserWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 34_869_872_672_654L; + + /** + * Receipt list controller + */ + @Inject + private FinancialsReceiptListWebViewController receiptListController; + + /** + * User instance + */ + @Inject + private FinancialsUserLoginWebSessionController userLoginController; + + /** + * User's receipts + */ + private final List userReceipts; + + /** + * Default constructor + */ + public FinancialsReceiptUserWebSessionBean () { + // Call super constructor + super(); + + // Init lists + this.userReceipts = new LinkedList<>(); + } + + /** + * 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 + } + + // Is same user? + if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { + // Same user, then add it + this.getUserReceipts().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.receiptListController.getAllReceipts()) { + // Is same user? + if (Objects.equals(receipt.getReceiptUser(), event.getLoggedInUser())) { + // Yes, then add it + this.getUserReceipts().add(receipt); + } + } + } + + /** + * Getter for user's receipts + *

+ * @return User's receipts + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getUserReceipts () { + return this.userReceipts; + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionController.java new file mode 100644 index 00000000..6c01e060 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/user/FinancialsReceiptUserWebSessionController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018 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.user; + +import java.io.Serializable; + +/** + * An interface of user's receipt backing beans + *

+ * @author Roland Häder + */ +public interface FinancialsReceiptUserWebSessionController extends Serializable { + +} diff --git a/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java b/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java index 08a3c41d..8a144c40 100644 --- a/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java @@ -22,8 +22,8 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; -import org.mxchange.jfinancials.beans.financial.model.receipt.FinancialsReceiptWebRequestBean; -import org.mxchange.jfinancials.beans.financial.model.receipt.FinancialsReceiptWebRequestController; +import org.mxchange.jfinancials.beans.financial.model.receipt.list.FinancialsReceiptListWebViewBean; +import org.mxchange.jfinancials.beans.financial.model.receipt.list.FinancialsReceiptListWebViewController; import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; import org.mxchange.jfinancials.model.receipt.BillableReceipt; @@ -38,14 +38,14 @@ public class FinancialsReceiptConverter implements Converter { /** * Receipt backing bean */ - private static FinancialsReceiptWebRequestController RECEIPT_CONTROLLER; + private static FinancialsReceiptListWebViewController RECEIPT_LIST_CONTROLLER; @Override public BillableReceipt getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { // Is the instance there? - if (null == RECEIPT_CONTROLLER) { + if (null == RECEIPT_LIST_CONTROLLER) { // Get bean from CDI directly - RECEIPT_CONTROLLER = CDI.current().select(FinancialsReceiptWebRequestBean.class).get(); + RECEIPT_LIST_CONTROLLER = CDI.current().select(FinancialsReceiptListWebViewBean.class).get(); } // Is the value null or empty? @@ -65,7 +65,7 @@ public class FinancialsReceiptConverter implements Converter { final Long receiptId = Long.valueOf(submittedValue); // Try to get user instance from it - receipt = RECEIPT_CONTROLLER.findReceiptById(receiptId); + receipt = RECEIPT_LIST_CONTROLLER.findReceiptById(receiptId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/localization/project_de_DE.properties b/src/java/org/mxchange/localization/project_de_DE.properties index bdd82382..c74c277b 100644 --- a/src/java/org/mxchange/localization/project_de_DE.properties +++ b/src/java/org/mxchange/localization/project_de_DE.properties @@ -51,7 +51,6 @@ ADMIN_RECEIPT_ISSUE_DATE_REQUIRED=Bitte geben Sie das Ausstellungsdatum des Kass ADMIN_MENU_RECEIPTS_TITLE=Kassenbons & Eintraege ADMIN_LINK_LIST_RECEIPTS_TITLE=Listet alle registrierten Kassenbons/Rechnungen auf.. ADMIN_LINK_LIST_RECEIPTS=Kassenbons/Rechnungen auflisten -ADMIN_LIST_RECEIPTS_HEADER=Alle Kassenbons/Rechnungen auflisten ADMIN_RECEIPT_BASIC_LEGEND=Grunddaten des Kassenbons ADMIN_RECEIPT_BASIC_LEGEND_TITLE=Bitte geben Sie hier die Grunddaten des neuen Kassenbons ein. ENTER_RECEIPT_ISSUE_DATE=Ausstellungsdatum des Kassenbons eingeben: @@ -303,3 +302,26 @@ CATEGORY_SHOW_IN_STATISTICS_TITLE=Ob diese Kategorie in Statistiken vorkommt. CATEGORY_PARENT_HEADER=Elternkategorie: CATEGORY_PARENT_TITLE=Elternkategorie dieser Kategorie. CATEGORY_HAS_NO_PARENT=Diese Kategorie hat keine Elternkategorie. +ADMIN_SINGLE_RECEIPT_DETAILS_HEADER=Details zum einzelnen Kassenbon +ADMIN_RECEIPT_DETAILS_HEADER=Details zur Kassenbon-Id {0}: +#@TODO Please fix German umlauts! +ADMIN_LINK_SHOW_RECEIPT_SELLER_EMPLOYEE_TITLE=Zeigt zugewiesenen Verkaeufer des Kassenbons an. +#@TODO Please fix German umlauts! +ADMIN_LINK_ASSIGN_RECEIPT_SELLER_EMPLOYEE_TITLE=Verkaeufer dem Kassenbon zuweisen. +ADMIN_LINK_ASSIGN_RECEIPT_OWNER_USER_TITLE=Besitzenden Benutzer dem Kassenbon zuweisen. +RECEIPT_NUMBER_TITLE=Nummer des Kassenbons. +RECEIPT_ISSUED_TITLE=Wann dieser Kassenbon ausgestellt wurde. +ASSIGNED_RECEIPT_BRANCH_OFFICE_TITLE=Zugewiesene Filiale zum Kassenbons: +SELLER_HEADER=Verkaeufer: +#@TODO Please fix German umlauts! +ASSIGNED_RECEIPT_SELLER_TITLE=Zugewiesener Verkaeufer zum Kassenbon: +#@TODO Please fix German umlauts! +NO_SELLER_ASSIGNED_TO_RECEIPT=Kein Verkaeufer dem Kassenbon zugewiesen. +ASSIGNED_RECEIPT_USER_TITLE=Zugewiesener Benutzer zum Kassenbon. +NO_USER_ASSIGNED_TO_RECEIPT=Kein Benutzer dem Kassenbon zugewiesen. +RECEIPT_ID_NUMBER_TITLE=Id-Nummer des Kassenbonus. +RECEIPT_BARCODE_HEADER=Streifencode: +RECEIPT_BARCODE_TITLE=Streifencode des Kassenbons. +RECEIPT_SEQUENCE_NUMBER_HEADER=Durchlaufende Nummer: +RECEIPT_SEQUENCE_NUMBER_TITLE=Durchlaufende Nummer des Kassenbons. +RECEIPT_PAYMENT_TYPE_TITLE=Bezahlungsart des Kassenbons. diff --git a/src/java/org/mxchange/localization/project_en_US.properties b/src/java/org/mxchange/localization/project_en_US.properties index 9c7b9ae1..964894de 100644 --- a/src/java/org/mxchange/localization/project_en_US.properties +++ b/src/java/org/mxchange/localization/project_en_US.properties @@ -38,7 +38,6 @@ ADMIN_RECEIPT_ISSUE_DATE_REQUIRED=Please enter date of issue of receipt. ADMIN_MENU_RECEIPTS_TITLE=Receipts & Items ADMIN_LINK_LIST_RECEIPTS_TITLE=Lists all registered receipts. ADMIN_LINK_LIST_RECEIPTS=Receipts -ADMIN_LIST_RECEIPTS_HEADER=List all receipts ADMIN_RECEIPT_BASIC_LEGEND=Basic data of receipt: ADMIN_RECEIPT_BASIC_LEGEND_TITLE=Please enter here basic data of the new receipt. ENTER_RECEIPT_ISSUE_DATE=Enter date of issue of receipt: @@ -221,3 +220,22 @@ CATEGORY_SHOW_IN_STATISTICS_TITLE=Whether this category is shown in statistics. CATEGORY_PARENT_HEADER=Parent category: CATEGORY_PARENT_TITLE=Parent category of this category. CATEGORY_HAS_NO_PARENT=This category has no parent category. +ADMIN_SINGLE_RECEIPT_DETAILS_HEADER=Details of a single receipt +ADMIN_RECEIPT_DETAILS_HEADER=Details of receipt id {0}: +ADMIN_LINK_SHOW_RECEIPT_SELLER_EMPLOYEE_TITLE=Shows assigned seller employee of receipt. +ADMIN_LINK_ASSIGN_RECEIPT_SELLER_EMPLOYEE_TITLE=Assign seller to receipt. +ADMIN_LINK_ASSIGN_RECEIPT_OWNER_USER_TITLE=Assign owning user to receipt. +RECEIPT_NUMBER_TITLE=Number of receipt. +RECEIPT_ISSUED_TITLE=When this receipt has been issued. +ASSIGNED_RECEIPT_BRANCH_OFFICE_TITLE=Assigned branch office of receipt: +SELLER_HEADER=Seller: +ASSIGNED_RECEIPT_SELLER_TITLE=Assigned seller of receipt: +NO_SELLER_ASSIGNED_TO_RECEIPT=No seller assigned to receipt. +ASSIGNED_RECEIPT_USER_TITLE=Assigned user of receipt. +NO_USER_ASSIGNED_TO_RECEIPT=No user assigned to receipt. +RECEIPT_ID_NUMBER_TITLE=Id number of receipt. +RECEIPT_BARCODE_HEADER=Barcode: +RECEIPT_BARCODE_TITLE=Barcode of receipt. +RECEIPT_SEQUENCE_NUMBER_HEADER=Sequence number: +RECEIPT_SEQUENCE_NUMBER_TITLE=Sequence number of receipt. +RECEIPT_PAYMENT_TYPE_TITLE=Payment type of receipt. diff --git a/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl b/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl index 718bf5d0..598c637e 100644 --- a/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl +++ b/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl @@ -108,7 +108,7 @@ > - + diff --git a/web/admin/financial/receipt/admin_receipt_list.xhtml b/web/admin/financial/receipt/admin_receipt_list.xhtml index 19e65f7b..f3ba86d7 100644 --- a/web/admin/financial/receipt/admin_receipt_list.xhtml +++ b/web/admin/financial/receipt/admin_receipt_list.xhtml @@ -18,16 +18,17 @@ - + + - - + + - + + + + + + + - - + + + + @@ -64,7 +81,6 @@ title="#{msg.FILTER_BY_MULTIPLE_BRANCH_OFFICES_TITLE}" > - @@ -90,11 +106,11 @@ - + - + @@ -115,11 +131,11 @@ - + - + @@ -130,19 +146,18 @@ - + - - - + @@ -152,6 +167,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -176,7 +250,7 @@ type="submit" value="#{project.BUTTON_ADMIN_ADD_RECEIPT}" action="#{adminReceiptController.addReceipt()}" - update=":master:form-list-financial-receipt:receiptList" + update=":master:form-list-financial-receipts:receiptList" /> 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 5fc51f11..1f94db7f 100644 --- a/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml +++ b/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml @@ -66,8 +66,7 @@ title="#{project.FILTER_BY_MULTIPLE_RECEIPTS_TITLE}" > - - + @@ -87,7 +86,6 @@ title="#{project.FILTER_BY_MULTIPLE_ITEM_PRODUCTS_TITLE}" > - diff --git a/web/user/financials/login_financials_add_income.xhtml b/web/user/financials/login_financials_add_income.xhtml index ef54df58..fde9c1f5 100644 --- a/web/user/financials/login_financials_add_income.xhtml +++ b/web/user/financials/login_financials_add_income.xhtml @@ -47,7 +47,6 @@ required="true" requiredMessage="#{project.FIELD_FINANCIAL_INCOME_REQUIRED}" > - -- 2.39.5