diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c581de29ee9..2fce0a684b8 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1645,7 +1645,7 @@ abstract class CommonObject $sourceid = (! empty($sourceid) ? $sourceid : $this->id); $targetid = (! empty($targetid) ? $targetid : $this->id); - $sourcetype = (! empty($sourcetype) ? $sourcetype : (! empty($this->origin) ? $this->origin : $this->element)); + $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); $targettype = (! empty($targettype) ? $targettype : $this->element); // Links beetween objects are stored in this table diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index 1a14077c8b6..4003db49467 100644 --- a/htdocs/core/lib/sendings.lib.php +++ b/htdocs/core/lib/sendings.lib.php @@ -45,12 +45,17 @@ function shipping_prepare_head($object) $head[$h][2] = 'shipping'; $h++; - if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire && ! empty($object->linkedObjectsIds['delivery'][0])) + if ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire) { - $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linkedObjectsIds['delivery'][0]; - $head[$h][1] = $langs->trans("DeliveryCard"); - $head[$h][2] = 'delivery'; - $h++; + // delivery link + $object->fetchObjectLinked($object->id,$object->element); + if (! empty($object->linkedObjectsIds['delivery'][0])) + { + $head[$h][0] = DOL_URL_ROOT."/livraison/fiche.php?id=".$object->linkedObjectsIds['delivery'][0]; + $head[$h][1] = $langs->trans("DeliveryCard"); + $head[$h][2] = 'delivery'; + $h++; + } } $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->id; diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 5d3903e5471..dc178c8fa25 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -867,9 +867,6 @@ else $soc = new Societe($db); $soc->fetch($object->socid); - // delivery link - $object->fetchObjectLinked($object->id,$object->element,-1,-1); - $head=shipping_prepare_head($object); dol_fiche_head($head, 'shipping', $langs->trans("Sending"), 0, 'sending'); diff --git a/htdocs/expedition/index.php b/htdocs/expedition/index.php index 619e48405f7..5c6baed4e4d 100644 --- a/htdocs/expedition/index.php +++ b/htdocs/expedition/index.php @@ -226,8 +226,8 @@ $sql = "SELECT e.rowid, e.ref"; $sql.= ", s.nom, 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.sourcetype IN ('commande')"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.targettype IN ('shipping')"; +$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'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc"; $sql.= " WHERE e.entity = ".$conf->entity; diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index 5377fee4f97..5bd83c257aa 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -549,7 +549,7 @@ class Livraison extends CommonObject { require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); $this->db->begin(); - + $error=0; $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet"; @@ -559,7 +559,7 @@ class Livraison extends CommonObject // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) $error++; - + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison"; @@ -804,7 +804,7 @@ class Livraison extends CommonObject global $langs; // Get the linked object - $this->fetchObjectLinked(-1,-1,$this->id,$this->element); + $this->fetchObjectLinked('','',$this->id,$this->element); //var_dump($this->linkedObjectIds); // Get the product ref and qty in source $sqlSourceLine = "SELECT st.rowid, st.description, st.qty";