mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 17:48:25 +01:00
Merge branch '9.0' of git@github.com:Dolibarr/dolibarr.git into 10.0
Conflicts: htdocs/core/lib/functionsnumtoword.lib.php
This commit is contained in:
@@ -13,37 +13,49 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* or see http://www.gnu.org/
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* or see https://www.gnu.org/
|
||||
*/
|
||||
/**
|
||||
* \file htdocs/core/lib/functionsnumbertoword.lib.php
|
||||
* \file htdocs/core/lib/functionsnumtoword.lib.php
|
||||
* \brief A set of functions for Dolibarr
|
||||
* This file contains all frequently used functions.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param float $num Number to convert (must be a numeric value, like reported by price2num())
|
||||
* @param Translate $langs Language
|
||||
* @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
|
||||
*/
|
||||
function dol_convertToWord($num, $langs, $currency = false, $centimes = false)
|
||||
{
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($centimes && strlen($num) == 1) {
|
||||
$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);
|
||||
$num = (int) $TNum[0];
|
||||
$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(!empty($TNum[1])) {
|
||||
$decimalpart = $TNum[1];
|
||||
$decimalpart = preg_replace('/0+$/', '', $decimalpart);
|
||||
|
||||
if ($decimalpart) {
|
||||
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');
|
||||
}
|
||||
return $concatWords;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -150,6 +167,7 @@ function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
|
||||
if ($numero < 0) $numero *= -1;
|
||||
if ($numero >= 1000000000001)
|
||||
return -1;
|
||||
|
||||
// Get 2 decimals to cents, another functions round or truncate
|
||||
$strnumber = number_format($numero, 10);
|
||||
$len = strlen($strnumber);
|
||||
|
||||
Reference in New Issue
Block a user