2
0
forked from Wavyzz/dolibarr

New - Improve the reading of profIDs

This commit is contained in:
Sylvain Legrand
2022-01-28 11:22:12 +01:00
parent 3f9feef914
commit b65f849c5d
3 changed files with 39 additions and 9 deletions

View File

@@ -2925,6 +2925,36 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor
return $htmllink;
}
/**
* Format profIDs according to country
*
* @param string $profID value of profID to format
* @param string $profIDtype type of profID to format (ProfId1, ProfId2, ProfId3, ProfId4, ProfId5, ProfId6 or VATIntra)
* @param string $countrycode Country code to use for formatting
* @param int $addcpButton Add button to copy to clipboard (1 => show only on hoover ; 2 => always display )
* @param string $separ Separation between numbers for a better visibility example : xxx xxx xxx xxxxx
* @return string Formated profID
*/
function dol_print_profids($profID, $profIDtype, $countrycode = '', $addcpButton = 1, $separ = ' ')
{
global $mysoc;
if (empty($profID) || empty($profIDtype)) return '';
if (empty($countrycode)) $countrycode = $mysoc->country_code;
$newProfID = $profID;
$id = substr($profIDtype, -1);
$ret = '';
if (strtoupper($countrycode) == 'FR') {
// France
if ($id == 1 && dol_strlen($newProfID) == 9) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3);
if ($id == 2 && dol_strlen($newProfID) == 14) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3).$separ.substr($newProfID, 9, 5);
if ($profIDtype == 'VATIntra' && dol_strlen($newProfID) == 13) $newProfID = substr($newProfID, 0, 4).$separ.substr($newProfID, 4, 3).$separ.substr($newProfID, 7, 3).$separ.substr($newProfID, 10, 3);
}
if (!empty($addcpButton)) $ret = showValueWithClipboardCPButton(dol_escape_htmltag($profID), ($addcpButton == 1 ? 1 : 0), $newProfID);
else $ret = $newProfID;
return $ret;
}
/**
* Format phone numbers according to country
*