From b65f849c5de3ef963f53e2f8c741228fc66f7b5b Mon Sep 17 00:00:00 2001 From: Sylvain Legrand Date: Fri, 28 Jan 2022 11:22:12 +0100 Subject: [PATCH] New - Improve the reading of profIDs --- htdocs/core/lib/functions.lib.php | 30 ++++++++++++++++++++++++++++++ htdocs/main.inc.php | 14 +++++++------- htdocs/societe/card.php | 4 ++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a59f35a3978..edab23ce514 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -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 * diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index fd811877295..acc8c440821 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -2073,24 +2073,24 @@ function top_menu_user($hideloginname = 0, $urllogout = '') $dropdownBody .= '
'; if ($langs->transcountry("ProfId1", $mysoc->country_code) != '-') { - $dropdownBody .= '
'.$langs->transcountry("ProfId1", $mysoc->country_code).': '.showValueWithClipboardCPButton(getDolGlobalString("MAIN_INFO_SIREN")).''; + $dropdownBody .= '
'.$langs->transcountry("ProfId1", $mysoc->country_code).': '.dol_print_profids(getDolGlobalString("MAIN_INFO_SIREN")).''; } if ($langs->transcountry("ProfId2", $mysoc->country_code) != '-') { - $dropdownBody .= '
'.$langs->transcountry("ProfId2", $mysoc->country_code).': '.showValueWithClipboardCPButton(getDolGlobalString("MAIN_INFO_SIRET")).''; + $dropdownBody .= '
'.$langs->transcountry("ProfId2", $mysoc->country_code).': '.dol_print_profids(getDolGlobalString("MAIN_INFO_SIRET")).''; } if ($langs->transcountry("ProfId3", $mysoc->country_code) != '-') { - $dropdownBody .= '
'.$langs->transcountry("ProfId3", $mysoc->country_code).': '.showValueWithClipboardCPButton(getDolGlobalString("MAIN_INFO_APE")).''; + $dropdownBody .= '
'.$langs->transcountry("ProfId3", $mysoc->country_code).': '.dol_print_profids(getDolGlobalString("MAIN_INFO_APE")).''; } if ($langs->transcountry("ProfId4", $mysoc->country_code) != '-') { - $dropdownBody .= '
'.$langs->transcountry("ProfId4", $mysoc->country_code).': '.showValueWithClipboardCPButton(getDolGlobalString("MAIN_INFO_RCS")).''; + $dropdownBody .= '
'.$langs->transcountry("ProfId4", $mysoc->country_code).': '.dol_print_profids(getDolGlobalString("MAIN_INFO_RCS")).''; } if ($langs->transcountry("ProfId5", $mysoc->country_code) != '-') { - $dropdownBody .= '
'.$langs->transcountry("ProfId5", $mysoc->country_code).': '.showValueWithClipboardCPButton(getDolGlobalString("MAIN_INFO_PROFID5")).''; + $dropdownBody .= '
'.$langs->transcountry("ProfId5", $mysoc->country_code).': '.dol_print_profids(getDolGlobalString("MAIN_INFO_PROFID5")).''; } if ($langs->transcountry("ProfId6", $mysoc->country_code) != '-') { - $dropdownBody .= '
'.$langs->transcountry("ProfId6", $mysoc->country_code).': '.showValueWithClipboardCPButton(getDolGlobalString("MAIN_INFO_PROFID6")).''; + $dropdownBody .= '
'.$langs->transcountry("ProfId6", $mysoc->country_code).': '.dol_print_profids(getDolGlobalString("MAIN_INFO_PROFID6")).''; } - $dropdownBody .= '
'.$langs->trans("VATIntraShort").': '.showValueWithClipboardCPButton(getDolGlobalString("MAIN_INFO_TVAINTRA")).''; + $dropdownBody .= '
'.$langs->trans("VATIntraShort").': '.dol_print_profids(getDolGlobalString("MAIN_INFO_TVAINTRA")).''; $dropdownBody .= '
'; diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index b6c483fc026..43e9bb30314 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -2542,7 +2542,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; print ''.$idprof.''; $key = 'idprof'.$i; - print showValueWithClipboardCPButton(dol_escape_htmltag($object->$key)); + print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1); if ($object->$key) { if ($object->id_prof_check($i, $object) > 0) { print '   '.$object->id_prof_url($i, $object); @@ -2655,7 +2655,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''.$langs->trans('VATIntra').''; if ($object->tva_intra) { $s = ''; - $s .= showValueWithClipboardCPButton(dol_escape_htmltag($object->tva_intra)); + $s .= dol_print_profids($object->tva_intra, 'VATIntra', $object->country_code, 1); $s .= ''; if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {