fix: nettoyage des requetes sql
This commit is contained in:
parent
b2cad2c540
commit
5ba650728d
@ -2015,13 +2015,18 @@ class Commande extends CommonObject
|
||||
global $conf, $user;
|
||||
|
||||
$this->nbtodo=$this->nbtodolate=0;
|
||||
$clause = "WHERE";
|
||||
|
||||
$sql = 'SELECT c.rowid,'.$this->db->pdate('c.date_creation').' as datec';
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c';
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= ' WHERE c.fk_statut BETWEEN 1 AND 2';
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id)
|
||||
{
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc";
|
||||
$sql.= " WHERE sc.fk_user = " .$user->id;
|
||||
$clause = "AND";
|
||||
}
|
||||
$sql.= ' '.$clause.' c.fk_statut BETWEEN 1 AND 2';
|
||||
if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id;
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
|
||||
@ -2570,29 +2570,34 @@ class Facture extends CommonObject
|
||||
global $conf, $user;
|
||||
|
||||
$this->nbtodo=$this->nbtodolate=0;
|
||||
$clause = "WHERE";
|
||||
|
||||
$sql = 'SELECT f.rowid,'.$this->db->pdate('f.date_lim_reglement').' as datefin';
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
$sql.= ' WHERE f.paye=0 AND f.fk_statut = 1';
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id)
|
||||
{
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON f.fk_soc = sc.fk_soc";
|
||||
$sql.= " WHERE sc.fk_user = " .$user->id;
|
||||
$clause = "AND";
|
||||
}
|
||||
$sql.= ' '.$clause.' f.paye=0 AND f.fk_statut = 1';
|
||||
if ($user->societe_id) $sql.=' AND f.fk_soc = '.$user->societe_id;
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$this->nbtodo++;
|
||||
if ($obj->datefin < (time() - $conf->facture->client->warning_delay)) $this->nbtodolate++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$this->nbtodo++;
|
||||
if ($obj->datefin < (time() - $conf->facture->client->warning_delay)) $this->nbtodolate++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2473,30 +2473,30 @@ class Product
|
||||
$sql = "SELECT count(p.rowid) as nb";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
|
||||
if ($conf->categorie->enabled && !$user->rights->categorie->voir)
|
||||
{
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid";
|
||||
}
|
||||
{
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid";
|
||||
}
|
||||
$sql.= " WHERE p.fk_product_type <> 1";
|
||||
if ($conf->categorie->enabled && !$user->rights->categorie->voir)
|
||||
{
|
||||
$sql.= " AND IFNULL(c.visible,1)=1";
|
||||
}
|
||||
{
|
||||
$sql.= " AND IFNULL(c.visible,1)=1";
|
||||
}
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$this->nb["products"]=$obj->nb;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$this->nb["products"]=$obj->nb;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1846,14 +1846,19 @@ class Propal extends CommonObject
|
||||
global $conf, $user;
|
||||
|
||||
$this->nbtodo=$this->nbtodolate=0;
|
||||
$clause = "WHERE";
|
||||
|
||||
$sql ="SELECT p.rowid, p.ref, ".$this->db->pdate("p.datec")." as datec,".$this->db->pdate("p.fin_validite")." as datefin";
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
|
||||
$sql.=" FROM ".MAIN_DB_PREFIX."propal as p";
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
if ($mode == 'opened') $sql.=" WHERE p.fk_statut = 1";
|
||||
if ($mode == 'signed') $sql.=" WHERE p.fk_statut = 2";
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id)
|
||||
{
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
|
||||
$sql.= " WHERE sc.fk_user = " .$user->id;
|
||||
$clause = "AND";
|
||||
}
|
||||
if ($mode == 'opened') $sql.=" ".$clause." p.fk_statut = 1";
|
||||
if ($mode == 'signed') $sql.=" ".$clause." p.fk_statut = 2";
|
||||
if ($user->societe_id) $sql.=" AND p.fk_soc = ".$user->societe_id;
|
||||
if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -1862,11 +1867,11 @@ class Propal extends CommonObject
|
||||
$this->nbtodo++;
|
||||
if ($obj->datefin < (time() - $conf->propal->cloture->warning_delay))
|
||||
{
|
||||
if ($mode == 'opened') $this->nbtodolate++;
|
||||
if ($mode == 'signed') $this->nbtodolate++;
|
||||
// \todo Definir règle des propales à facturer en retard
|
||||
// if ($mode == 'signed' && ! sizeof($this->FactureListeArray($obj->rowid))) $this->nbtodolate++;
|
||||
}
|
||||
if ($mode == 'opened') $this->nbtodolate++;
|
||||
if ($mode == 'signed') $this->nbtodolate++;
|
||||
// \todo Definir règle des propales à facturer en retard
|
||||
// if ($mode == 'signed' && ! sizeof($this->FactureListeArray($obj->rowid))) $this->nbtodolate++;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user