Merge branch '10.0' of git@github.com:Dolibarr/dolibarr.git into 11.0

This commit is contained in:
Laurent Destailleur 2020-08-06 02:53:19 +02:00
commit ce960c8d0d

View File

@ -24,26 +24,38 @@
/** /**
* Function to return number in text. * Function to return a number into a text.
* May use module NUMBERWORDS if found.
* *
* * @param float $num Number to convert (must be a numeric value, like reported by price2num())
* @param float $num Number to convert
* @param Translate $langs Language * @param Translate $langs Language
* @param boolean $currency 0=number to translate | 1=currency to translate * @param boolean $currency 0=number to translate | 1=currency to translate
* @param boolean $centimes 0=no centimes | 1=centimes to translate * @param boolean $centimes 0=no cents/centimes | 1=there is cents/centimes to translate
* @return string|false Text of the number * @return string|false Text of the number
*/ */
function dol_convertToWord($num, $langs, $currency = false, $centimes = false) function dol_convertToWord($num, $langs, $currency = false, $centimes = false)
{ {
global $conf; global $conf;
$num = str_replace(array(',', ' '), '', trim($num)); //$num = str_replace(array(',', ' '), '', trim($num)); This should be useless since $num MUST be a php numeric value
if (!$num) { if (!$num) {
return false; return false;
} }
if ($centimes && strlen($num) == 1) { if ($centimes && strlen($num) == 1) {
$num = $num * 10; $num = $num * 10;
} }
if (!empty($conf->global->MAIN_MODULE_NUMBERWORDS)) {
if ($currency) {
$type = 1;
} else {
$type = 0;
}
$concatWords = $langs->getLabelFromNumber($num, $type);
return $concatWords;
} else {
$TNum = explode('.', $num); $TNum = explode('.', $num);
$num = (int) $TNum[0]; $num = (int) $TNum[0];
$words = array(); $words = array();
@ -126,13 +138,18 @@ function dol_convertToWord($num, $langs, $currency = false, $centimes = false)
} }
// If we need to write cents call again this function for cents // If we need to write cents call again this function for cents
if(!empty($TNum[1])) { $decimalpart = $TNum[1];
$decimalpart = preg_replace('/0+$/', '', $decimalpart);
if ($decimalpart) {
if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and'); if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and');
$concatWords .= ' '.dol_convertToWord($TNum[1], $langs, $currency, true);
$concatWords .= ' '.dol_convertToWord($decimalpart, $langs, '', true);
if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes'); if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes');
} }
return $concatWords; return $concatWords;
} }
}
/** /**
@ -150,6 +167,7 @@ function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
if ($numero < 0) $numero *= -1; if ($numero < 0) $numero *= -1;
if ($numero >= 1000000000001) if ($numero >= 1000000000001)
return -1; return -1;
// Get 2 decimals to cents, another functions round or truncate // Get 2 decimals to cents, another functions round or truncate
$strnumber = number_format($numero, 10); $strnumber = number_format($numero, 10);
$len = strlen($strnumber); $len = strlen($strnumber);