From: Roland Häder Date: Sun, 24 Sep 2017 12:15:06 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ee3143c752030bcbf85093936e6d9126e096d248;p=jfinancials-war.git 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 Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java deleted file mode 100644 index c2edf3ff..00000000 --- a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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.income; - -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.List; -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.user.login.FinancialsUserLoginWebSessionController; -import org.mxchange.jfinancials.model.income.BillableIncome; -import org.mxchange.jfinancials.model.income.FinancialIncome; -import org.mxchange.jfinancials.model.income.FinancialIncomeSessionBeanRemote; -import org.mxchange.jfinancials.model.income.interval.FinancialInterval; - -/** - * An administrative financial income bean (controller) - *

- * @author Roland Häder - */ -@Named ("financialIncomeController") -@RequestScoped -public class FinancialsIncomeWebRequestBean extends BaseFinancialsController implements FinancialsIncomeWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 56_189_028_928_371L; - - /** - * EJB for general financial income purposes - */ - @EJB (lookup = "java:global/jfinancials-ejb/financialIncome!org.mxchange.jfinancials.model.income.FinancialIncomeSessionBeanRemote") - private FinancialIncomeSessionBeanRemote financialBean; - - /** - * Income interval - */ - private FinancialInterval incomeInterval; - - /** - * Income single amount - */ - private Float incomeSingleAmount; - - /** - * Income (type) title - */ - private String incomeTitle; - - /** - * User instance - */ - @Inject - private FinancialsUserLoginWebSessionController userLoginController; - - /** - * Constructor - */ - public FinancialsIncomeWebRequestBean () { - // Call super constructor - super(); - } - - /** - * Adds income data by calling proper business method of the EJB. - *

- * @return Redirect outcome - */ - public String addIncome () { - // Is all data valid? - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged-in - throw new IllegalStateException("User is not logged-in"); //NOI18N - } else if (null == this.getIncomeInterval()) { - // Throw NPE - throw new NullPointerException("incomeInterval is null"); //NOI18N - } else if (null == this.getIncomeSingleAmount()) { - // Throw again - throw new NullPointerException("incomeSingleAmount is null"); //NOI18N - } else if (this.getIncomeSingleAmount() < 0) { - // Not allowed value - throw new IllegalArgumentException(MessageFormat.format("incomeSingleAmount={0} is not valid.", this.getIncomeSingleAmount())); //NOI18N - } else if (null == this.getIncomeTitle()) { - // Throw again - throw new NullPointerException("incomeTitle is null"); //NOI18N - } else if (this.getIncomeTitle().isEmpty()) { - // Should not be empty - throw new IllegalArgumentException("incomeTitle is empty"); //NOI18N - } - - // Now that all required data has been entered, prepare new income instance - final BillableIncome income = new FinancialIncome(this.getIncomeTitle(), this.getIncomeSingleAmount(), this.getIncomeInterval(), this.userLoginController.getLoggedInUser()); - - // 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 - } - - @Override - public List allIncomeIntervals () { - // Return list from enum values - return Arrays.asList(FinancialInterval.values()); - } - - @Override - public FinancialInterval getIncomeInterval () { - return this.incomeInterval; - } - - @Override - public void setIncomeInterval (final FinancialInterval incomeInterval) { - this.incomeInterval = incomeInterval; - } - - @Override - public Float getIncomeSingleAmount () { - return this.incomeSingleAmount; - } - - @Override - public void setIncomeSingleAmount (final Float incomeSingleAmount) { - this.incomeSingleAmount = incomeSingleAmount; - } - - @Override - public String getIncomeTitle () { - return this.incomeTitle; - } - - @Override - public void setIncomeTitle (final String incomeTitle) { - this.incomeTitle = incomeTitle; - } - -} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java deleted file mode 100644 index e25f954e..00000000 --- a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.income; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jfinancials.model.income.interval.FinancialInterval; - -/** - * An administrative interface for financial income beans - *

- * @author Roland Häder - */ -public interface FinancialsIncomeWebRequestController extends Serializable { - - /** - * Getter for income single amount - *

- * @return Income single amount - */ - Float getIncomeSingleAmount (); - - /** - * Setter for income single amount - *

- * @param incomeSingleAmount Income single amount - */ - void setIncomeSingleAmount (final Float incomeSingleAmount); - - /** - * Getter for income (type) title - *

- * @return Income title - */ - String getIncomeTitle (); - - /** - * Setter for income (type) title - *

- * @param incomeTitle Income title - */ - void setIncomeTitle (final String incomeTitle); - - /** - * Getter for income interval - *

- * @return Income interval - */ - FinancialInterval getIncomeInterval (); - - /** - * Setter for income (type) interval - *

- * @param incomeInterval Income interval - */ - void setIncomeInterval (final FinancialInterval incomeInterval); - - /** - * Returns a list of all all income intervals - *

- * @return Income intervals - */ - List allIncomeIntervals (); - -} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java new file mode 100644 index 00000000..20c6795c --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java @@ -0,0 +1,156 @@ +/* + * 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.income; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.List; +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +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.model.income.BillableIncome; +import org.mxchange.jfinancials.model.income.FinancialIncome; +import org.mxchange.jfinancials.model.income.FinancialIncomeSessionBeanRemote; +import org.mxchange.jfinancials.model.income.interval.FinancialInterval; + +/** + * An administrative financial income bean (controller) + *

+ * @author Roland Häder + */ +@Named ("financialIncomeController") +@RequestScoped +public class FinancialsIncomeWebRequestBean extends BaseFinancialsBean implements FinancialsIncomeWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_189_028_928_371L; + + /** + * EJB for general financial income purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/financialIncome!org.mxchange.jfinancials.model.income.FinancialIncomeSessionBeanRemote") + private FinancialIncomeSessionBeanRemote financialBean; + + /** + * Income interval + */ + private FinancialInterval incomeInterval; + + /** + * Income single amount + */ + private Float incomeSingleAmount; + + /** + * Income (type) title + */ + private String incomeTitle; + + /** + * User instance + */ + @Inject + private FinancialsUserLoginWebSessionController userLoginController; + + /** + * Constructor + */ + public FinancialsIncomeWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Adds income data by calling proper business method of the EJB. + *

+ * @return Redirect outcome + */ + public String addIncome () { + // Is all data valid? + if (!this.userLoginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else if (null == this.getIncomeInterval()) { + // Throw NPE + throw new NullPointerException("incomeInterval is null"); //NOI18N + } else if (null == this.getIncomeSingleAmount()) { + // Throw again + throw new NullPointerException("incomeSingleAmount is null"); //NOI18N + } else if (this.getIncomeSingleAmount() < 0) { + // Not allowed value + throw new IllegalArgumentException(MessageFormat.format("incomeSingleAmount={0} is not valid.", this.getIncomeSingleAmount())); //NOI18N + } else if (null == this.getIncomeTitle()) { + // Throw again + throw new NullPointerException("incomeTitle is null"); //NOI18N + } else if (this.getIncomeTitle().isEmpty()) { + // Should not be empty + throw new IllegalArgumentException("incomeTitle is empty"); //NOI18N + } + + // Now that all required data has been entered, prepare new income instance + final BillableIncome income = new FinancialIncome(this.getIncomeTitle(), this.getIncomeSingleAmount(), this.getIncomeInterval(), this.userLoginController.getLoggedInUser()); + + // 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 + } + + @Override + public List allIncomeIntervals () { + // Return list from enum values + return Arrays.asList(FinancialInterval.values()); + } + + @Override + public FinancialInterval getIncomeInterval () { + return this.incomeInterval; + } + + @Override + public void setIncomeInterval (final FinancialInterval incomeInterval) { + this.incomeInterval = incomeInterval; + } + + @Override + public Float getIncomeSingleAmount () { + return this.incomeSingleAmount; + } + + @Override + public void setIncomeSingleAmount (final Float incomeSingleAmount) { + this.incomeSingleAmount = incomeSingleAmount; + } + + @Override + public String getIncomeTitle () { + return this.incomeTitle; + } + + @Override + public void setIncomeTitle (final String incomeTitle) { + this.incomeTitle = incomeTitle; + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestController.java new file mode 100644 index 00000000..e885949a --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestController.java @@ -0,0 +1,79 @@ +/* + * 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.income; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jfinancials.model.income.interval.FinancialInterval; + +/** + * An administrative interface for financial income beans + *

+ * @author Roland Häder + */ +public interface FinancialsIncomeWebRequestController extends Serializable { + + /** + * Getter for income single amount + *

+ * @return Income single amount + */ + Float getIncomeSingleAmount (); + + /** + * Setter for income single amount + *

+ * @param incomeSingleAmount Income single amount + */ + void setIncomeSingleAmount (final Float incomeSingleAmount); + + /** + * Getter for income (type) title + *

+ * @return Income title + */ + String getIncomeTitle (); + + /** + * Setter for income (type) title + *

+ * @param incomeTitle Income title + */ + void setIncomeTitle (final String incomeTitle); + + /** + * Getter for income interval + *

+ * @return Income interval + */ + FinancialInterval getIncomeInterval (); + + /** + * Setter for income (type) interval + *

+ * @param incomeInterval Income interval + */ + void setIncomeInterval (final FinancialInterval incomeInterval); + + /** + * Returns a list of all all income intervals + *

+ * @return Income intervals + */ + List allIncomeIntervals (); + +} 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 new file mode 100644 index 00000000..00af46b6 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java @@ -0,0 +1,340 @@ +/* + * 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.text.MessageFormat; +import java.util.Date; +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.model.employee.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.jproduct.model.payment.PaymentType; +import org.mxchange.jusercore.model.user.User; + +/** + * An administrative backing bean for receipts + *

+ * @author Roland Häder + */ +@Named ("adminReceiptController") +@RequestScoped +public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean implements FinancialAdminReceiptWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 595_754_280_374_171L; + + /** + * Event being fired when administrator has added a new receipt + */ + @Inject + @Any + private Event adminAddedReceiptEvent; + + /** + * EJB for general financial receipt purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/adminFinancialReceipt!org.mxchange.jfinancials.model.receipt.FinancialAdminReceiptSessionBeanRemote") + private FinancialAdminReceiptSessionBeanRemote adminFinancialBean; + + /** + * Bar-code number + */ + 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 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 who "owns" this receipt + */ + private User receiptUser; + + /** + * Default constructor + */ + public FinancialAdminReceiptWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Adds the completed receipt to database by calling an EJB business method. + * If not all required fields are set, a proper exception is being thrown. + *

+ * @return Link outcome + */ + public String addReceipt () { + // Are all required fields set? + if (this.getReceiptBranchOffice() == null) { + // Is not set + throw new NullPointerException("this.receiptBranchOffice is not set."); //NOI18N + } else if (this.getReceiptBranchOffice().getBranchId() == null) { + // It must be an already peristed instance + throw new NullPointerException("this.receiptBranchOffice.businessContactId is not set."); //NOI18N + } else if (this.getReceiptBranchOffice().getBranchId() < 1) { + // It must be an already peristed instance + throw new IllegalArgumentException(MessageFormat.format("this.receiptBranchOffice.businessContactId={0} is not valid.", this.getReceiptBranchOffice().getBranchId())); //NOI18N + } else if (this.getReceiptPaymentType() == null) { + // Is not set + throw new NullPointerException("this.receiptPaymentType is not set."); //NOI18N + } else if (this.getReceiptIssued() == null) { + // Is not set + throw new NullPointerException("this.receiptIssued is not set."); //NOI18N + } + + // Prepare receipt instance + final BillableReceipt receipt = this.createReceiptInstance(); + + // Is the receipt already there? + if (this.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 + } + + // Init variable + final BillableReceipt updatedReceipt; + + // All is set, then try to call EJB + try { + // Add it + updatedReceipt = this.adminFinancialBean.addReceipt(receipt); + } catch (final ReceiptAlreadyAddedException ex) { + // Throw it again + throw new FaceletException(ex); + } + + // Fire event with updated instance + this.adminAddedReceiptEvent.fire(new ReceiptAddedEvent(updatedReceipt)); + + // Return redirect outcome + return "add_receipt_item?faces-redirect=true"; //NOI18N + } + + /** + * 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; + } + + /** + * 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 Receipt instance + */ + private BillableReceipt createReceiptInstance () { + // Create new instance with minimum required data + final BillableReceipt receipt = new FinancialReceipt(this.getReceiptPaymentType(), this.getReceiptBranchOffice(), this.getReceiptIssued()); + + // Set optional data + receipt.setReceiptUser(this.getReceiptUser()); + receipt.setReceiptNumber(this.getReceiptNumber()); + receipt.setReceiptBarCodeNumber(this.getReceiptBarCodeNumber()); + receipt.setReceiptRegisterNumber(this.getReceiptRegisterNumber()); + receipt.setReceiptSellerEmployee(this.getReceiptSellerEmployee()); + + // 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/model/receipt/FinancialsReceiptWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java new file mode 100644 index 00000000..a79d5549 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java @@ -0,0 +1,38 @@ +/* + * 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 java.io.Serializable; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; + +/** + * An administrative interface for financial receipt beans + *

+ * @author Roland Häder + */ +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/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java deleted file mode 100644 index 3e9c128f..00000000 --- a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * 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 java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.List; -import javax.ejb.EJB; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Observes; -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.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 BaseFinancialsController implements FinancialsReceiptWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 56_189_028_928_371L; - - /** - * EJB for general financial receipt purposes - */ - @EJB (lookup = "java:global/jfinancials-ejb/financialReceipt!org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote") - private FinancialReceiptSessionBeanRemote financialBean; - - /** - * Payment type being used for this receipt - */ - private PaymentType paymentType; - - /** - * Recipient issuing company (for example where the user went shopping to) - */ - private BranchOffice receiptBranchOffice; - - /** - * Date/time the receipt has been issued - */ - private Calendar receiptIssued; - - /** - * Receipt number (only numbers) - */ - private Long receiptNumber; - - /** - * Cached receipts - */ - private final List receipts; - - /** - * User instance - */ - @Inject - private FinancialsUserLoginWebSessionController userLoginController; - - /** - * Constructor - */ - @SuppressWarnings ("CollectionWithoutInitialCapacity") - public FinancialsReceiptWebRequestBean () { - // Call super constructor - super(); - - // Init cache - this.receipts = new ArrayList<>(); - } - - /** - * 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 () { - // 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) { - // 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.getPaymentType() == null) { - // Is not set - throw new NullPointerException("this.paymentType 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()); - - 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.financialBean.addReceipt(receipt); - } catch (final ReceiptAlreadyAddedException ex) { - // Throw it again - throw new FaceletException(ex); - } - - // @TODO Maybe fire event here? - // 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 - *

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

- * @param paymentType Payment type - */ - public void setPaymentType (final PaymentType paymentType) { - this.paymentType = paymentType; - } - - /** - * 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 Calendar getReceiptIssued () { - return this.receiptIssued; - } - - /** - * Setter for receipt issue date and time - *

- * @param receiptIssued Receipt issue date and time - */ - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setReceiptIssued (final Calendar 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; - } - - /** - * Checks if receipt has already been added to database - *

- * @param receipt Prepared receipt instance - *

- * @return Whether the receipt has already been added - */ - private boolean isReceiptAdded (final BillableReceipt receipt) { - // Always trust the cache - return this.receipts.contains(receipt); - } - -} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java deleted file mode 100644 index e5c331cc..00000000 --- a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 java.io.Serializable; - -/** - * An administrative interface for financial receipt beans - *

- * @author Roland Häder - */ -public interface FinancialsReceiptWebRequestController extends Serializable { - -} 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 @@ - - -
- -
+ + + + + - -
- -
+ + + -
- - - - - -
-
- - -
- -
- -
- -
-
- - - - - - -
- -
- -
- - - -
-
- - - - - - - - - - - -
- -
- -
- - - - -
-
- - -
+ + +