From 26dff90658131ec074e18022e949162a49423dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 6 Sep 2023 13:58:08 +0200 Subject: [PATCH] deprecate set_as_client --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/contrat/class/contrat.class.php | 2 +- htdocs/expedition/class/expedition.class.php | 2 +- htdocs/societe/class/societe.class.php | 18 ++++++++++++++++-- test/phpunit/SocieteTest.php | 2 +- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index b76ba76fb8d..be4cff37295 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2702,7 +2702,7 @@ class Propal extends CommonObject // The connected company is classified as a client $soc=new Societe($this->db); $soc->id = $this->socid; - $result = $soc->set_as_client(); + $result = $soc->setAsCustomer(); if ($result < 0) { $this->error=$this->db->lasterror(); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 250d6c49aa0..6dedde25fc0 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -505,7 +505,7 @@ class Commande extends CommonOrder $soc->fetch($this->socid); // Class of company linked to order - $result = $soc->set_as_client(); + $result = $soc->setAsCustomer(); // Define new ref if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0b20b4ddae8..b87ccdfe286 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3372,7 +3372,7 @@ class Facture extends CommonInvoice if (!$error) { // Define third party as a customer - $result = $this->thirdparty->set_as_client(); + $result = $this->thirdparty->setAsCustomer(); // If active we decrement the main product and its components at invoice validation if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse > 0) { diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index bf63fbf261d..1b3e60939e0 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -499,7 +499,7 @@ class Contrat extends CommonObject // A contract is validated so we can move thirdparty to status customer if (empty($conf->global->CONTRACT_DISABLE_AUTOSET_AS_CLIENT_ON_CONTRACT_VALIDATION)) { - $result = $this->thirdparty->set_as_client(); + $result = $this->thirdparty->setAsCustomer(); } // Define new ref diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 967b4e9a4fb..1171e0367b9 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -725,7 +725,7 @@ class Expedition extends CommonObject $soc->fetch($this->socid); // Class of company linked to order - $result = $soc->set_as_client(); + $result = $soc->setAsCustomer(); // Define new ref if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 8f67f7567d1..19c6349e296 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2171,16 +2171,30 @@ class Societe extends CommonObject * Define third party as a customer * * @return int <0 if KO, >0 if OK + * @deprecated + * @see setAsCustomer() */ public function set_as_client() { // phpcs:enable + dol_syslog(get_class($this)."::set_as_client is deprecated use setAsCustomer instead", LOG_NOTICE); + return $this->setAsCustomer(); + } + + /** + * Define third party as a customer + * + * @return int <0 if KO, >0 if OK + * @since dolibarr v19 + */ + public function setAsCustomer() + { if ($this->id) { $newclient = 1; - if (($this->client == 2 || $this->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) { + if (($this->client == 2 || $this->client == 3) && !getDolGlobalInt('SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) { $newclient = 3; //If prospect, we keep prospect tag } - $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql .= " SET client = ".((int) $newclient); $sql .= " WHERE rowid = ".((int) $this->id); diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 9191a7e1d5c..96d2071ce7d 100644 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -337,7 +337,7 @@ class SocieteTest extends PHPUnit\Framework\TestCase $langs=$this->savlangs; $db=$this->savdb; - $result=$localobject->set_as_client(); + $result=$localobject->setAsCustomer(); print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0);