/**
* Remote bean for categories
*/
- @EJB(lookup = "java:global/jfinancials-ejb/adminCategory!org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote")
+ @EJB (lookup = "java:global/jfinancials-ejb/adminCategory!org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote")
private AdminCategorySessionBeanRemote categoryBean;
+ /**
+ * Whether this category is shown in statistics
+ */
+ private Boolean categoryShownInStatistics;
+
/**
* Category categoryTitle
*/
* unexpected happened
*/
public void addCategory () throws FaceletException {
- try {
- // Create category
- final Category category = new ProductCategory();
+ // Create category
+ final Category category = this.createCategoryInstance();
- // Set fields
- category.setParentCategory(this.getParentCategory());
- category.setCategoryTitle(this.getCategoryTitle());
+ // Declare updated category instance
+ final Category updatedCategory;
+ try {
// Deligate to remote bean
- final Category updatedCategory = this.categoryBean.addProductCategory(category);
-
- // Fire event
- this.categoryAddedEvent.fire(new CategoryAddedEvent(updatedCategory));
-
- // Unset all older values
- this.clear();
+ updatedCategory = this.categoryBean.addProductCategory(category);
} catch (final CategoryAlreadyAddedException ex) {
// Continue to throw
throw new FaceletException(ex);
}
+
+ // Fire event
+ this.categoryAddedEvent.fire(new CategoryAddedEvent(updatedCategory));
+
+ // Unset all older values
+ this.clear();
+ }
+
+ /**
+ * Getter for whether category is shown in statistics
+ * <p>
+ * @return Whether category is shown in statistics
+ */
+ public Boolean getCategoryShownInStatistics () {
+ return this.categoryShownInStatistics;
+ }
+
+ /**
+ * Setter for whether category is shown in statistics
+ * <p>
+ * @param categoryShownInStatistics Whether category is shown in statistics
+ */
+ public void setCategoryShownInStatistics (final Boolean categoryShownInStatistics) {
+ this.categoryShownInStatistics = categoryShownInStatistics;
}
/**
* Clears this bean (example: when category has been added)
*/
private void clear () {
- this.setCategoryTitle(""); //NOI18N
+ // Clear all fields
+ this.setCategoryTitle(null);
this.setParentCategory(null);
}
+ /**
+ * Creates a category instance with all fields (except primary key)
+ * <p>
+ * @return Category instance
+ */
+ private Category createCategoryInstance () {
+ // Create category
+ final Category category = new ProductCategory(this.getCategoryTitle(), this.getParentCategory(), this.getCategoryShownInStatistics());
+
+ // Return it
+ return category;
+ }
+
}
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.employee.Employable;
import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
import org.mxchange.jfinancials.beans.BaseFinancialsBean;
import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController;
import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jcontactsbusiness.model.employee.Employable;
/**
* A general helper for beans
* available. If null is provided, an empty string is returned.
* <p>
* @param employee Employable instance
- <p>
+ * <p>
* @return Contact's full name
*/
public String renderEmployee (final Employable employee) {
// Add name and price
sb.append(product.getProductTitle());
sb.append(" ("); //NOI18N
- sb.append(this.localizationController.formatCurrency(product.getProductPrice()));
+ sb.append(this.localizationController.formatCurrency(product.getProductGrossPrice()));
sb.append(")"); //NOI18N
}
}
/**
- * Returns the receipt. If null is provided, an empty string
- * is returned.
+ * Returns the receipt. If null is provided, an empty string is returned.
* <p>
* @param receipt Receipt instance
* <p>
sb.append(this.getMessageFromBundle(receipt.getReceiptPaymentType().getI18nKey()));
// Is receipt number included?
- if (receipt.getReceiptNumber() !=null) {
+ if (receipt.getReceiptNumber() != null) {
// Append it
sb.append(", ").append(this.getMessageFromBundle("RECEIPT_NUMBER")).append(" "); //NOI18N
sb.append(receipt.getReceiptNumber());
private Category productCategory;
/**
- * Property productPrice
+ * Product's gross price
*/
- private Float productPrice;
+ private Float productGrossPrice;
+
+ /**
+ * Product's net price
+ */
+ private Float productNetPrice;
/**
* Remote bean for products
@EJB (lookup = "java:global/jfinancial-ejb/adminProduct!org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote")
private AdminProductSessionBeanRemote productRemoteBean;
+ /**
+ * Product's tax rate
+ */
+ private Float productTaxRate;
+
/**
* Property productTitle
*/
/**
* Adds given product data from request to database
* <p>
- * @throws javax.faces.view.facelets.FaceletException If something
- * unexpected happened
+ * @throws FaceletException If something unexpected happened
*/
public void addProduct () throws FaceletException {
- try {
- // Create product instance
- final Product product = new GenericProduct();
+ // Create product instance
+ final Product product = this.createProductInstance();
- // Add all
- product.setProductAvailability(this.getProductAvailability());
- product.setProductCategory(this.getProductCategory());
- product.setProductPrice(this.getProductPrice());
- product.setProductTitle(this.getProductTitle());
+ // Declare updated product instance
+ final Product updatedProduct;
+ try {
// Call bean
- final Product updatedProduct = this.productRemoteBean.addGenericProduct(product);
-
- // Fire event
- this.addedProductEvent.fire(new ProductAddedEvent(updatedProduct));
-
- // Set all to null
- this.clear();
+ updatedProduct = this.productRemoteBean.addGenericProduct(product);
} catch (final ProductAlreadyAddedException ex) {
// Continue to throw
throw new FaceletException(ex);
}
+
+ // Fire event
+ this.addedProductEvent.fire(new ProductAddedEvent(updatedProduct));
+
+ // Set all to null
+ this.clear();
}
/**
}
/**
- * Getter for product's price property
+ * Getter for product's gross price
+ * <p>
+ * @return Product's gross price
+ */
+ public Float getProductGrossPrice () {
+ return this.productGrossPrice;
+ }
+
+ /**
+ * Setter for product's gross price
* <p>
- * @return Product's price property
+ * @param productGrossPrice Product's gross price
*/
- public Float getProductPrice () {
- return this.productPrice;
+ public void setProductGrossPrice (final Float productGrossPrice) {
+ this.productGrossPrice = productGrossPrice;
}
/**
- * Setter for product's price property
+ * Getter for product's net price
* <p>
- * @param productPrice Product's price property
+ * @return Product's net price
*/
- public void setProductPrice (final Float productPrice) {
- this.productPrice = productPrice;
+ public Float getProductNetPrice () {
+ return this.productNetPrice;
+ }
+
+ /**
+ * Setter for product's net price
+ * <p>
+ * @param productNetPrice Product's net price
+ */
+ public void setProductNetPrice (final Float productNetPrice) {
+ this.productNetPrice = productNetPrice;
+ }
+
+ /**
+ * Getter for product's tax rate
+ * <p>
+ * @return Product's tax rate
+ */
+ public Float getProductTaxRate () {
+ return this.productTaxRate;
+ }
+
+ /**
+ * Setter for product's tax rate
+ * <p>
+ * @param productTaxRate Product's tax rate
+ */
+ public void setProductTaxRate (final Float productTaxRate) {
+ this.productTaxRate = productTaxRate;
}
/**
private void clear () {
this.setProductAvailability(Boolean.FALSE);
this.setProductCategory(null);
- this.setProductPrice(null);
+ this.setProductNetPrice(null);
+ this.setProductTaxRate(null);
+ this.setProductGrossPrice(null);
this.setProductTitle(null);
}
+ /**
+ * Creates a product instance with all fields
+ * <p>
+ * @return Product instance
+ */
+ private Product createProductInstance () {
+ // Create product instance
+ final Product product = new GenericProduct(this.getProductTitle(), this.getProductGrossPrice(), this.getProductCategory(), this.getProductAvailability());
+
+ // Set all optional fields
+ product.setProductNetPrice(this.getProductNetPrice());
+ product.setProductTaxRate(this.getProductTaxRate());
+
+ // Return it
+ return product;
+ }
+
}