diff --git a/applications/accounting/config/arithmetic.properties b/applications/accounting/config/arithmetic.properties index 1c3a1686d4b..5dea2b2b579 100644 --- a/applications/accounting/config/arithmetic.properties +++ b/applications/accounting/config/arithmetic.properties @@ -49,6 +49,3 @@ finaccount.roundingSimpleMethod = HalfUp salestax.calc.decimals = 3 salestax.final.decimals = 2 salestax.rounding = ROUND_HALF_UP - -# the default accounting-number format for negatives in parentheses -accounting-number.format = #,##0.00;(#,##0.00) diff --git a/applications/order/template/order/EditOrderItems.ftl b/applications/order/template/order/EditOrderItems.ftl index 39267cb5999..7f6de80f5f3 100644 --- a/applications/order/template/order/EditOrderItems.ftl +++ b/applications/order/template/order/EditOrderItems.ftl @@ -175,7 +175,7 @@ under the License. <#-- check for permission to modify price --> <#if (allowPriceChange) && !("ITEM_CANCELLED" == orderItem.statusId || "ITEM_COMPLETED" == orderItem.statusId)> - + "/>   <#else>
<@ofbizCurrency amount=orderItem.unitPrice isoCode=currencyUomId/> / <@ofbizCurrency amount=orderItem.unitListPrice isoCode=currencyUomId/>
diff --git a/applications/order/widget/ordermgr/FieldLookupForms.xml b/applications/order/widget/ordermgr/FieldLookupForms.xml index bb4ea8841c2..dec99c6a0ec 100644 --- a/applications/order/widget/ordermgr/FieldLookupForms.xml +++ b/applications/order/widget/ordermgr/FieldLookupForms.xml @@ -497,7 +497,7 @@ under the License. - +
- - - + + + - + diff --git a/applications/order/widget/ordermgr/QuoteForms.xml b/applications/order/widget/ordermgr/QuoteForms.xml index 8c8c088caf4..78321692182 100644 --- a/applications/order/widget/ordermgr/QuoteForms.xml +++ b/applications/order/widget/ordermgr/QuoteForms.xml @@ -212,7 +212,7 @@ under the License. - + @@ -267,8 +267,8 @@ under the License. - - + + - + @@ -137,29 +137,29 @@ under the License. - - - - - + + + + + - - - - + + + +
- - - - - - - + + + + + + +
diff --git a/applications/order/widget/ordermgr/RequirementForms.xml b/applications/order/widget/ordermgr/RequirementForms.xml index 82b7bf73fc7..9f9179548f9 100644 --- a/applications/order/widget/ordermgr/RequirementForms.xml +++ b/applications/order/widget/ordermgr/RequirementForms.xml @@ -91,9 +91,9 @@ under the License. - - - + + + @@ -249,7 +249,7 @@ under the License. - + @@ -322,10 +322,10 @@ under the License. - + - +
- + @@ -373,7 +373,7 @@ under the License. - +
args, String key) { - String result = ""; - Object o = args.get(key); - if (o != null) { - if (Debug.verboseOn()) Debug.logVerbose("Arg Object : " + o.getClass().getName(), module); - if (o instanceof TemplateScalarModel) { - TemplateScalarModel s = (TemplateScalarModel) o; - try { - result = s.getAsString(); - } catch (TemplateModelException e) { - Debug.logError(e, "Template Exception", module); - } - } else { - result = o.toString(); - } - } - return result; - } - private static Double getAmount(Map args, String key) { - if (args.containsKey(key)) { - Object o = args.get(key); - if (Debug.verboseOn()) Debug.logVerbose("Amount Object : " + o.getClass().getName(), module); - - // handle nulls better - if (o == null) { - o = 0.00; - } - if (o instanceof NumberModel) { - NumberModel s = (NumberModel) o; - return s.getAsNumber().doubleValue(); - } - if (o instanceof SimpleNumber) { - SimpleNumber s = (SimpleNumber) o; - return s.getAsNumber().doubleValue(); - } - if (o instanceof SimpleScalar) { - SimpleScalar s = (SimpleScalar) o; - return Double.valueOf(s.getAsString()); - } - return Double.valueOf(o.toString()); - } - return 0.00; - } - - @Override public Writer getWriter(Writer out, @SuppressWarnings("rawtypes") Map args) { - final StringBuilder buf = new StringBuilder(); - Map arguments = UtilGenerics.cast(args); - final Double amount = OfbizAmountTransform.getAmount(arguments, "amount"); - final String locale = OfbizAmountTransform.getArg(arguments, "locale"); - final String format = OfbizAmountTransform.getArg(arguments, "format"); - - return new Writer(out) { - @Override - public void write(char cbuf[], int off, int len) { - buf.append(cbuf, off, len); - } - - @Override - public void flush() throws IOException { - out.flush(); - } - - @Override - public void close() throws IOException { - try { - if (Debug.verboseOn()) Debug.logVerbose("parms: " + amount + " " + format + " " + locale, module); - Locale localeObj = null; - if (locale.length() < 1) { - // Load the locale from the session - Environment env = Environment.getCurrentEnvironment(); - BeanModel req = (BeanModel) env.getVariable("request"); - if (req != null) { - HttpServletRequest request = (HttpServletRequest) req.getWrappedObject(); - localeObj = UtilHttp.getLocale(request); - } else { - localeObj = env.getLocale(); - } - } else { - localeObj = new Locale(locale); - } - if (format.equals(OfbizAmountTransform.SPELLED_OUT_FORMAT)) { - out.write(UtilFormatOut.formatSpelledOutAmount(amount.doubleValue(), localeObj)); - } else { - out.write(UtilFormatOut.formatAmount(amount, localeObj)); - } - } catch (TemplateModelException e) { - throw new IOException(e.getMessage()); - } - } - }; + arguments.put("format", UtilFormatOut.AMOUNT_FORMAT); + arguments.put("number", args.get("amount")); + return super.getWriter(out, arguments); } } diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizCurrencyTransform.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizCurrencyTransform.java index ce17a7bc21f..7ee0419030d 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizCurrencyTransform.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizCurrencyTransform.java @@ -141,9 +141,9 @@ public Writer getWriter(Writer out, @SuppressWarnings("rawtypes") Map args) { Delegator delegator = (Delegator) request.getAttribute("delegator"); // Get rounding from SystemProperty if (UtilValidate.isNotEmpty(delegator)) { - scaleEnabled = EntityUtilProperties.getPropertyValue("general", "currency.scale.enabled", "N", delegator); + scaleEnabled = EntityUtilProperties.getPropertyValue("number", "currency.scale.enabled", "N", delegator); if (UtilValidate.isEmpty(roundingNumber)) { - String roundingString = EntityUtilProperties.getPropertyValue("general", "currency.rounding.default", "10", delegator); + String roundingString = EntityUtilProperties.getPropertyValue("number", "currency.rounding.default", "10", delegator); if (UtilValidate.isInteger(roundingString)) roundingNumber = Integer.parseInt(roundingString); } } diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizNumberTransform.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizNumberTransform.java new file mode 100644 index 00000000000..e28f7a7757a --- /dev/null +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/ftl/OfbizNumberTransform.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.ofbiz.webapp.ftl; + +import freemarker.core.Environment; +import freemarker.ext.beans.BeanModel; +import freemarker.ext.beans.NumberModel; +import freemarker.template.SimpleNumber; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateModelException; +import freemarker.template.TemplateScalarModel; +import freemarker.template.TemplateTransformModel; +import java.io.IOException; +import java.io.Writer; +import java.util.Locale; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilFormatOut; +import org.apache.ofbiz.base.util.UtilGenerics; +import org.apache.ofbiz.base.util.UtilHttp; +import org.apache.ofbiz.entity.Delegator; + +/** + * OfbizAmountTransform - Freemarker Transform for content links + */ +public class OfbizNumberTransform implements TemplateTransformModel { + + public static final String module = OfbizNumberTransform.class.getName(); + String format = null; + + private static String getArg(Map args, String key) { + String result = ""; + Object o = args.get(key); + if (o != null) { + if (Debug.verboseOn()) Debug.logVerbose("Arg Object : " + o.getClass().getName(), module); + if (o instanceof TemplateScalarModel) { + TemplateScalarModel s = (TemplateScalarModel) o; + try { + result = s.getAsString(); + } catch (TemplateModelException e) { + Debug.logError(e, "Template Exception", module); + } + } else { + result = o.toString(); + } + } + return result; + } + private static Double getNumber(Map args, String key) { + if (args.containsKey(key)) { + Object o = args.get(key); + if (Debug.verboseOn()) Debug.logVerbose("Number Object : " + o.getClass().getName(), module); + + // handle nulls better + if (o == null) { + o = 0.00; + } + + if (o instanceof NumberModel) { + NumberModel s = (NumberModel) o; + return s.getAsNumber().doubleValue(); + } + if (o instanceof SimpleNumber) { + SimpleNumber s = (SimpleNumber) o; + return s.getAsNumber().doubleValue(); + } + if (o instanceof SimpleScalar) { + SimpleScalar s = (SimpleScalar) o; + return Double.valueOf(s.getAsString()); + } + return Double.valueOf(o.toString()); + } + return 0.00; + } + + @Override + public Writer getWriter(Writer out, @SuppressWarnings("rawtypes") Map args) { + final StringBuilder buf = new StringBuilder(); + + Map arguments = UtilGenerics.cast(args); + final Double number = OfbizNumberTransform.getNumber(arguments, "number"); + final String locale = OfbizNumberTransform.getArg(arguments, "locale"); + final String format = OfbizNumberTransform.getArg(arguments, "format"); + + return new Writer(out) { + @Override + public void write(char cbuf[], int off, int len) { + buf.append(cbuf, off, len); + } + + @Override + public void flush() throws IOException { + out.flush(); + } + + @Override + public void close() throws IOException { + try { + if (Debug.verboseOn()) Debug.logVerbose("parms: " + number + " " + format + " " + locale, module); + Locale localeObj = null; + Delegator delegator = null; + // Load the locale from the session + Environment env = Environment.getCurrentEnvironment(); + BeanModel req = (BeanModel) env.getVariable("request"); + if (req != null) { + HttpServletRequest request = (HttpServletRequest) req.getWrappedObject(); + delegator = (Delegator) request.getAttribute("delegator"); + if (locale.length() < 1) { + localeObj = UtilHttp.getLocale(request); + } else { + localeObj = env.getLocale(); + } + } else { + localeObj = new Locale(locale); + } + out.write(UtilFormatOut.formatNumber(number, format, delegator, localeObj)); + } catch (TemplateModelException e) { + throw new IOException(e.getMessage()); + } + } + }; + } +} diff --git a/framework/webtools/widget/MiscForms.xml b/framework/webtools/widget/MiscForms.xml index dbe30b256b8..1d72e5bd833 100644 --- a/framework/webtools/widget/MiscForms.xml +++ b/framework/webtools/widget/MiscForms.xml @@ -28,10 +28,19 @@ under the License.
+ + + + + + + + +