/**
* Adds income data by calling proper business method of the EJB.
- * <p>
- * @return Redirect outcome
*/
- public String addIncome () {
+ public void addIncome () {
// Is all data valid?
if (!this.userLoginController.isUserLoggedIn()) {
// Not logged-in
// Handle it over to the EJB
// @TODO Use updated income instance, e.g. fire event
final BillableIncome updatedIncome = this.financialBean.addIncome(income);
-
- // All fine
- return "add_user_fiancial_income"; //NOI18N
}
/**
* 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>
- * @return Link outcome
*/
- public String addReceipt () {
+ public void addReceipt () {
// Are all required fields set?
if (this.getReceiptBranchOffice() == null) {
// Is not set
// Clear bean
this.clear();
-
- // Return redirect outcome
- return ""; //NOI18N
}
/**
* 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>
- * @return Link outcome
*/
- public String addReceipt () {
+ public void addReceipt () {
// Are all required fields set?
if (!this.userLoginController.isUserLoggedIn()) {
// Not logged-in
// Clear bean
this.clear();
-
- // Return redirect outcome
- return "admin_list_receipts?faces-redirect=true"; //NOI18N
}
/**
import javax.inject.Named;
import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
import org.mxchange.jfinancials.beans.BaseFinancialsBean;
+import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController;
import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent;
import org.mxchange.jfinancials.events.receipt_item.added.ReceiptItemAddedEvent;
import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedException;
private BigDecimal productTaxRate;
/**
- * General receipt item controller
+ * Receipt item list controller
*/
@Inject
- private FinancialsReceiptItemWebRequestController receiptItemController;
+ private FinancialsReceiptItemListWebViewController receiptItemListController;
/**
* Default constructor
* method. If not all required fields are set, a proper exception is being
* thrown.
* <p>
- * @return Link outcome
*/
- public String addReceiptItem () {
+ public void addReceiptItem () {
// Are all required fields set?
// Prepare receipt item instance
final BillableReceiptItem receiptItem = this.createReceiptItemInstance();
// Is the receipt already there?
- if (this.receiptItemController.isReceiptItemAdded(receiptItem)) {
+ if (this.receiptItemListController.isReceiptItemAdded(receiptItem)) {
// Receipt has already been added
throw new FaceletException(MessageFormat.format("Receipt for itemReceipt.receiptId={0},itemProduct.productId={1},itemProductQuantity={2} has already been added.", receiptItem.getItemReceipt().getReceiptId(), receiptItem.getItemProduct().getProductId(), receiptItem.getItemProductQuantity())); //NOI18N
}
// Clear bean
this.clear();
-
- // Return redirect outcome
- return ""; //NOI18N
}
/**
*/
package org.mxchange.jfinancials.beans.financial.model.receipt_item;
-import fish.payara.cdi.jsr107.impl.NamedCache;
import java.text.MessageFormat;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-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.jfinancials.beans.BaseFinancialsBean;
+import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController;
import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController;
import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent;
import org.mxchange.jfinancials.events.receipt_item.added.ReceiptItemAddedEvent;
import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem;
import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItem;
import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote;
-import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
/**
* A general financial receipt item bean (controller)
@Any
private Event<ObservableReceiptItemAddedEvent> addedReceiptItemEvent;
- /**
- * All receipt items list
- */
- private final List<BillableReceiptItem> allReceiptItems;
-
- /**
- * Filtered receipt items list
- */
- private List<BillableReceiptItem> filteredReceiptItems;
-
/**
* EJB for general financial receipt purposes
*/
private FinancialReceiptItemSessionBeanRemote receiptItemBean;
/**
- * A list of all branch offices (globally)
+ * Receipt item list controller
*/
@Inject
- @NamedCache (cacheName = "receiptItemCache")
- private Cache<Long, BillableReceiptItem> receiptItemCache;
+ private FinancialsReceiptItemListWebViewController receiptItemListController;
/**
* User instance
@Inject
private FinancialsUserLoginWebSessionController userLoginController;
- /**
- * User's receipt items
- */
- private final List<BillableReceiptItem> userReceiptItems;
-
/**
* Constructor
*/
public FinancialsReceiptItemWebRequestBean () {
// Call super constructor
super();
-
- // Init lists
- this.allReceiptItems = new LinkedList<>();
- this.userReceiptItems = new LinkedList<>();
}
/**
- * Adds the completed receipt item to database by calling an EJB business method.
- * If not all required fields are set, a proper exception is being thrown.
+ * Adds the completed receipt item to database by calling an EJB business
+ * method. If not all required fields are set, a proper exception is being
+ * thrown.
* <p>
- * @return Link outcome
*/
- public String addReceiptItem () {
+ public void addReceiptItem () {
// Are all required fields set?
if (!this.userLoginController.isUserLoggedIn()) {
// Not logged-in
final BillableReceiptItem receiptItem = this.createReceiptInstance();
// Is the receipt already there?
- if (this.isReceiptItemAdded(receiptItem)) {
+ if (this.receiptItemListController.isReceiptItemAdded(receiptItem)) {
// Receipt has already been added
throw new FaceletException(MessageFormat.format("Receipt for itemReceipt.receiptId={0},itemProduct.productId={1},itemProductQuantity={2} has already been added.", receiptItem.getItemReceipt().getReceiptId(), receiptItem.getItemProduct().getProductId(), receiptItem.getItemProductQuantity())); //NOI18N
}
// Clear bean
this.clear();
-
- // Return redirect outcome
- return "admin_list_receipt_items?faces-redirect=true"; //NOI18N
- }
-
- /**
- * Observes events being fired when a new receipt item has been added
- * <p>
- * @param event Event being fired
- */
- public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) {
- // Validate parameter
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- }
-
- // Add to cache and general list
- this.receiptItemCache.put(event.getReceiptItem().getItemId(), event.getReceiptItem());
- this.allReceiptItems.add(event.getReceiptItem());
-
- // Is same user?
- if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) {
- // Same user, then add it
- this.userReceiptItems.add(event.getReceiptItem());
- }
- }
-
- /**
- * Event observer for logged-in user
- * <p>
- * @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 BillableReceiptItem receiptItem : this.allReceiptItems) {
- // Is same user?
- if (Objects.equals(receiptItem.getItemReceipt().getReceiptUser(), event.getLoggedInUser())) {
- // Yes, then add it
- this.userReceiptItems.add(receiptItem);
- }
- }
- }
-
- /**
- * Returns all receipt items
- * <p>
- * @return All receipt items
- */
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<BillableReceiptItem> allReceiptItems () {
- return this.allReceiptItems;
- }
-
- /**
- * Getter for filtered receipt items
- * <p>
- * @return Filtered receipts
- */
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<BillableReceiptItem> getFilteredReceiptItems () {
- return this.filteredReceiptItems;
- }
-
- /**
- * Setter for filtered receipt items
- * <p>
- * @param filteredReceiptItems Filtered receipt items
- */
- @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
- public void setFilteredReceiptItems (final List<BillableReceiptItem> filteredReceiptItems) {
- this.filteredReceiptItems = filteredReceiptItems;
- }
-
- @PostConstruct
- public void initCache () {
- // Is cache there?
- if (!this.receiptItemCache.iterator().hasNext()) {
- // Get whole list
- final List<BillableReceiptItem> receiptItems = this.receiptItemBean.allReceiptItems();
-
- // Add all
- for (final BillableReceiptItem receiptItem : receiptItems) {
- // Add it to cache
- this.receiptItemCache.put(receiptItem.getItemId(), receiptItem);
- }
- }
-
- // Is the list empty, but filled cache?
- if (this.allReceiptItems.isEmpty() && this.receiptItemCache.iterator().hasNext()) {
- // Get iterator
- final Iterator<Cache.Entry<Long, BillableReceiptItem>> iterator = this.receiptItemCache.iterator();
-
- // Build up list
- while (iterator.hasNext()) {
- // GEt next element
- final Cache.Entry<Long, BillableReceiptItem> next = iterator.next();
-
- // Add to list
- this.allReceiptItems.add(next.getValue());
- }
-
- // Sort list
- this.allReceiptItems.sort(new Comparator<BillableReceiptItem>() {
- @Override
- public int compare (final BillableReceiptItem o1, final BillableReceiptItem o2) {
- return o1.getItemId() > o2.getItemId() ? 1 : o1.getItemId() < o2.getItemId() ? -1 : 0;
- }
- }
- );
- }
- }
-
- @Override
- public boolean isReceiptItemAdded (final BillableReceiptItem receiptItem) {
- // Always trust the cache
- return this.allReceiptItems.contains(receiptItem);
}
/**
}
/**
- * Returns a fully created receipt item instance (except primary key, of course)
+ * Returns a fully created receipt item instance (except primary key, of
+ * course)
* <p>
* @return Receipt item instance
*/
final BillableReceiptItem receiptItem = new FinancialReceiptItem();
// Set optional fields
-
// Return it
return receiptItem;
}
+
}
package org.mxchange.jfinancials.beans.financial.model.receipt_item;
import java.io.Serializable;
-import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem;
/**
* An administrative interface for financial receipt item beans
*/
public interface FinancialsReceiptItemWebRequestController extends Serializable {
- /**
- * Checks if receipt item has already been added to database
- * <p>
- * @param receiptItem Prepared receipt item instance
- * <p>
- * @return Whether the receipt item has already been added
- */
- boolean isReceiptItemAdded (final BillableReceiptItem receiptItem);
-
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.financial.model.receipt_item.list;
+
+import fish.payara.cdi.jsr107.impl.NamedCache;
+import java.text.MessageFormat;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+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.beans.user.login.FinancialsUserLoginWebSessionController;
+import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent;
+import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem;
+import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote;
+import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
+
+/**
+ * A list financial receipt item bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("receiptItemListController")
+@ViewScoped
+public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean implements FinancialsReceiptItemListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 56_189_028_928_472L;
+
+ /**
+ * All receipt items list
+ */
+ private final List<BillableReceiptItem> allReceiptItems;
+
+ /**
+ * Filtered receipt items list
+ */
+ private List<BillableReceiptItem> filteredReceiptItems;
+
+ /**
+ * EJB for general financial receipt purposes
+ */
+ @EJB (lookup = "java:global/jfinancials-ejb/financialReceiptItem!org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote")
+ private FinancialReceiptItemSessionBeanRemote receiptItemBean;
+
+ /**
+ * A list of all branch offices (globally)
+ */
+ @Inject
+ @NamedCache (cacheName = "receiptItemCache")
+ private transient Cache<Long, BillableReceiptItem> receiptItemCache;
+
+ /**
+ * Selected receipt item
+ */
+ private BillableReceiptItem selectedReceiptItem;
+
+ /**
+ * User instance
+ */
+ @Inject
+ private FinancialsUserLoginWebSessionController userLoginController;
+
+ /**
+ * User's receipt items
+ */
+ private final List<BillableReceiptItem> userReceiptItems;
+
+ /**
+ * Constructor
+ */
+ @SuppressWarnings ("CollectionWithoutInitialCapacity")
+ public FinancialsReceiptItemListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init lists
+ this.allReceiptItems = new LinkedList<>();
+ this.userReceiptItems = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when a new receipt item has been added
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ }
+
+ // Add to cache and general list
+ this.receiptItemCache.put(event.getReceiptItem().getItemId(), event.getReceiptItem());
+ this.getAllReceiptItems().add(event.getReceiptItem());
+
+ // Is same user?
+ if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) {
+ // Same user, then add it
+ this.userReceiptItems.add(event.getReceiptItem());
+ }
+ }
+
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @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 BillableReceiptItem receiptItem : this.allReceiptItems) {
+ // Is same user?
+ if (Objects.equals(receiptItem.getItemReceipt().getReceiptUser(), event.getLoggedInUser())) {
+ // Yes, then add it
+ this.userReceiptItems.add(receiptItem);
+ }
+ }
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<BillableReceiptItem> getAllReceiptItems () {
+ return this.allReceiptItems;
+ }
+
+ /**
+ * Getter for filtered receipt items
+ * <p>
+ * @return Filtered receipts
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<BillableReceiptItem> getFilteredReceiptItems () {
+ return this.filteredReceiptItems;
+ }
+
+ /**
+ * Setter for filtered receipt items
+ * <p>
+ * @param filteredReceiptItems Filtered receipt items
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredReceiptItems (final List<BillableReceiptItem> filteredReceiptItems) {
+ this.filteredReceiptItems = filteredReceiptItems;
+ }
+
+ /**
+ * Getter for selected receipt item
+ * <p>
+ * @return Selected receipt item
+ */
+ public BillableReceiptItem getSelectedReceiptItem () {
+ return this.selectedReceiptItem;
+ }
+
+ /**
+ * Setter for selected receipt item
+ * <p>
+ * @param selectedReceiptItem Selected receipt item
+ */
+ public void setSelectedReceiptItem (final BillableReceiptItem selectedReceiptItem) {
+ this.selectedReceiptItem = selectedReceiptItem;
+ }
+
+ @PostConstruct
+ public void initCache () {
+ // Is cache there?
+ if (!this.receiptItemCache.iterator().hasNext()) {
+ // Get whole list
+ final List<BillableReceiptItem> receiptItems = this.receiptItemBean.allReceiptItems();
+
+ // Add all
+ for (final BillableReceiptItem receiptItem : receiptItems) {
+ // Add it to cache
+ this.receiptItemCache.put(receiptItem.getItemId(), receiptItem);
+ }
+ }
+
+ // Is the list empty, but filled cache?
+ if (this.getAllReceiptItems().isEmpty() && this.receiptItemCache.iterator().hasNext()) {
+ // Get iterator
+ final Iterator<Cache.Entry<Long, BillableReceiptItem>> iterator = this.receiptItemCache.iterator();
+
+ // Build up list
+ while (iterator.hasNext()) {
+ // GEt next element
+ final Cache.Entry<Long, BillableReceiptItem> next = iterator.next();
+
+ // Add to list
+ this.getAllReceiptItems().add(next.getValue());
+ }
+
+ // Sort list
+ this.getAllReceiptItems().sort(new Comparator<BillableReceiptItem>() {
+ @Override
+ public int compare (final BillableReceiptItem o1, final BillableReceiptItem o2) {
+ return o1.getItemId() > o2.getItemId() ? 1 : o1.getItemId() < o2.getItemId() ? -1 : 0;
+ }
+ }
+ );
+ }
+ }
+
+ @Override
+ public boolean isReceiptItemAdded (final BillableReceiptItem receiptItem) {
+ // Always trust the cache
+ return this.getAllReceiptItems().contains(receiptItem);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.financial.model.receipt_item.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem;
+
+/**
+ * An administrative interface for financial receipt item list beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialsReceiptItemListWebViewController extends Serializable {
+
+ /**
+ * Checks if receipt item has already been added to database
+ * <p>
+ * @param receiptItem Prepared receipt item instance
+ * <p>
+ * @return Whether the receipt item has already been added
+ */
+ boolean isReceiptItemAdded (final BillableReceiptItem receiptItem);
+
+ /**
+ * Returns all receipt items
+ * <p>
+ * @return All receipt items
+ */
+ List<BillableReceiptItem> getAllReceiptItems ();
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.financial.model.receipt_item.user;
+
+import java.text.MessageFormat;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+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.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController;
+import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController;
+import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent;
+import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem;
+import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
+
+/**
+ * A list financial receipt item bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("receiptItemUserController")
+@ViewScoped
+public class FinancialsReceiptItemUserWebSessionBean extends BaseFinancialsBean implements FinancialsReceiptItemUserWebSessionController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 56_189_028_928_572L;
+
+ /**
+ * Receipt item list controller
+ */
+ @Inject
+ private FinancialsReceiptItemListWebViewController receiptItemListController;
+
+ /**
+ * User instance
+ */
+ @Inject
+ private FinancialsUserLoginWebSessionController userLoginController;
+
+ /**
+ * User's receipt items
+ */
+ private final List<BillableReceiptItem> userReceiptItems;
+
+ /**
+ * Constructor
+ */
+ @SuppressWarnings ("CollectionWithoutInitialCapacity")
+ public FinancialsReceiptItemUserWebSessionBean () {
+ // Call super constructor
+ super();
+
+ // Init lists
+ this.userReceiptItems = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when a new receipt item has been added
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ }
+
+ // Is same user?
+ if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) {
+ // Same user, then add it
+ this.userReceiptItems.add(event.getReceiptItem());
+ }
+ }
+
+ /**
+ * Event observer for logged-in user
+ * <p>
+ * @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 BillableReceiptItem receiptItem : this.receiptItemListController.getAllReceiptItems()) {
+ // Is same user?
+ if (Objects.equals(receiptItem.getItemReceipt().getReceiptUser(), event.getLoggedInUser())) {
+ // Yes, then add it
+ this.userReceiptItems.add(receiptItem);
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.financial.model.receipt_item.user;
+
+import java.io.Serializable;
+
+/**
+ * An administrative interface for financial receipt item user beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialsReceiptItemUserWebSessionController extends Serializable {
+
+}
TABLE_SUMMARY_ADMIN_LIST_RECEIPT_ITEMS=Diese Tabelle listet alle eingetragenen Artikel auf.
#@TODO Please fix German umlauts!
ADMIN_EMPTY_LIST_RECEIPT_ITEM=Es befinden sich keine Artikel in der Datenbank. Oder Ihre Suche ergab keine Uebereinstimmungen.
-ADMIN_LIST_RECEIPT_ITEMS_HEADER=Alle Artikel auflisten
ADMIN_ASSIGNED_ITEM_RECEIPT=Zugewiesener Kassenbon:
ADMIN_ASSIGNED_ITEM_PRODUCT=Zugewiesenes Produkt:
#@TODO Please fix German umlauts!
RECEIPT_SEQUENCE_NUMBER_HEADER=Durchlaufende Nummer:
RECEIPT_SEQUENCE_NUMBER_TITLE=Durchlaufende Nummer des Kassenbons.
RECEIPT_PAYMENT_TYPE_TITLE=Bezahlungsart des Kassenbons.
+PAGE_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Produkt anzeigen
+CONTENT_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Produkt anzeigen:
+PAGE_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Produkt editieren
+CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Produkt editieren:
+#@TODO Please fix German umlauts!
+PAGE_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Produkt loeschen
+#@TODO Please fix German umlauts!
+CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Produkt loeschen:
+ERROR_PARAMETER_PRODUCT_ID_NOT_SET=Fehler: Produkt-Id nicht gesetzt (Parameter: productId).
+#@TODO Please fix German umlauts!
+PARAMETER_PRODUCT_ID_INVALID=Parameter "productId" ist ungueltig.
CONTENT_TITLE_ADMIN_FINANCIALS_RECEIPT_ITEM_LIST=List receipt items:
TABLE_SUMMARY_ADMIN_LIST_RECEIPT_ITEMS=This table lists all registered receipt items.
ADMIN_EMPTY_LIST_RECEIPT_ITEM=There are no receipt items in database. Or your search criteria doesn't match anything.
-ADMIN_LIST_RECEIPT_ITEMS_HEADER=List all receipt items
ADMIN_ASSIGNED_ITEM_RECEIPT=Assigned item's receipt:
ADMIN_ASSIGNED_ITEM_PRODUCT=Assigned product:
ADMIN_ADD_RECEIPT_ITEM_TITLE=Add new receipt item
RECEIPT_SEQUENCE_NUMBER_HEADER=Sequence number:
RECEIPT_SEQUENCE_NUMBER_TITLE=Sequence number of receipt.
RECEIPT_PAYMENT_TYPE_TITLE=Payment type of receipt.
+PAGE_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Show product
+CONTENT_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Show product:
+PAGE_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Edit product
+CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Edit product:
+PAGE_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Delete product
+CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Delete product:
+ERROR_PARAMETER_PRODUCT_ID_NOT_SET=Error: Product Id is not set (parameter: productId).
+PARAMETER_PRODUCT_ID_INVALID=Parameter "productId" is invalid.
>
<f:converter converterId="GenericProductConverter" />
<f:selectItem itemValue="#{null}" itemLabel="#{msg.PLEASE_SELECT}" noSelectionOption="true" itemDisabled="true" />
- <f:selectItems value="#{productListController.allProducts}" var="product" itemValue="#{product}" itemLabel="#{beanHelper.renderGenericProduct(product)}" />
+ <f:selectItems value="#{productListController.allProducts}" var="product" itemValue="#{product}" itemLabel="#{productBeanHelper.renderGenericProduct(product)}" />
</p:selectOneMenu>
<p:outputLabel for="itemManufacturer" value="#{project.SELECT_RECEIPT_ITEM_MANUFACTURER}" />
</p:dialog>
</h:form>
- <h:form>
+ <h:form id="form-add-receipt">
<p:panelGrid layout="grid" columns="1" styleClass="table table-full">
<h:panelGroup styleClass="table-header" layout="block">
<h4>
</ui:define>
<ui:define name="content">
- <h:form id="form-list-financial-receipt-item">
+ <h:form id="form-list-financial-receipt-items">
<p:dataTable
id="receiptItemList"
var="receiptItem"
- value="#{receiptItemController.allReceiptItems()}"
- filteredValue="#{receiptItemController.filteredReceiptItems}"
+ value="#{receiptItemListController.allReceiptItems}"
tableStyleClass="table table-full"
- rows="10"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
+ filteredValue="#{receiptItemListController.filteredReceiptItems}"
+ rows="10"
+ rowKey="#{receiptItem.itemId}"
reflow="true"
resizableColumns="true"
rowsPerPageTemplate="5,10,20,50,100"
summary="#{project.TABLE_SUMMARY_ADMIN_LIST_RECEIPT_ITEMS}"
emptyMessage="#{project.ADMIN_EMPTY_LIST_RECEIPT_ITEM}"
widgetVar="receiptItemList"
+ selectionMode="single"
+ selection="#{receiptItemListController.selectedReceiptItem}"
+ skipChildren="true"
>
<f:facet name="header">
- <p:panelGrid columns="2" columnClasses="ui-grid-col-10,ui-grid-col-2" layout="grid" styleClass="ui-noborder ui-transparent-widget">
- <h:outputText value="#{project.ADMIN_LIST_RECEIPT_ITEMS_HEADER}" />
+ <p:panelGrid columns="3" layout="grid" columnClasses="ui-grid-col-4,ui-grid-col-6,ui-grid-col-2">
+ <p:spacer />
- <h:panelGroup>
+ <p:panelGrid columns="2" columnClasses="ui-grid-4,ui-grid-8" layout="grid" styleClass="table table-full 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:panelGrid>
+
+ <p:outputPanel>
+ <p:spacer height="4" />
<p:commandButton id="toggler" type="button" value="#{msg.SELECT_SHOWN_COLUMNS}" styleClass="column-selector" />
<p:columnToggler datasource="receiptItemList" trigger="toggler" />
- </h:panelGroup>
- </p:panelGrid >
+ </p:outputPanel>
+ </p:panelGrid>
</f:facet>
+ <p:ajax
+ event="rowSelect"
+ update=":master:form-list-financial-receipt-items:receipt-item-details"
+ oncomplete="PF('receiptItemDialog').show()"
+ />
+
<p:column headerText="#{msg.ID_NUMBER_HEADER}" sortBy="#{receiptItem.itemId}" filterBy="#{receiptItem.itemId}">
<p:link outcome="admin_show_receipt_item" title="#{project.ADMIN_LINK_SHOW_RECEIPT_ITEM_TITLE}" value="#{receiptItem.itemId}">
<f:param name="receiptId" value="#{receiptItem.itemId}" />
title="#{project.FILTER_BY_MULTIPLE_ITEM_PRODUCTS_TITLE}"
>
<f:converter converterId="GenericProductConverter" />
- <f:selectItems value="#{productListController.allProducts}" var="product" itemValue="#{product}" itemLabel="#{beanHelper.renderGenericProduct(product)}" />
+ <f:selectItems value="#{productListController.allProducts}" var="product" itemValue="#{product}" itemLabel="#{productBeanHelper.renderGenericProduct(product)}" />
</p:selectCheckboxMenu>
</f:facet>
- <p:link outcome="admin_show_generic_product" title="#{project.ADMIN_LINK_SHOW_RECEIPT_ITEM_PRODUCT_TITLE}" value="#{beanHelper.renderGenericProduct(receiptItem.itemProduct)}">
+ <p:link outcome="admin_show_generic_product" title="#{project.ADMIN_LINK_SHOW_RECEIPT_ITEM_PRODUCT_TITLE}" value="#{productBeanHelper.renderGenericProduct(receiptItem.itemProduct)}">
<f:param name="productId" value="#{receiptItem.itemProduct.productId}" />
</p:link>
</p:column>
filter="true"
filterMatchMode="contains"
label="#{msg.LABEL_COMPANIES}"
- onchange="PF('itemList').filter()"
+ onchange="PF('receiptItemList').filter()"
updateLabel="true"
title="#{msg.FILTER_BY_MULTIPLE_COMPANIES_TITLE}"
>
<pl:outputReceiptItemAdminMiniLinks receiptItem="#{receiptItem}" />
</p:column>
</p:dataTable>
+
+ <p:dialog
+ dynamic="true"
+ modal="true"
+ resizable="false"
+ header="#{project.ADMIN_SINGLE_RECEIPT_ITEM_DETAILS_HEADER}"
+ hideEffect="fade"
+ showEffect="fade"
+ widgetVar="receiptItemDialog"
+ position="center,center"
+ responsive="true"
+ >
+ <p:outputPanel id="receipt-item-details">
+ <p:panelGrid columns="2" rendered="#{not empty receiptItemListController.selectedReceiptItem}" columnClasses="label,value">
+ <f:facet name="header">
+ <h:outputFormat value="#{project.ADMIN_RECEIPT_DETAILS_HEADER}">
+ <f:param value="#{receiptItemListController.selectedReceiptItem.itemId}" />
+ </h:outputFormat>
+ </f:facet>
+
+ <p:outputLabel value="#{msg.ID_NUMBER_HEADER}" title="#{project.RECEIPT_ID_NUMBER_TITLE}" />
+ <h:outputText value="#{receiptItemListController.selectedReceiptItem.itemId}" />
+ </p:panelGrid>
+ </p:outputPanel>
+ </p:dialog>
</h:form>
- <h:form>
+ <h:form id="form-add-receipt-item">
<p:panelGrid layout="grid" columns="1" styleClass="table table-full">
<h:panelGroup styleClass="table-header" layout="block">
<h4>
type="submit"
value="#{project.BUTTON_ADMIN_ADD_RECEIPT_TEM}"
action="#{adminReceiptItemController.addReceiptItem()}"
- update=":master:form-list-financial-receipt-item:receiptItemList"
+ update=":master:form-list-financial-receipt-items:receiptItemList"
/>
</p:panelGrid>
</p:panelGrid>