From aa7e3c2fdd09bcc1decbc4bdd371b17b513961c2 Mon Sep 17 00:00:00 2001
From: fhenry <florian.henry@open-concept.pro>
Date: Sat, 11 May 2013 17:10:11 +0200
Subject: [PATCH] [ task #892 ] Add option in thridparty customer/supplier
 admin to hide non active in select_company method

---
 htdocs/core/class/html.form.class.php    |  1 +
 htdocs/core/modules/modSociete.class.php |  7 +++++
 htdocs/langs/en_US/admin.lang            |  1 +
 htdocs/langs/fr_FR/admin.lang            |  1 +
 htdocs/societe/admin/societe.php         | 37 ++++++++++++++++++++++++
 5 files changed, 47 insertions(+)

diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 000f14ee59f..4a03afcbb4b 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -681,6 +681,7 @@ class Form
         if (! empty($user->societe_id)) $sql.= " AND s.rowid = ".$user->societe_id;
         if ($filter) $sql.= " AND (".$filter.")";
         if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+        if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND s.status<>0 ";
         $sql.= " ORDER BY nom ASC";
 
         dol_syslog(get_class($this)."::select_company sql=".$sql);
diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php
index 6bb15f60a38..9c122e43280 100644
--- a/htdocs/core/modules/modSociete.class.php
+++ b/htdocs/core/modules/modSociete.class.php
@@ -116,6 +116,13 @@ class modSociete extends DolibarrModules
 		$this->const[$r][4] = 0;
 		$r++;
 
+		$this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
+		$this->const[$r][1] = "chaine";
+		$this->const[$r][2] = "0";
+		$this->const[$r][3] = "hide thirdparty customer inative in combobox";
+		$this->const[$r][4] = 0;
+		$r++;
+
 		// Boxes
 		$this->boxes = array();
 		$r=0;
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index f13698ad1a1..cac27722e61 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -53,6 +53,7 @@ ConfirmAjax=Use Ajax confirmation popups
 UseSearchToSelectCompany=Use autocompletion fields to choose third parties (instead of using a list box).<br><br>Also if you have a large number of third parties (> 100 000), you can increase speed by setting constant SOCIETE_DONOTSEARCH_ANYWHERE to 1 in Setup->Other. Search will then be limited to start of string.
 ActivityStateToSelectCompany= Add a filter option to show/hide thirdparties which are currently in activity or has ceased it
 UseSearchToSelectContact=Use autocompletion fields to choose contact (instead of using a list box).<br><br>Also if you have a large number of third parties (> 100 000), you can increase speed by setting constant CONTACT_DONOTSEARCH_ANYWHERE to 1 in Setup->Other. Search will then be limited to start of string.
+HideClosedThirdpartyComboBox=Hide Third party with Status to Closed into customer select list (or combobox)
 SearchFilter=Search filters options
 NumberOfKeyToSearch=Nbr of characters to trigger search: %s
 ViewFullDateActions=Show full dates events in the third sheet
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index 4bb7b833596..29333762881 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -52,6 +52,7 @@ ConfirmAjax= Utiliser les popups de confirmation Ajax
 UseSearchToSelectCompany= Utiliser un champ avec autocomplétion pour choisir un tiers (plutôt qu'une liste déroulante).<br><br>Notez que si vous avez un nombre important de tiers (> 100 000), vous pouvez améliorer les performances en définissant la constante SOCIETE_DONOTSEARCH_ANYWHERE à 1 dans Configuration->Divers. La recherche sera alors limitée au début de la chaine.
 ActivityStateToSelectCompany= Ajouter une option de filtrage lors des recherches pour afficher/masquer les tiers en exercice ou ayant cessés d'exercer
 UseSearchToSelectContact= Utiliser un champ avec autocomplétion pour choisir un contact (plutôt qu'une liste déroulante).<br><br>Notez que si vous avez un nombre important de contacts (> 100 000), vous pouvez améliorer les performances en définissant la constante CONTACT_DONOTSEARCH_ANYWHERE à 1 dans Configuration->Divers. La recherche sera alors limitée au début de la chaine.
+HideClosedThirdpartyComboBox=Ne pas afficher les clients à l'état "Clos" dans les listes déroulantes (ou champ avec autocomplétion)
 SearchFilter=Options des filtres de recherche
 NumberOfKeyToSearch=Nb carac. déclenchant recherche: %s
 ViewFullDateActions= Visualiser les dates des actions en entier dans la fiche tiers
diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php
index c8dcbb5d7f2..85768ba5c8c 100644
--- a/htdocs/societe/admin/societe.php
+++ b/htdocs/societe/admin/societe.php
@@ -245,6 +245,22 @@ if ($action == 'setprofidinvoicemandatory')
 	}
 }
 
+//Set hide closed customer into combox or select
+if ($action == 'sethideinactivethirdparty')
+{
+	$status = GETPOST('status','alpha');
+
+	if (dolibarr_set_const($db, "COMPANY_HIDE_INACTIVE_IN_COMBOBOX",$status,'chaine',0,'',$conf->entity) > 0)
+	{
+		header("Location: ".$_SERVER["PHP_SELF"]);
+		exit;
+	}
+	else
+	{
+		dol_print_error($db);
+	}
+}
+
 /*
  * 	View
  */
@@ -728,6 +744,27 @@ else
 	print "</td>";
 }
 print '</tr>';
+
+
+// COMPANY_USE_SEARCH_TO_SELECT
+$var=!$var;
+print "<tr ".$bc[$var].">";
+print '<td width="80%">'.$langs->trans("HideClosedThirdpartyComboBox").'</td>';
+if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX))
+{
+	print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=sethideinactivethirdparty&status=0">';
+	print img_picto($langs->trans("Activated"),'switch_on');
+	print '</a></td>';
+}
+else
+{
+	print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=sethideinactivethirdparty&status=1">';
+	print img_picto($langs->trans("Disabled"),'switch_off');
+	print '</a></td>';
+}
+print '</tr>';
+
+
 print '</table>';
 
 
-- 
GitLab