From e0551f1e32202e418771d7f548ac8889ebe4a1ee Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sat, 27 Mar 2021 17:29:06 +0100 Subject: [PATCH 1/9] Add ADHERENT_DEFAULT_CREATE_THIRDPARTY --- htdocs/adherents/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index b75bce38ca9..1d007bf654b 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -207,7 +207,7 @@ if (empty($reshook)) { } // Create third party from a member - if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) { + if (($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) || (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY))) { if ($result > 0) { // User creation $company = new Societe($db); From 6fdff2c3abe71c0273195d077464920ff3c2d2b8 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sun, 28 Mar 2021 19:19:40 +0200 Subject: [PATCH 2/9] autoaffect individual status for thirdparty --- htdocs/adherents/card.php | 43 +++++++++++++++++++++----- htdocs/societe/class/societe.class.php | 15 ++++++--- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 1d007bf654b..a934f9ca607 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -207,7 +207,7 @@ if (empty($reshook)) { } // Create third party from a member - if (($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) || (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY))) { + if (($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)) { if ($result > 0) { // User creation $company = new Societe($db); @@ -550,7 +550,7 @@ if (empty($reshook)) { $db->commit(); $rowid = $object->id; $id = $object->id; - $action = ''; + } else { $db->rollback(); @@ -559,12 +559,41 @@ if (empty($reshook)) { } else { setEventMessages($object->error, $object->errors, 'errors'); } - - $action = 'create'; } - } else { - $action = 'create'; - } + // Auto-create thirdparty on member creation + if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) { + if ($result > 0) { + // User creation + $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); + + if ($result < 0) { + $langs->load("errors"); + setEventMessages($langs->trans($company->error), null, 'errors'); + setEventMessages($company->error, $company->errors, 'errors'); + } + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + $action = ($result < 0 || !$error) ? '' : 'create'; } if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes') { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c141290d9e9..7fb7d51377d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -868,6 +868,7 @@ class Societe extends CommonObject $sql .= ", name_alias"; $sql .= ", entity"; $sql .= ", datec"; + $sql .= ", fk_typent"; $sql .= ", fk_user_creat"; $sql .= ", canvas"; $sql .= ", status"; @@ -882,6 +883,7 @@ class Societe extends CommonObject $sql .= ", accountancy_code_sell"; $sql .= ") VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'"; $sql .= ", ".(!empty($user->id) ? ((int) $user->id) : "null"); + $sql .= ", ".(!empty($this->typent_id) ? ((int) $this->typent_id) : "null"); $sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null"); $sql .= ", ".$this->status; $sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null"); @@ -958,7 +960,7 @@ class Societe extends CommonObject * @param array $tags Array of tag to affect to contact * @return int <0 if KO, >0 if OK */ - public function create_individual(User $user, $no_email, $tags = array()) + public function create_individual(User $user, $no_email = 0, $tags = array()) { global $conf; @@ -3793,21 +3795,24 @@ class Societe extends CommonObject $this->client = 1; // A member is a customer by default $this->code_client = ($customercode ? $customercode : -1); $this->code_fournisseur = -1; - + $this->typent_id = ($member->morphy == 'phy' ? 8 : 0); // The type of thirdparty is private (individual) if the member is human (phy) + $this->db->begin(); - + // Cree et positionne $this->id $result = $this->create($user); + if ($result >= 0) { // Auto-create contact on thirdparty creation - if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) { + if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) { // Fill fields needed by contact - $this->name_bis = $member->lastname; + $this->name_bis = $member->lastname; $this->firstname = $member->firstname; $this->civility_id = $member->civility_id; dol_syslog("We ask to create a contact/address too", LOG_DEBUG); $result = $this->create_individual($user); + if ($result < 0) { setEventMessages($this->error, $this->errors, 'errors'); $this->db->rollback(); From 1ae0e2a920072cd9ffd4fc64dde90c6173c250aa Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sun, 28 Mar 2021 19:38:20 +0200 Subject: [PATCH 3/9] fix stafix style errorsle fix stale errorfix style errors --- htdocs/adherents/card.php | 3 +-- htdocs/societe/class/societe.class.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index a934f9ca607..d8931602557 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -549,8 +549,7 @@ if (empty($reshook)) { $db->commit(); $rowid = $object->id; - $id = $object->id; - + $id = $object->id; } else { $db->rollback(); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 7fb7d51377d..dd73cb6e16c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3798,7 +3798,7 @@ class Societe extends CommonObject $this->typent_id = ($member->morphy == 'phy' ? 8 : 0); // The type of thirdparty is private (individual) if the member is human (phy) $this->db->begin(); - + // Cree et positionne $this->id $result = $this->create($user); From b7045ef3a031c76f40759d71eb0493290c0e4578 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 28 Mar 2021 17:42:18 +0000 Subject: [PATCH 4/9] Fixing style errors. --- htdocs/adherents/card.php | 62 +++++++++++++------------- htdocs/societe/class/societe.class.php | 10 ++--- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index d8931602557..12f0c2050ee 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -549,7 +549,7 @@ if (empty($reshook)) { $db->commit(); $rowid = $object->id; - $id = $object->id; + $id = $object->id; } else { $db->rollback(); @@ -561,37 +561,37 @@ if (empty($reshook)) { } // Auto-create thirdparty on member creation if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) { - if ($result > 0) { - // User creation - $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); - - if ($result < 0) { - $langs->load("errors"); - setEventMessages($langs->trans($company->error), null, 'errors'); - setEventMessages($company->error, $company->errors, 'errors'); - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($result > 0) { + // User creation + $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); + + if ($result < 0) { + $langs->load("errors"); + setEventMessages($langs->trans($company->error), null, 'errors'); + setEventMessages($company->error, $company->errors, 'errors'); + } + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } } - } + } $action = ($result < 0 || !$error) ? '' : 'create'; } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index dd73cb6e16c..d23c2cdf06c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3796,23 +3796,23 @@ class Societe extends CommonObject $this->code_client = ($customercode ? $customercode : -1); $this->code_fournisseur = -1; $this->typent_id = ($member->morphy == 'phy' ? 8 : 0); // The type of thirdparty is private (individual) if the member is human (phy) - + $this->db->begin(); // Cree et positionne $this->id $result = $this->create($user); - + if ($result >= 0) { // Auto-create contact on thirdparty creation - if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) { + if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT)) { // Fill fields needed by contact - $this->name_bis = $member->lastname; + $this->name_bis = $member->lastname; $this->firstname = $member->firstname; $this->civility_id = $member->civility_id; dol_syslog("We ask to create a contact/address too", LOG_DEBUG); $result = $this->create_individual($user); - + if ($result < 0) { setEventMessages($this->error, $this->errors, 'errors'); $this->db->rollback(); From d9733b395e1aa90b6c76adbd651701cd0029e8d3 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Sun, 28 Mar 2021 22:30:47 +0200 Subject: [PATCH 5/9] Copyright in adherents/card.php --- htdocs/adherents/card.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 12f0c2050ee..4267a801df5 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -7,6 +7,7 @@ * Copyright (C) 2012-2020 Philippe Grand * Copyright (C) 2015-2018 Alexandre Spangaro * Copyright (C) 2018-2020 Frédéric France + * Copyright (C) 2021 Waël Almoman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -207,7 +208,7 @@ if (empty($reshook)) { } // Create third party from a member - if (($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)) { + if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) { if ($result > 0) { // User creation $company = new Societe($db); From b6d03dcad08b373896cfe3f1c7741ad0fdfabc11 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Mon, 29 Mar 2021 03:27:02 +0200 Subject: [PATCH 6/9] Update copyright --- htdocs/adherents/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 4267a801df5..7a17937e051 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -7,7 +7,7 @@ * Copyright (C) 2012-2020 Philippe Grand * Copyright (C) 2015-2018 Alexandre Spangaro * Copyright (C) 2018-2020 Frédéric France - * Copyright (C) 2021 Waël Almoman + * Copyright (C) 2021 Waël Almoman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From 57b15c1821ff0c0e050221019f2c9c4e918213a3 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Mon, 29 Mar 2021 22:15:28 +0200 Subject: [PATCH 7/9] use dol_getIdFromCode for TE_PRIVATE --- htdocs/societe/class/societe.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index d23c2cdf06c..7e6f25d573d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3795,7 +3795,8 @@ class Societe extends CommonObject $this->client = 1; // A member is a customer by default $this->code_client = ($customercode ? $customercode : -1); $this->code_fournisseur = -1; - $this->typent_id = ($member->morphy == 'phy' ? 8 : 0); // The type of thirdparty is private (individual) if the member is human (phy) + $this->typent_code = ($member->morphy == 'phy' ? 'TE_PRIVATE' : 0); + $this->typent_id = dol_getIdFromCode($this->db, $this->typent_code, 'c_typent', 'id', 'code'); $this->db->begin(); From a01403c4dedf28e929ce497800ec0c79b7c22fdf Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 29 Mar 2021 20:16:58 +0000 Subject: [PATCH 8/9] 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 7e6f25d573d..2653bafbcae 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3795,8 +3795,8 @@ class Societe extends CommonObject $this->client = 1; // A member is a customer by default $this->code_client = ($customercode ? $customercode : -1); $this->code_fournisseur = -1; - $this->typent_code = ($member->morphy == 'phy' ? 'TE_PRIVATE' : 0); - $this->typent_id = dol_getIdFromCode($this->db, $this->typent_code, 'c_typent', 'id', 'code'); + $this->typent_code = ($member->morphy == 'phy' ? 'TE_PRIVATE' : 0); + $this->typent_id = dol_getIdFromCode($this->db, $this->typent_code, 'c_typent', 'id', 'code'); $this->db->begin(); From c36c4937ea29d579092a129d42b1779e76ee4210 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 30 Mar 2021 00:31:37 +0200 Subject: [PATCH 9/9] Update societe.class.php --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 2653bafbcae..4af4b1e994b 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3796,7 +3796,7 @@ class Societe extends CommonObject $this->code_client = ($customercode ? $customercode : -1); $this->code_fournisseur = -1; $this->typent_code = ($member->morphy == 'phy' ? 'TE_PRIVATE' : 0); - $this->typent_id = dol_getIdFromCode($this->db, $this->typent_code, 'c_typent', 'id', 'code'); + $this->typent_id = $this->typent_code ? dol_getIdFromCode($this->db, $this->typent_code, 'c_typent', 'id', 'code') : 0; $this->db->begin();