From f30c95ad2233c04b9776973cae57869ef360cd58 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Fri, 8 Jul 2022 14:53:46 +0200 Subject: [PATCH] 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