From 2c7dc2f28f08a99e1d06a9f96a50fc0e3949e41e Mon Sep 17 00:00:00 2001 From: Sylvain Legrand Date: Wed, 31 Jul 2024 15:32:07 +0200 Subject: [PATCH] NEW option: assign default roles to "individual" third-party contacts (#30499) * New option: assign default roles to "individual" third-party contacts When the option to automatically create a contact for third parties of the "Individuals" type is active (THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION). Allow to define the default roles assigned to these contacts. Process: 1 Selection of default roles in the settings (and saving) 2 Creation of a third party of the "Individuals" type and therefore of its associated contact. 3 The contact thus created is automatically assigned the predefined roles. * Update societe.php * Update societe.php --- htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/fr_FR/admin.lang | 1 + htdocs/societe/admin/societe.php | 34 ++++++++++++++++++++++++++ htdocs/societe/class/societe.class.php | 1 + 4 files changed, 37 insertions(+) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index dc2d0d980ea..3ad8a4e4573 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2540,3 +2540,4 @@ MainAuthenticationOidcLoginClaimDesc=OpenID Connect claim matching the Dolibarr BlackListWords=Black list of words AddBlackList=Add to black list AnOwnerMustBeSetIfEmailTemplateIsPrivate=An owner must be set if the email template is set as private +ContactsDefaultRoles=For third parties of the "individual" type, a contact can be created simultaneously. Define here the roles that will be systematically assigned to this contact. diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index a1aa4b035c5..6b5b1e28c28 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -2507,3 +2507,4 @@ SendToUrl=Envoyer à l'URL WebsiteTemplateWasCopied=Le(s) modèle(s) de site Web "%s" fournis par ce module ont été enregistrés dans le répertoire des modèles de sites Web (/doctemplates/websites) et est prêt à être importé en tant que nouveau site Web. EnabledByDefaultAtInstall=Activé par défaut lors de l'installation VulnerableToRCEAttack=Vous êtes vulnérable aux attaques de type RCE en utilisant la fonction personnalisée dol_json_decode +ContactsDefaultRoles=Pour les les tiers de type "particulier" un contact peut-être créé simultanément. Définissez ici les rôles qui seront systématiquement attribués à ce contact. diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php index bb683c97c9c..c220073cb88 100644 --- a/htdocs/societe/admin/societe.php +++ b/htdocs/societe/admin/societe.php @@ -31,6 +31,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; $langs->loadLangs(array("admin", "companies", "other")); @@ -106,6 +107,19 @@ if ($action == 'updateoptions') { setEventMessages($langs->trans("Error"), null, 'errors'); } } + + if (GETPOST('CONTACTS_DEFAULT_ROLES')) { + $rolessearch = GETPOST('activate_CONTACTS_DEFAULT_ROLES', 'array'); + $res = dolibarr_set_const($db, "CONTACTS_DEFAULT_ROLES", implode(',', $rolessearch), 'chaine', 0, '', $conf->entity); + if (!($res > 0)) { + $error++; + } + if (!$error) { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } else { + setEventMessages($langs->trans("Error"), null, 'errors'); + } + } } // Activate a document generator module @@ -926,6 +940,26 @@ if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) { print ''; } +if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) { + print ''; + print ''.$langs->trans('ContactsDefaultRoles').''; + if (!$conf->use_javascript_ajax) { + print ''; + print $langs->trans("NotAvailableWhenAjaxDisabled"); + print ""; + } else { + print ''; + $contact = new Contact($db); // InfraS add + $contactType = $contact->listeTypeContacts('external', 0, 1); + $selected = explode(',', getDolGlobalString('CONTACTS_DEFAULT_ROLES')); + print $form->multiselectarray('activate_CONTACTS_DEFAULT_ROLES', $contactType, $selected, 0, 0, 'minwidth75imp'); + print ''; + print ''; + print ""; + } + print ''; +} + print ''; print ''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 900b6ee990a..b2ccbb22a93 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1117,6 +1117,7 @@ class Societe extends CommonObject $contact->town = $this->town; $this->setUpperOrLowerCase(); $contact->phone_pro = $this->phone; + $contact->roles = explode(',', getDolGlobalString('CONTACTS_DEFAULT_ROLES')); $contactId = $contact->create($user, $notrigger); if ($contactId < 0) {