2 * Copyright (C) 2016 - 2022 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jfinancials.beans.helper.product;
19 import javax.faces.view.ViewScoped;
20 import javax.inject.Inject;
21 import javax.inject.Named;
22 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
23 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
24 import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController;
25 import org.mxchange.jproduct.model.category.Category;
26 import org.mxchange.jproduct.model.product.Product;
29 * A helper for product beans
31 * @author Roland Häder<roland@mxchange.org>
33 @Named ("productBeanHelper")
35 public class FinancialsProductWebViewHelperBean extends BaseFinancialsBean implements FinancialsProductWebViewHelperController {
40 private static final long serialVersionUID = 17_258_793_567_145_701L;
43 * Localization controller
46 private FinancialsLocalizationSessionController localizationController;
51 public FinancialsProductWebViewHelperBean () {
52 // Call super constructor
57 * Returns the product name and price. If null is provided, an empty string
60 * @param product Product instance
62 * @return Product name
64 public String renderGenericProduct (final Product product) {
65 // Default is empty string, so let's get started
66 final StringBuilder sb = new StringBuilder(10);
69 if (product instanceof Product) {
70 // Is product number given?
71 if (product.getProductBarCodeNumber() != null) {
73 sb.append(this.getMessageFromBundle("BARCODE")).append(" "); //NOI18N
74 sb.append(product.getProductBarCodeNumber());
75 sb.append(", "); //NOI18N
76 } else if (product.getProductNumber() != null) {
78 sb.append(this.getMessageFromBundle("NUMBER")).append(" "); //NOI18N
79 sb.append(product.getProductNumber());
80 sb.append(", "); //NOI18N
84 sb.append(this.getMessageFromBundle(product.getProductI18nKey()));
86 // Is there any age group?
87 if (product.getProductAgeGroup() != null) {
89 sb.append(", ").append(this.getMessageFromBundle(product.getProductAgeGroup().getMessageKey())); //NOI18N
93 if ((product.getProductSize() != null) && (!product.getProductSize().isEmpty())) {
95 sb.append(", ").append(this.getMessageFromBundle("SIZE")).append(product.getProductSize()); //NOI18N
98 // Is manufacturer assigned?
99 if (product.getProductManufacturer() instanceof BasicData) {
100 // Yes, then take at least short name
101 sb.append(", ").append(product.getProductManufacturer().getCompanyShortName());
105 sb.append(" ("); //NOI18N
106 sb.append(this.localizationController.formatFloatNumber(product.getProductGrossPrice().floatValue()));
107 sb.append(" "); //NOI18N
108 sb.append(product.getProductCurrencyCode());
110 // Is tax rate given?
111 if (product.getProductTaxRate() != null) {
112 // Add tax rate, formatted after current locale
113 sb.append(", ").append(this.localizationController.formatFloatNumber(product.getProductTaxRate().floatValue())).append("%"); //NOI18N
117 sb.append(")"); //NOI18N
121 return sb.toString();
125 * Returns the category's i18n string translated. If null is provided, an
126 * empty string is returned.
128 * @param category Product category instance
130 * @return Category's i18n string translation
132 public String renderProductCategory (final Category category) {
133 // Default is empty string, so let's get started
134 final StringBuilder sb = new StringBuilder(10);
136 // Is a category set?
137 if (category instanceof Category) {
139 sb.append(this.getMessageFromBundle(category.getCategoryI18nKey()));
141 // Is a parent category set?
142 if (category.getParentCategory() instanceof Category) {
143 // Then add it in braces, too
144 sb.append(" ("); //NOI18N
145 sb.append(this.getMessageFromBundle(category.getParentCategory().getCategoryI18nKey()));
146 sb.append(")"); //NOI18N
151 return sb.toString();