From 019125f258f09c16c838c5889d38b2c231ee920b Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Wed, 2 Nov 2016 10:29:14 +0100
Subject: [PATCH] Uniformize code

---
 htdocs/commande/class/commande.class.php     |  8 +-
 htdocs/expedition/class/expedition.class.php | 23 ++++--
 htdocs/expedition/index.php                  | 77 ++++++++++++--------
 3 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 249646a8f54..0ae5ab4b217 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -3367,12 +3367,8 @@ class Commande extends CommonOrder
 
 		if ($user->rights->commande->lire) {
 			$label = '<u>'.$langs->trans("ShowOrder").'</u>';
-			if (!empty($this->ref)) {
-				$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
-			}
-			if (!empty($this->ref_client)) {
-				$label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.$this->ref_client;
-			}
+			$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
+			$label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
 			if (!empty($this->total_ht)) {
 				$label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
 			}
diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php
index c5d84836f90..9cf00cac1cb 100644
--- a/htdocs/expedition/class/expedition.class.php
+++ b/htdocs/expedition/class/expedition.class.php
@@ -1461,27 +1461,40 @@ class Expedition extends CommonObject
      *	@param      int			$option         Where point the link
      *	@param      int			$max          	Max length to show
      *	@param      int			$short			Use short labels
+     *  @param      int         $notooltip      1=No tooltip
      *	@return     string          			String with URL
      */
-	function getNomUrl($withpicto=0,$option=0,$max=0,$short=0)
+	function getNomUrl($withpicto=0,$option=0,$max=0,$short=0,$notooltip=0)
 	{
 		global $langs;
 
 		$result='';
         $label = '<u>' . $langs->trans("ShowSending") . '</u>';
-        if (! empty($this->ref))
-            $label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
-
+        $label .= '<br><b>' . $langs->trans('Ref') . ':</b> '.$this->ref;
+        $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client);
+            
 		$url = DOL_URL_ROOT.'/expedition/card.php?id='.$this->id;
 
 		if ($short) return $url;
 
+		$linkclose='';
+		if (empty($notooltip))
+		{
+		    if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
+		    {
+		        $label=$langs->trans("ShowSending");
+		        $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
+		    }
+		    $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
+		    $linkclose.=' class="classfortooltip"';
+		}
+		
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
 		$linkend='</a>';
 
 		$picto='sending';
 
-		if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
+		if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
 		if ($withpicto && $withpicto != 2) $result.=' ';
 		$result.=$linkstart.$this->ref.$linkend;
 		return $result;
diff --git a/htdocs/expedition/index.php b/htdocs/expedition/index.php
index 19b11a0ddf6..66355a471ee 100644
--- a/htdocs/expedition/index.php
+++ b/htdocs/expedition/index.php
@@ -61,9 +61,9 @@ print "</table></form><br>\n";
  */
 $clause = " WHERE ";
 
-$sql = "SELECT e.rowid, e.ref";
-$sql.= ", s.nom as name, s.rowid as socid";
-$sql.= ", c.ref as commande_ref, c.rowid as commande_id";
+$sql = "SELECT e.rowid, e.ref, e.ref_customer,";
+$sql.= " s.nom as name, s.rowid as socid,";
+$sql.= " c.ref as commande_ref, c.rowid as commande_id";
 $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid";
@@ -91,11 +91,14 @@ if ($resql)
 		$var = True;
 		while ($i < $num)
 		{
-			$var=!$var;
 			$obj = $db->fetch_object($resql);
-			print "<tr ".$bc[$var].'><td class="nowrap">';
+			
 			$shipment->id=$obj->rowid;
 			$shipment->ref=$obj->ref;
+			$shipment->ref_customer=$obj->ref_customer;
+				
+			$var=!$var;
+			print "<tr ".$bc[$var].'><td class="nowrap">';
 			print $shipment->getNomUrl(1);
 			print "</td>";
 			print '<td>';
@@ -114,9 +117,9 @@ if ($resql)
 /*
  * Commandes a traiter
  */
-$sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
-$sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
-$sql.= ", ".MAIN_DB_PREFIX."societe as s";
+$sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut, s.nom as name, s.rowid as socid";
+$sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
+$sql.= " ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " WHERE c.fk_soc = s.rowid";
 $sql.= " AND c.entity = ".$conf->entity;
@@ -140,19 +143,23 @@ if ($resql)
 		$var = True;
 		while ($i < $num)
 		{
-			$var=!$var;
 			$obj = $db->fetch_object($resql);
-			print "<tr ".$bc[$var].">";
-			print '<td class="nowrap">';
+
 			$orderstatic->id=$obj->rowid;
 			$orderstatic->ref=$obj->ref;
+			$orderstatic->ref_customer=$obj->ref_customer;
 			$orderstatic->statut=$obj->fk_statut;
 			$orderstatic->facturee=0;
+			
+			$companystatic->name=$obj->name;
+			$companystatic->id=$obj->socid;
+			
+			$var=!$var;
+			print "<tr ".$bc[$var].">";
+			print '<td class="nowrap">';
 			print $orderstatic->getNomUrl(1);
 			print '</td>';
 			print '<td>';
-			$companystatic->name=$obj->name;
-			$companystatic->id=$obj->socid;
 			print $companystatic->getNomUrl(1,'customer',32);
 			print '</td>';
 			print '<td align="right">';
@@ -173,9 +180,9 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
 /*
  * Commandes en traitement
  */
-$sql = "SELECT c.rowid, c.ref, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
-$sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
-$sql.= ", ".MAIN_DB_PREFIX."societe as s";
+$sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
+$sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
+$sql.= " ".MAIN_DB_PREFIX."societe as s";
 if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
 $sql.= " WHERE c.fk_soc = s.rowid";
 $sql.= " AND c.entity = ".$conf->entity;
@@ -198,21 +205,25 @@ if ( $resql )
 		$var = True;
 		while ($i < $num)
 		{
-			$var=!$var;
 			$obj = $db->fetch_object($resql);
-			print "<tr ".$bc[$var]."><td width=\"30%\">";
-			$orderstatic->id=$obj->rowid;
+			
+		    $orderstatic->id=$obj->rowid;
 			$orderstatic->ref=$obj->ref;
+			$orderstatic->ref_customer=$obj->ref_customer;
+			$orderstatic->statut=$obj->status;
+            $orderstatic->facturee=$obj->billed;
+			
+            $companystatic->name=$obj->name;
+			$companystatic->id=$obj->socid;
+				
+			$var=!$var;
+			print "<tr ".$bc[$var]."><td>";
 			print $orderstatic->getNomUrl(1);
 			print '</td>';
 			print '<td>';
-			$companystatic->name=$obj->name;
-			$companystatic->id=$obj->socid;
 			print $companystatic->getNomUrl(1,'customer');
 			print '</td>';
             print '<td align="right">';
-            $orderstatic->statut=$obj->status;
-            $orderstatic->facturee=$obj->billed;
             print $orderstatic->getLibStatut(3);
             print '</td>';
             print '</tr>';
@@ -227,9 +238,9 @@ else dol_print_error($db);
 /*
  * Last shipments
  */
-$sql = "SELECT e.rowid, e.ref";
-$sql.= ", s.nom as name, s.rowid as socid";
-$sql.= ", c.ref as commande_ref, c.rowid as commande_id";
+$sql = "SELECT e.rowid, e.ref, e.ref_customer,";
+$sql.= " s.nom as name, s.rowid as socid,";
+$sql.= " c.ref as commande_ref, c.rowid as commande_id";
 $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
@@ -255,13 +266,19 @@ if ($resql)
 		$var = True;
 		while ($i < $num)
 		{
-			$var=!$var;
 			$obj = $db->fetch_object($resql);
-			print '<tr '.$bc[$var].'><td width="20%"><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowSending"),"sending").' ';
-			print $obj->ref.'</a></td>';
+		    
+			$shipment->id=$obj->rowid;
+			$shipment->ref=$obj->ref;
+			$shipment->ref_customer=$obj->ref_customer;
+				
+			$var=!$var;
+			print '<tr '.$bc[$var].'><td>';
+			print $shipment->getNomUrl(1);
+			print '</td>';
 			print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
 			print '<td>';
-			if ($obj->commande_id)
+			if ($obj->commande_id > 0)
 			{
 				$orderstatic->id=$obj->commande_id;
 				$orderstatic->ref=$obj->commande_ref;
-- 
GitLab