bugfix: modification de la fonction de vérification de l'utlisation d'un produit

This commit is contained in:
Regis Houssin 2006-04-10 10:20:18 +00:00
parent 62e40a90c9
commit 0add294119

View File

@ -255,17 +255,67 @@ class Product
*/ */
function verif_prod_use($id) function verif_prod_use($id)
{ {
$sql = "SELECT COUNT(*)"; $sqr = 0
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as p, ".MAIN_DB_PREFIX."commandedet as c";
$sql.= ", ".MAIN_DB_PREFIX."facturedet as f, ".MAIN_DB_PREFIX."contratdet as ct"; $sql = "SELECT rowid";
$sql.= " WHERE p.fk_product = ".$id." OR c.fk_product = ".$id." OR f.fk_product = ".$id." OR ct.fk_product = ".$id; $sql.= " FROM ".MAIN_DB_PREFIX."propaldet";
$resql = $this->db->query($sql); $sql.= " WHERE fk_product = ".$id;
if ($resql)
{ $result = $this->db->query($sql);
$row = $this->db->fetch_row($resql); if ($result)
$nbuse = $row[0]; {
} $num = $this->db->num_rows($result);
if ($nbuse == 0) 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)
{
$num = $this->db->num_rows($result);
if ($num != 0)
{
$sqr++;
}
}
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet";
$sql.= " WHERE fk_product = ".$id;
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
if ($num != 0)
{
$sqr++;
}
}
if ($sqr == 0)
{ {
return 0; return 0;
} }