price2num was broken with some localization

This commit is contained in:
Laurent Destailleur
2008-12-06 11:28:40 +00:00
parent bb3ed6bd91
commit 2bc593e534
4 changed files with 40 additions and 17 deletions

View File

@@ -71,16 +71,31 @@ $var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("LanguageParameter","PHP LC_NUMERIC")."</td><td>".setlocale(LC_NUMERIC,0)."</td></tr>\n";
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("LanguageParameter","PHP LC_TIME")."</td><td>".setlocale(LC_TIME,0)."</td></tr>\n";
//$var=!$var;
//print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("LanguageParameter","PHP LC_MONETARY")."</td><td>".setlocale(LC_MONETARY,0)."</td></tr>\n";
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("LanguageParameter","PHP LC_MONETARY")."</td><td>".setlocale(LC_MONETARY,0)."</td></tr>\n";
print "<tr ".$bc[$var].'><td width="300">=> price2num(1234.56)</td><td>'.price2num(1233.56+1,'MT')."</td></tr>";
$var=!$var;
print "<tr ".$bc[$var].'><td width="300">=> dolibarr_print_date(0,"daytext")</td><td>'.dolibarr_print_date(0,"daytext")."</td>";
// Thousands
$var=!$var;
$thousand=$langs->trans("SeparatorThousand");
if ($thousand == 'SeparatorThousand') $thousand=' '; // ' ' does not work on trans method
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("CurrentValueSeparatorThousand")."</td><td>".($thousand==' '?$langs->trans("Space"):$thousand)."</td></tr>\n";
// Decimals
$var=!$var;
$dec=$langs->trans("SeparatorDecimal");
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("CurrentValueSeparatorDecimal")."</td><td>".$dec."</td></tr>\n";
$var=!$var;
$thousand=$langs->trans("SeparatorThousand");
if ($thousand == 'SeparatorThousand') $thousand=' '; // ' ' does not work on trans method
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("CurrentValueSeparatorThousand")."</td><td>".$thousand."</td></tr>\n";
print "<tr ".$bc[$var].'><td width=\"300\">=> price2num('."'1".$thousand."234".$dec."56')</td><td>".price2num("1".$thousand."234".$dec."56",'MT')."</td>";
if ($thousand != ',' && $thousand != '.')
{
$var=!$var;
print "<tr ".$bc[$var].'><td width=\"300\">=> price2num('."'1 234.56')</td><td>".price2num("1 234.56",'MT')."</td>";
print "</tr>\n";
}
print '<tr class="liste_titre"><td>'.$langs->trans("TimeZone").'</td><td>'.$langs->trans("Value").'</td></tr>'."\n";
// Timezone
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("DolibarrTZ")."</td><td>".$langs->trans("FeatureNotYetAvailable")."</td></tr>\n";
@@ -96,9 +111,9 @@ if (function_exists('date_default_timezone_get'))
print "</td></tr>\n"; // value defined in http://fr3.php.net/manual/en/timezones.europe.php
}
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("PHPServerOffsetWithGreenwich")."</td><td>".(- dolibarr_mktime(0,0,0,1,1,1970))."</td></tr>\n";
print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("PHPServerOffsetWithGreenwich")."</td><td>".(- dolibarr_mktime(0,0,0,1,1,1970))."</td></tr>\n";
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("CurrentHour")."</td><td>".dolibarr_print_date(time(),'dayhour')."</td></tr>\n";
print "<tr ".$bc[$var]."><td width=\"300\">=> ".$langs->trans("CurrentHour")."</td><td>".dolibarr_print_date(time(),'dayhour')."</td></tr>\n";
print '</table>';
print '<br>';

View File

@@ -37,6 +37,8 @@ UsePopupCalendar=Use popup for dates input
UsePreviewTabs=Use preview tabs
ShowPreview=Show preview
ThemeCurrentlyActive=Theme currently active
CurrentTimeZone=Current TimeZone
Space=Space
Fields=Fields
Mask=Mask
NextValue=Next value

View File

@@ -37,6 +37,8 @@ UsePopupCalendar=Utiliser les popups pour la saisie des dates
UsePreviewTabs=Afficher les onglets "Aper<65>u"
ShowPreview=Afficher aper<65>u
ThemeCurrentlyActive=Theme actuellement actif
CurrentTimeZone=TimeZone courant
Space=Espace
Fields=Champs
Mask=Masque
NextValue=Prochaine valeur

View File

@@ -468,10 +468,10 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='')
if ($format == 'dayhourldap') $format='%Y%m%d%H%M%SZ';
if ($format == 'dayhourxcard') $format='%Y%m%dT%H%M%SZ';
// Si date non definie, on renvoie ''
if ($time == '') return ''; // $time=0 permis car signifie 01/01/1970 00:00:00
// If date undefined or "", we return ""
if (strlen($time) == 0) return ''; // $time=0 allowed (it means 01/01/1970 00:00:00)
// Analyse de la date
// Analyse de la date (deprecated)
if (eregi('^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?',$time,$reg))
{
// This part of code should not be used.
@@ -492,7 +492,7 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='')
$ret=adodb_strftime($format,$time,$to_gmt);
}
// Page code for text from strftime functions
// What is page code of texts from strftime functions ?
$pagecodefrom='ISO-8859-1';
$localtime=setlocale(LC_TIME,0);
if (eregi('UTF',$localtime)) $pagecodefrom='UTF-8';
@@ -2148,14 +2148,10 @@ function price2num($amount,$rounding='',$alreadysqlnb=-1)
// Round PHP function does not allow number like '1,234.5' nor '1.234,5' nor '1 234,5'
// Numbers must be '1234.5'
// Decimal delimiter for database SQL request must be '.'
$dec=','; $thousand=' ';
if ($langs->trans("SeparatorDecimal") != "SeparatorDecimal") $dec=$langs->trans("SeparatorDecimal");
if ($langs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$langs->trans("SeparatorThousand");
// Define nbofdec
$nbofdec=max(0,strlen($amount-intval($amount))-2);
// Convert value to universal number format (no thousand separator, '.' as decimal separator)
if ($alreadysqlnb != 1) // If not a PHP number or unknown, we change format
{
@@ -2163,7 +2159,11 @@ function price2num($amount,$rounding='',$alreadysqlnb=-1)
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
// to format defined by LC_NUMERIC after a calculation and we want source format to be like defined by Dolibarr setup.
if (is_numeric($amount))
{
$nbofdec=max(0,strlen($amount-intval($amount))-2);
$amount=number_format($amount,$nbofdec,$dec,$thousand);
}
//print "QQ".$amount.'<br>';
// Now make replace (the main goal of function)
@@ -2186,7 +2186,11 @@ function price2num($amount,$rounding='',$alreadysqlnb=-1)
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
// to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup.
if (is_numeric($amount))
{
$nbofdec=max(0,strlen($amount-intval($amount))-2);
$amount=number_format($amount,min($nbofdec,$nbofdectoround),$dec,$thousand); // Convert amount to format with dolibarr dec and thousand
}
//print "RR".$amount.'<br>';
// Always make replace because each math function (like round) replace