diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index e7268f0c47e2fb9cb8802da5d5690252f8df0f2b..be63cf9283d25e2ba6193e705aefde27af8b099d 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -92,7 +92,7 @@ class Propal extends CommonObject var $products=array(); var $lines = array(); - + var $origin; var $origin_id; @@ -544,7 +544,7 @@ class Propal extends CommonObject } if (! empty($this->ref)) { - $this->verifyNumRef($soc); // Check ref is not yet used + $result=$this->verifyNumRef(); // Check ref is not yet used } @@ -636,7 +636,7 @@ class Propal extends CommonObject break; } } - + // Add linked object if ($this->origin && $this->origin_id) { @@ -1241,6 +1241,7 @@ class Propal extends CommonObject // Propale signee include_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); + // TODO move in triggers $result=$this->create_commande($user); if ($result >= 0) @@ -1313,6 +1314,7 @@ class Propal extends CommonObject * \brief Cree une commande a partir de la proposition commerciale * \param user Utilisateur * \return int <0 si ko, >=0 si ok + * TODO move in triggers */ function create_commande($user) { @@ -1611,7 +1613,7 @@ class Propal extends CommonObject $this->db->rollback(); return 0; } - + // We remove directory $propalref = dol_sanitizeFileName($this->ref); if ($conf->propale->dir_output) @@ -2020,30 +2022,6 @@ class Propal extends CommonObject } } - /** - * \brief Check if ref is used. And if used tkae next one. - * \param soc objet societe - */ - function verifyNumRef($soc) - { - global $conf; - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."propal"; - $sql.= " WHERE ref = '".$this->ref."'"; - $sql.= " AND entity = ".$conf->entity; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num > 0) - { - $this->ref = $this->getNextNumRef($soc); - } - } - } - /** * \brief Renvoie la reference de propale suivante non utilisee en fonction du module diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 88f24e9dab59e6cc1ccac0e7166f49cfb8d69b8d..c5f31d3f185294ced80b4a27d04234f92afe375a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -32,6 +32,34 @@ class CommonObject { + /** + * \brief Check if ref is used. + * \return int <0 if KO, 0 if not found, >0 if found + */ + function verifyNumRef() + { + global $conf; + + $sql = "SELECT rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX.$this->element; + $sql.= " WHERE ref = '".$this->ref."'"; + $sql.= " AND entity = ".$conf->entity; + + dol_syslog("CommonObject::verifyNumRef sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + return $num; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog("CommonObject::verifyNumRef ".$this->error, LOG_ERR); + return -1; + } + } + /** * \brief Ajoute un contact associe au l'entite definie dans $this->element * \param fk_socpeople Id du contact a ajouter @@ -160,7 +188,7 @@ class CommonObject return -1; } } - + /** * \brief Supprime une ligne de contact * \return statur >0 si ok, <0 si ko @@ -169,13 +197,13 @@ class CommonObject { $temp = array(); $typeContact = $this->liste_type_contact(0); - + foreach($typeContact as $key => $value) { array_push($temp,$key); } $listId = implode(",", $temp); - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; $sql.= " WHERE element_id =".$this->id; $sql.= " AND fk_c_type_contact IN (".$listId.")"; diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index ddd9e951d041315633c70402f8f17c02b28c468d..740d49df8d9b52e8aa0aea74bc40e98919a0743f 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -101,20 +101,23 @@ class Fichinter extends CommonObject // on verifie si la ref n'est pas utilisee $soc = new Societe($this->db); $result=$soc->fetch($this->socid); - $result=$this->verifyNumRef($soc); - if ($result > 0) + if (! empty($this->ref)) { - $this->error='ErrorRefAlreadyExists'; - dol_syslog("Fichinter::create ".$this->error,LOG_WARNING); - $this->db->rollback(); - return -3; - } - else if ($result < 0) - { - $this->error=$this->db->error(); - dol_syslog("Fichinter::create ".$this->error,LOG_ERR); - $this->db->rollback(); - return -2; + $result=$this->verifyNumRef(); // Check ref is not yet used + if ($result > 0) + { + $this->error='ErrorRefAlreadyExists'; + dol_syslog("Fichinter::create ".$this->error,LOG_WARNING); + $this->db->rollback(); + return -3; + } + else if ($result < 0) + { + $this->error=$this->db->error(); + dol_syslog("Fichinter::create ".$this->error,LOG_ERR); + $this->db->rollback(); + return -2; + } } $now=dol_now(); @@ -409,39 +412,6 @@ class Fichinter extends CommonObject return $result; } - /** - * \brief Verifie si la ref n'est pas deja utilisee. Si oui, la modifie avec la prochaine libre. - * \param soc objet societe - * \return int <0 if KO, 0 if not found, >0 if found - */ - function verifyNumRef($soc) - { - global $conf; - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter"; - $sql.= " WHERE ref = '".$this->ref."'"; - $sql.= " AND entity = ".$conf->entity; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num > 0) - { - $this->ref = $this->getNextNumRef($soc); - } - dol_syslog("Fichinter::verifyNumber num=".$num,LOG_DEBUG); - return $num; - } - else - { - $this->error=$this->db->lasterror(); - dol_syslog("Fichinter::verifyNumber ".$this->error, LOG_ERR); - return -1; - } - } - /** * \brief Renvoie la reference de fiche intervention suivante non utilisee en fonction du module diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 431437631b6e899507a06bcf537e8c542adc41c2..5b9e59b8686d4f4b7d68ec521c4c8f1f7b469711 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -610,7 +610,7 @@ elseif ($fichinterid) print '<table class="nobordernopadding" width="100%"><tr><td>'; print $langs->trans('Description'); print '</td>'; - if ($_GET['action'] != 'editdescription' && $fichinter->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdescription&id='.$fichinter->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>'; + if ($_GET['action'] != 'editdescription' && $fichinter->statut == 0) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdescription&id='.$fichinter->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>'; print '</tr></table>'; print '</td><td colspan="3">'; if ($_GET['action'] == 'editdescription')