From 5ba650728df015a49304b85adaa3cdd157ee410b Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 11 Oct 2007 12:55:14 +0000 Subject: [PATCH] fix: nettoyage des requetes sql --- htdocs/commande/commande.class.php | 13 +++++++--- htdocs/facture.class.php | 39 +++++++++++++++++------------- htdocs/product.class.php | 38 ++++++++++++++--------------- htdocs/propal.class.php | 25 +++++++++++-------- 4 files changed, 65 insertions(+), 50 deletions(-) diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 4c2adddbe7b..bfae7157046 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -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) { diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 94b36a11ce8..c1bd0380880 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -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; + } } diff --git a/htdocs/product.class.php b/htdocs/product.class.php index cb0450c66ff..38defb73928 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -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; + } } /** diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index ab8ed7cade4..1bd4326e6ff 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -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; }