diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index ba5a53b2831..47a4aefcadf 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -278,8 +278,8 @@ class Contrat extends CommonObject $sql.= " note, note_public"; $sql.= " FROM ".MAIN_DB_PREFIX."contrat WHERE rowid = $id"; + dolibarr_syslog("Contrat::fetch sql=".$sql); $resql = $this->db->query($sql) ; - if ($resql) { $result = $this->db->fetch_array($resql); @@ -1219,6 +1219,8 @@ class ContratLigne var $date_fin_prevue; var $date_fin_reel; + var $datem; + /** * \brief Constructeur d'objets ligne de contrat @@ -1293,7 +1295,54 @@ class ContratLigne } } - /** + /** + * \brief Chargement depuis la base des données du contrat + * \param id Id du contrat à charger + * \return int <0 si ko, id du contrat chargé si ok + */ + function fetch($id) + { + $sql = "SELECT rowid, fk_contrat, fk_product, ".$this->db->pdate("tms")." as datem,"; + $sql.= " statut,"; + $sql.= " label,"; + $sql.= " description"; + $sql.= " FROM ".MAIN_DB_PREFIX."contratdet WHERE rowid = ".$id; + + dolibarr_syslog("ContratLigne::fetch sql=".$sql); + $resql = $this->db->query($sql) ; + if ($resql) + { + $obj = $this->db->fetch_object($resql); + if ($obj) + { + $this->id = $obj->rowid; + $this->fk_contrat = $obj->fk_contrat; + $this->fk_product = $obj->fk_product; + $this->datem = $obj->datem; + $this->statut = $obj->statut; + $this->label = $obj->label; + $this->description = $obj->description; + + $this->db->free($resql); + return $this->id; + } + else + { + $this->error="Contract line not found"; + dolibarr_syslog("ContratLigne::Fetch ".$this->error,LOG_ERROR); + return -2; + } + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("ContratLigne::Fetch ".$this->error,LOG_ERROR); + return -1; + } + } + + + /** * \brief Mise a jour en base des champs total_xxx de ligne * \remarks Utilisé par migration * \return int <0 si ko, >0 si ok diff --git a/htdocs/contrat/ligne.php b/htdocs/contrat/ligne.php index 9a04188c7e3..9efa4355f2c 100644 --- a/htdocs/contrat/ligne.php +++ b/htdocs/contrat/ligne.php @@ -106,11 +106,16 @@ $html = new Form($db); /* */ /* *************************************************************************** */ -$id = $_GET["id"]; -if ($id > 0) +$lineid = $_GET["ligne"]; +if ($lineid > 0) { + $line = new ContratLigne($db); + $result=$line->fetch($lineid); + $contrat = New Contrat($db); - if ( $contrat->fetch($id) > 0) + $result=$contrat->fetch($line->fk_contrat); + + if ($result > 0) { $soc = new Societe($db); $soc->fetch($contrat->socid); @@ -123,7 +128,7 @@ if ($id > 0) $h=sizeof($head); // On ajout onglet service - $head[$h][0] = DOL_URL_ROOT.'/contrat/ligne.php?id='.$contrat->id."&ligne=".$_GET["ligne"]; + $head[$h][0] = DOL_URL_ROOT.'/contrat/ligne.php?id='.$contrat->id."&ligne=".$line->id; $head[$h][1] = $langs->trans($langs->trans("EditServiceLine")); $hselected = $h; @@ -233,8 +238,8 @@ if ($id > 0) $sql.= " p.ref, p.label"; $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; - $sql.= " WHERE cd.fk_contrat = ".$id; - $sql.= " AND cd.rowid = ".$_GET["ligne"]; + $sql.= " WHERE cd.fk_contrat = ".$contrat->id; + $sql.= " AND cd.rowid = ".$line->id; $sql.= " ORDER BY cd.rowid"; $result = $db->query($sql); @@ -420,7 +425,7 @@ if ($id > 0) */ $form = new Form($db); - print '
'; + print ''; print ''; print ''; @@ -449,7 +454,7 @@ if ($id > 0) print ''; - print ''; + print ''; print '
'.$langs->trans("CloseService").'
'.$langs->trans("Comment").'
'.$langs->trans("Comment").'
'; print '
';