diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 46859b8e251..380afb8c28e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -86,6 +86,7 @@ class Commande extends CommonObject var $origin; var $origin_id; + var $linked_objects=array(); var $user_author_id; @@ -706,37 +707,44 @@ class Commande extends CommonObject if ($this->id) { $this->ref="(PROV".$this->id.")"; - - // Add linked object - if ($this->origin && $this->origin_id) + + // Add object linked + if (is_array($this->linked_objects) && ! empty($this->linked_objects)) { - $ret = $this->add_object_linked(); - if (! $ret) dol_print_error($this->db); - } - - // TODO mutualiser - if ($this->origin == 'propal' && $this->origin_id) - { - // On recupere les differents contact interne et externe - $prop = new Propal($this->db, $this->socid, $this->origin_id); - - // On recupere le commercial suivi propale - $this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL'); - - if ($this->userid) - { - //On passe le commercial suivi propale en commercial suivi commande - $this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal'); - } - - // On recupere le contact client suivi propale - $this->contactid = $prop->getIdcontact('external', 'CUSTOMER'); - - if ($this->contactid) - { - //On passe le contact client suivi propale en contact client suivi commande - $this->add_contact($this->contactid[0], 'CUSTOMER', 'external'); - } + foreach($this->linked_objects as $origin => $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + + // TODO mutualiser + if ($origin == 'propal' && $origin_id) + { + // On recupere les differents contact interne et externe + $prop = new Propal($this->db, $this->socid, $origin_id); + + // On recupere le commercial suivi propale + $this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL'); + + if ($this->userid) + { + //On passe le commercial suivi propale en commercial suivi commande + $this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal'); + } + + // On recupere le contact client suivi propale + $this->contactid = $prop->getIdcontact('external', 'CUSTOMER'); + + if ($this->contactid) + { + //On passe le contact client suivi propale en contact client suivi commande + $this->add_contact($this->contactid[0], 'CUSTOMER', 'external'); + } + } + } } } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 34ad697af52..f252443df80 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2006 Rodolphe Quiedeville * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2011 Philippe Grand @@ -229,6 +229,13 @@ if ($action == 'add' && $user->rights->commande->creer) $object->origin = $_POST['origin']; $object->origin_id = $_POST['originid']; + + // Possibility to add external linked objects with hooks + $object->linked_objects[$object->origin] = $object->origin_id; + if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) + { + $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); + } $object_id = $object->create($user); @@ -1368,7 +1375,7 @@ if ($action == 'create' && $user->rights->commande->creer) } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); + $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 80803d6d714..860a9bfbd59 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3,7 +3,7 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2012 Christophe Battarel @@ -742,6 +742,13 @@ if ($action == 'add' && $user->rights->facture->creer) $object->origin = $_POST['origin']; $object->origin_id = $_POST['originid']; + + // Possibility to add external linked objects with hooks + $object->linked_objects[$object->origin] = $object->origin_id; + if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) + { + $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); + } $id = $object->create($user); @@ -1802,7 +1809,7 @@ if ($action == 'create') } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); + $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 1e27f24c64b..3a7e59c7a80 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -90,6 +90,7 @@ class Facture extends CommonObject var $fk_facture_source; var $origin; var $origin_id; + var $linked_objects=array(); var $fk_project; var $date_lim_reglement; var $cond_reglement_id; // Id in llx_c_paiement @@ -242,14 +243,17 @@ class Facture extends CommonObject if (! $resql) $error++; // Add object linked - if (! $error && $this->id && $this->origin && $this->origin_id) + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) { - $ret = $this->add_object_linked(); - if (! $ret) - { - dol_print_error($this->db); - $error++; - } + foreach($this->linked_objects as $origin => $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + } } /* diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 44e6edc6d1a..68e9a6d3270 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1458,12 +1458,17 @@ abstract class CommonObject } /** - * Add objects linked in llx_element_element. + * Add objects linked in llx_element_element. * - * @return int <=0 if KO, >0 if OK + * @param string $origin Linked element type + * @param int $origin_id Linked element id + * @return int <=0 if KO, >0 if OK */ - function add_object_linked() + function add_object_linked($origin=null, $origin_id=null) { + $origin = (! empty($origin) ? $origin : $this->origin); + $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; @@ -1472,8 +1477,8 @@ abstract class CommonObject $sql.= ", fk_target"; $sql.= ", targettype"; $sql.= ") VALUES ("; - $sql.= $this->origin_id; - $sql.= ", '".$this->origin."'"; + $sql.= $origin_id; + $sql.= ", '".$origin."'"; $sql.= ", ".$this->id; $sql.= ", '".$this->element."'"; $sql.= ")";