Merge pull request #13035 from Dolibarr/scrutinizer-patch-2

Scrutinizer Auto-Fixes
This commit is contained in:
Laurent Destailleur 2020-02-08 17:09:25 +01:00 committed by GitHub
commit 3dfe7161cf
3 changed files with 123 additions and 123 deletions

View File

@ -68,9 +68,9 @@ class AssetType extends CommonObject
public $note; public $note;
/** @var array Array of asset */ /** @var array Array of asset */
public $asset=array(); public $asset = array();
public $fields=array( public $fields = array(
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15, 'index'=>1), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15, 'index'=>1),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20), 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
@ -104,9 +104,9 @@ class AssetType extends CommonObject
{ {
global $conf; global $conf;
$error=0; $error = 0;
$this->label=trim($this->label); $this->label = trim($this->label);
$this->accountancy_code_asset = trim($this->accountancy_code_asset); $this->accountancy_code_asset = trim($this->accountancy_code_asset);
$this->accountancy_code_depreciation_asset = trim($this->accountancy_code_depreciation_asset); $this->accountancy_code_depreciation_asset = trim($this->accountancy_code_depreciation_asset);
$this->accountancy_code_depreciation_expense = trim($this->accountancy_code_depreciation_expense); $this->accountancy_code_depreciation_expense = trim($this->accountancy_code_depreciation_expense);
@ -114,20 +114,20 @@ class AssetType extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."asset_type ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."asset_type (";
$sql.= "label"; $sql .= "label";
$sql.= ", accountancy_code_asset"; $sql .= ", accountancy_code_asset";
$sql.= ", accountancy_code_depreciation_asset"; $sql .= ", accountancy_code_depreciation_asset";
$sql.= ", accountancy_code_depreciation_expense"; $sql .= ", accountancy_code_depreciation_expense";
$sql.= ", note"; $sql .= ", note";
$sql.= ", entity"; $sql .= ", entity";
$sql.= ") VALUES ("; $sql .= ") VALUES (";
$sql.= "'".$this->db->escape($this->label)."'"; $sql .= "'".$this->db->escape($this->label)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_asset)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_asset)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_depreciation_asset)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_depreciation_asset)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_depreciation_expense)."'"; $sql .= ", '".$this->db->escape($this->accountancy_code_depreciation_expense)."'";
$sql.= ", '".$this->db->escape($this->note)."'"; $sql .= ", '".$this->db->escape($this->note)."'";
$sql.= ", ".$conf->entity; $sql .= ", ".$conf->entity;
$sql.= ")"; $sql .= ")";
dol_syslog("Asset_type::create", LOG_DEBUG); dol_syslog("Asset_type::create", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
@ -142,15 +142,15 @@ class AssetType extends CommonObject
return -3; return -3;
} }
if (! $notrigger) if (!$notrigger)
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('ASSET_TYPE_CREATE', $user); $result = $this->call_trigger('ASSET_TYPE_CREATE', $user);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
// End call triggers // End call triggers
} }
if (! $error) if (!$error)
{ {
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
@ -164,7 +164,7 @@ class AssetType extends CommonObject
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error = $this->db->lasterror();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -181,45 +181,45 @@ class AssetType extends CommonObject
{ {
global $conf, $hookmanager; global $conf, $hookmanager;
$error=0; $error = 0;
$this->label=trim($this->label); $this->label = trim($this->label);
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."asset_type "; $sql = "UPDATE ".MAIN_DB_PREFIX."asset_type ";
$sql.= "SET "; $sql .= "SET ";
$sql.= "label = '".$this->db->escape($this->label) ."',"; $sql .= "label = '".$this->db->escape($this->label)."',";
$sql.= "accountancy_code_asset = '".$this->db->escape($this->accountancy_code_asset)."',"; $sql .= "accountancy_code_asset = '".$this->db->escape($this->accountancy_code_asset)."',";
$sql.= "accountancy_code_depreciation_asset = '".$this->db->escape($this->accountancy_code_depreciation_asset)."',"; $sql .= "accountancy_code_depreciation_asset = '".$this->db->escape($this->accountancy_code_depreciation_asset)."',";
$sql.= "accountancy_code_depreciation_expense = '".$this->db->escape($this->accountancy_code_depreciation_expense)."',"; $sql .= "accountancy_code_depreciation_expense = '".$this->db->escape($this->accountancy_code_depreciation_expense)."',";
$sql.= "note = '".$this->db->escape($this->note) ."'"; $sql .= "note = '".$this->db->escape($this->note)."'";
$sql.= " WHERE rowid =".$this->id; $sql .= " WHERE rowid =".$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$action='update'; $action = 'update';
// Actions on extra fields // Actions on extra fields
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$this->insertExtraFields(); $result = $this->insertExtraFields();
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
} }
} }
if (! $error && ! $notrigger) if (!$error && !$notrigger)
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('ASSET_TYPE_MODIFY', $user); $result = $this->call_trigger('ASSET_TYPE_MODIFY', $user);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
// End call triggers // End call triggers
} }
if (! $error) if (!$error)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -233,7 +233,7 @@ class AssetType extends CommonObject
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error = $this->db->lasterror();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -251,13 +251,13 @@ class AssetType extends CommonObject
$error = 0; $error = 0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."asset_type"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."asset_type";
$sql.= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
$resql=$this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
// Call trigger // Call trigger
$result=$this->call_trigger('ASSET_TYPE_DELETE', $user); $result = $this->call_trigger('ASSET_TYPE_DELETE', $user);
if ($result < 0) { $error++; $this->db->rollback(); return -2; } if ($result < 0) { $error++; $this->db->rollback(); return -2; }
// End call triggers // End call triggers
@ -267,7 +267,7 @@ class AssetType extends CommonObject
else else
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->lasterror(); $this->error = $this->db->lasterror();
return -1; return -1;
} }
} }
@ -286,7 +286,7 @@ class AssetType extends CommonObject
dol_syslog("Asset_type::fetch", LOG_DEBUG); dol_syslog("Asset_type::fetch", LOG_DEBUG);
$resql=$this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) if ($this->db->num_rows($resql))
@ -306,7 +306,7 @@ class AssetType extends CommonObject
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error = $this->db->lasterror();
return -1; return -1;
} }
} }
@ -320,15 +320,15 @@ class AssetType extends CommonObject
public function liste_array() public function liste_array()
{ {
// phpcs:enable // phpcs:enable
global $conf,$langs; global $conf, $langs;
$assettypes = array(); $assettypes = array();
$sql = "SELECT rowid, label as label"; $sql = "SELECT rowid, label as label";
$sql.= " FROM ".MAIN_DB_PREFIX."asset_type"; $sql .= " FROM ".MAIN_DB_PREFIX."asset_type";
$sql.= " WHERE entity IN (".getEntity('asset_type').")"; $sql .= " WHERE entity IN (".getEntity('asset_type').")";
$resql=$this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$nump = $this->db->num_rows($resql); $nump = $this->db->num_rows($resql);
@ -365,13 +365,13 @@ class AssetType extends CommonObject
{ {
global $conf, $user; global $conf, $user;
$ret=array(); $ret = array();
$sql = "SELECT a.rowid"; $sql = "SELECT a.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."asset as a"; $sql .= " FROM ".MAIN_DB_PREFIX."asset as a";
$sql.= " WHERE a.entity IN (".getEntity('asset').")"; $sql .= " WHERE a.entity IN (".getEntity('asset').")";
$sql.= " AND a.fk_asset_type = ".$this->id; $sql .= " AND a.fk_asset_type = ".$this->id;
if (! empty($excludefilter)) $sql.=' AND ('.$excludefilter.')'; if (!empty($excludefilter)) $sql .= ' AND ('.$excludefilter.')';
dol_syslog(get_class($this)."::listAssetsForGroup", LOG_DEBUG); dol_syslog(get_class($this)."::listAssetsForGroup", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -379,31 +379,31 @@ class AssetType extends CommonObject
{ {
while ($obj = $this->db->fetch_object($resql)) while ($obj = $this->db->fetch_object($resql))
{ {
if (! array_key_exists($obj->rowid, $ret)) if (!array_key_exists($obj->rowid, $ret))
{ {
if ($mode < 2) if ($mode < 2)
{ {
$assetstatic=new Asset($this->db); $assetstatic = new Asset($this->db);
if ($mode == 1) { if ($mode == 1) {
$assetstatic->fetch($obj->rowid, '', '', '', false, false); $assetstatic->fetch($obj->rowid, '', '', '', false, false);
} else { } else {
$assetstatic->fetch($obj->rowid); $assetstatic->fetch($obj->rowid);
} }
$ret[$obj->rowid]=$assetstatic; $ret[$obj->rowid] = $assetstatic;
} }
else $ret[$obj->rowid]=$obj->rowid; else $ret[$obj->rowid] = $obj->rowid;
} }
} }
$this->db->free($resql); $this->db->free($resql);
$this->asset=$ret; $this->asset = $ret;
return $ret; return $ret;
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error = $this->db->lasterror();
return -1; return -1;
} }
} }
@ -420,15 +420,15 @@ class AssetType extends CommonObject
{ {
global $langs; global $langs;
$result=''; $result = '';
$label=$langs->trans("ShowTypeCard", $this->label); $label = $langs->trans("ShowTypeCard", $this->label);
$linkstart = '<a href="'.DOL_URL_ROOT.'/asset/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $linkstart = '<a href="'.DOL_URL_ROOT.'/asset/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>'; $linkend = '</a>';
$result .= $linkstart; $result .= $linkstart;
if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1); if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->label, $maxlen):$this->label); if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->label, $maxlen) : $this->label);
$result .= $linkend; $result .= $linkend;
return $result; return $result;
@ -448,13 +448,13 @@ class AssetType extends CommonObject
// Initialize parameters // Initialize parameters
$this->id = 0; $this->id = 0;
$this->ref = 'ATSPEC'; $this->ref = 'ATSPEC';
$this->specimen=1; $this->specimen = 1;
$this->label='ASSET TYPE SPECIMEN'; $this->label = 'ASSET TYPE SPECIMEN';
$this->note='This is a note'; $this->note = 'This is a note';
// Assets of this asset type is just me // Assets of this asset type is just me
$this->asset=array( $this->asset = array(
$user->id => $user $user->id => $user
); );
} }

