diff --git a/htdocs/product.class.php b/htdocs/product.class.php index b22c7fffca9015909c1d915b0d6a19239528457e..3351251b485ce6b885d6ce99603a68e1e0de1d06 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -451,62 +451,23 @@ class Product extends CommonObject function verif_prod_use($id) { $sqr = 0; + + $element = array('propaldet','commandedet','facturedet','contratdet'); - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."propaldet"; - $sql.= " WHERE fk_product = ".$id; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num != 0) - { - $sqr++; - } - } - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."facturedet"; - $sql.= " WHERE fk_product = ".$id; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num != 0) - { - $sqr++; - } - } - - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet"; - $sql.= " WHERE fk_product = ".$id; - - $result = $this->db->query($sql); - if ($result) + foreach($element as $table) { - $num = $this->db->num_rows($result); - if ($num != 0) - { - $sqr++; - } - } - - - $sql = "SELECT rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet"; - $sql.= " WHERE fk_product = ".$id; + $sql = "SELECT rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX.$table; + $sql.= " WHERE fk_product = ".$id; - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - if ($num != 0) + $result = $this->db->query($sql); + if ($result) { - $sqr++; + $num = $this->db->num_rows($result); + if ($num != 0) + { + $sqr++; + } } }