Hi Erwan,

Couldn't we have just applied the new property to the existing currency display 
type?  Also, ideally the description for the field type would make mention of 
it being configurable.

Thanks
Scott

On 26/04/2010, at 8:51 PM, er...@apache.org wrote:

> Author: erwan
> Date: Mon Apr 26 08:51:25 2010
> New Revision: 937964
> 
> URL: http://svn.apache.org/viewvc?rev=937964&view=rev
> Log:
> Adding a new display type "accouting-number", which allows to display 
> negatives in parentheses
> 
> Modified:
>    ofbiz/trunk/applications/accounting/config/arithmetic.properties
>    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java
>    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
> 
> Modified: ofbiz/trunk/applications/accounting/config/arithmetic.properties
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/arithmetic.properties?rev=937964&r1=937963&r2=937964&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/accounting/config/arithmetic.properties 
> (original)
> +++ ofbiz/trunk/applications/accounting/config/arithmetic.properties Mon Apr 
> 26 08:51:25 2010
> @@ -49,3 +49,6 @@ 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)
> 
> Modified: 
> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java?rev=937964&r1=937963&r2=937964&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java 
> (original)
> +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java Mon 
> Apr 26 08:51:25 2010
> @@ -109,6 +109,21 @@ public class UtilFormatOut {
>         return formatCurrency(price.doubleValue(), isoCode, locale, 
> maximumFractionDigits);
>     }
> 
> +    /** Format a decimal number to the pattern given
> +     * @param number The price double to be formatted
> +     * @param pattern pattern apply to format number
> +     * @param locale The Locale used to format the number
> +     * @return A String with the formatted price
> +     */
> +    public static String formatDecimalNumber(double number, String pattern, 
> Locale locale) {
> +        com.ibm.icu.text.NumberFormat nf = 
> com.ibm.icu.text.NumberFormat.getNumberInstance(locale);
> +        String nbParsing = "";
> +        ((com.ibm.icu.text.DecimalFormat)nf).applyPattern( pattern );
> +        ((com.ibm.icu.text.DecimalFormat)nf).toPattern();
> +        nbParsing = nf.format(number);
> +        return nbParsing;
> +    }
> +
>     /** Formats a double into a properly formatted currency string based on 
> isoCode and Locale
>      * @param price The price double to be formatted
>      * @param isoCode the currency ISO code
> 
> Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=937964&r1=937963&r2=937964&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
> +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Mon Apr 26 08:51:25 2010
> @@ -667,6 +667,9 @@ under the License.
>                     <xs:enumeration value="image">
>                         <xs:annotation><xs:documentation>Display the image 
> specified in image-location</xs:documentation></xs:annotation>
>                     </xs:enumeration>
> +                    <xs:enumeration value="accounting-number">
> +                        <xs:annotation><xs:documentation>Display negatives 
> in parentheses</xs:documentation></xs:annotation>
> +                    </xs:enumeration>
>                 </xs:restriction>
>             </xs:simpleType>
>         </xs:attribute>
> 
> Modified: 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=937964&r1=937963&r2=937964&view=diff
> ==============================================================================
> --- 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
> (original)
> +++ 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
> Mon Apr 26 08:51:25 2010
> @@ -2131,6 +2131,20 @@ public class ModelFormField {
>                 retVal = retVal.substring(0,10);
>             } else if ("date-time".equals(this.type) && retVal.length() > 16) 
> {
>                 retVal = retVal.substring(0,16);
> +            } else if ("accounting-number".equals(this.type)) {
> +                Locale locale = (Locale) context.get("locale");
> +                if (locale == null) {
> +                    locale = Locale.getDefault();
> +                }
> +                try {
> +                    Double parsedRetVal = (Double) 
> ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false);
> +                    String template = 
> UtilProperties.getPropertyValue("arithmetic", "accounting-number.format", 
> "#,##0.00;(#,##0.00)");
> +                    retVal = 
> UtilFormatOut.formatDecimalNumber(parsedRetVal.doubleValue(), template, 
> locale);
> +                } catch (GeneralException e) {
> +                    String errMsg = "Error formatting number [" + retVal + 
> "]: " + e.toString();
> +                    Debug.logError(e, errMsg, module);
> +                    throw new IllegalArgumentException(errMsg);
> +                }
>             }
>             return retVal;
>         }
> 
> 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to