From f30c95ad2233c04b9776973cae57869ef360cd58 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Fri, 8 Jul 2022 14:53:46 +0200 Subject: [PATCH 1/3] Create a 3rd party from the self-subscription membership form Only when ADHERENT_DEFAULT_CREATE_THIRDPARTY = 1 --- htdocs/adherents/card.php | 28 ++++---------------------- htdocs/public/members/new.php | 12 ++++++++++- htdocs/societe/class/societe.class.php | 17 ++++++++++++---- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index ee195da77be..4ac0d020458 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -564,36 +564,16 @@ if (empty($reshook)) { $id = $object->id; } else { $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); - if ($object->error) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } } + // Auto-create thirdparty on member creation if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) { if ($result > 0) { - // User creation + // Create third party out of a member $company = new Societe($db); - - $companyalias = ''; - $fullname = $object->getFullName($langs); - - if ($object->morphy == 'mor') { - $companyname = $object->company; - if (!empty($fullname)) { - $companyalias = $fullname; - } - } else { - $companyname = $fullname; - if (!empty($object->company)) { - $companyalias = $object->company; - } - } - - $result = $company->create_from_member($object, $companyname, $companyalias); - + $result = $company->create_from_member($object); if ($result < 0) { $langs->load("errors"); setEventMessages($langs->trans($company->error), null, 'errors'); diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index d29d80cf5d4..ac06a95a2b6 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -254,7 +254,7 @@ if (empty($reshook) && $action == 'add') { $public = GETPOSTISSET('public') ? 1 : 0; if (!$error) { - // email a peu pres correct et le login n'existe pas + // E-mail looks OK and login does not exist $adh = new Adherent($db); $adh->statut = -1; $adh->public = $public; @@ -375,6 +375,16 @@ if (empty($reshook) && $action == 'add') { } } + // Auto-create thirdparty on member creation + if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) { + $company = new Societe($db); + $result = $company->create_from_member($adh); + if ($result < 0) { + $error++; + $errmsg .= join('
', $company->errors); + } + } + if (!empty($backtopage)) { $urlback = $backtopage; } elseif (!empty($conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION)) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 7c5773363c4..9d7a666d87d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3904,12 +3904,21 @@ class Societe extends CommonObject global $conf, $user, $langs; dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); - - $name = $socname ? $socname : $member->societe; - if (empty($name)) { - $name = $member->getFullName($langs); + $fullname = $member->getFullName($langs); + + if ($member->morphy == 'mor') { + $socname = $member->company? $member->company : $member->societe; + if (!empty($fullname) && empty($socalias)) { + $socalias = $fullname; + } + } else if(empty($socname) && $member->morphy == 'phy') { + $socname = $fullname; + if (!empty($member->company) && empty($socalias)) { + $socalias = $member->company; + } } + $name = $socname; $alias = $socalias ? $socalias : ''; // Positionne parametres From b0c9f5c3123084b3ac3767d2e27647e414b75108 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 25 Jul 2022 14:14:28 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/societe/class/societe.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 9d7a666d87d..68942d5f9ba 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3905,13 +3905,13 @@ class Societe extends CommonObject dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); $fullname = $member->getFullName($langs); - + if ($member->morphy == 'mor') { $socname = $member->company? $member->company : $member->societe; if (!empty($fullname) && empty($socalias)) { $socalias = $fullname; } - } else if(empty($socname) && $member->morphy == 'phy') { + } elseif (empty($socname) && $member->morphy == 'phy') { $socname = $fullname; if (!empty($member->company) && empty($socalias)) { $socalias = $member->company; From 8b87bfb693ae29962930dae14f0693185bea7d9a Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Thu, 11 Aug 2022 02:41:46 +0200 Subject: [PATCH 3/3] Keep original value of parameter, if any --- htdocs/societe/class/societe.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 68942d5f9ba..8de2bbe8bf0 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3907,12 +3907,16 @@ class Societe extends CommonObject $fullname = $member->getFullName($langs); if ($member->morphy == 'mor') { - $socname = $member->company? $member->company : $member->societe; + if (empty($socname)) { + $socname = $member->company? $member->company : $member->societe; + } if (!empty($fullname) && empty($socalias)) { $socalias = $fullname; } } elseif (empty($socname) && $member->morphy == 'phy') { - $socname = $fullname; + if (empty($socname)) { + $socname = $fullname; + } if (!empty($member->company) && empty($socalias)) { $socalias = $member->company; }