View File

@ -412,7 +412,7 @@ print '</tr>'."\n";
// Fields title label // Fields title label
// -------------------------------------------------------------------- // --------------------------------------------------------------------
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
foreach($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
$cssforfield = (empty($val['css']) ? '' : $val['css']); $cssforfield = (empty($val['css']) ? '' : $val['css']);
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
@ -427,8 +427,8 @@ foreach($object->fields as $key => $val)
// Extra fields // Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields // Hook fields
$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Action column // Action column
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ')."\n"; print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ')."\n";
@ -436,7 +436,7 @@ print '</tr>'."\n";
// Detect if we need a fetch on each output line // Detect if we need a fetch on each output line
$needToFetchEachLine=0; $needToFetchEachLine = 0;
if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
{ {
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
@ -448,19 +448,19 @@ if (is_array($extrafields->attributes[$object->table_element]['computed']) && co
// Loop on record // Loop on record
// -------------------------------------------------------------------- // --------------------------------------------------------------------
$i=0; $i = 0;
$totalarray=array(); $totalarray = array();
while ($i < ($limit ? min($num, $limit) : $num)) while ($i < ($limit ? min($num, $limit) : $num))
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if (empty($obj)) break; // Should not happen if (empty($obj)) break; // Should not happen
// Store properties in $object // Store properties in $object
$object->setVarsFromFetchObj($obj); $object->setVarsFromFetchObj($obj);
// Show here line of result // Show here line of result
print '<tr class="oddeven">'; print '<tr class="oddeven">';
foreach($object->fields as $key => $val) foreach ($object->fields as $key => $val)
{ {
$cssforfield = (empty($val['css']) ? '' : $val['css']); $cssforfield = (empty($val['css']) ? '' : $val['css']);
if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';

View File

@ -38,15 +38,15 @@ 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));
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 (!empty($conf->global->MAIN_MODULE_NUMBERWORDS)) {
if ($currency) { if ($currency) {
$type = 1; $type = 1;
} else { } else {
@ -106,24 +106,24 @@ function dol_convertToWord($num, $langs, $currency = false, $centimes = false)
$num_length = strlen($num); $num_length = strlen($num);
$levels = (int) (($num_length + 2) / 3); $levels = (int) (($num_length + 2) / 3);
$max_length = $levels * 3; $max_length = $levels * 3;
$num = substr('00' . $num, -$max_length); $num = substr('00'.$num, -$max_length);
$num_levels = str_split($num, 3); $num_levels = str_split($num, 3);
$nboflevels = count($num_levels); $nboflevels = count($num_levels);
for ($i = 0; $i < $nboflevels; $i++) { for ($i = 0; $i < $nboflevels; $i++) {
$levels--; $levels--;
$hundreds = (int) ($num_levels[$i] / 100); $hundreds = (int) ($num_levels[$i] / 100);
$hundreds = ($hundreds ? ' ' . $list1[$hundreds] . ' '.$langs->transnoentities('hundred') . ( $hundreds == 1 ? '' : 's' ) . ' ': ''); $hundreds = ($hundreds ? ' '.$list1[$hundreds].' '.$langs->transnoentities('hundred').($hundreds == 1 ? '' : 's').' ' : '');
$tens = (int) ($num_levels[$i] % 100); $tens = (int) ($num_levels[$i] % 100);
$singles = ''; $singles = '';
if ( $tens < 20 ) { if ($tens < 20) {
$tens = ($tens ? ' ' . $list1[$tens] . ' ' : '' ); $tens = ($tens ? ' '.$list1[$tens].' ' : '');
} else { } else {
$tens = (int) ($tens / 10); $tens = (int) ($tens / 10);
$tens = ' ' . $list2[$tens] . ' '; $tens = ' '.$list2[$tens].' ';
$singles = (int) ($num_levels[$i] % 10); $singles = (int) ($num_levels[$i] % 10);
$singles = ' ' . $list1[$singles] . ' '; $singles = ' '.$list1[$singles].' ';
} }
$words[] = $hundreds . $tens . $singles . ( ( $levels && ( int ) ( $num_levels[$i] ) ) ? ' ' . $list3[$levels] . ' ' : '' ); $words[] = $hundreds.$tens.$singles.(($levels && (int) ($num_levels[$i])) ? ' '.$list3[$levels].' ' : '');
} //end for loop } //end for loop
$commas = count($words); $commas = count($words);
if ($commas > 1) { if ($commas > 1) {
@ -133,15 +133,15 @@ function dol_convertToWord($num, $langs, $currency = false, $centimes = false)
// Delete multi whitespaces // Delete multi whitespaces
$concatWords = trim(preg_replace('/[ ]+/', ' ', $concatWords)); $concatWords = trim(preg_replace('/[ ]+/', ' ', $concatWords));
if(!empty($currency)) { if (!empty($currency)) {
$concatWords .= ' '.$currency; $concatWords .= ' '.$currency;
} }
// 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])) { if (!empty($TNum[1])) {
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($TNum[1], $langs, $currency, true);
if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes'); if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes');
} }
return $concatWords; return $concatWords;
} }
@ -165,35 +165,35 @@ function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
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);
for ($i=0; $i<$len; $i++) for ($i = 0; $i < $len; $i++)
{ {
if ($strnumber[$i]=='.') { if ($strnumber[$i] == '.') {
$parte_decimal = $strnumber[$i+1].$strnumber[$i+2]; $parte_decimal = $strnumber[$i + 1].$strnumber[$i + 2];
break; break;
} }
} }
/*In dolibarr 3.6.2 (my current version) doesn't have $langs->default and /*In dolibarr 3.6.2 (my current version) doesn't have $langs->default and
in case exist why ask $lang like a parameter?*/ in case exist why ask $lang like a parameter?*/
if (((is_object($langs) && $langs->default == 'es_MX') || (! is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency') if (((is_object($langs) && $langs->default == 'es_MX') || (!is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency')
{ {
if ($numero>=1 && $numero<2) { if ($numero >= 1 && $numero < 2) {
return ("UN PESO ".$parte_decimal." / 100 M.N."); return ("UN PESO ".$parte_decimal." / 100 M.N.");
} }
elseif ($numero>=0 && $numero<1){ elseif ($numero >= 0 && $numero < 1) {
return ("CERO PESOS ".$parte_decimal." / 100 M.N."); return ("CERO PESOS ".$parte_decimal." / 100 M.N.");
} }
elseif ($numero>=1000000 && $numero<1000001){ elseif ($numero >= 1000000 && $numero < 1000001) {
return ("UN MILL&OacuteN DE PESOS ".$parte_decimal." / 100 M.N."); return ("UN MILL&OacuteN DE PESOS ".$parte_decimal." / 100 M.N.");
} }
elseif ($numero>=1000000000000 && $numero<1000000000001){ elseif ($numero >= 1000000000000 && $numero < 1000000000001) {
return ("UN BILL&OacuteN DE PESOS ".$parte_decimal." / 100 M.N."); return ("UN BILL&OacuteN DE PESOS ".$parte_decimal." / 100 M.N.");
} }
else { else {
$entexto =""; $entexto = "";
$number = $numero; $number = $numero;
if ($number >= 1000000000){ if ($number >= 1000000000) {
$CdMMillon = (int) ($numero / 100000000000); $CdMMillon = (int) ($numero / 100000000000);
$numero = $numero - $CdMMillon * 100000000000; $numero = $numero - $CdMMillon * 100000000000;
$DdMMillon = (int) ($numero / 10000000000); $DdMMillon = (int) ($numero / 10000000000);
@ -203,7 +203,7 @@ function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
$entexto .= hundreds2text($CdMMillon, $DdMMillon, $UdMMillon); $entexto .= hundreds2text($CdMMillon, $DdMMillon, $UdMMillon);
$entexto .= " MIL "; $entexto .= " MIL ";
} }
if ($number >= 1000000){ if ($number >= 1000000) {
$CdMILLON = (int) ($numero / 100000000); $CdMILLON = (int) ($numero / 100000000);
$numero = $numero - $CdMILLON * 100000000; $numero = $numero - $CdMILLON * 100000000;
$DdMILLON = (int) ($numero / 10000000); $DdMILLON = (int) ($numero / 10000000);
@ -211,7 +211,7 @@ function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
$udMILLON = (int) ($numero / 1000000); $udMILLON = (int) ($numero / 1000000);
$numero = $numero - $udMILLON * 1000000; $numero = $numero - $udMILLON * 1000000;
$entexto .= hundreds2text($CdMILLON, $DdMILLON, $udMILLON); $entexto .= hundreds2text($CdMILLON, $DdMILLON, $udMILLON);
if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON==1) if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON == 1)
$entexto .= " MILL&OacuteN "; $entexto .= " MILL&OacuteN ";
else else
$entexto .= " MILLONES "; $entexto .= " MILLONES ";
@ -232,7 +232,7 @@ function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
$d = (int) ($numero / 10); $d = (int) ($numero / 10);
$u = (int) $numero - $d * 10; $u = (int) $numero - $d * 10;
$entexto .= hundreds2text($c, $d, $u); $entexto .= hundreds2text($c, $d, $u);
if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number>1000000) if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number > 1000000)
$entexto .= " DE"; $entexto .= " DE";
$entexto .= " PESOS ".$parte_decimal." / 100 M.N."; $entexto .= " PESOS ".$parte_decimal." / 100 M.N.";
} }
@ -250,40 +250,40 @@ function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
*/ */
function hundreds2text($hundreds, $tens, $units) function hundreds2text($hundreds, $tens, $units)
{ {
if ($hundreds==1 && $tens==0 && $units==0){ if ($hundreds == 1 && $tens == 0 && $units == 0) {
return "CIEN"; return "CIEN";
} }
$centenas = array("CIENTO","DOSCIENTOS","TRESCIENTOS","CUATROCIENTOS","QUINIENTOS","SEISCIENTOS","SETECIENTOS","OCHOCIENTOS","NOVECIENTOS"); $centenas = array("CIENTO", "DOSCIENTOS", "TRESCIENTOS", "CUATROCIENTOS", "QUINIENTOS", "SEISCIENTOS", "SETECIENTOS", "OCHOCIENTOS", "NOVECIENTOS");
$decenas = array("","","TREINTA ","CUARENTA ","CINCUENTA ","SESENTA ","SETENTA ","OCHENTA ","NOVENTA "); $decenas = array("", "", "TREINTA ", "CUARENTA ", "CINCUENTA ", "SESENTA ", "SETENTA ", "OCHENTA ", "NOVENTA ");
$veintis = array("VEINTE","VEINTIUN","VEINTID&OacuteS","VEINTITR&EacuteS","VEINTICUATRO","VEINTICINCO","VEINTIS&EacuteIS","VEINTISIETE","VEINTIOCHO","VEINTINUEVE"); $veintis = array("VEINTE", "VEINTIUN", "VEINTID&OacuteS", "VEINTITR&EacuteS", "VEINTICUATRO", "VEINTICINCO", "VEINTIS&EacuteIS", "VEINTISIETE", "VEINTIOCHO", "VEINTINUEVE");
$diecis = array("DIEZ","ONCE","DOCE","TRECE","CATORCE","QUINCE","DIECIS&EacuteIS","DIECISIETE","DIECIOCHO","DIECINUEVE"); $diecis = array("DIEZ", "ONCE", "DOCE", "TRECE", "CATORCE", "QUINCE", "DIECIS&EacuteIS", "DIECISIETE", "DIECIOCHO", "DIECINUEVE");
$unidades = array("UN","DOS","TRES","CUATRO","CINCO","SEIS","SIETE","OCHO","NUEVE"); $unidades = array("UN", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE");
$entexto = ""; $entexto = "";
if ($hundreds!=0){ if ($hundreds != 0) {
$entexto .= $centenas[$hundreds-1]; $entexto .= $centenas[$hundreds - 1];
} }
if ($tens>2){ if ($tens > 2) {
if ($hundreds!=0) $entexto .= " "; if ($hundreds != 0) $entexto .= " ";
$entexto .= $decenas[$tens-1]; $entexto .= $decenas[$tens - 1];
if ($units!=0){ if ($units != 0) {
$entexto .= " Y "; $entexto .= " Y ";
$entexto .= $unidades[$units-1]; $entexto .= $unidades[$units - 1];
} }
return $entexto; return $entexto;
} }
elseif ($tens==2){ elseif ($tens == 2) {
if ($hundreds!=0) $entexto .= " "; if ($hundreds != 0) $entexto .= " ";
$entexto .= " ".$veintis[$units]; $entexto .= " ".$veintis[$units];
return $entexto; return $entexto;
} }
elseif ($tens==1){ elseif ($tens == 1) {
if ($hundreds!=0) $entexto .= " "; if ($hundreds != 0) $entexto .= " ";
$entexto .= $diecis[$units]; $entexto .= $diecis[$units];
return $entexto; return $entexto;
} }
if ($units!=0) { if ($units != 0) {
if ($hundreds!=0 || $tens!=0) $entexto .= " "; if ($hundreds != 0 || $tens != 0) $entexto .= " ";
$entexto .= $unidades[$units-1]; $entexto .= $unidades[$units - 1];
} }
return $entexto; return $entexto;
} }