Added formating functions for price/percent/exrate/qty fields in user native format.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 14 Mar 2008 20:28:11 +0000 (20:28 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 14 Mar 2008 20:28:11 +0000 (20:28 +0000)
includes/current_user.inc

index a86d00d3058ac68493f56c34e47cfabd659501a3..a913bf5e56789ef8ddfc66e85aafd6d3a8a4dc21 100644 (file)
@@ -113,6 +113,45 @@ function number_format2($number, $decimals=0)
        return number_format($number, $decimals, $dsep, $tsep);
 }
 
+function price_format($number) {
+    return number_format2($number, 
+       $_SESSION["wa_current_user"]->prefs->price_dec());
+}
+
+function qty_format($number) {
+    return number_format2($number, 
+       $_SESSION["wa_current_user"]->prefs->qty_dec());
+}
+
+function exrate_format($number) {
+    return number_format2($number, 
+       $_SESSION["wa_current_user"]->prefs->exrate_dec());
+}
+
+function percent_format($number) {
+    return number_format2($number, 
+       $_SESSION["wa_current_user"]->prefs->percent_dec());
+}
+
+function user_numeric($input) {
+    global $decseps, $thoseps;
+
+    $num = trim($input);
+    $sep = $thoseps[user_tho_sep()];
+    if($sep!='') $num = str_replace( $sep, '', $num);
+       str_replace($sep, '', $num);
+    $sep = $decseps[user_dec_sep()];
+    if($sep!='.') $num = str_replace( $sep, '.', $num);
+    
+    if (!is_numeric($num))
+         return false;
+    $num = (float)$num;
+    if ($num == (int)$num)
+         return (int)$num;
+    else
+         return $num;
+}
+
 function user_company() 
 {
        return $_SESSION["wa_current_user"]->company;